[PARISC] futex: special case cmpxchg NULL in kernel space
[sfrench/cifs-2.6.git] / include / asm-parisc / futex.h
index 9feff4ce1424bc390608326240be369eb13aa648..fdc6d055ef7f2af68872f2f195d8b417ebb9558f 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef _ASM_FUTEX_H
-#define _ASM_FUTEX_H
+#ifndef _ASM_PARISC_FUTEX_H
+#define _ASM_PARISC_FUTEX_H
 
 #ifdef __KERNEL__
 
@@ -21,7 +21,7 @@ futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
        if (! access_ok (VERIFY_WRITE, uaddr, sizeof(int)))
                return -EFAULT;
 
-       inc_preempt_count();
+       pagefault_disable();
 
        switch (op) {
        case FUTEX_OP_SET:
@@ -33,7 +33,7 @@ futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
                ret = -ENOSYS;
        }
 
-       dec_preempt_count();
+       pagefault_enable();
 
        if (!ret) {
                switch (cmp) {
@@ -49,5 +49,29 @@ futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
        return ret;
 }
 
-#endif
-#endif
+/* Non-atomic version */
+static inline int
+futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
+{
+       int err = 0;
+       int uval;
+
+       /* futex.c wants to do a cmpxchg_inatomic on kernel NULL, which is
+        * our gateway page, and causes no end of trouble...
+        */
+       if (segment_eq(KERNEL_DS, get_fs()) && !uaddr)
+               return -EFAULT;
+
+       if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
+               return -EFAULT;
+
+       err = get_user(uval, uaddr);
+       if (err) return -EFAULT;
+       if (uval == oldval)
+               err = put_user(newval, uaddr);
+       if (err) return -EFAULT;
+       return uval;
+}
+
+#endif /*__KERNEL__*/
+#endif /*_ASM_PARISC_FUTEX_H*/