@@ -5,6 +5,7 @@ use std::{alloc, slice};
55use rustc_abi:: { Align , Size } ;
66use rustc_middle:: mir:: interpret:: AllocBytes ;
77
8+ #[ cfg( all( unix, any( target_arch = "x86" , target_arch = "x86_64" ) ) ) ]
89use crate :: discrete_alloc:: MachineAlloc ;
910use crate :: helpers:: ToU64 as _;
1011
@@ -41,7 +42,10 @@ impl Drop for MiriAllocBytes {
4142
4243 // SAFETY: Invariant, `self.ptr` points to memory allocated with `self.layout`.
4344 unsafe {
45+ #[ cfg( all( unix, any( target_arch = "x86" , target_arch = "x86_64" ) ) ) ]
4446 MachineAlloc :: dealloc ( self . ptr , alloc_layout) ;
47+ #[ cfg( not( all( unix, any( target_arch = "x86" , target_arch = "x86_64" ) ) ) ) ]
48+ alloc:: dealloc ( self . ptr , alloc_layout) ;
4549 }
4650 }
4751}
@@ -95,7 +99,16 @@ impl AllocBytes for MiriAllocBytes {
9599 let size = slice. len ( ) ;
96100 let align = align. bytes ( ) ;
97101 // SAFETY: `alloc_fn` will only be used with `size != 0`.
98- let alloc_fn = |layout| unsafe { MachineAlloc :: alloc ( layout) } ;
102+ let alloc_fn = |layout| unsafe {
103+ #[ cfg( all( unix, any( target_arch = "x86" , target_arch = "x86_64" ) ) ) ]
104+ {
105+ MachineAlloc :: alloc ( layout)
106+ }
107+ #[ cfg( not( all( unix, any( target_arch = "x86" , target_arch = "x86_64" ) ) ) ) ]
108+ {
109+ alloc:: alloc ( layout)
110+ }
111+ } ;
99112 let alloc_bytes = MiriAllocBytes :: alloc_with ( size. to_u64 ( ) , align, alloc_fn)
100113 . unwrap_or_else ( |( ) | {
101114 panic ! ( "Miri ran out of memory: cannot create allocation of {size} bytes" )
@@ -114,7 +127,16 @@ impl AllocBytes for MiriAllocBytes {
114127 let size = size. bytes ( ) ;
115128 let align = align. bytes ( ) ;
116129 // SAFETY: `alloc_fn` will only be used with `size != 0`.
117- let alloc_fn = |layout| unsafe { MachineAlloc :: alloc_zeroed ( layout) } ;
130+ let alloc_fn = |layout| unsafe {
131+ #[ cfg( all( unix, any( target_arch = "x86" , target_arch = "x86_64" ) ) ) ]
132+ {
133+ MachineAlloc :: alloc_zeroed ( layout)
134+ }
135+ #[ cfg( not( all( unix, any( target_arch = "x86" , target_arch = "x86_64" ) ) ) ) ]
136+ {
137+ alloc:: alloc_zeroed ( layout)
138+ }
139+ } ;
118140 MiriAllocBytes :: alloc_with ( size, align, alloc_fn) . ok ( )
119141 }
120142
0 commit comments