1 use crate::vm::sys::DecommitBehavior; 2 use std::fs::File; 3 use std::io; 4 use std::mem::MaybeUninit; 5 use std::sync::Arc; 6 use windows_sys::Win32::System::Memory::*; 7 use windows_sys::Win32::System::SystemInformation::*; 8 9 pub use crate::runtime::vm::pagemap_disabled::{PageMap, reset_with_pagemap}; 10 11 pub unsafe fn expose_existing_mapping(ptr: *mut u8, len: usize) -> io::Result<()> { 12 if len == 0 { 13 return Ok(()); 14 } 15 if unsafe { VirtualAlloc(ptr.cast(), len, MEM_COMMIT, PAGE_READWRITE).is_null() } { 16 Err(std::io::Error::last_os_error()) 17 } else { 18 Ok(()) 19 } 20 } 21 22 pub unsafe fn hide_existing_mapping(ptr: *mut u8, len: usize) -> io::Result<()> { 23 unsafe { erase_existing_mapping(ptr, len) } 24 } 25 26 pub unsafe fn erase_existing_mapping(ptr: *mut u8, len: usize) -> io::Result<()> { 27 if len == 0 { 28 return Ok(()); 29 } 30 if unsafe { VirtualFree(ptr.cast(), len, MEM_DECOMMIT) == 0 } { 31 Err(std::io::Error::last_os_error()) 32 } else { 33 Ok(()) 34 } 35 } 36 37 #[cfg(feature = "pooling-allocator")] 38 pub unsafe fn commit_pages(addr: *mut u8, len: usize) -> io::Result<()> { 39 unsafe { expose_existing_mapping(addr, len) } 40 } 41 42 #[cfg(feature = "pooling-allocator")] 43 pub unsafe fn decommit_pages(addr: *mut u8, len: usize) -> io::Result<()> { 44 unsafe { erase_existing_mapping(addr, len) } 45 } 46 47 pub fn get_page_size() -> usize { 48 unsafe { 49 let mut info = MaybeUninit::uninit(); 50 GetSystemInfo(info.as_mut_ptr()); 51 info.assume_init_ref().dwPageSize as usize 52 } 53 } 54 55 pub fn decommit_behavior() -> DecommitBehavior { 56 DecommitBehavior::Zero 57 } 58 59 #[derive(PartialEq, Debug)] 60 pub enum MemoryImageSource {} 61 62 impl MemoryImageSource { 63 pub fn from_file(_file: &Arc<File>) -> Option<MemoryImageSource> { 64 None 65 } 66 67 pub fn from_data(_data: &[u8]) -> io::Result<Option<MemoryImageSource>> { 68 Ok(None) 69 } 70 71 pub unsafe fn remap_as_zeros_at(&self, _base: *mut u8, _len: usize) -> io::Result<()> { 72 match *self {} 73 } 74 } 75