@@ -20,26 +20,31 @@ pub fn prctl<'tcx>(
20
20
// https://github.com/rust-lang/libc/pull/3941 lands.
21
21
const PR_SET_NAME : i32 = 15 ;
22
22
const PR_GET_NAME : i32 = 16 ;
23
+ const TASK_COMM_LEN : usize = 16 ;
23
24
24
25
let [ op] = check_min_arg_count ( "prctl" , args) ?;
25
26
let res = match this. read_scalar ( op) ?. to_i32 ( ) ? {
26
27
PR_SET_NAME => {
27
28
let [ _, name] = check_min_arg_count ( "prctl(PR_SET_NAME, ...)" , args) ?;
28
29
29
- let tid = this. pthread_self ( ) ?;
30
- let name = this. read_scalar ( name) ?;
31
- let name_len = 16 ;
30
+ let name = this. read_scalar ( name) ?. to_pointer ( this) ?;
31
+ let name =
32
+ this. read_c_str ( name) ?. iter ( ) . take ( TASK_COMM_LEN - 1 ) . copied ( ) . collect :: < Vec < _ > > ( ) ;
33
+
34
+ let thread = this. pthread_self ( ) ?. to_int ( this. libc_ty_layout ( "pthread_t" ) . size ) ?;
35
+ let thread = ThreadId :: try_from ( thread) . unwrap ( ) ;
32
36
33
- this. pthread_setname_np ( tid, name, name_len) ?
37
+ this. set_thread_name ( thread, name) ;
38
+ Scalar :: from_u32 ( 0 )
34
39
}
35
40
PR_GET_NAME => {
36
41
let [ _, name] = check_min_arg_count ( "prctl(PR_GET_NAME, ...)" , args) ?;
37
42
38
- let tid = this. pthread_self ( ) ?;
43
+ let thread = this. pthread_self ( ) ?;
39
44
let name = this. read_scalar ( name) ?;
40
- let name_len = Scalar :: from_target_usize ( 16 , this) ;
45
+ let name_len = Scalar :: from_target_usize ( TASK_COMM_LEN as u64 , this) ;
41
46
42
- this. pthread_getname_np ( tid , name, name_len) ?
47
+ this. pthread_getname_np ( thread , name, name_len) ?
43
48
}
44
49
op => {
45
50
this. handle_unsupported_foreign_item ( format ! ( "can't execute prctl with OP {op}" ) ) ?;
0 commit comments