Skip to content

Commit

Permalink
mpk: turn on memory_protection_keys during fuzzing (#7393)
Browse files Browse the repository at this point in the history
This also twists the `max_memory_protection_keys` knob.
  • Loading branch information
abrown authored Oct 27, 2023
1 parent 5ea563f commit ecd3747
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions crates/fuzzing/src/generators/pooling_config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Generate instance limits for the pooling allocation strategy.
use arbitrary::{Arbitrary, Unstructured};
use wasmtime::MpkEnabled;

/// Configuration for `wasmtime::PoolingAllocationStrategy`.
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
Expand Down Expand Up @@ -30,6 +31,9 @@ pub struct PoolingAllocationConfig {

pub async_stack_zeroing: bool,
pub async_stack_keep_resident: usize,

pub memory_protection_keys: MpkEnabled,
pub max_memory_protection_keys: usize,
}

impl PoolingAllocationConfig {
Expand Down Expand Up @@ -62,6 +66,8 @@ impl PoolingAllocationConfig {
cfg.async_stack_zeroing(self.async_stack_zeroing);
cfg.async_stack_keep_resident(self.async_stack_keep_resident);

cfg.memory_protection_keys(self.memory_protection_keys);

cfg
}
}
Expand Down Expand Up @@ -104,6 +110,9 @@ impl<'a> Arbitrary<'a> for PoolingAllocationConfig {

async_stack_zeroing: u.arbitrary()?,
async_stack_keep_resident: u.int_in_range(0..=1 << 20)?,

memory_protection_keys: u.choose(&[MpkEnabled::Auto, MpkEnabled::Disable])?.clone(),
max_memory_protection_keys: u.int_in_range(0..=20)?,
})
}
}
2 changes: 1 addition & 1 deletion crates/runtime/src/mpk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ cfg_if::cfg_if! {
}

/// Describe the tri-state configuration of memory protection keys (MPK).
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum MpkEnabled {
/// Use MPK if supported by the current system; fall back to guard regions
/// otherwise.
Expand Down

0 comments on commit ecd3747

Please sign in to comment.