Convert raise from raw syscalls to using the system pthread library.
As a bonus, raise will now target the current thread instead of the
process.
Updates #17490
Change-Id: I2e44f2000bf870e99a5b4dc5ff5e0799fba91bde
Reviewed-on: https://go-review.googlesource.com/110475
Run-TryBot: Elias Naur <elias.naur@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
//go:noescape
func setitimer(mode int32, new, old *itimerval)
-func raise(sig uint32)
+//go:nosplit
+func raise(sig uint32) {
+ tid := pthread_self()
+ pthread_kill(tid, int(sig))
+}
+
func raiseproc(sig uint32)
//extern SigTabTT runtime·sigtab[];
//go:noescape
func pthread_create_trampoline(t *pthread, attr *pthreadattr, start uintptr, arg unsafe.Pointer) int32
+//go:nowritebarrier
+func pthread_kill(thread pthread, sig int) (errno int32) {
+ systemstack(func() {
+ errno = pthread_kill_trampoline(thread, sig)
+ })
+ return
+}
+
+//go:noescape
+func pthread_kill_trampoline(thread pthread, sig int) int32
+
+//go:nowritebarrier
+func pthread_self() (t pthread) {
+ systemstack(func() {
+ t = pthread_self_trampoline()
+ })
+ return
+}
+
+//go:noescape
+func pthread_self_trampoline() pthread
+
// Tell the linker that the libc_* functions are to be found
// in a system library, with the libc_ prefix missing.
//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"
// Magic incantation to get libSystem actually dynamically linked.
// TODO: Why does the code require this? See cmd/compile/internal/ld/go.go:210
MOVL AX, ret+12(FP)
RET
-TEXT runtime·raise(SB),NOSPLIT,$0
- // Ideally we'd send the signal to the current thread,
- // not the whole process, but that's too hard on OS X.
- JMP runtime·raiseproc(SB)
-
TEXT runtime·raiseproc(SB),NOSPLIT,$16
MOVL $20, AX // getpid
INT $0x80
MOVL AX, ret+16(FP)
RET
+
+TEXT runtime·pthread_self_trampoline(SB),NOSPLIT,$0-4
+ PUSHL BP
+ MOVL SP, BP
+
+ ANDL $~15, SP
+
+ CALL libc_pthread_self(SB)
+
+ MOVL BP, SP
+ POPL BP
+
+ MOVL AX, ret+0(FP)
+ RET
+
+TEXT runtime·pthread_kill_trampoline(SB),NOSPLIT,$0-12
+ MOVL thread+0(FP), AX
+ MOVL sig+4(FP), CX
+ PUSHL BP
+ MOVL SP, BP
+
+ SUBL $8, SP
+ ANDL $~15, SP
+
+ MOVL AX, 0(SP)
+ MOVL CX, 4(SP)
+ CALL libc_pthread_kill(SB)
+
+ MOVL BP, SP
+ POPL BP
+
+ MOVL AX, ret+8(FP)
+ RET
MOVL AX, ret+24(FP)
RET
-TEXT runtime·raise(SB),NOSPLIT,$0
- // Ideally we'd send the signal to the current thread,
- // not the whole process, but that's too hard on OS X.
- JMP runtime·raiseproc(SB)
-
TEXT runtime·raiseproc(SB),NOSPLIT,$24
MOVL $(0x2000000+20), AX // getpid
SYSCALL
POPQ BP
MOVL AX, ret+32(FP)
RET
+
+TEXT runtime·pthread_self_trampoline(SB),NOSPLIT,$0-8
+ PUSHQ BP
+ MOVQ SP, BP
+ ANDQ $~15, SP
+ CALL libc_pthread_self(SB)
+ MOVQ BP, SP
+ POPQ BP
+ MOVQ AX, ret+0(FP)
+ RET
+
+TEXT runtime·pthread_kill_trampoline(SB),NOSPLIT,$0-20
+ MOVQ thread+0(FP), DI
+ MOVQ sig+8(FP), SI
+ PUSHQ BP
+ MOVQ SP, BP
+ ANDQ $~15, SP
+ CALL libc_pthread_kill(SB)
+ MOVQ BP, SP
+ POPQ BP
+ MOVL AX, ret+16(FP)
+ RET