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

Consolidate platform-specific definitions in Wasmtime #7626

Merged

Conversation

alexcrichton
Copy link
Member

Prior to this commit Wasmtime did not not have a style or system for
containing platform-specific logic in files. The goal of this commit is
to consolidate all platform-specific functionality into one location to
make it easier to port Wasmtime to new systems. This commit creates a
sys module within the wasmtime-runtime crate which conditionally
defines all of the platform support that Wasmtime requires, namely
things related to virtual memory management and trap handling. Many of
the previous unix.rs files interspersed throughout the tree are now
all located in a single unix directory. This additionally helps split
out miri-specific functionality by pretending miri is its own
platform.

This change additionally goes through #[cfg] directives throughout
wasmtime-runtime, wasmtime-jit, and wasmtime itself to place all
of this target-specific functionality within this sys directory. The
end state is that there are two new top-level modules in the
wasmtime-runtime crate:

  • arch - this conditionally defines architecture-specific logic such
    as the state used by backtraces, libcalls, etc.
  • sys - this conditionally defines OS or platform-specific logic such
    as virtual memory management.

One secondary goal of this commit is to enable the ability to easily
add new platforms to Wasmtime, even if it's in a fork of Wasmtime.
Previously patches might have to touch a good number of locations where
now they'd ideally only have to touch sys/mod.rs to declare a new
platform and sys/$platform/*.rs to define all the functionality.

This commit extends the gating behavior of the preexisting
`debug-builtins` Cargo feature to cover more GDB-related functionality
associated with debugging. This can additionally slim down the set of
exposed symbols from Wasmtime over the default with them included.
This commit adds a `timing` feature to the `cranelift-codegen` crate
which is enabled by default. This feature gates the timing functionality
in Cranelift to enable turning it off if desired. The goal of this
commit is to remove a system dependency on `Instant` for possibly
esoteric environments.
Prior to this commit Wasmtime did not not have a style or system for
containing platform-specific logic in files. The goal of this commit is
to consolidate all platform-specific functionality into one location to
make it easier to port Wasmtime to new systems. This commit creates a
`sys` module within the `wasmtime-runtime` crate which conditionally
defines all of the platform support that Wasmtime requires, namely
things related to virtual memory management and trap handling. Many of
the previous `unix.rs` files interspersed throughout the tree are now
all located in a single `unix` directory. This additionally helps split
out `miri`-specific functionality by pretending `miri` is its own
platform.

This change additionally goes through `#[cfg]` directives throughout
`wasmtime-runtime`, `wasmtime-jit`, and `wasmtime` itself to place all
of this target-specific functionality within this `sys` directory. The
end state is that there are two new top-level modules in the
`wasmtime-runtime` crate:

* `arch` - this conditionally defines architecture-specific logic such
  as the state used by backtraces, libcalls, etc.
* `sys` - this conditionally defines OS or platform-specific logic such
  as virtual memory management.

One secondary goal of this commit is to enable the ability to easily
add new platforms to Wasmtime, even if it's in a fork of Wasmtime.
Previously patches might have to touch a good number of locations where
now they'd ideally only have to touch `sys/mod.rs` to declare a new
platform and `sys/$platform/*.rs` to define all the functionality.
@alexcrichton alexcrichton requested review from a team as code owners December 3, 2023 05:53
@alexcrichton alexcrichton requested review from abrown and pchickey and removed request for a team December 3, 2023 05:53
@github-actions github-actions bot added the cranelift Issues related to the Cranelift code generator label Dec 3, 2023
Copy link
Contributor

@abrown abrown left a comment

Choose a reason for hiding this comment

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

I think this is good to go. The idea of centralizing all the platform-specific bits into one place is a good one. @alexcrichton, my take is that none of this refactoring should substantially change any logic, at least observably for users; is that right?

crates/runtime/src/cow.rs Outdated Show resolved Hide resolved
crates/runtime/src/sys/miri/vm.rs Outdated Show resolved Hide resolved
crates/runtime/src/sys/miri/traphandlers.rs Outdated Show resolved Hide resolved
crates/runtime/src/sys/mod.rs Outdated Show resolved Hide resolved
crates/runtime/src/sys/unix/signals.rs Show resolved Hide resolved
@@ -47,6 +88,7 @@ macro_rules! wasm_to_libcall_trampoline {
);
};
}
pub(crate) use wasm_to_libcall_trampoline;

#[cfg(test)]
mod wasm_to_libcall_trampoline_offsets_tests {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess a future refactor could move the MPK stuff here as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

True! I forgot to go back and handle that one as well.

The disabled.rs file would be used on Windows/MIRI/non-x86_64. Some bits would probably go into arch like pkru.rs and others would go into unix/mpk.rs perhaps where non-Linux systems would use disabled.rs and Linux would use the "real version"

@alexcrichton
Copy link
Member Author

my take is that none of this refactoring should substantially change any logic, at least observably for users; is that right?

Correct!

@abrown abrown added this pull request to the merge queue Dec 4, 2023
Merged via the queue into bytecodealliance:main with commit 494e2b8 Dec 4, 2023
41 checks passed
@alexcrichton alexcrichton deleted the consolidate-platform-definitions branch December 5, 2023 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants