From 784a380e5f3a51b55345fc4057489a5d490221db Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 27 Jul 2021 07:33:27 -0700 Subject: [PATCH] Add comments about vmctx pointers in various datastructures. (#2925) This forward-ports the relevant parts of #1396. --- crates/runtime/src/export.rs | 3 ++- crates/runtime/src/vmcontext.rs | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/runtime/src/export.rs b/crates/runtime/src/export.rs index 6c6f0a310adf..f1934a812cd3 100644 --- a/crates/runtime/src/export.rs +++ b/crates/runtime/src/export.rs @@ -89,7 +89,8 @@ impl From for Export { pub struct ExportGlobal { /// The address of the global storage. pub definition: *mut VMGlobalDefinition, - /// Pointer to the containing `VMContext`. + /// Pointer to a `VMContext` which has a lifetime at least as long as the + /// global. This may not be the `VMContext` which defines the global. pub vmctx: *mut VMContext, /// The global declaration, used for compatibilty checking. pub global: Global, diff --git a/crates/runtime/src/vmcontext.rs b/crates/runtime/src/vmcontext.rs index af4ac12b9cb7..5229e3bce7e3 100644 --- a/crates/runtime/src/vmcontext.rs +++ b/crates/runtime/src/vmcontext.rs @@ -159,6 +159,10 @@ mod test_vmmemory_import { /// The fields compiled code needs to access to utilize a WebAssembly global /// variable imported from another instance. +/// +/// Note that unlike with functions, tables, and memories, `VMGlobalImport` +/// doesn't include a `vmctx` pointer. Globals are never resized, and don't +/// require a `vmctx` pointer to access. #[derive(Debug, Copy, Clone)] #[repr(C)] pub struct VMGlobalImport { @@ -744,8 +748,6 @@ mod test_vminterrupts { /// The struct here is empty, as the sizes of these fields are dynamic, and /// we can't describe them in Rust's type system. Sufficient memory is /// allocated at runtime. -/// -/// TODO: We could move the globals into the `vmctx` allocation too. #[derive(Debug)] #[repr(C, align(16))] // align 16 since globals are aligned to that and contained inside pub struct VMContext {