Files
tinygo/src/runtime/runtime_wasip2.go
T
Ayke van Laethem 9ca6f72583 wasm: refactor/modify stub signal handling
This commit changes signal handling in a few ways:

  * It stubs signals for all wasm targets (not just wasi) and baremetal,
    since none of those have traditional POSIX signals. And moves the
    code for that into a single file, instead of duplicating it.
  * It removes the stub for signal_ignored since the value `false` might
    be wrong in some cases and it doesn't usually seem to be called (it
    is not called in tsgo). Should be trivial to re-add if it is shown
    to be needed.
  * It adds a stub for `os/signal.signalWaitUntilIdle` which _is_ called
    by tsgo.
2025-05-21 20:04:05 +02:00

53 lines
958 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"
)
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())
}