@@ -88,6 +88,10 @@ pub trait Machine<'mir, 'tcx>: Sized {
8888 /// Pointers are "tagged" with provenance information; typically the `AllocId` they belong to.
8989 type PointerTag : Provenance + Eq + Hash + ' static ;
9090
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+
9195 /// Machines can define extra (non-instance) things that represent values of function pointers.
9296 /// For example, Miri uses this to return a function pointer from `dlsym`
9397 /// that can later be called to execute the right thing.
@@ -122,6 +126,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
122126
123127 /// Whether, when checking alignment, we should `force_int` and thus support
124128 /// custom alignment logic based on whatever the integer address happens to be.
129+ ///
130+ /// Requires PointerTag::OFFSET_IS_ADDR to be true.
125131 fn force_int_for_alignment_check ( ecx : & InterpCx < ' mir , ' tcx , Self > ) -> bool ;
126132
127133 /// Whether to enforce the validity invariant
@@ -285,11 +291,14 @@ pub trait Machine<'mir, 'tcx>: Sized {
285291 addr : u64 ,
286292 ) -> Pointer < Option < Self :: PointerTag > > ;
287293
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()`.
289298 fn ptr_get_alloc (
290299 ecx : & InterpCx < ' mir , ' tcx , Self > ,
291300 ptr : Pointer < Self :: PointerTag > ,
292- ) -> ( AllocId , Size ) ;
301+ ) -> ( AllocId , Size , Self :: TagExtra ) ;
293302
294303 /// Called to initialize the "extra" state of an allocation and make the pointers
295304 /// it contains (in relocations) tagged. The way we construct allocations is
@@ -321,7 +330,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
321330 _tcx : TyCtxt < ' tcx > ,
322331 _machine : & Self ,
323332 _alloc_extra : & Self :: AllocExtra ,
324- _tag : Self :: PointerTag ,
333+ _tag : ( AllocId , Self :: TagExtra ) ,
325334 _range : AllocRange ,
326335 ) -> InterpResult < ' tcx > {
327336 Ok ( ( ) )
@@ -333,7 +342,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
333342 _tcx : TyCtxt < ' tcx > ,
334343 _machine : & mut Self ,
335344 _alloc_extra : & mut Self :: AllocExtra ,
336- _tag : Self :: PointerTag ,
345+ _tag : ( AllocId , Self :: TagExtra ) ,
337346 _range : AllocRange ,
338347 ) -> InterpResult < ' tcx > {
339348 Ok ( ( ) )
@@ -345,7 +354,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
345354 _tcx : TyCtxt < ' tcx > ,
346355 _machine : & mut Self ,
347356 _alloc_extra : & mut Self :: AllocExtra ,
348- _tag : Self :: PointerTag ,
357+ _tag : ( AllocId , Self :: TagExtra ) ,
349358 _range : AllocRange ,
350359 ) -> InterpResult < ' tcx > {
351360 Ok ( ( ) )
@@ -397,6 +406,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
397406// (CTFE and ConstProp) use the same instance. Here, we share that code.
398407pub macro compile_time_machine( <$mir: lifetime, $tcx: lifetime>) {
399408 type PointerTag = AllocId ;
409+ type TagExtra = ( ) ;
410+
400411 type ExtraFnVal = !;
401412
402413 type MemoryMap =
@@ -474,9 +485,12 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
474485 }
475486
476487 #[ 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 ) {
478492 // We know `offset` is relative to the allocation, so we can use `into_parts`.
479493 let ( alloc_id, offset) = ptr. into_parts ( ) ;
480- ( alloc_id, offset)
494+ ( alloc_id, offset, ( ) )
481495 }
482496}
0 commit comments