aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/sys_freebsd_arm.s
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2017-06-16 15:54:21 -0400
committerAustin Clements <austin@google.com>2017-10-11 17:47:18 +0000
commiteff2b2620db005cb58c266c0f25309d6f466cb25 (patch)
tree4d9e5ad4d70b89c7bedb7b3b6af7753ee6ada3f4 /src/runtime/sys_freebsd_arm.s
parenta9c3d09d0e9a8bf5986ec54d29ea6c68c2786d57 (diff)
downloadgo-eff2b2620db005cb58c266c0f25309d6f466cb25.tar.gz
go-eff2b2620db005cb58c266c0f25309d6f466cb25.zip
runtime: make it possible to exit Go-created threads
Currently, threads created by the runtime exist until the whole program exits. For #14592 and #20395, we want to be able to exit and clean up threads created by the runtime. This commit implements that mechanism. The main difficulty is how to clean up the g0 stack. In cgo mode and on Solaris and Windows where the OS manages thread stacks, we simply arrange to return from mstart and let the system clean up the thread. If the runtime allocated the g0 stack, then we use a new exitThread syscall wrapper that arranges to clear a flag in the M once the stack can safely be reaped and call the thread termination syscall. exitThread is based on the existing exit1 wrapper, which was always meant to terminate the calling thread. However, exit1 has never been used since it was introduced 9 years ago, so it was broken on several platforms. exitThread also has the additional complication of having to flag that the stack is unused, which requires some tricks on platforms that use the stack for syscalls. This still leaves the problem of how to reap the unused g0 stacks. For this, we move the M from allm to a new freem list as part of the M exiting. Later, allocm scans the freem list, finds Ms that are marked as done with their stack, removes these from the list and frees their g0 stacks. This also allows these Ms to be garbage collected. This CL does not yet use any of this functionality. Follow-up CLs will. Likewise, there are no new tests in this CL because we'll need follow-up functionality to test it. Change-Id: Ic851ee74227b6d39c6fc1219fc71b45d3004bc63 Reviewed-on: https://go-review.googlesource.com/46037 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/sys_freebsd_arm.s')
-rw-r--r--src/runtime/sys_freebsd_arm.s23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/runtime/sys_freebsd_arm.s b/src/runtime/sys_freebsd_arm.s
index 2851587b0d..0121e62309 100644
--- a/src/runtime/sys_freebsd_arm.s
+++ b/src/runtime/sys_freebsd_arm.s
@@ -82,13 +82,22 @@ TEXT runtime·exit(SB),NOSPLIT,$-8
MOVW.CS R8, (R8)
RET
-TEXT runtime·exit1(SB),NOSPLIT,$-8
- MOVW code+0(FP), R0 // arg 1 exit status
- MOVW $SYS_thr_exit, R7
- SWI $0
- MOVW.CS $0, R8 // crash on syscall failure
- MOVW.CS R8, (R8)
- RET
+// func exitThread(wait *uint32)
+TEXT runtime·exitThread(SB),NOSPLIT,$0-4
+ MOVW wait+0(FP), R0
+ // We're done using the stack.
+ MOVW $0, R1
+storeloop:
+ LDREX (R0), R4 // loads R4
+ STREX R1, (R0), R1 // stores R2
+ CMP $0, R1
+ BNE storeloop
+ MOVW $0, R0 // arg 1 long *state
+ MOVW $SYS_thr_exit, R7
+ SWI $0
+ MOVW.CS $0, R8 // crash on syscall failure
+ MOVW.CS R8, (R8)
+ JMP 0(PC)
TEXT runtime·open(SB),NOSPLIT,$-8
MOVW name+0(FP), R0 // arg 1 name