1 | /* Copyright (C) 1995-2021 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. |
3 | Contributed by Ulrich Drepper <drepper@cygnus.com>, August 1995. |
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 <sys/sem.h> |
20 | #include <ipc_priv.h> |
21 | #include <sysdep.h> |
22 | #include <errno.h> |
23 | |
24 | static int |
25 | semtimedop_syscall (int semid, struct sembuf *sops, size_t nsops, |
26 | const struct __timespec64 *timeout) |
27 | { |
28 | #ifdef __NR_semtimedop_time64 |
29 | return INLINE_SYSCALL_CALL (semtimedop_time64, semid, sops, nsops, timeout); |
30 | #elif defined __ASSUME_DIRECT_SYSVIPC_SYSCALLS && defined __NR_semtimedop |
31 | return INLINE_SYSCALL_CALL (semtimedop, semid, sops, nsops, timeout); |
32 | #else |
33 | return INLINE_SYSCALL_CALL (ipc, IPCOP_semtimedop, semid, |
34 | SEMTIMEDOP_IPC_ARGS (nsops, sops, timeout)); |
35 | #endif |
36 | } |
37 | |
38 | /* Perform user-defined atomical operation of array of semaphores. */ |
39 | int |
40 | __semtimedop64 (int semid, struct sembuf *sops, size_t nsops, |
41 | const struct __timespec64 *timeout) |
42 | { |
43 | #ifdef __ASSUME_TIME64_SYSCALLS |
44 | return semtimedop_syscall (semid, sops, nsops, timeout); |
45 | #else |
46 | bool need_time64 = timeout != NULL && !in_time_t_range (timeout->tv_sec); |
47 | if (need_time64) |
48 | { |
49 | int r = semtimedop_syscall (semid, sops, nsops, timeout); |
50 | if (r == 0 || errno != ENOSYS) |
51 | return r; |
52 | __set_errno (EOVERFLOW); |
53 | return -1; |
54 | } |
55 | |
56 | struct timespec ts32, *pts32 = NULL; |
57 | if (timeout != NULL) |
58 | { |
59 | ts32 = valid_timespec64_to_timespec (*timeout); |
60 | pts32 = &ts32; |
61 | } |
62 | # ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS |
63 | return INLINE_SYSCALL_CALL (semtimedop, semid, sops, nsops, pts32); |
64 | # else |
65 | return INLINE_SYSCALL_CALL (ipc, IPCOP_semtimedop, semid, |
66 | SEMTIMEDOP_IPC_ARGS (nsops, sops, pts32)); |
67 | # endif |
68 | #endif |
69 | } |
70 | #if __TIMESIZE != 64 |
71 | libc_hidden_def (__semtimedop64) |
72 | |
73 | int |
74 | __semtimedop (int semid, struct sembuf *sops, size_t nsops, |
75 | const struct timespec *timeout) |
76 | { |
77 | struct __timespec64 ts64, *pts64 = NULL; |
78 | if (timeout != NULL) |
79 | { |
80 | ts64 = valid_timespec_to_timespec64 (*timeout); |
81 | pts64 = &ts64; |
82 | } |
83 | return __semtimedop64 (semid, sops, nsops, pts64); |
84 | } |
85 | #endif |
86 | weak_alias (__semtimedop, semtimedop) |
87 | |