1 /* Copyright (C) 1995-2022 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 <sys/sem.h>
19 #include <ipc_priv.h>
20 #include <sysdep.h>
21 #include <errno.h>
22
23 static int
semtimedop_syscall(int semid,struct sembuf * sops,size_t nsops,const struct __timespec64 * timeout)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
37 /* Perform user-defined atomical operation of array of semaphores. */
38 int
__semtimedop64(int semid,struct sembuf * sops,size_t nsops,const struct __timespec64 * timeout)39 __semtimedop64 (int semid, struct sembuf *sops, size_t nsops,
40 const struct __timespec64 *timeout)
41 {
42 #ifdef __ASSUME_TIME64_SYSCALLS
43 return semtimedop_syscall (semid, sops, nsops, timeout);
44 #else
45 bool need_time64 = timeout != NULL && !in_time_t_range (timeout->tv_sec);
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 }
54
55 struct timespec ts32, *pts32 = NULL;
56 if (timeout != NULL)
57 {
58 ts32 = valid_timespec64_to_timespec (*timeout);
59 pts32 = &ts32;
60 }
61 # ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
62 return INLINE_SYSCALL_CALL (semtimedop, semid, sops, nsops, pts32);
63 # else
64 return INLINE_SYSCALL_CALL (ipc, IPCOP_semtimedop, semid,
65 SEMTIMEDOP_IPC_ARGS (nsops, sops, pts32));
66 # endif
67 #endif
68 }
69 #if __TIMESIZE != 64
libc_hidden_def(__semtimedop64)70 libc_hidden_def (__semtimedop64)
71
72 int
73 __semtimedop (int semid, struct sembuf *sops, size_t nsops,
74 const struct timespec *timeout)
75 {
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);
83 }
84 #endif
85 weak_alias (__semtimedop, semtimedop)
86