Skip to content

Commit d55e619

Browse files
authored
Miscellaneous fixes (#1306)
- Fix compilation on AIX - Fix attributes for `ioctl::IFlags` bitflags. - Fix test compilation on Redox. - Make all raw signal numbers signed. - Make `SocketAddrStorage` and `WaitIdStatus` impl `Sync` and `Sync`, to match libc.
1 parent 912db92 commit d55e619

8 files changed

Lines changed: 46 additions & 11 deletions

File tree

src/backend/libc/fs/dir.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
#[cfg(not(any(solarish, target_os = "haiku", target_os = "nto", target_os = "vita")))]
1+
#[cfg(not(any(
2+
solarish,
3+
target_os = "aix",
4+
target_os = "haiku",
5+
target_os = "nto",
6+
target_os = "vita"
7+
)))]
28
use super::types::FileType;
39
use crate::backend::c;
410
use crate::backend::conv::owned_fd;

src/backend/linux_raw/net/addr.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ impl fmt::Debug for SocketAddrUnix {
194194
#[repr(transparent)]
195195
pub struct SocketAddrStorage(c::sockaddr_storage);
196196

197+
// SAFETY: Bindgen adds a union with a raw pointer for alignment but it's never
198+
// used. `sockaddr_storage` is just a bunch of bytes and it doesn't hold
199+
// pointers.
200+
unsafe impl Send for SocketAddrStorage {}
201+
202+
// SAFETY: Same as with `Send`.
203+
unsafe impl Sync for SocketAddrStorage {}
204+
197205
impl SocketAddrStorage {
198206
/// Return a socket addr storage initialized to all zero bytes. The
199207
/// `sa_family` is set to `AddressFamily::UNSPEC`.

src/fs/ioctl.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ bitflags! {
101101
/// `FS_*` constants for use with [`ioctl_getflags`].
102102
///
103103
/// [`ioctl_getflags`]: crate::fs::ioctl::ioctl_getflags
104+
#[repr(transparent)]
105+
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
104106
pub struct IFlags: ffi::c_uint {
105107
/// `FS_APPEND_FL`
106108
const APPEND = linux_raw_sys::general::FS_APPEND_FL;

src/process/wait.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//! Wait for processes to change state.
2+
//!
3+
//! # Safety
4+
//!
5+
//! This code needs to implement `Send` and `Sync` for `WaitIdStatus` because
6+
//! the linux-raw-sys bindings generate a type that doesn't do so
7+
//! automatically.
8+
#![allow(unsafe_code)]
19
use crate::process::Pid;
210
use crate::{backend, io};
311
use bitflags::bitflags;
@@ -137,6 +145,15 @@ impl WaitStatus {
137145
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "wasi")))]
138146
pub struct WaitIdStatus(pub(crate) backend::c::siginfo_t);
139147

148+
// SAFTEY: `siginfo_t` does contain some raw pointers, such as the `si_ptr`
149+
// and the `si_addr` fields, however it's up to users to use those correctly.
150+
#[cfg(linux_raw)]
151+
unsafe impl Send for WaitIdStatus {}
152+
153+
// SAFETY: Same as with `Send`.
154+
#[cfg(linux_raw)]
155+
unsafe impl Sync for WaitIdStatus {}
156+
140157
#[cfg(not(any(target_os = "openbsd", target_os = "redox", target_os = "wasi")))]
141158
impl WaitIdStatus {
142159
/// Returns whether the process is currently stopped.

src/runtime.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ pub unsafe fn brk(addr: *mut c_void) -> io::Result<*mut c_void> {
586586
///
587587
/// See [`sigrt`] for a convenient way to construct `SIGRTMIN + n` values.
588588
#[cfg(linux_raw)]
589-
pub const SIGRTMIN: u32 = linux_raw_sys::general::SIGRTMIN;
589+
pub const SIGRTMIN: i32 = linux_raw_sys::general::SIGRTMIN as i32;
590590

591591
/// `SIGRTMAX`—The last of the raw OS “real-time” signal range.
592592
///
@@ -595,7 +595,7 @@ pub const SIGRTMIN: u32 = linux_raw_sys::general::SIGRTMIN;
595595
/// won't share a process with a libc (perhaps because you yourself are
596596
/// implementing a libc).
597597
#[cfg(linux_raw)]
598-
pub const SIGRTMAX: u32 = {
598+
pub const SIGRTMAX: i32 = {
599599
// Use the actual `SIGRTMAX` value on platforms which define it.
600600
#[cfg(not(any(
601601
target_arch = "arm",
@@ -604,7 +604,7 @@ pub const SIGRTMAX: u32 = {
604604
target_arch = "x86_64",
605605
)))]
606606
{
607-
linux_raw_sys::general::SIGRTMAX
607+
linux_raw_sys::general::SIGRTMAX as i32
608608
}
609609

610610
// On platforms that don't, derive it from `_NSIG`.
@@ -615,7 +615,7 @@ pub const SIGRTMAX: u32 = {
615615
target_arch = "x86_64",
616616
))]
617617
{
618-
linux_raw_sys::general::_NSIG - 1
618+
linux_raw_sys::general::_NSIG as i32 - 1
619619
}
620620
};
621621

@@ -627,14 +627,14 @@ pub const SIGRTMAX: u32 = {
627627
/// implementing a libc).
628628
#[cfg(linux_raw)]
629629
#[doc(alias = "SIGRTMIN")]
630-
pub fn sigrt(n: u32) -> Option<Signal> {
630+
pub fn sigrt(n: i32) -> Option<Signal> {
631631
let sig = SIGRTMIN.wrapping_add(n);
632632
if (SIGRTMIN..=SIGRTMAX).contains(&sig) {
633633
// SAFETY: We've checked that `sig` is in the expected range. It could
634634
// still conflict with libc's reserved values, however users of the
635635
// `runtime` module here must already know that there's no other libc
636636
// to conflict with.
637-
Some(unsafe { Signal::from_raw_unchecked(sig as i32) })
637+
Some(unsafe { Signal::from_raw_unchecked(sig) })
638638
} else {
639639
None
640640
}

src/termios/types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,7 @@ impl core::fmt::Debug for SpecialCodeIndex {
12431243
#[cfg(any(
12441244
solarish,
12451245
all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")),
1246+
target_os = "aix",
12461247
target_os = "haiku",
12471248
))]
12481249
Self::VTIME => write!(f, "VTIME/VEOL"),
@@ -1262,6 +1263,7 @@ impl core::fmt::Debug for SpecialCodeIndex {
12621263
#[cfg(not(any(
12631264
solarish,
12641265
all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")),
1266+
target_os = "aix",
12651267
target_os = "haiku",
12661268
)))]
12671269
Self::VEOL => write!(f, "VEOL"),

tests/fs/special.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[cfg(feature = "process")]
2-
#[cfg(not(target_os = "wasi"))]
2+
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
33
#[test]
44
fn test_special_fds() {
55
use rustix::fs::{fstat, open, openat, Mode, OFlags, Stat, ABS, CWD};

tests/termios/termios.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ fn test_termios_modes() {
105105
assert!(!tio.local_modes.contains(LocalModes::TOSTOP));
106106
assert!(!tio.output_modes.contains(OutputModes::ONOCR));
107107
assert!(!tio.input_modes.contains(InputModes::IGNBRK));
108-
assert!(!tio.control_modes.contains(ControlModes::CRTSCTS));
108+
assert!(!tio.control_modes.contains(ControlModes::CLOCAL));
109109

110110
tio.local_modes.insert(LocalModes::TOSTOP);
111111
tio.output_modes.insert(OutputModes::ONOCR);
112112
tio.input_modes.insert(InputModes::IGNBRK);
113-
tio.control_modes.insert(ControlModes::CRTSCTS);
113+
tio.control_modes.insert(ControlModes::CLOCAL);
114114

115115
tcsetattr(&pty, OptionalActions::Now, &tio).unwrap();
116116

@@ -119,7 +119,7 @@ fn test_termios_modes() {
119119
assert!(new_tio.local_modes.contains(LocalModes::TOSTOP));
120120
assert!(new_tio.output_modes.contains(OutputModes::ONOCR));
121121
assert!(new_tio.input_modes.contains(InputModes::IGNBRK));
122-
assert!(new_tio.control_modes.contains(ControlModes::CRTSCTS));
122+
assert!(new_tio.control_modes.contains(ControlModes::CLOCAL));
123123
}
124124

125125
// Disable on illumos where `tcgetattr` doesn't appear to support

0 commit comments

Comments
 (0)