@@ -114,6 +114,8 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
114114 None => self . tcx . item_name ( def_id) . as_str ( ) ,
115115 } ;
116116
117+ let tcx = & { self . tcx . tcx } ;
118+
117119 // All these functions take raw pointers, so if we access memory directly
118120 // (as opposed to through a place), we have to remember to erase any tag
119121 // that might still hang around!
@@ -175,7 +177,9 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
175177 MiriMemoryKind :: Rust . into ( )
176178 ) ?
177179 . 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) ) ?;
179183 self . write_scalar ( Scalar :: Ptr ( ptr) , dest) ?;
180184 }
181185 "__rust_dealloc" => {
@@ -239,7 +243,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
239243 "dlsym" => {
240244 let _handle = self . read_scalar ( args[ 0 ] ) ?;
241245 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) ?;
243247 let err = format ! ( "bad c unicode symbol: {:?}" , symbol_name) ;
244248 let symbol_name = :: std:: str:: from_utf8 ( symbol_name) . unwrap_or ( & err) ;
245249 return err ! ( Unimplemented ( format!(
@@ -346,7 +350,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
346350 "getenv" => {
347351 let result = {
348352 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) ?;
350354 match self . machine . env_vars . get ( name) {
351355 Some ( & var) => Scalar :: Ptr ( var) ,
352356 None => Scalar :: ptr_null ( & * self . tcx ) ,
@@ -360,8 +364,8 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
360364 {
361365 let name_ptr = self . read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
362366 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 ( ) ;
365369 if !name. is_empty ( ) && !name. contains ( & b'=' ) {
366370 success = Some ( self . machine . env_vars . remove ( & name) ) ;
367371 }
@@ -382,9 +386,10 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
382386 {
383387 let name_ptr = self . read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
384388 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) ?;
386390 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) ?;
388393 if !name. is_empty ( ) && !name. contains ( & b'=' ) {
389394 new = Some ( ( name. to_owned ( ) , value. to_owned ( ) ) ) ;
390395 }
@@ -397,9 +402,12 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
397402 Align :: from_bytes ( 1 ) . unwrap ( ) ,
398403 MiriMemoryKind :: Env . into ( ) ,
399404 ) ?. 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+ }
403411 if let Some ( var) = self . machine . env_vars . insert (
404412 name. to_owned ( ) ,
405413 value_copy,
@@ -444,7 +452,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
444452
445453 "strlen" => {
446454 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 ( ) ;
448456 self . write_scalar ( Scalar :: from_uint ( n as u64 , dest. layout . size ) , dest) ?;
449457 }
450458
@@ -507,13 +515,15 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
507515 let key_layout = self . layout_of ( key_type) ?;
508516
509517 // 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 ;
511519 if key_layout. size . bits ( ) < 128 && key >= ( 1u128 << key_layout. size . bits ( ) as u128 ) {
512520 return err ! ( OutOfTls ) ;
513521 }
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,
515526 key_ptr,
516- key_layout. align . abi ,
517527 Scalar :: from_uint ( key, key_layout. size ) . into ( ) ,
518528 key_layout. size ,
519529 ) ?;
@@ -610,7 +620,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
610620 // This just creates a key; Windows does not natively support TLS dtors.
611621
612622 // 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 ;
614624
615625 // Figure out how large a TLS key actually is. This is c::DWORD.
616626 if dest. layout . size . bits ( ) < 128 && key >= ( 1u128 << dest. layout . size . bits ( ) as u128 ) {
0 commit comments