runtime: pass to signal handler value of g at time of signal
The existing code assumed that signals only arrived
while executing on the goroutine stack (g == m->curg),
not while executing on the scheduler stack (g == m->g0).
Most of the signal handling trampolines correctly saved
and restored g already, but the sighandler C code did not
have access to it.
Some rewriting of assembly to make the various
implementations as similar as possible.
Will need to change Windows too but I don't
understand how sigtramp gets called there.
R=r
CC=golang-dev
https://golang.org/cl/4203042
diff --git a/src/pkg/runtime/linux/amd64/sys.s b/src/pkg/runtime/linux/amd64/sys.s
index 170b659..1bf734d 100644
--- a/src/pkg/runtime/linux/amd64/sys.s
+++ b/src/pkg/runtime/linux/amd64/sys.s
@@ -64,8 +64,8 @@
get_tls(BX)
// save g
- MOVQ g(BX), BP
- MOVQ BP, 40(SP)
+ MOVQ g(BX), R10
+ MOVQ R10, 40(SP)
// g = m->gsignal
MOVQ m(BX), BP
@@ -75,12 +75,14 @@
MOVQ DI, 0(SP)
MOVQ SI, 8(SP)
MOVQ DX, 16(SP)
+ MOVQ R10, 24(SP)
+
CALL runtime·sighandler(SB)
// restore g
get_tls(BX)
- MOVQ 40(SP), BP
- MOVQ BP, g(BX)
+ MOVQ 40(SP), R10
+ MOVQ R10, g(BX)
RET
TEXT runtime·sigignore(SB),7,$0