Skip to content

Commit

Permalink
Auto merge of rust-lang#2837 - LegNeato:sigrtmin, r=saethlin
Browse files Browse the repository at this point in the history
Add shim for SIGRTMIN

Fixes rust-lang/miri#2832.
  • Loading branch information
bors committed Apr 11, 2023
2 parents 2c45553 + df36499 commit 93a0575
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/tools/miri/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/tools/miri/src/shims/unix/linux/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _;
Expand Down Expand Up @@ -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)?;

Expand Down
19 changes: 19 additions & 0 deletions src/tools/miri/tests/pass-dep/shims/libc-misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -319,5 +337,6 @@ fn main() {
{
test_posix_fadvise();
test_sync_file_range();
test_sigrt();
}
}

0 comments on commit 93a0575

Please sign in to comment.