rustup for pthread_setname_np on Linux
This commit is contained in:
parent
39ee574715
commit
23cd7b863f
6 changed files with 44 additions and 33 deletions
|
|
@ -1 +1 @@
|
|||
1603a70f82240ba2d27f72f964e36614d7620ad3
|
||||
20ffea6938b5839c390252e07940b99e3b6a889a
|
||||
|
|
|
|||
|
|
@ -437,7 +437,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
}
|
||||
"pthread_self" => {
|
||||
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
|
||||
this.pthread_self(dest)?;
|
||||
let res = this.pthread_self()?;
|
||||
this.write_scalar(res, dest)?;
|
||||
}
|
||||
"sched_yield" => {
|
||||
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
|
||||
|
|
|
|||
|
|
@ -69,6 +69,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
let result = this.pthread_condattr_getclock(attr, clock_id)?;
|
||||
this.write_scalar(Scalar::from_i32(result), dest)?;
|
||||
}
|
||||
"pthread_setname_np" => {
|
||||
let [thread, name] =
|
||||
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
|
||||
let res = this.pthread_setname_np(
|
||||
this.read_scalar(thread)?.check_init()?,
|
||||
this.read_scalar(name)?.check_init()?,
|
||||
)?;
|
||||
this.write_scalar(res, dest)?;
|
||||
}
|
||||
|
||||
// Dynamically invoked syscalls
|
||||
"syscall" => {
|
||||
|
|
|
|||
|
|
@ -173,8 +173,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
// Threading
|
||||
"pthread_setname_np" => {
|
||||
let [name] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
|
||||
let name = this.read_pointer(name)?;
|
||||
this.pthread_setname_np(name)?;
|
||||
let thread = this.pthread_self()?;
|
||||
this.pthread_setname_np(thread, this.read_scalar(name)?.check_init()?)?;
|
||||
}
|
||||
|
||||
// Incomplete shims that we "stub out" just to get pre-main initialization code to work.
|
||||
|
|
|
|||
|
|
@ -84,11 +84,27 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
Ok(0)
|
||||
}
|
||||
|
||||
fn pthread_self(&mut self, dest: &PlaceTy<'tcx, Provenance>) -> InterpResult<'tcx> {
|
||||
fn pthread_self(&mut self) -> InterpResult<'tcx, Scalar<Provenance>> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let thread_id = this.get_active_thread();
|
||||
this.write_scalar(Scalar::from_uint(thread_id.to_u32(), dest.layout.size), dest)
|
||||
Ok(Scalar::from_machine_usize(thread_id.into(), this))
|
||||
}
|
||||
|
||||
fn pthread_setname_np(
|
||||
&mut self,
|
||||
thread: Scalar<Provenance>,
|
||||
name: Scalar<Provenance>,
|
||||
) -> InterpResult<'tcx, Scalar<Provenance>> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
let thread = ThreadId::try_from(thread.to_machine_usize(this)?).unwrap();
|
||||
let name = name.to_pointer(this)?;
|
||||
|
||||
let name = this.read_c_str(name)?.to_owned();
|
||||
this.set_thread_name(thread, name);
|
||||
|
||||
Ok(Scalar::from_u32(0))
|
||||
}
|
||||
|
||||
fn prctl(&mut self, args: &[OpTy<'tcx, Provenance>]) -> InterpResult<'tcx, i32> {
|
||||
|
|
@ -117,7 +133,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
// byte. Since `read_c_str` returns the string without the null
|
||||
// byte, we need to truncate to 15.
|
||||
name.truncate(15);
|
||||
this.set_active_thread_name(name);
|
||||
this.set_thread_name(this.get_active_thread(), name);
|
||||
} else if option == this.eval_libc_i32("PR_GET_NAME")? {
|
||||
if args.len() < 2 {
|
||||
throw_ub_format!(
|
||||
|
|
@ -127,7 +143,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
}
|
||||
|
||||
let address = this.read_pointer(&args[1])?;
|
||||
let mut name = this.get_active_thread_name().to_vec();
|
||||
let mut name = this.get_thread_name(this.get_active_thread()).to_vec();
|
||||
name.push(0u8);
|
||||
assert!(name.len() <= 16);
|
||||
this.write_bytes_ptr(address, name)?;
|
||||
|
|
@ -138,16 +154,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
Ok(0)
|
||||
}
|
||||
|
||||
fn pthread_setname_np(&mut self, name: Pointer<Option<Provenance>>) -> InterpResult<'tcx> {
|
||||
let this = self.eval_context_mut();
|
||||
this.assert_target_os("macos", "pthread_setname_np");
|
||||
|
||||
let name = this.read_c_str(name)?.to_owned();
|
||||
this.set_active_thread_name(name);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn sched_yield(&mut self) -> InterpResult<'tcx, i32> {
|
||||
let this = self.eval_context_mut();
|
||||
|
||||
|
|
|
|||
|
|
@ -69,9 +69,9 @@ impl From<u32> for ThreadId {
|
|||
}
|
||||
}
|
||||
|
||||
impl ThreadId {
|
||||
pub fn to_u32_scalar(&self) -> Scalar<Provenance> {
|
||||
Scalar::from_u32(self.0)
|
||||
impl From<ThreadId> for u64 {
|
||||
fn from(t: ThreadId) -> Self {
|
||||
t.0.into()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -394,14 +394,9 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Set the name of the active thread.
|
||||
fn set_active_thread_name(&mut self, new_thread_name: Vec<u8>) {
|
||||
self.active_thread_mut().thread_name = Some(new_thread_name);
|
||||
}
|
||||
|
||||
/// Get the name of the active thread.
|
||||
pub fn get_active_thread_name(&self) -> &[u8] {
|
||||
self.active_thread_ref().thread_name()
|
||||
/// Set the name of the given thread.
|
||||
pub fn set_thread_name(&mut self, thread: ThreadId, new_thread_name: Vec<u8>) {
|
||||
self.threads[thread].thread_name = Some(new_thread_name);
|
||||
}
|
||||
|
||||
/// Get the name of the given thread.
|
||||
|
|
@ -704,18 +699,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn set_active_thread_name(&mut self, new_thread_name: Vec<u8>) {
|
||||
fn set_thread_name(&mut self, thread: ThreadId, new_thread_name: Vec<u8>) {
|
||||
let this = self.eval_context_mut();
|
||||
this.machine.threads.set_active_thread_name(new_thread_name);
|
||||
this.machine.threads.set_thread_name(thread, new_thread_name);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_active_thread_name<'c>(&'c self) -> &'c [u8]
|
||||
fn get_thread_name<'c>(&'c self, thread: ThreadId) -> &'c [u8]
|
||||
where
|
||||
'mir: 'c,
|
||||
{
|
||||
let this = self.eval_context_ref();
|
||||
this.machine.threads.get_active_thread_name()
|
||||
this.machine.threads.get_thread_name(thread)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue