Skip to content

Commit

Permalink
Enable warnings if pooling-allocator is disabled (#10142)
Browse files Browse the repository at this point in the history
* Enable warnings if `pooling-allocator` is disabled

Continuation of work in #10131

* Fix windows build
  • Loading branch information
alexcrichton authored Jan 28, 2025
1 parent a7d76ec commit 24620d9
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 3 deletions.
1 change: 0 additions & 1 deletion crates/wasmtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@
not(feature = "gc-drc"),
not(feature = "gc-null"),
not(feature = "cranelift"),
not(feature = "pooling-allocator"),
not(feature = "runtime"),
not(feature = "std"),
),
Expand Down
1 change: 1 addition & 0 deletions crates/wasmtime/src/runtime/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ impl ModuleRuntimeInfo {
/// A unique ID for this particular module. This can be used to
/// allow for fastpaths to optimize a "re-instantiate the same
/// module again" case.
#[cfg(feature = "pooling-allocator")]
fn unique_id(&self) -> Option<CompiledModuleId> {
match self {
ModuleRuntimeInfo::Module(m) => Some(m.id()),
Expand Down
9 changes: 9 additions & 0 deletions crates/wasmtime/src/runtime/vm/instance/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ pub struct InstanceAllocationRequest<'a> {

/// Request that the instance's memories be protected by a specific
/// protection key.
#[cfg_attr(
not(feature = "pooling-allocator"),
expect(
dead_code,
reason = "easier to keep this field than remove it, not perf-critical to remove"
)
)]
pub pkey: Option<ProtectionKey>,

/// Tunable configuration options the engine is using.
Expand Down Expand Up @@ -126,6 +133,7 @@ impl Default for MemoryAllocationIndex {

impl MemoryAllocationIndex {
/// Get the underlying index of this `MemoryAllocationIndex`.
#[cfg(feature = "pooling-allocator")]
pub fn index(&self) -> usize {
self.0 as usize
}
Expand All @@ -145,6 +153,7 @@ impl Default for TableAllocationIndex {

impl TableAllocationIndex {
/// Get the underlying index of this `TableAllocationIndex`.
#[cfg(feature = "pooling-allocator")]
pub fn index(&self) -> usize {
self.0 as usize
}
Expand Down
4 changes: 4 additions & 0 deletions crates/wasmtime/src/runtime/vm/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ pub use self::mmap::MmapMemory;
mod malloc;
pub use self::malloc::MallocMemory;

#[cfg(feature = "pooling-allocator")]
mod static_;
#[cfg(feature = "pooling-allocator")]
use self::static_::StaticMemory;

#[cfg(feature = "threads")]
Expand Down Expand Up @@ -244,6 +246,7 @@ impl Memory {
}

/// Create a new static (immovable) memory instance for the specified plan.
#[cfg(feature = "pooling-allocator")]
pub fn new_static(
ty: &wasmtime_environ::Memory,
tunables: &Tunables,
Expand Down Expand Up @@ -732,6 +735,7 @@ impl LocalMemory {
base..end
}

#[cfg(feature = "pooling-allocator")]
pub fn unwrap_static_image(self) -> MemoryImageSlot {
self.memory_image.unwrap()
}
Expand Down
9 changes: 9 additions & 0 deletions crates/wasmtime/src/runtime/vm/mpk/disabled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
#![allow(missing_docs)]

#[cfg(feature = "pooling-allocator")]
use crate::prelude::*;

#[cfg(feature = "pooling-allocator")]
pub fn is_supported() -> bool {
false
}

#[cfg(feature = "pooling-allocator")]
pub fn keys(_: usize) -> &'static [ProtectionKey] {
&[]
}

pub fn allow(_: ProtectionMask) {}

pub fn current_mask() -> ProtectionMask {
Expand All @@ -20,9 +25,11 @@ pub fn current_mask() -> ProtectionMask {
#[derive(Clone, Copy, Debug)]
pub enum ProtectionKey {}
impl ProtectionKey {
#[cfg(feature = "pooling-allocator")]
pub fn protect(&self, _: &mut [u8]) -> Result<()> {
match *self {}
}
#[cfg(feature = "pooling-allocator")]
pub fn as_stripe(&self) -> usize {
match *self {}
}
Expand All @@ -34,9 +41,11 @@ impl ProtectionMask {
pub fn all() -> Self {
Self
}
#[cfg(feature = "pooling-allocator")]
pub fn zero() -> Self {
Self
}
#[cfg(feature = "pooling-allocator")]
pub fn or(self, _: ProtectionKey) -> Self {
Self
}
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmtime/src/runtime/vm/mpk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ cfg_if::cfg_if! {
mod enabled;
mod pkru;
mod sys;
pub use enabled::{allow, current_mask, is_supported, keys, ProtectionKey, ProtectionMask};
pub use enabled::*;
} else {
mod disabled;
pub use disabled::{allow, current_mask, is_supported, keys, ProtectionKey, ProtectionMask};
pub use disabled::*;
}
}
1 change: 1 addition & 0 deletions crates/wasmtime/src/runtime/vm/sys/unix/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub unsafe fn commit_pages(_addr: *mut u8, _len: usize) -> io::Result<()> {
Ok(())
}

#[cfg(feature = "pooling-allocator")]
pub unsafe fn decommit_pages(addr: *mut u8, len: usize) -> io::Result<()> {
if len == 0 {
return Ok(());
Expand Down
1 change: 1 addition & 0 deletions crates/wasmtime/src/runtime/vm/sys/windows/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub unsafe fn commit_pages(addr: *mut u8, len: usize) -> io::Result<()> {
expose_existing_mapping(addr, len)
}

#[cfg(feature = "pooling-allocator")]
pub unsafe fn decommit_pages(addr: *mut u8, len: usize) -> io::Result<()> {
erase_existing_mapping(addr, len)
}
Expand Down

0 comments on commit 24620d9

Please sign in to comment.