stub_32.h (2334B)
1/* 2 * Copyright (C) 2004 Jeff Dike (jdike@addtoit.com) 3 * Licensed under the GPL 4 */ 5 6#ifndef __SYSDEP_STUB_H 7#define __SYSDEP_STUB_H 8 9#include <asm/ptrace.h> 10#include <generated/asm-offsets.h> 11 12#define STUB_MMAP_NR __NR_mmap2 13#define MMAP_OFFSET(o) ((o) >> UM_KERN_PAGE_SHIFT) 14 15static inline long stub_syscall0(long syscall) 16{ 17 long ret; 18 19 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall)); 20 21 return ret; 22} 23 24static inline long stub_syscall1(long syscall, long arg1) 25{ 26 long ret; 27 28 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1)); 29 30 return ret; 31} 32 33static inline long stub_syscall2(long syscall, long arg1, long arg2) 34{ 35 long ret; 36 37 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1), 38 "c" (arg2)); 39 40 return ret; 41} 42 43static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3) 44{ 45 long ret; 46 47 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1), 48 "c" (arg2), "d" (arg3)); 49 50 return ret; 51} 52 53static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3, 54 long arg4) 55{ 56 long ret; 57 58 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1), 59 "c" (arg2), "d" (arg3), "S" (arg4)); 60 61 return ret; 62} 63 64static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3, 65 long arg4, long arg5) 66{ 67 long ret; 68 69 __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1), 70 "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5)); 71 72 return ret; 73} 74 75static inline void trap_myself(void) 76{ 77 __asm("int3"); 78} 79 80static inline void remap_stack_and_trap(void) 81{ 82 __asm__ volatile ( 83 "movl %%esp,%%ebx ;" 84 "andl %0,%%ebx ;" 85 "movl %1,%%eax ;" 86 "movl %%ebx,%%edi ; addl %2,%%edi ; movl (%%edi),%%edi ;" 87 "movl %%ebx,%%ebp ; addl %3,%%ebp ; movl (%%ebp),%%ebp ;" 88 "int $0x80 ;" 89 "addl %4,%%ebx ; movl %%eax, (%%ebx) ;" 90 "int $3" 91 : : 92 "g" (~(UM_KERN_PAGE_SIZE - 1)), 93 "g" (STUB_MMAP_NR), 94 "g" (UML_STUB_FIELD_FD), 95 "g" (UML_STUB_FIELD_OFFSET), 96 "g" (UML_STUB_FIELD_CHILD_ERR), 97 "c" (UM_KERN_PAGE_SIZE), 98 "d" (PROT_READ | PROT_WRITE), 99 "S" (MAP_FIXED | MAP_SHARED) 100 : 101 "memory"); 102} 103 104static __always_inline void *get_stub_page(void) 105{ 106 unsigned long ret; 107 108 asm volatile ( 109 "movl %%esp,%0 ;" 110 "andl %1,%0" 111 : "=a" (ret) 112 : "g" (~(UM_KERN_PAGE_SIZE - 1))); 113 114 return (void *)ret; 115} 116#endif