@@ -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!
@@ -175,7 +177,9 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
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" => {
@@ -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
}
@@ -397,9 +402,12 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
397
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
@@ -507,13 +515,15 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
507
515
let key_layout = self . layout_of ( key_type) ?;
508
516
509
517
// Create key and write it into the memory where key_ptr wants it
510
- 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 ;
511
519
if key_layout. size . bits ( ) < 128 && key >= ( 1u128 << key_layout. size . bits ( ) as u128 ) {
512
520
return err ! ( OutOfTls ) ;
513
521
}
514
- 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,
515
526
key_ptr,
516
- key_layout. align . abi ,
517
527
Scalar :: from_uint ( key, key_layout. size ) . into ( ) ,
518
528
key_layout. size ,
519
529
) ?;
@@ -610,7 +620,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
610
620
// This just creates a key; Windows does not natively support TLS dtors.
611
621
612
622
// Create key and return it
613
- 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 ;
614
624
615
625
// Figure out how large a TLS key actually is. This is c::DWORD.
616
626
if dest. layout . size . bits ( ) < 128 && key >= ( 1u128 << dest. layout . size . bits ( ) as u128 ) {
0 commit comments