Skip to content

Commit f09547c

Browse files
committed
unix/thread: properly use pthread_t for thread IDs
1 parent fdd9500 commit f09547c

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

ci/ci.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ case $HOST_TARGET in
146146
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC panic/panic concurrency/simple atomic threadname libc-getentropy libc-getrandom libc-misc fs env num_cpus
147147
MIRI_TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC panic/panic concurrency/simple atomic threadname libc-getentropy libc-getrandom libc-misc fs env num_cpus
148148
MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal $VERY_BASIC hello panic/panic
149-
MIRI_TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $VERY_BASIC hello panic/panic pthread-sync
149+
MIRI_TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync
150150
# TODO fix solaris stack guard
151151
# MIRI_TEST_TARGET=x86_64-pc-solaris run_tests_minimal $VERY_BASIC hello panic/panic pthread-sync
152152
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal $VERY_BASIC wasm

src/shims/unix/thread.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
5151
fn pthread_detach(&mut self, thread: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx, i32> {
5252
let this = self.eval_context_mut();
5353

54-
let thread_id = this.read_target_usize(thread)?;
54+
let thread_id = this.read_scalar(thread)?.to_int(this.libc_ty_layout("pthread_t").size)?;
5555
this.detach_thread(
5656
thread_id.try_into().expect("thread ID should fit in u32"),
5757
/*allow_terminated_joined*/ false,
@@ -64,7 +64,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
6464
let this = self.eval_context_mut();
6565

6666
let thread_id = this.get_active_thread();
67-
Ok(Scalar::from_target_usize(thread_id.into(), this))
67+
Ok(Scalar::from_uint(thread_id.to_u32(), this.libc_ty_layout("pthread_t").size))
6868
}
6969

7070
/// Set the name of the current thread. `max_name_len` is the maximal length of the name
@@ -77,7 +77,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
7777
) -> InterpResult<'tcx, Scalar<Provenance>> {
7878
let this = self.eval_context_mut();
7979

80-
let thread = ThreadId::try_from(thread.to_target_usize(this)?).unwrap();
80+
let thread = thread.to_int(this.libc_ty_layout("pthread_t").size)?;
81+
let thread = ThreadId::try_from(thread).unwrap();
8182
let name = name.to_pointer(this)?;
8283

8384
let name = this.read_c_str(name)?.to_owned();
@@ -100,7 +101,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
100101
) -> InterpResult<'tcx, Scalar<Provenance>> {
101102
let this = self.eval_context_mut();
102103

103-
let thread = ThreadId::try_from(thread.to_target_usize(this)?).unwrap();
104+
let thread = thread.to_int(this.libc_ty_layout("pthread_t").size)?;
105+
let thread = ThreadId::try_from(thread).unwrap();
104106
let name_out = name_out.to_pointer(this)?;
105107
let len = len.to_target_usize(this)?;
106108

0 commit comments

Comments
 (0)