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

Function memory_guard_page_trap

tests/all/pooling_allocator.rs:136–196  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

134#[test]
135#[cfg_attr(miri, ignore)]
136fn memory_guard_page_trap() -> Result<()> {
137 let mut pool = crate::small_pool_config();
138 pool.max_memory_size(2 << 16).table_elements(0);
139 let mut config = Config::new();
140 config.allocation_strategy(pool);
141
142 let engine = Engine::new(&config)?;
143
144 let module = Module::new(
145 &engine,
146 r#"
147 (module
148 (memory (export "m") 0)
149 (func (export "f") (param i32) local.get 0 i32.load drop)
150 )
151 "#,
152 )?;
153
154 // Instantiate the module and check for out of bounds trap
155 for _ in 0..10 {
156 let mut store = Store::new(&engine, ());
157 let instance = Instance::new(&mut store, &module, &[])?;
158 let m = instance.get_memory(&mut store, "m").unwrap();
159 let f = instance.get_typed_func::<i32, ()>(&mut store, "f")?;
160
161 let trap = f
162 .call(&mut store, 0)
163 .expect_err("function should trap")
164 .downcast::<Trap>()?;
165 assert_eq!(trap, Trap::MemoryOutOfBounds);
166
167 let trap = f
168 .call(&mut store, 1)
169 .expect_err("function should trap")
170 .downcast::<Trap>()?;
171 assert_eq!(trap, Trap::MemoryOutOfBounds);
172
173 m.grow(&mut store, 1).expect("memory should grow");
174 f.call(&mut store, 0).expect("function should not trap");
175
176 let trap = f
177 .call(&mut store, 65536)
178 .expect_err("function should trap")
179 .downcast::<Trap>()?;
180 assert_eq!(trap, Trap::MemoryOutOfBounds);
181
182 let trap = f
183 .call(&mut store, 65537)
184 .expect_err("function should trap")
185 .downcast::<Trap>()?;
186 assert_eq!(trap, Trap::MemoryOutOfBounds);
187
188 m.grow(&mut store, 1).expect("memory should grow");
189 f.call(&mut store, 65536).expect("function should not trap");
190
191 m.grow(&mut store, 1)
192 .expect_err("memory should be at the limit");
193 }

Callers

nothing calls this directly

Calls 11

OkFunction · 0.85
allocation_strategyMethod · 0.80
small_pool_configFunction · 0.70
newFunction · 0.50
table_elementsMethod · 0.45
max_memory_sizeMethod · 0.45
unwrapMethod · 0.45
get_memoryMethod · 0.45
callMethod · 0.45
expectMethod · 0.45
growMethod · 0.45

Tested by

no test coverage detected