2 * Dummy stubs used when CONFIG_POSIX_TIMERS=n
4 * Created by: Nicolas Pitre, July 2016
5 * Copyright: (C) 2016 Linaro Limited
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/linkage.h>
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
15 #include <linux/errno.h>
16 #include <linux/syscalls.h>
17 #include <linux/ktime.h>
18 #include <linux/timekeeping.h>
19 #include <linux/posix-timers.h>
21 asmlinkage long sys_ni_posix_timers(void)
23 pr_err_once("process %d (%s) attempted a POSIX timer syscall "
24 "while CONFIG_POSIX_TIMERS is not set\n",
25 current->pid, current->comm);
29 #define SYS_NI(name) SYSCALL_ALIAS(sys_##name, sys_ni_posix_timers)
32 SYS_NI(timer_gettime);
33 SYS_NI(timer_getoverrun);
34 SYS_NI(timer_settime);
36 SYS_NI(clock_adjtime);
39 #ifdef __ARCH_WANT_SYS_ALARM
44 * We preserve minimal support for CLOCK_REALTIME and CLOCK_MONOTONIC
45 * as it is easy to remain compatible with little code. CLOCK_BOOTTIME
46 * is also included for convenience as at least systemd uses it.
49 SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
50 const struct timespec __user *, tp)
52 struct timespec64 new_tp64;
53 struct timespec new_tp;
55 if (which_clock != CLOCK_REALTIME)
57 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
60 new_tp64 = timespec_to_timespec64(new_tp);
61 return do_sys_settimeofday64(&new_tp64, NULL);
64 SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock,
65 struct timespec __user *,tp)
67 struct timespec64 kernel_tp64;
68 struct timespec kernel_tp;
70 switch (which_clock) {
71 case CLOCK_REALTIME: ktime_get_real_ts64(&kernel_tp64); break;
72 case CLOCK_MONOTONIC: ktime_get_ts64(&kernel_tp64); break;
73 case CLOCK_BOOTTIME: get_monotonic_boottime64(&kernel_tp64); break;
74 default: return -EINVAL;
77 kernel_tp = timespec64_to_timespec(kernel_tp64);
78 if (copy_to_user(tp, &kernel_tp, sizeof (kernel_tp)))
83 SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, struct timespec __user *, tp)
85 struct timespec rtn_tp = {
87 .tv_nsec = hrtimer_resolution,
90 switch (which_clock) {
94 if (copy_to_user(tp, &rtn_tp, sizeof(rtn_tp)))
102 SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags,
103 const struct timespec __user *, rqtp,
104 struct timespec __user *, rmtp)
106 struct timespec64 t64;
109 switch (which_clock) {
111 case CLOCK_MONOTONIC:
113 if (copy_from_user(&t, rqtp, sizeof (struct timespec)))
115 t64 = timespec_to_timespec64(t);
116 if (!timespec64_valid(&t64))
118 return hrtimer_nanosleep(&t64, rmtp, flags & TIMER_ABSTIME ?
119 HRTIMER_MODE_ABS : HRTIMER_MODE_REL,
127 long clock_nanosleep_restart(struct restart_block *restart_block)
129 return hrtimer_nanosleep_restart(restart_block);