@@ -8,6 +8,7 @@ use rustc_target::spec::abi::Abi;
8
8
use crate :: * ;
9
9
use shims:: foreign_items:: EmulateByNameResult ;
10
10
use shims:: windows:: sync:: EvalContextExt as _;
11
+ use smallvec:: SmallVec ;
11
12
12
13
impl < ' mir , ' tcx : ' mir > EvalContextExt < ' mir , ' tcx > for crate :: MiriEvalContext < ' mir , ' tcx > { }
13
14
pub trait EvalContextExt < ' mir , ' tcx : ' mir > : crate :: MiriEvalContextExt < ' mir , ' tcx > {
@@ -122,11 +123,42 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
122
123
iter:: repeat ( 0u8 ) . take ( system_info. layout . size . bytes ( ) as usize ) ,
123
124
) ?;
124
125
// Set selected fields.
126
+ let word_ty = this. tcx . mk_ty ( TyKind :: Uint ( UintTy :: U16 ) ) ;
125
127
let dword_ty = this. tcx . mk_ty ( TyKind :: Uint ( UintTy :: U32 ) ) ;
128
+ let usize_ty = this. tcx . mk_ty ( TyKind :: Uint ( UintTy :: Usize ) ) ;
129
+ let word_layout = this. layout_of ( word_ty) ?;
126
130
let dword_layout = this. layout_of ( dword_ty) ?;
131
+ let usize_layout = this. layout_of ( usize_ty) ?;
132
+
133
+ // Using `mplace_field` is error-prone, see: https://github.com/rust-lang/miri/issues/2136.
134
+ // Pointer fields have different sizes on different targets.
135
+ // To avoid all these issue we calculate the offsets dynamically.
136
+ let field_sizes = [
137
+ word_layout. size , // 0, wProcessorArchitecture : WORD
138
+ word_layout. size , // 1, wReserved : WORD
139
+ dword_layout. size , // 2, dwPageSize : DWORD
140
+ usize_layout. size , // 3, lpMinimumApplicationAddress : LPVOID
141
+ usize_layout. size , // 4, lpMaximumApplicationAddress : LPVOID
142
+ usize_layout. size , // 5, dwActiveProcessorMask : DWORD_PTR
143
+ dword_layout. size , // 6, dwNumberOfProcessors : DWORD
144
+ dword_layout. size , // 7, dwProcessorType : DWORD
145
+ dword_layout. size , // 8, dwAllocationGranularity : DWORD
146
+ word_layout. size , // 9, wProcessorLevel : WORD
147
+ word_layout. size , // 10, wProcessorRevision : WORD
148
+ ] ;
149
+ let field_offsets: SmallVec < [ Size ; 11 ] > = field_sizes
150
+ . iter ( )
151
+ . copied ( )
152
+ . scan ( Size :: ZERO , |a, x| {
153
+ let res = Some ( * a) ;
154
+ * a += x;
155
+ res
156
+ } )
157
+ . collect ( ) ;
158
+
127
159
// Set page size.
128
160
let page_size = system_info. offset (
129
- Size :: from_bytes ( 4 ) ,
161
+ field_offsets [ 2 ] ,
130
162
MemPlaceMeta :: None ,
131
163
dword_layout,
132
164
& this. tcx ,
@@ -137,7 +169,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
137
169
) ?;
138
170
// Set number of processors.
139
171
let num_cpus = system_info. offset (
140
- Size :: from_bytes ( 32 ) ,
172
+ field_offsets [ 6 ] ,
141
173
MemPlaceMeta :: None ,
142
174
dword_layout,
143
175
& this. tcx ,
0 commit comments