]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/pthread_kill.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / pthread_kill.c
CommitLineData
2b778ceb 1/* Copyright (C) 2002-2021 Free Software Foundation, Inc.
76a50749
UD
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
4
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.
9
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.
14
15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
76a50749
UD
18
19#include <errno.h>
20#include <signal.h>
21#include <pthreadP.h>
22#include <tls.h>
23#include <sysdep.h>
c579f48e 24#include <unistd.h>
76a50749
UD
25
26
27int
14bb4e57 28__pthread_kill (pthread_t threadid, int signo)
76a50749
UD
29{
30 struct pthread *pd = (struct pthread *) threadid;
31
8c2e9a29 32 /* Make sure the descriptor is valid. */
fc242bef
UD
33 if (DEBUGGING_P && INVALID_TD_P (pd))
34 /* Not a valid thread handle. */
35 return ESRCH;
36
33c6de58 37 /* Force load of pd->tid into local variable or register. Otherwise
fc242bef
UD
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);
a1ffb40e 41 if (__glibc_unlikely (tid <= 0))
8c2e9a29
UD
42 /* Not a valid thread handle. */
43 return ESRCH;
44
ded5b9b7 45 /* Disallow sending the signal we use for cancellation, timers,
53b4fed6
UD
46 for the setxid implementation. */
47 if (signo == SIGCANCEL || signo == SIGTIMER || signo == SIGSETXID)
e814f748
UD
48 return EINVAL;
49
76a50749 50 /* We have a special syscall to do the work. */
c579f48e 51 pid_t pid = __getpid ();
e798b60f 52
bc2eb932
AZ
53 int val = INTERNAL_SYSCALL_CALL (tgkill, pid, tid, signo);
54 return (INTERNAL_SYSCALL_ERROR_P (val)
55 ? INTERNAL_SYSCALL_ERRNO (val) : 0);
76a50749 56}
09efc3ba 57strong_alias (__pthread_kill, pthread_kill)