|
| 1 | +use std::iter; |
| 2 | + |
1 | 3 | use rustc_span::Symbol;
|
2 | 4 | use rustc_target::spec::abi::Abi;
|
3 | 5 |
|
4 | 6 | use crate::helpers::check_min_arg_count;
|
5 |
| -use crate::shims::unix::thread::EvalContextExt as _; |
| 7 | +use crate::shims::unix::thread::{DEFAULT_THREAD_NAME, EvalContextExt as _}; |
6 | 8 | use crate::*;
|
7 | 9 |
|
8 | 10 | pub fn prctl<'tcx>(
|
@@ -40,11 +42,25 @@ pub fn prctl<'tcx>(
|
40 | 42 | PR_GET_NAME => {
|
41 | 43 | let [_, name] = check_min_arg_count("prctl(PR_GET_NAME, ...)", args)?;
|
42 | 44 |
|
43 |
| - let thread = this.pthread_self()?; |
44 |
| - let name = this.read_scalar(name)?; |
45 |
| - let name_len = Scalar::from_target_usize(TASK_COMM_LEN as u64, this); |
| 45 | + let name_out = this.read_scalar(name)?; |
| 46 | + let name_out = name_out.to_pointer(this)?; |
| 47 | + |
| 48 | + let thread = this.pthread_self()?.to_int(this.libc_ty_layout("pthread_t").size)?; |
| 49 | + let thread = ThreadId::try_from(thread).unwrap(); |
46 | 50 |
|
47 |
| - this.pthread_getname_np(thread, name, name_len)? |
| 51 | + // FIXME: we should use the program name if the thread name is not set |
| 52 | + let name = this.get_thread_name(thread).unwrap_or(DEFAULT_THREAD_NAME).to_owned(); |
| 53 | + let name_len = name.len().max(TASK_COMM_LEN - 1); |
| 54 | + |
| 55 | + this.eval_context_mut().write_bytes_ptr( |
| 56 | + name_out, |
| 57 | + name.iter() |
| 58 | + .take(name_len) |
| 59 | + .copied() |
| 60 | + .chain(iter::repeat_n(0u8, TASK_COMM_LEN.strict_sub(name_len))), |
| 61 | + )?; |
| 62 | + |
| 63 | + Scalar::from_u32(0) |
48 | 64 | }
|
49 | 65 | op => {
|
50 | 66 | this.handle_unsupported_foreign_item(format!("can't execute prctl with OP {op}"))?;
|
|
0 commit comments