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