1 //===-- sanitizer_syscall_linux_aarch64.inc --------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // Implementations of internal_syscall and internal_iserror for Linux/aarch64.
10 //===----------------------------------------------------------------------===//
12 #define SYSCALL(name) __NR_ ## name
14 static uptr __internal_syscall(u64 nr) {
15 register u64 x8 asm("x8") = nr;
16 register u64 x0 asm("x0");
23 #define __internal_syscall0(n) \
24 (__internal_syscall)(n)
26 static uptr __internal_syscall(u64 nr, u64 arg1) {
27 register u64 x8 asm("x8") = nr;
28 register u64 x0 asm("x0") = arg1;
35 #define __internal_syscall1(n, a1) \
36 (__internal_syscall)(n, (u64)(a1))
38 static uptr __internal_syscall(u64 nr, u64 arg1, long arg2) {
39 register u64 x8 asm("x8") = nr;
40 register u64 x0 asm("x0") = arg1;
41 register u64 x1 asm("x1") = arg2;
44 : "r"(x8), "0"(x0), "r"(x1)
48 #define __internal_syscall2(n, a1, a2) \
49 (__internal_syscall)(n, (u64)(a1), (long)(a2))
51 static uptr __internal_syscall(u64 nr, u64 arg1, long arg2, long arg3) {
52 register u64 x8 asm("x8") = nr;
53 register u64 x0 asm("x0") = arg1;
54 register u64 x1 asm("x1") = arg2;
55 register u64 x2 asm("x2") = arg3;
58 : "r"(x8), "0"(x0), "r"(x1), "r"(x2)
62 #define __internal_syscall3(n, a1, a2, a3) \
63 (__internal_syscall)(n, (u64)(a1), (long)(a2), (long)(a3))
65 static uptr __internal_syscall(u64 nr, u64 arg1, long arg2, long arg3,
67 register u64 x8 asm("x8") = nr;
68 register u64 x0 asm("x0") = arg1;
69 register u64 x1 asm("x1") = arg2;
70 register u64 x2 asm("x2") = arg3;
71 register u64 x3 asm("x3") = arg4;
74 : "r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3)
78 #define __internal_syscall4(n, a1, a2, a3, a4) \
79 (__internal_syscall)(n, (u64)(a1), (long)(a2), (long)(a3), (long)(a4))
81 static uptr __internal_syscall(u64 nr, u64 arg1, long arg2, long arg3,
82 u64 arg4, long arg5) {
83 register u64 x8 asm("x8") = nr;
84 register u64 x0 asm("x0") = arg1;
85 register u64 x1 asm("x1") = arg2;
86 register u64 x2 asm("x2") = arg3;
87 register u64 x3 asm("x3") = arg4;
88 register u64 x4 asm("x4") = arg5;
91 : "r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4)
95 #define __internal_syscall5(n, a1, a2, a3, a4, a5) \
96 (__internal_syscall)(n, (u64)(a1), (long)(a2), (long)(a3), (long)(a4), \
99 static uptr __internal_syscall(u64 nr, u64 arg1, long arg2, long arg3,
100 u64 arg4, long arg5, long arg6) {
101 register u64 x8 asm("x8") = nr;
102 register u64 x0 asm("x0") = arg1;
103 register u64 x1 asm("x1") = arg2;
104 register u64 x2 asm("x2") = arg3;
105 register u64 x3 asm("x3") = arg4;
106 register u64 x4 asm("x4") = arg5;
107 register u64 x5 asm("x5") = arg6;
110 : "r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4), "r"(x5)
114 #define __internal_syscall6(n, a1, a2, a3, a4, a5, a6) \
115 (__internal_syscall)(n, (u64)(a1), (long)(a2), (long)(a3), (long)(a4), \
116 (u64)(a5), (long)(a6))
118 #define __SYSCALL_NARGS_X(a1, a2, a3, a4, a5, a6, a7, a8, n, ...) n
119 #define __SYSCALL_NARGS(...) \
120 __SYSCALL_NARGS_X(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0, )
121 #define __SYSCALL_CONCAT_X(a, b) a##b
122 #define __SYSCALL_CONCAT(a, b) __SYSCALL_CONCAT_X(a, b)
123 #define __SYSCALL_DISP(b, ...) \
124 __SYSCALL_CONCAT(b, __SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)
126 #define internal_syscall(...) __SYSCALL_DISP(__internal_syscall, __VA_ARGS__)
128 // Helper function used to avoid cobbler errno.
129 bool internal_iserror(uptr retval, int *rverrno) {
130 if (retval >= (uptr)-4095) {