|
8 | 8 |
|
9 | 9 | use crate::prelude::*;
|
10 | 10 | use crate::runtime::vm::{
|
11 |
| - SendSyncPtr, VMArrayCallFunction, VMFuncRef, VMGlobalDefinition, VMMemoryDefinition, |
12 |
| - VMOpaqueContext, VMStore, VMStoreRawPtr, VMTableDefinition, VMWasmCallFunction, ValRaw, VmPtr, |
13 |
| - VmSafe, |
| 11 | + SendSyncPtr, VMArrayCallFunction, VMContext, VMFuncRef, VMGlobalDefinition, VMMemoryDefinition, |
| 12 | + VMOpaqueContext, VMStore, VMStoreRawPtr, VMTableDefinition, VMTableImport, VMWasmCallFunction, |
| 13 | + ValRaw, VmPtr, VmSafe, |
14 | 14 | };
|
15 | 15 | use alloc::alloc::Layout;
|
16 | 16 | use alloc::sync::Arc;
|
@@ -290,16 +290,20 @@ impl ComponentInstance {
|
290 | 290 | }
|
291 | 291 | }
|
292 | 292 |
|
293 |
| - /// Returns the runtime table definition corresponding to the index of the |
294 |
| - /// table provided. |
| 293 | + /// Returns the runtime table definition and associated instance `VMContext` |
| 294 | + /// corresponding to the index of the table provided. |
295 | 295 | ///
|
296 | 296 | /// This can only be called after `idx` has been initialized at runtime
|
297 | 297 | /// during the instantiation process of a component.
|
298 |
| - pub fn runtime_table(&self, idx: RuntimeTableIndex) -> *mut VMTableDefinition { |
| 298 | + /// |
| 299 | + /// Note that we use a `VMTableImport` here because of its structure, not |
| 300 | + /// because these tables are actually imports. |
| 301 | + pub fn runtime_table(&self, idx: RuntimeTableIndex) -> VMTableImport { |
299 | 302 | unsafe {
|
300 |
| - let ret = *self.vmctx_plus_offset::<VmPtr<_>>(self.offsets.runtime_table(idx)); |
301 |
| - debug_assert!(ret.as_ptr() as usize != INVALID_PTR); |
302 |
| - ret.as_ptr() |
| 303 | + let ret = *self.vmctx_plus_offset::<VMTableImport>(self.offsets.runtime_table(idx)); |
| 304 | + debug_assert!(ret.from.as_ptr() as usize != INVALID_PTR); |
| 305 | + debug_assert!(ret.vmctx.as_ptr() as usize != INVALID_PTR); |
| 306 | + ret |
303 | 307 | }
|
304 | 308 | }
|
305 | 309 |
|
@@ -418,20 +422,31 @@ impl ComponentInstance {
|
418 | 422 | }
|
419 | 423 | }
|
420 | 424 |
|
421 |
| - /// Stores the runtime memory pointer at the index specified. |
| 425 | + /// Stores the runtime table pointer at the index specified. |
422 | 426 | ///
|
423 | 427 | /// This is intended to be called during the instantiation process of a
|
424 |
| - /// component once a memory is available, which may not be until part-way |
| 428 | + /// component once a table is available, which may not be until part-way |
425 | 429 | /// through component instantiation.
|
426 | 430 | ///
|
427 | 431 | /// Note that it should be a property of the component model that the `ptr`
|
428 | 432 | /// here is never needed prior to it being configured here in the instance.
|
429 |
| - pub fn set_runtime_table(&mut self, idx: RuntimeTableIndex, ptr: NonNull<VMTableDefinition>) { |
| 433 | + pub fn set_runtime_table( |
| 434 | + &mut self, |
| 435 | + idx: RuntimeTableIndex, |
| 436 | + ptr: NonNull<VMTableDefinition>, |
| 437 | + vmctx: NonNull<VMContext>, |
| 438 | + ) { |
| 439 | + // Note that we use a `VMTableImport` here because of its structure, not |
| 440 | + // because these tables are actually imports. |
430 | 441 | unsafe {
|
431 |
| - let storage = self |
432 |
| - .vmctx_plus_offset_mut::<VmPtr<VMTableDefinition>>(self.offsets.runtime_table(idx)); |
433 |
| - debug_assert!((*storage).as_ptr() as usize == INVALID_PTR); |
434 |
| - *storage = ptr.into(); |
| 442 | + let storage = |
| 443 | + self.vmctx_plus_offset_mut::<VMTableImport>(self.offsets.runtime_table(idx)); |
| 444 | + debug_assert!((*storage).vmctx.as_ptr() as usize == INVALID_PTR); |
| 445 | + debug_assert!((*storage).from.as_ptr() as usize == INVALID_PTR); |
| 446 | + *storage = VMTableImport { |
| 447 | + vmctx: vmctx.into(), |
| 448 | + from: ptr.into(), |
| 449 | + }; |
435 | 450 | }
|
436 | 451 | }
|
437 | 452 |
|
@@ -554,6 +569,11 @@ impl ComponentInstance {
|
554 | 569 | let offset = self.offsets.resource_destructor(i);
|
555 | 570 | *self.vmctx_plus_offset_mut(offset) = INVALID_PTR;
|
556 | 571 | }
|
| 572 | + for i in 0..self.offsets.num_runtime_tables { |
| 573 | + let i = RuntimeTableIndex::from_u32(i); |
| 574 | + let offset = self.offsets.runtime_table(i); |
| 575 | + *self.vmctx_plus_offset_mut(offset) = INVALID_PTR; |
| 576 | + } |
557 | 577 | }
|
558 | 578 | }
|
559 | 579 |
|
@@ -833,8 +853,13 @@ impl OwnedComponentInstance {
|
833 | 853 | }
|
834 | 854 |
|
835 | 855 | /// See `ComponentInstance::set_runtime_table`
|
836 |
| - pub fn set_runtime_table(&mut self, idx: RuntimeTableIndex, ptr: NonNull<VMTableDefinition>) { |
837 |
| - unsafe { self.instance_mut().set_runtime_table(idx, ptr) } |
| 856 | + pub fn set_runtime_table( |
| 857 | + &mut self, |
| 858 | + idx: RuntimeTableIndex, |
| 859 | + ptr: NonNull<VMTableDefinition>, |
| 860 | + vmctx: NonNull<VMContext>, |
| 861 | + ) { |
| 862 | + unsafe { self.instance_mut().set_runtime_table(idx, ptr, vmctx) } |
838 | 863 | }
|
839 | 864 |
|
840 | 865 | /// See `ComponentInstance::set_lowering`
|
|
0 commit comments