hc
2024-10-09 05e59e5fb0064c97a1c10921ecd549f2d4a58565
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:
....@@ -144,38 +146,45 @@
144146 return -EINVAL;
145147 if (flags & TIMER_ABSTIME)
146148 rmtp = NULL;
149
+ current->restart_block.fn = do_no_restart_syscall;
147150 current->restart_block.nanosleep.type = rmtp ? TT_NATIVE : TT_NONE;
148151 current->restart_block.nanosleep.rmtp = rmtp;
149
- return hrtimer_nanosleep(&t, flags & TIMER_ABSTIME ?
152
+ texp = timespec64_to_ktime(t);
153
+ if (flags & TIMER_ABSTIME)
154
+ texp = timens_ktime_to_host(which_clock, texp);
155
+ return hrtimer_nanosleep(texp, flags & TIMER_ABSTIME ?
150156 HRTIMER_MODE_ABS : HRTIMER_MODE_REL,
151157 which_clock);
152158 }
153159
154160 #ifdef CONFIG_COMPAT
155161 COMPAT_SYS_NI(timer_create);
156
-COMPAT_SYS_NI(clock_adjtime);
157
-COMPAT_SYS_NI(timer_settime);
158
-COMPAT_SYS_NI(timer_gettime);
162
+#endif
163
+
164
+#if defined(CONFIG_COMPAT) || defined(CONFIG_ALPHA)
159165 COMPAT_SYS_NI(getitimer);
160166 COMPAT_SYS_NI(setitimer);
161167 #endif
162168
163169 #ifdef CONFIG_COMPAT_32BIT_TIME
164
-COMPAT_SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
165
- struct compat_timespec __user *, tp)
170
+SYS_NI(timer_settime32);
171
+SYS_NI(timer_gettime32);
172
+
173
+SYSCALL_DEFINE2(clock_settime32, const clockid_t, which_clock,
174
+ struct old_timespec32 __user *, tp)
166175 {
167176 struct timespec64 new_tp;
168177
169178 if (which_clock != CLOCK_REALTIME)
170179 return -EINVAL;
171
- if (compat_get_timespec64(&new_tp, tp))
180
+ if (get_old_timespec32(&new_tp, tp))
172181 return -EFAULT;
173182
174183 return do_sys_settimeofday64(&new_tp, NULL);
175184 }
176185
177
-COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
178
- struct compat_timespec __user *, tp)
186
+SYSCALL_DEFINE2(clock_gettime32, clockid_t, which_clock,
187
+ struct old_timespec32 __user *, tp)
179188 {
180189 int ret;
181190 struct timespec64 kernel_tp;
....@@ -184,13 +193,13 @@
184193 if (ret)
185194 return ret;
186195
187
- if (compat_put_timespec64(&kernel_tp, tp))
196
+ if (put_old_timespec32(&kernel_tp, tp))
188197 return -EFAULT;
189198 return 0;
190199 }
191200
192
-COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
193
- struct compat_timespec __user *, tp)
201
+SYSCALL_DEFINE2(clock_getres_time32, clockid_t, which_clock,
202
+ struct old_timespec32 __user *, tp)
194203 {
195204 struct timespec64 rtn_tp = {
196205 .tv_sec = 0,
....@@ -201,7 +210,7 @@
201210 case CLOCK_REALTIME:
202211 case CLOCK_MONOTONIC:
203212 case CLOCK_BOOTTIME:
204
- if (compat_put_timespec64(&rtn_tp, tp))
213
+ if (put_old_timespec32(&rtn_tp, tp))
205214 return -EFAULT;
206215 return 0;
207216 default:
....@@ -209,11 +218,12 @@
209218 }
210219 }
211220
212
-COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
213
- struct compat_timespec __user *, rqtp,
214
- struct compat_timespec __user *, rmtp)
221
+SYSCALL_DEFINE4(clock_nanosleep_time32, clockid_t, which_clock, int, flags,
222
+ struct old_timespec32 __user *, rqtp,
223
+ struct old_timespec32 __user *, rmtp)
215224 {
216225 struct timespec64 t;
226
+ ktime_t texp;
217227
218228 switch (which_clock) {
219229 case CLOCK_REALTIME:
....@@ -224,15 +234,19 @@
224234 return -EINVAL;
225235 }
226236
227
- if (compat_get_timespec64(&t, rqtp))
237
+ if (get_old_timespec32(&t, rqtp))
228238 return -EFAULT;
229239 if (!timespec64_valid(&t))
230240 return -EINVAL;
231241 if (flags & TIMER_ABSTIME)
232242 rmtp = NULL;
243
+ current->restart_block.fn = do_no_restart_syscall;
233244 current->restart_block.nanosleep.type = rmtp ? TT_COMPAT : TT_NONE;
234245 current->restart_block.nanosleep.compat_rmtp = rmtp;
235
- return hrtimer_nanosleep(&t, flags & TIMER_ABSTIME ?
246
+ texp = timespec64_to_ktime(t);
247
+ if (flags & TIMER_ABSTIME)
248
+ texp = timens_ktime_to_host(which_clock, texp);
249
+ return hrtimer_nanosleep(texp, flags & TIMER_ABSTIME ?
236250 HRTIMER_MODE_ABS : HRTIMER_MODE_REL,
237251 which_clock);
238252 }