MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / guards_present_pooling_mpk

Function guards_present_pooling_mpk

tests/all/memory.rs:256–315  ·  view source on GitHub ↗

only platform with mpk

(config: &mut Config)

Source from the content-addressed store, hash-verified

254#[cfg_attr(asan, ignore)]
255#[cfg(target_arch = "x86_64")] // only platform with mpk
256fn guards_present_pooling_mpk(config: &mut Config) -> Result<()> {
257 if !wasmtime::PoolingAllocationConfig::are_memory_protection_keys_available() {
258 println!("skipping `guards_present_pooling_mpk` test; mpk is not supported");
259 return Ok(());
260 }
261
262 const GUARD_SIZE: u64 = 65536;
263 let mut pool = crate::small_pool_config();
264 pool.total_memories(4)
265 .max_memory_size(10 << 16)
266 .memory_protection_keys(Enabled::Yes)
267 .max_memory_protection_keys(2);
268 config.memory_reservation(1 << 20);
269 config.memory_guard_size(GUARD_SIZE);
270 config.guard_before_linear_memory(true);
271 config.allocation_strategy(InstanceAllocationStrategy::Pooling(pool));
272 let engine = Engine::new(&config)?;
273
274 let mut store = Store::new(&engine, ());
275
276 let mem1 = {
277 let m = Module::new(&engine, "(module (memory (export \"\") 1 2))")?;
278 Instance::new(&mut store, &m, &[])?
279 .get_memory(&mut store, "")
280 .unwrap()
281 };
282 let mem2 = {
283 let m = Module::new(&engine, "(module (memory (export \"\") 1))")?;
284 Instance::new(&mut store, &m, &[])?
285 .get_memory(&mut store, "")
286 .unwrap()
287 };
288
289 unsafe fn assert_guards(store: &Store<()>, mem: &Memory) {
290 unsafe {
291 // guards before
292 println!("check pre-mem");
293 assert_faults(mem.data_ptr(&store).offset(-(GUARD_SIZE as isize)));
294
295 // unmapped just after memory
296 println!("check mem");
297 assert_faults(mem.data_ptr(&store).add(mem.data_size(&store)));
298
299 // guards after memory
300 println!("check post-mem");
301 assert_faults(mem.data_ptr(&store).add(1 << 20));
302 }
303 }
304 unsafe {
305 assert_guards(&store, &mem1);
306 assert_guards(&store, &mem2);
307 println!("growing");
308 mem1.grow(&mut store, 1).unwrap();
309 mem2.grow(&mut store, 1).unwrap();
310 assert_guards(&store, &mem1);
311 assert_guards(&store, &mem2);
312 }
313

Callers

nothing calls this directly

Calls 15

OkFunction · 0.85
assert_guardsFunction · 0.85
allocation_strategyMethod · 0.80
small_pool_configFunction · 0.70
newFunction · 0.50
max_memory_sizeMethod · 0.45
total_memoriesMethod · 0.45
memory_reservationMethod · 0.45
memory_guard_sizeMethod · 0.45

Tested by

no test coverage detected