@@ -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!
@@ -124,7 +126,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
124126 if size == 0 {
125127 self . write_null ( dest) ?;
126128 } else {
127- let align = self . tcx . data_layout . pointer_align ;
129+ let align = self . tcx . data_layout . pointer_align . abi ;
128130 let ptr = self . memory_mut ( ) . allocate ( Size :: from_bytes ( size) , align, MiriMemoryKind :: C . into ( ) ) ?;
129131 self . write_scalar ( Scalar :: Ptr ( ptr. with_default_tag ( ) ) , dest) ?;
130132 }
@@ -153,7 +155,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
153155 let ptr = self . memory_mut ( )
154156 . allocate (
155157 Size :: from_bytes ( size) ,
156- Align :: from_bytes ( align, align ) . unwrap ( ) ,
158+ Align :: from_bytes ( align) . unwrap ( ) ,
157159 MiriMemoryKind :: Rust . into ( )
158160 ) ?
159161 . with_default_tag ( ) ;
@@ -171,11 +173,13 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
171173 let ptr = self . memory_mut ( )
172174 . allocate (
173175 Size :: from_bytes ( size) ,
174- Align :: from_bytes ( align, align ) . unwrap ( ) ,
176+ Align :: from_bytes ( align) . unwrap ( ) ,
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" => {
@@ -190,7 +194,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
190194 }
191195 self . memory_mut ( ) . deallocate (
192196 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 ( ) ) ) ,
194198 MiriMemoryKind :: Rust . into ( ) ,
195199 ) ?;
196200 }
@@ -208,9 +212,9 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
208212 let new_ptr = self . memory_mut ( ) . reallocate (
209213 ptr,
210214 Size :: from_bytes ( old_size) ,
211- Align :: from_bytes ( align, align ) . unwrap ( ) ,
215+ Align :: from_bytes ( align) . unwrap ( ) ,
212216 Size :: from_bytes ( new_size) ,
213- Align :: from_bytes ( align, align ) . unwrap ( ) ,
217+ Align :: from_bytes ( align) . unwrap ( ) ,
214218 MiriMemoryKind :: Rust . into ( ) ,
215219 ) ?;
216220 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
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 }
@@ -394,12 +399,15 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
394399 // +1 for the null terminator
395400 let value_copy = self . memory_mut ( ) . allocate (
396401 Size :: from_bytes ( ( value. len ( ) + 1 ) as u64 ) ,
397- Align :: from_bytes ( 1 , 1 ) . unwrap ( ) ,
402+ 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
@@ -469,10 +477,9 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
469477 instance,
470478 promoted : None ,
471479 } ;
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 ( ) ?;
476483 if value == name {
477484 result = Some ( path_value) ;
478485 break ;
@@ -508,13 +515,15 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
508515 let key_layout = self . layout_of ( key_type) ?;
509516
510517 // 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 ;
512519 if key_layout. size . bits ( ) < 128 && key >= ( 1u128 << key_layout. size . bits ( ) as u128 ) {
513520 return err ! ( OutOfTls ) ;
514521 }
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,
516526 key_ptr,
517- key_layout. align ,
518527 Scalar :: from_uint ( key, key_layout. size ) . into ( ) ,
519528 key_layout. size ,
520529 ) ?;
@@ -611,7 +620,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
611620 // This just creates a key; Windows does not natively support TLS dtors.
612621
613622 // 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 ;
615624
616625 // Figure out how large a TLS key actually is. This is c::DWORD.
617626 if dest. layout . size . bits ( ) < 128 && key >= ( 1u128 << dest. layout . size . bits ( ) as u128 ) {
0 commit comments