@@ -5,6 +5,7 @@ use std::{alloc, slice};
5
5
use rustc_abi:: { Align , Size } ;
6
6
use rustc_middle:: mir:: interpret:: AllocBytes ;
7
7
8
+ #[ cfg( all( unix, any( target_arch = "x86" , target_arch = "x86_64" ) ) ) ]
8
9
use crate :: discrete_alloc:: MachineAlloc ;
9
10
use crate :: helpers:: ToU64 as _;
10
11
@@ -41,7 +42,10 @@ impl Drop for MiriAllocBytes {
41
42
42
43
// SAFETY: Invariant, `self.ptr` points to memory allocated with `self.layout`.
43
44
unsafe {
45
+ #[ cfg( all( unix, any( target_arch = "x86" , target_arch = "x86_64" ) ) ) ]
44
46
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) ;
45
49
}
46
50
}
47
51
}
@@ -95,7 +99,16 @@ impl AllocBytes for MiriAllocBytes {
95
99
let size = slice. len ( ) ;
96
100
let align = align. bytes ( ) ;
97
101
// 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
+ } ;
99
112
let alloc_bytes = MiriAllocBytes :: alloc_with ( size. to_u64 ( ) , align, alloc_fn)
100
113
. unwrap_or_else ( |( ) | {
101
114
panic ! ( "Miri ran out of memory: cannot create allocation of {size} bytes" )
@@ -114,7 +127,16 @@ impl AllocBytes for MiriAllocBytes {
114
127
let size = size. bytes ( ) ;
115
128
let align = align. bytes ( ) ;
116
129
// 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
+ } ;
118
140
MiriAllocBytes :: alloc_with ( size, align, alloc_fn) . ok ( )
119
141
}
120
142
0 commit comments