]> git.lizzy.rs Git - rust.git/commitdiff
fix setting thread name on macOS
authorRalf Jung <post@ralfj.de>
Sun, 3 May 2020 11:22:56 +0000 (13:22 +0200)
committerRalf Jung <post@ralfj.de>
Sun, 3 May 2020 11:22:56 +0000 (13:22 +0200)
src/shims/foreign_items/posix/macos.rs
src/shims/thread.rs

index 0e3019ce33a39f8ee036dc5f138584a3637258c6..3677960fd8777771a2a4516853b977cdb6af7b94 100644 (file)
@@ -98,6 +98,12 @@ fn emulate_foreign_item_by_name(
                 this.write_scalar(stack_size, dest)?;
             }
 
+            // Threading
+            "pthread_setname_np" => {
+                let ptr = this.read_scalar(args[0])?.not_undef()?;
+                this.pthread_setname_np(ptr)?;
+            }
+
             // Incomplete shims that we "stub out" just to get pre-main initialization code to work.
             // These shims are enabled only when the caller is in the standard library.
             "mmap" if this.frame().instance.to_string().starts_with("std::sys::unix::") => {
index 2f553c1c729e85629a930ae399112834ba38a86b..ac1bb39a69828ba1de76a8ed568840d11d9b351e 100644 (file)
@@ -95,6 +95,7 @@ fn prctl(
         _arg5: OpTy<'tcx, Tag>,
     ) -> InterpResult<'tcx, i32> {
         let this = self.eval_context_mut();
+        this.assert_target_os("linux", "prctl");
 
         let option = this.read_scalar(option)?.to_i32()?;
         if option == this.eval_libc_i32("PR_SET_NAME")? {
@@ -118,6 +119,19 @@ fn prctl(
         Ok(0)
     }
 
+    fn pthread_setname_np(
+        &mut self,
+        ptr: Scalar<Tag>,
+    ) -> InterpResult<'tcx> {
+        let this = self.eval_context_mut();
+        this.assert_target_os("macos", "pthread_setname_np");
+
+        let name = this.memory.read_c_str(ptr)?.to_owned();
+        this.set_active_thread_name(name)?;
+
+        Ok(())
+    }
+
     fn sched_yield(&mut self) -> InterpResult<'tcx, i32> {
         let this = self.eval_context_mut();