@@ -109,6 +109,9 @@ struct k_clock {
int (*timer_set) (struct k_itimer * timr, int flags,
struct itimerspec * new_setting,
struct itimerspec * old_setting);
+ int (*timer_set64) (struct k_itimer *timr, int flags,
+ struct itimerspec64 *new_setting,
+ struct itimerspec64 *old_setting);
int (*timer_del) (struct k_itimer * timr);
#define TIMER_RETRY 1
void (*timer_get) (struct k_itimer * timr,
@@ -553,6 +553,23 @@ static void default_timer_get64(struct k_itimer *timr,
*cur_setting64 = itimerspec_to_itimerspec64(&cur_setting);
}
+static int default_timer_set64(struct k_itimer *timr, int flags,
+ struct itimerspec64 *new_setting64,
+ struct itimerspec64 *old_setting64)
+{
+ struct k_clock *kc = clockid_to_kclock(timr->it_clock);
+ struct itimerspec new_setting, old_setting;
+ struct itimerspec *rtn = old_setting64 ? &old_setting : NULL;
+ int ret;
+
+ new_setting = itimerspec64_to_itimerspec(new_setting64);
+ ret = kc->timer_set(timr, flags, &new_setting, rtn);
+ if (!ret && old_setting64)
+ *old_setting64 = itimerspec_to_itimerspec64(&old_setting);
+
+ return ret;
+}
+
void posix_timers_register_clock(const clockid_t clock_id,
struct k_clock *new_clock)
{
@@ -575,6 +592,8 @@ void posix_timers_register_clock(const clockid_t clock_id,
if (new_clock->timer_get && !new_clock->timer_get64)
new_clock->timer_get64 = default_timer_get64;
+ if (new_clock->timer_set && !new_clock->timer_set64)
+ new_clock->timer_set64 = default_timer_set64;
posix_clocks[clock_id] = *new_clock;
}
@@ -920,16 +939,16 @@ common_timer_set(struct k_itimer *timr, int flags,
return 0;
}
-static int __timer_settime(timer_t timer_id, int flags, struct itimerspec *new_spec,
- struct itimerspec *old_spec)
+static int __timer_settime(timer_t timer_id, int flags, struct itimerspec64 *new_spec,
+ struct itimerspec64 *old_spec)
{
struct k_itimer *timr;
int error = 0;
unsigned long flag;
struct k_clock *kc;
- if (!timespec_valid(&new_spec->it_interval) ||
- !timespec_valid(&new_spec->it_value))
+ if (!timespec64_valid(&new_spec->it_interval) ||
+ !timespec64_valid(&new_spec->it_value))
return -EINVAL;
retry:
@@ -938,10 +957,10 @@ retry:
return -EINVAL;
kc = clockid_to_kclock(timr->it_clock);
- if (WARN_ON_ONCE(!kc || !kc->timer_set))
+ if (WARN_ON_ONCE(!kc || !kc->timer_set64))
error = -EINVAL;
else
- error = kc->timer_set(timr, flags, new_spec, old_spec);
+ error = kc->timer_set64(timr, flags, new_spec, old_spec);
unlock_timer(timr, flag);
if (error == TIMER_RETRY) {
@@ -957,20 +976,20 @@ SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
const struct itimerspec __user *, new_setting,
struct itimerspec __user *, old_setting)
{
- struct itimerspec new_spec, old_spec;
+ struct itimerspec64 new_spec, old_spec;
int error = 0;
- struct itimerspec *rtn = old_setting ? &old_spec : NULL;
+ struct itimerspec64 *rtn = old_setting ? &old_spec : NULL;
if (!new_setting)
return -EINVAL;
- if (copy_from_user(&new_spec, new_setting, sizeof (new_spec)))
+ if (get_itimerspec(&new_spec, new_setting))
return -EFAULT;
error = __timer_settime(timer_id, flags, &new_spec, rtn);
if (old_setting && !error &&
- copy_to_user(old_setting, &old_spec, sizeof (old_spec)))
+ put_itimerspec(&old_spec, old_setting))
error = -EFAULT;
return error;
This patch introduces the timer_set64 method with itimerspec64 type for k_clock structure, that makes it ready for the 2038 year. Convert to the 64bit method with itimerspec64 type for the timer_settime syscall function, and change the timer_settime syscall implementation. Also add a default 64bit method for the timer_set64 pointer of k_clock structure, and it will be removed after all the drivers are converted to 64bit methods. Signed-off-by: Baolin Wang <baolin.wang@linaro.org> --- include/linux/posix-timers.h | 3 +++ kernel/time/posix-timers.c | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 10 deletions(-)