Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support running on miri #113

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "stacker"
version = "0.1.17"
edition = "2021"
rust-version = "1.63"
authors = ["Alex Crichton <[email protected]>", "Simonas Kazlauskas <[email protected]>"]
build = "build.rs"
Expand Down
1 change: 1 addition & 0 deletions psm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "psm"
version = "0.1.24"
edition = "2021"
authors = ["Simonas Kazlauskas <[email protected]>"]
build = "build.rs"
description = "Portable Stack Manipulation: stack manipulation and introspection routines"
Expand Down
10 changes: 7 additions & 3 deletions psm/build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
extern crate cc;

fn find_assembly(
arch: &str,
endian: &str,
os: &str,
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 @@ -60,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 @@
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 All @@ -288,7 +294,7 @@
// Make sure the libstacker.a (implemented in C) is linked.
// See https://github.com/rust-lang/rust/issues/65610
#[link(name="stacker")]
extern {

Check warning on line 297 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Cargo.toml on windows-latest with nightly and

extern declarations without an explicit ABI are deprecated

Check warning on line 297 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Cargo.toml on windows-latest with nightly and --release

extern declarations without an explicit ABI are deprecated

Check warning on line 297 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Cargo.toml on windows-latest with nightly and -Zminimal-versions

extern declarations without an explicit ABI are deprecated

Check warning on line 297 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Cargo.toml on x86_64-pc-windows-gnu with nightly

extern declarations without an explicit ABI are deprecated

Check warning on line 297 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Cargo.toml on i686-pc-windows-gnu with nightly

extern declarations without an explicit ABI are deprecated
fn __stacker_get_current_fiber() -> *mut c_void;
}

Expand Down
Loading