@@ -1244,16 +1244,20 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
1244
1244
// based on their particular choice for `Provenance`, `AllocExtra`, and `Bytes`.
1245
1245
let kind = Self :: GLOBAL_KIND
1246
1246
. expect ( "if GLOBAL_KIND is None, adjust_global_allocation must be overwritten" ) ;
1247
- // This closure is special in that it always relies on `take_prepared_alloc_bytes`
1248
- // to give it some reserved memory space .
1247
+ // This closure is special in that it relies on `take_prepared_alloc_bytes` to give it some
1248
+ // reserved memory space in case Miri needs to handle addresses especially for native calls .
1249
1249
let alloc = alloc. adjust_from_tcx ( & ecx. tcx , |bytes, align| {
1250
- assert_eq ! ( alloc. align, align) ;
1251
- let kind = Self :: GLOBAL_KIND . unwrap ( ) . into ( ) ;
1252
- let mut alloc_bytes = ecx. take_prepared_alloc_bytes ( id, kind) ?;
1253
- assert_eq ! ( alloc_bytes. len( ) , bytes. len( ) ) ;
1254
- // SAFETY: `alloc_bytes` and `bytes` span the same number of bytes.
1255
- unsafe { alloc_bytes. as_mut_ptr ( ) . copy_from ( bytes. as_ptr ( ) , bytes. len ( ) ) } ;
1256
- Ok ( alloc_bytes)
1250
+ Ok ( if ecx. machine . native_lib . is_some ( ) {
1251
+ assert_eq ! ( alloc. align, align) ;
1252
+ let kind = Self :: GLOBAL_KIND . unwrap ( ) . into ( ) ;
1253
+ let mut alloc_bytes = ecx. take_prepared_alloc_bytes ( id, kind) ?;
1254
+ assert_eq ! ( alloc_bytes. len( ) , bytes. len( ) ) ;
1255
+ // SAFETY: `alloc_bytes` and `bytes` span the same number of bytes.
1256
+ unsafe { alloc_bytes. as_mut_ptr ( ) . copy_from ( bytes. as_ptr ( ) , bytes. len ( ) ) } ;
1257
+ alloc_bytes
1258
+ } else {
1259
+ MiriAllocBytes :: from_bytes ( Cow :: Borrowed ( & * bytes) , align)
1260
+ } )
1257
1261
} ,
1258
1262
|ptr| ecx. global_root_pointer ( ptr) ,
1259
1263
) ?;
0 commit comments