diff --git a/internal/engine/compiler/engine.go b/internal/engine/compiler/engine.go index 078d46f7..ac9b7fea 100644 --- a/internal/engine/compiler/engine.go +++ b/internal/engine/compiler/engine.go @@ -348,13 +348,13 @@ const ( functionSize = 56 // Offsets for wasm.ModuleInstance. - moduleInstanceGlobalsOffset = 24 - moduleInstanceMemoryOffset = 48 - moduleInstanceTablesOffset = 56 - moduleInstanceEngineOffset = 80 - moduleInstanceTypeIDsOffset = 96 - moduleInstanceDataInstancesOffset = 120 - moduleInstanceElementInstancesOffset = 144 + moduleInstanceGlobalsOffset = 32 + moduleInstanceMemoryOffset = 56 + moduleInstanceTablesOffset = 64 + moduleInstanceEngineOffset = 88 + moduleInstanceTypeIDsOffset = 104 + moduleInstanceDataInstancesOffset = 128 + moduleInstanceElementInstancesOffset = 152 // Offsets for wasm.TableInstance. tableInstanceTableOffset = 0 diff --git a/internal/wasm/store.go b/internal/wasm/store.go index d768c7e3..0b1cfb00 100644 --- a/internal/wasm/store.go +++ b/internal/wasm/store.go @@ -58,6 +58,17 @@ type ( // // This implements api.Module. ModuleInstance struct { + // Closed is used both to guard moduleEngine.CloseWithExitCode and to store the exit code. + // + // The update value is closedType + exitCode << 32. This ensures an exit code of zero isn't mistaken for never closed. + // + // Note: Exclusively reading and updating this with atomics guarantees cross-goroutine observations. + // See /RATIONALE.md + // + // TODO: Retype this to atomic.Unit64 when Go 1.18 is no longer supported. Until then, keep Closed at the top of + // this struct. See PR #1299 for an implementation and discussion. + Closed uint64 + ModuleName string Exports map[string]*Export Globals []*GlobalInstance @@ -94,14 +105,6 @@ type ( // security implications. Sys *internalsys.Context - // closed is the pointer used both to guard moduleEngine.CloseWithExitCode and to store the exit code. - // - // The update value is closedType + exitCode << 32. This ensures an exit code of zero isn't mistaken for never closed. - // - // Note: Exclusively reading and updating this with atomics guarantees cross-goroutine observations. - // See /RATIONALE.md - Closed uint64 - // CodeCloser is non-nil when the code should be closed after this module. CodeCloser api.Closer