@@ -88,6 +88,10 @@ pub trait Machine<'mir, 'tcx>: Sized {
88
88
/// Pointers are "tagged" with provenance information; typically the `AllocId` they belong to.
89
89
type PointerTag : Provenance + Eq + Hash + ' static ;
90
90
91
+ /// When getting the AllocId of a pointer, some extra data is also obtained from the tag
92
+ /// that is passed to memory access hooks so they can do things with it.
93
+ type TagExtra : Copy + ' static ;
94
+
91
95
/// Machines can define extra (non-instance) things that represent values of function pointers.
92
96
/// For example, Miri uses this to return a function pointer from `dlsym`
93
97
/// that can later be called to execute the right thing.
@@ -122,6 +126,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
122
126
123
127
/// Whether, when checking alignment, we should `force_int` and thus support
124
128
/// custom alignment logic based on whatever the integer address happens to be.
129
+ ///
130
+ /// Requires PointerTag::OFFSET_IS_ADDR to be true.
125
131
fn force_int_for_alignment_check ( ecx : & InterpCx < ' mir , ' tcx , Self > ) -> bool ;
126
132
127
133
/// Whether to enforce the validity invariant
@@ -285,11 +291,14 @@ pub trait Machine<'mir, 'tcx>: Sized {
285
291
addr : u64 ,
286
292
) -> Pointer < Option < Self :: PointerTag > > ;
287
293
288
- /// Convert a pointer with provenance into an allocation-offset pair.
294
+ /// Convert a pointer with provenance into an allocation-offset pair
295
+ /// and extra provenance info.
296
+ ///
297
+ /// The returned `AllocId` must be the same as `ptr.provenance.get_alloc_id()`.
289
298
fn ptr_get_alloc (
290
299
ecx : & InterpCx < ' mir , ' tcx , Self > ,
291
300
ptr : Pointer < Self :: PointerTag > ,
292
- ) -> ( AllocId , Size ) ;
301
+ ) -> ( AllocId , Size , Self :: TagExtra ) ;
293
302
294
303
/// Called to initialize the "extra" state of an allocation and make the pointers
295
304
/// it contains (in relocations) tagged. The way we construct allocations is
@@ -321,7 +330,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
321
330
_tcx : TyCtxt < ' tcx > ,
322
331
_machine : & Self ,
323
332
_alloc_extra : & Self :: AllocExtra ,
324
- _tag : Self :: PointerTag ,
333
+ _tag : ( AllocId , Self :: TagExtra ) ,
325
334
_range : AllocRange ,
326
335
) -> InterpResult < ' tcx > {
327
336
Ok ( ( ) )
@@ -333,7 +342,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
333
342
_tcx : TyCtxt < ' tcx > ,
334
343
_machine : & mut Self ,
335
344
_alloc_extra : & mut Self :: AllocExtra ,
336
- _tag : Self :: PointerTag ,
345
+ _tag : ( AllocId , Self :: TagExtra ) ,
337
346
_range : AllocRange ,
338
347
) -> InterpResult < ' tcx > {
339
348
Ok ( ( ) )
@@ -345,7 +354,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
345
354
_tcx : TyCtxt < ' tcx > ,
346
355
_machine : & mut Self ,
347
356
_alloc_extra : & mut Self :: AllocExtra ,
348
- _tag : Self :: PointerTag ,
357
+ _tag : ( AllocId , Self :: TagExtra ) ,
349
358
_range : AllocRange ,
350
359
) -> InterpResult < ' tcx > {
351
360
Ok ( ( ) )
@@ -397,6 +406,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
397
406
// (CTFE and ConstProp) use the same instance. Here, we share that code.
398
407
pub macro compile_time_machine( <$mir: lifetime, $tcx: lifetime>) {
399
408
type PointerTag = AllocId ;
409
+ type TagExtra = ( ) ;
410
+
400
411
type ExtraFnVal = !;
401
412
402
413
type MemoryMap =
@@ -474,9 +485,12 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
474
485
}
475
486
476
487
#[ inline( always) ]
477
- fn ptr_get_alloc ( _ecx : & InterpCx < $mir, $tcx, Self > , ptr : Pointer < AllocId > ) -> ( AllocId , Size ) {
488
+ fn ptr_get_alloc (
489
+ _ecx : & InterpCx < $mir, $tcx, Self > ,
490
+ ptr : Pointer < AllocId > ,
491
+ ) -> ( AllocId , Size , Self :: TagExtra ) {
478
492
// We know `offset` is relative to the allocation, so we can use `into_parts`.
479
493
let ( alloc_id, offset) = ptr. into_parts ( ) ;
480
- ( alloc_id, offset)
494
+ ( alloc_id, offset, ( ) )
481
495
}
482
496
}
0 commit comments