mirror of
https://github.com/golang/go
synced 2024-11-23 16:10:05 -07:00
runtime: don't grow the stack on sigpanic if throwsplit
Currently, if a _SigPanic signal arrives in a throwsplit context, nothing is stopping the runtime from injecting a call to sigpanic that may attempt to grow the stack. This will fail and, in turn, mask the real problem. Fix this by checking for throwsplit in the signal handler itself before injecting the sigpanic call. Updates #21431, where this problem is likely masking the real problem. Change-Id: I64b61ff08e8c4d6f6c0fb01315d7d5e66bf1d3e2 Reviewed-on: https://go-review.googlesource.com/87595 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
9b49ac0366
commit
9483a0bc23
@ -45,6 +45,11 @@ func sighandler(_ureg *ureg, note *byte, gp *g) int {
|
||||
break
|
||||
}
|
||||
}
|
||||
if flags&_SigPanic != 0 && gp.throwsplit {
|
||||
// We can't safely sigpanic because it may grow the
|
||||
// stack. Abort in the signal handler instead.
|
||||
flags = (flags &^ _SigPanic) | _SigThrow
|
||||
}
|
||||
if flags&_SigGoExit != 0 {
|
||||
exits((*byte)(add(unsafe.Pointer(note), 9))) // Strip "go: exit " prefix.
|
||||
}
|
||||
|
@ -752,6 +752,9 @@ func dopanic_m(gp *g, pc, sp uintptr) {
|
||||
exit(2)
|
||||
}
|
||||
|
||||
// canpanic returns false if a signal should throw instead of
|
||||
// panicking.
|
||||
//
|
||||
//go:nosplit
|
||||
func canpanic(gp *g) bool {
|
||||
// Note that g is m->gsignal, different from gp.
|
||||
|
@ -38,6 +38,11 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
|
||||
if sig < uint32(len(sigtable)) {
|
||||
flags = sigtable[sig].flags
|
||||
}
|
||||
if flags&_SigPanic != 0 && gp.throwsplit {
|
||||
// We can't safely sigpanic because it may grow the
|
||||
// stack. Abort in the signal handler instead.
|
||||
flags = (flags &^ _SigPanic) | _SigThrow
|
||||
}
|
||||
if c.sigcode() != _SI_USER && flags&_SigPanic != 0 {
|
||||
// The signal is going to cause a panic.
|
||||
// Arrange the stack so that it looks like the point
|
||||
|
@ -360,6 +360,12 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
|
||||
// the signal handler. The effect is that the program will act as
|
||||
// though the function that got the signal simply called sigpanic
|
||||
// instead.
|
||||
//
|
||||
// This must NOT be nosplit because the linker doesn't know where
|
||||
// sigpanic calls can be injected.
|
||||
//
|
||||
// The signal handler must not inject a call to sigpanic if
|
||||
// getg().throwsplit, since sigpanic may need to grow the stack.
|
||||
func sigpanic() {
|
||||
g := getg()
|
||||
if !canpanic(g) {
|
||||
|
@ -71,6 +71,12 @@ func exceptionhandler(info *exceptionrecord, r *context, gp *g) int32 {
|
||||
return _EXCEPTION_CONTINUE_SEARCH
|
||||
}
|
||||
|
||||
if gp.throwsplit {
|
||||
// We can't safely sigpanic because it may grow the
|
||||
// stack. Let it fall through.
|
||||
return _EXCEPTION_CONTINUE_SEARCH
|
||||
}
|
||||
|
||||
// Make it look like a call to the signal func.
|
||||
// Have to pass arguments out of band since
|
||||
// augmenting the stack frame would break
|
||||
|
Loading…
Reference in New Issue
Block a user