Skip to content

Commit f24abdd

Browse files
committed
Revert "Add miri shims for gettid-like functions"
This reverts commit 4e8452a.
1 parent 8d2ac92 commit f24abdd

File tree

7 files changed

+7
-67
lines changed

7 files changed

+7
-67
lines changed

src/tools/miri/src/shims/env.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,4 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
114114
let this = self.eval_context_ref();
115115
if this.machine.communicate() { std::process::id() } else { 1000 }
116116
}
117-
118-
fn get_current_tid(&self) -> u32 {
119-
self.get_tid(self.eval_context_ref().machine.threads.active_thread())
120-
}
121-
122-
fn get_tid(&self, thread: ThreadId) -> u32 {
123-
let this = self.eval_context_ref();
124-
let index = thread.to_u32();
125-
126-
// todo: is this also true on Windows?
127-
// Compute a TID for this thread, ensuring that the main thread has PID == TID.
128-
this.get_pid().strict_add(index)
129-
}
130117
}

src/tools/miri/src/shims/unix/env.rs

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_data_structures::fx::FxHashMap;
77
use rustc_index::IndexVec;
88
use rustc_middle::ty::Ty;
99
use rustc_middle::ty::layout::LayoutOf;
10-
use rustc_span::Symbol;
1110

1211
use crate::*;
1312

@@ -276,34 +275,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
276275
interp_ok(Scalar::from_u32(this.get_pid()))
277276
}
278277

279-
/// The `gettid`-like function for Unix platforms that take no parameters
280-
fn unix_gettid(&mut self, _link_name: Symbol) -> InterpResult<'tcx, Scalar> {
278+
fn linux_gettid(&mut self) -> InterpResult<'tcx, Scalar> {
281279
let this = self.eval_context_ref();
280+
this.assert_target_os("linux", "gettid");
282281

283-
// todo: assert the platform
282+
let index = this.machine.threads.active_thread().to_u32();
284283

285-
interp_ok(Scalar::from_u32(this.get_current_tid()))
286-
}
287-
288-
/// The Apple-specific `int pthread_threadid_np(pthread_t thread, uint64_t *thread_id)`
289-
fn apple_pthread_threadip_np(
290-
&mut self,
291-
thread_op: &OpTy<'tcx>,
292-
tid_op: &OpTy<'tcx>,
293-
) -> InterpResult<'tcx, Scalar> {
294-
let this = self.eval_context_mut();
295-
296-
// todo: assert the platform
297-
298-
let thread = this.read_target_usize(thread_op)?;
299-
300-
// todo: real error
301-
assert_eq!(thread, 0, "querying the thread ID of other threads is not yet supported");
302-
303-
let tid_dest = this.deref_pointer_as(tid_op, this.machine.layouts.u64)?;
304-
this.write_int(this.get_current_tid(), &tid_dest)?;
284+
// Compute a TID for this thread, ensuring that the main thread has PID == TID.
285+
let tid = this.get_pid().strict_add(index);
305286

306-
// Never an error if we only ever check the current thread.
307-
interp_ok(Scalar::from_u32(0))
287+
interp_ok(Scalar::from_u32(tid))
308288
}
309289
}

src/tools/miri/src/shims/unix/freebsd/foreign_items.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
5656
};
5757
this.write_scalar(res, dest)?;
5858
}
59-
"pthread_getthreadid_np" => {
60-
let [] = this.check_shim(abi, CanonAbi::C, link_name, args)?;
61-
let result = this.unix_gettid(link_name)?;
62-
this.write_scalar(result, dest)?;
63-
}
6459

6560
"cpuset_getaffinity" => {
6661
// The "same" kind of api as `sched_getaffinity` but more fine grained control for FreeBSD specifically.

src/tools/miri/src/shims/unix/linux/foreign_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
117117
}
118118
"gettid" => {
119119
let [] = this.check_shim(abi, CanonAbi::C, link_name, args)?;
120-
let result = this.unix_gettid(link_name)?;
120+
let result = this.linux_gettid()?;
121121
this.write_scalar(result, dest)?;
122122
}
123123

src/tools/miri/src/shims/unix/macos/foreign_items.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
222222
};
223223
this.write_scalar(res, dest)?;
224224
}
225-
"pthread_threadid_np" => {
226-
let [thread, tid_ptr] = this.check_shim(abi, CanonAbi::C, link_name, args)?;
227-
let res = this.apple_pthread_threadip_np(thread, tid_ptr)?;
228-
this.write_scalar(res, dest)?;
229-
}
230225

231226
// Synchronization primitives
232227
"os_sync_wait_on_address" => {

src/tools/miri/src/shims/unix/solarish/foreign_items.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
8484
};
8585
this.write_scalar(res, dest)?;
8686
}
87-
"thr_self" => {
88-
let [] = this.check_shim(abi, CanonAbi::C, link_name, args)?;
89-
let result = this.unix_gettid(link_name)?;
90-
this.write_scalar(result, dest)?;
91-
}
9287

9388
// File related shims
9489
"stat" | "stat64" => {

src/tools/miri/src/shims/windows/foreign_items.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -630,18 +630,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
630630
this.write_scalar(name, &name_ptr)?;
631631
this.write_scalar(res, dest)?;
632632
}
633-
"GetThreadId" => {
634-
let [handle] = this.check_shim(abi, sys_conv, link_name, args)?;
635-
let handle = this.read_handle(handle, "GetThreadId")?;
636-
637-
let thread = match handle {
638-
Handle::Thread(thread) => thread,
639-
Handle::Pseudo(PseudoHandle::CurrentThread) => this.active_thread(),
640-
_ => this.invalid_handle("GetThreadDescription")?,
641-
};
642-
643-
this.write_scalar(Scalar::from_u32(this.get_tid(thread)), dest)?;
644-
}
645633

646634
// Miscellaneous
647635
"ExitProcess" => {

0 commit comments

Comments
 (0)