[PATCH] rcu: Mention rcu_bh in description of rcutorture's torture_type parameter
[linux-2.6.git] / kernel / compat.c
index dad1065..75573e5 100644 (file)
 #include <linux/time.h>
 #include <linux/signal.h>
 #include <linux/sched.h>       /* for MAX_SCHEDULE_TIMEOUT */
-#include <linux/futex.h>       /* for FUTEX_WAIT */
 #include <linux/syscalls.h>
 #include <linux/unistd.h>
 #include <linux/security.h>
+#include <linux/timex.h>
+#include <linux/migrate.h>
+#include <linux/posix-timers.h>
 
 #include <asm/uaccess.h>
-#include <asm/bug.h>
 
 int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts)
 {
@@ -48,8 +49,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
        if (!time_after(expire, now))
                return 0;
 
-       current->state = TASK_INTERRUPTIBLE;
-       expire = schedule_timeout(expire - now);
+       expire = schedule_timeout_interruptible(expire - now);
        if (expire == 0)
                return 0;
 
@@ -82,8 +82,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
                return -EINVAL;
 
        expire = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec);
-       current->state = TASK_INTERRUPTIBLE;
-       expire = schedule_timeout(expire);
+       expire = schedule_timeout_interruptible(expire);
        if (expire == 0)
                return 0;
 
@@ -241,28 +240,6 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
        return ret;
 }
 
-#ifdef CONFIG_FUTEX
-asmlinkage long compat_sys_futex(u32 __user *uaddr, int op, int val,
-               struct compat_timespec __user *utime, u32 __user *uaddr2,
-               int val3)
-{
-       struct timespec t;
-       unsigned long timeout = MAX_SCHEDULE_TIMEOUT;
-       int val2 = 0;
-
-       if ((op == FUTEX_WAIT) && utime) {
-               if (get_compat_timespec(&t, utime))
-                       return -EFAULT;
-               timeout = timespec_to_jiffies(&t) + 1;
-       }
-       if (op >= FUTEX_REQUEUE)
-               val2 = (int) (unsigned long) utime;
-
-       return do_futex((unsigned long)uaddr, op, val, timeout,
-                       (unsigned long)uaddr2, val2, val3);
-}
-#endif
-
 asmlinkage long compat_sys_setrlimit(unsigned int resource,
                struct compat_rlimit __user *rlim)
 {
@@ -516,6 +493,24 @@ static int put_compat_itimerspec(struct compat_itimerspec __user *dst,
        return 0;
 } 
 
+long compat_sys_timer_create(clockid_t which_clock,
+                       struct compat_sigevent __user *timer_event_spec,
+                       timer_t __user *created_timer_id)
+{
+       struct sigevent __user *event = NULL;
+
+       if (timer_event_spec) {
+               struct sigevent kevent;
+
+               event = compat_alloc_user_space(sizeof(*event));
+               if (get_compat_sigevent(&kevent, timer_event_spec) ||
+                   copy_to_user(event, &kevent, sizeof(*event)))
+                       return -EFAULT;
+       }
+
+       return sys_timer_create(which_clock, event, created_timer_id);
+}
+
 long compat_sys_timer_settime(timer_t timer_id, int flags,
                          struct compat_itimerspec __user *new, 
                          struct compat_itimerspec __user *old)
@@ -607,6 +602,30 @@ long compat_sys_clock_getres(clockid_t which_clock,
        return err;
 } 
 
+static long compat_clock_nanosleep_restart(struct restart_block *restart)
+{
+       long err;
+       mm_segment_t oldfs;
+       struct timespec tu;
+       struct compat_timespec *rmtp = (struct compat_timespec *)(restart->arg1);
+
+       restart->arg1 = (unsigned long) &tu;
+       oldfs = get_fs();
+       set_fs(KERNEL_DS);
+       err = clock_nanosleep_restart(restart);
+       set_fs(oldfs);
+
+       if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
+           put_compat_timespec(&tu, rmtp))
+               return -EFAULT;
+
+       if (err == -ERESTART_RESTARTBLOCK) {
+               restart->fn = compat_clock_nanosleep_restart;
+               restart->arg1 = (unsigned long) rmtp;
+       }
+       return err;
+}
+
 long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
                            struct compat_timespec __user *rqtp,
                            struct compat_timespec __user *rmtp)
@@ -614,6 +633,7 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
        long err;
        mm_segment_t oldfs;
        struct timespec in, out; 
+       struct restart_block *restart;
 
        if (get_compat_timespec(&in, rqtp)) 
                return -EFAULT;
@@ -624,9 +644,16 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
                                  (struct timespec __user *) &in,
                                  (struct timespec __user *) &out);
        set_fs(oldfs);
+
        if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
            put_compat_timespec(&out, rmtp))
                return -EFAULT;
+
+       if (err == -ERESTART_RESTARTBLOCK) {
+               restart = &current_thread_info()->restart_block;
+               restart->fn = compat_clock_nanosleep_restart;
+               restart->arg1 = (unsigned long) rmtp;
+       }
        return err;     
 } 
 
@@ -640,7 +667,7 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
 int get_compat_sigevent(struct sigevent *event,
                const struct compat_sigevent __user *u_event)
 {
-       memset(&event, 0, sizeof(*event));
+       memset(event, 0, sizeof(*event));
        return (!access_ok(VERIFY_READ, u_event, sizeof(*u_event)) ||
                __get_user(event->sigev_value.sival_int,
                        &u_event->sigev_value.sival_int) ||
@@ -651,8 +678,6 @@ int get_compat_sigevent(struct sigevent *event,
                ? -EFAULT : 0;
 }
 
-/* timer_create is architecture specific because it needs sigevent conversion */
-
 long compat_get_bitmap(unsigned long *mask, compat_ulong_t __user *umask,
                       unsigned long bitmap_size)
 {
@@ -738,17 +763,10 @@ void
 sigset_from_compat (sigset_t *set, compat_sigset_t *compat)
 {
        switch (_NSIG_WORDS) {
-#if defined (__COMPAT_ENDIAN_SWAP__)
-       case 4: set->sig[3] = compat->sig[7] | (((long)compat->sig[6]) << 32 );
-       case 3: set->sig[2] = compat->sig[5] | (((long)compat->sig[4]) << 32 );
-       case 2: set->sig[1] = compat->sig[3] | (((long)compat->sig[2]) << 32 );
-       case 1: set->sig[0] = compat->sig[1] | (((long)compat->sig[0]) << 32 );
-#else
        case 4: set->sig[3] = compat->sig[6] | (((long)compat->sig[7]) << 32 );
        case 3: set->sig[2] = compat->sig[4] | (((long)compat->sig[5]) << 32 );
        case 2: set->sig[1] = compat->sig[2] | (((long)compat->sig[3]) << 32 );
        case 1: set->sig[0] = compat->sig[0] | (((long)compat->sig[1]) << 32 );
-#endif
        }
 }
 
@@ -795,8 +813,7 @@ compat_sys_rt_sigtimedwait (compat_sigset_t __user *uthese,
                        recalc_sigpending();
                        spin_unlock_irq(&current->sighand->siglock);
 
-                       current->state = TASK_INTERRUPTIBLE;
-                       timeout = schedule_timeout(timeout);
+                       timeout = schedule_timeout_interruptible(timeout);
 
                        spin_lock_irq(&current->sighand->siglock);
                        sig = dequeue_signal(current, &s, &info);
@@ -858,3 +875,111 @@ asmlinkage long compat_sys_stime(compat_time_t __user *tptr)
 }
 
 #endif /* __ARCH_WANT_COMPAT_SYS_TIME */
+
+#ifdef __ARCH_WANT_COMPAT_SYS_RT_SIGSUSPEND
+asmlinkage long compat_sys_rt_sigsuspend(compat_sigset_t __user *unewset, compat_size_t sigsetsize)
+{
+       sigset_t newset;
+       compat_sigset_t newset32;
+
+       /* XXX: Don't preclude handling different sized sigset_t's.  */
+       if (sigsetsize != sizeof(sigset_t))
+               return -EINVAL;
+
+       if (copy_from_user(&newset32, unewset, sizeof(compat_sigset_t)))
+               return -EFAULT;
+       sigset_from_compat(&newset, &newset32);
+       sigdelsetmask(&newset, sigmask(SIGKILL)|sigmask(SIGSTOP));
+
+       spin_lock_irq(&current->sighand->siglock);
+       current->saved_sigmask = current->blocked;
+       current->blocked = newset;
+       recalc_sigpending();
+       spin_unlock_irq(&current->sighand->siglock);
+
+       current->state = TASK_INTERRUPTIBLE;
+       schedule();
+       set_thread_flag(TIF_RESTORE_SIGMASK);
+       return -ERESTARTNOHAND;
+}
+#endif /* __ARCH_WANT_COMPAT_SYS_RT_SIGSUSPEND */
+
+asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp)
+{
+       struct timex txc;
+       int ret;
+
+       memset(&txc, 0, sizeof(struct timex));
+
+       if (!access_ok(VERIFY_READ, utp, sizeof(struct compat_timex)) ||
+                       __get_user(txc.modes, &utp->modes) ||
+                       __get_user(txc.offset, &utp->offset) ||
+                       __get_user(txc.freq, &utp->freq) ||
+                       __get_user(txc.maxerror, &utp->maxerror) ||
+                       __get_user(txc.esterror, &utp->esterror) ||
+                       __get_user(txc.status, &utp->status) ||
+                       __get_user(txc.constant, &utp->constant) ||
+                       __get_user(txc.precision, &utp->precision) ||
+                       __get_user(txc.tolerance, &utp->tolerance) ||
+                       __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
+                       __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
+                       __get_user(txc.tick, &utp->tick) ||
+                       __get_user(txc.ppsfreq, &utp->ppsfreq) ||
+                       __get_user(txc.jitter, &utp->jitter) ||
+                       __get_user(txc.shift, &utp->shift) ||
+                       __get_user(txc.stabil, &utp->stabil) ||
+                       __get_user(txc.jitcnt, &utp->jitcnt) ||
+                       __get_user(txc.calcnt, &utp->calcnt) ||
+                       __get_user(txc.errcnt, &utp->errcnt) ||
+                       __get_user(txc.stbcnt, &utp->stbcnt))
+               return -EFAULT;
+
+       ret = do_adjtimex(&txc);
+
+       if (!access_ok(VERIFY_WRITE, utp, sizeof(struct compat_timex)) ||
+                       __put_user(txc.modes, &utp->modes) ||
+                       __put_user(txc.offset, &utp->offset) ||
+                       __put_user(txc.freq, &utp->freq) ||
+                       __put_user(txc.maxerror, &utp->maxerror) ||
+                       __put_user(txc.esterror, &utp->esterror) ||
+                       __put_user(txc.status, &utp->status) ||
+                       __put_user(txc.constant, &utp->constant) ||
+                       __put_user(txc.precision, &utp->precision) ||
+                       __put_user(txc.tolerance, &utp->tolerance) ||
+                       __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
+                       __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
+                       __put_user(txc.tick, &utp->tick) ||
+                       __put_user(txc.ppsfreq, &utp->ppsfreq) ||
+                       __put_user(txc.jitter, &utp->jitter) ||
+                       __put_user(txc.shift, &utp->shift) ||
+                       __put_user(txc.stabil, &utp->stabil) ||
+                       __put_user(txc.jitcnt, &utp->jitcnt) ||
+                       __put_user(txc.calcnt, &utp->calcnt) ||
+                       __put_user(txc.errcnt, &utp->errcnt) ||
+                       __put_user(txc.stbcnt, &utp->stbcnt))
+               ret = -EFAULT;
+
+       return ret;
+}
+
+#ifdef CONFIG_NUMA
+asmlinkage long compat_sys_move_pages(pid_t pid, unsigned long nr_pages,
+               compat_uptr_t __user *pages32,
+               const int __user *nodes,
+               int __user *status,
+               int flags)
+{
+       const void __user * __user *pages;
+       int i;
+
+       pages = compat_alloc_user_space(nr_pages * sizeof(void *));
+       for (i = 0; i < nr_pages; i++) {
+               compat_uptr_t p;
+
+               if (get_user(p, pages32 + i) ||
+                       put_user(compat_ptr(p), pages + i))
+                       return -EFAULT;
+       }
+       return sys_move_pages(pid, nr_pages, pages, nodes, status, flags);
+}
+#endif