| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Dummy stubs used when CONFIG_POSIX_TIMERS=n |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Created by: Nicolas Pitre, July 2016 |
|---|
| 5 | 6 | * 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. |
|---|
| 10 | 7 | */ |
|---|
| 11 | 8 | |
|---|
| 12 | 9 | #include <linux/linkage.h> |
|---|
| .. | .. |
|---|
| 17 | 14 | #include <linux/ktime.h> |
|---|
| 18 | 15 | #include <linux/timekeeping.h> |
|---|
| 19 | 16 | #include <linux/posix-timers.h> |
|---|
| 17 | +#include <linux/time_namespace.h> |
|---|
| 20 | 18 | #include <linux/compat.h> |
|---|
| 21 | 19 | |
|---|
| 22 | 20 | #ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER |
|---|
| .. | .. |
|---|
| 48 | 46 | SYS_NI(clock_adjtime); |
|---|
| 49 | 47 | SYS_NI(getitimer); |
|---|
| 50 | 48 | SYS_NI(setitimer); |
|---|
| 49 | +SYS_NI(clock_adjtime32); |
|---|
| 51 | 50 | #ifdef __ARCH_WANT_SYS_ALARM |
|---|
| 52 | 51 | SYS_NI(alarm); |
|---|
| 53 | 52 | #endif |
|---|
| .. | .. |
|---|
| 79 | 78 | break; |
|---|
| 80 | 79 | case CLOCK_MONOTONIC: |
|---|
| 81 | 80 | ktime_get_ts64(tp); |
|---|
| 81 | + timens_add_monotonic(tp); |
|---|
| 82 | 82 | break; |
|---|
| 83 | 83 | case CLOCK_BOOTTIME: |
|---|
| 84 | 84 | ktime_get_boottime_ts64(tp); |
|---|
| 85 | + timens_add_boottime(tp); |
|---|
| 85 | 86 | break; |
|---|
| 86 | 87 | default: |
|---|
| 87 | 88 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 128 | 129 | struct __kernel_timespec __user *, rmtp) |
|---|
| 129 | 130 | { |
|---|
| 130 | 131 | struct timespec64 t; |
|---|
| 132 | + ktime_t texp; |
|---|
| 131 | 133 | |
|---|
| 132 | 134 | switch (which_clock) { |
|---|
| 133 | 135 | case CLOCK_REALTIME: |
|---|
| .. | .. |
|---|
| 144 | 146 | return -EINVAL; |
|---|
| 145 | 147 | if (flags & TIMER_ABSTIME) |
|---|
| 146 | 148 | rmtp = NULL; |
|---|
| 149 | + current->restart_block.fn = do_no_restart_syscall; |
|---|
| 147 | 150 | current->restart_block.nanosleep.type = rmtp ? TT_NATIVE : TT_NONE; |
|---|
| 148 | 151 | 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 ? |
|---|
| 150 | 156 | HRTIMER_MODE_ABS : HRTIMER_MODE_REL, |
|---|
| 151 | 157 | which_clock); |
|---|
| 152 | 158 | } |
|---|
| 153 | 159 | |
|---|
| 154 | 160 | #ifdef CONFIG_COMPAT |
|---|
| 155 | 161 | 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) |
|---|
| 159 | 165 | COMPAT_SYS_NI(getitimer); |
|---|
| 160 | 166 | COMPAT_SYS_NI(setitimer); |
|---|
| 161 | 167 | #endif |
|---|
| 162 | 168 | |
|---|
| 163 | 169 | #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) |
|---|
| 166 | 175 | { |
|---|
| 167 | 176 | struct timespec64 new_tp; |
|---|
| 168 | 177 | |
|---|
| 169 | 178 | if (which_clock != CLOCK_REALTIME) |
|---|
| 170 | 179 | return -EINVAL; |
|---|
| 171 | | - if (compat_get_timespec64(&new_tp, tp)) |
|---|
| 180 | + if (get_old_timespec32(&new_tp, tp)) |
|---|
| 172 | 181 | return -EFAULT; |
|---|
| 173 | 182 | |
|---|
| 174 | 183 | return do_sys_settimeofday64(&new_tp, NULL); |
|---|
| 175 | 184 | } |
|---|
| 176 | 185 | |
|---|
| 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) |
|---|
| 179 | 188 | { |
|---|
| 180 | 189 | int ret; |
|---|
| 181 | 190 | struct timespec64 kernel_tp; |
|---|
| .. | .. |
|---|
| 184 | 193 | if (ret) |
|---|
| 185 | 194 | return ret; |
|---|
| 186 | 195 | |
|---|
| 187 | | - if (compat_put_timespec64(&kernel_tp, tp)) |
|---|
| 196 | + if (put_old_timespec32(&kernel_tp, tp)) |
|---|
| 188 | 197 | return -EFAULT; |
|---|
| 189 | 198 | return 0; |
|---|
| 190 | 199 | } |
|---|
| 191 | 200 | |
|---|
| 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) |
|---|
| 194 | 203 | { |
|---|
| 195 | 204 | struct timespec64 rtn_tp = { |
|---|
| 196 | 205 | .tv_sec = 0, |
|---|
| .. | .. |
|---|
| 201 | 210 | case CLOCK_REALTIME: |
|---|
| 202 | 211 | case CLOCK_MONOTONIC: |
|---|
| 203 | 212 | case CLOCK_BOOTTIME: |
|---|
| 204 | | - if (compat_put_timespec64(&rtn_tp, tp)) |
|---|
| 213 | + if (put_old_timespec32(&rtn_tp, tp)) |
|---|
| 205 | 214 | return -EFAULT; |
|---|
| 206 | 215 | return 0; |
|---|
| 207 | 216 | default: |
|---|
| .. | .. |
|---|
| 209 | 218 | } |
|---|
| 210 | 219 | } |
|---|
| 211 | 220 | |
|---|
| 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) |
|---|
| 215 | 224 | { |
|---|
| 216 | 225 | struct timespec64 t; |
|---|
| 226 | + ktime_t texp; |
|---|
| 217 | 227 | |
|---|
| 218 | 228 | switch (which_clock) { |
|---|
| 219 | 229 | case CLOCK_REALTIME: |
|---|
| .. | .. |
|---|
| 224 | 234 | return -EINVAL; |
|---|
| 225 | 235 | } |
|---|
| 226 | 236 | |
|---|
| 227 | | - if (compat_get_timespec64(&t, rqtp)) |
|---|
| 237 | + if (get_old_timespec32(&t, rqtp)) |
|---|
| 228 | 238 | return -EFAULT; |
|---|
| 229 | 239 | if (!timespec64_valid(&t)) |
|---|
| 230 | 240 | return -EINVAL; |
|---|
| 231 | 241 | if (flags & TIMER_ABSTIME) |
|---|
| 232 | 242 | rmtp = NULL; |
|---|
| 243 | + current->restart_block.fn = do_no_restart_syscall; |
|---|
| 233 | 244 | current->restart_block.nanosleep.type = rmtp ? TT_COMPAT : TT_NONE; |
|---|
| 234 | 245 | 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 ? |
|---|
| 236 | 250 | HRTIMER_MODE_ABS : HRTIMER_MODE_REL, |
|---|
| 237 | 251 | which_clock); |
|---|
| 238 | 252 | } |
|---|