]>
Commit | Line | Data |
---|---|---|
d4697bc9 | 1 | /* Copyright (C) 2002-2014 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 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://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> | |
db54f488 | 24 | #include <kernel-features.h> |
76a50749 UD |
25 | |
26 | ||
27 | int | |
09efc3ba | 28 | __pthread_kill (threadid, signo) |
76a50749 UD |
29 | pthread_t threadid; |
30 | int signo; | |
31 | { | |
32 | struct pthread *pd = (struct pthread *) threadid; | |
33 | ||
8c2e9a29 | 34 | /* Make sure the descriptor is valid. */ |
fc242bef UD |
35 | if (DEBUGGING_P && INVALID_TD_P (pd)) |
36 | /* Not a valid thread handle. */ | |
37 | return ESRCH; | |
38 | ||
33c6de58 | 39 | /* Force load of pd->tid into local variable or register. Otherwise |
fc242bef UD |
40 | if a thread exits between ESRCH test and tgkill, we might return |
41 | EINVAL, because pd->tid would be cleared by the kernel. */ | |
42 | pid_t tid = atomic_forced_read (pd->tid); | |
a1ffb40e | 43 | if (__glibc_unlikely (tid <= 0)) |
8c2e9a29 UD |
44 | /* Not a valid thread handle. */ |
45 | return ESRCH; | |
46 | ||
ded5b9b7 | 47 | /* Disallow sending the signal we use for cancellation, timers, |
53b4fed6 UD |
48 | for the setxid implementation. */ |
49 | if (signo == SIGCANCEL || signo == SIGTIMER || signo == SIGSETXID) | |
e814f748 UD |
50 | return EINVAL; |
51 | ||
76a50749 | 52 | /* We have a special syscall to do the work. */ |
e798b60f UD |
53 | INTERNAL_SYSCALL_DECL (err); |
54 | ||
c0ecb80a UD |
55 | /* One comment: The PID field in the TCB can temporarily be changed |
56 | (in fork). But this must not affect this code here. Since this | |
57 | function would have to be called while the thread is executing | |
58 | fork, it would have to happen in a signal handler. But this is | |
59 | no allowed, pthread_kill is not guaranteed to be async-safe. */ | |
db54f488 | 60 | int val; |
db54f488 | 61 | val = INTERNAL_SYSCALL (tgkill, err, 3, THREAD_GETMEM (THREAD_SELF, pid), |
fc242bef | 62 | tid, signo); |
e798b60f UD |
63 | |
64 | return (INTERNAL_SYSCALL_ERROR_P (val, err) | |
65 | ? INTERNAL_SYSCALL_ERRNO (val, err) : 0); | |
76a50749 | 66 | } |
09efc3ba | 67 | strong_alias (__pthread_kill, pthread_kill) |