Skip to content

Commit 0d11be7

Browse files
committed
fix(wasip2): export _initialize
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
1 parent 9d14489 commit 0d11be7

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/runtime/runtime_wasm_wasip2.go

Lines changed: 26 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,34 @@ import (
1112

1213
type timeUnit int64
1314

14-
//export wasi:cli/run@0.2.0#run
15-
func __wasi_cli_run_run() uint32 {
15+
var callInitAll = sync.OnceFunc(initAll)
16+
17+
var initialize = sync.OnceFunc(func() {
1618
// These need to be initialized early so that the heap can be initialized.
1719
heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
1820
heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize)
19-
run()
21+
initHeap()
22+
})
23+
24+
//export _initialize
25+
func _initialize() {
26+
initialize()
27+
callInitAll()
28+
}
29+
30+
//export wasi:cli/run@0.2.0#run
31+
func __wasi_cli_run_run() uint32 {
32+
initialize()
33+
if hasScheduler {
34+
go func() {
35+
callInitAll()
36+
callMain()
37+
schedulerDone = true
38+
}()
39+
scheduler()
40+
} else {
41+
callMain()
42+
}
2043
return 0
2144
}
2245

0 commit comments

Comments
 (0)