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