Fix failing nss/tst-nss-files-hosts-long with local resolver
[glibc.git] / nptl / pthread_kill.c
blobf79a2b26fc7f72e5df89c81f2274bcfb6a2fcfe5
1 /* Send a signal to a specific pthread. Stub version.
2 Copyright (C) 2014-2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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 <https://www.gnu.org/licenses/>. */
19 #include <unistd.h>
20 #include <pthreadP.h>
21 #include <shlib-compat.h>
23 int
24 __pthread_kill_internal (pthread_t threadid, int signo)
26 pid_t tid;
27 struct pthread *pd = (struct pthread *) threadid;
29 if (pd == THREAD_SELF)
30 /* It is a special case to handle raise() implementation after a vfork
31 call (which does not update the PD tid field). */
32 tid = INLINE_SYSCALL_CALL (gettid);
33 else
34 /* Force load of pd->tid into local variable or register. Otherwise
35 if a thread exits between ESRCH test and tgkill, we might return
36 EINVAL, because pd->tid would be cleared by the kernel. */
37 tid = atomic_forced_read (pd->tid);
39 int val;
40 if (__glibc_likely (tid > 0))
42 pid_t pid = __getpid ();
44 val = INTERNAL_SYSCALL_CALL (tgkill, pid, tid, signo);
45 val = (INTERNAL_SYSCALL_ERROR_P (val)
46 ? INTERNAL_SYSCALL_ERRNO (val) : 0);
48 else
49 val = ESRCH;
51 return val;
54 int
55 __pthread_kill (pthread_t threadid, int signo)
57 /* Disallow sending the signal we use for cancellation, timers,
58 for the setxid implementation. */
59 if (__is_internal_signal (signo))
60 return EINVAL;
62 return __pthread_kill_internal (threadid, signo);
64 /* Some architectures (for instance arm) might pull raise through libgcc, so
65 avoid the symbol version if it ends up being used on ld.so. */
66 #if !IS_IN(rtld)
67 libc_hidden_def (__pthread_kill)
68 versioned_symbol (libc, __pthread_kill, pthread_kill, GLIBC_2_34);
70 # if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_34)
71 compat_symbol (libc, __pthread_kill, pthread_kill, GLIBC_2_0);
72 # endif
73 #endif