diff options
| -rw-r--r-- | kernel/compat.c | 57 |
1 files changed, 11 insertions, 46 deletions
diff --git a/kernel/compat.c b/kernel/compat.c index 3bae3742c2a..252a446fb0d 100644 --- a/kernel/compat.c +++ b/kernel/compat.c | |||
| @@ -40,62 +40,27 @@ int put_compat_timespec(const struct timespec *ts, struct compat_timespec __user | |||
| 40 | __put_user(ts->tv_nsec, &cts->tv_nsec)) ? -EFAULT : 0; | 40 | __put_user(ts->tv_nsec, &cts->tv_nsec)) ? -EFAULT : 0; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | static long compat_nanosleep_restart(struct restart_block *restart) | ||
| 44 | { | ||
| 45 | unsigned long expire = restart->arg0, now = jiffies; | ||
| 46 | struct compat_timespec __user *rmtp; | ||
| 47 | |||
| 48 | /* Did it expire while we handled signals? */ | ||
| 49 | if (!time_after(expire, now)) | ||
| 50 | return 0; | ||
| 51 | |||
| 52 | expire = schedule_timeout_interruptible(expire - now); | ||
| 53 | if (expire == 0) | ||
| 54 | return 0; | ||
| 55 | |||
| 56 | rmtp = (struct compat_timespec __user *)restart->arg1; | ||
| 57 | if (rmtp) { | ||
| 58 | struct compat_timespec ct; | ||
| 59 | struct timespec t; | ||
| 60 | |||
| 61 | jiffies_to_timespec(expire, &t); | ||
| 62 | ct.tv_sec = t.tv_sec; | ||
| 63 | ct.tv_nsec = t.tv_nsec; | ||
| 64 | if (copy_to_user(rmtp, &ct, sizeof(ct))) | ||
| 65 | return -EFAULT; | ||
| 66 | } | ||
| 67 | /* The 'restart' block is already filled in */ | ||
| 68 | return -ERESTART_RESTARTBLOCK; | ||
| 69 | } | ||
| 70 | |||
| 71 | asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp, | 43 | asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp, |
| 72 | struct compat_timespec __user *rmtp) | 44 | struct compat_timespec __user *rmtp) |
| 73 | { | 45 | { |
| 74 | struct timespec t; | 46 | struct timespec tu, rmt; |
| 75 | struct restart_block *restart; | 47 | long ret; |
| 76 | unsigned long expire; | ||
| 77 | 48 | ||
| 78 | if (get_compat_timespec(&t, rqtp)) | 49 | if (get_compat_timespec(&tu, rqtp)) |
| 79 | return -EFAULT; | 50 | return -EFAULT; |
| 80 | 51 | ||
| 81 | if ((t.tv_nsec >= 1000000000L) || (t.tv_nsec < 0) || (t.tv_sec < 0)) | 52 | if (!timespec_valid(&tu)) |
| 82 | return -EINVAL; | 53 | return -EINVAL; |
| 83 | 54 | ||
| 84 | expire = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec); | 55 | ret = hrtimer_nanosleep(&tu, rmtp ? &rmt : NULL, HRTIMER_MODE_REL, |
| 85 | expire = schedule_timeout_interruptible(expire); | 56 | CLOCK_MONOTONIC); |
| 86 | if (expire == 0) | ||
| 87 | return 0; | ||
| 88 | 57 | ||
| 89 | if (rmtp) { | 58 | if (ret && rmtp) { |
| 90 | jiffies_to_timespec(expire, &t); | 59 | if (put_compat_timespec(&rmt, rmtp)) |
| 91 | if (put_compat_timespec(&t, rmtp)) | ||
| 92 | return -EFAULT; | 60 | return -EFAULT; |
| 93 | } | 61 | } |
| 94 | restart = ¤t_thread_info()->restart_block; | 62 | |
| 95 | restart->fn = compat_nanosleep_restart; | 63 | return ret; |
| 96 | restart->arg0 = jiffies + expire; | ||
| 97 | restart->arg1 = (unsigned long) rmtp; | ||
| 98 | return -ERESTART_RESTARTBLOCK; | ||
| 99 | } | 64 | } |
| 100 | 65 | ||
| 101 | static inline long get_compat_itimerval(struct itimerval *o, | 66 | static inline long get_compat_itimerval(struct itimerval *o, |
