1/* Copyright (C) 2003-2021 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
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 License as
7 published by the Free Software Foundation; either version 2.1 of the
8 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; see the file COPYING.LIB. If
17 not, see <https://www.gnu.org/licenses/>. */
18
19#include <errno.h>
20#include <stdlib.h>
21#include <time.h>
22#include <sysdep.h>
23#include <kernel-features.h>
24#include "kernel-posix-timers.h"
25#include <shlib-compat.h>
26
27#if !TIMER_T_WAS_INT_COMPAT
28int
29___timer_settime64 (timer_t timerid, int flags,
30 const struct __itimerspec64 *value,
31 struct __itimerspec64 *ovalue)
32{
33 kernel_timer_t ktimerid = timerid_to_kernel_timer (timerid);
34
35# ifdef __ASSUME_TIME64_SYSCALLS
36# ifndef __NR_timer_settime64
37# define __NR_timer_settime64 __NR_timer_settime
38# endif
39 return INLINE_SYSCALL_CALL (timer_settime64, ktimerid, flags, value,
40 ovalue);
41# else
42# ifdef __NR_timer_settime64
43 int ret = INLINE_SYSCALL_CALL (timer_settime64, ktimerid, flags, value,
44 ovalue);
45 if (ret == 0 || errno != ENOSYS)
46 return ret;
47# endif
48 struct itimerspec its32, oits32;
49
50 if (! in_time_t_range ((value->it_value).tv_sec)
51 || ! in_time_t_range ((value->it_interval).tv_sec))
52 {
53 __set_errno (EOVERFLOW);
54 return -1;
55 }
56
57 its32.it_interval = valid_timespec64_to_timespec (value->it_interval);
58 its32.it_value = valid_timespec64_to_timespec (value->it_value);
59
60 int retval = INLINE_SYSCALL_CALL (timer_settime, ktimerid, flags,
61 &its32, ovalue ? &oits32 : NULL);
62 if (retval == 0 && ovalue)
63 {
64 ovalue->it_interval = valid_timespec_to_timespec64 (oits32.it_interval);
65 ovalue->it_value = valid_timespec_to_timespec64 (oits32.it_value);
66 }
67
68 return retval;
69# endif
70}
71
72# if __TIMESIZE == 64
73versioned_symbol (libc, ___timer_settime64, timer_settime, GLIBC_2_34);
74# if OTHER_SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_34)
75compat_symbol (librt, ___timer_settime64, timer_settime, GLIBC_2_2);
76# endif
77
78#else /* __TIMESIZE != 64 */
79libc_hidden_ver (___timer_settime64, __timer_settime64)
80versioned_symbol (libc, ___timer_settime64, __timer_settime64, GLIBC_2_34);
81
82int
83__timer_settime (timer_t timerid, int flags, const struct itimerspec *value,
84 struct itimerspec *ovalue)
85{
86 struct __itimerspec64 its64, oits64;
87 int retval;
88
89 its64.it_interval = valid_timespec_to_timespec64 (value->it_interval);
90 its64.it_value = valid_timespec_to_timespec64 (value->it_value);
91
92 retval = __timer_settime64 (timerid, flags, &its64, ovalue ? &oits64 : NULL);
93 if (retval == 0 && ovalue)
94 {
95 ovalue->it_interval = valid_timespec64_to_timespec (oits64.it_interval);
96 ovalue->it_value = valid_timespec64_to_timespec (oits64.it_value);
97 }
98
99 return retval;
100}
101versioned_symbol (libc, __timer_settime, timer_settime, GLIBC_2_34);
102
103# if OTHER_SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_34)
104compat_symbol (librt, __timer_settime, timer_settime, GLIBC_2_2);
105# endif
106# endif /* __TIMESIZE != 64 */
107
108#else /* TIMER_T_WAS_INT_COMPAT */
109
110extern __typeof (timer_settime) __timer_settime_new;
111libc_hidden_proto (__timer_settime_new)
112
113int
114___timer_settime_new (timer_t timerid, int flags,
115 const struct itimerspec *value,
116 struct itimerspec *ovalue)
117{
118 kernel_timer_t ktimerid = timerid_to_kernel_timer (timerid);
119
120 return INLINE_SYSCALL_CALL (timer_settime, ktimerid, flags, value, ovalue);
121}
122versioned_symbol (libc, ___timer_settime_new, timer_settime, GLIBC_2_34);
123libc_hidden_ver (___timer_settime_new, __timer_settime_new)
124
125# if OTHER_SHLIB_COMPAT (librt, GLIBC_2_3_3, GLIBC_2_34)
126compat_symbol (librt, ___timer_settime_new, timer_settime, GLIBC_2_3_3);
127# endif
128
129# if OTHER_SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_3_3)
130int
131__timer_settime_old (int timerid, int flags, const struct itimerspec *value,
132 struct itimerspec *ovalue)
133{
134 return __timer_settime_new (__timer_compat_list[timerid], flags,
135 value, ovalue);
136}
137compat_symbol (librt, __timer_settime_old, timer_settime, GLIBC_2_2);
138# endif
139
140#endif /* TIMER_T_WAS_INT_COMPAT */
141