Rizin
unix-like reverse engineering framework and cli tools
sfsyscall.h
Go to the documentation of this file.
1 // ssed on the registers rdi, rsi, rdx, r10, r8 and r9
2 /*
3  * sfsyscall.h --- SFLib syscall macros for OpenBSD/i386
4  * see http://www.secdev.org/projects/shellforge.html for more informations
5  *
6  * Copyright (C) 2004 Philippe Biondi <phil@secdev.org>
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  */
17 
18 #ifndef SFSYSCALL_H
19 #define SFSYSCALL_H
20 
21 #ifdef SF_USE_ERRNO
22 /* Remove errno stuff */
23 int errno;
24 #error "SF_USER_ERRNO not supported yet"
25 #else
26 #define __sfsyscall_return(type, res) \
27  do { \
28  return (type)(res); \
29  } while (0)
30 #endif
31 
32 /* syscall macros */
33 
34 #define _sfsyscall0(type, name) \
35  type name(void) { \
36  long __res; \
37  __asm__ volatile("syscall" \
38  : "=a"(__res) \
39  : "0"(0x2000000 | __NR_##name)); \
40  __sfsyscall_return(type, __res); \
41  }
42 
43 #define _sfsyscall1(type, name, type1, arg1) \
44  type name(type1 arg1) { \
45  long __res; \
46  __asm__ volatile("mov %2, %%rdi\n\t" \
47  "syscall\n\t" \
48  : "=a"(__res) \
49  : "0"(0x2000000 | __NR_##name), "g"((long)(arg1))); \
50  __sfsyscall_return(type, __res); \
51  }
52 
53 #define _sfsyscall2(type, name, type1, arg1, type2, arg2) \
54  type name(type1 arg1, type2 arg2) { \
55  long __res; \
56  __asm__ volatile("mov %2, %%rdi\n\t" \
57  "mov %3, %%rsi\n\t" \
58  "syscall\n\t" \
59  : "=a"(__res) \
60  : "0"(0x2000000 | __NR_##name), "g"((long)(arg1)), "g"((long)(arg2))); \
61  __sfsyscall_return(type, __res); \
62  }
63 
64 #define _sfsyscall3ipi(type, name, type1, arg1, type2, arg2, type3, arg3) \
65  type name(type1 arg1, type2 arg2, type3 arg3) { \
66  long __res; \
67  __asm__ volatile("mov %4, %%rdx\n\t" \
68  "syscall\n\t" \
69  : "=a"(__res) \
70  : "0"(0x2000000 | __NR_##name), \
71  "D"(arg1), \
72  "S"(arg2), \
73  "g"((long)(arg3))); \
74  __sfsyscall_return(type, __res); \
75  }
76 
77 #define _sfsyscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
78  type name(type1 arg1, type2 arg2, type3 arg3) { \
79  long __res; \
80  __asm__ volatile("mov %2, %%rdi\n\t" \
81  "mov %3, %%rsi\n\t" \
82  "mov %4, %%rdx\n\t" \
83  "syscall\n\t" \
84  : "=a"(__res) \
85  : "0"(0x2000000 | __NR_##name), "g"((long)(arg1)), "g"((long)(arg2)), \
86  "g"((long)(arg3))); \
87  __sfsyscall_return(type, __res); \
88  }
89 
90 #define _sfsyscall4(type, name, type1, arg1, type2, arg2, type3, arg3, type4, arg4) \
91  type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
92  long __res; \
93  __asm__ volatile("mov %2, %%rdi\n\t" \
94  "mov %3, %%rsi\n\t" \
95  "mov %4, %%rdx\n\t" \
96  "mov %5, %%r10\n\t" \
97  "syscall\n\t" \
98  : "=a"(__res) \
99  : "0"(0x2000000 | __NR_##name), "g"((long)(arg1)), "c"((long)(arg2)), \
100  "d"((long)(arg3)), "S"((long)(arg4))); \
101  __sfsyscall_return(type, __res); \
102  }
103 
104 #define _sfsyscall5(type, name, type1, arg1, type2, arg2, type3, arg3, type4, arg4, \
105  type5, arg5) \
106  type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) { \
107  long __res; \
108  __asm__ volatile("mov %2, %%rdi\n\t" \
109  "mov %3, %%rsi\n\t" \
110  "mov %4, %%rdx\n\t" \
111  "mov %5, %%r10\n\t" \
112  "mov %6, %%r8\n\t" \
113  "syscall\n\t" \
114  : "=a"(__res) \
115  : "0"(0x2000000 | __NR_##name), "g"((long)(arg1)), "g"((long)(arg2)), \
116  "g"((long)(arg3)), "g"((long)(arg4)), "g"((long)(arg5))); \
117  __sfsyscall_return(type, __res); \
118  }
119 
120 #define _sfsyscall6(type, name, type1, arg1, type2, arg2, type3, arg3, type4, arg4, \
121  type5, arg5, type6, arg6) \
122  type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) { \
123  long __res; \
124  __asm__ volatile("mov %2, %%rdi\n\t" \
125  "mov %3, %%rsi\n\t" \
126  "mov %4, %%rdx\n\t" \
127  "mov %5, %%r10\n\t" \
128  "mov %6, %%r8\n\t" \
129  "mov %7, %%r9\n\t" \
130  "syscall\n\t" \
131  : "=a"(__res) \
132  : "0"(0x2000000 | __NR_##name), "g"((long)(arg1)), "g"((long)(arg2)), \
133  "g"((long)(arg3)), "g"((long)(arg4)), "g"((long)(arg5)), \
134  "g"((long)(arg6))); \
135  __sfsyscall_return(type, __res); \
136  }
137 
138 #endif /* SFSYSCALL_H */