Make build-config magic use memfd by default.

This commit is contained in:
Chris Fallin
2022-01-31 16:54:04 -08:00
parent ccfa245261
commit 0ff8f6ab20
9 changed files with 22 additions and 26 deletions

View File

@@ -25,6 +25,7 @@ backtrace = "0.3.61"
lazy_static = "1.3.0"
rand = "0.8.3"
anyhow = "1.0.38"
memfd = { version = "0.4.1", optional = true }
[target.'cfg(target_os = "macos")'.dependencies]
mach = "0.3.2"
@@ -37,7 +38,6 @@ winapi = { version = "0.3.7", features = ["winbase", "memoryapi", "errhandlingap
[target.'cfg(target_os = "linux")'.dependencies]
userfaultfd = { version = "0.4.1", optional = true }
memfd = { version = "0.4.1", optional = true }
[build-dependencies]
cc = "1.0"
@@ -60,5 +60,3 @@ uffd = ["userfaultfd", "pooling-allocator"]
# It is useful for applications that do not bind their own exception ports and
# need portable signal handling.
posix-signals-on-macos = []
memfd-allocator = ["pooling-allocator", "memfd"]

View File

@@ -10,4 +10,15 @@ fn main() {
)
.file("src/helpers.c")
.compile("wasmtime-helpers");
// Check to see if we are on Linux and the `memfd` feature is
// active. If so, enable the `memfd` rustc cfg so `#[cfg(memfd)]`
// will work.
let os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let is_memfd = env::var("CARGO_FEATURE_MEMFD").is_ok();
let is_pooling = env::var("CARGO_FEATURE_POOLING_ALLOCATOR").is_ok();
let is_uffd = env::var("CARGO_FEATURE_UFFD").is_ok();
if &os == "linux" && is_memfd && is_pooling && !is_uffd {
println!("cargo:rustc-cfg=memfd");
}
}

View File

@@ -703,7 +703,7 @@ impl MemoryPool {
let mapping = Mmap::accessible_reserved(0, allocation_size)
.context("failed to create memory pool mapping")?;
let num_memfd_slots = if cfg!(feature = "memfd-allocator") {
let num_memfd_slots = if cfg!(memfd) {
max_instances * max_memories
} else {
0

View File

@@ -19,7 +19,7 @@
clippy::use_self
)
)]
#![cfg_attr(feature = "memfd-allocator", allow(dead_code))]
#![cfg_attr(memfd, allow(dead_code))]
use std::sync::atomic::AtomicU64;
@@ -67,14 +67,14 @@ pub use crate::vmcontext::{
mod module_id;
pub use module_id::{CompiledModuleId, CompiledModuleIdAllocator};
#[cfg(feature = "memfd-allocator")]
#[cfg(memfd)]
mod memfd;
#[cfg(feature = "memfd-allocator")]
#[cfg(memfd)]
pub use crate::memfd::{MemFdSlot, MemoryMemFd, ModuleMemFds};
#[cfg(not(feature = "memfd-allocator"))]
#[cfg(not(memfd))]
mod memfd_disabled;
#[cfg(not(feature = "memfd-allocator"))]
#[cfg(not(memfd))]
pub use crate::memfd_disabled::{MemFdSlot, MemoryMemFd, ModuleMemFds};
/// Version number of this crate.

View File

@@ -37,11 +37,9 @@ impl ModuleMemFds {
/// To allow MemFdSlot to be unconditionally passed around in various
/// places (e.g. a `Memory`), we define a zero-sized type when memfd is
/// not included in the build.
#[cfg(not(feature = "memfd-allocator"))]
#[derive(Debug)]
pub struct MemFdSlot;
#[cfg(not(feature = "memfd-allocator"))]
#[allow(dead_code)]
impl MemFdSlot {
pub(crate) fn create(_: *mut libc::c_void, _: usize) -> Self {

View File

@@ -54,14 +54,7 @@ pub unsafe fn platform_init() {
// Sometimes we need to handle SIGBUS too:
// - On ARM, handle Unaligned Accesses.
// - On Darwin, guard page accesses are raised as SIGBUS.
// - With the MemFD allocator, heap growth is controlled by
// ftruncate'ing an mmap'd file, and so out-of-bounds accesses
// are raised as SIGBUS.
if cfg!(target_arch = "arm")
|| cfg!(target_os = "macos")
|| cfg!(target_os = "freebsd")
|| cfg!(feature = "memfd-allocator")
{
if cfg!(target_arch = "arm") || cfg!(target_os = "macos") || cfg!(target_os = "freebsd") {
register(&mut PREV_SIGBUS, libc::SIGBUS);
}
}

View File

@@ -50,7 +50,7 @@ wasi-cap-std-sync = { path = "../wasi-common/cap-std-sync" }
maintenance = { status = "actively-developed" }
[features]
default = ['async', 'cache', 'wat', 'jitdump', 'parallel-compilation', 'cranelift', 'pooling-allocator']
default = ['async', 'cache', 'wat', 'jitdump', 'parallel-compilation', 'cranelift', 'pooling-allocator', 'memfd']
# An on-by-default feature enabling runtime compilation of WebAssembly modules
# with the Cranelift compiler. Cranelift is the default compilation backend of
@@ -90,4 +90,4 @@ all-arch = ["wasmtime-cranelift/all-arch"]
# need portable signal handling.
posix-signals-on-macos = ["wasmtime-runtime/posix-signals-on-macos"]
memfd-allocator = ["wasmtime-runtime/memfd-allocator", "pooling-allocator"]
memfd = ["wasmtime-runtime/memfd", "pooling-allocator"]