summaryrefslogtreecommitdiff
path: root/src/runtime/sys_plan9_amd64.s
diff options
context:
space:
mode:
authorAnthony Martin <ality@pbrane.org>2014-09-09 17:19:01 -0700
committerAnthony Martin <ality@pbrane.org>2014-09-09 17:19:01 -0700
commited43a9dc789237c01a3d997d133fdcbe0323670c (patch)
treeb22112b53e01e06a6b175fe37b6e8911c52ad85f /src/runtime/sys_plan9_amd64.s
parentc6cd0b3047aa3cb22482c12701b31a817df85316 (diff)
downloadgo-ed43a9dc789237c01a3d997d133fdcbe0323670c.tar.gz
runtime: call rfork on scheduler stack on Plan 9
A race exists between the parent and child processes after a fork. The child needs to access the new M pointer passed as an argument but the parent may have already returned and clobbered it. Previously, we avoided this by saving the necessary data into registers before the rfork system call but this isn't guaranteed to work because Plan 9 makes no promises about the register state after a system call. Only the 386 kernel seems to save them. For amd64 and arm, this method won't work. We eliminate the race by allocating stack space for the scheduler goroutines (g0) in the per-process copy-on-write stack segment and by only calling rfork on the scheduler stack. LGTM=aram, 0intro, rsc R=aram, 0intro, mischief, rsc CC=golang-codereviews https://codereview.appspot.com/110680044
Diffstat (limited to 'src/runtime/sys_plan9_amd64.s')
-rw-r--r--src/runtime/sys_plan9_amd64.s48
1 files changed, 21 insertions, 27 deletions
diff --git a/src/runtime/sys_plan9_amd64.s b/src/runtime/sys_plan9_amd64.s
index 36d2d97e2..b0e186460 100644
--- a/src/runtime/sys_plan9_amd64.s
+++ b/src/runtime/sys_plan9_amd64.s
@@ -130,42 +130,36 @@ TEXT runtime·plan9_semrelease(SB),NOSPLIT,$0
RET
TEXT runtime·rfork(SB),NOSPLIT,$0
- MOVQ $19, BP // rfork
+ MOVQ $19, BP
SYSCALL
-
- // In parent, return.
- CMPQ AX, $0
- JEQ 3(PC)
- MOVL AX, ret+40(FP)
+ MOVL AX, ret+8(FP)
RET
- // In child on forked stack.
- MOVQ mm+24(SP), BX // m
- MOVQ gg+32(SP), DX // g
- MOVQ fn+40(SP), SI // fn
-
- // set SP to be on the new child stack
- MOVQ stack+16(SP), CX
- MOVQ CX, SP
+TEXT runtime·tstart_plan9(SB),NOSPLIT,$0
+ MOVQ newm+0(FP), CX
+ MOVQ m_g0(CX), DX
- // Initialize m, g.
- get_tls(AX)
- MOVQ DX, g(AX)
- MOVQ BX, g_m(DX)
+ // Layout new m scheduler stack on os stack.
+ MOVQ SP, AX
+ MOVQ AX, (g_stack+stack_hi)(DX)
+ SUBQ $(64*1024), AX // stack size
+ MOVQ AX, (g_stack+stack_lo)(DX)
+ MOVQ AX, g_stackguard0(DX)
+ MOVQ AX, g_stackguard1(DX)
// Initialize procid from TOS struct.
MOVQ _tos(SB), AX
MOVQ 64(AX), AX
- MOVQ AX, m_procid(BX) // save pid as m->procid
-
+ MOVQ AX, m_procid(CX) // save pid as m->procid
+
+ // Finally, initialize g.
+ get_tls(BX)
+ MOVQ DX, g(BX)
+
CALL runtime·stackcheck(SB) // smashes AX, CX
-
- MOVQ 0(DX), DX // paranoia; check they are not nil
- MOVQ 0(BX), BX
-
- CALL SI // fn()
- CALL runtime·exit(SB)
- MOVL AX, ret+40(FP)
+ CALL runtime·mstart(SB)
+
+ MOVQ $0x1234, 0x1234 // not reached
RET
// This is needed by asm_amd64.s