]>
Commit | Line | Data |
---|---|---|
6d7e8eda | 1 | /* Copyright (C) 1995-2023 Free Software Foundation, Inc. |
cf20f569 | 2 | This file is part of the GNU C Library. |
cf20f569 UD |
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 | |
59ba27a6 | 15 | License along with the GNU C Library; if not, see |
5a82c748 | 16 | <https://www.gnu.org/licenses/>. */ |
cf20f569 | 17 | |
cf20f569 UD |
18 | #include <sys/sem.h> |
19 | #include <ipc_priv.h> | |
cf20f569 | 20 | #include <sysdep.h> |
38cee35b | 21 | #include <errno.h> |
cf20f569 | 22 | |
eef7913c AZ |
23 | static int |
24 | semtimedop_syscall (int semid, struct sembuf *sops, size_t nsops, | |
25 | const struct __timespec64 *timeout) | |
26 | { | |
27 | #ifdef __NR_semtimedop_time64 | |
28 | return INLINE_SYSCALL_CALL (semtimedop_time64, semid, sops, nsops, timeout); | |
29 | #elif defined __ASSUME_DIRECT_SYSVIPC_SYSCALLS && defined __NR_semtimedop | |
30 | return INLINE_SYSCALL_CALL (semtimedop, semid, sops, nsops, timeout); | |
31 | #else | |
32 | return INLINE_SYSCALL_CALL (ipc, IPCOP_semtimedop, semid, | |
33 | SEMTIMEDOP_IPC_ARGS (nsops, sops, timeout)); | |
34 | #endif | |
35 | } | |
36 | ||
cf20f569 | 37 | /* Perform user-defined atomical operation of array of semaphores. */ |
7c437d37 AZ |
38 | int |
39 | __semtimedop64 (int semid, struct sembuf *sops, size_t nsops, | |
40 | const struct __timespec64 *timeout) | |
41 | { | |
eef7913c AZ |
42 | #ifdef __ASSUME_TIME64_SYSCALLS |
43 | return semtimedop_syscall (semid, sops, nsops, timeout); | |
2deb7793 | 44 | #else |
a9acb7b3 | 45 | bool need_time64 = timeout != NULL && !in_int32_t_range (timeout->tv_sec); |
eef7913c AZ |
46 | if (need_time64) |
47 | { | |
48 | int r = semtimedop_syscall (semid, sops, nsops, timeout); | |
49 | if (r == 0 || errno != ENOSYS) | |
50 | return r; | |
51 | __set_errno (EOVERFLOW); | |
52 | return -1; | |
53 | } | |
7c437d37 AZ |
54 | |
55 | struct timespec ts32, *pts32 = NULL; | |
56 | if (timeout != NULL) | |
57 | { | |
7c437d37 AZ |
58 | ts32 = valid_timespec64_to_timespec (*timeout); |
59 | pts32 = &ts32; | |
60 | } | |
eef7913c AZ |
61 | # ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS |
62 | return INLINE_SYSCALL_CALL (semtimedop, semid, sops, nsops, pts32); | |
7c437d37 | 63 | # else |
eef7913c AZ |
64 | return INLINE_SYSCALL_CALL (ipc, IPCOP_semtimedop, semid, |
65 | SEMTIMEDOP_IPC_ARGS (nsops, sops, pts32)); | |
7c437d37 | 66 | # endif |
eef7913c | 67 | #endif |
7c437d37 AZ |
68 | } |
69 | #if __TIMESIZE != 64 | |
70 | libc_hidden_def (__semtimedop64) | |
cf20f569 UD |
71 | |
72 | int | |
765cdd0b AZ |
73 | __semtimedop (int semid, struct sembuf *sops, size_t nsops, |
74 | const struct timespec *timeout) | |
cf20f569 | 75 | { |
7c437d37 AZ |
76 | struct __timespec64 ts64, *pts64 = NULL; |
77 | if (timeout != NULL) | |
78 | { | |
79 | ts64 = valid_timespec_to_timespec64 (*timeout); | |
80 | pts64 = &ts64; | |
81 | } | |
82 | return __semtimedop64 (semid, sops, nsops, pts64); | |
cf20f569 | 83 | } |
7c437d37 | 84 | #endif |
765cdd0b | 85 | weak_alias (__semtimedop, semtimedop) |