0001
0002
0003
0004
0005
0006 #ifndef __SYSDEP_STUB_H
0007 #define __SYSDEP_STUB_H
0008
0009 #include <asm/ptrace.h>
0010 #include <generated/asm-offsets.h>
0011
0012 #define STUB_MMAP_NR __NR_mmap2
0013 #define MMAP_OFFSET(o) ((o) >> UM_KERN_PAGE_SHIFT)
0014
0015 static inline long stub_syscall0(long syscall)
0016 {
0017 long ret;
0018
0019 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall));
0020
0021 return ret;
0022 }
0023
0024 static inline long stub_syscall1(long syscall, long arg1)
0025 {
0026 long ret;
0027
0028 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1));
0029
0030 return ret;
0031 }
0032
0033 static inline long stub_syscall2(long syscall, long arg1, long arg2)
0034 {
0035 long ret;
0036
0037 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
0038 "c" (arg2));
0039
0040 return ret;
0041 }
0042
0043 static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
0044 {
0045 long ret;
0046
0047 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
0048 "c" (arg2), "d" (arg3));
0049
0050 return ret;
0051 }
0052
0053 static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
0054 long arg4)
0055 {
0056 long ret;
0057
0058 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
0059 "c" (arg2), "d" (arg3), "S" (arg4));
0060
0061 return ret;
0062 }
0063
0064 static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
0065 long arg4, long arg5)
0066 {
0067 long ret;
0068
0069 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1),
0070 "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5));
0071
0072 return ret;
0073 }
0074
0075 static inline void trap_myself(void)
0076 {
0077 __asm("int3");
0078 }
0079
0080 static inline void remap_stack_and_trap(void)
0081 {
0082 __asm__ volatile (
0083 "movl %%esp,%%ebx ;"
0084 "andl %0,%%ebx ;"
0085 "movl %1,%%eax ;"
0086 "movl %%ebx,%%edi ; addl %2,%%edi ; movl (%%edi),%%edi ;"
0087 "movl %%ebx,%%ebp ; addl %3,%%ebp ; movl (%%ebp),%%ebp ;"
0088 "int $0x80 ;"
0089 "addl %4,%%ebx ; movl %%eax, (%%ebx) ;"
0090 "int $3"
0091 : :
0092 "g" (~(UM_KERN_PAGE_SIZE - 1)),
0093 "g" (STUB_MMAP_NR),
0094 "g" (UML_STUB_FIELD_FD),
0095 "g" (UML_STUB_FIELD_OFFSET),
0096 "g" (UML_STUB_FIELD_CHILD_ERR),
0097 "c" (UM_KERN_PAGE_SIZE),
0098 "d" (PROT_READ | PROT_WRITE),
0099 "S" (MAP_FIXED | MAP_SHARED)
0100 :
0101 "memory");
0102 }
0103
0104 static __always_inline void *get_stub_page(void)
0105 {
0106 unsigned long ret;
0107
0108 asm volatile (
0109 "movl %%esp,%0 ;"
0110 "andl %1,%0"
0111 : "=a" (ret)
0112 : "g" (~(UM_KERN_PAGE_SIZE - 1)));
0113
0114 return (void *)ret;
0115 }
0116 #endif