Skip to content

Commit 0ff8f6a

Browse files
committed
Make build-config magic use memfd by default.
1 parent ccfa245 commit 0ff8f6a

File tree

9 files changed

+22
-26
lines changed

9 files changed

+22
-26
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ jobs:
136136
- run: cargo check -p wasmtime --no-default-features --features async
137137
- run: cargo check -p wasmtime --no-default-features --features uffd
138138
- run: cargo check -p wasmtime --no-default-features --features pooling-allocator
139-
- run: cargo check -p wasmtime --no-default-features --features memfd-allocator
140139
- run: cargo check -p wasmtime --no-default-features --features cranelift
141140
- run: cargo check -p wasmtime --no-default-features --features cranelift,wat,async,cache
142141

@@ -316,8 +315,6 @@ jobs:
316315
cargo test --features uffd -p wasmtime-runtime instance::allocator::pooling
317316
cargo test --features uffd -p wasmtime-cli pooling_allocator
318317
cargo test --features uffd -p wasmtime-cli wast::Cranelift
319-
cargo test --features memfd-allocator -p wasmtime-cli pooling_allocator
320-
cargo test --features memfd-allocator -p wasmtime-cli wast::Cranelift
321318
if: matrix.os == 'ubuntu-latest' && matrix.target == ''
322319
env:
323320
RUST_BACKTRACE: 1

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ path = "src/bin/wasmtime.rs"
2121
doc = false
2222

2323
[dependencies]
24-
wasmtime = { path = "crates/wasmtime", version = "0.33.0", default-features = false, features = ['cache', 'cranelift'] }
24+
wasmtime = { path = "crates/wasmtime", version = "0.33.0", default-features = false, features = ['cache', 'cranelift', 'pooling-allocator', 'memfd'] }
2525
wasmtime-cache = { path = "crates/cache", version = "=0.33.0" }
2626
wasmtime-cranelift = { path = "crates/cranelift", version = "=0.33.0" }
2727
wasmtime-environ = { path = "crates/environ", version = "=0.33.0" }
@@ -96,7 +96,6 @@ wasi-crypto = ["wasmtime-wasi-crypto"]
9696
wasi-nn = ["wasmtime-wasi-nn"]
9797
uffd = ["wasmtime/uffd"]
9898
pooling-allocator = ["wasmtime/pooling-allocator"]
99-
memfd-allocator = ["pooling-allocator", "wasmtime/memfd-allocator"]
10099
all-arch = ["wasmtime/all-arch"]
101100
posix-signals-on-macos = ["wasmtime/posix-signals-on-macos"]
102101

crates/runtime/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ backtrace = "0.3.61"
2525
lazy_static = "1.3.0"
2626
rand = "0.8.3"
2727
anyhow = "1.0.38"
28+
memfd = { version = "0.4.1", optional = true }
2829

2930
[target.'cfg(target_os = "macos")'.dependencies]
3031
mach = "0.3.2"
@@ -37,7 +38,6 @@ winapi = { version = "0.3.7", features = ["winbase", "memoryapi", "errhandlingap
3738

3839
[target.'cfg(target_os = "linux")'.dependencies]
3940
userfaultfd = { version = "0.4.1", optional = true }
40-
memfd = { version = "0.4.1", optional = true }
4141

4242
[build-dependencies]
4343
cc = "1.0"
@@ -60,5 +60,3 @@ uffd = ["userfaultfd", "pooling-allocator"]
6060
# It is useful for applications that do not bind their own exception ports and
6161
# need portable signal handling.
6262
posix-signals-on-macos = []
63-
64-
memfd-allocator = ["pooling-allocator", "memfd"]

crates/runtime/build.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,15 @@ fn main() {
1010
)
1111
.file("src/helpers.c")
1212
.compile("wasmtime-helpers");
13+
14+
// Check to see if we are on Linux and the `memfd` feature is
15+
// active. If so, enable the `memfd` rustc cfg so `#[cfg(memfd)]`
16+
// will work.
17+
let os = env::var("CARGO_CFG_TARGET_OS").unwrap();
18+
let is_memfd = env::var("CARGO_FEATURE_MEMFD").is_ok();
19+
let is_pooling = env::var("CARGO_FEATURE_POOLING_ALLOCATOR").is_ok();
20+
let is_uffd = env::var("CARGO_FEATURE_UFFD").is_ok();
21+
if &os == "linux" && is_memfd && is_pooling && !is_uffd {
22+
println!("cargo:rustc-cfg=memfd");
23+
}
1324
}

crates/runtime/src/instance/allocator/pooling.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ impl MemoryPool {
703703
let mapping = Mmap::accessible_reserved(0, allocation_size)
704704
.context("failed to create memory pool mapping")?;
705705

706-
let num_memfd_slots = if cfg!(feature = "memfd-allocator") {
706+
let num_memfd_slots = if cfg!(memfd) {
707707
max_instances * max_memories
708708
} else {
709709
0

crates/runtime/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
clippy::use_self
2020
)
2121
)]
22-
#![cfg_attr(feature = "memfd-allocator", allow(dead_code))]
22+
#![cfg_attr(memfd, allow(dead_code))]
2323

2424
use std::sync::atomic::AtomicU64;
2525

@@ -67,14 +67,14 @@ pub use crate::vmcontext::{
6767
mod module_id;
6868
pub use module_id::{CompiledModuleId, CompiledModuleIdAllocator};
6969

70-
#[cfg(feature = "memfd-allocator")]
70+
#[cfg(memfd)]
7171
mod memfd;
72-
#[cfg(feature = "memfd-allocator")]
72+
#[cfg(memfd)]
7373
pub use crate::memfd::{MemFdSlot, MemoryMemFd, ModuleMemFds};
7474

75-
#[cfg(not(feature = "memfd-allocator"))]
75+
#[cfg(not(memfd))]
7676
mod memfd_disabled;
77-
#[cfg(not(feature = "memfd-allocator"))]
77+
#[cfg(not(memfd))]
7878
pub use crate::memfd_disabled::{MemFdSlot, MemoryMemFd, ModuleMemFds};
7979

8080
/// Version number of this crate.

crates/runtime/src/memfd_disabled.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@ impl ModuleMemFds {
3737
/// To allow MemFdSlot to be unconditionally passed around in various
3838
/// places (e.g. a `Memory`), we define a zero-sized type when memfd is
3939
/// not included in the build.
40-
#[cfg(not(feature = "memfd-allocator"))]
4140
#[derive(Debug)]
4241
pub struct MemFdSlot;
4342

44-
#[cfg(not(feature = "memfd-allocator"))]
4543
#[allow(dead_code)]
4644
impl MemFdSlot {
4745
pub(crate) fn create(_: *mut libc::c_void, _: usize) -> Self {

crates/runtime/src/traphandlers/unix.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,7 @@ pub unsafe fn platform_init() {
5454
// Sometimes we need to handle SIGBUS too:
5555
// - On ARM, handle Unaligned Accesses.
5656
// - On Darwin, guard page accesses are raised as SIGBUS.
57-
// - With the MemFD allocator, heap growth is controlled by
58-
// ftruncate'ing an mmap'd file, and so out-of-bounds accesses
59-
// are raised as SIGBUS.
60-
if cfg!(target_arch = "arm")
61-
|| cfg!(target_os = "macos")
62-
|| cfg!(target_os = "freebsd")
63-
|| cfg!(feature = "memfd-allocator")
64-
{
57+
if cfg!(target_arch = "arm") || cfg!(target_os = "macos") || cfg!(target_os = "freebsd") {
6558
register(&mut PREV_SIGBUS, libc::SIGBUS);
6659
}
6760
}

crates/wasmtime/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ wasi-cap-std-sync = { path = "../wasi-common/cap-std-sync" }
5050
maintenance = { status = "actively-developed" }
5151

5252
[features]
53-
default = ['async', 'cache', 'wat', 'jitdump', 'parallel-compilation', 'cranelift', 'pooling-allocator']
53+
default = ['async', 'cache', 'wat', 'jitdump', 'parallel-compilation', 'cranelift', 'pooling-allocator', 'memfd']
5454

5555
# An on-by-default feature enabling runtime compilation of WebAssembly modules
5656
# with the Cranelift compiler. Cranelift is the default compilation backend of
@@ -90,4 +90,4 @@ all-arch = ["wasmtime-cranelift/all-arch"]
9090
# need portable signal handling.
9191
posix-signals-on-macos = ["wasmtime-runtime/posix-signals-on-macos"]
9292

93-
memfd-allocator = ["wasmtime-runtime/memfd-allocator", "pooling-allocator"]
93+
memfd = ["wasmtime-runtime/memfd", "pooling-allocator"]

0 commit comments

Comments
 (0)