From 184a6a0d1ec03329b890a06ecb2156cb7b21e95c Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Sun, 11 Feb 2024 17:42:25 -0800 Subject: [PATCH] wazevo: fixes newAlignedOpaque not to use unsafe (#2043) Signed-off-by: Takeshi Yoneda --- internal/engine/wazevo/module_engine.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/engine/wazevo/module_engine.go b/internal/engine/wazevo/module_engine.go index f95e3e684e..b72ac2b162 100644 --- a/internal/engine/wazevo/module_engine.go +++ b/internal/engine/wazevo/module_engine.go @@ -79,10 +79,11 @@ func newAlignedOpaque(size int) moduleContextOpaque { if size%16 != 0 { panic("size must be a multiple of 16") } - type _16 [16]byte - buf := make([]_16, size/16) - slice := unsafe.Slice(&buf[0][0], size) - return *(*moduleContextOpaque)(&slice) + buf := make([]byte, size+16) + // Align the buffer to 16 bytes. + rem := uintptr(unsafe.Pointer(&buf[0])) % 16 + buf = buf[16-rem:] + return buf } func putLocalMemory(opaque []byte, offset wazevoapi.Offset, mem *wasm.MemoryInstance) {