Browse Source

wasm: execute an 'unreachable' trap inst on panic

This already happened when directly calling panic() but not with some
runtime panics like accessing a slice out of bounds.
pull/62/head
Ayke van Laethem 6 years ago
parent
commit
a459570d94
No known key found for this signature in database GPG Key ID: E97FF5335DFDFDED
  1. 5
      src/runtime/panic.go
  2. 3
      src/runtime/runtime_wasm.go

5
src/runtime/panic.go

@ -1,5 +1,10 @@
package runtime package runtime
// trap is a compiler hint that this function cannot be executed. It is
// translated into either a trap instruction or a call to abort().
//go:linkname trap llvm.trap
func trap()
// Builtin function panic(msg), used as a compiler intrinsic. // Builtin function panic(msg), used as a compiler intrinsic.
func _panic(message interface{}) { func _panic(message interface{}) {
printstring("panic: ") printstring("panic: ")

3
src/runtime/runtime_wasm.go

@ -49,6 +49,7 @@ func align(ptr uintptr) uintptr {
return (ptr + 3) &^ 3 return (ptr + 3) &^ 3
} }
// Abort executes the wasm 'unreachable' instruction.
func abort() { func abort() {
// TODO trap()
} }

Loading…
Cancel
Save