Skip to content

Commit

Permalink
feat: add support for tid argument in sched_(get/set)affinity
Browse files Browse the repository at this point in the history
  • Loading branch information
sleiderr committed Jan 9, 2025
1 parent d9894a3 commit 09f7cba
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/shims/unix/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,17 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let cpusetsize = this.read_target_usize(cpusetsize)?;
let mask = this.read_pointer(mask)?;

// TODO: when https://github.com/rust-lang/miri/issues/3730 is fixed this should use its notion of tid/pid
let thread_id = match pid {
0 => this.active_thread(),
let thread_id = match (pid, &*this.tcx.sess.target.os) {
(0, _) => this.active_thread(),
(tid, "linux") => {
if let Ok(tid) = this.machine.threads.thread_id_try_from(tid) {
tid
} else {
this.set_last_error_and_return(LibcError("ESRCH"), dest)?;

return interp_ok(EmulateItemResult::NeedsReturn);
}
},
_ => throw_unsup_format!("`sched_getaffinity` is only supported with a pid of 0 (indicating the current thread)"),
};

Expand Down Expand Up @@ -717,9 +725,17 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let cpusetsize = this.read_target_usize(cpusetsize)?;
let mask = this.read_pointer(mask)?;

// TODO: when https://github.com/rust-lang/miri/issues/3730 is fixed this should use its notion of tid/pid
let thread_id = match pid {
0 => this.active_thread(),
let thread_id = match (pid, &*this.tcx.sess.target.os) {
(0, _) => this.active_thread(),
(tid, "linux") => {
if let Ok(tid) = this.machine.threads.thread_id_try_from(tid) {
tid
} else {
this.set_last_error_and_return(LibcError("ESRCH"), dest)?;

return interp_ok(EmulateItemResult::NeedsReturn);
}
},
_ => throw_unsup_format!("`sched_setaffinity` is only supported with a pid of 0 (indicating the current thread)"),
};

Expand Down

0 comments on commit 09f7cba

Please sign in to comment.