| .. | .. | 
|---|
 | 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: | 
|---|
| .. | .. | 
|---|
| 146 | 148 |  		rmtp = NULL; | 
|---|
| 147 | 149 |  	current->restart_block.nanosleep.type = rmtp ? TT_NATIVE : TT_NONE; | 
|---|
| 148 | 150 |  	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 ?  | 
|---|
| 150 | 155 |  				 HRTIMER_MODE_ABS : HRTIMER_MODE_REL, | 
|---|
| 151 | 156 |  				 which_clock); | 
|---|
| 152 | 157 |  } | 
|---|
| 153 | 158 |   | 
|---|
| 154 | 159 |  #ifdef CONFIG_COMPAT | 
|---|
| 155 | 160 |  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)  | 
|---|
| 159 | 164 |  COMPAT_SYS_NI(getitimer); | 
|---|
| 160 | 165 |  COMPAT_SYS_NI(setitimer); | 
|---|
| 161 | 166 |  #endif | 
|---|
| 162 | 167 |   | 
|---|
| 163 | 168 |  #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)  | 
|---|
| 166 | 174 |  { | 
|---|
| 167 | 175 |  	struct timespec64 new_tp; | 
|---|
| 168 | 176 |   | 
|---|
| 169 | 177 |  	if (which_clock != CLOCK_REALTIME) | 
|---|
| 170 | 178 |  		return -EINVAL; | 
|---|
| 171 |  | -	if (compat_get_timespec64(&new_tp, tp))  | 
|---|
 | 179 | +	if (get_old_timespec32(&new_tp, tp))  | 
|---|
| 172 | 180 |  		return -EFAULT; | 
|---|
| 173 | 181 |   | 
|---|
| 174 | 182 |  	return do_sys_settimeofday64(&new_tp, NULL); | 
|---|
| 175 | 183 |  } | 
|---|
| 176 | 184 |   | 
|---|
| 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)  | 
|---|
| 179 | 187 |  { | 
|---|
| 180 | 188 |  	int ret; | 
|---|
| 181 | 189 |  	struct timespec64 kernel_tp; | 
|---|
| .. | .. | 
|---|
| 184 | 192 |  	if (ret) | 
|---|
| 185 | 193 |  		return ret; | 
|---|
| 186 | 194 |   | 
|---|
| 187 |  | -	if (compat_put_timespec64(&kernel_tp, tp))  | 
|---|
 | 195 | +	if (put_old_timespec32(&kernel_tp, tp))  | 
|---|
| 188 | 196 |  		return -EFAULT; | 
|---|
| 189 | 197 |  	return 0; | 
|---|
| 190 | 198 |  } | 
|---|
| 191 | 199 |   | 
|---|
| 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)  | 
|---|
| 194 | 202 |  { | 
|---|
| 195 | 203 |  	struct timespec64 rtn_tp = { | 
|---|
| 196 | 204 |  		.tv_sec = 0, | 
|---|
| .. | .. | 
|---|
| 201 | 209 |  	case CLOCK_REALTIME: | 
|---|
| 202 | 210 |  	case CLOCK_MONOTONIC: | 
|---|
| 203 | 211 |  	case CLOCK_BOOTTIME: | 
|---|
| 204 |  | -		if (compat_put_timespec64(&rtn_tp, tp))  | 
|---|
 | 212 | +		if (put_old_timespec32(&rtn_tp, tp))  | 
|---|
| 205 | 213 |  			return -EFAULT; | 
|---|
| 206 | 214 |  		return 0; | 
|---|
| 207 | 215 |  	default: | 
|---|
| .. | .. | 
|---|
| 209 | 217 |  	} | 
|---|
| 210 | 218 |  } | 
|---|
| 211 | 219 |   | 
|---|
| 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)  | 
|---|
| 215 | 223 |  { | 
|---|
| 216 | 224 |  	struct timespec64 t; | 
|---|
 | 225 | +	ktime_t texp;  | 
|---|
| 217 | 226 |   | 
|---|
| 218 | 227 |  	switch (which_clock) { | 
|---|
| 219 | 228 |  	case CLOCK_REALTIME: | 
|---|
| .. | .. | 
|---|
| 224 | 233 |  		return -EINVAL; | 
|---|
| 225 | 234 |  	} | 
|---|
| 226 | 235 |   | 
|---|
| 227 |  | -	if (compat_get_timespec64(&t, rqtp))  | 
|---|
 | 236 | +	if (get_old_timespec32(&t, rqtp))  | 
|---|
| 228 | 237 |  		return -EFAULT; | 
|---|
| 229 | 238 |  	if (!timespec64_valid(&t)) | 
|---|
| 230 | 239 |  		return -EINVAL; | 
|---|
| .. | .. | 
|---|
| 232 | 241 |  		rmtp = NULL; | 
|---|
| 233 | 242 |  	current->restart_block.nanosleep.type = rmtp ? TT_COMPAT : TT_NONE; | 
|---|
| 234 | 243 |  	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 ?  | 
|---|
| 236 | 248 |  				 HRTIMER_MODE_ABS : HRTIMER_MODE_REL, | 
|---|
| 237 | 249 |  				 which_clock); | 
|---|
| 238 | 250 |  } | 
|---|