Remove dependency on the region crate (#4407)
This commit removes Wasmtime's dependency on the `region` crate. The motivation for this came about when I was updating dependencies and saw that `region` had a new major version at 3.0.0 as opposed to our currently used 2.3 track. In reviewing the use cases of `region` within Wasmtime I found two trends in particular which motivated this commit: * Some unix-specific areas of `wasmtime_runtime` use `rustix::mm::mprotect` instead of `region::protect` already. This means that the usage of `region::protect` for changing virtual memory protections was already inconsistent. * Many uses of `region::protect` were already in unix-specific regions which could make use of `rustix`. Overall I opted to remove the dependency on the `region` crate to avoid chasing its versions over time. Unix-specific changes of protections were easily changed to `rustix::mm::mprotect`. There were two locations where a windows/unix split is now required and I subjectively ruled "that seems ok". Finally removing `region` also meant that the "what is the current page size" query needed to be inlined into `wasmtime_runtime`, which I have also subjectively ruled "that seems fine". Finally one final refactoring here was that the `unix.rs` and `linux.rs` split for the pooling allocator was merged. These two files already only differed in one function so I slapped a `cfg_if!` in there to help reduce the duplication.
This commit is contained in:
@@ -21,10 +21,9 @@
|
||||
)]
|
||||
#![cfg_attr(not(memory_init_cow), allow(unused_variables, unreachable_code))]
|
||||
|
||||
use std::sync::atomic::AtomicU64;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Error;
|
||||
use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use wasmtime_environ::DefinedFuncIndex;
|
||||
use wasmtime_environ::DefinedMemoryIndex;
|
||||
use wasmtime_environ::FunctionInfo;
|
||||
@@ -200,3 +199,35 @@ pub trait ModuleRuntimeInfo: Send + Sync + 'static {
|
||||
/// `VMSharedSignatureIndex` entries corresponding to the `SignatureIndex`.
|
||||
fn signature_ids(&self) -> &[VMSharedSignatureIndex];
|
||||
}
|
||||
|
||||
/// Returns the host OS page size, in bytes.
|
||||
pub fn page_size() -> usize {
|
||||
static PAGE_SIZE: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
return match PAGE_SIZE.load(Ordering::Relaxed) {
|
||||
0 => {
|
||||
let size = get_page_size();
|
||||
assert!(size != 0);
|
||||
PAGE_SIZE.store(size, Ordering::Relaxed);
|
||||
size
|
||||
}
|
||||
n => n,
|
||||
};
|
||||
|
||||
#[cfg(windows)]
|
||||
fn get_page_size() -> usize {
|
||||
use std::mem::MaybeUninit;
|
||||
use windows_sys::Win32::System::SystemInformation::*;
|
||||
|
||||
unsafe {
|
||||
let mut info = MaybeUninit::uninit();
|
||||
GetSystemInfo(info.as_mut_ptr());
|
||||
info.assume_init_ref().dwPageSize as usize
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn get_page_size() -> usize {
|
||||
unsafe { libc::sysconf(libc::_SC_PAGESIZE) as usize }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user