elf: Fix _dl_debug_vdprintf to work before self-relocation
[glibc.git] / sysdeps / unix / sysv / linux / semtimedop.c
blob4cff1f982a35db655da2eb353811a73919924779
1 /* Copyright (C) 1995-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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/>. */
18 #include <sys/sem.h>
19 #include <ipc_priv.h>
20 #include <sysdep.h>
21 #include <errno.h>
23 static int
24 semtimedop_syscall (int semid, struct sembuf *sops, size_t nsops,
25 const struct __timespec64 *timeout)
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
37 /* Perform user-defined atomic operation of array of semaphores. */
38 int
39 __semtimedop64 (int semid, struct sembuf *sops, size_t nsops,
40 const struct __timespec64 *timeout)
42 #ifdef __ASSUME_TIME64_SYSCALLS
43 return semtimedop_syscall (semid, sops, nsops, timeout);
44 #else
45 bool need_time64 = timeout != NULL && !in_int32_t_range (timeout->tv_sec);
46 if (need_time64)
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;
55 struct timespec ts32, *pts32 = NULL;
56 if (timeout != NULL)
58 ts32 = valid_timespec64_to_timespec (*timeout);
59 pts32 = &ts32;
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
69 #if __TIMESIZE != 64
70 libc_hidden_def (__semtimedop64)
72 int
73 __semtimedop (int semid, struct sembuf *sops, size_t nsops,
74 const struct timespec *timeout)
76 struct __timespec64 ts64, *pts64 = NULL;
77 if (timeout != NULL)
79 ts64 = valid_timespec_to_timespec64 (*timeout);
80 pts64 = &ts64;
82 return __semtimedop64 (semid, sops, nsops, pts64);
84 #endif
85 weak_alias (__semtimedop, semtimedop)