Skip to content

Commit

Permalink
Fixed target OS condition in gettid
Browse files Browse the repository at this point in the history
  • Loading branch information
YohDeadfall committed Sep 26, 2024
1 parent 2efcdf4 commit ed2aec0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,20 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
)
}

/// Helper function used inside the shims of foreign functions to assert that the target OS
/// is one of `target_oses`. It panics showing a message with the `name` of the foreign function
/// if this is not the case.
fn assert_target_os_is_one_of(&self, target_oses: &[&str], name: &str) {
assert!(
target_oses.contains(&self.eval_context_ref().tcx.sess.target.os.as_ref()),
"`{name}` is only available on the {} target OS's",
target_oses.iter().enumerate().map(|(i, t)| match i {
0 => format!("`{t}`"),
_ => format!(", `{t}`"),
}).collect::<String>()
)
}

/// Helper function used inside the shims of foreign functions to assert that the target OS
/// is part of the UNIX family. It panics showing a message with the `name` of the foreign function
/// if this is not the case.
Expand Down
2 changes: 1 addition & 1 deletion src/shims/unix/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {

fn linux_gettid(&mut self) -> InterpResult<'tcx, Scalar> {
let this = self.eval_context_ref();
this.assert_target_os("linux", "gettid");
this.assert_target_os_is_one_of(&["linux", "android"], "gettid");

let index = this.machine.threads.active_thread().to_u32();

Expand Down

0 comments on commit ed2aec0

Please sign in to comment.