add a hook to ResourceLimiter to detect memory grow failure.

* allow the ResourceLimiter to reject a memory grow before the
memory's own maximum.
* add a hook so a ResourceLimiter can detect any reason that
a memory grow fails, including if the OS denies additional memory
* add tests for this new functionality. I only took the time to
test the OS denial on Linux, it should be possible on Mac OS
as well but I don't have a test setup. I have no idea how to
do this on windows.
This commit is contained in:
Pat Hickey
2021-09-14 11:24:11 -07:00
parent 2412e8d784
commit bb7f58d936
6 changed files with 249 additions and 47 deletions

View File

@@ -62,7 +62,7 @@ mod not_for_windows {
Some(self.size - self.guard_size)
}
fn grow_to(&mut self, new_size: usize) -> Option<()> {
fn grow_to(&mut self, new_size: usize) -> Result<(), anyhow::Error> {
println!("grow to {:x}", new_size);
let delta = new_size - self.used_wasm_bytes;
unsafe {
@@ -73,7 +73,7 @@ mod not_for_windows {
*self.glob_bytes_counter.lock().unwrap() += delta;
self.used_wasm_bytes = new_size;
Some(())
Ok(())
}
fn as_ptr(&self) -> *mut u8 {