1 | /* Copyright (C) 1997-2021 Free Software Foundation, Inc. |
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 |
16 | <https://www.gnu.org/licenses/>. */ |
17 | |
18 | #include <signal.h> |
19 | #include <sysdep.h> |
20 | |
21 | int |
22 | __sigtimedwait64 (const sigset_t *set, siginfo_t *info, |
23 | const struct __timespec64 *timeout) |
24 | { |
25 | #ifndef __NR_rt_sigtimedwait_time64 |
26 | # define __NR_rt_sigtimedwait_time64 __NR_rt_sigtimedwait |
27 | #endif |
28 | int result = SYSCALL_CANCEL (rt_sigtimedwait_time64, set, info, timeout, |
29 | __NSIG_BYTES); |
30 | |
31 | #ifndef __ASSUME_TIME64_SYSCALLS |
32 | if (result != 0 && errno == ENOSYS) |
33 | { |
34 | struct timespec ts32, *pts32 = NULL; |
35 | if (timeout != NULL) |
36 | { |
37 | if (! in_time_t_range (timeout->tv_sec)) |
38 | { |
39 | __set_errno (EINVAL); |
40 | return -1; |
41 | } |
42 | ts32 = valid_timespec64_to_timespec (*timeout); |
43 | pts32 = &ts32; |
44 | } |
45 | result = SYSCALL_CANCEL (rt_sigtimedwait, set, info, pts32, |
46 | __NSIG_BYTES); |
47 | } |
48 | #endif |
49 | |
50 | /* The kernel generates a SI_TKILL code in si_code in case tkill is |
51 | used. tkill is transparently used in raise(). Since having |
52 | SI_TKILL as a code is useful in general we fold the results |
53 | here. */ |
54 | if (result != -1 && info != NULL && info->si_code == SI_TKILL) |
55 | info->si_code = SI_USER; |
56 | |
57 | return result; |
58 | } |
59 | #if __TIMESIZE != 64 |
60 | libc_hidden_def (__sigtimedwait64) |
61 | |
62 | int |
63 | __sigtimedwait (const sigset_t *set, siginfo_t *info, |
64 | const struct timespec *timeout) |
65 | { |
66 | struct __timespec64 ts64, *pts64 = NULL; |
67 | if (timeout != NULL) |
68 | { |
69 | ts64 = valid_timespec_to_timespec64 (*timeout); |
70 | pts64 = &ts64; |
71 | } |
72 | return __sigtimedwait64 (set, info, pts64); |
73 | } |
74 | #endif |
75 | libc_hidden_def (__sigtimedwait) |
76 | weak_alias (__sigtimedwait, sigtimedwait) |
77 | |