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

Replace signals-based-traps with auto-detection #9941

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

alexcrichton
Copy link
Member

This commit refactors the platform support of the wasmtime crate itself to remove the previously added signals-based-traps feature in favor of auto-detecting whether it's there or not. The build.rs script for the wasmtime crate will now detect the target platform and auto-enable this feature as necessary.

The signals-based-traps cargo feature is removed and split into two custom #[cfg] directives that the build script sets:

  • has_virtual_memory - this is used to gate mmap implementations for example. This is enabled on unix || windows and will be off for no_std targets for example. This is split out of "signals-based-traps" to better handle platforms like iOS which have virtual memory but don't execute native code (removing the need for native signals).

  • has_native_signals - gates signal handlers on Unix for example. This is disabled on MIRI but otherwise enabled for unix || windows. This is intended to in the future get disabled for iOS by default for example since it's not necessary when using Pulley. This is additionally off-by-default for no_std platforms.

Two new crate features were added for no_std or "custom" platforms to opt-in to the wasmtime-platform.h C APIs for implementing virtual memory and signals. These are used in the min-platform embedding example.

This commit additionally updates some various documentation here and there to be more up-to-date.

This commit refactors the platform support of the `wasmtime` crate
itself to remove the previously added `signals-based-traps` feature in
favor of auto-detecting whether it's there or not. The `build.rs`
script for the `wasmtime` crate will now detect the target platform and
auto-enable this feature as necessary.

The `signals-based-traps` cargo feature is removed and split into two
custom `#[cfg]` directives that the build script sets:

* `has_virtual_memory` - this is used to gate mmap implementations for
  example. This is enabled on `unix || windows` and will be off for
  `no_std` targets for example. This is split out of
  "signals-based-traps" to better handle platforms like iOS which have
  virtual memory but don't execute native code (removing the need for
  native signals).

* `has_native_signals` - gates signal handlers on Unix for example. This
  is disabled on MIRI but otherwise enabled for `unix || windows`. This
  is intended to in the future get disabled for iOS by default for
  example since it's not necessary when using Pulley. This is
  additionally off-by-default for `no_std` platforms.

Two new crate features were added for `no_std` or "custom" platforms to
opt-in to the `wasmtime-platform.h` C APIs for implementing virtual
memory and signals. These are used in the `min-platform` embedding example.

This commit additionally updates some various documentation here and
there to be more up-to-date.
@alexcrichton alexcrichton requested review from a team as code owners January 7, 2025 19:16
@alexcrichton alexcrichton requested review from fitzgen and removed request for a team January 7, 2025 19:16
@alexcrichton
Copy link
Member Author

One of the rough high-level goals here is that in conjunction with #9837 I hope to disable has_native_signals on Pulley-only platforms in the near future to statically remove all that code. That should make Wasmtime more portable by default since when there's no Cranelift backend there's no need to install signal handlers which often has lots of platform/architecture-specific implications.

@github-actions github-actions bot added fuzzing Issues related to our fuzzing infrastructure wasi Issues pertaining to WASI wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:config Issues related to the configuration of Wasmtime wasmtime:docs Issues related to Wasmtime's documentation labels Jan 7, 2025
Copy link

github-actions bot commented Jan 7, 2025

Subscribe to Label Action

cc @fitzgen

This issue or pull request has been labeled: "fuzzing", "wasi", "wasmtime:api", "wasmtime:config", "wasmtime:docs"

Thus the following users have been cc'd because of the following labels:

  • fitzgen: fuzzing

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Copy link

github-actions bot commented Jan 7, 2025

Label Messager: wasmtime:config

It looks like you are changing Wasmtime's configuration options. Make sure to
complete this check list:

  • If you added a new Config method, you wrote extensive documentation for
    it.

    Our documentation should be of the following form:

    Short, simple summary sentence.
    
    More details. These details can be multiple paragraphs. There should be
    information about not just the method, but its parameters and results as
    well.
    
    Is this method fallible? If so, when can it return an error?
    
    Can this method panic? If so, when does it panic?
    
    # Example
    
    Optional example here.
    
  • If you added a new Config method, or modified an existing one, you
    ensured that this configuration is exercised by the fuzz targets.

    For example, if you expose a new strategy for allocating the next instance
    slot inside the pooling allocator, you should ensure that at least one of our
    fuzz targets exercises that new strategy.

    Often, all that is required of you is to ensure that there is a knob for this
    configuration option in wasmtime_fuzzing::Config (or one
    of its nested structs).

    Rarely, this may require authoring a new fuzz target to specifically test this
    configuration. See our docs on fuzzing for more details.

  • If you are enabling a configuration option by default, make sure that it
    has been fuzzed for at least two weeks before turning it on by default.


To modify this label's message, edit the .github/label-messager/wasmtime-config.md file.

To add new label messages or remove existing label messages, edit the
.github/label-messager.json configuration file.

Learn more.


let has_native_signals =
!miri && (supported_platform || cfg!(feature = "custom-native-signals"));
let has_virtual_memory = supported_platform || cfg!(feature = "custom-virtual-memory");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasm32-unknown-emscripten is marked as unix, but has neither signals, nor virtual memory. I guess it is not all too important that Wasmtime works on Emscripten though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point yeah, although this unix || windows logic matches what's currently in the sys module so we technically already didn't support Emscripten. It should be reasonable though to add support here though in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fuzzing Issues related to our fuzzing infrastructure wasi Issues pertaining to WASI wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:config Issues related to the configuration of Wasmtime wasmtime:docs Issues related to Wasmtime's documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants