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

Function guards_present

tests/all/memory.rs:147–191  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

145#[cfg_attr(miri, ignore)]
146#[cfg_attr(asan, ignore)]
147fn guards_present() -> Result<()> {
148 const GUARD_SIZE: u64 = 65536;
149
150 let mut config = Config::new();
151 config.memory_reservation(1 << 20);
152 config.memory_guard_size(GUARD_SIZE);
153 config.guard_before_linear_memory(true);
154 let engine = Engine::new(&config)?;
155 let mut store = Store::new(&engine, ());
156 let static_mem = Memory::new(&mut store, MemoryType::new(1, Some(2)))?;
157 let dynamic_mem = Memory::new(&mut store, MemoryType::new(1, None))?;
158
159 let assert_guards = |store: &Store<()>| unsafe {
160 // guards before
161 println!("check pre-static-mem");
162 assert_faults(static_mem.data_ptr(&store).offset(-(GUARD_SIZE as isize)));
163 println!("check pre-dynamic-mem");
164 assert_faults(dynamic_mem.data_ptr(&store).offset(-(GUARD_SIZE as isize)));
165
166 // guards after
167 println!("check post-static-mem");
168 assert_faults(
169 static_mem
170 .data_ptr(&store)
171 .add(static_mem.data_size(&store)),
172 );
173 println!("check post-dynamic-mem");
174 assert_faults(
175 dynamic_mem
176 .data_ptr(&store)
177 .add(dynamic_mem.data_size(&store)),
178 );
179 };
180 assert_guards(&store);
181 // static memory should start with the second page unmapped
182 unsafe {
183 assert_faults(static_mem.data_ptr(&store).add(65536));
184 }
185 println!("growing");
186 static_mem.grow(&mut store, 1).unwrap();
187 dynamic_mem.grow(&mut store, 1).unwrap();
188 assert_guards(&store);
189
190 Ok(())
191}
192
193#[wasmtime_test]
194#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 13

assert_faultsFunction · 0.85
assert_guardsFunction · 0.85
OkFunction · 0.85
data_ptrMethod · 0.80
newFunction · 0.50
memory_reservationMethod · 0.45
memory_guard_sizeMethod · 0.45
offsetMethod · 0.45
addMethod · 0.45
data_sizeMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected