@@ -4,86 +4,83 @@ use crate::*;
4
4
5
5
impl < ' tcx > MiriMachine < ' tcx > {
6
6
fn alloc_extern_static (
7
- this : & mut MiriInterpCx < ' tcx > ,
7
+ ecx : & mut MiriInterpCx < ' tcx > ,
8
8
name : & str ,
9
9
val : ImmTy < ' tcx > ,
10
10
) -> InterpResult < ' tcx > {
11
- let place = this . allocate ( val. layout , MiriMemoryKind :: ExternStatic . into ( ) ) ?;
12
- this . write_immediate ( * val, & place) ?;
13
- Self :: add_extern_static ( this , name, place. ptr ( ) ) ;
11
+ let place = ecx . allocate ( val. layout , MiriMemoryKind :: ExternStatic . into ( ) ) ?;
12
+ ecx . write_immediate ( * val, & place) ?;
13
+ Self :: add_extern_static ( ecx , name, place. ptr ( ) ) ;
14
14
interp_ok ( ( ) )
15
15
}
16
16
17
17
/// Zero-initialized pointer-sized extern statics are pretty common.
18
18
/// Most of them are for weak symbols, which we all set to null (indicating that the
19
19
/// symbol is not supported, and triggering fallback code which ends up calling
20
20
/// some other shim that we do support).
21
- fn null_ptr_extern_statics (
22
- this : & mut MiriInterpCx < ' tcx > ,
23
- names : & [ & str ] ,
24
- ) -> InterpResult < ' tcx > {
21
+ fn null_ptr_extern_statics ( ecx : & mut MiriInterpCx < ' tcx > , names : & [ & str ] ) -> InterpResult < ' tcx > {
25
22
for name in names {
26
- let val = ImmTy :: from_int ( 0 , this . machine . layouts . usize ) ;
27
- Self :: alloc_extern_static ( this , name, val) ?;
23
+ let val = ImmTy :: from_int ( 0 , ecx . machine . layouts . usize ) ;
24
+ Self :: alloc_extern_static ( ecx , name, val) ?;
28
25
}
29
26
interp_ok ( ( ) )
30
27
}
31
28
32
29
/// Extern statics that are initialized with function pointers to the symbols of the same name.
33
30
fn weak_symbol_extern_statics (
34
- this : & mut MiriInterpCx < ' tcx > ,
31
+ ecx : & mut MiriInterpCx < ' tcx > ,
35
32
names : & [ & str ] ,
36
33
) -> InterpResult < ' tcx > {
37
34
for name in names {
38
- assert ! ( this . is_dyn_sym( name) , "{name} is not a dynamic symbol" ) ;
39
- let layout = this . machine . layouts . const_raw_ptr ;
40
- let ptr = this . fn_ptr ( FnVal :: Other ( DynSym :: from_str ( name) ) ) ;
41
- let val = ImmTy :: from_scalar ( Scalar :: from_pointer ( ptr, this ) , layout) ;
42
- Self :: alloc_extern_static ( this , name, val) ?;
35
+ assert ! ( ecx . is_dyn_sym( name) , "{name} is not a dynamic symbol" ) ;
36
+ let layout = ecx . machine . layouts . const_raw_ptr ;
37
+ let ptr = ecx . fn_ptr ( FnVal :: Other ( DynSym :: from_str ( name) ) ) ;
38
+ let val = ImmTy :: from_scalar ( Scalar :: from_pointer ( ptr, ecx ) , layout) ;
39
+ Self :: alloc_extern_static ( ecx , name, val) ?;
43
40
}
44
41
interp_ok ( ( ) )
45
42
}
46
43
47
44
/// Sets up the "extern statics" for this machine.
48
- pub fn init_extern_statics ( this : & mut MiriInterpCx < ' tcx > ) -> InterpResult < ' tcx > {
45
+ pub fn init_extern_statics ( ecx : & mut MiriInterpCx < ' tcx > ) -> InterpResult < ' tcx > {
49
46
// "__rust_no_alloc_shim_is_unstable"
50
- let val = ImmTy :: from_int ( 0 , this . machine . layouts . u8 ) ; // always 0, value does not matter
51
- Self :: alloc_extern_static ( this , "__rust_no_alloc_shim_is_unstable" , val) ?;
47
+ let val = ImmTy :: from_int ( 0 , ecx . machine . layouts . u8 ) ; // always 0, value does not matter
48
+ Self :: alloc_extern_static ( ecx , "__rust_no_alloc_shim_is_unstable" , val) ?;
52
49
53
50
// "__rust_alloc_error_handler_should_panic"
54
- let val = this . tcx . sess . opts . unstable_opts . oom . should_panic ( ) ;
55
- let val = ImmTy :: from_int ( val, this . machine . layouts . u8 ) ;
56
- Self :: alloc_extern_static ( this , "__rust_alloc_error_handler_should_panic" , val) ?;
51
+ let val = ecx . tcx . sess . opts . unstable_opts . oom . should_panic ( ) ;
52
+ let val = ImmTy :: from_int ( val, ecx . machine . layouts . u8 ) ;
53
+ Self :: alloc_extern_static ( ecx , "__rust_alloc_error_handler_should_panic" , val) ?;
57
54
58
- if this . target_os_is_unix ( ) {
55
+ if ecx . target_os_is_unix ( ) {
59
56
// "environ" is mandated by POSIX.
60
- let environ = this . machine . env_vars . unix ( ) . environ ( ) ;
61
- Self :: add_extern_static ( this , "environ" , environ) ;
57
+ let environ = ecx . machine . env_vars . unix ( ) . environ ( ) ;
58
+ Self :: add_extern_static ( ecx , "environ" , environ) ;
62
59
}
63
60
64
- match this . tcx . sess . target . os . as_ref ( ) {
61
+ match ecx . tcx . sess . target . os . as_ref ( ) {
65
62
"linux" => {
66
- Self :: null_ptr_extern_statics ( this , & [
63
+ Self :: null_ptr_extern_statics ( ecx , & [
67
64
"__cxa_thread_atexit_impl" ,
68
65
"__clock_gettime64" ,
69
66
] ) ?;
70
- Self :: weak_symbol_extern_statics ( this , & [ "getrandom" , "statx" ] ) ?;
67
+ Self :: weak_symbol_extern_statics ( ecx , & [ "getrandom" , "statx" ] ) ?;
71
68
}
72
69
"freebsd" => {
73
- Self :: null_ptr_extern_statics ( this , & [ "__cxa_thread_atexit_impl" ] ) ?;
70
+ Self :: null_ptr_extern_statics ( ecx , & [ "__cxa_thread_atexit_impl" ] ) ?;
74
71
}
75
72
"android" => {
76
- Self :: null_ptr_extern_statics ( this , & [ "bsd_signal" ] ) ?;
77
- Self :: weak_symbol_extern_statics ( this , & [ "signal" , "getrandom" ] ) ?;
73
+ Self :: null_ptr_extern_statics ( ecx , & [ "bsd_signal" ] ) ?;
74
+ Self :: weak_symbol_extern_statics ( ecx , & [ "signal" , "getrandom" ] ) ?;
78
75
}
79
76
"windows" => {
80
77
// "_tls_used"
81
78
// This is some obscure hack that is part of the Windows TLS story. It's a `u8`.
82
- let val = ImmTy :: from_int ( 0 , this . machine . layouts . u8 ) ;
83
- Self :: alloc_extern_static ( this , "_tls_used" , val) ?;
79
+ let val = ImmTy :: from_int ( 0 , ecx . machine . layouts . u8 ) ;
80
+ Self :: alloc_extern_static ( ecx , "_tls_used" , val) ?;
84
81
}
85
82
"illumos" | "solaris" => {
86
- Self :: weak_symbol_extern_statics ( this , & [ "pthread_setname_np" ] ) ?;
83
+ Self :: weak_symbol_extern_statics ( ecx , & [ "pthread_setname_np" ] ) ?;
87
84
}
88
85
_ => { } // No "extern statics" supported on this target
89
86
}
0 commit comments