Skip to content

Commit ddca5cc

Browse files
authored
Use KernelSigSet instead of SigSet in all runtime functions. (#1367)
After more testing, it appears Linux always requires sigset size parameters to match its `kernel_sigset_t` size. So, change rustix's strategy to use `KernelSigSet` for everything, and remove `SigSet`. c-scape will want `SigSet`, but it can define that for itself. See the comments on the `KernelSigSet` type for more details. Also, rename more things in the runtime module to `kernel_*`, to better reflect that they differ from their libc counterparts, and expand the safety comments.
1 parent 178c95d commit ddca5cc

File tree

6 files changed

+281
-595
lines changed

6 files changed

+281
-595
lines changed

src/backend/linux_raw/runtime/syscalls.rs

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::ffi::CStr;
2121
use crate::fs::AtFlags;
2222
use crate::io;
2323
use crate::pid::{Pid, RawPid};
24-
use crate::runtime::{Fork, How, KernelSigSet, KernelSigaction, SigSet, Siginfo, Stack};
24+
use crate::runtime::{Fork, How, KernelSigSet, KernelSigaction, Siginfo, Stack};
2525
use crate::signal::Signal;
2626
use crate::timespec::Timespec;
2727
use crate::utils::option_as_ptr;
@@ -165,7 +165,7 @@ pub(crate) unsafe fn kernel_sigaction(
165165
}
166166

167167
#[inline]
168-
pub(crate) unsafe fn sigaltstack(new: Option<Stack>) -> io::Result<Stack> {
168+
pub(crate) unsafe fn kernel_sigaltstack(new: Option<Stack>) -> io::Result<Stack> {
169169
let mut old = MaybeUninit::<Stack>::uninit();
170170
let new = option_as_ptr(new.as_ref());
171171
ret(syscall!(__NR_sigaltstack, new, &mut old))?;
@@ -195,97 +195,96 @@ pub(crate) unsafe fn kernel_sigprocmask(
195195
}
196196

197197
#[inline]
198-
pub(crate) fn sigpending() -> SigSet {
199-
let mut pending = MaybeUninit::<SigSet>::uninit();
198+
pub(crate) fn kernel_sigpending() -> KernelSigSet {
199+
let mut pending = MaybeUninit::<KernelSigSet>::uninit();
200200
unsafe {
201201
ret_infallible(syscall!(
202202
__NR_rt_sigpending,
203203
&mut pending,
204-
size_of::<SigSet, _>()
204+
size_of::<KernelSigSet, _>()
205205
));
206206
pending.assume_init()
207207
}
208208
}
209209

210210
#[inline]
211-
pub(crate) fn sigsuspend(set: &SigSet) -> io::Result<()> {
211+
pub(crate) fn kernel_sigsuspend(set: &KernelSigSet) -> io::Result<()> {
212212
unsafe {
213213
ret(syscall_readonly!(
214214
__NR_rt_sigsuspend,
215215
by_ref(set),
216-
size_of::<SigSet, _>()
216+
size_of::<KernelSigSet, _>()
217217
))
218218
}
219219
}
220220

221221
#[inline]
222-
pub(crate) fn sigwait(set: &SigSet) -> io::Result<Signal> {
223-
unsafe {
224-
Ok(Signal::from_raw_unchecked(ret_c_int(syscall_readonly!(
225-
__NR_rt_sigtimedwait,
226-
by_ref(set),
227-
zero(),
228-
zero(),
229-
size_of::<SigSet, _>()
230-
))?))
231-
}
222+
pub(crate) unsafe fn kernel_sigwait(set: &KernelSigSet) -> io::Result<Signal> {
223+
Ok(Signal::from_raw_unchecked(ret_c_int(syscall_readonly!(
224+
__NR_rt_sigtimedwait,
225+
by_ref(set),
226+
zero(),
227+
zero(),
228+
size_of::<KernelSigSet, _>()
229+
))?))
232230
}
233231

234232
#[inline]
235-
pub(crate) fn sigwaitinfo(set: &SigSet) -> io::Result<Siginfo> {
233+
pub(crate) unsafe fn kernel_sigwaitinfo(set: &KernelSigSet) -> io::Result<Siginfo> {
236234
let mut info = MaybeUninit::<Siginfo>::uninit();
237-
unsafe {
238-
let _signum = ret_c_int(syscall!(
239-
__NR_rt_sigtimedwait,
240-
by_ref(set),
241-
&mut info,
242-
zero(),
243-
size_of::<SigSet, _>()
244-
))?;
245-
Ok(info.assume_init())
246-
}
235+
let _signum = ret_c_int(syscall!(
236+
__NR_rt_sigtimedwait,
237+
by_ref(set),
238+
&mut info,
239+
zero(),
240+
size_of::<KernelSigSet, _>()
241+
))?;
242+
Ok(info.assume_init())
247243
}
248244

249245
#[inline]
250-
pub(crate) fn sigtimedwait(set: &SigSet, timeout: Option<Timespec>) -> io::Result<Siginfo> {
246+
pub(crate) unsafe fn kernel_sigtimedwait(
247+
set: &KernelSigSet,
248+
timeout: Option<Timespec>,
249+
) -> io::Result<Siginfo> {
251250
let mut info = MaybeUninit::<Siginfo>::uninit();
252251
let timeout_ptr = option_as_ptr(timeout.as_ref());
253252

254253
// `rt_sigtimedwait_time64` was introduced in Linux 5.1. The old
255254
// `rt_sigtimedwait` syscall is not y2038-compatible on 32-bit
256255
// architectures.
257256
#[cfg(target_pointer_width = "32")]
258-
unsafe {
257+
{
259258
match ret_c_int(syscall!(
260259
__NR_rt_sigtimedwait_time64,
261260
by_ref(set),
262261
&mut info,
263262
timeout_ptr,
264-
size_of::<SigSet, _>()
263+
size_of::<KernelSigSet, _>()
265264
)) {
266265
Ok(_signum) => (),
267-
Err(io::Errno::NOSYS) => sigtimedwait_old(set, timeout, &mut info)?,
266+
Err(io::Errno::NOSYS) => kernel_sigtimedwait_old(set, timeout, &mut info)?,
268267
Err(err) => return Err(err),
269268
}
270269
Ok(info.assume_init())
271270
}
272271

273272
#[cfg(target_pointer_width = "64")]
274-
unsafe {
273+
{
275274
let _signum = ret_c_int(syscall!(
276275
__NR_rt_sigtimedwait,
277276
by_ref(set),
278277
&mut info,
279278
timeout_ptr,
280-
size_of::<SigSet, _>()
279+
size_of::<KernelSigSet, _>()
281280
))?;
282281
Ok(info.assume_init())
283282
}
284283
}
285284

286285
#[cfg(target_pointer_width = "32")]
287-
unsafe fn sigtimedwait_old(
288-
set: &SigSet,
286+
unsafe fn kernel_sigtimedwait_old(
287+
set: &KernelSigSet,
289288
timeout: Option<Timespec>,
290289
info: &mut MaybeUninit<Siginfo>,
291290
) -> io::Result<()> {
@@ -304,7 +303,7 @@ unsafe fn sigtimedwait_old(
304303
by_ref(set),
305304
info,
306305
old_timeout_ptr,
307-
size_of::<SigSet, _>()
306+
size_of::<KernelSigSet, _>()
308307
))?;
309308

310309
Ok(())

src/io_uring/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ pub use crate::fs::{
4747
Advice, AtFlags, Mode, OFlags, RenameFlags, ResolveFlags, Statx, StatxFlags, XattrFlags,
4848
};
4949
pub use crate::io::ReadWriteFlags;
50+
pub use crate::kernel_sigset::KernelSigSet;
5051
pub use crate::net::addr::{SocketAddrLen, SocketAddrOpaque, SocketAddrStorage};
5152
pub use crate::net::{RecvFlags, SendFlags, SocketFlags};
5253
pub use crate::signal::Signal;
53-
pub use crate::sigset::SigSet;
5454
pub use crate::thread::futex::{
5555
Wait as FutexWait, WaitFlags as FutexWaitFlags, WaitPtr as FutexWaitPtr,
5656
WaitvFlags as FutexWaitvFlags,
@@ -171,7 +171,7 @@ pub unsafe fn io_uring_enter<Fd: AsFd, T>(
171171
arg: Option<&T>,
172172
) -> io::Result<u32> {
173173
debug_assert!(
174-
size_of::<T>() == size_of::<SigSet>()
174+
size_of::<T>() == size_of::<KernelSigSet>()
175175
|| size_of::<T>() == size_of::<io_uring_getevents_arg>()
176176
);
177177
debug_assert!(

0 commit comments

Comments
 (0)