Code review feedback changes.

* Add `anyhow` dependency to `wasmtime-runtime`.
* Revert `get_data` back to `fn`.
* Remove `DataInitializer` and box the data in `Module` translation instead.
* Improve comments on `MemoryInitialization`.
* Remove `MemoryInitialization::OutOfBounds` in favor of proper bulk memory
  semantics.
* Use segmented memory initialization except for when the uffd feature is
  enabled on Linux.
* Validate modules with the allocator after translation.
* Updated various functions in the runtime to return `anyhow::Result`.
* Use a slice when copying pages instead of `ptr::copy_nonoverlapping`.
* Remove unnecessary casts in `OnDemandAllocator::deallocate`.
* Better document the `uffd` feature.
* Use WebAssembly page-sized pages in the paged initialization.
* Remove the stack pool from the uffd handler and simply protect just the guard
  pages.
This commit is contained in:
Peter Huene
2021-03-03 16:41:33 -08:00
parent 5ee2b8742a
commit a464465e2f
19 changed files with 569 additions and 791 deletions

View File

@@ -43,7 +43,7 @@ impl<'config> ModuleCacheEntry<'config> {
}
/// Gets cached data if state matches, otherwise calls the `compute`.
pub fn get_data<T, U, E>(&self, state: T, compute: impl Fn(T) -> Result<U, E>) -> Result<U, E>
pub fn get_data<T, U, E>(&self, state: T, compute: fn(T) -> Result<U, E>) -> Result<U, E>
where
T: Hash,
U: Serialize + for<'a> Deserialize<'a>,

View File

@@ -65,68 +65,28 @@ fn test_write_read_cache() {
let entry1 = ModuleCacheEntry::from_inner(ModuleCacheEntryInner::new(compiler1, &cache_config));
let entry2 = ModuleCacheEntry::from_inner(ModuleCacheEntryInner::new(compiler2, &cache_config));
entry1
.get_data(1, |_| -> Result<i32, ()> { Ok(100) })
.unwrap();
entry1
.get_data(1, |_| -> Result<i32, ()> { panic!() })
.unwrap();
entry1.get_data::<_, i32, i32>(1, |_| Ok(100)).unwrap();
entry1.get_data::<_, i32, i32>(1, |_| panic!()).unwrap();
entry1
.get_data(2, |_| -> Result<i32, ()> { Ok(100) })
.unwrap();
entry1
.get_data(1, |_| -> Result<i32, ()> { panic!() })
.unwrap();
entry1
.get_data(2, |_| -> Result<i32, ()> { panic!() })
.unwrap();
entry1.get_data::<_, i32, i32>(2, |_| Ok(100)).unwrap();
entry1.get_data::<_, i32, i32>(1, |_| panic!()).unwrap();
entry1.get_data::<_, i32, i32>(2, |_| panic!()).unwrap();
entry1
.get_data(3, |_| -> Result<i32, ()> { Ok(100) })
.unwrap();
entry1
.get_data(1, |_| -> Result<i32, ()> { panic!() })
.unwrap();
entry1
.get_data(2, |_| -> Result<i32, ()> { panic!() })
.unwrap();
entry1
.get_data(3, |_| -> Result<i32, ()> { panic!() })
.unwrap();
entry1.get_data::<_, i32, i32>(3, |_| Ok(100)).unwrap();
entry1.get_data::<_, i32, i32>(1, |_| panic!()).unwrap();
entry1.get_data::<_, i32, i32>(2, |_| panic!()).unwrap();
entry1.get_data::<_, i32, i32>(3, |_| panic!()).unwrap();
entry1
.get_data(4, |_| -> Result<i32, ()> { Ok(100) })
.unwrap();
entry1
.get_data(1, |_| -> Result<i32, ()> { panic!() })
.unwrap();
entry1
.get_data(2, |_| -> Result<i32, ()> { panic!() })
.unwrap();
entry1
.get_data(3, |_| -> Result<i32, ()> { panic!() })
.unwrap();
entry1
.get_data(4, |_| -> Result<i32, ()> { panic!() })
.unwrap();
entry1.get_data::<_, i32, i32>(4, |_| Ok(100)).unwrap();
entry1.get_data::<_, i32, i32>(1, |_| panic!()).unwrap();
entry1.get_data::<_, i32, i32>(2, |_| panic!()).unwrap();
entry1.get_data::<_, i32, i32>(3, |_| panic!()).unwrap();
entry1.get_data::<_, i32, i32>(4, |_| panic!()).unwrap();
entry2
.get_data(1, |_| -> Result<i32, ()> { Ok(100) })
.unwrap();
entry1
.get_data(1, |_| -> Result<i32, ()> { panic!() })
.unwrap();
entry1
.get_data(2, |_| -> Result<i32, ()> { panic!() })
.unwrap();
entry1
.get_data(3, |_| -> Result<i32, ()> { panic!() })
.unwrap();
entry1
.get_data(4, |_| -> Result<i32, ()> { panic!() })
.unwrap();
entry2
.get_data(1, |_| -> Result<i32, ()> { panic!() })
.unwrap();
entry2.get_data::<_, i32, i32>(1, |_| Ok(100)).unwrap();
entry1.get_data::<_, i32, i32>(1, |_| panic!()).unwrap();
entry1.get_data::<_, i32, i32>(2, |_| panic!()).unwrap();
entry1.get_data::<_, i32, i32>(3, |_| panic!()).unwrap();
entry1.get_data::<_, i32, i32>(4, |_| panic!()).unwrap();
entry2.get_data::<_, i32, i32>(1, |_| panic!()).unwrap();
}