@@ -152,9 +152,18 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
152152 if !matches ! ( arg. layout. backend_repr, BackendRepr :: Scalar ( _) ) {
153153 throw_unsup_format ! ( "only scalar argument types are support for native calls" )
154154 }
155- libffi_args. push ( imm_to_carg ( this. read_immediate ( arg) ?, this) ?) ;
155+ 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.
160+ } ;
161+ this. alloc_mark_init_rec ( alloc_id) ?;
162+ }
163+ libffi_args. push ( imm_to_carg ( imm, this) ?) ;
156164 }
157165
166+ // TODO: Directly collect into correct Vec? -- lifetime issues.
158167 // Convert them to `libffi::high::Arg` type.
159168 let libffi_args = libffi_args
160169 . iter ( )
@@ -238,18 +247,10 @@ fn imm_to_carg<'tcx>(v: ImmTy<'tcx>, cx: &impl HasDataLayout) -> InterpResult<'t
238247 ty:: Uint ( UintTy :: U64 ) => CArg :: UInt64 ( v. to_scalar ( ) . to_u64 ( ) ?) ,
239248 ty:: Uint ( UintTy :: Usize ) =>
240249 CArg :: USize ( v. to_scalar ( ) . to_target_usize ( cx) ?. try_into ( ) . unwrap ( ) ) ,
241- ty:: RawPtr ( _, mutability) => {
242- // Arbitrary mutable pointer accesses are not currently supported in Miri.
243- if mutability. is_mut ( ) {
244- throw_unsup_format ! (
245- "unsupported mutable pointer type for native call: {}" ,
246- v. layout. ty
247- ) ;
248- } else {
249- let s = v. to_scalar ( ) . to_pointer ( cx) ?. addr ( ) ;
250- // This relies on the `expose_provenance` in `addr_from_alloc_id`.
251- CArg :: RawPtr ( std:: ptr:: with_exposed_provenance_mut ( s. bytes_usize ( ) ) )
252- }
250+ ty:: RawPtr ( ..) => {
251+ let s = v. to_scalar ( ) . to_pointer ( cx) ?. addr ( ) ;
252+ // This relies on the `expose_provenance` in `addr_from_alloc_id`.
253+ CArg :: RawPtr ( std:: ptr:: with_exposed_provenance_mut ( s. bytes_usize ( ) ) )
253254 }
254255 _ => throw_unsup_format ! ( "unsupported argument type for native call: {}" , v. layout. ty) ,
255256 } )
0 commit comments