@@ -7,11 +7,11 @@ use std::hash::Hash;
77
88use rustc:: hir:: def_id:: DefId ;
99use rustc:: mir;
10- use rustc:: ty:: { self , query :: TyCtxtAt } ;
10+ use rustc:: ty:: { self , TyCtxt } ;
1111
1212use super :: {
13- Allocation , AllocId , InterpResult , Scalar , AllocationExtra ,
14- InterpCx , PlaceTy , OpTy , ImmTy , MemoryKind , Pointer , Memory
13+ Allocation , AllocId , InterpResult , InterpError , Scalar , AllocationExtra ,
14+ InterpCx , PlaceTy , OpTy , ImmTy , MemoryKind , Pointer , Memory ,
1515} ;
1616
1717/// Whether this kind of memory is allowed to leak
@@ -67,6 +67,11 @@ pub trait Machine<'mir, 'tcx>: Sized {
6767 /// The `default()` is used for pointers to consts, statics, vtables and functions.
6868 type PointerTag : :: std:: fmt:: Debug + Copy + Eq + Hash + ' static ;
6969
70+ /// Machines can define extra (non-instance) things that represent values of function pointers.
71+ /// For example, Miri uses this to return a fucntion pointer from `dlsym`
72+ /// that can later be called to execute the right thing.
73+ type ExtraFnVal : :: std:: fmt:: Debug + Copy ;
74+
7075 /// Extra data stored in every call frame.
7176 type FrameExtra ;
7277
@@ -119,6 +124,16 @@ pub trait Machine<'mir, 'tcx>: Sized {
119124 ret : Option < mir:: BasicBlock > ,
120125 ) -> InterpResult < ' tcx , Option < & ' mir mir:: Body < ' tcx > > > ;
121126
127+ /// Execute `fn_val`. it is the hook's responsibility to advance the instruction
128+ /// pointer as appropriate.
129+ fn call_extra_fn (
130+ ecx : & mut InterpCx < ' mir , ' tcx , Self > ,
131+ fn_val : Self :: ExtraFnVal ,
132+ args : & [ OpTy < ' tcx , Self :: PointerTag > ] ,
133+ dest : Option < PlaceTy < ' tcx , Self :: PointerTag > > ,
134+ ret : Option < mir:: BasicBlock > ,
135+ ) -> InterpResult < ' tcx > ;
136+
122137 /// Directly process an intrinsic without pushing a stack frame.
123138 /// If this returns successfully, the engine will take care of jumping to the next block.
124139 fn call_intrinsic (
@@ -136,8 +151,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
136151 ///
137152 /// This allocation will then be fed to `tag_allocation` to initialize the "extra" state.
138153 fn find_foreign_static (
154+ tcx : TyCtxt < ' tcx > ,
139155 def_id : DefId ,
140- tcx : TyCtxtAt < ' tcx > ,
141156 ) -> InterpResult < ' tcx , Cow < ' tcx , Allocation > > ;
142157
143158 /// Called for all binary operations on integer(-like) types when one operand is a pointer
@@ -174,10 +189,10 @@ pub trait Machine<'mir, 'tcx>: Sized {
174189 /// For static allocations, the tag returned must be the same as the one returned by
175190 /// `tag_static_base_pointer`.
176191 fn tag_allocation < ' b > (
192+ memory_extra : & Self :: MemoryExtra ,
177193 id : AllocId ,
178194 alloc : Cow < ' b , Allocation > ,
179195 kind : Option < MemoryKind < Self :: MemoryKinds > > ,
180- memory : & Memory < ' mir , ' tcx , Self > ,
181196 ) -> ( Cow < ' b , Allocation < Self :: PointerTag , Self :: AllocExtra > > , Self :: PointerTag ) ;
182197
183198 /// Return the "base" tag for the given static allocation: the one that is used for direct
@@ -186,8 +201,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
186201 /// Be aware that requesting the `Allocation` for that `id` will lead to cycles
187202 /// for cyclic statics!
188203 fn tag_static_base_pointer (
204+ memory_extra : & Self :: MemoryExtra ,
189205 id : AllocId ,
190- memory : & Memory < ' mir , ' tcx , Self > ,
191206 ) -> Self :: PointerTag ;
192207
193208 /// Executes a retagging operation
@@ -209,20 +224,22 @@ pub trait Machine<'mir, 'tcx>: Sized {
209224 extra : Self :: FrameExtra ,
210225 ) -> InterpResult < ' tcx > ;
211226
227+ #[ inline( always) ]
212228 fn int_to_ptr (
213- int : u64 ,
214229 _mem : & Memory < ' mir , ' tcx , Self > ,
230+ int : u64 ,
215231 ) -> InterpResult < ' tcx , Pointer < Self :: PointerTag > > {
216- if int == 0 {
217- err ! ( InvalidNullPointerUsage )
232+ Err ( ( if int == 0 {
233+ InterpError :: InvalidNullPointerUsage
218234 } else {
219- err ! ( ReadBytesAsPointer )
220- }
235+ InterpError :: ReadBytesAsPointer
236+ } ) . into ( ) )
221237 }
222238
239+ #[ inline( always) ]
223240 fn ptr_to_int (
224- _ptr : Pointer < Self :: PointerTag > ,
225241 _mem : & Memory < ' mir , ' tcx , Self > ,
242+ _ptr : Pointer < Self :: PointerTag > ,
226243 ) -> InterpResult < ' tcx , u64 > {
227244 err ! ( ReadPointerAsBytes )
228245 }
0 commit comments