1 | /* Copyright (C) 2009-2021 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. |
3 | Contributed by Ulrich Drepper <drepper@redhat.com>, 2009. |
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 |
16 | License along with the GNU C Library; if not, see |
17 | <https://www.gnu.org/licenses/>. */ |
18 | |
19 | #include <errno.h> |
20 | #include <signal.h> |
21 | #include <string.h> |
22 | #include <unistd.h> |
23 | #include <pthreadP.h> |
24 | #include <tls.h> |
25 | #include <sysdep.h> |
26 | #include <shlib-compat.h> |
27 | |
28 | int |
29 | __pthread_sigqueue (pthread_t threadid, int signo, const union sigval value) |
30 | { |
31 | #ifdef __NR_rt_tgsigqueueinfo |
32 | struct pthread *pd = (struct pthread *) threadid; |
33 | |
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 | pid_t tid = atomic_forced_read (pd->tid); |
38 | if (__glibc_unlikely (tid <= 0)) |
39 | /* Not a valid thread handle. */ |
40 | return ESRCH; |
41 | |
42 | /* Disallow sending the signal we use for cancellation, timers, |
43 | for the setxid implementation. */ |
44 | if (signo == SIGCANCEL || signo == SIGTIMER || signo == SIGSETXID) |
45 | return EINVAL; |
46 | |
47 | pid_t pid = getpid (); |
48 | |
49 | /* Set up the siginfo_t structure. */ |
50 | siginfo_t info; |
51 | memset (&info, '\0', sizeof (siginfo_t)); |
52 | info.si_signo = signo; |
53 | info.si_code = SI_QUEUE; |
54 | info.si_pid = pid; |
55 | info.si_uid = __getuid (); |
56 | info.si_value = value; |
57 | |
58 | /* We have a special syscall to do the work. */ |
59 | int val = INTERNAL_SYSCALL_CALL (rt_tgsigqueueinfo, pid, tid, signo, |
60 | &info); |
61 | return (INTERNAL_SYSCALL_ERROR_P (val) |
62 | ? INTERNAL_SYSCALL_ERRNO (val) : 0); |
63 | #else |
64 | return ENOSYS; |
65 | #endif |
66 | } |
67 | versioned_symbol (libc, __pthread_sigqueue, pthread_sigqueue, GLIBC_2_34); |
68 | |
69 | #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_11, GLIBC_2_34) |
70 | compat_symbol (libpthread, __pthread_sigqueue, pthread_sigqueue, GLIBC_2_11); |
71 | #endif |
72 | |