um: rework userspace stubs to not hard-code stub location
[linux-2.6-microblaze.git] / arch / x86 / um / shared / sysdep / stub_64.h
index b7b8b8e..6e2626b 100644 (file)
@@ -7,8 +7,8 @@
 #define __SYSDEP_STUB_H
 
 #include <sysdep/ptrace_user.h>
+#include <generated/asm-offsets.h>
 
-#define STUB_SYSCALL_RET PT_INDEX(RAX)
 #define STUB_MMAP_NR __NR_mmap
 #define MMAP_OFFSET(o) (o)
 
@@ -82,18 +82,30 @@ static inline void trap_myself(void)
        __asm("int3");
 }
 
-static inline void remap_stack(long fd, unsigned long offset)
+static inline void remap_stack_and_trap(void)
 {
-       __asm__ volatile ("movq %4,%%r10 ; movq %5,%%r8 ; "
-                         "movq %6, %%r9; " __syscall "; movq %7, %%rbx ; "
-                         "movq %%rax, (%%rbx)":
-                         : "a" (STUB_MMAP_NR), "D" (STUB_DATA),
-                           "S" (UM_KERN_PAGE_SIZE),
-                           "d" (PROT_READ | PROT_WRITE),
-                            "g" (MAP_FIXED | MAP_SHARED), "g" (fd),
-                           "g" (offset),
-                           "i" (&((struct stub_data *) STUB_DATA)->child_err)
-                         : __syscall_clobber, "r10", "r8", "r9" );
+       __asm__ volatile (
+               "movq %0,%%rax ;"
+               "movq %%rsp,%%rdi ;"
+               "andq %1,%%rdi ;"
+               "movq %2,%%r10 ;"
+               "movq %%rdi,%%r8 ; addq %3,%%r8 ; movq (%%r8),%%r8 ;"
+               "movq %%rdi,%%r9 ; addq %4,%%r9 ; movq (%%r9),%%r9 ;"
+               __syscall ";"
+               "movq %%rsp,%%rdi ; andq %1,%%rdi ;"
+               "addq %5,%%rdi ; movq %%rax, (%%rdi) ;"
+               "int3"
+               : :
+               "g" (STUB_MMAP_NR),
+               "g" (~(UM_KERN_PAGE_SIZE - 1)),
+               "g" (MAP_FIXED | MAP_SHARED),
+               "g" (UML_STUB_FIELD_FD),
+               "g" (UML_STUB_FIELD_OFFSET),
+               "g" (UML_STUB_FIELD_CHILD_ERR),
+               "S" (UM_KERN_PAGE_SIZE),
+               "d" (PROT_READ | PROT_WRITE)
+               :
+               __syscall_clobber, "r10", "r8", "r9");
 }
 
 #endif