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/amd64
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  long __res; \
57  __asm__ volatile("###> " #name " <###\n\t" \
58  "syscall" \
59  : "=a" (__res) \
60  : "0" (__NR_##name) \
61  : "memory", "rcx", "r11", "cc" \
62  ); \
63  __sfsyscall_return(type,__res); \
64 }
65 
66 #define _sfsyscall1(type, name, type1, arg1) \
67 type name(type1 arg1) { \
68  long __res; \
69  register type1 rdi asm("rdi"); \
70  rdi = arg1; \
71  asm volatile("###> " #name "(%2) <###\n\t" \
72  "syscall" \
73  : "=a" (__res) \
74  : "0" (__NR_##name), \
75  "r" (rdi) \
76  : "memory", "rcx", "r11", "cc" \
77  ); \
78  __sfsyscall_return(type,__res); \
79 }
80 
81 #define _sfsyscall2(type, name, type1, arg1, type2, arg2) \
82  type name(type1 arg1, type2 arg2) { \
83  long __res; \
84  register type1 rdi asm("rdi"); \
85  register type2 rsi asm("rsi"); \
86  rdi = arg1; \
87  rsi = arg2; \
88  __asm__ volatile("###> " #name "(%2, %3) <###\n\t" \
89  "syscall" \
90  : "=a" (__res) \
91  : "0" (__NR_##name), \
92  "r" (rdi), \
93  "r" (rsi) \
94  : "memory", "rcx", "r11", "cc" \
95  ); \
96  __sfsyscall_return(type, __res); \
97 }
98 
99 #define _sfsyscall3(type, name, type1, arg1, type2, arg2, type3, arg3) \
100  type name(type1 arg1, type2 arg2, type3 arg3) { \
101  long __res; \
102  register type1 rdi asm("rdi"); \
103  register type2 rsi asm("rsi"); \
104  register type3 rdx asm("rdx"); \
105  rdi = arg1; \
106  rsi = arg2; \
107  rdx = arg3; \
108  asm volatile("###> " #name "(%2, %3, %4) <###\n\t" \
109  "syscall" \
110  : "=a" (__res) \
111  : "0" (__NR_##name), \
112  "r" (rdi), \
113  "r" (rsi), \
114  "r" (rdx) \
115  : "memory", "rcx", "r11", "cc" \
116  ); \
117  __sfsyscall_return(type, __res); \
118  }
119 
120 #define _sfsyscall4(type, name, type1, arg1, type2, arg2, type3, arg3, type4, arg4) \
121  type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
122  long __res; \
123  register type1 rdi asm("rdi"); \
124  register type2 rsi asm("rsi"); \
125  register type3 rdx asm("rdx"); \
126  register type4 r10 asm("r10"); \
127  rdi = arg1; \
128  rsi = arg2; \
129  rdx = arg3; \
130  r10 = arg4; \
131  asm volatile("###> " #name "(%2, %3, %4, %5) <###\n\t" \
132  "syscall" \
133  : "=a" (__res) \
134  : "0" (__NR_##name), \
135  "r" (rdi), \
136  "r" (rsi), \
137  "r" (rdx), \
138  "r" (r10) \
139  : "memory", "rcx", "r11", "cc" \
140  ); \
141  __sfsyscall_return(type, __res); \
142  }
143 
144 #define _sfsyscall5(type, name, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5) \
145  type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
146  type5 arg5) { \
147  long __res; \
148  register type1 rdi asm("rdi"); \
149  register type2 rsi asm("rsi"); \
150  register type3 rdx asm("rdx"); \
151  register type4 r10 asm("r10"); \
152  register type5 r8 asm("r8"); \
153  rdi = arg1; \
154  rsi = arg2; \
155  rdx = arg3; \
156  r10 = arg4; \
157  r8 = arg5; \
158  asm volatile("###> " #name "(%2, %3, %4, %5, %6) <###\n\t" \
159  "syscall" \
160  : "=a" (__res) \
161  : "0" (__NR_##name), \
162  "r" (rdi), \
163  "r" (rsi), \
164  "r" (rdx), \
165  "r" (r10), \
166  "r" (r8) \
167  : "memory", "rcx", "r11", "cc" \
168  ); \
169  __sfsyscall_return(type, __res); \
170  }
171 
172 #define _sfsyscall6(type, name, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5, type6, arg6)\
173  type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, \
174  type5 arg5, type6 arg6) { \
175  long __res; \
176  register type1 rdi asm("rdi"); \
177  register type2 rsi asm("rsi"); \
178  register type3 rdx asm("rdx"); \
179  register type4 r10 asm("r10"); \
180  register type5 r8 asm("r8"); \
181  register type6 r9 asm("r9"); \
182  rdi = arg1; \
183  rsi = arg2; \
184  rdx = arg3; \
185  r10 = arg4; \
186  r8 = arg5; \
187  r9 = arg6; \
188  asm volatile("###> " #name "(%2, %3, %4, %5, %6, %7) <###\n\t" \
189  "syscall" \
190  : "=a" (__res) \
191  : "0" (__NR_##name), \
192  "r" (rdi), \
193  "r" (rsi), \
194  "r" (rdx), \
195  "r" (r10), \
196  "r" (r8), \
197  "r" (r9) \
198  : "memory", "rcx", "r11", "cc" \
199  ); \
200  __sfsyscall_return(type, __res); \
201  }
202 
203 #endif /* SFSYSCALL_H */