@@ -72,6 +72,60 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
72
72
}
73
73
74
74
// Threading
75
+ "prctl" => {
76
+ // We do not use `check_shim` here because `syscall` is variadic. The argument
77
+ // count is checked bellow.
78
+ this. check_abi_and_shim_symbol_clash ( abi, Abi :: C { unwind : false } , link_name) ?;
79
+
80
+ if args. is_empty ( ) {
81
+ throw_ub_format ! (
82
+ "incorrect number of arguments for prctl: got 0, expected at least 1"
83
+ ) ;
84
+ }
85
+
86
+ // Since only two prctl calls are currently handled, and both expext just two arguments,
87
+ // it makes sense to handle validation here, outside of the match block below.
88
+ if args. len ( ) < 2 {
89
+ throw_ub_format ! (
90
+ "incorrect number of arguments for `PR_SET_NAME` prctl: got {}, expected at least 2" ,
91
+ args. len( )
92
+ ) ;
93
+ }
94
+
95
+ for ( i, arg) in args. iter ( ) . enumerate ( ) {
96
+ let val = this. read_scalar ( arg) ?. to_i32 ( ) ?;
97
+ if val != 0 {
98
+ throw_ub_format ! (
99
+ "incorrect value of {}th argument for 'PR_SET_NAME' prctl: got {}, expected 0L" ,
100
+ i,
101
+ val
102
+ ) ;
103
+ }
104
+ }
105
+
106
+ let op = this. read_scalar ( & args[ 0 ] ) ?. to_i32 ( ) ?;
107
+ let pr_set_name = this. eval_libc_i32 ( "PR_SET_NAME" ) ;
108
+ let pr_get_name = this. eval_libc_i32 ( "PR_GET_NAME" ) ;
109
+
110
+ let res = match op {
111
+ op if op == pr_set_name => {
112
+ let tid = this. linux_gettid ( ) ?;
113
+ let name = this. read_scalar ( & args[ 1 ] ) ?;
114
+ let name_len = 16 ;
115
+
116
+ this. pthread_setname_np ( tid, name, name_len) ?
117
+ }
118
+ op if op == pr_get_name => {
119
+ let tid = this. linux_gettid ( ) ?;
120
+ let name = this. read_scalar ( & args[ 1 ] ) ?;
121
+ let name_len = Scalar :: from_target_usize ( 16 , this) ;
122
+
123
+ this. pthread_getname_np ( tid, name, name_len) ?
124
+ }
125
+ _ => return Ok ( EmulateItemResult :: NotSupported ) ,
126
+ } ;
127
+ this. write_scalar ( res, dest) ?;
128
+ }
75
129
"pthread_setname_np" => {
76
130
let [ thread, name] =
77
131
this. check_shim ( abi, Abi :: C { unwind : false } , link_name, args) ?;
0 commit comments