Skip to content

Commit

Permalink
Patch low-hanging fruit semver removals for libc and linux-raw-sys (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>

* 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 <[email protected]>

---------

Signed-off-by: John Nunley <[email protected]>
  • Loading branch information
notgull authored and sunfishcode committed Aug 26, 2024
1 parent c5529aa commit e9ac49a
Show file tree
Hide file tree
Showing 25 changed files with 95 additions and 59 deletions.
3 changes: 2 additions & 1 deletion src/backend/libc/event/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ use crate::backend::c;
use crate::backend::conv::ret_u32;
use crate::backend::conv::{ret, ret_owned_fd};
use crate::fd::{AsFd, AsRawFd, OwnedFd};
use crate::ffi;
use crate::io;
use crate::utils::as_mut_ptr;
#[cfg(feature = "alloc")]
Expand Down Expand Up @@ -287,7 +288,7 @@ pub fn delete(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> {
/// [Linux]: https://man7.org/linux/man-pages/man2/epoll_wait.2.html
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: c::c_int) -> io::Result<()> {
pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: ffi::c_int) -> io::Result<()> {
// SAFETY: We're calling `epoll_wait` via FFI and we know how it
// behaves.
unsafe {
Expand Down
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
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
4 changes: 2 additions & 2 deletions src/backend/libc/pipe/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(linux_kernel)]
use core::marker::PhantomData;
#[cfg(not(any(apple, target_os = "wasi")))]
use {crate::backend::c, bitflags::bitflags};
use {crate::backend::c, crate::ffi, bitflags::bitflags};

#[cfg(not(any(apple, target_os = "wasi")))]
bitflags! {
Expand Down Expand Up @@ -43,7 +43,7 @@ bitflags! {
/// [`tee`]: crate::pipe::tee
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct SpliceFlags: c::c_uint {
pub struct SpliceFlags: ffi::c_uint {
/// `SPLICE_F_MOVE`
const MOVE = c::SPLICE_F_MOVE;
/// `SPLICE_F_NONBLOCK`
Expand Down
1 change: 1 addition & 0 deletions src/backend/libc/termios/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub(crate) mod syscalls;
pub(crate) mod types;
13 changes: 13 additions & 0 deletions src/backend/libc/termios/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[cfg(not(target_os = "redox"))]
use crate::ffi;

// We don't want to use tcflag_t directly so we don't expose libc
// publicly. Redox uses u32, apple uses c_ulong, everything else
// seems to use c_uint.

#[cfg(apple)]
pub type tcflag_t = ffi::c_ulong;
#[cfg(target_os = "redox")]
pub type tcflag_t = u32;
#[cfg(not(any(apple, target_os = "redox")))]
pub type tcflag_t = ffi::c_uint;
8 changes: 5 additions & 3 deletions src/backend/linux_raw/event/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@

#![allow(unsafe_code)]

use crate::backend::c;
use crate::backend::event::syscalls;
use crate::fd::{AsFd, AsRawFd, OwnedFd};
use crate::ffi;
use crate::io;
#[cfg(feature = "alloc")]
use alloc::vec::Vec;
Expand All @@ -86,7 +86,7 @@ bitflags! {
/// `EPOLL_*` for use with [`create`].
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct CreateFlags: c::c_uint {
pub struct CreateFlags: ffi::c_uint {
/// `EPOLL_CLOEXEC`
const CLOEXEC = linux_raw_sys::general::EPOLL_CLOEXEC;

Expand Down Expand Up @@ -267,7 +267,7 @@ pub fn delete(epoll: impl AsFd, source: impl AsFd) -> io::Result<()> {
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc"), alias = "epoll_wait"))]
#[inline]
pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: c::c_int) -> io::Result<()> {
pub fn wait(epoll: impl AsFd, event_list: &mut EventVec, timeout: ffi::c_int) -> io::Result<()> {
// SAFETY: We're calling `epoll_wait` via FFI and we know how it
// behaves.
unsafe {
Expand Down Expand Up @@ -493,6 +493,8 @@ impl<'a> IntoIterator for &'a EventVec {

#[test]
fn test_epoll_layouts() {
use crate::backend::c;

check_renamed_type!(Event, epoll_event);
check_renamed_type!(Event, epoll_event);
check_renamed_struct_renamed_field!(Event, epoll_event, flags, events);
Expand Down
4 changes: 2 additions & 2 deletions src/backend/linux_raw/event/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::backend::c;
use crate::ffi;
use bitflags::bitflags;

bitflags! {
Expand All @@ -7,7 +7,7 @@ bitflags! {
/// [`eventfd`]: crate::event::eventfd
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct EventfdFlags: c::c_uint {
pub struct EventfdFlags: ffi::c_uint {
/// `EFD_CLOEXEC`
const CLOEXEC = linux_raw_sys::general::EFD_CLOEXEC;
/// `EFD_NONBLOCK`
Expand Down
5 changes: 3 additions & 2 deletions src/backend/linux_raw/fs/inotify.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! inotify support for working with inotifies

use crate::backend::c;
use crate::ffi;
use bitflags::bitflags;

bitflags! {
Expand All @@ -9,7 +10,7 @@ bitflags! {
/// [`inotify_init`]: crate::fs::inotify::inotify_init
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct CreateFlags: c::c_uint {
pub struct CreateFlags: ffi::c_uint {
/// `IN_CLOEXEC`
const CLOEXEC = linux_raw_sys::general::IN_CLOEXEC;
/// `IN_NONBLOCK`
Expand All @@ -26,7 +27,7 @@ bitflags! {
/// [`inotify_add_watch`]: crate::fs::inotify::inotify_add_watch
#[repr(transparent)]
#[derive(Default, Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct WatchFlags: c::c_uint {
pub struct WatchFlags: ffi::c_uint {
/// `IN_ACCESS`
const ACCESS = linux_raw_sys::general::IN_ACCESS;
/// `IN_ATTRIB`
Expand Down
14 changes: 7 additions & 7 deletions src/backend/linux_raw/fs/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::backend::c;
use crate::ffi;
use bitflags::bitflags;

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

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

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

Expand Down Expand Up @@ -298,7 +298,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 = linux_raw_sys::general::RENAME_EXCHANGE;

Expand Down Expand Up @@ -425,7 +425,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 = linux_raw_sys::general::MFD_CLOEXEC;

Expand Down Expand Up @@ -739,7 +739,7 @@ pub type RawMode = linux_raw_sys::general::__kernel_mode_t;
target_arch = "arm",
))]
// Don't use `__kernel_mode_t` since it's `u16` which differs from `st_size`.
pub type RawMode = c::c_uint;
pub type RawMode = ffi::c_uint;

/// `dev_t`
// Within the kernel the `dev_t` is 32-bit, but userspace uses a 64-bit field.
Expand Down
8 changes: 4 additions & 4 deletions src/backend/linux_raw/io/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::backend::c;
use crate::ffi;
use bitflags::bitflags;

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

Expand All @@ -24,7 +24,7 @@ bitflags! {
/// [`pwritev2`]: crate::io::pwritev
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct ReadWriteFlags: c::c_uint {
pub struct ReadWriteFlags: ffi::c_uint {
/// `RWF_DSYNC` (since Linux 4.7)
const DSYNC = linux_raw_sys::general::RWF_DSYNC;
/// `RWF_HIPRI` (since Linux 4.6)
Expand All @@ -47,7 +47,7 @@ bitflags! {
/// [`dup2`]: crate::io::dup2
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct DupFlags: c::c_uint {
pub struct DupFlags: ffi::c_uint {
/// `O_CLOEXEC`
const CLOEXEC = linux_raw_sys::general::O_CLOEXEC;

Expand Down
3 changes: 2 additions & 1 deletion src/backend/linux_raw/mm/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;

bitflags! {
Expand Down Expand Up @@ -254,7 +255,7 @@ bitflags! {
/// [`userfaultfd`]: crate::mm::userfaultfd
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct UserfaultfdFlags: c::c_uint {
pub struct UserfaultfdFlags: ffi::c_uint {
/// `O_CLOEXEC`
const CLOEXEC = linux_raw_sys::general::O_CLOEXEC;
/// `O_NONBLOCK`
Expand Down
9 changes: 5 additions & 4 deletions src/backend/linux_raw/pipe/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;
use core::marker::PhantomData;

Expand All @@ -8,7 +9,7 @@ bitflags! {
/// [`pipe_with`]: crate::pipe::pipe_with
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct PipeFlags: c::c_uint {
pub struct PipeFlags: ffi::c_uint {
/// `O_CLOEXEC`
const CLOEXEC = linux_raw_sys::general::O_CLOEXEC;
/// `O_DIRECT`
Expand All @@ -30,7 +31,7 @@ bitflags! {
/// [`tee`]: crate::pipe::tee
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct SpliceFlags: c::c_uint {
pub struct SpliceFlags: ffi::c_uint {
/// `SPLICE_F_MOVE`
const MOVE = linux_raw_sys::general::SPLICE_F_MOVE;
/// `SPLICE_F_NONBLOCK`
Expand Down Expand Up @@ -64,7 +65,7 @@ impl<'a> IoSliceRaw<'a> {
pub fn from_slice(buf: &'a [u8]) -> Self {
IoSliceRaw {
_buf: c::iovec {
iov_base: (buf.as_ptr() as *mut u8).cast::<c::c_void>(),
iov_base: (buf.as_ptr() as *mut u8).cast::<ffi::c_void>(),
iov_len: buf.len() as _,
},
_lifetime: PhantomData,
Expand All @@ -75,7 +76,7 @@ impl<'a> IoSliceRaw<'a> {
pub fn from_slice_mut(buf: &'a mut [u8]) -> Self {
IoSliceRaw {
_buf: c::iovec {
iov_base: buf.as_mut_ptr().cast::<c::c_void>(),
iov_base: buf.as_mut_ptr().cast::<ffi::c_void>(),
iov_len: buf.len() as _,
},
_lifetime: PhantomData,
Expand Down
4 changes: 2 additions & 2 deletions src/backend/linux_raw/shm/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::backend::c;
use crate::ffi;
use bitflags::bitflags;

bitflags! {
Expand All @@ -7,7 +7,7 @@ bitflags! {
/// [`shm_open`]: crate:shm::shm_open
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct ShmOFlags: c::c_uint {
pub struct ShmOFlags: ffi::c_uint {
/// `O_CREAT`
#[doc(alias = "CREAT")]
const CREATE = linux_raw_sys::general::O_CREAT;
Expand Down
1 change: 1 addition & 0 deletions src/backend/linux_raw/termios/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub(crate) mod syscalls;
pub(crate) mod types;
11 changes: 11 additions & 0 deletions src/backend/linux_raw/termios/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![allow(non_camel_case_types)]

use crate::ffi;

// We don't want to use tcflag_t directly so we don't expose linux_raw_sys
// publicly. It appears to be c_ulong on SPARC and c_uint everywhere else.

#[cfg(target_arch = "sparc")]
pub type tcflag_t = ffi::c_ulong;
#[cfg(not(target_arch = "sparc"))]
pub type tcflag_t = ffi::c_uint;
Loading

0 comments on commit e9ac49a

Please sign in to comment.