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:
Alex Crichton
2022-07-07 16:28:25 -05:00
committed by GitHub
parent 9c43749dfe
commit 601e8f3094
14 changed files with 134 additions and 121 deletions

View File

@@ -23,7 +23,6 @@ wasmtime-component-macro = { path = "../component-macro", version = "=0.40.0", o
target-lexicon = { version = "0.12.0", default-features = false }
wasmparser = "0.87.0"
anyhow = "1.0.19"
region = "2.2.0"
libc = "0.2"
cfg-if = "1.0"
backtrace = { version = "0.3.61" }

View File

@@ -1458,7 +1458,7 @@ impl Config {
}
fn round_up_to_pages(val: u64) -> u64 {
let page_size = region::page::size() as u64;
let page_size = wasmtime_runtime::page_size() as u64;
debug_assert!(page_size.is_power_of_two());
val.checked_add(page_size - 1)
.map(|val| val & !(page_size - 1))