1 /* Copyright (C) 2002-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
28 __pthread_kill (pthread_t threadid
, int signo
)
30 struct pthread
*pd
= (struct pthread
*) threadid
;
32 /* Make sure the descriptor is valid. */
33 if (DEBUGGING_P
&& INVALID_TD_P (pd
))
34 /* Not a valid thread handle. */
37 /* Force load of pd->tid into local variable or register. Otherwise
38 if a thread exits between ESRCH test and tgkill, we might return
39 EINVAL, because pd->tid would be cleared by the kernel. */
40 pid_t tid
= atomic_forced_read (pd
->tid
);
41 if (__glibc_unlikely (tid
<= 0))
42 /* Not a valid thread handle. */
45 /* Disallow sending the signal we use for cancellation, timers,
46 for the setxid implementation. */
47 if (signo
== SIGCANCEL
|| signo
== SIGTIMER
|| signo
== SIGSETXID
)
50 /* We have a special syscall to do the work. */
51 INTERNAL_SYSCALL_DECL (err
);
53 pid_t pid
= __getpid ();
55 int val
= INTERNAL_SYSCALL_CALL (tgkill
, err
, pid
, tid
, signo
);
56 return (INTERNAL_SYSCALL_ERROR_P (val
, err
)
57 ? INTERNAL_SYSCALL_ERRNO (val
, err
) : 0);
59 strong_alias (__pthread_kill
, pthread_kill
)