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>
12 #define STUB_MMAP_NR __NR_mmap
13 #define MMAP_OFFSET(o) (o)
15 #define __syscall_clobber "r11","rcx","memory"
16 #define __syscall "syscall"
18 static inline long stub_syscall0(long syscall)
22 __asm__ volatile (__syscall
24 : "0" (syscall) : __syscall_clobber );
29 static inline long stub_syscall2(long syscall, long arg1, long arg2)
33 __asm__ volatile (__syscall
35 : "0" (syscall), "D" (arg1), "S" (arg2) : __syscall_clobber );
40 static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
44 __asm__ volatile (__syscall
46 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3)
47 : __syscall_clobber );
52 static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
57 __asm__ volatile ("movq %5,%%r10 ; " __syscall
59 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
61 : __syscall_clobber, "r10" );
66 static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
71 __asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; " __syscall
73 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
74 "g" (arg4), "g" (arg5)
75 : __syscall_clobber, "r10", "r8" );
80 static inline void trap_myself(void)
85 static inline void remap_stack_and_trap(void)
92 "movq %%rdi,%%r8 ; addq %3,%%r8 ; movq (%%r8),%%r8 ;"
93 "movq %%rdi,%%r9 ; addq %4,%%r9 ; movq (%%r9),%%r9 ;"
95 "movq %%rsp,%%rdi ; andq %1,%%rdi ;"
96 "addq %5,%%rdi ; movq %%rax, (%%rdi) ;"
100 "g" (~(UM_KERN_PAGE_SIZE - 1)),
101 "g" (MAP_FIXED | MAP_SHARED),
102 "g" (UML_STUB_FIELD_FD),
103 "g" (UML_STUB_FIELD_OFFSET),
104 "g" (UML_STUB_FIELD_CHILD_ERR),
105 "S" (UM_KERN_PAGE_SIZE),
106 "d" (PROT_READ | PROT_WRITE)
108 __syscall_clobber, "r10", "r8", "r9");
111 static __always_inline void *get_stub_page(void)
119 : "g" (~(UM_KERN_PAGE_SIZE - 1)));