Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove WaitidStatus::as_raw #1074

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 32 additions & 30 deletions src/backend/libc/fs/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use crate::backend::c;
use crate::backend::conv::ret_usize;
use crate::backend::conv::{borrowed_fd, c_str, ret, ret_c_int, ret_off_t, ret_owned_fd};
use crate::fd::{BorrowedFd, OwnedFd};
use crate::ffi::CStr;
#[cfg(all(apple, feature = "alloc"))]
use crate::ffi::CString;
use crate::ffi::{self, CStr};
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
use crate::fs::Access;
#[cfg(not(any(
Expand Down Expand Up @@ -89,7 +89,7 @@ use {
};

#[cfg(all(target_env = "gnu", fix_y2038))]
weak!(fn __utimensat64(c::c_int, *const c::c_char, *const LibcTimespec, c::c_int) -> c::c_int);
weak!(fn __utimensat64(c::c_int, *const ffi::c_char, *const LibcTimespec, c::c_int) -> c::c_int);
#[cfg(all(target_env = "gnu", fix_y2038))]
weak!(fn __futimens64(c::c_int, *const LibcTimespec) -> c::c_int);

Expand Down Expand Up @@ -122,7 +122,7 @@ fn open_via_syscall(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<Owned
unsafe {
syscall! {
fn open(
pathname: *const c::c_char,
pathname: *const ffi::c_char,
oflags: c::c_int,
mode: c::mode_t
) via SYS_open -> c::c_int
Expand Down Expand Up @@ -182,7 +182,7 @@ fn openat_via_syscall(
syscall! {
fn openat(
base_dirfd: c::c_int,
pathname: *const c::c_char,
pathname: *const ffi::c_char,
oflags: c::c_int,
mode: c::mode_t
) via SYS_openat -> c::c_int
Expand Down Expand Up @@ -277,9 +277,11 @@ pub(crate) fn statvfs(filename: &CStr) -> io::Result<StatVfs> {
#[inline]
pub(crate) fn readlink(path: &CStr, buf: &mut [u8]) -> io::Result<usize> {
unsafe {
ret_usize(
c::readlink(c_str(path), buf.as_mut_ptr().cast::<c::c_char>(), buf.len()) as isize,
)
ret_usize(c::readlink(
c_str(path),
buf.as_mut_ptr().cast::<ffi::c_char>(),
buf.len(),
) as isize)
}
}

Expand All @@ -294,7 +296,7 @@ pub(crate) fn readlinkat(
ret_usize(c::readlinkat(
borrowed_fd(dirfd),
c_str(path),
buf.as_mut_ptr().cast::<c::c_char>(),
buf.as_mut_ptr().cast::<ffi::c_char>(),
buf.len(),
) as isize)
}
Expand Down Expand Up @@ -354,9 +356,9 @@ pub(crate) fn linkat(
weak! {
fn linkat(
c::c_int,
*const c::c_char,
*const ffi::c_char,
c::c_int,
*const c::c_char,
*const ffi::c_char,
c::c_int
) -> c::c_int
}
Expand Down Expand Up @@ -411,7 +413,7 @@ pub(crate) fn unlinkat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io
weak! {
fn unlinkat(
c::c_int,
*const c::c_char,
*const ffi::c_char,
c::c_int
) -> c::c_int
}
Expand Down Expand Up @@ -464,9 +466,9 @@ pub(crate) fn renameat(
weak! {
fn renameat(
c::c_int,
*const c::c_char,
*const ffi::c_char,
c::c_int,
*const c::c_char
*const ffi::c_char
) -> c::c_int
}
// If we have `renameat`, use it.
Expand Down Expand Up @@ -508,9 +510,9 @@ pub(crate) fn renameat2(
weak_or_syscall! {
fn renameat2(
olddirfd: c::c_int,
oldpath: *const c::c_char,
oldpath: *const ffi::c_char,
newdirfd: c::c_int,
newpath: *const c::c_char,
newpath: *const ffi::c_char,
flags: c::c_uint
) via SYS_renameat2 -> c::c_int
}
Expand Down Expand Up @@ -547,9 +549,9 @@ pub(crate) fn renameat2(
syscall! {
fn renameat2(
olddirfd: c::c_int,
oldpath: *const c::c_char,
oldpath: *const ffi::c_char,
newdirfd: c::c_int,
newpath: *const c::c_char,
newpath: *const ffi::c_char,
flags: c::c_uint
) via SYS_renameat2 -> c::c_int
}
Expand Down Expand Up @@ -750,7 +752,7 @@ pub(crate) fn accessat(
weak! {
fn faccessat(
c::c_int,
*const c::c_char,
*const ffi::c_char,
c::c_int,
c::c_int
) -> c::c_int
Expand Down Expand Up @@ -857,14 +859,14 @@ pub(crate) fn utimensat(
weak! {
fn utimensat(
c::c_int,
*const c::c_char,
*const ffi::c_char,
*const c::timespec,
c::c_int
) -> c::c_int
}
extern "C" {
fn setattrlist(
path: *const c::c_char,
path: *const ffi::c_char,
attr_list: *const Attrlist,
attr_buf: *const c::c_void,
attr_buf_size: c::size_t,
Expand Down Expand Up @@ -1051,7 +1053,7 @@ pub(crate) fn chmodat(
syscall! {
fn fchmodat(
base_dirfd: c::c_int,
pathname: *const c::c_char,
pathname: *const ffi::c_char,
mode: c::mode_t
) via SYS_fchmodat -> c::c_int
}
Expand Down Expand Up @@ -1081,7 +1083,7 @@ pub(crate) fn fclonefileat(
fn fclonefileat(
srcfd: BorrowedFd<'_>,
dst_dirfd: BorrowedFd<'_>,
dst: *const c::c_char,
dst: *const ffi::c_char,
flags: c::c_int
) via SYS_fclonefileat -> c::c_int
}
Expand Down Expand Up @@ -1713,15 +1715,15 @@ pub(crate) fn memfd_create(name: &CStr, flags: MemfdFlags) -> io::Result<OwnedFd
#[cfg(target_os = "freebsd")]
weakcall! {
fn memfd_create(
name: *const c::c_char,
name: *const ffi::c_char,
flags: c::c_uint
) -> c::c_int
}

#[cfg(linux_kernel)]
weak_or_syscall! {
fn memfd_create(
name: *const c::c_char,
name: *const ffi::c_char,
flags: c::c_uint
) via SYS_memfd_create -> c::c_int
}
Expand All @@ -1742,7 +1744,7 @@ pub(crate) fn openat2(
syscall! {
fn openat2(
base_dirfd: c::c_int,
pathname: *const c::c_char,
pathname: *const ffi::c_char,
how: *mut open_how,
size: usize
) via SYS_OPENAT2 -> c::c_int
Expand Down Expand Up @@ -1910,12 +1912,12 @@ fn stat64_to_stat(s64: c::stat64) -> io::Result<Stat> {
#[cfg(linux_kernel)]
#[allow(non_upper_case_globals)]
mod sys {
use super::{c, BorrowedFd, Statx};
use super::{c, ffi, BorrowedFd, Statx};

weak_or_syscall! {
pub(super) fn statx(
dirfd_: BorrowedFd<'_>,
path: *const c::c_char,
path: *const ffi::c_char,
flags: c::c_int,
mask: c::c_uint,
buf: *mut Statx
Expand Down Expand Up @@ -2442,7 +2444,7 @@ pub(crate) fn fsetxattr(
}

#[cfg(any(apple, linux_kernel, target_os = "hurd"))]
pub(crate) fn listxattr(path: &CStr, list: &mut [c::c_char]) -> io::Result<usize> {
pub(crate) fn listxattr(path: &CStr, list: &mut [ffi::c_char]) -> io::Result<usize> {
#[cfg(not(apple))]
unsafe {
ret_usize(c::listxattr(path.as_ptr(), list.as_mut_ptr(), list.len()))
Expand All @@ -2460,7 +2462,7 @@ pub(crate) fn listxattr(path: &CStr, list: &mut [c::c_char]) -> io::Result<usize
}

#[cfg(any(apple, linux_kernel, target_os = "hurd"))]
pub(crate) fn llistxattr(path: &CStr, list: &mut [c::c_char]) -> io::Result<usize> {
pub(crate) fn llistxattr(path: &CStr, list: &mut [ffi::c_char]) -> io::Result<usize> {
#[cfg(not(apple))]
unsafe {
ret_usize(c::llistxattr(path.as_ptr(), list.as_mut_ptr(), list.len()))
Expand All @@ -2478,7 +2480,7 @@ pub(crate) fn llistxattr(path: &CStr, list: &mut [c::c_char]) -> io::Result<usiz
}

#[cfg(any(apple, linux_kernel, target_os = "hurd"))]
pub(crate) fn flistxattr(fd: BorrowedFd<'_>, list: &mut [c::c_char]) -> io::Result<usize> {
pub(crate) fn flistxattr(fd: BorrowedFd<'_>, list: &mut [ffi::c_char]) -> io::Result<usize> {
let fd = borrowed_fd(fd);

#[cfg(not(apple))]
Expand Down
17 changes: 9 additions & 8 deletions src/backend/libc/mount/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::backend::c;
use crate::ffi;
use bitflags::bitflags;

#[cfg(linux_kernel)]
Expand All @@ -8,7 +9,7 @@ bitflags! {
/// [`mount`]: crate::mount::mount
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct MountFlags: c::c_ulong {
pub struct MountFlags: ffi::c_ulong {
/// `MS_BIND`
const BIND = c::MS_BIND;

Expand Down Expand Up @@ -90,7 +91,7 @@ bitflags! {
/// [`fsopen`]: crate::mount::fsopen
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct FsOpenFlags: c::c_uint {
pub struct FsOpenFlags: ffi::c_uint {
/// `FSOPEN_CLOEXEC`
const FSOPEN_CLOEXEC = 0x0000_0001;

Expand All @@ -107,7 +108,7 @@ bitflags! {
/// [`fsmount`]: crate::mount::fsmount
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct FsMountFlags: c::c_uint {
pub struct FsMountFlags: ffi::c_uint {
/// `FSMOUNT_CLOEXEC`
const FSMOUNT_CLOEXEC = 0x0000_0001;

Expand Down Expand Up @@ -155,7 +156,7 @@ bitflags! {
/// [`fsmount`]: crate::mount::fsmount
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct MountAttrFlags: c::c_uint {
pub struct MountAttrFlags: ffi::c_uint {
/// `MOUNT_ATTR_RDONLY`
const MOUNT_ATTR_RDONLY = 0x0000_0001;

Expand Down Expand Up @@ -205,7 +206,7 @@ bitflags! {
/// [`move_mount`]: crate::mount::move_mount
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct MoveMountFlags: c::c_uint {
pub struct MoveMountFlags: ffi::c_uint {
/// `MOVE_MOUNT_F_EMPTY_PATH`
const MOVE_MOUNT_F_SYMLINKS = 0x0000_0001;

Expand Down Expand Up @@ -247,7 +248,7 @@ bitflags! {
/// [`open_tree`]: crate::mount::open_tree
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct OpenTreeFlags: c::c_uint {
pub struct OpenTreeFlags: ffi::c_uint {
/// `OPENTREE_CLONE`
const OPEN_TREE_CLONE = 1;

Expand Down Expand Up @@ -279,7 +280,7 @@ bitflags! {
/// [`fspick`]: crate::mount::fspick
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct FsPickFlags: c::c_uint {
pub struct FsPickFlags: ffi::c_uint {
/// `FSPICK_CLOEXEC`
const FSPICK_CLOEXEC = 0x0000_0001;

Expand All @@ -304,7 +305,7 @@ bitflags! {
/// [`mount_change`]: crate::mount::mount_change
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct MountPropagationFlags: c::c_ulong {
pub struct MountPropagationFlags: ffi::c_ulong {
/// `MS_SILENT`
const SILENT = c::MS_SILENT;
/// `MS_SHARED`
Expand Down
21 changes: 18 additions & 3 deletions src/backend/libc/thread/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ pub(crate) fn clock_nanosleep_relative(id: ClockId, request: &Timespec) -> Nanos
let flags = 0;
let mut remain = MaybeUninit::<Timespec>::uninit();

match c::clock_nanosleep(id as c::clockid_t, flags, request, remain.as_mut_ptr()) {
match c::clock_nanosleep(
id as c::clockid_t,
flags,
request as *const Timespec as *const libc::timespec,
remain.as_mut_ptr().cast(),
) {
0 => NanosleepRelativeResult::Ok,
err if err == io::Errno::INTR.0 => {
NanosleepRelativeResult::Interrupted(remain.assume_init())
Expand Down Expand Up @@ -182,7 +187,14 @@ pub(crate) fn clock_nanosleep_absolute(id: ClockId, request: &Timespec) -> io::R
{
let flags = c::TIMER_ABSTIME;

match unsafe { c::clock_nanosleep(id as c::clockid_t, flags as _, request, null_mut()) } {
match unsafe {
c::clock_nanosleep(
id as c::clockid_t,
flags as _,
request as *const Timespec as *const libc::timespec,
null_mut(),
)
} {
0 => Ok(()),
err => Err(io::Errno(err)),
}
Expand Down Expand Up @@ -247,7 +259,10 @@ pub(crate) fn nanosleep(request: &Timespec) -> NanosleepRelativeResult {
unsafe {
let mut remain = MaybeUninit::<Timespec>::uninit();

match ret(c::nanosleep(request, remain.as_mut_ptr())) {
match ret(c::nanosleep(
request as *const Timespec as *const libc::timespec,
remain.as_mut_ptr().cast(),
)) {
Ok(()) => NanosleepRelativeResult::Ok,
Err(io::Errno::INTR) => NanosleepRelativeResult::Interrupted(remain.assume_init()),
Err(err) => NanosleepRelativeResult::Err(err),
Expand Down
Loading
Loading