11//! Implements calling functions from a native library.
22
3- #[ cfg( trace) ]
4- pub mod trace;
5-
63use std:: ops:: Deref ;
74
85use libffi:: high:: call as ffi;
@@ -12,15 +9,27 @@ use rustc_middle::mir::interpret::Pointer;
129use rustc_middle:: ty:: { self as ty, IntTy , UintTy } ;
1310use rustc_span:: Symbol ;
1411
15- #[ cfg( trace) ]
12+ #[ cfg_attr(
13+ all(
14+ target_os = "linux" ,
15+ target_env = "gnu" ,
16+ any( target_arch = "x86" , target_arch = "x86_64" , target_arch = "aarch64" )
17+ ) ,
18+ path = "trace/mod.rs"
19+ ) ]
20+ #[ cfg_attr(
21+ not( all(
22+ target_os = "linux" ,
23+ target_env = "gnu" ,
24+ any( target_arch = "x86" , target_arch = "x86_64" , target_arch = "aarch64" )
25+ ) ) ,
26+ path = "trace_stub.rs"
27+ ) ]
28+ pub mod trace;
29+
1630use self :: trace:: Supervisor ;
1731use crate :: * ;
1832
19- #[ cfg( trace) ]
20- type CallResult < ' tcx > = InterpResult < ' tcx , ( ImmTy < ' tcx > , Option < self :: trace:: messages:: MemEvents > ) > ;
21- #[ cfg( not( trace) ) ]
22- type CallResult < ' tcx > = InterpResult < ' tcx , ( ImmTy < ' tcx > , Option < !> ) > ;
23-
2433impl < ' tcx > EvalContextExtPriv < ' tcx > for crate :: MiriInterpCx < ' tcx > { }
2534trait EvalContextExtPriv < ' tcx > : crate :: MiriInterpCxExt < ' tcx > {
2635 /// Call native host function and return the output as an immediate.
@@ -30,13 +39,11 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
3039 dest : & MPlaceTy < ' tcx > ,
3140 ptr : CodePtr ,
3241 libffi_args : Vec < libffi:: high:: Arg < ' a > > ,
33- ) -> CallResult < ' tcx > {
42+ ) -> trace :: CallResult < ' tcx > {
3443 let this = self . eval_context_mut ( ) ;
35- #[ cfg( trace) ]
3644 let alloc = this. machine . allocator . as_ref ( ) . unwrap ( ) ;
3745
3846 // SAFETY: We don't touch the machine memory past this point.
39- #[ cfg( trace) ]
4047 let ( guard, stack_ptr) = unsafe { Supervisor :: start_ffi ( alloc) } ;
4148
4249 // Call the function (`ptr`) with arguments `libffi_args`, and obtain the return value
@@ -111,10 +118,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
111118
112119 // SAFETY: We got the guard and stack pointer from start_ffi, and
113120 // the allocator is the same
114- #[ cfg( trace) ]
115121 let events = unsafe { Supervisor :: end_ffi ( alloc, guard, stack_ptr) } ;
116- #[ cfg( not( trace) ) ]
117- let events = None ;
122+ //let events = None;
118123
119124 interp_ok ( ( res?, events) )
120125 }
@@ -213,10 +218,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
213218 if !this. machine . native_call_mem_warned . replace ( true ) {
214219 // Newly set, so first time we get here.
215220 this. emit_diagnostic ( NonHaltingDiagnostic :: NativeCallSharedMem {
216- #[ cfg( trace) ]
217221 tracing : self :: trace:: Supervisor :: is_enabled ( ) ,
218- #[ cfg( not( trace) ) ]
219- tracing : false ,
220222 } ) ;
221223 }
222224
0 commit comments