From 0d11be7db643c7856875a9be6c8818294ddc12bd Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Wed, 2 Oct 2024 18:02:24 +0200 Subject: [PATCH] fix(wasip2): export `_initialize` Signed-off-by: Roman Volosatovs --- src/runtime/runtime_wasm_wasip2.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/runtime/runtime_wasm_wasip2.go b/src/runtime/runtime_wasm_wasip2.go index 57e6623d33..b9cc340d63 100644 --- a/src/runtime/runtime_wasm_wasip2.go +++ b/src/runtime/runtime_wasm_wasip2.go @@ -3,6 +3,7 @@ package runtime import ( + "sync" "unsafe" "internal/wasi/cli/v0.2.0/environment" @@ -11,12 +12,34 @@ import ( type timeUnit int64 -//export wasi:cli/run@0.2.0#run -func __wasi_cli_run_run() uint32 { +var callInitAll = sync.OnceFunc(initAll) + +var initialize = sync.OnceFunc(func() { // These need to be initialized early so that the heap can be initialized. heapStart = uintptr(unsafe.Pointer(&heapStartSymbol)) heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize) - run() + initHeap() +}) + +//export _initialize +func _initialize() { + initialize() + callInitAll() +} + +//export wasi:cli/run@0.2.0#run +func __wasi_cli_run_run() uint32 { + initialize() + if hasScheduler { + go func() { + callInitAll() + callMain() + schedulerDone = true + }() + scheduler() + } else { + callMain() + } return 0 }