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

Port 1.0-staging to main #1152

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion src/backend/libc/event/poll_fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::backend::conv::borrowed_fd;
use crate::backend::fd::{AsFd, AsRawFd, BorrowedFd, LibcFd};
#[cfg(windows)]
use crate::backend::fd::{AsSocket, RawFd};
use crate::ffi;
use bitflags::bitflags;
use core::fmt;
use core::marker::PhantomData;
Expand All @@ -13,7 +14,7 @@ bitflags! {
/// [`poll`]: crate::event::poll
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct PollFlags: c::c_short {
pub struct PollFlags: ffi::c_short {
/// `POLLIN`
const IN = c::POLLIN;
/// `POLLPRI`
Expand Down
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
13 changes: 7 additions & 6 deletions src/backend/libc/fs/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(not(any(target_os = "espidf", target_os = "vita")))]
Expand All @@ -8,7 +9,7 @@ bitflags! {
/// [`accessat`]: fn.accessat.html
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct Access: c::c_int {
pub struct Access: ffi::c_int {
/// `R_OK`
const READ_OK = c::R_OK;

Expand Down Expand Up @@ -378,7 +379,7 @@ bitflags! {
/// [`fcopyfile`]: crate::fs::fcopyfile
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct CopyfileFlags: c::c_uint {
pub struct CopyfileFlags: ffi::c_uint {
/// `COPYFILE_ACL`
const ACL = copyfile::ACL;

Expand Down Expand Up @@ -443,7 +444,7 @@ bitflags! {
/// [`renameat_with`]: crate::fs::renameat_with
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct RenameFlags: c::c_uint {
pub struct RenameFlags: ffi::c_uint {
/// `RENAME_EXCHANGE`
const EXCHANGE = bitcast!(c::RENAME_EXCHANGE);

Expand Down Expand Up @@ -598,7 +599,7 @@ bitflags! {
/// [`memfd_create`]: crate::fs::memfd_create
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct MemfdFlags: c::c_uint {
pub struct MemfdFlags: ffi::c_uint {
/// `MFD_CLOEXEC`
const CLOEXEC = c::MFD_CLOEXEC;

Expand Down Expand Up @@ -1127,15 +1128,15 @@ pub type RawMode = c::mode_t;

/// `mode_t`
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
pub type RawMode = c::c_uint;
pub type RawMode = ffi::c_uint;

/// `dev_t`
#[cfg(not(all(target_os = "android", target_pointer_width = "32")))]
pub type Dev = c::dev_t;

/// `dev_t`
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
pub type Dev = c::c_ulonglong;
pub type Dev = ffi::c_ulonglong;

/// `__fsword_t`
#[cfg(all(
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 @@ -246,7 +247,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 @@ -278,7 +279,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 @@ -303,7 +304,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
Loading
Loading