pooling needs the store earlier

This commit is contained in:
Pat Hickey
2021-10-20 16:53:24 -07:00
parent 9d1b24632e
commit 67a6c27e22
2 changed files with 10 additions and 6 deletions

View File

@@ -92,12 +92,10 @@ impl StorePtr {
pub fn new(ptr: *mut dyn Store) -> Self { pub fn new(ptr: *mut dyn Store) -> Self {
Self(Some(ptr)) Self(Some(ptr))
} }
/* /// The raw contents of this struct
/// Update an empty StorePtr to point to a Store. pub fn as_raw(&self) -> Option<*mut dyn Store> {
pub fn set(&mut self, ptr: *mut dyn Store) { self.0.clone()
self.0 = Some(ptr)
} }
*/
/// Use the StorePtr as a mut ref to the Store. /// Use the StorePtr as a mut ref to the Store.
// XXX should this be an unsafe fn? is it always safe at a use site? // XXX should this be an unsafe fn? is it always safe at a use site?
pub(crate) fn get(&mut self) -> Option<&mut dyn Store> { pub(crate) fn get(&mut self) -> Option<&mut dyn Store> {
@@ -461,7 +459,7 @@ fn initialize_instance(
} }
unsafe fn initialize_vmcontext(instance: &mut Instance, req: InstanceAllocationRequest) { unsafe fn initialize_vmcontext(instance: &mut Instance, req: InstanceAllocationRequest) {
if let Some(store) = req.store.0 { if let Some(store) = req.store.as_raw() {
*instance.interrupts() = (*store).vminterrupts(); *instance.interrupts() = (*store).vminterrupts();
*instance.externref_activations_table() = (*store).externref_activations_table().0; *instance.externref_activations_table() = (*store).externref_activations_table().0;
instance.set_store(store); instance.set_store(store);

View File

@@ -384,6 +384,12 @@ impl InstancePool {
instance.host_state = std::mem::replace(&mut req.host_state, Box::new(())); instance.host_state = std::mem::replace(&mut req.host_state, Box::new(()));
instance.wasm_data = &*req.wasm_data; instance.wasm_data = &*req.wasm_data;
// set_instance_memories and _tables will need the store before we can completely
// initialize the vmcontext.
if let Some(store) = req.store.as_raw() {
instance.set_store(store);
}
Self::set_instance_memories( Self::set_instance_memories(
instance, instance,
self.memories.get(index), self.memories.get(index),