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

Method new

tests/all/memory_creator.rs:19–47  ·  view source on GitHub ↗
(minimum: usize, maximum: usize, glob_counter: Arc<Mutex<usize>>)

Source from the content-addressed store, hash-verified

17
18 impl CustomMemory {
19 unsafe fn new(minimum: usize, maximum: usize, glob_counter: Arc<Mutex<usize>>) -> Self {
20 let page_size = rustix::param::page_size();
21 let guard_size = page_size;
22 let size = maximum + guard_size;
23 // We rely on the Wasm page size being multiple of host page size.
24 assert_eq!(size % page_size, 0);
25
26 let mem = unsafe {
27 mmap_anonymous(null_mut(), size, ProtFlags::empty(), MapFlags::PRIVATE)
28 .expect("mmap failed")
29 };
30
31 // NOTE: mmap_anonymous returns zero initialized memory, which is relied upon by this
32 // API.
33
34 unsafe {
35 mprotect(mem, minimum, MprotectFlags::READ | MprotectFlags::WRITE)
36 .expect("mprotect failed");
37 }
38 *glob_counter.lock().unwrap() += minimum;
39
40 Self {
41 mem: mem as usize,
42 size,
43 guard_size,
44 used_wasm_bytes: minimum,
45 glob_bytes_counter: glob_counter,
46 }
47 }
48 }
49
50 impl Drop for CustomMemory {

Callers

nothing calls this directly

Calls 5

emptyFunction · 0.50
newFunction · 0.50
expectMethod · 0.45
unwrapMethod · 0.45
lockMethod · 0.45

Tested by

no test coverage detected