@@ -20,6 +20,8 @@ mod tls;
20
20
mod range_map;
21
21
mod mono_hash_map;
22
22
mod stacked_borrows;
23
+ mod intptrcast;
24
+ mod memory;
23
25
24
26
use std:: collections:: HashMap ;
25
27
use std:: borrow:: Cow ;
@@ -48,6 +50,7 @@ use crate::range_map::RangeMap;
48
50
pub use crate :: helpers:: { EvalContextExt as HelpersEvalContextExt } ;
49
51
use crate :: mono_hash_map:: MonoHashMap ;
50
52
pub use crate :: stacked_borrows:: { EvalContextExt as StackedBorEvalContextExt } ;
53
+ use crate :: memory:: AllocExtra ;
51
54
52
55
// Used by priroda.
53
56
pub use crate :: stacked_borrows:: { Tag , Permission , Stack , Stacks , Item } ;
@@ -79,9 +82,12 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
79
82
let mut ecx = InterpretCx :: new (
80
83
tcx. at ( syntax:: source_map:: DUMMY_SP ) ,
81
84
ty:: ParamEnv :: reveal_all ( ) ,
82
- Evaluator :: new ( config. validate , config . seed ) ,
85
+ Evaluator :: new ( config. validate ) ,
83
86
) ;
84
87
88
+ // FIXME: InterpretCx::new should take an initial MemoryExtra
89
+ ecx. memory_mut ( ) . extra . rng = config. seed . map ( StdRng :: seed_from_u64) ;
90
+
85
91
let main_instance = ty:: Instance :: mono ( ecx. tcx . tcx , main_id) ;
86
92
let main_mir = ecx. load_mir ( main_instance. def ) ?;
87
93
@@ -205,7 +211,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
205
211
cur_ptr = cur_ptr. offset ( char_size, tcx) ?;
206
212
}
207
213
}
208
-
214
+
209
215
assert ! ( args. next( ) . is_none( ) , "start lang item has more arguments than expected" ) ;
210
216
211
217
Ok ( ecx)
@@ -341,14 +347,10 @@ pub struct Evaluator<'tcx> {
341
347
342
348
/// Whether to enforce the validity invariant.
343
349
pub ( crate ) validate : bool ,
344
-
345
- /// The random number generator to use if Miri
346
- /// is running in non-deterministic mode
347
- pub ( crate ) rng : Option < StdRng >
348
350
}
349
351
350
352
impl < ' tcx > Evaluator < ' tcx > {
351
- fn new ( validate : bool , seed : Option < u64 > ) -> Self {
353
+ fn new ( validate : bool ) -> Self {
352
354
Evaluator {
353
355
env_vars : HashMap :: default ( ) ,
354
356
argc : None ,
@@ -357,7 +359,6 @@ impl<'tcx> Evaluator<'tcx> {
357
359
last_error : 0 ,
358
360
tls : TlsData :: default ( ) ,
359
361
validate,
360
- rng : seed. map ( |s| StdRng :: seed_from_u64 ( s) )
361
362
}
362
363
}
363
364
}
@@ -386,8 +387,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
386
387
type MemoryKinds = MiriMemoryKind ;
387
388
388
389
type FrameExtra = stacked_borrows:: CallId ;
389
- type MemoryExtra = stacked_borrows :: MemoryState ;
390
- type AllocExtra = stacked_borrows :: Stacks ;
390
+ type MemoryExtra = memory :: MemoryExtra ;
391
+ type AllocExtra = memory :: AllocExtra ;
391
392
type PointerTag = Tag ;
392
393
393
394
type MemoryMap = MonoHashMap < AllocId , ( MemoryKind < MiriMemoryKind > , Allocation < Tag , Self :: AllocExtra > ) > ;
@@ -512,17 +513,17 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
512
513
) -> ( Cow < ' b , Allocation < Self :: PointerTag , Self :: AllocExtra > > , Self :: PointerTag ) {
513
514
let kind = kind. expect ( "we set our STATIC_KIND so this cannot be None" ) ;
514
515
let alloc = alloc. into_owned ( ) ;
515
- let ( extra , base_tag) = Stacks :: new_allocation (
516
+ let ( stacks , base_tag) = Stacks :: new_allocation (
516
517
id,
517
518
Size :: from_bytes ( alloc. bytes . len ( ) as u64 ) ,
518
- Rc :: clone ( & memory. extra ) ,
519
+ Rc :: clone ( & memory. extra . stacked_borrows ) ,
519
520
kind,
520
521
) ;
521
522
if kind != MiriMemoryKind :: Static . into ( ) {
522
523
assert ! ( alloc. relocations. is_empty( ) , "Only statics can come initialized with inner pointers" ) ;
523
524
// Now we can rely on the inner pointers being static, too.
524
525
}
525
- let mut memory_extra = memory. extra . borrow_mut ( ) ;
526
+ let mut memory_extra = memory. extra . stacked_borrows . borrow_mut ( ) ;
526
527
let alloc: Allocation < Tag , Self :: AllocExtra > = Allocation {
527
528
bytes : alloc. bytes ,
528
529
relocations : Relocations :: from_presorted (
@@ -535,7 +536,10 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
535
536
undef_mask : alloc. undef_mask ,
536
537
align : alloc. align ,
537
538
mutability : alloc. mutability ,
538
- extra,
539
+ extra : AllocExtra {
540
+ stacked_borrows : stacks,
541
+ intptrcast : Default :: default ( ) ,
542
+ } ,
539
543
} ;
540
544
( Cow :: Owned ( alloc) , base_tag)
541
545
}
@@ -545,7 +549,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
545
549
id : AllocId ,
546
550
memory : & Memory < ' mir , ' tcx , Self > ,
547
551
) -> Self :: PointerTag {
548
- memory. extra . borrow_mut ( ) . static_base_ptr ( id)
552
+ memory. extra . stacked_borrows . borrow_mut ( ) . static_base_ptr ( id)
549
553
}
550
554
551
555
#[ inline( always) ]
@@ -570,14 +574,38 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
570
574
fn stack_push (
571
575
ecx : & mut InterpretCx < ' mir , ' tcx , Self > ,
572
576
) -> InterpResult < ' tcx , stacked_borrows:: CallId > {
573
- Ok ( ecx. memory ( ) . extra . borrow_mut ( ) . new_call ( ) )
577
+ Ok ( ecx. memory ( ) . extra . stacked_borrows . borrow_mut ( ) . new_call ( ) )
574
578
}
575
579
576
580
#[ inline( always) ]
577
581
fn stack_pop (
578
582
ecx : & mut InterpretCx < ' mir , ' tcx , Self > ,
579
583
extra : stacked_borrows:: CallId ,
580
584
) -> InterpResult < ' tcx > {
581
- Ok ( ecx. memory ( ) . extra . borrow_mut ( ) . end_call ( extra) )
585
+ Ok ( ecx. memory ( ) . extra . stacked_borrows . borrow_mut ( ) . end_call ( extra) )
586
+ }
587
+
588
+ fn int_to_ptr (
589
+ int : u64 ,
590
+ memory : & Memory < ' mir , ' tcx , Self > ,
591
+ ) -> InterpResult < ' tcx , Pointer < Self :: PointerTag > > {
592
+ if int == 0 {
593
+ err ! ( InvalidNullPointerUsage )
594
+ } else if memory. extra . rng . is_none ( ) {
595
+ err ! ( ReadBytesAsPointer )
596
+ } else {
597
+ intptrcast:: GlobalState :: int_to_ptr ( int, memory)
598
+ }
599
+ }
600
+
601
+ fn ptr_to_int (
602
+ ptr : Pointer < Self :: PointerTag > ,
603
+ memory : & Memory < ' mir , ' tcx , Self > ,
604
+ ) -> InterpResult < ' tcx , u64 > {
605
+ if memory. extra . rng . is_none ( ) {
606
+ err ! ( ReadPointerAsBytes )
607
+ } else {
608
+ intptrcast:: GlobalState :: ptr_to_int ( ptr, memory)
609
+ }
582
610
}
583
611
}
0 commit comments