2 * Copyright (C) 2004 Jeff Dike (jdike@addtoit.com)
3 * Licensed under the GPL
6 #ifndef __SYSDEP_STUB_H
7 #define __SYSDEP_STUB_H
9 #include <sysdep/ptrace_user.h>
10 #include <generated/asm-offsets.h>
11 #include <linux/stddef.h>
13 #define STUB_MMAP_NR __NR_mmap
14 #define MMAP_OFFSET(o) (o)
16 #define __syscall_clobber "r11","rcx","memory"
17 #define __syscall "syscall"
19 static inline long stub_syscall0(long syscall)
23 __asm__ volatile (__syscall
25 : "0" (syscall) : __syscall_clobber );
30 static inline long stub_syscall2(long syscall, long arg1, long arg2)
34 __asm__ volatile (__syscall
36 : "0" (syscall), "D" (arg1), "S" (arg2) : __syscall_clobber );
41 static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
45 __asm__ volatile (__syscall
47 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3)
48 : __syscall_clobber );
53 static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
58 __asm__ volatile ("movq %5,%%r10 ; " __syscall
60 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
62 : __syscall_clobber, "r10" );
67 static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
72 __asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; " __syscall
74 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
75 "g" (arg4), "g" (arg5)
76 : __syscall_clobber, "r10", "r8" );
81 static inline void trap_myself(void)
86 static inline void remap_stack_and_trap(void)
93 "movq %%rdi,%%r8 ; addq %3,%%r8 ; movq (%%r8),%%r8 ;"
94 "movq %%rdi,%%r9 ; addq %4,%%r9 ; movq (%%r9),%%r9 ;"
96 "movq %%rsp,%%rdi ; andq %1,%%rdi ;"
97 "addq %5,%%rdi ; movq %%rax, (%%rdi) ;"
101 "g" (~(STUB_DATA_PAGES * UM_KERN_PAGE_SIZE - 1)),
102 "g" (MAP_FIXED | MAP_SHARED),
103 "g" (UML_STUB_FIELD_FD),
104 "g" (UML_STUB_FIELD_OFFSET),
105 "g" (UML_STUB_FIELD_CHILD_ERR),
106 "S" (STUB_DATA_PAGES * UM_KERN_PAGE_SIZE),
107 "d" (PROT_READ | PROT_WRITE)
109 __syscall_clobber, "r10", "r8", "r9");
112 static __always_inline void *get_stub_data(void)
120 : "g" (~(STUB_DATA_PAGES * UM_KERN_PAGE_SIZE - 1)));