1 //===-- sanitizer_syscall_linux_arm.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/arm.
10 //===----------------------------------------------------------------------===//
12 #define SYSCALL(name) __NR_ ## name
14 static uptr __internal_syscall(u32 nr) {
15 register u32 r8 asm("r7") = nr;
16 register u32 r0 asm("r0");
23 #define __internal_syscall0(n) \
24 (__internal_syscall)(n)
26 static uptr __internal_syscall(u32 nr, u32 arg1) {
27 register u32 r8 asm("r7") = nr;
28 register u32 r0 asm("r0") = arg1;
35 #define __internal_syscall1(n, a1) \
36 (__internal_syscall)(n, (u32)(a1))
38 static uptr __internal_syscall(u32 nr, u32 arg1, long arg2) {
39 register u32 r8 asm("r7") = nr;
40 register u32 r0 asm("r0") = arg1;
41 register u32 r1 asm("r1") = arg2;
44 : "r"(r8), "0"(r0), "r"(r1)
48 #define __internal_syscall2(n, a1, a2) \
49 (__internal_syscall)(n, (u32)(a1), (long)(a2))
51 static uptr __internal_syscall(u32 nr, u32 arg1, long arg2, long arg3) {
52 register u32 r8 asm("r7") = nr;
53 register u32 r0 asm("r0") = arg1;
54 register u32 r1 asm("r1") = arg2;
55 register u32 r2 asm("r2") = arg3;
58 : "r"(r8), "0"(r0), "r"(r1), "r"(r2)
62 #define __internal_syscall3(n, a1, a2, a3) \
63 (__internal_syscall)(n, (u32)(a1), (long)(a2), (long)(a3))
65 static uptr __internal_syscall(u32 nr, u32 arg1, long arg2, long arg3,
67 register u32 r8 asm("r7") = nr;
68 register u32 r0 asm("r0") = arg1;
69 register u32 r1 asm("r1") = arg2;
70 register u32 r2 asm("r2") = arg3;
71 register u32 r3 asm("r3") = arg4;
74 : "r"(r8), "0"(r0), "r"(r1), "r"(r2), "r"(r3)
78 #define __internal_syscall4(n, a1, a2, a3, a4) \
79 (__internal_syscall)(n, (u32)(a1), (long)(a2), (long)(a3), (long)(a4))
81 static uptr __internal_syscall(u32 nr, u32 arg1, long arg2, long arg3,
82 u32 arg4, long arg5) {
83 register u32 r8 asm("r7") = nr;
84 register u32 r0 asm("r0") = arg1;
85 register u32 r1 asm("r1") = arg2;
86 register u32 r2 asm("r2") = arg3;
87 register u32 r3 asm("r3") = arg4;
88 register u32 r4 asm("r4") = arg5;
91 : "r"(r8), "0"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4)
95 #define __internal_syscall5(n, a1, a2, a3, a4, a5) \
96 (__internal_syscall)(n, (u32)(a1), (long)(a2), (long)(a3), (long)(a4), \
99 static uptr __internal_syscall(u32 nr, u32 arg1, long arg2, long arg3,
100 u32 arg4, long arg5, long arg6) {
101 register u32 r8 asm("r7") = nr;
102 register u32 r0 asm("r0") = arg1;
103 register u32 r1 asm("r1") = arg2;
104 register u32 r2 asm("r2") = arg3;
105 register u32 r3 asm("r3") = arg4;
106 register u32 r4 asm("r4") = arg5;
107 register u32 r5 asm("r5") = arg6;
108 asm volatile("swi #0"
110 : "r"(r8), "0"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4), "r"(r5)
114 #define __internal_syscall6(n, a1, a2, a3, a4, a5, a6) \
115 (__internal_syscall)(n, (u32)(a1), (long)(a2), (long)(a3), (long)(a4), \
116 (u32)(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) {