From 2202278f6af676266034e756bd3848efe4e10ab8 Mon Sep 17 00:00:00 2001 From: Vytautas Astrauskas Date: Mon, 6 Apr 2020 16:30:30 -0700 Subject: [PATCH] Fix pthread_self. --- src/shims/foreign_items/posix.rs | 5 ++++- src/shims/threads.rs | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/shims/foreign_items/posix.rs b/src/shims/foreign_items/posix.rs index 4e08593d61c3..4cd3b8499112 100644 --- a/src/shims/foreign_items/posix.rs +++ b/src/shims/foreign_items/posix.rs @@ -329,6 +329,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let result = this.pthread_detach(args[0])?; this.write_scalar(Scalar::from_i32(result), dest)?; } + "pthread_self" => { + assert_eq!(args.len(), 0); + this.pthread_self(dest)?; + } "prctl" => { assert_eq!(args.len(), 5); let result = this.prctl(args[0], args[1], args[2], args[3], args[4])?; @@ -356,7 +360,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx // These shims are enabled only when the caller is in the standard library. | "pthread_attr_init" | "pthread_attr_destroy" - | "pthread_self" | "pthread_attr_setstacksize" | "pthread_condattr_init" | "pthread_condattr_setclock" diff --git a/src/shims/threads.rs b/src/shims/threads.rs index 3a55fb3c706c..fc733d7f5c9f 100644 --- a/src/shims/threads.rs +++ b/src/shims/threads.rs @@ -81,6 +81,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx Ok(0) } + fn pthread_self(&mut self, dest: PlaceTy<'tcx, Tag>) -> InterpResult<'tcx> { + let this = self.eval_context_mut(); + + let thread_id = this.get_active_thread()?; + this.write_scalar(Scalar::from_uint(thread_id.index() as u128, dest.layout.size), dest) + } fn prctl( &mut self, option: OpTy<'tcx, Tag>,