24
24
#include "libc/intrin/atomic.h"
25
25
#include "libc/intrin/describeflags.h"
26
26
#include "libc/intrin/strace.h"
27
+ #include "libc/runtime/internal.h"
27
28
#include "libc/runtime/syslib.internal.h"
28
29
#include "libc/sysv/consts/sicode.h"
29
30
#include "libc/thread/posixthread.internal.h"
@@ -46,8 +47,12 @@ errno_t pthread_kill(pthread_t thread, int sig) {
46
47
if (pt )
47
48
_pthread_ref (pt );
48
49
if (!thread ) {
50
+ // avoid crashing on easily predictable npe
51
+ // chances are you need a barrier to synchronize startup
49
52
err = EFAULT ;
50
53
} else if (!(1 <= sig && sig <= 64 )) {
54
+ // cosmo only supports this many signals
55
+ // some platforms have more but we're not sure what they do
51
56
err = EINVAL ;
52
57
} else if (thread == __get_tls ()-> tib_pthread ) {
53
58
err = raise (sig ); // XNU will EDEADLK it otherwise
@@ -60,8 +65,15 @@ errno_t pthread_kill(pthread_t thread, int sig) {
60
65
if (IsXnuSilicon ()) {
61
66
err = __syslib -> __pthread_kill (_pthread_syshand (pt ), sig );
62
67
} else {
68
+ int r = 0 ;
63
69
int e = errno ;
64
- if (sys_tkill (_pthread_tid (pt ), sig , pt -> tib )) {
70
+ int tid = _pthread_tid (pt );
71
+ if (IsLinux () || IsFreebsd ()) {
72
+ r = sys_tgkill (__pid , tid , sig );
73
+ } else {
74
+ r = sys_tkill (tid , sig , pt -> tib );
75
+ }
76
+ if (r ) {
65
77
err = errno ;
66
78
errno = e ;
67
79
}
0 commit comments