diff options
author | Elias Naur <elias.naur@gmail.com> | 2018-06-07 12:19:42 +0200 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2018-06-12 17:05:46 +0000 |
commit | 021c39d7a3361290d9e29497cf2a4a8fd2ee7b5c (patch) | |
tree | 573c7176129e0e5a0ed8b30b867453f04de0aa4b /src/runtime/asm_arm64.s | |
parent | ec989337c5d3203d52de1a2314813996c711fce6 (diff) | |
download | go-021c39d7a3361290d9e29497cf2a4a8fd2ee7b5c.tar.gz go-021c39d7a3361290d9e29497cf2a4a8fd2ee7b5c.zip |
runtime: use libc for signal functions on iOS
Also:
- Add extra SystemStack space for darwin/arm64 just
like for darwin/arm.
- Removed redundant stack alignment; the arm64 hardware enforces
the 16 byte alignment.
- Save and restore the g registers at library initialization.
- Zero g registers since libpreinit can call libc functions
that in turn use asmcgocall. asmcgocall requires an initialized g.
- Change asmcgocall to work even if no g is set. The change mimics
amd64.
Change-Id: I1b8c63b07cfec23b909c0d215b50dc229f8adbc8
Reviewed-on: https://go-review.googlesource.com/117176
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/asm_arm64.s')
-rw-r--r-- | src/runtime/asm_arm64.s | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/runtime/asm_arm64.s b/src/runtime/asm_arm64.s index d1b90b056c..af389be9fe 100644 --- a/src/runtime/asm_arm64.s +++ b/src/runtime/asm_arm64.s @@ -863,6 +863,8 @@ TEXT ·asmcgocall(SB),NOSPLIT,$0-20 MOVD arg+8(FP), R0 MOVD RSP, R2 // save original stack pointer + CMP $0, g + BEQ nosave MOVD g, R4 // Figure out if we need to switch to m->g0 stack. @@ -871,10 +873,12 @@ TEXT ·asmcgocall(SB),NOSPLIT,$0-20 MOVD g_m(g), R8 MOVD m_gsignal(R8), R3 CMP R3, g - BEQ noswitch + BEQ nosave MOVD m_g0(R8), R3 CMP R3, g - BEQ noswitch + BEQ nosave + + // Switch to system stack. MOVD R0, R9 // gosave<> and save_g might clobber R0 BL gosave<>(SB) MOVD R3, g @@ -884,12 +888,10 @@ TEXT ·asmcgocall(SB),NOSPLIT,$0-20 MOVD R9, R0 // Now on a scheduling stack (a pthread-created stack). -noswitch: // Save room for two of our pointers /*, plus 32 bytes of callee // save area that lives on the caller stack. */ MOVD RSP, R13 SUB $16, R13 - BIC $0xf, R13 // alignment for gcc ABI MOVD R13, RSP MOVD R4, 0(RSP) // save old g on stack MOVD (g_stack+stack_hi)(R4), R4 @@ -910,6 +912,30 @@ noswitch: MOVW R0, ret+16(FP) RET +nosave: + // Running on a system stack, perhaps even without a g. + // Having no g can happen during thread creation or thread teardown + // (see needm/dropm on Solaris, for example). + // This code is like the above sequence but without saving/restoring g + // and without worrying about the stack moving out from under us + // (because we're on a system stack, not a goroutine stack). + // The above code could be used directly if already on a system stack, + // but then the only path through this code would be a rare case on Solaris. + // Using this code for all "already on system stack" calls exercises it more, + // which should help keep it correct. + MOVD RSP, R13 + SUB $16, R13 + MOVD R13, RSP + MOVD $0, R4 + MOVD R4, 0(RSP) // Where above code stores g, in case someone looks during debugging. + MOVD R2, 8(RSP) // Save original stack pointer. + BL (R1) + // Restore stack pointer. + MOVD 8(RSP), R2 + MOVD R2, RSP + MOVD R0, ret+16(FP) + RET + // cgocallback(void (*fn)(void*), void *frame, uintptr framesize, uintptr ctxt) // Turn the fn into a Go func (by taking its address) and call // cgocallback_gofunc. |