]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
x86: introduce copy_user_handle_tail() routine
authorVitaly Mayatskikh <v.mayatskih@gmail.com>
Wed, 2 Jul 2008 13:48:21 +0000 (15:48 +0200)
committerIngo Molnar <mingo@elte.hu>
Wed, 9 Jul 2008 13:51:03 +0000 (15:51 +0200)
Introduce generic C routine for handling necessary tail operations after
protection fault in copy_*_user on x86.

Signed-off-by: Vitaly Mayatskikh <v.mayatskih@gmail.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
arch/x86/lib/usercopy_64.c
include/asm-x86/uaccess_64.h

index 0c89d1bb02871e0324b57418d5390535c1780c2b..f4df6e7c718be506a59ef157bda9591dfb1790a6 100644 (file)
@@ -158,3 +158,26 @@ unsigned long copy_in_user(void __user *to, const void __user *from, unsigned le
 }
 EXPORT_SYMBOL(copy_in_user);
 
+/*
+ * Try to copy last bytes and clear the rest if needed.
+ * Since protection fault in copy_from/to_user is not a normal situation,
+ * it is not necessary to optimize tail handling.
+ */
+unsigned long
+copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
+{
+       char c;
+       unsigned zero_len;
+
+       for (; len; --len) {
+               if (__get_user_nocheck(c, from++, sizeof(char)))
+                       break;
+               if (__put_user_nocheck(c, to++, sizeof(char)))
+                       break;
+       }
+
+       for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
+               if (__put_user_nocheck(c, to++, sizeof(char)))
+                       break;
+       return len;
+}
index 4e3ec004e14a53973c4d51a30ecaa8731106cc3e..515d4dce96b598bc6e9d07dba21332a44924948c 100644 (file)
@@ -195,4 +195,7 @@ static inline int __copy_from_user_inatomic_nocache(void *dst,
        return __copy_user_nocache(dst, src, size, 0);
 }
 
+unsigned long
+copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
+
 #endif /* __X86_64_UACCESS_H */