Skip to content

Commit 66d19a2

Browse files
committed
thread name handling that actually makes sense
1 parent d1965d6 commit 66d19a2

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/shims/windows/dlsym.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
122122
_ => this.invalid_handle("SetThreadDescription")?,
123123
};
124124

125-
this.set_thread_name_wide(thread, name);
125+
this.set_thread_name_wide(thread, &name);
126126

127127
this.write_null(dest)?;
128128
}

src/thread.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -803,12 +803,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
803803
}
804804

805805
#[inline]
806-
fn set_thread_name_wide(&mut self, thread: ThreadId, new_thread_name: Vec<u16>) {
806+
fn set_thread_name_wide(&mut self, thread: ThreadId, new_thread_name: &[u16]) {
807807
let this = self.eval_context_mut();
808-
this.machine.threads.set_thread_name(
809-
thread,
810-
new_thread_name.into_iter().flat_map(u16::to_ne_bytes).collect(),
811-
);
808+
809+
// `GetThreadDescription` isn't implemented, so being lossy is okay.
810+
// This is only read by diagnostics, which already use `from_utf8_lossy`.
811+
this.machine
812+
.threads
813+
.set_thread_name(thread, String::from_utf16_lossy(new_thread_name).into_bytes());
812814
}
813815

814816
#[inline]

0 commit comments

Comments
 (0)