Skip to content

Commit c922850

Browse files
committed
hopefully fix build on windows/macos
1 parent 6b5b22e commit c922850

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/alloc_bytes.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{alloc, slice};
55
use rustc_abi::{Align, Size};
66
use rustc_middle::mir::interpret::AllocBytes;
77

8+
#[cfg(all(unix, any(target_arch = "x86", target_arch = "x86_64")))]
89
use crate::discrete_alloc::MachineAlloc;
910
use 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

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ mod borrow_tracker;
7676
mod clock;
7777
mod concurrency;
7878
mod diagnostics;
79+
#[cfg(all(unix, any(target_arch = "x86", target_arch = "x86_64")))]
7980
mod discrete_alloc;
8081
mod eval;
8182
mod helpers;

src/shims/native_lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
196196
}
197197
}
198198

199+
#[cfg(all(unix, any(target_arch = "x86", target_arch = "x86_64")))]
199200
unsafe fn do_native_call<T: libffi::high::CType>(ptr: CodePtr, args: &[ffi::Arg<'_>]) -> T {
200201
use shims::trace::Supervisor;
201202

@@ -211,6 +212,12 @@ unsafe fn do_native_call<T: libffi::high::CType>(ptr: CodePtr, args: &[ffi::Arg<
211212
ret
212213
}
213214

215+
#[cfg(not(all(unix, any(target_arch = "x86", target_arch = "x86_64"))))]
216+
#[inline(always)]
217+
unsafe fn do_native_call<T: libffi::high::CType>(ptr: CodePtr, args: &[ffi::Arg<'_>]) -> T {
218+
ffi::call(ptr, args)
219+
}
220+
214221
#[derive(Debug, Clone)]
215222
/// Enum of supported arguments to external C functions.
216223
// We introduce this enum instead of just calling `ffi::arg` and storing a list

0 commit comments

Comments
 (0)