Skip to content

Commit e3e59dd

Browse files
committed
fix(wasip2): export _initialize
Signed-off-by: Roman Volosatovs <[email protected]>
1 parent 9d14489 commit e3e59dd

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/runtime/runtime_wasm_wasip2.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package runtime
44

55
import (
6+
"sync"
67
"unsafe"
78

89
"internal/wasi/cli/v0.2.0/environment"
@@ -11,12 +12,31 @@ import (
1112

1213
type timeUnit int64
1314

14-
//export wasi:cli/[email protected]#run
15-
func __wasi_cli_run_run() uint32 {
15+
var initialize = sync.OnceFunc(func() {
1616
// These need to be initialized early so that the heap can be initialized.
1717
heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
1818
heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize)
19-
run()
19+
initHeap()
20+
initAll()
21+
})
22+
23+
//export _initialize
24+
func _initialize() {
25+
initialize()
26+
}
27+
28+
//export wasi:cli/[email protected]#run
29+
func __wasi_cli_run_run() uint32 {
30+
initialize()
31+
if hasScheduler {
32+
go func() {
33+
callMain()
34+
schedulerDone = true
35+
}()
36+
scheduler()
37+
} else {
38+
callMain()
39+
}
2040
return 0
2141
}
2242

0 commit comments

Comments
 (0)