Skip to content

Commit 04abf06

Browse files
author
Vytautas Astrauskas
committed
Move copying of the thread name to the client side.
1 parent feb1883 commit 04abf06

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/shims/thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
119119
this.set_active_thread_name(name)?;
120120
} else if option == this.eval_libc_i32("PR_GET_NAME")? {
121121
let address = this.read_scalar(arg2)?.not_undef()?;
122-
let name = this.get_active_thread_name()?;
122+
let name = this.get_active_thread_name()?.to_vec();
123123
this.memory.write_bytes(address, name)?;
124124
} else {
125125
throw_unsup_format!("Unsupported prctl option.");

src/thread.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,16 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
254254
self.threads[thread_id].state = ThreadState::Enabled;
255255
}
256256

257-
/// Get the borrow of the currently active thread.
257+
/// Get a mutable borrow of the currently active thread.
258258
fn active_thread_mut(&mut self) -> &mut Thread<'mir, 'tcx> {
259259
&mut self.threads[self.active_thread]
260260
}
261261

262+
/// Get a shared borrow of the currently active thread.
263+
fn active_thread_ref(&self) -> &Thread<'mir, 'tcx> {
264+
&self.threads[self.active_thread]
265+
}
266+
262267
/// Mark the thread as detached, which means that no other thread will try
263268
/// to join it and the thread is responsible for cleaning up.
264269
fn detach_thread(&mut self, id: ThreadId) -> InterpResult<'tcx> {
@@ -304,9 +309,9 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
304309
}
305310

306311
/// Get the name of the active thread.
307-
fn get_thread_name(&mut self) -> InterpResult<'tcx, Vec<u8>> {
308-
if let Some(ref thread_name) = self.active_thread_mut().thread_name {
309-
Ok(thread_name.clone())
312+
fn get_thread_name(&self) -> InterpResult<'tcx, &[u8]> {
313+
if let Some(ref thread_name) = self.active_thread_ref().thread_name {
314+
Ok(thread_name)
310315
} else {
311316
throw_ub_format!("thread {:?} has no name set", self.active_thread)
312317
}
@@ -557,8 +562,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
557562
}
558563

559564
#[inline]
560-
fn get_active_thread_name(&mut self) -> InterpResult<'tcx, Vec<u8>> {
561-
let this = self.eval_context_mut();
565+
fn get_active_thread_name<'c>(&'c self) -> InterpResult<'tcx, &'c [u8]>
566+
where
567+
'mir: 'c,
568+
{
569+
let this = self.eval_context_ref();
562570
this.machine.threads.get_thread_name()
563571
}
564572

0 commit comments

Comments
 (0)