Skip to content

Commit

Permalink
Remove linux-raw-sys and libc from public API (#956)
Browse files Browse the repository at this point in the history
* Remove linux-raw-sys and libc from public API

This prevents libc and linux-raw-sys from affecting the semver status of
this crate.

Signed-off-by: John Nunley <[email protected]>

* Fix compile errors

Signed-off-by: John Nunley <[email protected]>

---------

Signed-off-by: John Nunley <[email protected]>
  • Loading branch information
notgull authored Jan 16, 2024
1 parent 2a70730 commit 6decc5f
Show file tree
Hide file tree
Showing 26 changed files with 184 additions and 206 deletions.
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(apple)]
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 @@ -90,7 +90,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 @@ -123,7 +123,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 @@ -178,7 +178,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 @@ -268,9 +268,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 @@ -285,7 +287,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 @@ -345,9 +347,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 @@ -402,7 +404,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 @@ -455,9 +457,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 @@ -499,9 +501,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 @@ -538,9 +540,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 @@ -741,7 +743,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 @@ -848,14 +850,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 @@ -1040,7 +1042,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 @@ -1070,7 +1072,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 @@ -1703,15 +1705,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 @@ -1732,7 +1734,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 @@ -1922,12 +1924,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 @@ -2405,7 +2407,7 @@ pub(crate) fn fsetxattr(
}

#[cfg(any(apple, linux_kernel))]
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 @@ -2423,7 +2425,7 @@ pub(crate) fn listxattr(path: &CStr, list: &mut [c::c_char]) -> io::Result<usize
}

#[cfg(any(apple, linux_kernel))]
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 @@ -2441,7 +2443,7 @@ pub(crate) fn llistxattr(path: &CStr, list: &mut [c::c_char]) -> io::Result<usiz
}

#[cfg(any(apple, linux_kernel))]
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 @@ -179,7 +184,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 @@ -237,7 +249,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

0 comments on commit 6decc5f

Please sign in to comment.