1 //===-- sanitizer_syscall_linux_aarch64.inc --------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Implementations of internal_syscall and internal_iserror for Linux/aarch64.
11 //===----------------------------------------------------------------------===//
13 #define SYSCALL(name) __NR_ ## name
15 static uptr __internal_syscall(u64 nr) {
16 register u64 x8 asm("x8") = nr;
17 register u64 x0 asm("x0");
24 #define __internal_syscall0(n) \
25 (__internal_syscall)(n)
27 static uptr __internal_syscall(u64 nr, u64 arg1) {
28 register u64 x8 asm("x8") = nr;
29 register u64 x0 asm("x0") = arg1;
36 #define __internal_syscall1(n, a1) \
37 (__internal_syscall)(n, (u64)(a1))
39 static uptr __internal_syscall(u64 nr, u64 arg1, long arg2) {
40 register u64 x8 asm("x8") = nr;
41 register u64 x0 asm("x0") = arg1;
42 register u64 x1 asm("x1") = arg2;
45 : "r"(x8), "0"(x0), "r"(x1)
49 #define __internal_syscall2(n, a1, a2) \
50 (__internal_syscall)(n, (u64)(a1), (long)(a2))
52 static uptr __internal_syscall(u64 nr, u64 arg1, long arg2, long arg3) {
53 register u64 x8 asm("x8") = nr;
54 register u64 x0 asm("x0") = arg1;
55 register u64 x1 asm("x1") = arg2;
56 register u64 x2 asm("x2") = arg3;
59 : "r"(x8), "0"(x0), "r"(x1), "r"(x2)
63 #define __internal_syscall3(n, a1, a2, a3) \
64 (__internal_syscall)(n, (u64)(a1), (long)(a2), (long)(a3))
66 static uptr __internal_syscall(u64 nr, u64 arg1, long arg2, long arg3,
68 register u64 x8 asm("x8") = nr;
69 register u64 x0 asm("x0") = arg1;
70 register u64 x1 asm("x1") = arg2;
71 register u64 x2 asm("x2") = arg3;
72 register u64 x3 asm("x3") = arg4;
75 : "r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3)
79 #define __internal_syscall4(n, a1, a2, a3, a4) \
80 (__internal_syscall)(n, (u64)(a1), (long)(a2), (long)(a3), (long)(a4))
82 static uptr __internal_syscall(u64 nr, u64 arg1, long arg2, long arg3,
83 u64 arg4, long arg5) {
84 register u64 x8 asm("x8") = nr;
85 register u64 x0 asm("x0") = arg1;
86 register u64 x1 asm("x1") = arg2;
87 register u64 x2 asm("x2") = arg3;
88 register u64 x3 asm("x3") = arg4;
89 register u64 x4 asm("x4") = arg5;
92 : "r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4)
96 #define __internal_syscall5(n, a1, a2, a3, a4, a5) \
97 (__internal_syscall)(n, (u64)(a1), (long)(a2), (long)(a3), (long)(a4), \
100 static uptr __internal_syscall(u64 nr, u64 arg1, long arg2, long arg3,
101 u64 arg4, long arg5, long arg6) {
102 register u64 x8 asm("x8") = nr;
103 register u64 x0 asm("x0") = arg1;
104 register u64 x1 asm("x1") = arg2;
105 register u64 x2 asm("x2") = arg3;
106 register u64 x3 asm("x3") = arg4;
107 register u64 x4 asm("x4") = arg5;
108 register u64 x5 asm("x5") = arg6;
111 : "r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4), "r"(x5)
115 #define __internal_syscall6(n, a1, a2, a3, a4, a5, a6) \
116 (__internal_syscall)(n, (u64)(a1), (long)(a2), (long)(a3), (long)(a4), \
117 (u64)(a5), (long)(a6))
119 #define __SYSCALL_NARGS_X(a1, a2, a3, a4, a5, a6, a7, a8, n, ...) n
120 #define __SYSCALL_NARGS(...) \
121 __SYSCALL_NARGS_X(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0, )
122 #define __SYSCALL_CONCAT_X(a, b) a##b
123 #define __SYSCALL_CONCAT(a, b) __SYSCALL_CONCAT_X(a, b)
124 #define __SYSCALL_DISP(b, ...) \
125 __SYSCALL_CONCAT(b, __SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)
127 #define internal_syscall(...) __SYSCALL_DISP(__internal_syscall, __VA_ARGS__)
129 // Helper function used to avoid cobbler errno.
130 bool internal_iserror(uptr retval, int *rverrno) {
131 if (retval >= (uptr)-4095) {