]> git.lizzy.rs Git - rust.git/commitdiff
Move copying of the thread name to the client side.
authorVytautas Astrauskas <astrauv@amazon.com>
Fri, 24 Apr 2020 23:46:51 +0000 (16:46 -0700)
committerVytautas Astrauskas <astrauv@amazon.com>
Mon, 27 Apr 2020 21:26:36 +0000 (14:26 -0700)
src/shims/thread.rs
src/thread.rs

index 65187326223cd4e474bc2cd960e7e67634887ad9..67e833f222e4b806a336ea0591b1e3868094817f 100644 (file)
@@ -119,7 +119,7 @@ fn prctl(
             this.set_active_thread_name(name)?;
         } else if option == this.eval_libc_i32("PR_GET_NAME")? {
             let address = this.read_scalar(arg2)?.not_undef()?;
-            let name = this.get_active_thread_name()?;
+            let name = this.get_active_thread_name()?.to_vec();
             this.memory.write_bytes(address, name)?;
         } else {
             throw_unsup_format!("Unsupported prctl option.");
index c4e0f9be1877bd11c4f505573184da4cb7322289..eb7af536cf119c34c60ad515c1ff313e2e8f5303 100644 (file)
@@ -254,11 +254,16 @@ fn enable_thread(&mut self, thread_id: ThreadId) {
         self.threads[thread_id].state = ThreadState::Enabled;
     }
 
-    /// Get the borrow of the currently active thread.
+    /// Get a mutable borrow of the currently active thread.
     fn active_thread_mut(&mut self) -> &mut Thread<'mir, 'tcx> {
         &mut self.threads[self.active_thread]
     }
 
+    /// Get a shared borrow of the currently active thread.
+    fn active_thread_ref(&self) -> &Thread<'mir, 'tcx> {
+        &self.threads[self.active_thread]
+    }
+
     /// Mark the thread as detached, which means that no other thread will try
     /// to join it and the thread is responsible for cleaning up.
     fn detach_thread(&mut self, id: ThreadId) -> InterpResult<'tcx> {
@@ -304,9 +309,9 @@ fn set_thread_name(&mut self, new_thread_name: Vec<u8>) {
     }
 
     /// Get the name of the active thread.
-    fn get_thread_name(&mut self) -> InterpResult<'tcx, Vec<u8>> {
-        if let Some(ref thread_name) = self.active_thread_mut().thread_name {
-            Ok(thread_name.clone())
+    fn get_thread_name(&self) -> InterpResult<'tcx, &[u8]> {
+        if let Some(ref thread_name) = self.active_thread_ref().thread_name {
+            Ok(thread_name)
         } else {
             throw_ub_format!("thread {:?} has no name set", self.active_thread)
         }
@@ -557,8 +562,11 @@ fn set_active_thread_name(&mut self, new_thread_name: Vec<u8>) -> InterpResult<'
     }
 
     #[inline]
-    fn get_active_thread_name(&mut self) -> InterpResult<'tcx, Vec<u8>> {
-        let this = self.eval_context_mut();
+    fn get_active_thread_name<'c>(&'c self) -> InterpResult<'tcx, &'c [u8]>
+    where
+        'mir: 'c,
+    {
+        let this = self.eval_context_ref();
         this.machine.threads.get_thread_name()
     }