@@ -114,6 +114,8 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
114
114
None => self . tcx . item_name ( def_id) . as_str ( ) ,
115
115
} ;
116
116
117
+ let tcx = & { self . tcx . tcx } ;
118
+
117
119
// All these functions take raw pointers, so if we access memory directly
118
120
// (as opposed to through a place), we have to remember to erase any tag
119
121
// that might still hang around!
@@ -124,7 +126,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
124
126
if size == 0 {
125
127
self . write_null ( dest) ?;
126
128
} else {
127
- let align = self . tcx . data_layout . pointer_align ;
129
+ let align = self . tcx . data_layout . pointer_align . abi ;
128
130
let ptr = self . memory_mut ( ) . allocate ( Size :: from_bytes ( size) , align, MiriMemoryKind :: C . into ( ) ) ?;
129
131
self . write_scalar ( Scalar :: Ptr ( ptr. with_default_tag ( ) ) , dest) ?;
130
132
}
@@ -153,7 +155,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
153
155
let ptr = self . memory_mut ( )
154
156
. allocate (
155
157
Size :: from_bytes ( size) ,
156
- Align :: from_bytes ( align, align ) . unwrap ( ) ,
158
+ Align :: from_bytes ( align) . unwrap ( ) ,
157
159
MiriMemoryKind :: Rust . into ( )
158
160
) ?
159
161
. with_default_tag ( ) ;
@@ -171,11 +173,13 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
171
173
let ptr = self . memory_mut ( )
172
174
. allocate (
173
175
Size :: from_bytes ( size) ,
174
- Align :: from_bytes ( align, align ) . unwrap ( ) ,
176
+ Align :: from_bytes ( align) . unwrap ( ) ,
175
177
MiriMemoryKind :: Rust . into ( )
176
178
) ?
177
179
. with_default_tag ( ) ;
178
- self . memory_mut ( ) . write_repeat ( ptr. into ( ) , 0 , Size :: from_bytes ( size) ) ?;
180
+ self . memory_mut ( )
181
+ . get_mut ( ptr. alloc_id ) ?
182
+ . write_repeat ( tcx, ptr, 0 , Size :: from_bytes ( size) ) ?;
179
183
self . write_scalar ( Scalar :: Ptr ( ptr) , dest) ?;
180
184
}
181
185
"__rust_dealloc" => {
@@ -190,7 +194,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
190
194
}
191
195
self . memory_mut ( ) . deallocate (
192
196
ptr,
193
- Some ( ( Size :: from_bytes ( old_size) , Align :: from_bytes ( align, align ) . unwrap ( ) ) ) ,
197
+ Some ( ( Size :: from_bytes ( old_size) , Align :: from_bytes ( align) . unwrap ( ) ) ) ,
194
198
MiriMemoryKind :: Rust . into ( ) ,
195
199
) ?;
196
200
}
@@ -208,9 +212,9 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
208
212
let new_ptr = self . memory_mut ( ) . reallocate (
209
213
ptr,
210
214
Size :: from_bytes ( old_size) ,
211
- Align :: from_bytes ( align, align ) . unwrap ( ) ,
215
+ Align :: from_bytes ( align) . unwrap ( ) ,
212
216
Size :: from_bytes ( new_size) ,
213
- Align :: from_bytes ( align, align ) . unwrap ( ) ,
217
+ Align :: from_bytes ( align) . unwrap ( ) ,
214
218
MiriMemoryKind :: Rust . into ( ) ,
215
219
) ?;
216
220
self . write_scalar ( Scalar :: Ptr ( new_ptr. with_default_tag ( ) ) , dest) ?;
@@ -239,7 +243,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
239
243
"dlsym" => {
240
244
let _handle = self . read_scalar ( args[ 0 ] ) ?;
241
245
let symbol = self . read_scalar ( args[ 1 ] ) ?. to_ptr ( ) ?;
242
- let symbol_name = self . memory ( ) . read_c_str ( symbol) ?;
246
+ let symbol_name = self . memory ( ) . get ( symbol . alloc_id ) ? . read_c_str ( tcx , symbol) ?;
243
247
let err = format ! ( "bad c unicode symbol: {:?}" , symbol_name) ;
244
248
let symbol_name = :: std:: str:: from_utf8 ( symbol_name) . unwrap_or ( & err) ;
245
249
return err ! ( Unimplemented ( format!(
@@ -346,7 +350,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
346
350
"getenv" => {
347
351
let result = {
348
352
let name_ptr = self . read_scalar ( args[ 0 ] ) ?. to_ptr ( ) ?;
349
- let name = self . memory ( ) . read_c_str ( name_ptr) ?;
353
+ let name = self . memory ( ) . get ( name_ptr . alloc_id ) ? . read_c_str ( tcx , name_ptr) ?;
350
354
match self . machine . env_vars . get ( name) {
351
355
Some ( & var) => Scalar :: Ptr ( var) ,
352
356
None => Scalar :: ptr_null ( & * self . tcx ) ,
@@ -360,8 +364,8 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
360
364
{
361
365
let name_ptr = self . read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
362
366
if !name_ptr. is_null_ptr ( self ) {
363
- let name = self . memory ( ) . read_c_str ( name_ptr. to_ptr ( ) ?
364
- ) ?. to_owned ( ) ;
367
+ let name_ptr = name_ptr. to_ptr ( ) ?;
368
+ let name = self . memory ( ) . get ( name_ptr . alloc_id ) ? . read_c_str ( tcx , name_ptr ) ?. to_owned ( ) ;
365
369
if !name. is_empty ( ) && !name. contains ( & b'=' ) {
366
370
success = Some ( self . machine . env_vars . remove ( & name) ) ;
367
371
}
@@ -382,9 +386,10 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
382
386
{
383
387
let name_ptr = self . read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
384
388
let value_ptr = self . read_scalar ( args[ 1 ] ) ?. to_ptr ( ) ?;
385
- let value = self . memory ( ) . read_c_str ( value_ptr) ?;
389
+ let value = self . memory ( ) . get ( value_ptr . alloc_id ) ? . read_c_str ( tcx , value_ptr) ?;
386
390
if !name_ptr. is_null_ptr ( self ) {
387
- let name = self . memory ( ) . read_c_str ( name_ptr. to_ptr ( ) ?) ?;
391
+ let name_ptr = name_ptr. to_ptr ( ) ?;
392
+ let name = self . memory ( ) . get ( name_ptr. alloc_id ) ?. read_c_str ( tcx, name_ptr) ?;
388
393
if !name. is_empty ( ) && !name. contains ( & b'=' ) {
389
394
new = Some ( ( name. to_owned ( ) , value. to_owned ( ) ) ) ;
390
395
}
@@ -394,12 +399,15 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
394
399
// +1 for the null terminator
395
400
let value_copy = self . memory_mut ( ) . allocate (
396
401
Size :: from_bytes ( ( value. len ( ) + 1 ) as u64 ) ,
397
- Align :: from_bytes ( 1 , 1 ) . unwrap ( ) ,
402
+ Align :: from_bytes ( 1 ) . unwrap ( ) ,
398
403
MiriMemoryKind :: Env . into ( ) ,
399
404
) ?. with_default_tag ( ) ;
400
- self . memory_mut ( ) . write_bytes ( value_copy. into ( ) , & value) ?;
401
- let trailing_zero_ptr = value_copy. offset ( Size :: from_bytes ( value. len ( ) as u64 ) , self ) ?. into ( ) ;
402
- self . memory_mut ( ) . write_bytes ( trailing_zero_ptr, & [ 0 ] ) ?;
405
+ {
406
+ let alloc = self . memory_mut ( ) . get_mut ( value_copy. alloc_id ) ?;
407
+ alloc. write_bytes ( tcx, value_copy, & value) ?;
408
+ let trailing_zero_ptr = value_copy. offset ( Size :: from_bytes ( value. len ( ) as u64 ) , tcx) ?;
409
+ alloc. write_bytes ( tcx, trailing_zero_ptr, & [ 0 ] ) ?;
410
+ }
403
411
if let Some ( var) = self . machine . env_vars . insert (
404
412
name. to_owned ( ) ,
405
413
value_copy,
@@ -444,7 +452,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
444
452
445
453
"strlen" => {
446
454
let ptr = self . read_scalar ( args[ 0 ] ) ?. to_ptr ( ) ?;
447
- let n = self . memory ( ) . read_c_str ( ptr) ?. len ( ) ;
455
+ let n = self . memory ( ) . get ( ptr . alloc_id ) ? . read_c_str ( tcx , ptr) ?. len ( ) ;
448
456
self . write_scalar ( Scalar :: from_uint ( n as u64 , dest. layout . size ) , dest) ?;
449
457
}
450
458
@@ -469,10 +477,9 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
469
477
instance,
470
478
promoted : None ,
471
479
} ;
472
- let const_val = self . const_eval ( cid) ?;
473
- let value = const_val. unwrap_bits (
474
- self . tcx . tcx ,
475
- ty:: ParamEnv :: empty ( ) . and ( self . tcx . types . i32 ) ) as i32 ;
480
+ let const_val = self . const_eval_raw ( cid) ?;
481
+ let const_val = self . read_scalar ( const_val. into ( ) ) ?;
482
+ let value = const_val. to_i32 ( ) ?;
476
483
if value == name {
477
484
result = Some ( path_value) ;
478
485
break ;
@@ -508,13 +515,15 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
508
515
let key_layout = self . layout_of ( key_type) ?;
509
516
510
517
// Create key and write it into the memory where key_ptr wants it
511
- let key = self . machine . tls . create_tls_key ( dtor, & * self . tcx ) as u128 ;
518
+ let key = self . machine . tls . create_tls_key ( dtor, tcx) as u128 ;
512
519
if key_layout. size . bits ( ) < 128 && key >= ( 1u128 << key_layout. size . bits ( ) as u128 ) {
513
520
return err ! ( OutOfTls ) ;
514
521
}
515
- self . memory_mut ( ) . write_scalar (
522
+
523
+ self . memory ( ) . check_align ( key_ptr. into ( ) , key_layout. align . abi ) ?;
524
+ self . memory_mut ( ) . get_mut ( key_ptr. alloc_id ) ?. write_scalar (
525
+ tcx,
516
526
key_ptr,
517
- key_layout. align ,
518
527
Scalar :: from_uint ( key, key_layout. size ) . into ( ) ,
519
528
key_layout. size ,
520
529
) ?;
@@ -611,7 +620,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
611
620
// This just creates a key; Windows does not natively support TLS dtors.
612
621
613
622
// Create key and return it
614
- let key = self . machine . tls . create_tls_key ( None , & * self . tcx ) as u128 ;
623
+ let key = self . machine . tls . create_tls_key ( None , tcx) as u128 ;
615
624
616
625
// Figure out how large a TLS key actually is. This is c::DWORD.
617
626
if dest. layout . size . bits ( ) < 128 && key >= ( 1u128 << dest. layout . size . bits ( ) as u128 ) {
0 commit comments