aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime/linux
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-08-04 17:50:22 -0700
committerRuss Cox <rsc@golang.org>2010-08-04 17:50:22 -0700
commite473f42b2d3ac9b877436638dc182342dcd2e86c (patch)
tree4a8b31048310c4334ac1c16f4321c6d9e667dfcb /src/pkg/runtime/linux
parent3dc6c9e64d8de9931ed621aaa15884512014afd2 (diff)
downloadgo-e473f42b2d3ac9b877436638dc182342dcd2e86c.tar.xz
amd64: use segment memory for thread-local storage
Returns R14 and R15 to the available register pool. Plays more nicely with ELF ABI C code. In particular, our signal handlers will no longer crash when a signal arrives during execution of a cgo C call. Fixes #720. R=ken2, r CC=golang-dev https://golang.org/cl/1847051
Diffstat (limited to 'src/pkg/runtime/linux')
-rw-r--r--src/pkg/runtime/linux/amd64/sys.s54
1 files changed, 45 insertions, 9 deletions
diff --git a/src/pkg/runtime/linux/amd64/sys.s b/src/pkg/runtime/linux/amd64/sys.s
index dd04731581..20287c8d02 100644
--- a/src/pkg/runtime/linux/amd64/sys.s
+++ b/src/pkg/runtime/linux/amd64/sys.s
@@ -60,12 +60,27 @@ TEXT rt_sigaction(SB),7,$0-32
SYSCALL
RET
-TEXT sigtramp(SB),7,$24-16
- MOVQ m_gsignal(m), g
+TEXT sigtramp(SB),7,$64
+ get_tls(BX)
+
+ // save g
+ MOVQ g(BX), BP
+ MOVQ BP, 40(SP)
+
+ // g = m->gsignal
+ MOVQ m(BX), BP
+ MOVQ m_gsignal(BP), BP
+ MOVQ BP, g(BX)
+
MOVQ DI, 0(SP)
MOVQ SI, 8(SP)
MOVQ DX, 16(SP)
CALL sighandler(SB)
+
+ // restore g
+ get_tls(BX)
+ MOVQ 40(SP), BP
+ MOVQ BP, g(BX)
RET
TEXT sigignore(SB),7,$0
@@ -129,17 +144,24 @@ TEXT clone(SB),7,$0
CMPQ AX, $0
JEQ 2(PC)
RET
-
- // In child, set up new stack
+
+ // In child, on new stack.
MOVQ SI, SP
- MOVQ R8, m
- MOVQ R9, g
- CALL stackcheck(SB)
-
+
// Initialize m->procid to Linux tid
MOVL $186, AX // gettid
SYSCALL
- MOVQ AX, m_procid(m)
+ MOVQ AX, m_procid(R8)
+
+ // Set FS to point at m->tls.
+ LEAQ m_tls(R8), DI
+ CALL settls(SB)
+
+ // In child, set up new stack
+ get_tls(CX)
+ MOVQ R8, m(CX)
+ MOVQ R9, g(CX)
+ CALL stackcheck(SB)
// Call fn
CALL R12
@@ -159,3 +181,17 @@ TEXT sigaltstack(SB),7,$-8
JLS 2(PC)
CALL notok(SB)
RET
+
+// set tls base to DI
+TEXT settls(SB),7,$32
+ ADDQ $16, DI // ELF wants to use -16(FS), -8(FS)
+
+ MOVQ DI, SI
+ MOVQ $0x1002, DI // ARCH_SET_FS
+ MOVQ $158, AX // arch_prctl
+ SYSCALL
+ CMPQ AX, $0xfffffffffffff001
+ JLS 2(PC)
+ CALL notok(SB)
+ RET
+