aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/runtime/runtime_wasm_wasip2.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/runtime_wasm_wasip2.go')
-rw-r--r--src/runtime/runtime_wasm_wasip2.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/runtime/runtime_wasm_wasip2.go b/src/runtime/runtime_wasm_wasip2.go
new file mode 100644
index 000000000..ca189aad6
--- /dev/null
+++ b/src/runtime/runtime_wasm_wasip2.go
@@ -0,0 +1,61 @@
+//go:build wasip2
+
+package runtime
+
+import (
+ "unsafe"
+
+ "internal/wasi/cli/v0.2.0/environment"
+ monotonicclock "internal/wasi/clocks/v0.2.0/monotonic-clock"
+)
+
+type timeUnit int64
+
+//export wasi:cli/[email protected]#run
+func __wasi_cli_run_run() uint32 {
+ _start()
+ return 0
+}
+
+//export _start
+func _start() {
+ // 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()
+}
+
+func init() {
+}
+
+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())
+}