Skip to content

Commit 6b18f6e

Browse files
committed
fix setting thread name on macOS
1 parent 6680118 commit 6b18f6e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/shims/foreign_items/posix/macos.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
9898
this.write_scalar(stack_size, dest)?;
9999
}
100100

101+
// Threading
102+
"pthread_setname_np" => {
103+
let ptr = this.read_scalar(args[0])?.not_undef()?;
104+
this.pthread_setname_np(ptr)?;
105+
}
106+
101107
// Incomplete shims that we "stub out" just to get pre-main initialization code to work.
102108
// These shims are enabled only when the caller is in the standard library.
103109
"mmap" if this.frame().instance.to_string().starts_with("std::sys::unix::") => {

src/shims/thread.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
9595
_arg5: OpTy<'tcx, Tag>,
9696
) -> InterpResult<'tcx, i32> {
9797
let this = self.eval_context_mut();
98+
this.assert_target_os("linux", "prctl");
9899

99100
let option = this.read_scalar(option)?.to_i32()?;
100101
if option == this.eval_libc_i32("PR_SET_NAME")? {
@@ -118,6 +119,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
118119
Ok(0)
119120
}
120121

122+
fn pthread_setname_np(
123+
&mut self,
124+
ptr: Scalar<Tag>,
125+
) -> InterpResult<'tcx> {
126+
let this = self.eval_context_mut();
127+
this.assert_target_os("macos", "pthread_setname_np");
128+
129+
let name = this.memory.read_c_str(ptr)?.to_owned();
130+
this.set_active_thread_name(name)?;
131+
132+
Ok(())
133+
}
134+
121135
fn sched_yield(&mut self) -> InterpResult<'tcx, i32> {
122136
let this = self.eval_context_mut();
123137

0 commit comments

Comments
 (0)