hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/kernel/time/posix-stubs.c
....@@ -1,12 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Dummy stubs used when CONFIG_POSIX_TIMERS=n
34 *
45 * Created by: Nicolas Pitre, July 2016
56 * Copyright: (C) 2016 Linaro Limited
6
- *
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.
107 */
118
129 #include <linux/linkage.h>
....@@ -17,6 +14,7 @@
1714 #include <linux/ktime.h>
1815 #include <linux/timekeeping.h>
1916 #include <linux/posix-timers.h>
17
+#include <linux/time_namespace.h>
2018 #include <linux/compat.h>
2119
2220 #ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER
....@@ -48,6 +46,7 @@
4846 SYS_NI(clock_adjtime);
4947 SYS_NI(getitimer);
5048 SYS_NI(setitimer);
49
+SYS_NI(clock_adjtime32);
5150 #ifdef __ARCH_WANT_SYS_ALARM
5251 SYS_NI(alarm);
5352 #endif
....@@ -79,9 +78,11 @@
7978 break;
8079 case CLOCK_MONOTONIC:
8180 ktime_get_ts64(tp);
81
+ timens_add_monotonic(tp);
8282 break;
8383 case CLOCK_BOOTTIME:
8484 ktime_get_boottime_ts64(tp);
85
+ timens_add_boottime(tp);
8586 break;
8687 default:
8788 return -EINVAL;
....@@ -128,6 +129,7 @@
128129 struct __kernel_timespec __user *, rmtp)
129130 {
130131 struct timespec64 t;
132
+ ktime_t texp;
131133
132134 switch (which_clock) {
133135 case CLOCK_REALTIME:
....@@ -146,36 +148,42 @@
146148 rmtp = NULL;
147149 current->restart_block.nanosleep.type = rmtp ? TT_NATIVE : TT_NONE;
148150 current->restart_block.nanosleep.rmtp = rmtp;
149
- return hrtimer_nanosleep(&t, flags & TIMER_ABSTIME ?
151
+ texp = timespec64_to_ktime(t);
152
+ if (flags & TIMER_ABSTIME)
153
+ texp = timens_ktime_to_host(which_clock, texp);
154
+ return hrtimer_nanosleep(texp, flags & TIMER_ABSTIME ?
150155 HRTIMER_MODE_ABS : HRTIMER_MODE_REL,
151156 which_clock);
152157 }
153158
154159 #ifdef CONFIG_COMPAT
155160 COMPAT_SYS_NI(timer_create);
156
-COMPAT_SYS_NI(clock_adjtime);
157
-COMPAT_SYS_NI(timer_settime);
158
-COMPAT_SYS_NI(timer_gettime);
161
+#endif
162
+
163
+#if defined(CONFIG_COMPAT) || defined(CONFIG_ALPHA)
159164 COMPAT_SYS_NI(getitimer);
160165 COMPAT_SYS_NI(setitimer);
161166 #endif
162167
163168 #ifdef CONFIG_COMPAT_32BIT_TIME
164
-COMPAT_SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
165
- struct compat_timespec __user *, tp)
169
+SYS_NI(timer_settime32);
170
+SYS_NI(timer_gettime32);
171
+
172
+SYSCALL_DEFINE2(clock_settime32, const clockid_t, which_clock,
173
+ struct old_timespec32 __user *, tp)
166174 {
167175 struct timespec64 new_tp;
168176
169177 if (which_clock != CLOCK_REALTIME)
170178 return -EINVAL;
171
- if (compat_get_timespec64(&new_tp, tp))
179
+ if (get_old_timespec32(&new_tp, tp))
172180 return -EFAULT;
173181
174182 return do_sys_settimeofday64(&new_tp, NULL);
175183 }
176184
177
-COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
178
- struct compat_timespec __user *, tp)
185
+SYSCALL_DEFINE2(clock_gettime32, clockid_t, which_clock,
186
+ struct old_timespec32 __user *, tp)
179187 {
180188 int ret;
181189 struct timespec64 kernel_tp;
....@@ -184,13 +192,13 @@
184192 if (ret)
185193 return ret;
186194
187
- if (compat_put_timespec64(&kernel_tp, tp))
195
+ if (put_old_timespec32(&kernel_tp, tp))
188196 return -EFAULT;
189197 return 0;
190198 }
191199
192
-COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
193
- struct compat_timespec __user *, tp)
200
+SYSCALL_DEFINE2(clock_getres_time32, clockid_t, which_clock,
201
+ struct old_timespec32 __user *, tp)
194202 {
195203 struct timespec64 rtn_tp = {
196204 .tv_sec = 0,
....@@ -201,7 +209,7 @@
201209 case CLOCK_REALTIME:
202210 case CLOCK_MONOTONIC:
203211 case CLOCK_BOOTTIME:
204
- if (compat_put_timespec64(&rtn_tp, tp))
212
+ if (put_old_timespec32(&rtn_tp, tp))
205213 return -EFAULT;
206214 return 0;
207215 default:
....@@ -209,11 +217,12 @@
209217 }
210218 }
211219
212
-COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
213
- struct compat_timespec __user *, rqtp,
214
- struct compat_timespec __user *, rmtp)
220
+SYSCALL_DEFINE4(clock_nanosleep_time32, clockid_t, which_clock, int, flags,
221
+ struct old_timespec32 __user *, rqtp,
222
+ struct old_timespec32 __user *, rmtp)
215223 {
216224 struct timespec64 t;
225
+ ktime_t texp;
217226
218227 switch (which_clock) {
219228 case CLOCK_REALTIME:
....@@ -224,7 +233,7 @@
224233 return -EINVAL;
225234 }
226235
227
- if (compat_get_timespec64(&t, rqtp))
236
+ if (get_old_timespec32(&t, rqtp))
228237 return -EFAULT;
229238 if (!timespec64_valid(&t))
230239 return -EINVAL;
....@@ -232,7 +241,10 @@
232241 rmtp = NULL;
233242 current->restart_block.nanosleep.type = rmtp ? TT_COMPAT : TT_NONE;
234243 current->restart_block.nanosleep.compat_rmtp = rmtp;
235
- return hrtimer_nanosleep(&t, flags & TIMER_ABSTIME ?
244
+ texp = timespec64_to_ktime(t);
245
+ if (flags & TIMER_ABSTIME)
246
+ texp = timens_ktime_to_host(which_clock, texp);
247
+ return hrtimer_nanosleep(texp, flags & TIMER_ABSTIME ?
236248 HRTIMER_MODE_ABS : HRTIMER_MODE_REL,
237249 which_clock);
238250 }