aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/signal_unix.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2022-08-04 10:12:28 -0700
committerMatthew Dempsky <mdempsky@google.com>2022-08-04 10:12:28 -0700
commitd558507db42d600e5ad82748bda0cb91df57b97d (patch)
tree169457500d42144774eb68c5ab2ef70ad67aa673 /src/runtime/signal_unix.go
parentc9f2150cfb3c1db87f6434f727c25403d985a6e4 (diff)
parent85d87b9c7507628144db51bd1e7e80cc3afed128 (diff)
downloadgo-d558507db42d600e5ad82748bda0cb91df57b97d.tar.gz
go-d558507db42d600e5ad82748bda0cb91df57b97d.zip
[dev.unified] all: merge master (85d87b9) into dev.unifieddev.unified
Merge List: + 2022-08-04 85d87b9c75 all: update vendored golang.org/x dependencies for Go 1.20 development + 2022-08-04 fb1bfd4d37 all: remove pre-Go 1.17 workarounds + 2022-08-04 44ff9bff0c runtime: clean up panic and deadlock lock ranks + 2022-08-04 f42dc0de74 runtime: make the lock rank DAG make more sense + 2022-08-04 d29a0282e9 runtime: add mayAcquire annotation for finlock + 2022-08-04 c5be4ed7df runtime: add missing trace lock edges + 2022-08-04 2b8a9a484f runtime: generate the lock ranking from a DAG description + 2022-08-04 ddfd639408 runtime: delete unused lock ranks + 2022-08-04 426ea5702b internal/dag: add a Graph type and make node order deterministic + 2022-08-04 d37cc9a8cd go/build, internal/dag: lift DAG parser into an internal package + 2022-08-04 ab0a94c6d3 cmd/dist: require Go 1.17 for building Go + 2022-08-04 1e3c19f3fe runtime: support riscv64 SV57 mode + 2022-08-03 f28fa952b5 make.bat, make.rc: show bootstrap toolchain version + 2022-08-03 87384801dc cmd/asm: update package doc to describe "-p" option + 2022-08-03 c6a2dada0d net: disable TestIPv6WriteMsgUDPAddrPortTargetAddrIPVersion [sic] on DragonflyBSD + 2022-08-02 29b9a328d2 runtime: trivial replacements of g in remaining files + 2022-08-02 c647264619 runtime: trivial replacements of g in signal_unix.go + 2022-08-02 399f50c9d7 runtime: tricky replacements of g in traceback.go + 2022-08-02 4509e951ec runtime: tricky replacements of g in proc.go + 2022-08-02 4400238ec8 runtime: trivial replacements of _g_ in remaining files + 2022-08-02 5999a28de8 runtime: trivial replacements of _g_ in os files + 2022-08-02 0e18cf6d09 runtime: trivial replacements of _g_ in GC files + 2022-08-02 4358a53a97 runtime: trivial replacements of _g_ in proc.go + 2022-08-02 b486518964 runtime: tricky replacements of _g_ in os3_solaris.go + 2022-08-02 54a0ab3f7b runtime: tricky replacements of _g_ in os3_plan9.go + 2022-08-02 4240ff764b runtime: tricky replacements of _g_ in signal_windows.go + 2022-08-02 8666d89ca8 runtime: tricky replacements of _g_ in signal_unix.go + 2022-08-02 74cee276fe runtime: tricky replacements of _g_ in trace.go + 2022-08-02 222799fde6 runtime: tricky replacements of _g_ in mgc.go + 2022-08-02 e9d7f54a1a runtime: tricky replacements of _g_ in proc.go + 2022-08-02 5e8d261918 runtime: rename _p_ to pp + 2022-08-02 0ad2ec6596 runtime: clean up dopanic_m + 2022-08-02 7e952962df runtime: clean up canpanic + 2022-08-02 9dbc0f3556 runtime: fix outdated g.m comment in traceback.go + 2022-08-02 d723df76da internal/goversion: update Version to 1.20 + 2022-08-02 1b7e71e8ae all: disable tests that fail on Alpine + 2022-08-01 f2a9f3e2e0 test: improve generic type assertion test + 2022-08-01 27038b70f8 cmd/compile: fix wrong dict pass condition for type assertions + 2022-08-01 e99f53fed9 doc: move Go 1.19 release notes to x/website + 2022-08-01 8b13a073a1 doc: mention removal of cmd/compile's -importmap and -installsuffix flags + 2022-08-01 e95fd4c238 doc/go1.19: fix typo: EM_LONGARCH -> EM_LOONGARCH + 2022-08-01 dee3efd9f8 doc/go1.19: fix a few links that were missing trailing slashes + 2022-07-30 f32519e5fb runtime: fix typos + 2022-07-29 9a2001a8cc cmd/dist: always pass -short=true with -quick + 2022-07-28 5c8ec89cb5 doc/go1.19: minor adjustments and links + 2022-07-28 417be37048 doc/go1.19: improve the loong64 release notes + 2022-07-28 027855e8d8 os/exec: add GODEBUG setting to opt out of ErrDot changes Change-Id: Idc0fbe93978c0dff7600b90a2c3ecc067fd9f5f2
Diffstat (limited to 'src/runtime/signal_unix.go')
-rw-r--r--src/runtime/signal_unix.go116
1 files changed, 59 insertions, 57 deletions
diff --git a/src/runtime/signal_unix.go b/src/runtime/signal_unix.go
index 0be499b2e9..f241df69f1 100644
--- a/src/runtime/signal_unix.go
+++ b/src/runtime/signal_unix.go
@@ -433,9 +433,9 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
return
}
c := &sigctxt{info, ctx}
- g := sigFetchG(c)
- setg(g)
- if g == nil {
+ gp := sigFetchG(c)
+ setg(gp)
+ if gp == nil {
if sig == _SIGPROF {
// Some platforms (Linux) have per-thread timers, which we use in
// combination with the process-wide timer. Avoid double-counting.
@@ -462,22 +462,22 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
return
}
- setg(g.m.gsignal)
+ setg(gp.m.gsignal)
// If some non-Go code called sigaltstack, adjust.
var gsignalStack gsignalStack
- setStack := adjustSignalStack(sig, g.m, &gsignalStack)
+ setStack := adjustSignalStack(sig, gp.m, &gsignalStack)
if setStack {
- g.m.gsignal.stktopsp = getcallersp()
+ gp.m.gsignal.stktopsp = getcallersp()
}
- if g.stackguard0 == stackFork {
+ if gp.stackguard0 == stackFork {
signalDuringFork(sig)
}
c.fixsigcode(sig)
- sighandler(sig, info, ctx, g)
- setg(g)
+ sighandler(sig, info, ctx, gp)
+ setg(gp)
if setStack {
restoreGsignalStack(&gsignalStack)
}
@@ -596,7 +596,7 @@ var testSigusr1 func(gp *g) bool
// sighandler is invoked when a signal occurs. The global g will be
// set to a gsignal goroutine and we will be running on the alternate
-// signal stack. The parameter g will be the value of the global g
+// signal stack. The parameter gp will be the value of the global g
// when the signal occurred. The sig, info, and ctxt parameters are
// from the system signal handler: they are the parameters passed when
// the SA is passed to the sigaction system call.
@@ -606,9 +606,11 @@ var testSigusr1 func(gp *g) bool
//
//go:nowritebarrierrec
func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
- _g_ := getg()
+ // The g executing the signal handler. This is almost always
+ // mp.gsignal. See delayedSignal for an exception.
+ gsignal := getg()
+ mp := gsignal.m
c := &sigctxt{info, ctxt}
- mp := _g_.m
// Cgo TSAN (not the Go race detector) intercepts signals and calls the
// signal handler at a later time. When the signal handler is called, the
@@ -620,7 +622,7 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
// signal delivery. We use that as an indicator of delayed signals.
// For delayed signals, the handler is called on the g0 stack (see
// adjustSignalStack).
- delayedSignal := *cgo_yield != nil && mp != nil && _g_.stack == mp.g0.stack
+ delayedSignal := *cgo_yield != nil && mp != nil && gsignal.stack == mp.g0.stack
if sig == _SIGPROF {
// Some platforms (Linux) have per-thread timers, which we use in
@@ -710,8 +712,8 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
return
}
- _g_.m.throwing = throwTypeRuntime
- _g_.m.caughtsig.set(gp)
+ mp.throwing = throwTypeRuntime
+ mp.caughtsig.set(gp)
if crashing == 0 {
startpanic_m()
@@ -723,12 +725,12 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
print("Signal ", sig, "\n")
}
- print("PC=", hex(c.sigpc()), " m=", _g_.m.id, " sigcode=", c.sigcode(), "\n")
- if _g_.m.incgo && gp == _g_.m.g0 && _g_.m.curg != nil {
+ print("PC=", hex(c.sigpc()), " m=", mp.id, " sigcode=", c.sigcode(), "\n")
+ if mp.incgo && gp == mp.g0 && mp.curg != nil {
print("signal arrived during cgo execution\n")
// Switch to curg so that we get a traceback of the Go code
// leading up to the cgocall, which switched from curg to g0.
- gp = _g_.m.curg
+ gp = mp.curg
}
if sig == _SIGILL || sig == _SIGFPE {
// It would be nice to know how long the instruction is.
@@ -760,10 +762,10 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
if level > 0 {
goroutineheader(gp)
tracebacktrap(c.sigpc(), c.sigsp(), c.siglr(), gp)
- if crashing > 0 && gp != _g_.m.curg && _g_.m.curg != nil && readgstatus(_g_.m.curg)&^_Gscan == _Grunning {
+ if crashing > 0 && gp != mp.curg && mp.curg != nil && readgstatus(mp.curg)&^_Gscan == _Grunning {
// tracebackothers on original m skipped this one; trace it now.
- goroutineheader(_g_.m.curg)
- traceback(^uintptr(0), ^uintptr(0), 0, _g_.m.curg)
+ goroutineheader(mp.curg)
+ traceback(^uintptr(0), ^uintptr(0), 0, mp.curg)
} else if crashing == 0 {
tracebackothers(gp)
print("\n")
@@ -814,34 +816,34 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
//
//go:linkname sigpanic
func sigpanic() {
- g := getg()
- if !canpanic(g) {
+ gp := getg()
+ if !canpanic() {
throw("unexpected signal during runtime execution")
}
- switch g.sig {
+ switch gp.sig {
case _SIGBUS:
- if g.sigcode0 == _BUS_ADRERR && g.sigcode1 < 0x1000 {
+ if gp.sigcode0 == _BUS_ADRERR && gp.sigcode1 < 0x1000 {
panicmem()
}
// Support runtime/debug.SetPanicOnFault.
- if g.paniconfault {
- panicmemAddr(g.sigcode1)
+ if gp.paniconfault {
+ panicmemAddr(gp.sigcode1)
}
- print("unexpected fault address ", hex(g.sigcode1), "\n")
+ print("unexpected fault address ", hex(gp.sigcode1), "\n")
throw("fault")
case _SIGSEGV:
- if (g.sigcode0 == 0 || g.sigcode0 == _SEGV_MAPERR || g.sigcode0 == _SEGV_ACCERR) && g.sigcode1 < 0x1000 {
+ if (gp.sigcode0 == 0 || gp.sigcode0 == _SEGV_MAPERR || gp.sigcode0 == _SEGV_ACCERR) && gp.sigcode1 < 0x1000 {
panicmem()
}
// Support runtime/debug.SetPanicOnFault.
- if g.paniconfault {
- panicmemAddr(g.sigcode1)
+ if gp.paniconfault {
+ panicmemAddr(gp.sigcode1)
}
- print("unexpected fault address ", hex(g.sigcode1), "\n")
+ print("unexpected fault address ", hex(gp.sigcode1), "\n")
throw("fault")
case _SIGFPE:
- switch g.sigcode0 {
+ switch gp.sigcode0 {
case _FPE_INTDIV:
panicdivide()
case _FPE_INTOVF:
@@ -850,11 +852,11 @@ func sigpanic() {
panicfloat()
}
- if g.sig >= uint32(len(sigtable)) {
- // can't happen: we looked up g.sig in sigtable to decide to call sigpanic
+ if gp.sig >= uint32(len(sigtable)) {
+ // can't happen: we looked up gp.sig in sigtable to decide to call sigpanic
throw("unexpected signal value")
}
- panic(errorString(sigtable[g.sig].name))
+ panic(errorString(sigtable[gp.sig].name))
}
// dieFromSignal kills the program with a signal.
@@ -1115,8 +1117,8 @@ func sigfwdgo(sig uint32, info *siginfo, ctx unsafe.Pointer) bool {
// (1) we weren't in VDSO page,
// (2) we were in a goroutine (i.e., m.curg != nil), and
// (3) we weren't in CGO.
- g := sigFetchG(c)
- if g != nil && g.m != nil && g.m.curg != nil && !g.m.incgo {
+ gp := sigFetchG(c)
+ if gp != nil && gp.m != nil && gp.m.curg != nil && !gp.m.incgo {
return false
}
@@ -1207,15 +1209,15 @@ func minitSignals() {
// of whether it is already set). Record which choice was made in
// newSigstack, so that it can be undone in unminit.
func minitSignalStack() {
- _g_ := getg()
+ mp := getg().m
var st stackt
sigaltstack(nil, &st)
if st.ss_flags&_SS_DISABLE != 0 || !iscgo {
- signalstack(&_g_.m.gsignal.stack)
- _g_.m.newSigstack = true
+ signalstack(&mp.gsignal.stack)
+ mp.newSigstack = true
} else {
- setGsignalStack(&st, &_g_.m.goSigStack)
- _g_.m.newSigstack = false
+ setGsignalStack(&st, &mp.goSigStack)
+ mp.newSigstack = false
}
}
@@ -1297,18 +1299,18 @@ type gsignalStack struct {
//go:nosplit
//go:nowritebarrierrec
func setGsignalStack(st *stackt, old *gsignalStack) {
- g := getg()
+ gp := getg()
if old != nil {
- old.stack = g.m.gsignal.stack
- old.stackguard0 = g.m.gsignal.stackguard0
- old.stackguard1 = g.m.gsignal.stackguard1
- old.stktopsp = g.m.gsignal.stktopsp
+ old.stack = gp.m.gsignal.stack
+ old.stackguard0 = gp.m.gsignal.stackguard0
+ old.stackguard1 = gp.m.gsignal.stackguard1
+ old.stktopsp = gp.m.gsignal.stktopsp
}
stsp := uintptr(unsafe.Pointer(st.ss_sp))
- g.m.gsignal.stack.lo = stsp
- g.m.gsignal.stack.hi = stsp + st.ss_size
- g.m.gsignal.stackguard0 = stsp + _StackGuard
- g.m.gsignal.stackguard1 = stsp + _StackGuard
+ gp.m.gsignal.stack.lo = stsp
+ gp.m.gsignal.stack.hi = stsp + st.ss_size
+ gp.m.gsignal.stackguard0 = stsp + _StackGuard
+ gp.m.gsignal.stackguard1 = stsp + _StackGuard
}
// restoreGsignalStack restores the gsignal stack to the value it had
@@ -1340,9 +1342,9 @@ func signalstack(s *stack) {
//go:nosplit
//go:linkname setsigsegv
func setsigsegv(pc uintptr) {
- g := getg()
- g.sig = _SIGSEGV
- g.sigpc = pc
- g.sigcode0 = _SEGV_MAPERR
- g.sigcode1 = 0 // TODO: emulate si_addr
+ gp := getg()
+ gp.sig = _SIGSEGV
+ gp.sigpc = pc
+ gp.sigcode0 = _SEGV_MAPERR
+ gp.sigcode1 = 0 // TODO: emulate si_addr
}