Files
tinygo/src/runtime/runtime_wasip2.go
Ayke van Laethem ceb7891986 wasm: correctly return from run() in wasm_exec.js
Instead of hanging forever, it should return the exit code from os.Exit.
2024-11-08 11:55:38 +01:00

55 lines
979 B
Go

//go:build wasip2
package runtime
import (
"unsafe"
"internal/wasi/cli/v0.2.0/environment"
wasiclirun "internal/wasi/cli/v0.2.0/run"
monotonicclock "internal/wasi/clocks/v0.2.0/monotonic-clock"
"internal/cm"
)
type timeUnit int64
func init() {
wasiclirun.Exports.Run = func() cm.BoolResult {
callMain()
return false
}
}
var args []string
//go:linkname os_runtime_args os.runtime_args
func os_runtime_args() []string {
if args == nil {
args = environment.GetArguments().Slice()
}
return args
}
//export cabi_realloc
func cabi_realloc(ptr, oldsize, align, newsize unsafe.Pointer) unsafe.Pointer {
return realloc(ptr, uintptr(newsize))
}
func ticksToNanoseconds(ticks timeUnit) int64 {
return int64(ticks)
}
func nanosecondsToTicks(ns int64) timeUnit {
return timeUnit(ns)
}
func sleepTicks(d timeUnit) {
p := monotonicclock.SubscribeDuration(monotonicclock.Duration(d))
p.Block()
}
func ticks() timeUnit {
return timeUnit(monotonicclock.Now())
}