@@ -144,13 +144,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
144
144
let ret = ret. expect ( "dest is `Some` but ret is `None`" ) ;
145
145
match link_name {
146
146
"malloc" => {
147
- let size = this. read_scalar ( args[ 0 ] ) ?. to_usize ( this) ?;
147
+ let size = this. read_scalar ( args[ 0 ] ) ?. to_machine_usize ( this) ?;
148
148
let res = this. malloc ( size, /*zero_init:*/ false , MiriMemoryKind :: C ) ;
149
149
this. write_scalar ( res, dest) ?;
150
150
}
151
151
"calloc" => {
152
- let items = this. read_scalar ( args[ 0 ] ) ?. to_usize ( this) ?;
153
- let len = this. read_scalar ( args[ 1 ] ) ?. to_usize ( this) ?;
152
+ let items = this. read_scalar ( args[ 0 ] ) ?. to_machine_usize ( this) ?;
153
+ let len = this. read_scalar ( args[ 1 ] ) ?. to_machine_usize ( this) ?;
154
154
let size = items
155
155
. checked_mul ( len)
156
156
. ok_or_else ( || err_panic ! ( Overflow ( mir:: BinOp :: Mul ) ) ) ?;
@@ -159,8 +159,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
159
159
}
160
160
"posix_memalign" => {
161
161
let ret = this. deref_operand ( args[ 0 ] ) ?;
162
- let align = this. read_scalar ( args[ 1 ] ) ?. to_usize ( this) ?;
163
- let size = this. read_scalar ( args[ 2 ] ) ?. to_usize ( this) ?;
162
+ let align = this. read_scalar ( args[ 1 ] ) ?. to_machine_usize ( this) ?;
163
+ let size = this. read_scalar ( args[ 2 ] ) ?. to_machine_usize ( this) ?;
164
164
// Align must be power of 2, and also at least ptr-sized (POSIX rules).
165
165
if !align. is_power_of_two ( ) {
166
166
throw_unsup ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
@@ -190,14 +190,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
190
190
}
191
191
"realloc" => {
192
192
let old_ptr = this. read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
193
- let new_size = this. read_scalar ( args[ 1 ] ) ?. to_usize ( this) ?;
193
+ let new_size = this. read_scalar ( args[ 1 ] ) ?. to_machine_usize ( this) ?;
194
194
let res = this. realloc ( old_ptr, new_size, MiriMemoryKind :: C ) ?;
195
195
this. write_scalar ( res, dest) ?;
196
196
}
197
197
198
198
"__rust_alloc" => {
199
- let size = this. read_scalar ( args[ 0 ] ) ?. to_usize ( this) ?;
200
- let align = this. read_scalar ( args[ 1 ] ) ?. to_usize ( this) ?;
199
+ let size = this. read_scalar ( args[ 0 ] ) ?. to_machine_usize ( this) ?;
200
+ let align = this. read_scalar ( args[ 1 ] ) ?. to_machine_usize ( this) ?;
201
201
if size == 0 {
202
202
throw_unsup ! ( HeapAllocZeroBytes ) ;
203
203
}
@@ -212,8 +212,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
212
212
this. write_scalar ( Scalar :: Ptr ( ptr) , dest) ?;
213
213
}
214
214
"__rust_alloc_zeroed" => {
215
- let size = this. read_scalar ( args[ 0 ] ) ?. to_usize ( this) ?;
216
- let align = this. read_scalar ( args[ 1 ] ) ?. to_usize ( this) ?;
215
+ let size = this. read_scalar ( args[ 0 ] ) ?. to_machine_usize ( this) ?;
216
+ let align = this. read_scalar ( args[ 1 ] ) ?. to_machine_usize ( this) ?;
217
217
if size == 0 {
218
218
throw_unsup ! ( HeapAllocZeroBytes ) ;
219
219
}
@@ -233,8 +233,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
233
233
}
234
234
"__rust_dealloc" => {
235
235
let ptr = this. read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
236
- let old_size = this. read_scalar ( args[ 1 ] ) ?. to_usize ( this) ?;
237
- let align = this. read_scalar ( args[ 2 ] ) ?. to_usize ( this) ?;
236
+ let old_size = this. read_scalar ( args[ 1 ] ) ?. to_machine_usize ( this) ?;
237
+ let align = this. read_scalar ( args[ 2 ] ) ?. to_machine_usize ( this) ?;
238
238
if old_size == 0 {
239
239
throw_unsup ! ( HeapAllocZeroBytes ) ;
240
240
}
@@ -253,9 +253,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
253
253
}
254
254
"__rust_realloc" => {
255
255
let ptr = this. read_scalar ( args[ 0 ] ) ?. to_ptr ( ) ?;
256
- let old_size = this. read_scalar ( args[ 1 ] ) ?. to_usize ( this) ?;
257
- let align = this. read_scalar ( args[ 2 ] ) ?. to_usize ( this) ?;
258
- let new_size = this. read_scalar ( args[ 3 ] ) ?. to_usize ( this) ?;
256
+ let old_size = this. read_scalar ( args[ 1 ] ) ?. to_machine_usize ( this) ?;
257
+ let align = this. read_scalar ( args[ 2 ] ) ?. to_machine_usize ( this) ?;
258
+ let new_size = this. read_scalar ( args[ 3 ] ) ?. to_machine_usize ( this) ?;
259
259
if old_size == 0 || new_size == 0 {
260
260
throw_unsup ! ( HeapAllocZeroBytes ) ;
261
261
}
@@ -277,11 +277,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
277
277
let sys_getrandom = this
278
278
. eval_path_scalar ( & [ "libc" , "SYS_getrandom" ] ) ?
279
279
. expect ( "Failed to get libc::SYS_getrandom" )
280
- . to_usize ( this) ?;
280
+ . to_machine_usize ( this) ?;
281
281
282
282
// `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)`
283
283
// is called if a `HashMap` is created the regular way (e.g. HashMap<K, V>).
284
- match this. read_scalar ( args[ 0 ] ) ?. to_usize ( this) ? {
284
+ match this. read_scalar ( args[ 0 ] ) ?. to_machine_usize ( this) ? {
285
285
id if id == sys_getrandom => {
286
286
// The first argument is the syscall id,
287
287
// so skip over it.
@@ -357,7 +357,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
357
357
"memcmp" => {
358
358
let left = this. read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
359
359
let right = this. read_scalar ( args[ 1 ] ) ?. not_undef ( ) ?;
360
- let n = Size :: from_bytes ( this. read_scalar ( args[ 2 ] ) ?. to_usize ( this) ?) ;
360
+ let n = Size :: from_bytes ( this. read_scalar ( args[ 2 ] ) ?. to_machine_usize ( this) ?) ;
361
361
362
362
let result = {
363
363
let left_bytes = this. memory . read_bytes ( left, n) ?;
@@ -377,7 +377,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
377
377
"memrchr" => {
378
378
let ptr = this. read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
379
379
let val = this. read_scalar ( args[ 1 ] ) ?. to_i32 ( ) ? as u8 ;
380
- let num = this. read_scalar ( args[ 2 ] ) ?. to_usize ( this) ?;
380
+ let num = this. read_scalar ( args[ 2 ] ) ?. to_machine_usize ( this) ?;
381
381
if let Some ( idx) = this
382
382
. memory
383
383
. read_bytes ( ptr, Size :: from_bytes ( num) ) ?
@@ -395,7 +395,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
395
395
"memchr" => {
396
396
let ptr = this. read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
397
397
let val = this. read_scalar ( args[ 1 ] ) ?. to_i32 ( ) ? as u8 ;
398
- let num = this. read_scalar ( args[ 2 ] ) ?. to_usize ( this) ?;
398
+ let num = this. read_scalar ( args[ 2 ] ) ?. to_machine_usize ( this) ?;
399
399
let idx = this
400
400
. memory
401
401
. read_bytes ( ptr, Size :: from_bytes ( num) ) ?
@@ -462,7 +462,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
462
462
"write" => {
463
463
let fd = this. read_scalar ( args[ 0 ] ) ?. to_i32 ( ) ?;
464
464
let buf = this. read_scalar ( args[ 1 ] ) ?. not_undef ( ) ?;
465
- let n = this. read_scalar ( args[ 2 ] ) ?. to_usize ( tcx) ?;
465
+ let n = this. read_scalar ( args[ 2 ] ) ?. to_machine_usize ( tcx) ?;
466
466
trace ! ( "Called write({:?}, {:?}, {:?})" , fd, buf, n) ;
467
467
let result = if fd == 1 || fd == 2 {
468
468
// stdout/stderr
@@ -771,7 +771,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
771
771
this. write_scalar ( this. machine . argv . expect ( "machine must be initialized" ) , dest) ?;
772
772
}
773
773
"SecRandomCopyBytes" => {
774
- let len = this. read_scalar ( args[ 1 ] ) ?. to_usize ( this) ?;
774
+ let len = this. read_scalar ( args[ 1 ] ) ?. to_machine_usize ( this) ?;
775
775
let ptr = this. read_scalar ( args[ 2 ] ) ?. not_undef ( ) ?;
776
776
this. gen_random ( ptr, len as usize ) ?;
777
777
this. write_null ( dest) ?;
@@ -786,25 +786,25 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
786
786
this. write_scalar ( Scalar :: from_int ( 1 , this. pointer_size ( ) ) , dest) ?;
787
787
}
788
788
"HeapAlloc" => {
789
- let _handle = this. read_scalar ( args[ 0 ] ) ?. to_isize ( this) ?;
789
+ let _handle = this. read_scalar ( args[ 0 ] ) ?. to_machine_isize ( this) ?;
790
790
let flags = this. read_scalar ( args[ 1 ] ) ?. to_u32 ( ) ?;
791
- let size = this. read_scalar ( args[ 2 ] ) ?. to_usize ( this) ?;
791
+ let size = this. read_scalar ( args[ 2 ] ) ?. to_machine_usize ( this) ?;
792
792
let zero_init = ( flags & 0x00000008 ) != 0 ; // HEAP_ZERO_MEMORY
793
793
let res = this. malloc ( size, zero_init, MiriMemoryKind :: WinHeap ) ;
794
794
this. write_scalar ( res, dest) ?;
795
795
}
796
796
"HeapFree" => {
797
- let _handle = this. read_scalar ( args[ 0 ] ) ?. to_isize ( this) ?;
797
+ let _handle = this. read_scalar ( args[ 0 ] ) ?. to_machine_isize ( this) ?;
798
798
let _flags = this. read_scalar ( args[ 1 ] ) ?. to_u32 ( ) ?;
799
799
let ptr = this. read_scalar ( args[ 2 ] ) ?. not_undef ( ) ?;
800
800
this. free ( ptr, MiriMemoryKind :: WinHeap ) ?;
801
801
this. write_scalar ( Scalar :: from_int ( 1 , Size :: from_bytes ( 4 ) ) , dest) ?;
802
802
}
803
803
"HeapReAlloc" => {
804
- let _handle = this. read_scalar ( args[ 0 ] ) ?. to_isize ( this) ?;
804
+ let _handle = this. read_scalar ( args[ 0 ] ) ?. to_machine_isize ( this) ?;
805
805
let _flags = this. read_scalar ( args[ 1 ] ) ?. to_u32 ( ) ?;
806
806
let ptr = this. read_scalar ( args[ 2 ] ) ?. not_undef ( ) ?;
807
- let size = this. read_scalar ( args[ 3 ] ) ?. to_usize ( this) ?;
807
+ let size = this. read_scalar ( args[ 3 ] ) ?. to_machine_usize ( this) ?;
808
808
let res = this. realloc ( ptr, size, MiriMemoryKind :: WinHeap ) ?;
809
809
this. write_scalar ( res, dest) ?;
810
810
}
@@ -883,7 +883,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
883
883
this. write_scalar ( Scalar :: from_int ( which, this. pointer_size ( ) ) , dest) ?;
884
884
}
885
885
"WriteFile" => {
886
- let handle = this. read_scalar ( args[ 0 ] ) ?. to_isize ( this) ?;
886
+ let handle = this. read_scalar ( args[ 0 ] ) ?. to_machine_isize ( this) ?;
887
887
let buf = this. read_scalar ( args[ 1 ] ) ?. not_undef ( ) ?;
888
888
let n = this. read_scalar ( args[ 2 ] ) ?. to_u32 ( ) ?;
889
889
let written_place = this. deref_operand ( args[ 3 ] ) ?;
@@ -973,7 +973,7 @@ fn linux_getrandom<'tcx>(
973
973
dest : PlaceTy < ' tcx , Tag > ,
974
974
) -> InterpResult < ' tcx > {
975
975
let ptr = this. read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
976
- let len = this. read_scalar ( args[ 1 ] ) ?. to_usize ( this) ?;
976
+ let len = this. read_scalar ( args[ 1 ] ) ?. to_machine_usize ( this) ?;
977
977
978
978
// The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
979
979
// neither of which have any effect on our current PRNG.
0 commit comments