2015-07-10 10:32:03 -06:00
|
|
|
// run
|
|
|
|
|
2016-04-10 15:32:26 -06:00
|
|
|
// Copyright 2015 The Go Authors. All rights reserved.
|
2015-07-10 10:32:03 -06:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// windows doesn't work, because Windows exception handling
|
|
|
|
// delivers signals based on the current PC, and that current PC
|
|
|
|
// doesn't go into the Go runtime.
|
|
|
|
// +build !windows
|
|
|
|
|
2018-03-04 04:15:37 -07:00
|
|
|
// wasm does not work, because the linear memory is not executable.
|
|
|
|
// +build !wasm
|
|
|
|
|
2020-12-15 21:24:33 -07:00
|
|
|
// This test doesn't work on gccgo/GoLLVM, because they will not find
|
|
|
|
// any unwind information for the artificial function, and will not be
|
|
|
|
// able to unwind past that point.
|
|
|
|
// +build !gccgo
|
|
|
|
|
2015-07-10 10:32:03 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-09-27 12:39:01 -06:00
|
|
|
"encoding/binary"
|
2015-07-10 10:32:03 -06:00
|
|
|
"runtime"
|
|
|
|
"runtime/debug"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
debug.SetPanicOnFault(true)
|
|
|
|
defer func() {
|
|
|
|
if err := recover(); err == nil {
|
|
|
|
panic("not panicking")
|
|
|
|
}
|
|
|
|
pc, _, _, _ := runtime.Caller(10)
|
|
|
|
f := runtime.FuncForPC(pc)
|
|
|
|
if f == nil || f.Name() != "main.f" {
|
|
|
|
if f == nil {
|
|
|
|
println("no func for ", unsafe.Pointer(pc))
|
|
|
|
} else {
|
|
|
|
println("found func:", f.Name())
|
|
|
|
}
|
|
|
|
panic("cannot find main.f on stack")
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
f(20)
|
|
|
|
}
|
|
|
|
|
|
|
|
func f(n int) {
|
|
|
|
if n > 0 {
|
2015-07-15 20:08:27 -06:00
|
|
|
f(n - 1)
|
2015-07-10 10:32:03 -06:00
|
|
|
}
|
|
|
|
var f struct {
|
|
|
|
x uintptr
|
|
|
|
}
|
2015-09-27 12:39:01 -06:00
|
|
|
|
test: trigger SIGSEGV instead of SIGTRAP in issue11656.go
In issue11656.go, it tests that if the runtime can get a
reasonable traceback when it faults at a non-function PC. It does
it by jumping to an address that contains an illegal or trap
instruction. When it traps, the SIGTRAP crashes the runtime.
This CL changes it to use an instruction that triggers SIGSEGV.
This is due to two reasons:
- currently, the handling of bad PC is done by preparePanic,
which is only used for a panicking signal (SIGSEGV, SIGBUS,
SIGFPE), not a fatal signal (e.g. SIGTRAP).
- the test uses defer+recover to get a traceback, which only
works for panicking signals, not fatal signals.
Ideally, we should handle all kinds of faults (SIGSEGV, SIGBUS,
SIGILL, SIGTRAP, etc.) with a nice traceback. I'll leave this
for the future.
This CL also adds RISCV64 support.
Fixes #43283.
Change-Id: I5e0fbf8530cc89d16e05c3257d282bc1d4d03405
Reviewed-on: https://go-review.googlesource.com/c/go/+/279423
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-21 16:41:16 -07:00
|
|
|
// We want to force a seg fault, to get a crash at a PC value != 0.
|
2015-09-27 12:39:01 -06:00
|
|
|
// Not all systems make the data section non-executable.
|
|
|
|
ill := make([]byte, 64)
|
|
|
|
switch runtime.GOARCH {
|
|
|
|
case "386", "amd64":
|
test: trigger SIGSEGV instead of SIGTRAP in issue11656.go
In issue11656.go, it tests that if the runtime can get a
reasonable traceback when it faults at a non-function PC. It does
it by jumping to an address that contains an illegal or trap
instruction. When it traps, the SIGTRAP crashes the runtime.
This CL changes it to use an instruction that triggers SIGSEGV.
This is due to two reasons:
- currently, the handling of bad PC is done by preparePanic,
which is only used for a panicking signal (SIGSEGV, SIGBUS,
SIGFPE), not a fatal signal (e.g. SIGTRAP).
- the test uses defer+recover to get a traceback, which only
works for panicking signals, not fatal signals.
Ideally, we should handle all kinds of faults (SIGSEGV, SIGBUS,
SIGILL, SIGTRAP, etc.) with a nice traceback. I'll leave this
for the future.
This CL also adds RISCV64 support.
Fixes #43283.
Change-Id: I5e0fbf8530cc89d16e05c3257d282bc1d4d03405
Reviewed-on: https://go-review.googlesource.com/c/go/+/279423
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-21 16:41:16 -07:00
|
|
|
ill = append(ill, 0x89, 0x04, 0x25, 0x00, 0x00, 0x00, 0x00) // MOVL AX, 0
|
2015-09-27 12:39:01 -06:00
|
|
|
case "arm":
|
test: trigger SIGSEGV instead of SIGTRAP in issue11656.go
In issue11656.go, it tests that if the runtime can get a
reasonable traceback when it faults at a non-function PC. It does
it by jumping to an address that contains an illegal or trap
instruction. When it traps, the SIGTRAP crashes the runtime.
This CL changes it to use an instruction that triggers SIGSEGV.
This is due to two reasons:
- currently, the handling of bad PC is done by preparePanic,
which is only used for a panicking signal (SIGSEGV, SIGBUS,
SIGFPE), not a fatal signal (e.g. SIGTRAP).
- the test uses defer+recover to get a traceback, which only
works for panicking signals, not fatal signals.
Ideally, we should handle all kinds of faults (SIGSEGV, SIGBUS,
SIGILL, SIGTRAP, etc.) with a nice traceback. I'll leave this
for the future.
This CL also adds RISCV64 support.
Fixes #43283.
Change-Id: I5e0fbf8530cc89d16e05c3257d282bc1d4d03405
Reviewed-on: https://go-review.googlesource.com/c/go/+/279423
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-21 16:41:16 -07:00
|
|
|
binary.LittleEndian.PutUint32(ill, 0xe3a00000) // MOVW $0, R0
|
|
|
|
binary.LittleEndian.PutUint32(ill, 0xe5800000) // MOVW R0, (R0)
|
2015-09-27 12:39:01 -06:00
|
|
|
case "arm64":
|
test: trigger SIGSEGV instead of SIGTRAP in issue11656.go
In issue11656.go, it tests that if the runtime can get a
reasonable traceback when it faults at a non-function PC. It does
it by jumping to an address that contains an illegal or trap
instruction. When it traps, the SIGTRAP crashes the runtime.
This CL changes it to use an instruction that triggers SIGSEGV.
This is due to two reasons:
- currently, the handling of bad PC is done by preparePanic,
which is only used for a panicking signal (SIGSEGV, SIGBUS,
SIGFPE), not a fatal signal (e.g. SIGTRAP).
- the test uses defer+recover to get a traceback, which only
works for panicking signals, not fatal signals.
Ideally, we should handle all kinds of faults (SIGSEGV, SIGBUS,
SIGILL, SIGTRAP, etc.) with a nice traceback. I'll leave this
for the future.
This CL also adds RISCV64 support.
Fixes #43283.
Change-Id: I5e0fbf8530cc89d16e05c3257d282bc1d4d03405
Reviewed-on: https://go-review.googlesource.com/c/go/+/279423
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-21 16:41:16 -07:00
|
|
|
binary.LittleEndian.PutUint32(ill, 0xf90003ff) // MOVD ZR, (ZR)
|
2015-09-27 12:39:01 -06:00
|
|
|
case "ppc64":
|
test: trigger SIGSEGV instead of SIGTRAP in issue11656.go
In issue11656.go, it tests that if the runtime can get a
reasonable traceback when it faults at a non-function PC. It does
it by jumping to an address that contains an illegal or trap
instruction. When it traps, the SIGTRAP crashes the runtime.
This CL changes it to use an instruction that triggers SIGSEGV.
This is due to two reasons:
- currently, the handling of bad PC is done by preparePanic,
which is only used for a panicking signal (SIGSEGV, SIGBUS,
SIGFPE), not a fatal signal (e.g. SIGTRAP).
- the test uses defer+recover to get a traceback, which only
works for panicking signals, not fatal signals.
Ideally, we should handle all kinds of faults (SIGSEGV, SIGBUS,
SIGILL, SIGTRAP, etc.) with a nice traceback. I'll leave this
for the future.
This CL also adds RISCV64 support.
Fixes #43283.
Change-Id: I5e0fbf8530cc89d16e05c3257d282bc1d4d03405
Reviewed-on: https://go-review.googlesource.com/c/go/+/279423
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-21 16:41:16 -07:00
|
|
|
binary.BigEndian.PutUint32(ill, 0xf8000000) // MOVD R0, (R0)
|
2015-09-27 12:39:01 -06:00
|
|
|
case "ppc64le":
|
test: trigger SIGSEGV instead of SIGTRAP in issue11656.go
In issue11656.go, it tests that if the runtime can get a
reasonable traceback when it faults at a non-function PC. It does
it by jumping to an address that contains an illegal or trap
instruction. When it traps, the SIGTRAP crashes the runtime.
This CL changes it to use an instruction that triggers SIGSEGV.
This is due to two reasons:
- currently, the handling of bad PC is done by preparePanic,
which is only used for a panicking signal (SIGSEGV, SIGBUS,
SIGFPE), not a fatal signal (e.g. SIGTRAP).
- the test uses defer+recover to get a traceback, which only
works for panicking signals, not fatal signals.
Ideally, we should handle all kinds of faults (SIGSEGV, SIGBUS,
SIGILL, SIGTRAP, etc.) with a nice traceback. I'll leave this
for the future.
This CL also adds RISCV64 support.
Fixes #43283.
Change-Id: I5e0fbf8530cc89d16e05c3257d282bc1d4d03405
Reviewed-on: https://go-review.googlesource.com/c/go/+/279423
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-21 16:41:16 -07:00
|
|
|
binary.LittleEndian.PutUint32(ill, 0xf8000000) // MOVD R0, (R0)
|
2016-12-15 09:46:44 -07:00
|
|
|
case "mips", "mips64":
|
test: trigger SIGSEGV instead of SIGTRAP in issue11656.go
In issue11656.go, it tests that if the runtime can get a
reasonable traceback when it faults at a non-function PC. It does
it by jumping to an address that contains an illegal or trap
instruction. When it traps, the SIGTRAP crashes the runtime.
This CL changes it to use an instruction that triggers SIGSEGV.
This is due to two reasons:
- currently, the handling of bad PC is done by preparePanic,
which is only used for a panicking signal (SIGSEGV, SIGBUS,
SIGFPE), not a fatal signal (e.g. SIGTRAP).
- the test uses defer+recover to get a traceback, which only
works for panicking signals, not fatal signals.
Ideally, we should handle all kinds of faults (SIGSEGV, SIGBUS,
SIGILL, SIGTRAP, etc.) with a nice traceback. I'll leave this
for the future.
This CL also adds RISCV64 support.
Fixes #43283.
Change-Id: I5e0fbf8530cc89d16e05c3257d282bc1d4d03405
Reviewed-on: https://go-review.googlesource.com/c/go/+/279423
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-21 16:41:16 -07:00
|
|
|
binary.BigEndian.PutUint32(ill, 0xfc000000) // MOVV R0, (R0)
|
2016-12-15 09:46:44 -07:00
|
|
|
case "mipsle", "mips64le":
|
test: trigger SIGSEGV instead of SIGTRAP in issue11656.go
In issue11656.go, it tests that if the runtime can get a
reasonable traceback when it faults at a non-function PC. It does
it by jumping to an address that contains an illegal or trap
instruction. When it traps, the SIGTRAP crashes the runtime.
This CL changes it to use an instruction that triggers SIGSEGV.
This is due to two reasons:
- currently, the handling of bad PC is done by preparePanic,
which is only used for a panicking signal (SIGSEGV, SIGBUS,
SIGFPE), not a fatal signal (e.g. SIGTRAP).
- the test uses defer+recover to get a traceback, which only
works for panicking signals, not fatal signals.
Ideally, we should handle all kinds of faults (SIGSEGV, SIGBUS,
SIGILL, SIGTRAP, etc.) with a nice traceback. I'll leave this
for the future.
This CL also adds RISCV64 support.
Fixes #43283.
Change-Id: I5e0fbf8530cc89d16e05c3257d282bc1d4d03405
Reviewed-on: https://go-review.googlesource.com/c/go/+/279423
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-21 16:41:16 -07:00
|
|
|
binary.LittleEndian.PutUint32(ill, 0xfc000000) // MOVV R0, (R0)
|
2016-03-20 17:25:58 -06:00
|
|
|
case "s390x":
|
test: trigger SIGSEGV instead of SIGTRAP in issue11656.go
In issue11656.go, it tests that if the runtime can get a
reasonable traceback when it faults at a non-function PC. It does
it by jumping to an address that contains an illegal or trap
instruction. When it traps, the SIGTRAP crashes the runtime.
This CL changes it to use an instruction that triggers SIGSEGV.
This is due to two reasons:
- currently, the handling of bad PC is done by preparePanic,
which is only used for a panicking signal (SIGSEGV, SIGBUS,
SIGFPE), not a fatal signal (e.g. SIGTRAP).
- the test uses defer+recover to get a traceback, which only
works for panicking signals, not fatal signals.
Ideally, we should handle all kinds of faults (SIGSEGV, SIGBUS,
SIGILL, SIGTRAP, etc.) with a nice traceback. I'll leave this
for the future.
This CL also adds RISCV64 support.
Fixes #43283.
Change-Id: I5e0fbf8530cc89d16e05c3257d282bc1d4d03405
Reviewed-on: https://go-review.googlesource.com/c/go/+/279423
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-21 16:41:16 -07:00
|
|
|
ill = append(ill, 0xa7, 0x09, 0x00, 0x00) // MOVD $0, R0
|
|
|
|
ill = append(ill, 0xe3, 0x00, 0x00, 0x00, 0x00, 0x24) // MOVD R0, (R0)
|
|
|
|
case "riscv64":
|
|
|
|
binary.LittleEndian.PutUint32(ill, 0x00003023) // MOV X0, (X0)
|
2015-09-27 12:39:01 -06:00
|
|
|
default:
|
|
|
|
// Just leave it as 0 and hope for the best.
|
|
|
|
}
|
|
|
|
|
|
|
|
f.x = uintptr(unsafe.Pointer(&ill[0]))
|
2020-12-15 21:24:33 -07:00
|
|
|
p := &f
|
|
|
|
fn := *(*func())(unsafe.Pointer(&p))
|
2015-07-10 10:32:03 -06:00
|
|
|
fn()
|
|
|
|
}
|