Skip to content

Commit b610483

Browse files
authored
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>
1 parent 1efd93c commit b610483

25 files changed

+93
-61
lines changed

src/backend/libc/event/epoll.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ use crate::backend::c;
7474
use crate::backend::conv::ret_u32;
7575
use crate::backend::conv::{ret, ret_owned_fd};
7676
use crate::fd::{AsFd, AsRawFd, OwnedFd};
77+
use crate::ffi;
7778
use crate::io;
7879
use crate::utils::as_mut_ptr;
7980
#[cfg(feature = "alloc")]
@@ -262,7 +263,7 @@ pub fn delete(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> {
262263
/// success, this returns the number of written elements.
263264
#[cfg(feature = "alloc")]
264265
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
265-
pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: c::c_int) -> io::Result<()> {
266+
pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: ffi::c_int) -> io::Result<()> {
266267
// SAFETY: We're calling `epoll_wait` via FFI and we know how it
267268
// behaves.
268269
unsafe {

src/backend/libc/event/poll_fd.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::backend::c;
22
use crate::backend::conv::borrowed_fd;
33
use crate::backend::fd::{AsFd, AsRawFd, BorrowedFd, LibcFd};
4+
use crate::ffi;
45
use bitflags::bitflags;
56
use core::marker::PhantomData;
67
#[cfg(windows)]
@@ -15,7 +16,7 @@ bitflags! {
1516
/// [`poll`]: crate::event::poll
1617
#[repr(transparent)]
1718
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
18-
pub struct PollFlags: c::c_short {
19+
pub struct PollFlags: ffi::c_short {
1920
/// `POLLIN`
2021
const IN = c::POLLIN;
2122
/// `POLLPRI`

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

@@ -370,7 +371,7 @@ bitflags! {
370371
/// [`fcopyfile`]: crate::fs::fcopyfile
371372
#[repr(transparent)]
372373
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
373-
pub struct CopyfileFlags: c::c_uint {
374+
pub struct CopyfileFlags: ffi::c_uint {
374375
/// `COPYFILE_ACL`
375376
const ACL = copyfile::ACL;
376377

@@ -435,7 +436,7 @@ bitflags! {
435436
/// [`renameat_with`]: crate::fs::renameat_with
436437
#[repr(transparent)]
437438
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
438-
pub struct RenameFlags: c::c_uint {
439+
pub struct RenameFlags: ffi::c_uint {
439440
/// `RENAME_EXCHANGE`
440441
const EXCHANGE = bitcast!(c::RENAME_EXCHANGE);
441442

@@ -590,7 +591,7 @@ bitflags! {
590591
/// [`memfd_create`]: crate::fs::memfd_create
591592
#[repr(transparent)]
592593
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
593-
pub struct MemfdFlags: c::c_uint {
594+
pub struct MemfdFlags: ffi::c_uint {
594595
/// `MFD_CLOEXEC`
595596
const CLOEXEC = c::MFD_CLOEXEC;
596597

@@ -1110,15 +1111,15 @@ pub type RawMode = c::mode_t;
11101111

11111112
/// `mode_t`
11121113
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
1113-
pub type RawMode = c::c_uint;
1114+
pub type RawMode = ffi::c_uint;
11141115

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

11191120
/// `dev_t`
11201121
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
1121-
pub type Dev = c::c_ulonglong;
1122+
pub type Dev = ffi::c_ulonglong;
11221123

11231124
/// `__fsword_t`
11241125
#[cfg(all(

src/backend/libc/pipe/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(linux_kernel)]
22
use core::marker::PhantomData;
33
#[cfg(not(any(apple, target_os = "wasi")))]
4-
use {crate::backend::c, bitflags::bitflags};
4+
use {crate::backend::c, crate::ffi, bitflags::bitflags};
55

66
#[cfg(not(any(apple, target_os = "wasi")))]
77
bitflags! {
@@ -38,7 +38,7 @@ bitflags! {
3838
/// [`tee`].
3939
#[repr(transparent)]
4040
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
41-
pub struct SpliceFlags: c::c_uint {
41+
pub struct SpliceFlags: ffi::c_uint {
4242
/// `SPLICE_F_MOVE`
4343
const MOVE = c::SPLICE_F_MOVE;
4444
/// `SPLICE_F_NONBLOCK`

src/backend/libc/termios/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pub(crate) mod syscalls;
2+
pub(crate) mod types;

src/backend/libc/termios/types.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#[cfg(not(target_os = "redox"))]
2+
use crate::ffi;
3+
4+
// We don't want to use tcflag_t directly so we don't expose libc
5+
// publicly. Redox uses u32, apple uses c_ulong, everything else
6+
// seems to use c_uint.
7+
8+
#[cfg(apple)]
9+
pub type tcflag_t = ffi::c_ulong;
10+
#[cfg(target_os = "redox")]
11+
pub type tcflag_t = u32;
12+
#[cfg(not(any(apple, target_os = "redox")))]
13+
pub type tcflag_t = ffi::c_uint;

src/backend/linux_raw/event/epoll.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@
7171
7272
#![allow(unsafe_code)]
7373

74-
use crate::backend::c;
7574
use crate::backend::event::syscalls;
7675
use crate::fd::{AsFd, AsRawFd, OwnedFd};
76+
use crate::ffi;
7777
use crate::io;
7878
#[cfg(feature = "alloc")]
7979
use alloc::vec::Vec;
@@ -86,7 +86,7 @@ bitflags! {
8686
/// `EPOLL_*` for use with [`new`].
8787
#[repr(transparent)]
8888
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
89-
pub struct CreateFlags: c::c_uint {
89+
pub struct CreateFlags: ffi::c_uint {
9090
/// `EPOLL_CLOEXEC`
9191
const CLOEXEC = linux_raw_sys::general::EPOLL_CLOEXEC;
9292

@@ -242,7 +242,7 @@ pub fn delete(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> {
242242
#[cfg(feature = "alloc")]
243243
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
244244
#[inline]
245-
pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: c::c_int) -> io::Result<()> {
245+
pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: ffi::c_int) -> io::Result<()> {
246246
// SAFETY: We're calling `epoll_wait` via FFI and we know how it
247247
// behaves.
248248
unsafe {
@@ -463,6 +463,8 @@ impl<'a> IntoIterator for &'a EventVec {
463463

464464
#[test]
465465
fn test_epoll_layouts() {
466+
use crate::backend::c;
467+
466468
check_renamed_type!(Event, epoll_event);
467469
check_renamed_type!(Event, epoll_event);
468470
check_renamed_struct_renamed_field!(Event, epoll_event, flags, events);

src/backend/linux_raw/event/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::backend::c;
1+
use crate::ffi;
22
use bitflags::bitflags;
33

44
bitflags! {
@@ -7,7 +7,7 @@ bitflags! {
77
/// [`eventfd`]: crate::event::eventfd
88
#[repr(transparent)]
99
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
10-
pub struct EventfdFlags: c::c_uint {
10+
pub struct EventfdFlags: ffi::c_uint {
1111
/// `EFD_CLOEXEC`
1212
const CLOEXEC = linux_raw_sys::general::EFD_CLOEXEC;
1313
/// `EFD_NONBLOCK`

src/backend/linux_raw/fs/inotify.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! inotify support for working with inotifies
22
3-
use crate::backend::c;
43
use crate::backend::fs::syscalls;
54
use crate::fd::{BorrowedFd, OwnedFd};
5+
use crate::ffi;
66
use crate::io;
77
use bitflags::bitflags;
88

@@ -12,7 +12,7 @@ bitflags! {
1212
/// [`inotify_init`]: crate::fs::inotify::inotify_init
1313
#[repr(transparent)]
1414
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
15-
pub struct CreateFlags: c::c_uint {
15+
pub struct CreateFlags: ffi::c_uint {
1616
/// `IN_CLOEXEC`
1717
const CLOEXEC = linux_raw_sys::general::IN_CLOEXEC;
1818
/// `IN_NONBLOCK`
@@ -29,7 +29,7 @@ bitflags! {
2929
/// [`inotify_add_watch`]: crate::fs::inotify::inotify_add_watch
3030
#[repr(transparent)]
3131
#[derive(Default, Copy, Clone, Eq, PartialEq, Hash, Debug)]
32-
pub struct WatchFlags: c::c_uint {
32+
pub struct WatchFlags: ffi::c_uint {
3333
/// `IN_ACCESS`
3434
const ACCESS = linux_raw_sys::general::IN_ACCESS;
3535
/// `IN_ATTRIB`

src/backend/linux_raw/fs/types.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::backend::c;
1+
use crate::ffi;
22
use bitflags::bitflags;
33

44
bitflags! {
@@ -7,7 +7,7 @@ bitflags! {
77
/// [`accessat`]: fn.accessat.html
88
#[repr(transparent)]
99
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
10-
pub struct Access: c::c_uint {
10+
pub struct Access: ffi::c_uint {
1111
/// `R_OK`
1212
const READ_OK = linux_raw_sys::general::R_OK;
1313

@@ -33,7 +33,7 @@ bitflags! {
3333
/// [`statat`]: crate::fs::statat
3434
#[repr(transparent)]
3535
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
36-
pub struct AtFlags: c::c_uint {
36+
pub struct AtFlags: ffi::c_uint {
3737
/// `AT_SYMLINK_NOFOLLOW`
3838
const SYMLINK_NOFOLLOW = linux_raw_sys::general::AT_SYMLINK_NOFOLLOW;
3939

@@ -172,7 +172,7 @@ bitflags! {
172172
/// [`openat`]: crate::fs::openat
173173
#[repr(transparent)]
174174
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
175-
pub struct OFlags: c::c_uint {
175+
pub struct OFlags: ffi::c_uint {
176176
/// `O_ACCMODE`
177177
const ACCMODE = linux_raw_sys::general::O_ACCMODE;
178178

@@ -291,7 +291,7 @@ bitflags! {
291291
/// [`renameat_with`]: crate::fs::renameat_with
292292
#[repr(transparent)]
293293
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
294-
pub struct RenameFlags: c::c_uint {
294+
pub struct RenameFlags: ffi::c_uint {
295295
/// `RENAME_EXCHANGE`
296296
const EXCHANGE = linux_raw_sys::general::RENAME_EXCHANGE;
297297

@@ -418,7 +418,7 @@ bitflags! {
418418
/// [`memfd_create`]: crate::fs::memfd_create
419419
#[repr(transparent)]
420420
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
421-
pub struct MemfdFlags: c::c_uint {
421+
pub struct MemfdFlags: ffi::c_uint {
422422
/// `MFD_CLOEXEC`
423423
const CLOEXEC = linux_raw_sys::general::MFD_CLOEXEC;
424424

@@ -724,7 +724,7 @@ pub type RawMode = linux_raw_sys::general::__kernel_mode_t;
724724
target_arch = "arm",
725725
))]
726726
// Don't use `__kernel_mode_t` since it's `u16` which differs from `st_size`.
727-
pub type RawMode = c::c_uint;
727+
pub type RawMode = ffi::c_uint;
728728

729729
/// `dev_t`
730730
// Within the kernel the dev_t is 32-bit, but userspace uses a 64-bit field.

src/backend/linux_raw/io/types.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::backend::c;
1+
use crate::ffi;
22
use bitflags::bitflags;
33

44
bitflags! {
@@ -8,7 +8,7 @@ bitflags! {
88
/// [`fcntl_setfd`]: crate::io::fcntl_setfd
99
#[repr(transparent)]
1010
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
11-
pub struct FdFlags: c::c_uint {
11+
pub struct FdFlags: ffi::c_uint {
1212
/// `FD_CLOEXEC`
1313
const CLOEXEC = linux_raw_sys::general::FD_CLOEXEC;
1414

@@ -24,7 +24,7 @@ bitflags! {
2424
/// [`pwritev2`]: crate::io::pwritev
2525
#[repr(transparent)]
2626
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
27-
pub struct ReadWriteFlags: c::c_uint {
27+
pub struct ReadWriteFlags: ffi::c_uint {
2828
/// `RWF_DSYNC` (since Linux 4.7)
2929
const DSYNC = linux_raw_sys::general::RWF_DSYNC;
3030
/// `RWF_HIPRI` (since Linux 4.6)
@@ -47,7 +47,7 @@ bitflags! {
4747
/// [`dup2`]: crate::io::dup2
4848
#[repr(transparent)]
4949
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
50-
pub struct DupFlags: c::c_uint {
50+
pub struct DupFlags: ffi::c_uint {
5151
/// `O_CLOEXEC`
5252
const CLOEXEC = linux_raw_sys::general::O_CLOEXEC;
5353

src/backend/linux_raw/mm/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::backend::c;
1+
use crate::ffi;
22
use bitflags::bitflags;
33

44
bitflags! {
@@ -252,7 +252,7 @@ bitflags! {
252252
/// [`userfaultfd`]: crate::mm::userfaultfd
253253
#[repr(transparent)]
254254
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
255-
pub struct UserfaultfdFlags: c::c_uint {
255+
pub struct UserfaultfdFlags: ffi::c_uint {
256256
/// `O_CLOEXEC`
257257
const CLOEXEC = linux_raw_sys::general::O_CLOEXEC;
258258
/// `O_NONBLOCK`

src/backend/linux_raw/pipe/types.rs

+5-4
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
use core::marker::PhantomData;
45

@@ -8,7 +9,7 @@ bitflags! {
89
/// [`pipe_with`]: crate::pipe::pipe_with
910
#[repr(transparent)]
1011
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
11-
pub struct PipeFlags: c::c_uint {
12+
pub struct PipeFlags: ffi::c_uint {
1213
/// `O_CLOEXEC`
1314
const CLOEXEC = linux_raw_sys::general::O_CLOEXEC;
1415
/// `O_DIRECT`
@@ -26,7 +27,7 @@ bitflags! {
2627
/// [`tee`].
2728
#[repr(transparent)]
2829
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
29-
pub struct SpliceFlags: c::c_uint {
30+
pub struct SpliceFlags: ffi::c_uint {
3031
/// `SPLICE_F_MOVE`
3132
const MOVE = linux_raw_sys::general::SPLICE_F_MOVE;
3233
/// `SPLICE_F_NONBLOCK`
@@ -60,7 +61,7 @@ impl<'a> IoSliceRaw<'a> {
6061
pub fn from_slice(buf: &'a [u8]) -> Self {
6162
IoSliceRaw {
6263
_buf: c::iovec {
63-
iov_base: (buf.as_ptr() as *mut u8).cast::<c::c_void>(),
64+
iov_base: (buf.as_ptr() as *mut u8).cast::<ffi::c_void>(),
6465
iov_len: buf.len() as _,
6566
},
6667
_lifetime: PhantomData,
@@ -71,7 +72,7 @@ impl<'a> IoSliceRaw<'a> {
7172
pub fn from_slice_mut(buf: &'a mut [u8]) -> Self {
7273
IoSliceRaw {
7374
_buf: c::iovec {
74-
iov_base: buf.as_mut_ptr().cast::<c::c_void>(),
75+
iov_base: buf.as_mut_ptr().cast::<ffi::c_void>(),
7576
iov_len: buf.len() as _,
7677
},
7778
_lifetime: PhantomData,

src/backend/linux_raw/shm/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::backend::c;
1+
use crate::ffi;
22
use bitflags::bitflags;
33

44
bitflags! {
@@ -7,7 +7,7 @@ bitflags! {
77
/// [`shm_open`]: crate:shm::shm_open
88
#[repr(transparent)]
99
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
10-
pub struct ShmOFlags: c::c_uint {
10+
pub struct ShmOFlags: ffi::c_uint {
1111
/// `O_CREAT`
1212
#[doc(alias = "CREAT")]
1313
const CREATE = linux_raw_sys::general::O_CREAT;

src/backend/linux_raw/termios/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pub(crate) mod syscalls;
2+
pub(crate) mod types;
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use crate::ffi;
2+
3+
// We don't want to use tcflag_t directly so we don't expose linux_raw_sys
4+
// publicly. It appears to be c_ulong on SPARC and c_uint everywhere else.
5+
6+
#[cfg(target_arch = "sparc")]
7+
pub type tcflag_t = ffi::c_ulong;
8+
#[cfg(not(target_arch = "sparc"))]
9+
pub type tcflag_t = ffi::c_uint;

0 commit comments

Comments
 (0)