@@ -11,14 +11,15 @@ use rand::rngs::StdRng;
1111use  syntax:: attr; 
1212use  syntax:: symbol:: sym; 
1313use  rustc:: hir:: def_id:: DefId ; 
14- use  rustc:: ty:: { self ,  layout:: { Size ,  LayoutOf } ,  query :: TyCtxtAt } ; 
14+ use  rustc:: ty:: { self ,  layout:: { Size ,  LayoutOf } ,  TyCtxt } ; 
1515use  rustc:: mir; 
1616
1717use  crate :: * ; 
1818
1919// Some global facts about the emulated machine. 
2020pub  const  PAGE_SIZE :  u64  = 4 * 1024 ;  // FIXME: adjust to target architecture 
21- pub  const  STACK_ADDR :  u64  = 16 * PAGE_SIZE ;  // not really about the "stack", but where we start assigning integer addresses to allocations 
21+ pub  const  STACK_ADDR :  u64  = 32 * PAGE_SIZE ;  // not really about the "stack", but where we start assigning integer addresses to allocations 
22+ pub  const  STACK_SIZE :  u64  = 16 * PAGE_SIZE ;  // whatever 
2223pub  const  NUM_CPUS :  u64  = 1 ; 
2324
2425/// Extra memory kinds 
@@ -135,6 +136,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
135136    type  MemoryExtra  = MemoryExtra ; 
136137    type  AllocExtra  = AllocExtra ; 
137138    type  PointerTag  = Tag ; 
139+     type  ExtraFnVal  = Dlsym ; 
138140
139141    type  MemoryMap  = MonoHashMap < AllocId ,  ( MemoryKind < MiriMemoryKind > ,  Allocation < Tag ,  Self :: AllocExtra > ) > ; 
140142
@@ -145,7 +147,6 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
145147        ecx. memory ( ) . extra . validate 
146148    } 
147149
148-     /// Returns `Ok()` when the function was handled; fail otherwise. 
149150    #[ inline( always) ]  
150151    fn  find_fn ( 
151152        ecx :  & mut  InterpCx < ' mir ,  ' tcx ,  Self > , 
@@ -157,6 +158,17 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
157158        ecx. find_fn ( instance,  args,  dest,  ret) 
158159    } 
159160
161+     #[ inline( always) ]  
162+     fn  call_extra_fn ( 
163+         ecx :  & mut  InterpCx < ' mir ,  ' tcx ,  Self > , 
164+         fn_val :  Dlsym , 
165+         args :  & [ OpTy < ' tcx ,  Tag > ] , 
166+         dest :  Option < PlaceTy < ' tcx ,  Tag > > , 
167+         ret :  Option < mir:: BasicBlock > , 
168+     )  -> InterpResult < ' tcx >  { 
169+         ecx. call_dlsym ( fn_val,  args,  dest,  ret) 
170+     } 
171+ 
160172    #[ inline( always) ]  
161173    fn  call_intrinsic ( 
162174        ecx :  & mut  rustc_mir:: interpret:: InterpCx < ' mir ,  ' tcx ,  Self > , 
@@ -220,8 +232,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
220232    } 
221233
222234    fn  find_foreign_static ( 
235+         tcx :  TyCtxt < ' tcx > , 
223236        def_id :  DefId , 
224-         tcx :  TyCtxtAt < ' tcx > , 
225237    )  -> InterpResult < ' tcx ,  Cow < ' tcx ,  Allocation > >  { 
226238        let  attrs = tcx. get_attrs ( def_id) ; 
227239        let  link_name = match  attr:: first_attr_value_str_by_name ( & attrs,  sym:: link_name)  { 
@@ -251,20 +263,20 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
251263    } 
252264
253265    fn  tag_allocation < ' b > ( 
266+         memory_extra :  & MemoryExtra , 
254267        id :  AllocId , 
255268        alloc :  Cow < ' b ,  Allocation > , 
256269        kind :  Option < MemoryKind < Self :: MemoryKinds > > , 
257-         memory :  & Memory < ' mir ,  ' tcx ,  Self > , 
258270    )  -> ( Cow < ' b ,  Allocation < Self :: PointerTag ,  Self :: AllocExtra > > ,  Self :: PointerTag )  { 
259271        let  kind = kind. expect ( "we set our STATIC_KIND so this cannot be None" ) ; 
260272        let  alloc = alloc. into_owned ( ) ; 
261-         let  ( stacks,  base_tag)  = if  !memory . extra . validate  { 
273+         let  ( stacks,  base_tag)  = if  !memory_extra . validate  { 
262274            ( None ,  Tag :: Untagged ) 
263275        }  else  { 
264276            let  ( stacks,  base_tag)  = Stacks :: new_allocation ( 
265277                id, 
266278                Size :: from_bytes ( alloc. bytes . len ( )  as  u64 ) , 
267-                 Rc :: clone ( & memory . extra . stacked_borrows ) , 
279+                 Rc :: clone ( & memory_extra . stacked_borrows ) , 
268280                kind, 
269281            ) ; 
270282            ( Some ( stacks) ,  base_tag) 
@@ -273,18 +285,18 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
273285            assert ! ( alloc. relocations. is_empty( ) ,  "Only statics can come initialized with inner pointers" ) ; 
274286            // Now we can rely on the inner pointers being static, too. 
275287        } 
276-         let  mut  memory_extra  = memory . extra . stacked_borrows . borrow_mut ( ) ; 
288+         let  mut  stacked_borrows  = memory_extra . stacked_borrows . borrow_mut ( ) ; 
277289        let  alloc:  Allocation < Tag ,  Self :: AllocExtra >  = Allocation  { 
278290            bytes :  alloc. bytes , 
279291            relocations :  Relocations :: from_presorted ( 
280292                alloc. relocations . iter ( ) 
281293                    // The allocations in the relocations (pointers stored *inside* this allocation) 
282294                    // all get the base pointer tag. 
283295                    . map ( |& ( offset,  ( ( ) ,  alloc) ) | { 
284-                         let  tag = if  !memory . extra . validate  { 
296+                         let  tag = if  !memory_extra . validate  { 
285297                            Tag :: Untagged 
286298                        }  else  { 
287-                             memory_extra . static_base_ptr ( alloc) 
299+                             stacked_borrows . static_base_ptr ( alloc) 
288300                        } ; 
289301                        ( offset,  ( tag,  alloc) ) 
290302                    } ) 
@@ -302,13 +314,13 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
302314
303315    #[ inline( always) ]  
304316    fn  tag_static_base_pointer ( 
317+         memory_extra :  & MemoryExtra , 
305318        id :  AllocId , 
306-         memory :  & Memory < ' mir ,  ' tcx ,  Self > , 
307319    )  -> Self :: PointerTag  { 
308-         if  !memory . extra . validate  { 
320+         if  !memory_extra . validate  { 
309321            Tag :: Untagged 
310322        }  else  { 
311-             memory . extra . stacked_borrows . borrow_mut ( ) . static_base_ptr ( id) 
323+             memory_extra . stacked_borrows . borrow_mut ( ) . static_base_ptr ( id) 
312324        } 
313325    } 
314326
@@ -342,8 +354,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
342354    } 
343355
344356    fn  int_to_ptr ( 
345-         int :  u64 , 
346357        memory :  & Memory < ' mir ,  ' tcx ,  Self > , 
358+         int :  u64 , 
347359    )  -> InterpResult < ' tcx ,  Pointer < Self :: PointerTag > >  { 
348360        if  int == 0  { 
349361            err ! ( InvalidNullPointerUsage ) 
@@ -355,8 +367,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
355367    } 
356368
357369    fn  ptr_to_int ( 
358-         ptr :  Pointer < Self :: PointerTag > , 
359370        memory :  & Memory < ' mir ,  ' tcx ,  Self > , 
371+         ptr :  Pointer < Self :: PointerTag > , 
360372    )  -> InterpResult < ' tcx ,  u64 >  { 
361373        if  memory. extra . rng . is_none ( )  { 
362374            err ! ( ReadPointerAsBytes ) 
0 commit comments