1 //===-- sanitizer_syscall_linux_arm.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/arm.
11 //===----------------------------------------------------------------------===//
13 #define SYSCALL(name) __NR_ ## name
15 static uptr __internal_syscall(u32 nr) {
16 register u32 r8 asm("r7") = nr;
17 register u32 r0 asm("r0");
24 #define __internal_syscall0(n) \
25 (__internal_syscall)(n)
27 static uptr __internal_syscall(u32 nr, u32 arg1) {
28 register u32 r8 asm("r7") = nr;
29 register u32 r0 asm("r0") = arg1;
36 #define __internal_syscall1(n, a1) \
37 (__internal_syscall)(n, (u32)(a1))
39 static uptr __internal_syscall(u32 nr, u32 arg1, long arg2) {
40 register u32 r8 asm("r7") = nr;
41 register u32 r0 asm("r0") = arg1;
42 register u32 r1 asm("r1") = arg2;
45 : "r"(r8), "0"(r0), "r"(r1)
49 #define __internal_syscall2(n, a1, a2) \
50 (__internal_syscall)(n, (u32)(a1), (long)(a2))
52 static uptr __internal_syscall(u32 nr, u32 arg1, long arg2, long arg3) {
53 register u32 r8 asm("r7") = nr;
54 register u32 r0 asm("r0") = arg1;
55 register u32 r1 asm("r1") = arg2;
56 register u32 r2 asm("r2") = arg3;
59 : "r"(r8), "0"(r0), "r"(r1), "r"(r2)
63 #define __internal_syscall3(n, a1, a2, a3) \
64 (__internal_syscall)(n, (u32)(a1), (long)(a2), (long)(a3))
66 static uptr __internal_syscall(u32 nr, u32 arg1, long arg2, long arg3,
68 register u32 r8 asm("r7") = nr;
69 register u32 r0 asm("r0") = arg1;
70 register u32 r1 asm("r1") = arg2;
71 register u32 r2 asm("r2") = arg3;
72 register u32 r3 asm("r3") = arg4;
75 : "r"(r8), "0"(r0), "r"(r1), "r"(r2), "r"(r3)
79 #define __internal_syscall4(n, a1, a2, a3, a4) \
80 (__internal_syscall)(n, (u32)(a1), (long)(a2), (long)(a3), (long)(a4))
82 static uptr __internal_syscall(u32 nr, u32 arg1, long arg2, long arg3,
83 u32 arg4, long arg5) {
84 register u32 r8 asm("r7") = nr;
85 register u32 r0 asm("r0") = arg1;
86 register u32 r1 asm("r1") = arg2;
87 register u32 r2 asm("r2") = arg3;
88 register u32 r3 asm("r3") = arg4;
89 register u32 r4 asm("r4") = arg5;
92 : "r"(r8), "0"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4)
96 #define __internal_syscall5(n, a1, a2, a3, a4, a5) \
97 (__internal_syscall)(n, (u32)(a1), (long)(a2), (long)(a3), (long)(a4), \
100 static uptr __internal_syscall(u32 nr, u32 arg1, long arg2, long arg3,
101 u32 arg4, long arg5, long arg6) {
102 register u32 r8 asm("r7") = nr;
103 register u32 r0 asm("r0") = arg1;
104 register u32 r1 asm("r1") = arg2;
105 register u32 r2 asm("r2") = arg3;
106 register u32 r3 asm("r3") = arg4;
107 register u32 r4 asm("r4") = arg5;
108 register u32 r5 asm("r5") = arg6;
109 asm volatile("swi #0"
111 : "r"(r8), "0"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4), "r"(r5)
115 #define __internal_syscall6(n, a1, a2, a3, a4, a5, a6) \
116 (__internal_syscall)(n, (u32)(a1), (long)(a2), (long)(a3), (long)(a4), \
117 (u32)(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) {