mirror of
https://github.com/golang/go
synced 2024-10-06 08:00:07 +00:00
runtime: trivial replacements of g in signal_unix.go
Change-Id: I0d8d50c8b7ae6cd01594091392dc726cf149e34a Reviewed-on: https://go-review.googlesource.com/c/go/+/418590 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Michael Pratt <mpratt@google.com>
This commit is contained in:
parent
399f50c9d7
commit
c647264619
|
@ -433,9 +433,9 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c := &sigctxt{info, ctx}
|
c := &sigctxt{info, ctx}
|
||||||
g := sigFetchG(c)
|
gp := sigFetchG(c)
|
||||||
setg(g)
|
setg(gp)
|
||||||
if g == nil {
|
if gp == nil {
|
||||||
if sig == _SIGPROF {
|
if sig == _SIGPROF {
|
||||||
// Some platforms (Linux) have per-thread timers, which we use in
|
// Some platforms (Linux) have per-thread timers, which we use in
|
||||||
// combination with the process-wide timer. Avoid double-counting.
|
// combination with the process-wide timer. Avoid double-counting.
|
||||||
|
@ -462,22 +462,22 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
setg(g.m.gsignal)
|
setg(gp.m.gsignal)
|
||||||
|
|
||||||
// If some non-Go code called sigaltstack, adjust.
|
// If some non-Go code called sigaltstack, adjust.
|
||||||
var gsignalStack gsignalStack
|
var gsignalStack gsignalStack
|
||||||
setStack := adjustSignalStack(sig, g.m, &gsignalStack)
|
setStack := adjustSignalStack(sig, gp.m, &gsignalStack)
|
||||||
if setStack {
|
if setStack {
|
||||||
g.m.gsignal.stktopsp = getcallersp()
|
gp.m.gsignal.stktopsp = getcallersp()
|
||||||
}
|
}
|
||||||
|
|
||||||
if g.stackguard0 == stackFork {
|
if gp.stackguard0 == stackFork {
|
||||||
signalDuringFork(sig)
|
signalDuringFork(sig)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.fixsigcode(sig)
|
c.fixsigcode(sig)
|
||||||
sighandler(sig, info, ctx, g)
|
sighandler(sig, info, ctx, gp)
|
||||||
setg(g)
|
setg(gp)
|
||||||
if setStack {
|
if setStack {
|
||||||
restoreGsignalStack(&gsignalStack)
|
restoreGsignalStack(&gsignalStack)
|
||||||
}
|
}
|
||||||
|
@ -816,34 +816,34 @@ func sighandler(sig uint32, info *siginfo, ctxt unsafe.Pointer, gp *g) {
|
||||||
//
|
//
|
||||||
//go:linkname sigpanic
|
//go:linkname sigpanic
|
||||||
func sigpanic() {
|
func sigpanic() {
|
||||||
g := getg()
|
gp := getg()
|
||||||
if !canpanic() {
|
if !canpanic() {
|
||||||
throw("unexpected signal during runtime execution")
|
throw("unexpected signal during runtime execution")
|
||||||
}
|
}
|
||||||
|
|
||||||
switch g.sig {
|
switch gp.sig {
|
||||||
case _SIGBUS:
|
case _SIGBUS:
|
||||||
if g.sigcode0 == _BUS_ADRERR && g.sigcode1 < 0x1000 {
|
if gp.sigcode0 == _BUS_ADRERR && gp.sigcode1 < 0x1000 {
|
||||||
panicmem()
|
panicmem()
|
||||||
}
|
}
|
||||||
// Support runtime/debug.SetPanicOnFault.
|
// Support runtime/debug.SetPanicOnFault.
|
||||||
if g.paniconfault {
|
if gp.paniconfault {
|
||||||
panicmemAddr(g.sigcode1)
|
panicmemAddr(gp.sigcode1)
|
||||||
}
|
}
|
||||||
print("unexpected fault address ", hex(g.sigcode1), "\n")
|
print("unexpected fault address ", hex(gp.sigcode1), "\n")
|
||||||
throw("fault")
|
throw("fault")
|
||||||
case _SIGSEGV:
|
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()
|
panicmem()
|
||||||
}
|
}
|
||||||
// Support runtime/debug.SetPanicOnFault.
|
// Support runtime/debug.SetPanicOnFault.
|
||||||
if g.paniconfault {
|
if gp.paniconfault {
|
||||||
panicmemAddr(g.sigcode1)
|
panicmemAddr(gp.sigcode1)
|
||||||
}
|
}
|
||||||
print("unexpected fault address ", hex(g.sigcode1), "\n")
|
print("unexpected fault address ", hex(gp.sigcode1), "\n")
|
||||||
throw("fault")
|
throw("fault")
|
||||||
case _SIGFPE:
|
case _SIGFPE:
|
||||||
switch g.sigcode0 {
|
switch gp.sigcode0 {
|
||||||
case _FPE_INTDIV:
|
case _FPE_INTDIV:
|
||||||
panicdivide()
|
panicdivide()
|
||||||
case _FPE_INTOVF:
|
case _FPE_INTOVF:
|
||||||
|
@ -852,11 +852,11 @@ func sigpanic() {
|
||||||
panicfloat()
|
panicfloat()
|
||||||
}
|
}
|
||||||
|
|
||||||
if g.sig >= uint32(len(sigtable)) {
|
if gp.sig >= uint32(len(sigtable)) {
|
||||||
// can't happen: we looked up g.sig in sigtable to decide to call sigpanic
|
// can't happen: we looked up gp.sig in sigtable to decide to call sigpanic
|
||||||
throw("unexpected signal value")
|
throw("unexpected signal value")
|
||||||
}
|
}
|
||||||
panic(errorString(sigtable[g.sig].name))
|
panic(errorString(sigtable[gp.sig].name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// dieFromSignal kills the program with a signal.
|
// dieFromSignal kills the program with a signal.
|
||||||
|
@ -1117,8 +1117,8 @@ func sigfwdgo(sig uint32, info *siginfo, ctx unsafe.Pointer) bool {
|
||||||
// (1) we weren't in VDSO page,
|
// (1) we weren't in VDSO page,
|
||||||
// (2) we were in a goroutine (i.e., m.curg != nil), and
|
// (2) we were in a goroutine (i.e., m.curg != nil), and
|
||||||
// (3) we weren't in CGO.
|
// (3) we weren't in CGO.
|
||||||
g := sigFetchG(c)
|
gp := sigFetchG(c)
|
||||||
if g != nil && g.m != nil && g.m.curg != nil && !g.m.incgo {
|
if gp != nil && gp.m != nil && gp.m.curg != nil && !gp.m.incgo {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1299,18 +1299,18 @@ type gsignalStack struct {
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
//go:nowritebarrierrec
|
//go:nowritebarrierrec
|
||||||
func setGsignalStack(st *stackt, old *gsignalStack) {
|
func setGsignalStack(st *stackt, old *gsignalStack) {
|
||||||
g := getg()
|
gp := getg()
|
||||||
if old != nil {
|
if old != nil {
|
||||||
old.stack = g.m.gsignal.stack
|
old.stack = gp.m.gsignal.stack
|
||||||
old.stackguard0 = g.m.gsignal.stackguard0
|
old.stackguard0 = gp.m.gsignal.stackguard0
|
||||||
old.stackguard1 = g.m.gsignal.stackguard1
|
old.stackguard1 = gp.m.gsignal.stackguard1
|
||||||
old.stktopsp = g.m.gsignal.stktopsp
|
old.stktopsp = gp.m.gsignal.stktopsp
|
||||||
}
|
}
|
||||||
stsp := uintptr(unsafe.Pointer(st.ss_sp))
|
stsp := uintptr(unsafe.Pointer(st.ss_sp))
|
||||||
g.m.gsignal.stack.lo = stsp
|
gp.m.gsignal.stack.lo = stsp
|
||||||
g.m.gsignal.stack.hi = stsp + st.ss_size
|
gp.m.gsignal.stack.hi = stsp + st.ss_size
|
||||||
g.m.gsignal.stackguard0 = stsp + _StackGuard
|
gp.m.gsignal.stackguard0 = stsp + _StackGuard
|
||||||
g.m.gsignal.stackguard1 = stsp + _StackGuard
|
gp.m.gsignal.stackguard1 = stsp + _StackGuard
|
||||||
}
|
}
|
||||||
|
|
||||||
// restoreGsignalStack restores the gsignal stack to the value it had
|
// restoreGsignalStack restores the gsignal stack to the value it had
|
||||||
|
@ -1342,9 +1342,9 @@ func signalstack(s *stack) {
|
||||||
//go:nosplit
|
//go:nosplit
|
||||||
//go:linkname setsigsegv
|
//go:linkname setsigsegv
|
||||||
func setsigsegv(pc uintptr) {
|
func setsigsegv(pc uintptr) {
|
||||||
g := getg()
|
gp := getg()
|
||||||
g.sig = _SIGSEGV
|
gp.sig = _SIGSEGV
|
||||||
g.sigpc = pc
|
gp.sigpc = pc
|
||||||
g.sigcode0 = _SEGV_MAPERR
|
gp.sigcode0 = _SEGV_MAPERR
|
||||||
g.sigcode1 = 0 // TODO: emulate si_addr
|
gp.sigcode1 = 0 // TODO: emulate si_addr
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue