@@ -11,14 +11,15 @@ use rand::rngs::StdRng;
11
11
use syntax:: attr;
12
12
use syntax:: symbol:: sym;
13
13
use rustc:: hir:: def_id:: DefId ;
14
- use rustc:: ty:: { self , layout:: { Size , LayoutOf } , query :: TyCtxtAt } ;
14
+ use rustc:: ty:: { self , layout:: { Size , LayoutOf } , TyCtxt } ;
15
15
use rustc:: mir;
16
16
17
17
use crate :: * ;
18
18
19
19
// Some global facts about the emulated machine.
20
20
pub 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
22
23
pub const NUM_CPUS : u64 = 1 ;
23
24
24
25
/// Extra memory kinds
@@ -135,6 +136,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
135
136
type MemoryExtra = MemoryExtra ;
136
137
type AllocExtra = AllocExtra ;
137
138
type PointerTag = Tag ;
139
+ type ExtraFnVal = Dlsym ;
138
140
139
141
type MemoryMap = MonoHashMap < AllocId , ( MemoryKind < MiriMemoryKind > , Allocation < Tag , Self :: AllocExtra > ) > ;
140
142
@@ -145,7 +147,6 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
145
147
ecx. memory ( ) . extra . validate
146
148
}
147
149
148
- /// Returns `Ok()` when the function was handled; fail otherwise.
149
150
#[ inline( always) ]
150
151
fn find_fn (
151
152
ecx : & mut InterpCx < ' mir , ' tcx , Self > ,
@@ -157,6 +158,17 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
157
158
ecx. find_fn ( instance, args, dest, ret)
158
159
}
159
160
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
+
160
172
#[ inline( always) ]
161
173
fn call_intrinsic (
162
174
ecx : & mut rustc_mir:: interpret:: InterpCx < ' mir , ' tcx , Self > ,
@@ -220,8 +232,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
220
232
}
221
233
222
234
fn find_foreign_static (
235
+ tcx : TyCtxt < ' tcx > ,
223
236
def_id : DefId ,
224
- tcx : TyCtxtAt < ' tcx > ,
225
237
) -> InterpResult < ' tcx , Cow < ' tcx , Allocation > > {
226
238
let attrs = tcx. get_attrs ( def_id) ;
227
239
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> {
251
263
}
252
264
253
265
fn tag_allocation < ' b > (
266
+ memory_extra : & MemoryExtra ,
254
267
id : AllocId ,
255
268
alloc : Cow < ' b , Allocation > ,
256
269
kind : Option < MemoryKind < Self :: MemoryKinds > > ,
257
- memory : & Memory < ' mir , ' tcx , Self > ,
258
270
) -> ( Cow < ' b , Allocation < Self :: PointerTag , Self :: AllocExtra > > , Self :: PointerTag ) {
259
271
let kind = kind. expect ( "we set our STATIC_KIND so this cannot be None" ) ;
260
272
let alloc = alloc. into_owned ( ) ;
261
- let ( stacks, base_tag) = if !memory . extra . validate {
273
+ let ( stacks, base_tag) = if !memory_extra . validate {
262
274
( None , Tag :: Untagged )
263
275
} else {
264
276
let ( stacks, base_tag) = Stacks :: new_allocation (
265
277
id,
266
278
Size :: from_bytes ( alloc. bytes . len ( ) as u64 ) ,
267
- Rc :: clone ( & memory . extra . stacked_borrows ) ,
279
+ Rc :: clone ( & memory_extra . stacked_borrows ) ,
268
280
kind,
269
281
) ;
270
282
( Some ( stacks) , base_tag)
@@ -273,18 +285,18 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
273
285
assert ! ( alloc. relocations. is_empty( ) , "Only statics can come initialized with inner pointers" ) ;
274
286
// Now we can rely on the inner pointers being static, too.
275
287
}
276
- let mut memory_extra = memory . extra . stacked_borrows . borrow_mut ( ) ;
288
+ let mut stacked_borrows = memory_extra . stacked_borrows . borrow_mut ( ) ;
277
289
let alloc: Allocation < Tag , Self :: AllocExtra > = Allocation {
278
290
bytes : alloc. bytes ,
279
291
relocations : Relocations :: from_presorted (
280
292
alloc. relocations . iter ( )
281
293
// The allocations in the relocations (pointers stored *inside* this allocation)
282
294
// all get the base pointer tag.
283
295
. map ( |& ( offset, ( ( ) , alloc) ) | {
284
- let tag = if !memory . extra . validate {
296
+ let tag = if !memory_extra . validate {
285
297
Tag :: Untagged
286
298
} else {
287
- memory_extra . static_base_ptr ( alloc)
299
+ stacked_borrows . static_base_ptr ( alloc)
288
300
} ;
289
301
( offset, ( tag, alloc) )
290
302
} )
@@ -302,13 +314,13 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
302
314
303
315
#[ inline( always) ]
304
316
fn tag_static_base_pointer (
317
+ memory_extra : & MemoryExtra ,
305
318
id : AllocId ,
306
- memory : & Memory < ' mir , ' tcx , Self > ,
307
319
) -> Self :: PointerTag {
308
- if !memory . extra . validate {
320
+ if !memory_extra . validate {
309
321
Tag :: Untagged
310
322
} else {
311
- memory . extra . stacked_borrows . borrow_mut ( ) . static_base_ptr ( id)
323
+ memory_extra . stacked_borrows . borrow_mut ( ) . static_base_ptr ( id)
312
324
}
313
325
}
314
326
@@ -342,8 +354,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
342
354
}
343
355
344
356
fn int_to_ptr (
345
- int : u64 ,
346
357
memory : & Memory < ' mir , ' tcx , Self > ,
358
+ int : u64 ,
347
359
) -> InterpResult < ' tcx , Pointer < Self :: PointerTag > > {
348
360
if int == 0 {
349
361
err ! ( InvalidNullPointerUsage )
@@ -355,8 +367,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
355
367
}
356
368
357
369
fn ptr_to_int (
358
- ptr : Pointer < Self :: PointerTag > ,
359
370
memory : & Memory < ' mir , ' tcx , Self > ,
371
+ ptr : Pointer < Self :: PointerTag > ,
360
372
) -> InterpResult < ' tcx , u64 > {
361
373
if memory. extra . rng . is_none ( ) {
362
374
err ! ( ReadPointerAsBytes )
0 commit comments