runtime: make out-of-memory failures fatal

Match the Go runtime by terminating instead of unwinding when an
allocator exhausts the heap. Recovering an OOM can leave allocator locks
held and cannot safely continue when the panic path itself needs memory.
This commit is contained in:
Jake Bailey
2026-07-24 10:00:19 -07:00
committed by Ron Evans
parent 7756941f39
commit 9105cce340
4 changed files with 16 additions and 4 deletions
+12
View File
@@ -91,6 +91,18 @@ func runtimePanic(msg string) {
runtimePanicAt(returnAddress(0), msg)
}
// runtimeFatal terminates for runtime failures that cannot safely be
// recovered, such as exhausting the heap.
func runtimeFatal(msg string) {
if panicStrategy() == tinygo.PanicStrategyTrap {
trap()
}
printstring("fatal error: ")
printstring(msg)
printnl()
abort()
}
func runtimePanicAt(addr unsafe.Pointer, msg string) {
if panicStrategy() == tinygo.PanicStrategyTrap {
trap()