Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 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 <asm/unistd.h> |
| 11 | |
| 12 | extern void stub_segv_handler(int sig); |
Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 13 | extern void stub_clone_handler(void); |
Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 14 | |
| 15 | #define STUB_SYSCALL_RET EAX |
| 16 | #define STUB_MMAP_NR __NR_mmap2 |
| 17 | #define MMAP_OFFSET(o) ((o) >> PAGE_SHIFT) |
| 18 | |
Jeff Dike | 17d4697 | 2005-11-21 21:32:09 -0800 | [diff] [blame^] | 19 | static inline long stub_syscall0(long syscall) |
| 20 | { |
| 21 | long ret; |
| 22 | |
| 23 | __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall)); |
| 24 | |
| 25 | return ret; |
| 26 | } |
| 27 | |
Paolo 'Blaisorblade' Giarrusso | 4f02724 | 2005-11-07 00:58:46 -0800 | [diff] [blame] | 28 | static inline long stub_syscall1(long syscall, long arg1) |
| 29 | { |
| 30 | long ret; |
| 31 | |
| 32 | __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1)); |
| 33 | |
| 34 | return ret; |
| 35 | } |
| 36 | |
Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 37 | static inline long stub_syscall2(long syscall, long arg1, long arg2) |
| 38 | { |
| 39 | long ret; |
| 40 | |
Paolo 'Blaisorblade' Giarrusso | 4f02724 | 2005-11-07 00:58:46 -0800 | [diff] [blame] | 41 | __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1), |
| 42 | "c" (arg2)); |
| 43 | |
| 44 | return ret; |
Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3) |
| 48 | { |
Paolo 'Blaisorblade' Giarrusso | 4f02724 | 2005-11-07 00:58:46 -0800 | [diff] [blame] | 49 | long ret; |
| 50 | |
| 51 | __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1), |
| 52 | "c" (arg2), "d" (arg3)); |
| 53 | |
| 54 | return ret; |
Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3, |
| 58 | long arg4) |
| 59 | { |
Paolo 'Blaisorblade' Giarrusso | 4f02724 | 2005-11-07 00:58:46 -0800 | [diff] [blame] | 60 | long ret; |
| 61 | |
| 62 | __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1), |
| 63 | "c" (arg2), "d" (arg3), "S" (arg4)); |
| 64 | |
| 65 | return ret; |
| 66 | } |
| 67 | |
| 68 | static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3, |
| 69 | long arg4, long arg5) |
| 70 | { |
| 71 | long ret; |
| 72 | |
| 73 | __asm__ volatile ("int $0x80" : "=a" (ret) : "0" (syscall), "b" (arg1), |
| 74 | "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5)); |
| 75 | |
| 76 | return ret; |
Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static inline long stub_syscall6(long syscall, long arg1, long arg2, long arg3, |
| 80 | long arg4, long arg5, long arg6) |
| 81 | { |
| 82 | long ret; |
Paolo 'Blaisorblade' Giarrusso | 4f02724 | 2005-11-07 00:58:46 -0800 | [diff] [blame] | 83 | |
| 84 | __asm__ volatile ("push %%ebp ; movl %%eax,%%ebp ; movl %1,%%eax ; " |
| 85 | "int $0x80 ; pop %%ebp" |
| 86 | : "=a" (ret) |
| 87 | : "g" (syscall), "b" (arg1), "c" (arg2), "d" (arg3), |
| 88 | "S" (arg4), "D" (arg5), "0" (arg6)); |
| 89 | |
| 90 | return ret; |
Bodo Stroesser | 9786a8f | 2005-07-07 17:56:50 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | static inline void trap_myself(void) |
| 94 | { |
| 95 | __asm("int3"); |
| 96 | } |
| 97 | |
Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 98 | #endif |