Files
tinygo/src/runtime/runtime_wasip2.go
T
Randy Reddig 453a1d35c3 compiler, runtime: enable go:wasmexport for wasip2 (#4499)
* compiler: prefer go:wasmexport over go:export

* runtime, targets/wasip2: enable -buildmode=c-shared for wasip2

* runtime: rename import from wasi_run to wasiclirun (PR feedback)
2024-10-04 17:36:47 -07:00

58 lines
1002 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())
}
func beforeExit() {
}