Skip to content

Commit 8c06468

Browse files
authored
Tidy up the public re-exports. (#1352)
Remove the re-exports of `fcntl_getfd`, `fcntl_setfd`, and `fcntl_dupfd_cloexec` from `rustix::fs`. They're now in `rustix::io` only. And remove the re-exports of the futex `Flags`, `OWNER_DIED`, and `WAITERS` in the top-level `rustix::thread` module. They're now in `rustix::thread::futex` only. Also, tidy up more comments, add a wait test, and remove the `rustix_` prefix on functions that don't need to be prefixed.
1 parent 9eb1102 commit 8c06468

19 files changed

Lines changed: 79 additions & 72 deletions

File tree

CHANGES.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,15 @@ pointer provenance.
243243
[`sigmask`]: https://docs.rs/rustix/1.0.0/rustix/io_uring/struct.io_uring_getevents_arg.html#structfield.sigmask
244244
[`ts`]: https://docs.rs/rustix/1.0.0/rustix/io_uring/struct.io_uring_getevents_arg.html#structfield.ts
245245
[`rustix::io_uring::getevents_arg`]: https://docs.rs/rustix/1.0.0/rustix/io_uring/struct.io_uring_getevents_arg.html
246-
[`rustix::io_uring::io_uring_ptr`]: https://docs.rs/rustix/1.0.0-prerelease.0/rustix/io_uring/struct.io_uring_ptr.html
246+
[`rustix::io_uring::io_uring_ptr`]: https://docs.rs/rustix/1.0.0/rustix/io_uring/struct.io_uring_ptr.html
247+
248+
The aliases for [`fcntl_dupfd_cloexec`], [`fcntl_getfd`], and [`fcntl_setfd`]
249+
in `rustix::fs` are removed; these functions are just available in
250+
`rustix::io` now.
251+
252+
[`fcntl_dupfd_cloexec`]: https://docs.rs/rustix/1.0.0/rustix/io/fn.fcntl_dupfd_cloexec.html
253+
[`fcntl_getfd`]: https://docs.rs/rustix/1.0.0/rustix/io/fn.fcntl_getfd.html
254+
[`fcntl_setfd`]: https://docs.rs/rustix/1.0.0/rustix/io/fn.fcntl_setfd.html
247255

248256
[`SocketAddrXdp`] no longer has a shared umem field. A new
249257
[`SocketAddrXdpWithSharedUmem`] is added for the purpose of calling `bind` and

src/backend/libc/fs/syscalls.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,9 @@ pub(crate) fn renameat2(
590590
flags.bits(),
591591
));
592592
}
593-
// Otherwise, see if we can use rename. There's no point in trying `renamex_np`
594-
// because it was added in the same macOS release as `renameatx_np`.
593+
// Otherwise, see if we can use `rename`. There's no point in trying
594+
// `renamex_np` because it was added in the same macOS release as
595+
// `renameatx_np`.
595596
if !flags.is_empty()
596597
|| borrowed_fd(old_dirfd) != c::AT_FDCWD
597598
|| borrowed_fd(new_dirfd) != c::AT_FDCWD

src/backend/libc/thread/syscalls.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,7 @@ pub(crate) unsafe fn futex_timeout(
562562
val3,
563563
))
564564
.or_else(|err| {
565-
// See the comments in `rustix_clock_gettime_via_syscall` about
566-
// emulation.
565+
// See the comments in `clock_gettime_via_syscall` about emulation.
567566
if err == io::Errno::NOSYS {
568567
futex_old_timespec(uaddr, op, flags, val, timeout, uaddr2, val3)
569568
} else {

src/backend/linux_raw/fs/syscalls.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,8 +1349,7 @@ unsafe fn _utimensat_old(
13491349
times: &Timestamps,
13501350
flags: AtFlags,
13511351
) -> io::Result<()> {
1352-
// See the comments in `rustix_clock_gettime_via_syscall` about
1353-
// emulation.
1352+
// See the comments in `clock_gettime_via_syscall` about emulation.
13541353
let old_times = [
13551354
__kernel_old_timespec {
13561355
tv_sec: times

src/backend/linux_raw/process/wait.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,37 @@ impl SiginfoExt for siginfo_t {
8585
._status
8686
}
8787
}
88+
89+
#[cfg(test)]
90+
mod tests {
91+
use super::*;
92+
93+
#[test]
94+
fn test_libc_correspondence() {
95+
for status in [
96+
0,
97+
1,
98+
63,
99+
64,
100+
65,
101+
127,
102+
128,
103+
129,
104+
255,
105+
256,
106+
257,
107+
4095,
108+
4096,
109+
4097,
110+
u32::MAX,
111+
] {
112+
assert_eq!(WIFSTOPPED(status), libc::WIFSTOPPED(status as i32));
113+
assert_eq!(WSTOPSIG(status), libc::WSTOPSIG(status as i32) as u32);
114+
assert_eq!(WIFCONTINUED(status), libc::WIFCONTINUED(status as i32));
115+
assert_eq!(WIFSIGNALED(status), libc::WIFSIGNALED(status as i32));
116+
assert_eq!(WTERMSIG(status), libc::WTERMSIG(status as i32) as u32);
117+
assert_eq!(WIFEXITED(status), libc::WIFEXITED(status as i32));
118+
assert_eq!(WEXITSTATUS(status), libc::WEXITSTATUS(status as i32) as u32);
119+
}
120+
}
121+
}

src/backend/linux_raw/thread/syscalls.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ pub(crate) fn clock_nanosleep_relative(id: ClockId, req: &Timespec) -> Nanosleep
3737
&mut rem
3838
))
3939
.or_else(|err| {
40-
// See the comments in `rustix_clock_gettime_via_syscall` about
41-
// emulation.
40+
// See the comments in `clock_gettime_via_syscall` about emulation.
4241
if err == io::Errno::NOSYS {
4342
clock_nanosleep_relative_old(id, req, &mut rem)
4443
} else {
@@ -105,8 +104,7 @@ pub(crate) fn clock_nanosleep_absolute(id: ClockId, req: &Timespec) -> io::Resul
105104
zero()
106105
))
107106
.or_else(|err| {
108-
// See the comments in `rustix_clock_gettime_via_syscall` about
109-
// emulation.
107+
// See the comments in `clock_gettime_via_syscall` about emulation.
110108
if err == io::Errno::NOSYS {
111109
clock_nanosleep_absolute_old(id, req)
112110
} else {
@@ -154,8 +152,7 @@ pub(crate) fn nanosleep(req: &Timespec) -> NanosleepRelativeResult {
154152
&mut rem
155153
))
156154
.or_else(|err| {
157-
// See the comments in `rustix_clock_gettime_via_syscall` about
158-
// emulation.
155+
// See the comments in `clock_gettime_via_syscall` about emulation.
159156
if err == io::Errno::NOSYS {
160157
nanosleep_old(req, &mut rem)
161158
} else {
@@ -272,8 +269,7 @@ pub(crate) unsafe fn futex_timeout(
272269
c_uint(val3)
273270
))
274271
.or_else(|err| {
275-
// See the comments in `rustix_clock_gettime_via_syscall` about
276-
// emulation.
272+
// See the comments in `clock_gettime_via_syscall` about emulation.
277273
if err == io::Errno::NOSYS {
278274
futex_old_timespec(uaddr, op, flags, val, timeout, uaddr2, val3)
279275
} else {

src/backend/linux_raw/time/syscalls.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ pub(crate) fn clock_getres(which_clock: ClockId) -> Timespec {
3232
unsafe {
3333
let mut result = MaybeUninit::<Timespec>::uninit();
3434
if let Err(err) = ret(syscall!(__NR_clock_getres_time64, which_clock, &mut result)) {
35-
// See the comments in `rustix_clock_gettime_via_syscall` about
36-
// emulation.
35+
// See the comments in `clock_gettime_via_syscall` about emulation.
3736
debug_assert_eq!(err, io::Errno::NOSYS);
3837
clock_getres_old(which_clock, &mut result);
3938
}
@@ -138,8 +137,7 @@ pub(crate) fn timerfd_settime(
138137
&mut result
139138
))
140139
.or_else(|err| {
141-
// See the comments in `rustix_clock_gettime_via_syscall` about
142-
// emulation.
140+
// See the comments in `clock_gettime_via_syscall` about emulation.
143141
if err == io::Errno::NOSYS {
144142
timerfd_settime_old(fd, flags, new_value, &mut result)
145143
} else {
@@ -222,8 +220,7 @@ pub(crate) fn timerfd_gettime(fd: BorrowedFd<'_>) -> io::Result<Itimerspec> {
222220
#[cfg(target_pointer_width = "32")]
223221
unsafe {
224222
ret(syscall!(__NR_timerfd_gettime64, fd, &mut result)).or_else(|err| {
225-
// See the comments in `rustix_clock_gettime_via_syscall` about
226-
// emulation.
223+
// See the comments in `clock_gettime_via_syscall` about emulation.
227224
if err == io::Errno::NOSYS {
228225
timerfd_gettime_old(fd, &mut result)
229226
} else {

src/backend/linux_raw/vdso_wrappers.rs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub(crate) fn clock_gettime_dynamic(which_clock: DynamicClockId<'_>) -> io::Resu
108108
match callee(id, timespec.as_mut_ptr()) {
109109
0 => (),
110110
EINVAL => return Err(io::Errno::INVAL),
111-
_ => _rustix_clock_gettime_via_syscall(id, timespec.as_mut_ptr())?,
111+
_ => _clock_gettime_via_syscall(id, timespec.as_mut_ptr())?,
112112
}
113113
Ok(timespec.assume_init())
114114
}
@@ -337,35 +337,26 @@ static GETCPU: AtomicPtr<Function> = AtomicPtr::new(null_mut());
337337
static SYSCALL: AtomicPtr<Function> = AtomicPtr::new(null_mut());
338338

339339
#[cfg(feature = "time")]
340-
unsafe extern "C" fn rustix_clock_gettime_via_syscall(
341-
clockid: c::c_int,
342-
res: *mut Timespec,
343-
) -> c::c_int {
344-
match _rustix_clock_gettime_via_syscall(clockid, res) {
340+
unsafe extern "C" fn clock_gettime_via_syscall(clockid: c::c_int, res: *mut Timespec) -> c::c_int {
341+
match _clock_gettime_via_syscall(clockid, res) {
345342
Ok(()) => 0,
346343
Err(err) => err.raw_os_error().wrapping_neg(),
347344
}
348345
}
349346

350347
#[cfg(feature = "time")]
351348
#[cfg(target_pointer_width = "32")]
352-
unsafe fn _rustix_clock_gettime_via_syscall(
353-
clockid: c::c_int,
354-
res: *mut Timespec,
355-
) -> io::Result<()> {
349+
unsafe fn _clock_gettime_via_syscall(clockid: c::c_int, res: *mut Timespec) -> io::Result<()> {
356350
let r0 = syscall!(__NR_clock_gettime64, c_int(clockid), res);
357351
match ret(r0) {
358-
Err(io::Errno::NOSYS) => _rustix_clock_gettime_via_syscall_old(clockid, res),
352+
Err(io::Errno::NOSYS) => _clock_gettime_via_syscall_old(clockid, res),
359353
otherwise => otherwise,
360354
}
361355
}
362356

363357
#[cfg(feature = "time")]
364358
#[cfg(target_pointer_width = "32")]
365-
unsafe fn _rustix_clock_gettime_via_syscall_old(
366-
clockid: c::c_int,
367-
res: *mut Timespec,
368-
) -> io::Result<()> {
359+
unsafe fn _clock_gettime_via_syscall_old(clockid: c::c_int, res: *mut Timespec) -> io::Result<()> {
369360
// Ordinarily `rustix` doesn't like to emulate system calls, but in the
370361
// case of time APIs, it's specific to Linux, specific to 32-bit
371362
// architectures *and* specific to old kernel versions, and it's not that
@@ -387,10 +378,7 @@ unsafe fn _rustix_clock_gettime_via_syscall_old(
387378

388379
#[cfg(feature = "time")]
389380
#[cfg(target_pointer_width = "64")]
390-
unsafe fn _rustix_clock_gettime_via_syscall(
391-
clockid: c::c_int,
392-
res: *mut Timespec,
393-
) -> io::Result<()> {
381+
unsafe fn _clock_gettime_via_syscall(clockid: c::c_int, res: *mut Timespec) -> io::Result<()> {
394382
ret(syscall!(__NR_clock_gettime, c_int(clockid), res))
395383
}
396384

@@ -402,7 +390,7 @@ unsafe fn _rustix_clock_gettime_via_syscall(
402390
target_arch = "powerpc64",
403391
target_arch = "s390x",
404392
))]
405-
unsafe extern "C" fn rustix_getcpu_via_syscall(
393+
unsafe extern "C" fn getcpu_via_syscall(
406394
cpu: *mut u32,
407395
node: *mut u32,
408396
unused: *mut c_void,
@@ -451,7 +439,7 @@ fn minimal_init() {
451439
CLOCK_GETTIME
452440
.compare_exchange(
453441
null_mut(),
454-
rustix_clock_gettime_via_syscall as *mut Function,
442+
clock_gettime_via_syscall as *mut Function,
455443
Relaxed,
456444
Relaxed,
457445
)
@@ -470,7 +458,7 @@ fn minimal_init() {
470458
GETCPU
471459
.compare_exchange(
472460
null_mut(),
473-
rustix_getcpu_via_syscall as *mut Function,
461+
getcpu_via_syscall as *mut Function,
474462
Relaxed,
475463
Relaxed,
476464
)

src/fs/constants.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use crate::backend;
44

5-
pub use crate::io::FdFlags;
65
pub use crate::timespec::{Nsecs, Secs, Timespec};
76
pub use backend::fs::types::*;
87

src/fs/fcntl.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ use crate::{backend, io};
1616
use backend::fd::AsFd;
1717
use backend::fs::types::OFlags;
1818

19-
// These `fcntl` functions live in the `io` module because they're not specific
20-
// to files, directories, or memfd objects. We re-export them here in the `fs`
21-
// module because the other the `fcntl` functions are here.
22-
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))]
23-
pub use crate::io::fcntl_dupfd_cloexec;
24-
pub use crate::io::{fcntl_getfd, fcntl_setfd};
25-
2619
/// `fcntl(fd, F_GETFL)`—Returns a file descriptor's access mode and status.
2720
///
2821
/// # References

0 commit comments

Comments
 (0)