Skip to content

Commit

Permalink
Support running on miri
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 authored and nagisa committed Feb 10, 2025
1 parent 8b9c70d commit 4045bf9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion psm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ fn find_assembly(
env: &str,
masm: bool,
) -> Option<(&'static str, bool)> {
println!("cargo:rustc-check-cfg=cfg(switchable_stack,asm,link_asm)");
match (arch, endian, os, env) {
// The implementations for stack switching exist, but, officially, doing so without Fibers
// is not supported in Windows. For x86_64 the implementation actually works locally,
Expand Down Expand Up @@ -58,6 +57,13 @@ fn find_assembly(
fn main() {
use std::env::var;

println!("cargo:rustc-check-cfg=cfg(switchable_stack,asm,link_asm)");

if var("CARGO_CFG_MIRI").is_ok() {
// Miri doesn't have a stack limit and the inline asm wouldn't work on miri anyway.
return;
}

let arch = var("CARGO_CFG_TARGET_ARCH").unwrap();
let env = var("CARGO_CFG_TARGET_ENV").unwrap();
let os = var("CARGO_CFG_TARGET_OS").unwrap();
Expand Down
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,20 @@ psm_stack_manipulation! {
no {
#[cfg(not(windows))]
fn _grow(stack_size: usize, callback: &mut dyn FnMut()) {
drop(stack_size);
let _ = stack_size;
callback();
}
}
}

cfg_if! {
if #[cfg(windows)] {
if #[cfg(miri)] {
// Miri doesn't have a stack limit
#[inline(always)]
unsafe fn guess_os_stack_limit() -> Option<usize> {
None
}
} else if #[cfg(windows)] {
use std::ptr;
use std::io;
use libc::c_void;
Expand Down

0 comments on commit 4045bf9

Please sign in to comment.