@@ -153,17 +153,19 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
153153 throw_unsup_format ! ( "only scalar argument types are support for native calls" )
154154 }
155155 let imm = this. read_immediate ( arg) ?;
156- if matches ! ( arg. layout. ty. kind( ) , ty:: RawPtr ( _, rustc_ast:: Mutability :: Mut ) ) {
157- let ptr = this. read_pointer ( & imm) ?;
158- let Ok ( ( alloc_id, _size, _prov_extra) ) = this. ptr_try_get_alloc_id ( ptr, 0 ) else {
159- todo ! ( ) ; // TODO: Handle absolute-address-returned case.
156+ libffi_args. push ( imm_to_carg ( & imm, this) ?) ;
157+ if matches ! ( arg. layout. ty. kind( ) , ty:: RawPtr ( ..) ) {
158+ let ptr = imm. to_scalar ( ) . to_pointer ( self ) ?;
159+ // We use `get_alloc_id` for its best-effort behaviour with Wildcard provenance.
160+ let Ok ( alloc_id) = ptr. provenance . and_then ( |prov| prov. get_alloc_id ( ) ) else {
161+ // Pointer without provenance may access any memory.
162+ continue ;
160163 } ;
161- this. alloc_mark_init_rec ( alloc_id) ?;
164+ this. prepare_for_native_call ( alloc_id, ptr. provenance ) ?;
165+ // TODO: Write tests for (forgetting to) expose: -initial allocation -recursively all allocations -unexposed pointers.
162166 }
163- libffi_args. push ( imm_to_carg ( imm, this) ?) ;
164167 }
165168
166- // TODO: Directly collect into correct Vec? -- lifetime issues.
167169 // Convert them to `libffi::high::Arg` type.
168170 let libffi_args = libffi_args
169171 . iter ( )
@@ -229,7 +231,7 @@ impl<'a> CArg {
229231
230232/// Extract the scalar value from the result of reading a scalar from the machine,
231233/// and convert it to a `CArg`.
232- fn imm_to_carg < ' tcx > ( v : ImmTy < ' tcx > , cx : & impl HasDataLayout ) -> InterpResult < ' tcx , CArg > {
234+ fn imm_to_carg < ' tcx > ( v : & ImmTy < ' tcx > , cx : & impl HasDataLayout ) -> InterpResult < ' tcx , CArg > {
233235 interp_ok ( match v. layout . ty . kind ( ) {
234236 // If the primitive provided can be converted to a type matching the type pattern
235237 // then create a `CArg` of this primitive value with the corresponding `CArg` constructor.
0 commit comments