@@ -7,7 +7,6 @@ use rustc_data_structures::fx::FxHashMap;
77use rustc_index:: IndexVec ;
88use rustc_middle:: ty:: Ty ;
99use rustc_middle:: ty:: layout:: LayoutOf ;
10- use rustc_span:: Symbol ;
1110
1211use 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}
0 commit comments