1 // SPDX-License-Identifier: GPL-2.0
3 * Dummy stubs used when CONFIG_POSIX_TIMERS=n
5 * Created by: Nicolas Pitre, July 2016
6 * Copyright: (C) 2016 Linaro Limited
9 #include <linux/linkage.h>
10 #include <linux/kernel.h>
11 #include <linux/sched.h>
12 #include <linux/errno.h>
13 #include <linux/syscalls.h>
14 #include <linux/ktime.h>
15 #include <linux/timekeeping.h>
16 #include <linux/posix-timers.h>
17 #include <linux/time_namespace.h>
18 #include <linux/compat.h>
21 * We preserve minimal support for CLOCK_REALTIME and CLOCK_MONOTONIC
22 * as it is easy to remain compatible with little code. CLOCK_BOOTTIME
23 * is also included for convenience as at least systemd uses it.
26 SYSCALL_DEFINE2(clock_settime
, const clockid_t
, which_clock
,
27 const struct __kernel_timespec __user
*, tp
)
29 struct timespec64 new_tp
;
31 if (which_clock
!= CLOCK_REALTIME
)
33 if (get_timespec64(&new_tp
, tp
))
36 return do_sys_settimeofday64(&new_tp
, NULL
);
39 static int do_clock_gettime(clockid_t which_clock
, struct timespec64
*tp
)
41 switch (which_clock
) {
43 ktime_get_real_ts64(tp
);
47 timens_add_monotonic(tp
);
50 ktime_get_boottime_ts64(tp
);
51 timens_add_boottime(tp
);
60 SYSCALL_DEFINE2(clock_gettime
, const clockid_t
, which_clock
,
61 struct __kernel_timespec __user
*, tp
)
64 struct timespec64 kernel_tp
;
66 ret
= do_clock_gettime(which_clock
, &kernel_tp
);
70 if (put_timespec64(&kernel_tp
, tp
))
75 SYSCALL_DEFINE2(clock_getres
, const clockid_t
, which_clock
, struct __kernel_timespec __user
*, tp
)
77 struct timespec64 rtn_tp
= {
79 .tv_nsec
= hrtimer_resolution
,
82 switch (which_clock
) {
86 if (put_timespec64(&rtn_tp
, tp
))
94 SYSCALL_DEFINE4(clock_nanosleep
, const clockid_t
, which_clock
, int, flags
,
95 const struct __kernel_timespec __user
*, rqtp
,
96 struct __kernel_timespec __user
*, rmtp
)
101 switch (which_clock
) {
103 case CLOCK_MONOTONIC
:
110 if (get_timespec64(&t
, rqtp
))
112 if (!timespec64_valid(&t
))
114 if (flags
& TIMER_ABSTIME
)
116 current
->restart_block
.fn
= do_no_restart_syscall
;
117 current
->restart_block
.nanosleep
.type
= rmtp
? TT_NATIVE
: TT_NONE
;
118 current
->restart_block
.nanosleep
.rmtp
= rmtp
;
119 texp
= timespec64_to_ktime(t
);
120 if (flags
& TIMER_ABSTIME
)
121 texp
= timens_ktime_to_host(which_clock
, texp
);
122 return hrtimer_nanosleep(texp
, flags
& TIMER_ABSTIME
?
123 HRTIMER_MODE_ABS
: HRTIMER_MODE_REL
,
127 #ifdef CONFIG_COMPAT_32BIT_TIME
129 SYSCALL_DEFINE2(clock_settime32
, const clockid_t
, which_clock
,
130 struct old_timespec32 __user
*, tp
)
132 struct timespec64 new_tp
;
134 if (which_clock
!= CLOCK_REALTIME
)
136 if (get_old_timespec32(&new_tp
, tp
))
139 return do_sys_settimeofday64(&new_tp
, NULL
);
142 SYSCALL_DEFINE2(clock_gettime32
, clockid_t
, which_clock
,
143 struct old_timespec32 __user
*, tp
)
146 struct timespec64 kernel_tp
;
148 ret
= do_clock_gettime(which_clock
, &kernel_tp
);
152 if (put_old_timespec32(&kernel_tp
, tp
))
157 SYSCALL_DEFINE2(clock_getres_time32
, clockid_t
, which_clock
,
158 struct old_timespec32 __user
*, tp
)
160 struct timespec64 rtn_tp
= {
162 .tv_nsec
= hrtimer_resolution
,
165 switch (which_clock
) {
167 case CLOCK_MONOTONIC
:
169 if (put_old_timespec32(&rtn_tp
, tp
))
177 SYSCALL_DEFINE4(clock_nanosleep_time32
, clockid_t
, which_clock
, int, flags
,
178 struct old_timespec32 __user
*, rqtp
,
179 struct old_timespec32 __user
*, rmtp
)
184 switch (which_clock
) {
186 case CLOCK_MONOTONIC
:
193 if (get_old_timespec32(&t
, rqtp
))
195 if (!timespec64_valid(&t
))
197 if (flags
& TIMER_ABSTIME
)
199 current
->restart_block
.fn
= do_no_restart_syscall
;
200 current
->restart_block
.nanosleep
.type
= rmtp
? TT_COMPAT
: TT_NONE
;
201 current
->restart_block
.nanosleep
.compat_rmtp
= rmtp
;
202 texp
= timespec64_to_ktime(t
);
203 if (flags
& TIMER_ABSTIME
)
204 texp
= timens_ktime_to_host(which_clock
, texp
);
205 return hrtimer_nanosleep(texp
, flags
& TIMER_ABSTIME
?
206 HRTIMER_MODE_ABS
: HRTIMER_MODE_REL
,