From 04abf066f15c2ce2d1a788a1021bb14dcb9ac045 Mon Sep 17 00:00:00 2001 From: Vytautas Astrauskas Date: Fri, 24 Apr 2020 16:46:51 -0700 Subject: [PATCH] Move copying of the thread name to the client side. --- src/shims/thread.rs | 2 +- src/thread.rs | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/shims/thread.rs b/src/shims/thread.rs index 65187326223..67e833f222e 100644 --- a/src/shims/thread.rs +++ b/src/shims/thread.rs @@ -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."); diff --git a/src/thread.rs b/src/thread.rs index c4e0f9be187..eb7af536cf1 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -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) { } /// Get the name of the active thread. - fn get_thread_name(&mut self) -> InterpResult<'tcx, Vec> { - 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) -> InterpResult<' } #[inline] - fn get_active_thread_name(&mut self) -> InterpResult<'tcx, Vec> { - 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() }