@@ -30,7 +30,7 @@ use rand::SeedableRng;
30
30
31
31
use rustc:: ty:: { self , TyCtxt , query:: TyCtxtAt } ;
32
32
use rustc:: ty:: layout:: { LayoutOf , Size , Align } ;
33
- use rustc:: hir:: { self , def_id:: DefId } ;
33
+ use rustc:: hir:: def_id:: DefId ;
34
34
use rustc:: mir;
35
35
pub use rustc_mir:: interpret:: * ;
36
36
// Resolve ambiguity.
@@ -113,7 +113,7 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
113
113
114
114
// Return value (in static memory so that it does not count as leak).
115
115
let ret = ecx. layout_of ( start_mir. return_ty ( ) ) ?;
116
- let ret_ptr = ecx. allocate ( ret, MiriMemoryKind :: MutStatic . into ( ) ) ;
116
+ let ret_ptr = ecx. allocate ( ret, MiriMemoryKind :: Static . into ( ) ) ;
117
117
118
118
// Push our stack frame.
119
119
ecx. push_stack_frame (
@@ -128,7 +128,7 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
128
128
let mut args = ecx. frame ( ) . mir . args_iter ( ) ;
129
129
130
130
// First argument: pointer to `main()`.
131
- let main_ptr = ecx. memory_mut ( ) . create_fn_alloc ( main_instance) . with_default_tag ( ) ;
131
+ let main_ptr = ecx. memory_mut ( ) . create_fn_alloc ( main_instance) ;
132
132
let dest = ecx. eval_place ( & mir:: Place :: Base ( mir:: PlaceBase :: Local ( args. next ( ) . unwrap ( ) ) ) ) ?;
133
133
ecx. write_scalar ( Scalar :: Ptr ( main_ptr) , dest) ?;
134
134
@@ -162,7 +162,7 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
162
162
// Add `0` terminator.
163
163
let mut arg = arg. into_bytes ( ) ;
164
164
arg. push ( 0 ) ;
165
- argvs. push ( ecx. memory_mut ( ) . allocate_static_bytes ( arg. as_slice ( ) ) . with_default_tag ( ) ) ;
165
+ argvs. push ( ecx. memory_mut ( ) . allocate_static_bytes ( arg. as_slice ( ) , MiriMemoryKind :: Static . into ( ) ) ) ;
166
166
}
167
167
// Make an array with all these pointers, in the Miri memory.
168
168
let argvs_layout = ecx. layout_of ( ecx. tcx . mk_array ( ecx. tcx . mk_imm_ptr ( ecx. tcx . types . u8 ) , argvs. len ( ) as u64 ) ) ?;
@@ -299,8 +299,8 @@ pub enum MiriMemoryKind {
299
299
C ,
300
300
/// Part of env var emulation.
301
301
Env ,
302
- /// Mutable statics .
303
- MutStatic ,
302
+ /// Statics .
303
+ Static ,
304
304
}
305
305
306
306
impl Into < MemoryKind < MiriMemoryKind > > for MiriMemoryKind {
@@ -316,7 +316,7 @@ impl MayLeak for MiriMemoryKind {
316
316
use self :: MiriMemoryKind :: * ;
317
317
match self {
318
318
Rust | C => false ,
319
- Env | MutStatic => true ,
319
+ Env | Static => true ,
320
320
}
321
321
}
322
322
}
@@ -392,7 +392,7 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
392
392
393
393
type MemoryMap = MonoHashMap < AllocId , ( MemoryKind < MiriMemoryKind > , Allocation < Tag , Self :: AllocExtra > ) > ;
394
394
395
- const STATIC_KIND : Option < MiriMemoryKind > = Some ( MiriMemoryKind :: MutStatic ) ;
395
+ const STATIC_KIND : Option < MiriMemoryKind > = Some ( MiriMemoryKind :: Static ) ;
396
396
397
397
#[ inline( always) ]
398
398
fn enforce_validity ( ecx : & InterpretCx < ' a , ' mir , ' tcx , Self > ) -> bool {
@@ -476,8 +476,7 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
476
476
fn find_foreign_static (
477
477
def_id : DefId ,
478
478
tcx : TyCtxtAt < ' a , ' tcx , ' tcx > ,
479
- memory_extra : & Self :: MemoryExtra ,
480
- ) -> EvalResult < ' tcx , Cow < ' tcx , Allocation < Tag , Self :: AllocExtra > > > {
479
+ ) -> EvalResult < ' tcx , Cow < ' tcx , Allocation > > {
481
480
let attrs = tcx. get_attrs ( def_id) ;
482
481
let link_name = match attr:: first_attr_value_str_by_name ( & attrs, sym:: link_name) {
483
482
Some ( name) => name. as_str ( ) ,
@@ -489,8 +488,7 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
489
488
// This should be all-zero, pointer-sized.
490
489
let size = tcx. data_layout . pointer_size ;
491
490
let data = vec ! [ 0 ; size. bytes( ) as usize ] ;
492
- let extra = Stacks :: new ( size, Tag :: default ( ) , Rc :: clone ( memory_extra) ) ;
493
- Allocation :: from_bytes ( & data, tcx. data_layout . pointer_align . abi , extra)
491
+ Allocation :: from_bytes ( & data, tcx. data_layout . pointer_align . abi )
494
492
}
495
493
_ => return err ! ( Unimplemented (
496
494
format!( "can't access foreign static: {}" , link_name) ,
@@ -506,47 +504,48 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
506
504
Ok ( ( ) )
507
505
}
508
506
509
- fn adjust_static_allocation < ' b > (
510
- alloc : & ' b Allocation ,
507
+ fn tag_allocation < ' b > (
508
+ id : AllocId ,
509
+ alloc : Cow < ' b , Allocation > ,
510
+ kind : Option < MemoryKind < Self :: MemoryKinds > > ,
511
511
memory_extra : & Self :: MemoryExtra ,
512
- ) -> Cow < ' b , Allocation < Tag , Self :: AllocExtra > > {
513
- let extra = Stacks :: new (
512
+ ) -> ( Cow < ' b , Allocation < Self :: PointerTag , Self :: AllocExtra > > , Self :: PointerTag ) {
513
+ let kind = kind. expect ( "we set our STATIC_KIND so this cannot be None" ) ;
514
+ let alloc = alloc. into_owned ( ) ;
515
+ let ( extra, base_tag) = Stacks :: new_allocation (
516
+ id,
514
517
Size :: from_bytes ( alloc. bytes . len ( ) as u64 ) ,
515
- Tag :: default ( ) ,
516
518
Rc :: clone ( memory_extra) ,
519
+ kind,
517
520
) ;
521
+ if kind != MiriMemoryKind :: Static . into ( ) {
522
+ assert ! ( alloc. relocations. is_empty( ) , "Only statics can come initialized with inner pointers" ) ;
523
+ // Now we can rely on the inner pointers being static, too.
524
+ }
525
+ let mut memory_extra = memory_extra. borrow_mut ( ) ;
518
526
let alloc: Allocation < Tag , Self :: AllocExtra > = Allocation {
519
- bytes : alloc. bytes . clone ( ) ,
527
+ bytes : alloc. bytes ,
520
528
relocations : Relocations :: from_presorted (
521
529
alloc. relocations . iter ( )
522
- . map ( |& ( offset, ( ( ) , alloc) ) | ( offset, ( Tag :: default ( ) , alloc) ) )
530
+ // The allocations in the relocations (pointers stored *inside* this allocation)
531
+ // all get the base pointer tag.
532
+ . map ( |& ( offset, ( ( ) , alloc) ) | ( offset, ( memory_extra. static_base_ptr ( alloc) , alloc) ) )
523
533
. collect ( )
524
534
) ,
525
- undef_mask : alloc. undef_mask . clone ( ) ,
535
+ undef_mask : alloc. undef_mask ,
526
536
align : alloc. align ,
527
537
mutability : alloc. mutability ,
528
538
extra,
529
539
} ;
530
- Cow :: Owned ( alloc)
531
- }
532
-
533
- #[ inline( always) ]
534
- fn new_allocation (
535
- size : Size ,
536
- extra : & Self :: MemoryExtra ,
537
- kind : MemoryKind < MiriMemoryKind > ,
538
- ) -> ( Self :: AllocExtra , Self :: PointerTag ) {
539
- Stacks :: new_allocation ( size, extra, kind)
540
+ ( Cow :: Owned ( alloc) , base_tag)
540
541
}
541
542
542
543
#[ inline( always) ]
543
- fn tag_dereference (
544
- _ecx : & InterpretCx < ' a , ' mir , ' tcx , Self > ,
545
- place : MPlaceTy < ' tcx , Tag > ,
546
- _mutability : Option < hir:: Mutability > ,
547
- ) -> EvalResult < ' tcx , Scalar < Tag > > {
548
- // Nothing happens.
549
- Ok ( place. ptr )
544
+ fn tag_static_base_pointer (
545
+ id : AllocId ,
546
+ memory_extra : & Self :: MemoryExtra ,
547
+ ) -> Self :: PointerTag {
548
+ memory_extra. borrow_mut ( ) . static_base_ptr ( id)
550
549
}
551
550
552
551
#[ inline( always) ]
0 commit comments