Rizin
unix-like reverse engineering framework and cli tools
sfsyscall.h
Go to the documentation of this file.
1 /*
2  * sfsyscall.h --- SFLib syscall macros for Linux/i386
3  * see http://www.secdev.org/projects/shellforge.html for more informations
4  *
5  * Copyright (C) 2004 Philippe Biondi <phil@secdev.org>
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by
9  * the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  */
16 
17 
18 /*
19  * Automatically generated by gensflib.py
20  * Mon Mar 21 13:23:31 2022
21  */
22 
23 #ifndef SFSYSCALL_H
24 #define SFSYSCALL_H
25 
26 
27 /* $Id$ */
28 
29 #ifdef SF_USE_ERRNO
30 
31 static int errno=1234;
32 
33 #define __sfsyscall_return(type, res) \
34 do { \
35  if ((unsigned long)(res) >= (unsigned long)(-125)) { \
36  errno = -(res); \
37  res = -1; \
38  } \
39  return (type) (res); \
40 } while (0)
41 
42 #else /* SF_USE_ERRNO */
43 
44 #define __sfsyscall_return(type, res) \
45 do { \
46  return (type) (res); \
47 } while (0)
48 
49 #endif /* SF_USE_ERRNO */
50 
51 
52 /* syscall macros */
53 
54 #define _sfsyscall0(type,name) \
55 type name(void) \
56 { \
57 long __res; \
58 __asm__ volatile ("###> " #name "() <###\n\t" \
59  "int $0x80" \
60  : "=a" (__res) \
61  : "0" (__NR_##name)); \
62 __sfsyscall_return(type,__res); \
63 }
64 
65 #define _sfsyscall1(type,name,type1,arg1) \
66 type name(type1 arg1) \
67 { \
68 long __res; \
69 __asm__ volatile ("###> " #name "(%2) <###\n\t" \
70  "pushl %%ebx\n\t" \
71  "mov %2,%%ebx\n\t" \
72  "int $0x80\n\t" \
73  "popl %%ebx" \
74  : "=a" (__res) \
75  : "0" (__NR_##name),"g" ((long)(arg1))); \
76 __sfsyscall_return(type,__res); \
77 }
78 
79 #define _sfsyscall2(type,name,type1,arg1,type2,arg2) \
80 type name(type1 arg1,type2 arg2) \
81 { \
82 long __res; \
83 __asm__ volatile ("###> " #name "(%2, %3) <###\n\t" \
84  "pushl %%ebx\n\t" \
85  "mov %2,%%ebx\n\t" \
86  "int $0x80\n\t" \
87  "popl %%ebx" \
88  : "=a" (__res) \
89  : "0" (__NR_##name),"g" ((long)(arg1)),"c" ((long)(arg2)) ); \
90 __sfsyscall_return(type,__res); \
91 }
92 
93 #define _sfsyscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
94 type name(type1 arg1,type2 arg2,type3 arg3) \
95 { \
96 long __res; \
97 __asm__ volatile ("###> " #name "(%2, %3, %4) <###\n\t" \
98  "pushl %%ebx\n\t" \
99  "mov %2,%%ebx\n\t" \
100  "int $0x80\n\t" \
101  "popl %%ebx" \
102  : "=a" (__res) \
103  : "0" (__NR_##name),"g" ((long)(arg1)),"c" ((long)(arg2)), \
104  "d" ((long)(arg3)) ); \
105 __sfsyscall_return(type,__res); \
106 }
107 
108 #define _sfsyscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
109 type name (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
110 { \
111 long __res; \
112 __asm__ volatile ("###> " #name "(%2, %3, %4, %5) <###\n\t" \
113  "pushl %%ebx\n\t" \
114  "mov %2,%%ebx\n\t" \
115  "int $0x80\n\t" \
116  "popl %%ebx" \
117  : "=a" (__res) \
118  : "0" (__NR_##name),"g" ((long)(arg1)),"c" ((long)(arg2)), \
119  "d" ((long)(arg3)),"S" ((long)(arg4)) ); \
120 __sfsyscall_return(type,__res); \
121 }
122 
123 #define _sfsyscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
124  type5,arg5) \
125 type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
126 { \
127 long __res; \
128 __asm__ volatile ("###> " #name "(%2, %3, %4, %5, %6) <###\n\t" \
129  "pushl %%ebx\n\t" \
130  "mov %2,%%ebx\n\t" \
131  "int $0x80\n\t" \
132  "popl %%ebx" \
133  : "=a" (__res) \
134  : "0" (__NR_##name),"g" ((long)(arg1)),"c" ((long)(arg2)), \
135  "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \
136 __sfsyscall_return(type,__res); \
137 }
138 
139 #define _sfsyscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
140  type5,arg5,type6,arg6) \
141 type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, type6 arg6) \
142 { \
143 long __res; \
144 __asm__ volatile ("##> " #name "(%2, %3, %4, %5, %6, %7) <###\n\t" \
145  "pushl %%ebx\n\t" \
146  "pushl %%ebp\n\t" \
147  "movl %2,%%ebx\n\t" \
148  "movl %7,%%ebp\n\t" \
149  "int $0x80\n\t" \
150  "popl %%ebp\n\t" \
151  "popl %%ebx" \
152  : "=a" (__res) \
153  : "0" (__NR_##name),"g" ((long)(arg1)),"c" ((long)(arg2)), \
154  "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)), \
155  "g" ((long)(arg6))); \
156 __sfsyscall_return(type,__res); \
157 }
158 
159 
160 #define _sfoldsyscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
161  type5,arg5,type6,arg6) \
162 type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, type6 arg6) \
163 { \
164 long __res; \
165 __asm__ volatile ("pushl %%ebx\n\t" \
166  "pushl %7\n\t" \
167  "pushl %6\n\t" \
168  "pushl %5\n\t" \
169  "pushl %4\n\t" \
170  "pushl %3\n\t" \
171  "pushl %2\n\t" \
172  "movl %%esp, %%ebx\n\t" \
173  "int $0x80\n\t" \
174  "add $0x18,%%esp\n\t" \
175  "popl %%ebx" \
176  : "=a" (__res) \
177  : "0" (__NR_##name),"g" ((long)(arg1)),"g" ((long)(arg2)), \
178  "g" ((long)(arg3)),"g" ((long)(arg4)),"g" ((long)(arg5)), \
179  "g" ((long)(arg6))); \
180 __sfsyscall_return(type,__res); \
181 }
182 
183 
184 #endif /* SFSYSCALL_H */