This patch converts to the 64bit methods with timespec64/itimerspec64 type, and changes the syscall implementation according to the CONFIG_64BIT macro.
Signed-off-by: Baolin Wang baolin.wang@linaro.org --- kernel/time/posix-timers.c | 103 +++++++++++++++++++++++++++++++++----------- 1 file changed, 78 insertions(+), 25 deletions(-)
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index 8564b88..7109688 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -522,13 +522,13 @@ void posix_timers_register_clock(const clockid_t clock_id, return; }
- if (!new_clock->clock_get) { - printk(KERN_WARNING "POSIX clock id %d lacks clock_get()\n", + if (!new_clock->clock_get && !new_clock->clock_get64) { + printk(KERN_WARNING "POSIX clock id %d lacks clock_get() and clock_get64()\n", clock_id); return; } - if (!new_clock->clock_getres) { - printk(KERN_WARNING "POSIX clock id %d lacks clock_getres()\n", + if (!new_clock->clock_getres && !new_clock->clock_getres64) { + printk(KERN_WARNING "POSIX clock id %d lacks clock_getres() and clock_getres64()\n", clock_id); return; } @@ -579,7 +579,8 @@ static struct k_clock *clockid_to_kclock(const clockid_t id) return (id & CLOCKFD_MASK) == CLOCKFD ? &clock_posix_dynamic : &clock_posix_cpu;
- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres) + if (id >= MAX_CLOCKS || (!posix_clocks[id].clock_getres + && !posix_clocks[id].clock_getres64)) return NULL; return &posix_clocks[id]; } @@ -766,7 +767,7 @@ common_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting) cur_setting->it_value = ktime_to_timespec(remaining); }
-static int __timer_gettime(timer_t timer_id, struct itimerspec *cur_setting) +static int __timer_gettime(timer_t timer_id, struct itimerspec64 *cur_setting) { struct k_itimer *timr; struct k_clock *kc; @@ -778,10 +779,10 @@ static int __timer_gettime(timer_t timer_id, struct itimerspec *cur_setting) return -EINVAL;
kc = clockid_to_kclock(timr->it_clock); - if (WARN_ON_ONCE(!kc || !kc->timer_get)) + if (WARN_ON_ONCE(!kc || !kc->timer_get64)) ret = -EINVAL; else - kc->timer_get(timr, cur_setting); + kc->timer_get64(timr, cur_setting);
unlock_timer(timr, flags); return ret; @@ -791,8 +792,17 @@ static int __timer_gettime(timer_t timer_id, struct itimerspec *cur_setting) SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id, struct itimerspec __user *, setting) { - struct itimerspec cur_setting; +#ifdef CONFIG_64BIT + struct itimerspec64 cur_setting; int ret = __timer_gettime(timer_id, &cur_setting); +#else + struct itimerspec64 cur_setting64; + struct itimerspec cur_setting; + int ret = __timer_gettime(timer_id, &cur_setting64); + + if (!ret) + cur_setting = itimerspec64_to_itimerspec(&cur_setting64); +#endif
if (!ret && copy_to_user(setting, &cur_setting, sizeof (cur_setting))) return -EFAULT; @@ -876,8 +886,8 @@ 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; @@ -890,10 +900,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) { @@ -909,9 +919,16 @@ 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; int error = 0; +#ifdef CONFIG_64BIT + struct itimerspec64 new_spec, old_spec; + struct itimerspec64 *rtn = old_setting ? &old_spec : NULL; +#else + struct itimerspec new_spec, old_spec; struct itimerspec *rtn = old_setting ? &old_spec : NULL; + struct itimerspec64 new_spec64; + struct itimerspec64 *rtn64; +#endif
if (!new_setting) return -EINVAL; @@ -923,7 +940,17 @@ SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags, !timespec_valid(&new_spec.it_value)) return -EINVAL;
+#ifdef CONFIG_64BIT error = __timer_settime(timer_id, flags, &new_spec, rtn); +#else + new_spec64 = itimerspec_to_itimerspec64(&new_spec); + if (rtn) + *rtn64 = itimerspec_to_itimerspec64(rtn); + else + rtn64 = NULL; + + error = __timer_settime(timer_id, flags, &new_spec64, rtn64); +#endif
if (old_setting && !error && copy_to_user(old_setting, &old_spec, sizeof (old_spec))) @@ -1019,44 +1046,62 @@ void exit_itimers(struct signal_struct *sig) } }
-static int __clock_settime(clockid_t which_clock, struct timespec *ts) +static int __clock_settime(clockid_t which_clock, struct timespec64 *ts) { struct k_clock *kc = clockid_to_kclock(which_clock);
- if (!kc || !kc->clock_set) + if (!kc || !kc->clock_set64) return -EINVAL;
- return kc->clock_set(which_clock, ts); + return kc->clock_set64(which_clock, ts); }
SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock, const struct timespec __user *, tp) { +#ifdef CONFIG_64BIT + struct timespec64 new_tp; +#else struct timespec new_tp; + struct timespec64 new_tp64; +#endif
if (copy_from_user(&new_tp, tp, sizeof (*tp))) return -EFAULT;
+#ifdef CONFIG_64BIT return __clock_settime(which_clock, &new_tp); +#else + new_tp64 = timespec_to_timespec64(new_tp); + return __clock_settime(which_clock, &new_tp64); +#endif }
-static int __clock_gettime(clockid_t which_clock, struct timespec *ts) +static int __clock_gettime(clockid_t which_clock, struct timespec64 *ts) { struct k_clock *kc = clockid_to_kclock(which_clock);
if (!kc) return -EINVAL;
- return kc->clock_get(which_clock, ts); + return kc->clock_get64(which_clock, ts); }
SYSCALL_DEFINE2(clock_gettime, const clockid_t, which_clock, struct timespec __user *,tp) { - struct timespec kernel_tp; int error; - +#ifdef CONFIG_64BIT + struct timespec64 kernel_tp; error = __clock_gettime(which_clock, &kernel_tp); +#else + struct timespec64 kernel_tp64; + struct timespec kernel_tp; + + error = __clock_gettime(which_clock, &kernel_tp64); + if (!error) + kernel_tp = timespec64_to_timespec(kernel_tp64); +#endif
if (!error && copy_to_user(tp, &kernel_tp, sizeof (kernel_tp))) error = -EFAULT; @@ -1087,23 +1132,31 @@ SYSCALL_DEFINE2(clock_adjtime, const clockid_t, which_clock, return err; }
-static int __clock_getres(clockid_t which_clock, struct timespec *ts) +static int __clock_getres(clockid_t which_clock, struct timespec64 *ts) { struct k_clock *kc = clockid_to_kclock(which_clock);
if (!kc) return -EINVAL;
- return kc->clock_getres(which_clock, ts); + return kc->clock_getres64(which_clock, ts); }
SYSCALL_DEFINE2(clock_getres, const clockid_t, which_clock, struct timespec __user *, tp) { - struct timespec rtn_tp; int error; - +#ifdef CONFIG_64BIT + struct timespec64 rtn_tp; error = __clock_getres(which_clock, &rtn_tp); +#else + struct timespec64 rtn_tp64; + struct timespec rtn_tp; + + error = __clock_getres(which_clock, &rtn_tp64); + if (!error) + rtn_tp = timespec64_to_timespec(rtn_tp64); +#endif
if (!error && tp && copy_to_user(tp, &rtn_tp, sizeof (rtn_tp))) error = -EFAULT;