Module: xenomai-3
Branch: next
Commit: 504f0e25a924dad0c4a4921449d2e7ca5a1fac80
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=504f0e25a924dad0c4a4921449d2e7ca5a1fac80

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed May 10 12:51:07 2017 +0200

cobalt/x86: provide generic version of strncpy_from_user_nocheck()

The former open-coded version of this routine caused havoc in the
exception table generated for recent kernels after the introduction of
a new format for exception entries during the 4.5->4.6 time frame.

Switch this code to a generic form which does not need to know about
the implementation details of exception fixup code.

---

 kernel/cobalt/arch/x86/machine.c |   98 ++++++--------------------------------
 1 file changed, 15 insertions(+), 83 deletions(-)

diff --git a/kernel/cobalt/arch/x86/machine.c b/kernel/cobalt/arch/x86/machine.c
index d9eb66d..4b25486 100644
--- a/kernel/cobalt/arch/x86/machine.c
+++ b/kernel/cobalt/arch/x86/machine.c
@@ -19,96 +19,28 @@
  */
 #include <linux/ipipe_tickdev.h>
 #include <cobalt/kernel/arith.h>
+#include <asm/xenomai/syscall.h>
 #include <asm/xenomai/machine.h>
 #include <asm/xenomai/thread.h>
 #include <asm/xenomai/smi.h>
 #include <asm/xenomai/c1e.h>
 
-#ifdef __i386__
-
-/*
- * Lifted from linux/arch/i386/lib/usercopy.c.
- *
- * Copyright 1997 Andi Kleen <a...@muc.de>
- * Copyright 1997 Linus Torvalds
- */
-
-#define __do_strncpy_from_user(dst, src, count, res)                      \
-do {                                                                      \
-       int __d0, __d1, __d2;                                              \
-       __asm__ __volatile__(                                              \
-               "       testl %1,%1\n"                                     \
-               "       jz 2f\n"                                           \
-               "0:     lodsb\n"                                           \
-               "       stosb\n"                                           \
-               "       testb %%al,%%al\n"                                 \
-               "       jz 1f\n"                                           \
-               "       decl %1\n"                                         \
-               "       jnz 0b\n"                                          \
-               "1:     subl %1,%0\n"                                      \
-               "2:\n"                                                     \
-               ".section .fixup,\"ax\"\n"                                 \
-               "3:     movl %5,%0\n"                                      \
-               "       jmp 2b\n"                                          \
-               ".previous\n"                                              \
-               ".section __ex_table,\"a\"\n"                              \
-               "       .align 4\n"                                        \
-               "       .long 0b,3b\n"                                     \
-               ".previous"                                                \
-               : "=&d"(res), "=&c"(count), "=&a" (__d0), "=&S" (__d1),    \
-                 "=&D" (__d2)                                             \
-               : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
-               : "memory");                                               \
-} while (0)
-
-#else /* __x86_64__ */
-
-/*
- * Lifted from linux/arch/x86_64/lib/usercopy.c.
- *
- * Copyright 1997 Andi Kleen <a...@muc.de>
- * Copyright 1997 Linus Torvalds
- * Copyright 2002 Andi Kleen <a...@suse.de>
- */
-
-#define __do_strncpy_from_user(dst, src, count, res)                      \
-do {                                                                      \
-       long __d0, __d1, __d2;                                             \
-       __asm__ __volatile__(                                              \
-               "       testq %1,%1\n"                                     \
-               "       jz 2f\n"                                           \
-               "0:     lodsb\n"                                           \
-               "       stosb\n"                                           \
-               "       testb %%al,%%al\n"                                 \
-               "       jz 1f\n"                                           \
-               "       decq %1\n"                                         \
-               "       jnz 0b\n"                                          \
-               "1:     subq %1,%0\n"                                      \
-               "2:\n"                                                     \
-               ".section .fixup,\"ax\"\n"                                 \
-               "3:     movq %5,%0\n"                                      \
-               "       jmp 2b\n"                                          \
-               ".previous\n"                                              \
-               ".section __ex_table,\"a\"\n"                              \
-               "       .align 8\n"                                        \
-               "       .quad 0b,3b\n"                                     \
-               ".previous"                                                \
-               : "=&r"(res), "=&c"(count), "=&a" (__d0), "=&S" (__d1),    \
-                 "=&D" (__d2)                                             \
-               : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
-               : "memory");                                               \
-} while (0)
-
-#endif
-
 long strncpy_from_user_nocheck(char *dst, const char __user *src, long count)
 {
-       long res;
-
-       stac();
-       __do_strncpy_from_user(dst, src, count, res);
-       clac();
-       return res;
+       int ret;
+       char c;
+       long n;
+       
+       for (n = 0; n < count; n++, src++, dst++) {
+               ret = __xn_get_user(c, src);
+               if (ret)
+                       return -EFAULT;
+               *dst = c;
+               if (c == 0)
+                       break;
+       }
+
+       return n;
 }
 EXPORT_SYMBOL_GPL(strncpy_from_user_nocheck);
 


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to