-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(no_std)!: respect std
feature when target is windows/unix
#11152
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
Conversation
BREAKING CHANGE: the fix disables standard features for dependents that use wasmtime with `default-features = false`.
Thanks for the PR! Could you elaborate on the motivation for this change as well? For example I'm not aware of a target that's |
@alexcrichton I’m experimenting with running Wasmtime (with Pulley) in the Windows kernel. The goal is to use WebAssembly to enable limited changes to kernel logic without requiring a full software update or system restart. I’m exploring Wasm as a potential alternative to eBPF for Windows. |
Oh nice! Do you know if there's a |
No, I don't think there's any specific target for (windows/unix) kernel. But just to clarify, are you suggesting that turning off |
Fill out the `compile_error!` to avoid failing a build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I can be more clear, my concern was a big vague there. I originally had the gut reaction of "this feels weird" but I'm effectively getting over that gut reaction. There's still changes I'd like to see in this PR, but I can try to be more clear about them. I've left various review comments below.
Don't require `std` feature for invalid faults
@alexcrichton after more experimentation on Windows, I realized |
For the stack switching issues can you update the |
// Do this before marking the memory as R+X, technically we should be able to do it after | ||
// but there are some CPU's that have had errata about doing this with read only memory. | ||
icache_coherence::clear_cache(text.as_ptr().cast(), text.len()) | ||
#[cfg(any(not(windows), feature = "std"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this it's a pretty critical operation here to manage the icache so we'll want to avoid this #[cfg]
which makes it difficult to see when it's used and when it isn't. I think the best solution here might be to sidestep the problem entirely and update this line to take the std
feature into account. For example that could be (unix || windows) && cfg!(feature = "std")
or something like that. A comment there would be good to explain that if std
is disabled then it's not supported in Wasmtime right now to interact with the OS which means that it's no longer supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that change but it doesn't solve the problem: Wasmtime still pulls std
through jit-icache-coherence
in no_std
Windows.
Another possible solution is to use libc
in jit-icache-coherence
for no_std
Windows at this line. For that, we could add a new std
feature flag to jit-icache-coherence
and enable it if std
in wasmtime
is enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just pushed a new commit that implements the change suggested above but happy to implement a different solution if this is problematic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your commit looks reasonable, thanks for doing that! I'll apologize again though about how this is a bit messy. I'd prefer to avoid having the crate be sort of half-std/half-not, so I think I've come up with an idea to sidestep this entirely which is to include the icache crate only if std
is enabled in Wasmtime itself. That solves the concerns I have about things getting a bit weird sometimes and the only remaining issue is various CI bits and how well this works out. I've pushed up a commit to this PR which implements what I was thinking of and I'll watch CI to see if my strategy won't work due to something I haven't thought of
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not at all! I appreciate your help and the time you've put into this. Okay, I'll wait for CI and merge the changes into the branch as soon as I see green. Thanks again!
- The `std` feature gates the use of standard library for icache coherence in Windows; otherwise, defaults to the `libc` implementation. - The `std` feature of Wasmtime now depends on the `wasmtime-jit-icache-coherence/std`
This PR fixes feature flag handling to properly respect the std feature when targeting Windows/Unix platforms.
Breaking Change: This fix will disable standard library features for dependents that use wasmtime with
default-features = false
.Changes:
Cargo.toml
files to conditionally enable std-dependent featuresno_std
compatibilityThe fix ensures that when wasmtime is used without default features, it properly builds in
no_std
on all supported platforms.