Skip to content

Commit 4a0c0e4

Browse files
sunfishcodenotgull
andauthored
Port 1.0-staging to main (#1152)
* Remove linux-raw-sys and libc from public API (#956) * 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 <dev@notgull.net> --------- Signed-off-by: John Nunley <dev@notgull.net> * Patch low-hanging fruit semver removals for libc and linux-raw-sys (#1063) * break: Remove low-hanging fruit for linux-raw-sys exposure linux-raw-sys is exposed as a public dependency. This commit removes many of the instances where it is publicly exposed. There are a few places that are more difficult and require greater discussion. I've left these in for now. This is checked using this command: $ cargo public-api --features all-apis | grep -i linux_raw_sys The remaining APIs that expose linux_raw_sys are as follows: pub type rustix::fs::FsWord = linux_raw_sys::general::__fsword_t pub type rustix::fs::RawMode = linux_raw_sys::general::__kernel_mode_t pub type rustix::fs::Stat = linux_raw_sys::general::stat pub type rustix::fs::StatFs = linux_raw_sys::general::statfs64 pub type rustix::fs::Statx = linux_raw_sys::general::statx pub type rustix::fs::StatxTimestamp = linux_raw_sys::general::statx_timestamp pub rustix::io_uring::io_uring_cqe::big_cqe: linux_raw_sys::io_uring::__IncompleteArrayField<u64> pub rustix::io_uring::io_uring_probe::ops: linux_raw_sys::io_uring::__IncompleteArrayField<rustix::io_uring::io_uring_probe_op> pub type rustix::io_uring::Statx = linux_raw_sys::general::statx pub type rustix::net::SocketAddrStorage = linux_raw_sys::net::sockaddr pub const fn rustix::process::WaitidStatus::as_raw(&self) -> &linux_raw_sys::general::siginfo_t pub type rustix::system::Sysinfo = linux_raw_sys::system::sysinfo pub type rustix::termios::Winsize = linux_raw_sys::general::winsize Signed-off-by: John Nunley <dev@notgull.net> * break: Low-hanging fruit for removing libc from public API Similarly to the last commit, this one removes libc types from the public API. Again there are libc types that are harder to remove so I've skipped them for now. This can be checked with: $ cargo public-api --features all-apis,use-libc | grep -i libc The remaining API's are: pub type rustix::fs::Dev = libc::unix::linux_like::linux::dev_t pub type rustix::fs::FsWord = libc::unix::linux_like::linux::gnu::b64::__fsword_t pub type rustix::fs::RawMode = libc::unix::linux_like::linux::mode_t pub type rustix::fs::Stat = libc::unix::linux_like::linux::gnu::b64::x86_64::stat64 pub type rustix::fs::StatFs = libc::unix::linux_like::linux::gnu::b64::x86_64::statfs64 pub type rustix::fs::Statx = libc::unix::linux_like::linux::gnu::statx pub type rustix::fs::StatxTimestamp = libc::unix::linux_like::linux::gnu::statx pub type rustix::io_uring::Statx = libc::unix::linux_like::linux::gnu::statx pub type rustix::net::SocketAddrStorage = libc::unix::linux_like::sockaddr_storage pub const fn rustix::process::WaitidStatus::as_raw(&self) -> &libc::unix::linux_like::linux::gnu::b64::x86_64::siginfo_t pub type rustix::system::Sysinfo = libc::unix::linux_like::linux::gnu::b64::sysinfo pub type rustix::termios::Winsize = libc::unix::winsize Signed-off-by: John Nunley <dev@notgull.net> --------- Signed-off-by: John Nunley <dev@notgull.net> * Fix compile errors. * Fix a warning. * Fix a warning. * Add `c_ulonglong`/`c_longlong` to the ffi module. * Fix a warning. * Add `ffi::c_void` on Windows. * bugfix: Fix unused type in WASI (#1177) Signed-off-by: John Nunley <dev@notgull.net> * Use `as_ptr` and `.cast` to avoid `as` casts. * Add some more libc type layout tests. * Make `Secs` always be `i64`. * Add casting helpers for timespec types. --------- Signed-off-by: John Nunley <dev@notgull.net> Co-authored-by: John Nunley <dev@notgull.net>
1 parent fd3fed2 commit 4a0c0e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+350
-265
lines changed

src/backend/libc/event/poll_fd.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::backend::conv::borrowed_fd;
33
use crate::backend::fd::{AsFd, AsRawFd, BorrowedFd, LibcFd};
44
#[cfg(windows)]
55
use crate::backend::fd::{AsSocket, RawFd};
6+
use crate::ffi;
67
use bitflags::bitflags;
78
use core::fmt;
89
use core::marker::PhantomData;
@@ -13,7 +14,7 @@ bitflags! {
1314
/// [`poll`]: crate::event::poll
1415
#[repr(transparent)]
1516
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
16-
pub struct PollFlags: c::c_short {
17+
pub struct PollFlags: ffi::c_short {
1718
/// `POLLIN`
1819
const IN = c::POLLIN;
1920
/// `POLLPRI`

src/backend/libc/fs/syscalls.rs

+32-30
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use crate::backend::c;
99
use crate::backend::conv::ret_usize;
1010
use crate::backend::conv::{borrowed_fd, c_str, ret, ret_c_int, ret_off_t, ret_owned_fd};
1111
use crate::fd::{BorrowedFd, OwnedFd};
12-
use crate::ffi::CStr;
1312
#[cfg(all(apple, feature = "alloc"))]
1413
use crate::ffi::CString;
14+
use crate::ffi::{self, CStr};
1515
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
1616
use crate::fs::Access;
1717
#[cfg(not(any(
@@ -88,7 +88,7 @@ use {
8888
};
8989

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

@@ -121,7 +121,7 @@ fn open_via_syscall(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<Owned
121121
unsafe {
122122
syscall! {
123123
fn open(
124-
pathname: *const c::c_char,
124+
pathname: *const ffi::c_char,
125125
oflags: c::c_int,
126126
mode: c::mode_t
127127
) via SYS_open -> c::c_int
@@ -181,7 +181,7 @@ fn openat_via_syscall(
181181
syscall! {
182182
fn openat(
183183
base_dirfd: c::c_int,
184-
pathname: *const c::c_char,
184+
pathname: *const ffi::c_char,
185185
oflags: c::c_int,
186186
mode: c::mode_t
187187
) via SYS_openat -> c::c_int
@@ -276,9 +276,11 @@ pub(crate) fn statvfs(filename: &CStr) -> io::Result<StatVfs> {
276276
#[inline]
277277
pub(crate) fn readlink(path: &CStr, buf: &mut [u8]) -> io::Result<usize> {
278278
unsafe {
279-
ret_usize(
280-
c::readlink(c_str(path), buf.as_mut_ptr().cast::<c::c_char>(), buf.len()) as isize,
281-
)
279+
ret_usize(c::readlink(
280+
c_str(path),
281+
buf.as_mut_ptr().cast::<ffi::c_char>(),
282+
buf.len(),
283+
) as isize)
282284
}
283285
}
284286

@@ -293,7 +295,7 @@ pub(crate) fn readlinkat(
293295
ret_usize(c::readlinkat(
294296
borrowed_fd(dirfd),
295297
c_str(path),
296-
buf.as_mut_ptr().cast::<c::c_char>(),
298+
buf.as_mut_ptr().cast::<ffi::c_char>(),
297299
buf.len(),
298300
) as isize)
299301
}
@@ -353,9 +355,9 @@ pub(crate) fn linkat(
353355
weak! {
354356
fn linkat(
355357
c::c_int,
356-
*const c::c_char,
358+
*const ffi::c_char,
357359
c::c_int,
358-
*const c::c_char,
360+
*const ffi::c_char,
359361
c::c_int
360362
) -> c::c_int
361363
}
@@ -410,7 +412,7 @@ pub(crate) fn unlinkat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io
410412
weak! {
411413
fn unlinkat(
412414
c::c_int,
413-
*const c::c_char,
415+
*const ffi::c_char,
414416
c::c_int
415417
) -> c::c_int
416418
}
@@ -463,9 +465,9 @@ pub(crate) fn renameat(
463465
weak! {
464466
fn renameat(
465467
c::c_int,
466-
*const c::c_char,
468+
*const ffi::c_char,
467469
c::c_int,
468-
*const c::c_char
470+
*const ffi::c_char
469471
) -> c::c_int
470472
}
471473
// If we have `renameat`, use it.
@@ -507,9 +509,9 @@ pub(crate) fn renameat2(
507509
weak_or_syscall! {
508510
fn renameat2(
509511
olddirfd: c::c_int,
510-
oldpath: *const c::c_char,
512+
oldpath: *const ffi::c_char,
511513
newdirfd: c::c_int,
512-
newpath: *const c::c_char,
514+
newpath: *const ffi::c_char,
513515
flags: c::c_uint
514516
) via SYS_renameat2 -> c::c_int
515517
}
@@ -546,9 +548,9 @@ pub(crate) fn renameat2(
546548
syscall! {
547549
fn renameat2(
548550
olddirfd: c::c_int,
549-
oldpath: *const c::c_char,
551+
oldpath: *const ffi::c_char,
550552
newdirfd: c::c_int,
551-
newpath: *const c::c_char,
553+
newpath: *const ffi::c_char,
552554
flags: c::c_uint
553555
) via SYS_renameat2 -> c::c_int
554556
}
@@ -744,7 +746,7 @@ pub(crate) fn accessat(
744746
weak! {
745747
fn faccessat(
746748
c::c_int,
747-
*const c::c_char,
749+
*const ffi::c_char,
748750
c::c_int,
749751
c::c_int
750752
) -> c::c_int
@@ -851,14 +853,14 @@ pub(crate) fn utimensat(
851853
weak! {
852854
fn utimensat(
853855
c::c_int,
854-
*const c::c_char,
856+
*const ffi::c_char,
855857
*const c::timespec,
856858
c::c_int
857859
) -> c::c_int
858860
}
859861
extern "C" {
860862
fn setattrlist(
861-
path: *const c::c_char,
863+
path: *const ffi::c_char,
862864
attr_list: *const Attrlist,
863865
attr_buf: *const c::c_void,
864866
attr_buf_size: c::size_t,
@@ -1045,7 +1047,7 @@ pub(crate) fn chmodat(
10451047
syscall! {
10461048
fn fchmodat(
10471049
base_dirfd: c::c_int,
1048-
pathname: *const c::c_char,
1050+
pathname: *const ffi::c_char,
10491051
mode: c::mode_t
10501052
) via SYS_fchmodat -> c::c_int
10511053
}
@@ -1075,7 +1077,7 @@ pub(crate) fn fclonefileat(
10751077
fn fclonefileat(
10761078
srcfd: BorrowedFd<'_>,
10771079
dst_dirfd: BorrowedFd<'_>,
1078-
dst: *const c::c_char,
1080+
dst: *const ffi::c_char,
10791081
flags: c::c_int
10801082
) via SYS_fclonefileat -> c::c_int
10811083
}
@@ -1714,15 +1716,15 @@ pub(crate) fn memfd_create(name: &CStr, flags: MemfdFlags) -> io::Result<OwnedFd
17141716
#[cfg(target_os = "freebsd")]
17151717
weakcall! {
17161718
fn memfd_create(
1717-
name: *const c::c_char,
1719+
name: *const ffi::c_char,
17181720
flags: c::c_uint
17191721
) -> c::c_int
17201722
}
17211723

17221724
#[cfg(linux_kernel)]
17231725
weak_or_syscall! {
17241726
fn memfd_create(
1725-
name: *const c::c_char,
1727+
name: *const ffi::c_char,
17261728
flags: c::c_uint
17271729
) via SYS_memfd_create -> c::c_int
17281730
}
@@ -1743,7 +1745,7 @@ pub(crate) fn openat2(
17431745
syscall! {
17441746
fn openat2(
17451747
base_dirfd: c::c_int,
1746-
pathname: *const c::c_char,
1748+
pathname: *const ffi::c_char,
17471749
how: *mut open_how,
17481750
size: usize
17491751
) via SYS_OPENAT2 -> c::c_int
@@ -1911,12 +1913,12 @@ fn stat64_to_stat(s64: c::stat64) -> io::Result<Stat> {
19111913
#[cfg(linux_kernel)]
19121914
#[allow(non_upper_case_globals)]
19131915
mod sys {
1914-
use super::{c, BorrowedFd, Statx};
1916+
use super::{c, ffi, BorrowedFd, Statx};
19151917

19161918
weak_or_syscall! {
19171919
pub(super) fn statx(
19181920
dirfd_: BorrowedFd<'_>,
1919-
path: *const c::c_char,
1921+
path: *const ffi::c_char,
19201922
flags: c::c_int,
19211923
mask: c::c_uint,
19221924
buf: *mut Statx
@@ -2443,7 +2445,7 @@ pub(crate) fn fsetxattr(
24432445
}
24442446

24452447
#[cfg(any(apple, linux_kernel, target_os = "hurd"))]
2446-
pub(crate) fn listxattr(path: &CStr, list: &mut [c::c_char]) -> io::Result<usize> {
2448+
pub(crate) fn listxattr(path: &CStr, list: &mut [ffi::c_char]) -> io::Result<usize> {
24472449
#[cfg(not(apple))]
24482450
unsafe {
24492451
ret_usize(c::listxattr(path.as_ptr(), list.as_mut_ptr(), list.len()))
@@ -2461,7 +2463,7 @@ pub(crate) fn listxattr(path: &CStr, list: &mut [c::c_char]) -> io::Result<usize
24612463
}
24622464

24632465
#[cfg(any(apple, linux_kernel, target_os = "hurd"))]
2464-
pub(crate) fn llistxattr(path: &CStr, list: &mut [c::c_char]) -> io::Result<usize> {
2466+
pub(crate) fn llistxattr(path: &CStr, list: &mut [ffi::c_char]) -> io::Result<usize> {
24652467
#[cfg(not(apple))]
24662468
unsafe {
24672469
ret_usize(c::llistxattr(path.as_ptr(), list.as_mut_ptr(), list.len()))
@@ -2479,7 +2481,7 @@ pub(crate) fn llistxattr(path: &CStr, list: &mut [c::c_char]) -> io::Result<usiz
24792481
}
24802482

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

24852487
#[cfg(not(apple))]

src/backend/libc/fs/types.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::backend::c;
2+
use crate::ffi;
23
use bitflags::bitflags;
34

45
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
@@ -8,7 +9,7 @@ bitflags! {
89
/// [`accessat`]: fn.accessat.html
910
#[repr(transparent)]
1011
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
11-
pub struct Access: c::c_int {
12+
pub struct Access: ffi::c_int {
1213
/// `R_OK`
1314
const READ_OK = c::R_OK;
1415

@@ -379,7 +380,7 @@ bitflags! {
379380
/// [`fcopyfile`]: crate::fs::fcopyfile
380381
#[repr(transparent)]
381382
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
382-
pub struct CopyfileFlags: c::c_uint {
383+
pub struct CopyfileFlags: ffi::c_uint {
383384
/// `COPYFILE_ACL`
384385
const ACL = copyfile::ACL;
385386

@@ -444,7 +445,7 @@ bitflags! {
444445
/// [`renameat_with`]: crate::fs::renameat_with
445446
#[repr(transparent)]
446447
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
447-
pub struct RenameFlags: c::c_uint {
448+
pub struct RenameFlags: ffi::c_uint {
448449
/// `RENAME_EXCHANGE`
449450
const EXCHANGE = bitcast!(c::RENAME_EXCHANGE);
450451

@@ -599,7 +600,7 @@ bitflags! {
599600
/// [`memfd_create`]: crate::fs::memfd_create
600601
#[repr(transparent)]
601602
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
602-
pub struct MemfdFlags: c::c_uint {
603+
pub struct MemfdFlags: ffi::c_uint {
603604
/// `MFD_CLOEXEC`
604605
const CLOEXEC = c::MFD_CLOEXEC;
605606

@@ -1161,15 +1162,15 @@ pub type RawMode = c::mode_t;
11611162

11621163
/// `mode_t`
11631164
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
1164-
pub type RawMode = c::c_uint;
1165+
pub type RawMode = ffi::c_uint;
11651166

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

11701171
/// `dev_t`
11711172
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
1172-
pub type Dev = c::c_ulonglong;
1173+
pub type Dev = ffi::c_ulonglong;
11731174

11741175
/// `__fsword_t`
11751176
#[cfg(all(

src/backend/libc/mount/types.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::backend::c;
2+
use crate::ffi;
23
use bitflags::bitflags;
34

45
#[cfg(linux_kernel)]
@@ -8,7 +9,7 @@ bitflags! {
89
/// [`mount`]: crate::mount::mount
910
#[repr(transparent)]
1011
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
11-
pub struct MountFlags: c::c_ulong {
12+
pub struct MountFlags: ffi::c_ulong {
1213
/// `MS_BIND`
1314
const BIND = c::MS_BIND;
1415

@@ -90,7 +91,7 @@ bitflags! {
9091
/// [`fsopen`]: crate::mount::fsopen
9192
#[repr(transparent)]
9293
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
93-
pub struct FsOpenFlags: c::c_uint {
94+
pub struct FsOpenFlags: ffi::c_uint {
9495
/// `FSOPEN_CLOEXEC`
9596
const FSOPEN_CLOEXEC = 0x0000_0001;
9697

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

@@ -155,7 +156,7 @@ bitflags! {
155156
/// [`fsmount`]: crate::mount::fsmount
156157
#[repr(transparent)]
157158
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
158-
pub struct MountAttrFlags: c::c_uint {
159+
pub struct MountAttrFlags: ffi::c_uint {
159160
/// `MOUNT_ATTR_RDONLY`
160161
const MOUNT_ATTR_RDONLY = 0x0000_0001;
161162

@@ -205,7 +206,7 @@ bitflags! {
205206
/// [`move_mount`]: crate::mount::move_mount
206207
#[repr(transparent)]
207208
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
208-
pub struct MoveMountFlags: c::c_uint {
209+
pub struct MoveMountFlags: ffi::c_uint {
209210
/// `MOVE_MOUNT_F_EMPTY_PATH`
210211
const MOVE_MOUNT_F_SYMLINKS = 0x0000_0001;
211212

@@ -246,7 +247,7 @@ bitflags! {
246247
/// [`open_tree`]: crate::mount::open_tree
247248
#[repr(transparent)]
248249
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
249-
pub struct OpenTreeFlags: c::c_uint {
250+
pub struct OpenTreeFlags: ffi::c_uint {
250251
/// `OPENTREE_CLONE`
251252
const OPEN_TREE_CLONE = 1;
252253

@@ -278,7 +279,7 @@ bitflags! {
278279
/// [`fspick`]: crate::mount::fspick
279280
#[repr(transparent)]
280281
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
281-
pub struct FsPickFlags: c::c_uint {
282+
pub struct FsPickFlags: ffi::c_uint {
282283
/// `FSPICK_CLOEXEC`
283284
const FSPICK_CLOEXEC = 0x0000_0001;
284285

@@ -303,7 +304,7 @@ bitflags! {
303304
/// [`mount_change`]: crate::mount::mount_change
304305
#[repr(transparent)]
305306
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
306-
pub struct MountPropagationFlags: c::c_ulong {
307+
pub struct MountPropagationFlags: ffi::c_ulong {
307308
/// `MS_SILENT`
308309
const SILENT = c::MS_SILENT;
309310
/// `MS_SHARED`

0 commit comments

Comments
 (0)