@@ -111,6 +111,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
111
111
112
112
// Querying system information
113
113
"GetSystemInfo" => {
114
+ use crate :: rustc_middle:: ty:: { layout:: LayoutOf , TyKind , UintTy } ;
115
+
114
116
let [ system_info] =
115
117
this. check_shim ( abi, Abi :: System { unwind : false } , link_name, args) ?;
116
118
let system_info = this. deref_operand ( system_info) ?;
@@ -119,21 +121,28 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
119
121
system_info. ptr ,
120
122
iter:: repeat ( 0u8 ) . take ( system_info. layout . size . bytes ( ) as usize ) ,
121
123
) ?;
122
- let dword_size = Size :: from_bytes ( 4 ) ;
123
-
124
- // In WinApi SYSTEM_INFO's first field is a 4-byte union, but num_cpus
125
- // inlines it as two 2-byte fields. In num_cpus case all fields are offset by 1
126
- // compared to WinApi. See https://github.com/rust-lang/miri/issues/2136#issuecomment-1133661262.
127
- let first_field = this. mplace_field ( & system_info, 0 ) ?;
128
- let offset = if first_field. layout . size . bytes ( ) == 2 { 1 } else { 0 } ;
129
-
130
- let page_size = this. mplace_field ( & system_info, 1 + offset) ?;
131
- let num_cpus = this. mplace_field ( & system_info, 5 + offset) ?;
132
-
124
+ // Set selected fields.
125
+ let dword_ty = this. tcx . mk_ty ( TyKind :: Uint ( UintTy :: U32 ) ) ;
126
+ let dword_layout = this. layout_of ( dword_ty) ?;
133
127
// Set page size.
134
- this. write_scalar ( Scalar :: from_int ( PAGE_SIZE , dword_size) , & page_size. into ( ) ) ?;
128
+ let page_size = system_info. offset (
129
+ Size :: from_bytes ( 4 ) ,
130
+ MemPlaceMeta :: None ,
131
+ dword_layout,
132
+ & this. tcx ,
133
+ ) ?;
134
+ this. write_scalar (
135
+ Scalar :: from_int ( PAGE_SIZE , dword_layout. size ) ,
136
+ & page_size. into ( ) ,
137
+ ) ?;
135
138
// Set number of processors.
136
- this. write_scalar ( Scalar :: from_int ( NUM_CPUS , dword_size) , & num_cpus. into ( ) ) ?;
139
+ let num_cpus = system_info. offset (
140
+ Size :: from_bytes ( 32 ) ,
141
+ MemPlaceMeta :: None ,
142
+ dword_layout,
143
+ & this. tcx ,
144
+ ) ?;
145
+ this. write_scalar ( Scalar :: from_int ( NUM_CPUS , dword_layout. size ) , & num_cpus. into ( ) ) ?;
137
146
}
138
147
139
148
// Thread-local storage
0 commit comments