1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:14:45 -07:00

runtime: use raise instead of pthread_self and pthread_kill

pthread_self and pthread_kill are not safe to call from a signal
handler. In particular, pthread_self fails in iOS when called from
a signal handler context.

Use raise instead; it is signal handler safe and simpler.

Change-Id: I0cbfe25151aed245f55d7b76719ce06dc78c6a75
Reviewed-on: https://go-review.googlesource.com/113877
Run-TryBot: Elias Naur <elias.naur@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Elias Naur 2018-05-21 15:33:20 +02:00
parent b88276da66
commit 467e15accc
4 changed files with 10 additions and 40 deletions

View File

@ -539,12 +539,6 @@ func sigtramp(fn uintptr, infostyle, sig uint32, info *siginfo, ctx unsafe.Point
//go:noescape
func setitimer(mode int32, new, old *itimerval)
//go:nosplit
func raise(sig uint32) {
tid := pthread_self()
pthread_kill(tid, int(sig))
}
func raiseproc(sig uint32)
//extern SigTabTT runtime·sigtab[];

View File

@ -41,10 +41,10 @@ func pthread_create_trampoline()
//go:nosplit
//go:cgo_unsafe_args
func pthread_kill(thread pthread, sig int) (errno int32) {
return asmcgocall(unsafe.Pointer(funcPC(pthread_kill_trampoline)), unsafe.Pointer(&thread))
func raise(sig uint32) {
asmcgocall(unsafe.Pointer(funcPC(raise_trampoline)), unsafe.Pointer(&sig))
}
func pthread_kill_trampoline()
func raise_trampoline()
//go:nosplit
//go:cgo_unsafe_args
@ -158,8 +158,7 @@ func exitThread(wait *uint32) {
//go:cgo_import_dynamic libc_pthread_attr_setdetachstate pthread_attr_setdetachstate "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_pthread_create pthread_create "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_exit exit "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_pthread_kill pthread_kill "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_pthread_self pthread_self "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_raise raise "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_open open "/usr/lib/libSystem.B.dylib"
//go:cgo_import_dynamic libc_close close "/usr/lib/libSystem.B.dylib"

View File

@ -619,27 +619,14 @@ TEXT runtime·pthread_create_trampoline(SB),NOSPLIT,$0
POPL BP
RET
TEXT runtime·pthread_self_trampoline(SB),NOSPLIT,$0
PUSHL BP
MOVL SP, BP
SUBL $8, SP
CALL libc_pthread_self(SB)
MOVL 16(SP), CX
MOVL AX, (CX) // Save result.
MOVL BP, SP
POPL BP
RET
TEXT runtime·pthread_kill_trampoline(SB),NOSPLIT,$0
TEXT runtime·raise_trampoline(SB),NOSPLIT,$0
PUSHL BP
MOVL SP, BP
SUBL $8, SP
MOVL 16(SP), CX
MOVL 0(CX), AX // arg 1 thread ID
MOVL 0(CX), AX // arg 1 sig
MOVL AX, 0(SP)
MOVL 4(CX), AX // arg 2 sig
MOVL AX, 4(SP)
CALL libc_pthread_kill(SB)
CALL libc_raise(SB)
MOVL BP, SP
POPL BP
RET

View File

@ -590,20 +590,10 @@ TEXT runtime·pthread_create_trampoline(SB),NOSPLIT,$0
POPQ BP
RET
TEXT runtime·pthread_self_trampoline(SB),NOSPLIT,$0
TEXT runtime·raise_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ DI, BX // Note: asmcgocall doesn't save anything in BX, so it is ok to clobber it here.
CALL libc_pthread_self(SB)
MOVQ AX, 0(BX) // Save result.
POPQ BP
RET
TEXT runtime·pthread_kill_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 signal
MOVQ 0(DI), DI // arg 1 thread
CALL libc_pthread_kill(SB)
MOVL 0(DI), DI // arg 1 signal
CALL libc_raise(SB)
POPQ BP
RET