]>
Commit | Line | Data |
---|---|---|
6d7e8eda | 1 | /* Copyright (C) 2009-2023 Free Software Foundation, Inc. |
8badf496 RM |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
5 | modify it under the terms of the GNU Lesser General Public | |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
8 | ||
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
15 | License along with the GNU C Library; if not, see | |
5a82c748 | 16 | <https://www.gnu.org/licenses/>. */ |
8badf496 RM |
17 | |
18 | #include <errno.h> | |
19 | #include <signal.h> | |
5f717849 FW |
20 | #include <string.h> |
21 | #include <unistd.h> | |
8badf496 | 22 | #include <pthreadP.h> |
5f717849 FW |
23 | #include <tls.h> |
24 | #include <sysdep.h> | |
2d53566e | 25 | #include <shlib-compat.h> |
8badf496 RM |
26 | |
27 | int | |
2d53566e | 28 | __pthread_sigqueue (pthread_t threadid, int signo, const union sigval value) |
8badf496 | 29 | { |
5f717849 | 30 | #ifdef __NR_rt_tgsigqueueinfo |
8badf496 RM |
31 | struct pthread *pd = (struct pthread *) threadid; |
32 | ||
5f717849 FW |
33 | /* Force load of pd->tid into local variable or register. Otherwise |
34 | if a thread exits between ESRCH test and tgkill, we might return | |
35 | EINVAL, because pd->tid would be cleared by the kernel. */ | |
36 | pid_t tid = atomic_forced_read (pd->tid); | |
37 | if (__glibc_unlikely (tid <= 0)) | |
38 | /* Not a valid thread handle. */ | |
39 | return ESRCH; | |
40 | ||
41 | /* Disallow sending the signal we use for cancellation, timers, | |
42 | for the setxid implementation. */ | |
43 | if (signo == SIGCANCEL || signo == SIGTIMER || signo == SIGSETXID) | |
44 | return EINVAL; | |
45 | ||
46 | pid_t pid = getpid (); | |
47 | ||
48 | /* Set up the siginfo_t structure. */ | |
49 | siginfo_t info; | |
50 | memset (&info, '\0', sizeof (siginfo_t)); | |
51 | info.si_signo = signo; | |
52 | info.si_code = SI_QUEUE; | |
53 | info.si_pid = pid; | |
2d53566e | 54 | info.si_uid = __getuid (); |
5f717849 FW |
55 | info.si_value = value; |
56 | ||
57 | /* We have a special syscall to do the work. */ | |
58 | int val = INTERNAL_SYSCALL_CALL (rt_tgsigqueueinfo, pid, tid, signo, | |
59 | &info); | |
60 | return (INTERNAL_SYSCALL_ERROR_P (val) | |
61 | ? INTERNAL_SYSCALL_ERRNO (val) : 0); | |
62 | #else | |
8badf496 | 63 | return ENOSYS; |
5f717849 | 64 | #endif |
8badf496 | 65 | } |
2d53566e FW |
66 | versioned_symbol (libc, __pthread_sigqueue, pthread_sigqueue, GLIBC_2_34); |
67 | ||
68 | #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_11, GLIBC_2_34) | |
69 | compat_symbol (libpthread, __pthread_sigqueue, pthread_sigqueue, GLIBC_2_11); | |
70 | #endif |