From 3bc5dab53f4260596d5ee15c6876d8637d41a7fc Mon Sep 17 00:00:00 2001 From: Christian Legnitto Date: Tue, 11 Apr 2023 09:01:25 -0400 Subject: [PATCH 1/2] Add shim for SIGRTMIN Fixes https://github.com/rust-lang/miri/issues/2832. --- src/tools/miri/src/machine.rs | 10 ++++++++-- .../src/shims/unix/linux/foreign_items.rs | 6 ++++++ .../miri/tests/pass-dep/shims/libc-misc.rs | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index 477d8d33ebba7..7d972dc514b9c 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -32,8 +32,14 @@ use crate::{ *, }; -/// The number of the available real-time signal with the lowest priority. -/// Dummy constant related to epoll, must be between 32 and 64. +/// First real-time signal. +/// `signal(7)` says this must be between 32 and 64 and specifies 34 or 35 +/// as typical values. +pub const SIGRTMIN: i32 = 34; + +/// Last real-time signal. +/// `signal(7)` says it must be between 32 and 64 and specifies +/// `SIGRTMAX` - `SIGRTMIN` >= 8 (which is the value of `_POSIX_RTSIG_MAX`) pub const SIGRTMAX: i32 = 42; /// Extra data stored with each stack frame diff --git a/src/tools/miri/src/shims/unix/linux/foreign_items.rs b/src/tools/miri/src/shims/unix/linux/foreign_items.rs index f4e7824d91df4..c11e2220e6f22 100644 --- a/src/tools/miri/src/shims/unix/linux/foreign_items.rs +++ b/src/tools/miri/src/shims/unix/linux/foreign_items.rs @@ -2,6 +2,7 @@ use rustc_span::Symbol; use rustc_target::spec::abi::Abi; use crate::machine::SIGRTMAX; +use crate::machine::SIGRTMIN; use crate::*; use shims::foreign_items::EmulateByNameResult; use shims::unix::fs::EvalContextExt as _; @@ -74,6 +75,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { let result = this.socketpair(domain, type_, protocol, sv)?; this.write_scalar(result, dest)?; } + "__libc_current_sigrtmin" => { + let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + + this.write_scalar(Scalar::from_i32(SIGRTMIN), dest)?; + } "__libc_current_sigrtmax" => { let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; diff --git a/src/tools/miri/tests/pass-dep/shims/libc-misc.rs b/src/tools/miri/tests/pass-dep/shims/libc-misc.rs index 98e1c3a0adb2e..b9f51a9f0a6b5 100644 --- a/src/tools/miri/tests/pass-dep/shims/libc-misc.rs +++ b/src/tools/miri/tests/pass-dep/shims/libc-misc.rs @@ -302,6 +302,24 @@ fn test_posix_mkstemp() { } } +#[cfg(target_os = "linux")] +fn test_sigrt() { + let min = libc::SIGRTMIN(); + let max = libc::SIGRTMAX(); + + // "The Linux kernel supports a range of 33 different real-time + // signals, numbered 32 to 64" + assert!(min >= 32); + assert!(max >= 32); + assert!(min <= 64); + assert!(max <= 64); + + // "POSIX.1-2001 requires that an implementation support at least + // _POSIX_RTSIG_MAX (8) real-time signals."" + assert!(min < max); + assert!(max - min >= 8) +} + fn main() { test_posix_gettimeofday(); test_posix_mkstemp(); @@ -319,5 +337,6 @@ fn main() { { test_posix_fadvise(); test_sync_file_range(); + test_sigrt(); } } From df364991594a98d626cc653b11d927f97c5eb16b Mon Sep 17 00:00:00 2001 From: Christian Legnitto Date: Tue, 11 Apr 2023 10:26:39 -0400 Subject: [PATCH 2/2] Update tests/pass-dep/shims/libc-misc.rs Co-authored-by: Ben Kimock --- src/tools/miri/tests/pass-dep/shims/libc-misc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri/tests/pass-dep/shims/libc-misc.rs b/src/tools/miri/tests/pass-dep/shims/libc-misc.rs index b9f51a9f0a6b5..6fffbc9b4ac6d 100644 --- a/src/tools/miri/tests/pass-dep/shims/libc-misc.rs +++ b/src/tools/miri/tests/pass-dep/shims/libc-misc.rs @@ -315,7 +315,7 @@ fn test_sigrt() { assert!(max <= 64); // "POSIX.1-2001 requires that an implementation support at least - // _POSIX_RTSIG_MAX (8) real-time signals."" + // _POSIX_RTSIG_MAX (8) real-time signals." assert!(min < max); assert!(max - min >= 8) }