wasmtime/runtime/vm/
pagemap_disabled.rs

1use crate::runtime::vm::HostAlignedByteCount;
2use core::slice;
3
4#[derive(Debug)]
5pub enum PageMap {}
6
7impl PageMap {
8    #[allow(dead_code, reason = "not used on linux64")]
9    pub fn new() -> Option<PageMap> {
10        None
11    }
12}
13
14/// Resets `ptr` for `len` bytes.
15///
16/// # Safety
17///
18/// Requires that `ptr` is valid to read and write for `len` bytes.
19pub unsafe fn reset_with_pagemap(
20    _pagemap: Option<&PageMap>,
21    mut ptr: *mut u8,
22    mut len: HostAlignedByteCount,
23    mut keep_resident: HostAlignedByteCount,
24    mut reset_manually: impl FnMut(&mut [u8]),
25    mut decommit: impl FnMut(*mut u8, usize),
26) {
27    keep_resident = keep_resident.min(len);
28
29    // `memset` the first `keep_resident` bytes.
30    //
31    // SAFETY: it's a contract of this function that `ptr` is valid to write for
32    // `len` bytes, and `keep_resident` is less than `len` here.
33    unsafe {
34        reset_manually(slice::from_raw_parts_mut(ptr, keep_resident.byte_count()));
35    }
36
37    // SAFETY: It's a contract of this function that the parameters are valid to
38    // always produce an in-bounds pointer.
39    unsafe {
40        ptr = ptr.add(keep_resident.byte_count());
41    }
42    len = len.checked_sub(keep_resident).unwrap();
43
44    // decommit the rest of it.
45    decommit(ptr, len.byte_count())
46}