1
1
use crate :: * ;
2
- use rustc_index:: vec:: Idx ;
3
2
use rustc_target:: abi:: LayoutOf ;
4
3
5
4
impl < ' mir , ' tcx > EvalContextExt < ' mir , ' tcx > for crate :: MiriEvalContext < ' mir , ' tcx > { }
@@ -19,33 +18,26 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
19
18
) ;
20
19
21
20
let new_thread_id = this. create_thread ( ) ?;
21
+ // Also switch to new thread so that we can push the first stackframe.
22
22
let old_thread_id = this. set_active_thread ( new_thread_id) ?;
23
23
24
24
let thread_info_place = this. deref_operand ( thread) ?;
25
- let thread_info_type = thread. layout . ty
26
- . builtin_deref ( true )
27
- . ok_or_else ( || err_ub_format ! (
28
- "wrong signature used for `pthread_create`: first argument must be a raw pointer."
29
- ) ) ?
30
- . ty ;
31
- let thread_info_layout = this. layout_of ( thread_info_type) ?;
32
25
this. write_scalar (
33
- Scalar :: from_uint ( new_thread_id. index ( ) as u128 , thread_info_layout . size ) ,
26
+ Scalar :: from_uint ( new_thread_id. to_u128 ( ) , thread_info_place . layout . size ) ,
34
27
thread_info_place. into ( ) ,
35
28
) ?;
36
29
37
30
let fn_ptr = this. read_scalar ( start_routine) ?. not_undef ( ) ?;
38
31
let instance = this. memory . get_fn ( fn_ptr) ?. as_instance ( ) ?;
39
32
40
33
let func_arg = this. read_immediate ( arg) ?;
41
- let func_args = [ * func_arg] ;
42
34
43
35
let ret_place =
44
36
this. allocate ( this. layout_of ( this. tcx . types . usize ) ?, MiriMemoryKind :: Machine . into ( ) ) ;
45
37
46
38
this. call_function (
47
39
instance,
48
- & func_args [ .. ] ,
40
+ & [ * func_arg ] ,
49
41
Some ( ret_place. into ( ) ) ,
50
42
StackPopCleanup :: None { cleanup : true } ,
51
43
) ?;
@@ -66,7 +58,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
66
58
throw_unsup_format ! ( "Miri supports pthread_join only with retval==NULL" ) ;
67
59
}
68
60
69
- let thread_id = this. read_scalar ( thread) ?. not_undef ( ) ? . to_machine_usize ( this) ?;
61
+ let thread_id = this. read_scalar ( thread) ?. to_machine_usize ( this) ?;
70
62
this. join_thread ( thread_id. into ( ) ) ?;
71
63
72
64
Ok ( 0 )
@@ -75,7 +67,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
75
67
fn pthread_detach ( & mut self , thread : OpTy < ' tcx , Tag > ) -> InterpResult < ' tcx , i32 > {
76
68
let this = self . eval_context_mut ( ) ;
77
69
78
- let thread_id = this. read_scalar ( thread) ?. not_undef ( ) ? . to_machine_usize ( this) ?;
70
+ let thread_id = this. read_scalar ( thread) ?. to_machine_usize ( this) ?;
79
71
this. detach_thread ( thread_id. into ( ) ) ?;
80
72
81
73
Ok ( 0 )
@@ -85,34 +77,20 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
85
77
let this = self . eval_context_mut ( ) ;
86
78
87
79
let thread_id = this. get_active_thread ( ) ?;
88
- this. write_scalar ( Scalar :: from_uint ( thread_id. index ( ) as u128 , dest. layout . size ) , dest)
80
+ this. write_scalar ( Scalar :: from_uint ( thread_id. to_u128 ( ) , dest. layout . size ) , dest)
89
81
}
90
82
91
83
fn prctl (
92
84
& mut self ,
93
85
option : OpTy < ' tcx , Tag > ,
94
86
arg2 : OpTy < ' tcx , Tag > ,
95
- arg3 : OpTy < ' tcx , Tag > ,
96
- arg4 : OpTy < ' tcx , Tag > ,
97
- arg5 : OpTy < ' tcx , Tag > ,
87
+ _arg3 : OpTy < ' tcx , Tag > ,
88
+ _arg4 : OpTy < ' tcx , Tag > ,
89
+ _arg5 : OpTy < ' tcx , Tag > ,
98
90
) -> InterpResult < ' tcx , i32 > {
99
91
let this = self . eval_context_mut ( ) ;
100
92
101
- // prctl last 5 arguments are declared as variadic. Therefore, we need
102
- // to check their types manually.
103
- let c_long_size = this. libc_ty_layout ( "c_long" ) ?. size . bytes ( ) ;
104
- let check_arg = |arg : OpTy < ' tcx , Tag > | -> InterpResult < ' tcx > {
105
- match this. read_scalar ( arg) ?. not_undef ( ) ? {
106
- Scalar :: Raw { size, .. } if u64:: from ( size) == c_long_size => Ok ( ( ) ) ,
107
- _ => throw_ub_format ! ( "an argument of unsupported type was passed to prctl" ) ,
108
- }
109
- } ;
110
- check_arg ( arg2) ?;
111
- check_arg ( arg3) ?;
112
- check_arg ( arg4) ?;
113
- check_arg ( arg5) ?;
114
-
115
- let option = this. read_scalar ( option) ?. not_undef ( ) ?. to_i32 ( ) ?;
93
+ let option = this. read_scalar ( option) ?. to_i32 ( ) ?;
116
94
if option == this. eval_libc_i32 ( "PR_SET_NAME" ) ? {
117
95
let address = this. read_scalar ( arg2) ?. not_undef ( ) ?;
118
96
let name = this. memory . read_c_str ( address) ?. to_owned ( ) ;
@@ -122,7 +100,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
122
100
let name = this. get_active_thread_name ( ) ?. to_vec ( ) ;
123
101
this. memory . write_bytes ( address, name) ?;
124
102
} else {
125
- throw_unsup_format ! ( "Unsupported prctl option." ) ;
103
+ throw_unsup_format ! ( "unsupported prctl option {}" , option ) ;
126
104
}
127
105
128
106
Ok ( 0 )
0 commit comments