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

Function guards_present_pooling

tests/all/memory.rs:196–250  ·  view source on GitHub ↗
(config: &mut Config)

Source from the content-addressed store, hash-verified

194#[cfg_attr(miri, ignore)]
195#[cfg_attr(asan, ignore)]
196fn guards_present_pooling(config: &mut Config) -> Result<()> {
197 const GUARD_SIZE: u64 = 65536;
198
199 let mut pool = crate::small_pool_config();
200 pool.total_memories(2)
201 .max_memory_size(10 << 16)
202 .memory_protection_keys(Enabled::No);
203 config.memory_reservation(1 << 20);
204 config.memory_guard_size(GUARD_SIZE);
205 config.guard_before_linear_memory(true);
206 config.allocation_strategy(InstanceAllocationStrategy::Pooling(pool));
207 let engine = Engine::new(&config)?;
208
209 let mut store = Store::new(&engine, ());
210
211 let mem1 = {
212 let m = Module::new(&engine, "(module (memory (export \"\") 1 2))")?;
213 Instance::new(&mut store, &m, &[])?
214 .get_memory(&mut store, "")
215 .unwrap()
216 };
217 let mem2 = {
218 let m = Module::new(&engine, "(module (memory (export \"\") 1))")?;
219 Instance::new(&mut store, &m, &[])?
220 .get_memory(&mut store, "")
221 .unwrap()
222 };
223
224 unsafe fn assert_guards(store: &Store<()>, mem: &Memory) {
225 unsafe {
226 // guards before
227 println!("check pre-mem");
228 assert_faults(mem.data_ptr(&store).offset(-(GUARD_SIZE as isize)));
229
230 // unmapped just after memory
231 println!("check mem");
232 assert_faults(mem.data_ptr(&store).add(mem.data_size(&store)));
233
234 // guards after memory
235 println!("check post-mem");
236 assert_faults(mem.data_ptr(&store).add(1 << 20));
237 }
238 }
239 unsafe {
240 assert_guards(&store, &mem1);
241 assert_guards(&store, &mem2);
242 println!("growing");
243 mem1.grow(&mut store, 1).unwrap();
244 mem2.grow(&mut store, 1).unwrap();
245 assert_guards(&store, &mem1);
246 assert_guards(&store, &mem2);
247 }
248
249 Ok(())
250}
251
252#[wasmtime_test]
253#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 14

assert_guardsFunction · 0.85
OkFunction · 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
unwrapMethod · 0.45

Tested by

no test coverage detected