]>
Commit | Line | Data |
---|---|---|
04277e02 | 1 | /* Copyright (C) 2005-2019 Free Software Foundation, Inc. |
554066b8 MS |
2 | |
3 | This file is part of the GNU C Library. | |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public License as | |
7 | published by the Free Software Foundation; either version 2.1 of the | |
8 | License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library; if not, see | |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
554066b8 MS |
18 | |
19 | #ifndef _LINUX_AARCH64_SYSDEP_H | |
20 | #define _LINUX_AARCH64_SYSDEP_H 1 | |
21 | ||
22 | #include <sysdeps/unix/sysdep.h> | |
23 | #include <sysdeps/aarch64/sysdep.h> | |
24 | #include <sysdeps/unix/sysv/linux/generic/sysdep.h> | |
25 | ||
26 | /* Defines RTLD_PRIVATE_ERRNO and USE_DL_SYSINFO. */ | |
27 | #include <dl-sysdep.h> | |
28 | ||
29 | #include <tls.h> | |
30 | ||
31 | /* In order to get __set_errno() definition in INLINE_SYSCALL. */ | |
32 | #ifndef __ASSEMBLER__ | |
33 | #include <errno.h> | |
34 | #endif | |
35 | ||
36 | /* For Linux we can use the system call table in the header file | |
37 | /usr/include/asm/unistd.h | |
38 | of the kernel. But these symbols do not follow the SYS_* syntax | |
39 | so we have to redefine the `SYS_ify' macro here. */ | |
40 | #undef SYS_ify | |
41 | #define SYS_ify(syscall_name) (__NR_##syscall_name) | |
42 | ||
43 | #ifdef __ASSEMBLER__ | |
44 | ||
45 | /* Linux uses a negative return value to indicate syscall errors, | |
46 | unlike most Unices, which use the condition codes' carry flag. | |
47 | ||
48 | Since version 2.1 the return value of a system call might be | |
49 | negative even if the call succeeded. E.g., the `lseek' system call | |
50 | might return a large offset. Therefore we must not anymore test | |
51 | for < 0, but test for a real error by making sure the value in R0 | |
52 | is a real error number. Linus said he will make sure the no syscall | |
53 | returns a value in -1 .. -4095 as a valid result so we can safely | |
54 | test with -4095. */ | |
55 | ||
56 | # undef PSEUDO | |
57 | # define PSEUDO(name, syscall_name, args) \ | |
58 | .text; \ | |
59 | ENTRY (name); \ | |
60 | DO_CALL (syscall_name, args); \ | |
ca3cfa40 RH |
61 | cmn x0, #4095; \ |
62 | b.cs .Lsyscall_error; | |
554066b8 | 63 | |
554066b8 MS |
64 | # undef PSEUDO_END |
65 | # define PSEUDO_END(name) \ | |
66 | SYSCALL_ERROR_HANDLER \ | |
67 | END (name) | |
68 | ||
69 | # undef PSEUDO_NOERRNO | |
70 | # define PSEUDO_NOERRNO(name, syscall_name, args) \ | |
71 | .text; \ | |
72 | ENTRY (name); \ | |
73 | DO_CALL (syscall_name, args); | |
74 | ||
554066b8 MS |
75 | # undef PSEUDO_END_NOERRNO |
76 | # define PSEUDO_END_NOERRNO(name) \ | |
77 | END (name) | |
78 | ||
f0712b54 RH |
79 | # define ret_NOERRNO ret |
80 | ||
554066b8 MS |
81 | /* The function has to return the error code. */ |
82 | # undef PSEUDO_ERRVAL | |
83 | # define PSEUDO_ERRVAL(name, syscall_name, args) \ | |
84 | .text; \ | |
85 | ENTRY (name) \ | |
86 | DO_CALL (syscall_name, args); \ | |
87 | neg x0, x0 | |
88 | ||
89 | # undef PSEUDO_END_ERRVAL | |
90 | # define PSEUDO_END_ERRVAL(name) \ | |
91 | END (name) | |
92 | ||
f0712b54 | 93 | # define ret_ERRVAL ret |
554066b8 | 94 | |
4f41c682 | 95 | # if !IS_IN (libc) |
ca3cfa40 | 96 | # define SYSCALL_ERROR .Lsyscall_error |
554066b8 MS |
97 | # if RTLD_PRIVATE_ERRNO |
98 | # define SYSCALL_ERROR_HANDLER \ | |
ca3cfa40 | 99 | .Lsyscall_error: \ |
554066b8 | 100 | adrp x1, C_SYMBOL_NAME(rtld_errno); \ |
554066b8 | 101 | neg w0, w0; \ |
3612eb8f | 102 | str w0, [x1, :lo12:C_SYMBOL_NAME(rtld_errno)]; \ |
554066b8 MS |
103 | mov x0, -1; \ |
104 | RET; | |
105 | # else | |
106 | ||
107 | # define SYSCALL_ERROR_HANDLER \ | |
ca3cfa40 | 108 | .Lsyscall_error: \ |
11a28aee RH |
109 | adrp x1, :gottprel:errno; \ |
110 | neg w2, w0; \ | |
42de7e20 | 111 | ldr PTR_REG(1), [x1, :gottprel_lo12:errno]; \ |
11a28aee | 112 | mrs x3, tpidr_el0; \ |
554066b8 | 113 | mov x0, -1; \ |
11a28aee | 114 | str w2, [x1, x3]; \ |
554066b8 MS |
115 | RET; |
116 | # endif | |
117 | # else | |
554066b8 | 118 | # define SYSCALL_ERROR __syscall_error |
ca3cfa40 RH |
119 | # define SYSCALL_ERROR_HANDLER \ |
120 | .Lsyscall_error: \ | |
121 | b __syscall_error; | |
554066b8 MS |
122 | # endif |
123 | ||
124 | /* Linux takes system call args in registers: | |
c69abcee | 125 | syscall number x8 |
554066b8 MS |
126 | arg 1 x0 |
127 | arg 2 x1 | |
128 | arg 3 x2 | |
129 | arg 4 x3 | |
130 | arg 5 x4 | |
131 | arg 6 x5 | |
132 | arg 7 x6 | |
133 | ||
134 | The compiler is going to form a call by coming here, through PSEUDO, with | |
135 | arguments | |
136 | syscall number in the DO_CALL macro | |
137 | arg 1 x0 | |
138 | arg 2 x1 | |
139 | arg 3 x2 | |
140 | arg 4 x3 | |
141 | arg 5 x4 | |
142 | arg 6 x5 | |
143 | arg 7 x6 | |
144 | ||
554066b8 MS |
145 | */ |
146 | ||
147 | # undef DO_CALL | |
148 | # define DO_CALL(syscall_name, args) \ | |
554066b8 | 149 | mov x8, SYS_ify (syscall_name); \ |
6e6c2d01 | 150 | svc 0 |
554066b8 MS |
151 | |
152 | #else /* not __ASSEMBLER__ */ | |
153 | ||
b8386c28 AZ |
154 | # ifdef __LP64__ |
155 | # define VDSO_NAME "LINUX_2.6.39" | |
156 | # define VDSO_HASH 123718537 | |
157 | # else | |
158 | # define VDSO_NAME "LINUX_4.9" | |
159 | # define VDSO_HASH 61765625 | |
160 | # endif | |
554066b8 MS |
161 | |
162 | /* List of system calls which are supported as vsyscalls. */ | |
163 | # define HAVE_CLOCK_GETRES_VSYSCALL 1 | |
164 | # define HAVE_CLOCK_GETTIME_VSYSCALL 1 | |
97554e43 | 165 | # define HAVE_GETTIMEOFDAY_VSYSCALL 1 |
554066b8 | 166 | |
60f9423b AZ |
167 | /* Previously AArch64 used the generic version without the libc_hidden_def |
168 | which lead in a non existent __send symbol in libc.so. */ | |
169 | # undef HAVE_INTERNAL_SEND_SYMBOL | |
170 | ||
09c76a74 AZ |
171 | # define SINGLE_THREAD_BY_GLOBAL 1 |
172 | ||
554066b8 MS |
173 | /* Define a macro which expands into the inline wrapper code for a system |
174 | call. */ | |
175 | # undef INLINE_SYSCALL | |
176 | # define INLINE_SYSCALL(name, nr, args...) \ | |
177 | ({ unsigned long _sys_result = INTERNAL_SYSCALL (name, , nr, args); \ | |
178 | if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0))\ | |
179 | { \ | |
180 | __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, )); \ | |
181 | _sys_result = (unsigned long) -1; \ | |
182 | } \ | |
183 | (long) _sys_result; }) | |
184 | ||
185 | # undef INTERNAL_SYSCALL_DECL | |
186 | # define INTERNAL_SYSCALL_DECL(err) do { } while (0) | |
187 | ||
188 | # undef INTERNAL_SYSCALL_RAW | |
189 | # define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \ | |
1670e207 | 190 | ({ long _sys_result; \ |
554066b8 MS |
191 | { \ |
192 | LOAD_ARGS_##nr (args) \ | |
193 | register long _x8 asm ("x8") = (name); \ | |
194 | asm volatile ("svc 0 // syscall " # name \ | |
1670e207 | 195 | : "=r" (_x0) : "r"(_x8) ASM_ARGS_##nr : "memory"); \ |
554066b8 MS |
196 | _sys_result = _x0; \ |
197 | } \ | |
1670e207 | 198 | _sys_result; }) |
554066b8 MS |
199 | |
200 | # undef INTERNAL_SYSCALL | |
201 | # define INTERNAL_SYSCALL(name, err, nr, args...) \ | |
202 | INTERNAL_SYSCALL_RAW(SYS_ify(name), err, nr, args) | |
203 | ||
204 | # undef INTERNAL_SYSCALL_AARCH64 | |
205 | # define INTERNAL_SYSCALL_AARCH64(name, err, nr, args...) \ | |
206 | INTERNAL_SYSCALL_RAW(__ARM_NR_##name, err, nr, args) | |
207 | ||
208 | # undef INTERNAL_SYSCALL_ERROR_P | |
209 | # define INTERNAL_SYSCALL_ERROR_P(val, err) \ | |
210 | ((unsigned long) (val) >= (unsigned long) -4095) | |
211 | ||
212 | # undef INTERNAL_SYSCALL_ERRNO | |
213 | # define INTERNAL_SYSCALL_ERRNO(val, err) (-(val)) | |
214 | ||
554066b8 MS |
215 | # define LOAD_ARGS_0() \ |
216 | register long _x0 asm ("x0"); | |
554066b8 MS |
217 | # define LOAD_ARGS_1(x0) \ |
218 | long _x0tmp = (long) (x0); \ | |
219 | LOAD_ARGS_0 () \ | |
220 | _x0 = _x0tmp; | |
554066b8 MS |
221 | # define LOAD_ARGS_2(x0, x1) \ |
222 | long _x1tmp = (long) (x1); \ | |
223 | LOAD_ARGS_1 (x0) \ | |
224 | register long _x1 asm ("x1") = _x1tmp; | |
554066b8 MS |
225 | # define LOAD_ARGS_3(x0, x1, x2) \ |
226 | long _x2tmp = (long) (x2); \ | |
227 | LOAD_ARGS_2 (x0, x1) \ | |
228 | register long _x2 asm ("x2") = _x2tmp; | |
554066b8 MS |
229 | # define LOAD_ARGS_4(x0, x1, x2, x3) \ |
230 | long _x3tmp = (long) (x3); \ | |
231 | LOAD_ARGS_3 (x0, x1, x2) \ | |
232 | register long _x3 asm ("x3") = _x3tmp; | |
554066b8 MS |
233 | # define LOAD_ARGS_5(x0, x1, x2, x3, x4) \ |
234 | long _x4tmp = (long) (x4); \ | |
235 | LOAD_ARGS_4 (x0, x1, x2, x3) \ | |
236 | register long _x4 asm ("x4") = _x4tmp; | |
554066b8 MS |
237 | # define LOAD_ARGS_6(x0, x1, x2, x3, x4, x5) \ |
238 | long _x5tmp = (long) (x5); \ | |
239 | LOAD_ARGS_5 (x0, x1, x2, x3, x4) \ | |
240 | register long _x5 asm ("x5") = _x5tmp; | |
554066b8 MS |
241 | # define LOAD_ARGS_7(x0, x1, x2, x3, x4, x5, x6)\ |
242 | long _x6tmp = (long) (x6); \ | |
243 | LOAD_ARGS_6 (x0, x1, x2, x3, x4, x5) \ | |
244 | register long _x6 asm ("x6") = _x6tmp; | |
1670e207 RH |
245 | |
246 | # define ASM_ARGS_0 | |
247 | # define ASM_ARGS_1 , "r" (_x0) | |
248 | # define ASM_ARGS_2 ASM_ARGS_1, "r" (_x1) | |
249 | # define ASM_ARGS_3 ASM_ARGS_2, "r" (_x2) | |
250 | # define ASM_ARGS_4 ASM_ARGS_3, "r" (_x3) | |
251 | # define ASM_ARGS_5 ASM_ARGS_4, "r" (_x4) | |
252 | # define ASM_ARGS_6 ASM_ARGS_5, "r" (_x5) | |
554066b8 MS |
253 | # define ASM_ARGS_7 ASM_ARGS_6, "r" (_x6) |
254 | ||
255 | # undef INTERNAL_SYSCALL_NCS | |
256 | # define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \ | |
257 | INTERNAL_SYSCALL_RAW (number, err, nr, args) | |
258 | ||
259 | #endif /* __ASSEMBLER__ */ | |
260 | ||
9188b681 | 261 | /* Pointer mangling is supported for AArch64. */ |
aa0e4663 JM |
262 | #if (IS_IN (rtld) \ |
263 | || (!defined SHARED && (IS_IN (libc) \ | |
264 | || IS_IN (libpthread)))) | |
9188b681 | 265 | # ifdef __ASSEMBLER__ |
389d1f1b SE |
266 | /* Note, dst, src, guard, and tmp are all register numbers rather than |
267 | register names so they will work with both ILP32 and LP64. */ | |
9188b681 VK |
268 | # define PTR_MANGLE(dst, src, guard, tmp) \ |
269 | LDST_PCREL (ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard_local)); \ | |
270 | PTR_MANGLE2 (dst, src, guard) | |
271 | /* Use PTR_MANGLE2 for efficiency if guard is already loaded. */ | |
272 | # define PTR_MANGLE2(dst, src, guard)\ | |
389d1f1b | 273 | eor x##dst, x##src, x##guard |
9188b681 VK |
274 | # define PTR_DEMANGLE(dst, src, guard, tmp)\ |
275 | PTR_MANGLE (dst, src, guard, tmp) | |
276 | # define PTR_DEMANGLE2(dst, src, guard)\ | |
277 | PTR_MANGLE2 (dst, src, guard) | |
278 | # else | |
279 | extern uintptr_t __pointer_chk_guard_local attribute_relro attribute_hidden; | |
280 | # define PTR_MANGLE(var) \ | |
281 | (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard_local) | |
282 | # define PTR_DEMANGLE(var) PTR_MANGLE (var) | |
283 | # endif | |
284 | #else | |
285 | # ifdef __ASSEMBLER__ | |
389d1f1b SE |
286 | /* Note, dst, src, guard, and tmp are all register numbers rather than |
287 | register names so they will work with both ILP32 and LP64. */ | |
9188b681 VK |
288 | # define PTR_MANGLE(dst, src, guard, tmp) \ |
289 | LDST_GLOBAL (ldr, guard, tmp, C_SYMBOL_NAME(__pointer_chk_guard)); \ | |
290 | PTR_MANGLE2 (dst, src, guard) | |
291 | /* Use PTR_MANGLE2 for efficiency if guard is already loaded. */ | |
292 | # define PTR_MANGLE2(dst, src, guard)\ | |
389d1f1b | 293 | eor x##dst, x##src, x##guard |
9188b681 VK |
294 | # define PTR_DEMANGLE(dst, src, guard, tmp)\ |
295 | PTR_MANGLE (dst, src, guard, tmp) | |
296 | # define PTR_DEMANGLE2(dst, src, guard)\ | |
297 | PTR_MANGLE2 (dst, src, guard) | |
298 | # else | |
299 | extern uintptr_t __pointer_chk_guard attribute_relro; | |
300 | # define PTR_MANGLE(var) \ | |
301 | (var) = (__typeof (var)) ((uintptr_t) (var) ^ __pointer_chk_guard) | |
302 | # define PTR_DEMANGLE(var) PTR_MANGLE (var) | |
303 | # endif | |
304 | #endif | |
554066b8 MS |
305 | |
306 | #endif /* linux/aarch64/sysdep.h */ |