]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/aarch64/nptl/sysdep-cancel.h
aarch64: Tabify sysdep-cancel.h
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / aarch64 / nptl / sysdep-cancel.h
1 /* Copyright (C) 2003-2014 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
7 License as published by the Free Software Foundation; either
8 version 2.1 of the 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 #include <sysdep.h>
20 #include <tls.h>
21 #ifndef __ASSEMBLER__
22 # include <nptl/pthreadP.h>
23 #endif
24
25 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
26
27 # undef PSEUDO
28 # define PSEUDO(name, syscall_name, args) \
29 .section ".text"; \
30 .type __##syscall_name##_nocancel,%function; \
31 .globl __##syscall_name##_nocancel; \
32 __##syscall_name##_nocancel: \
33 cfi_startproc; \
34 DO_CALL (syscall_name, args); \
35 cmn x0, 4095; \
36 b.cs .Lsyscall_error; \
37 PSEUDO_RET; \
38 cfi_endproc; \
39 .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
40 ENTRY (name); \
41 SINGLE_THREAD_P; \
42 bne .Lpseudo_cancel; \
43 DO_CALL (syscall_name, 0); \
44 cmn x0, 4095; \
45 b.cs .Lsyscall_error; \
46 PSEUDO_RET; \
47 .Lpseudo_cancel: \
48 DOCARGS_##args; /* save syscall args etc. around CENABLE. */ \
49 CENABLE; \
50 mov x16, x0; /* put mask in safe place. */ \
51 UNDOCARGS_##args; /* restore syscall args. */ \
52 mov x8, SYS_ify (syscall_name); /* do the call. */ \
53 svc 0; \
54 str x0, [sp, -16]!; /* save syscall return value. */ \
55 cfi_adjust_cfa_offset (16); \
56 mov x0, x16; /* get mask back. */ \
57 CDISABLE; \
58 ldr x0, [sp], 16; \
59 cfi_adjust_cfa_offset (-16); \
60 ldr x30, [sp], 16; \
61 cfi_adjust_cfa_offset (-16); \
62 cfi_restore (x30); \
63 cmn x0, 4095; \
64 b.cs .Lsyscall_error;
65
66 # define DOCARGS_0 \
67 str x30, [sp, -16]!; \
68 cfi_adjust_cfa_offset (16); \
69 cfi_rel_offset (x30, 0)
70
71 # define UNDOCARGS_0
72
73 # define DOCARGS_1 \
74 DOCARGS_0; \
75 str x0, [sp, -16]!; \
76 cfi_adjust_cfa_offset (16); \
77 cfi_rel_offset (x0, 0)
78
79 # define UNDOCARGS_1 \
80 ldr x0, [sp], 16; \
81 cfi_restore (x0); \
82 cfi_adjust_cfa_offset (-16); \
83
84 # define DOCARGS_2 \
85 DOCARGS_1; \
86 str x1, [sp, -16]!; \
87 cfi_adjust_cfa_offset (16); \
88 cfi_rel_offset (x1, 0)
89
90 # define UNDOCARGS_2 \
91 ldr x1, [sp], 16; \
92 cfi_restore (x1); \
93 cfi_adjust_cfa_offset (-16); \
94 UNDOCARGS_1
95
96 # define DOCARGS_3 \
97 DOCARGS_2; \
98 str x2, [sp, -16]!; \
99 cfi_adjust_cfa_offset (16); \
100 cfi_rel_offset (x2, 0)
101
102 # define UNDOCARGS_3 \
103 ldr x2, [sp], 16; \
104 cfi_restore (x2); \
105 cfi_adjust_cfa_offset (-16); \
106 UNDOCARGS_2
107
108 # define DOCARGS_4 \
109 DOCARGS_3; \
110 str x3, [sp, -16]!; \
111 cfi_adjust_cfa_offset (16); \
112 cfi_rel_offset (x3, 0)
113
114 # define UNDOCARGS_4 \
115 ldr x3, [sp], 16; \
116 cfi_restore (x3); \
117 cfi_adjust_cfa_offset (-16); \
118 UNDOCARGS_3
119
120 # define DOCARGS_5 \
121 DOCARGS_4; \
122 str x4, [sp, -16]!; \
123 cfi_adjust_cfa_offset (16); \
124 cfi_rel_offset (x4, 0)
125
126 # define UNDOCARGS_5 \
127 ldr x4, [sp], 16; \
128 cfi_restore (x4); \
129 cfi_adjust_cfa_offset (-16); \
130 UNDOCARGS_4
131
132 # define DOCARGS_6 \
133 DOCARGS_5; \
134 str x5, [sp, -16]!; \
135 cfi_adjust_cfa_offset (16); \
136 cfi_rel_offset (x5, 0)
137
138 # define UNDOCARGS_6 \
139 ldr x5, [sp], 16; \
140 cfi_restore (x5); \
141 cfi_adjust_cfa_offset (-16); \
142 UNDOCARGS_5
143
144 # ifdef IS_IN_libpthread
145 # define CENABLE bl __pthread_enable_asynccancel
146 # define CDISABLE bl __pthread_disable_asynccancel
147 # define __local_multiple_threads __pthread_multiple_threads
148 # elif !defined NOT_IN_libc
149 # define CENABLE bl __libc_enable_asynccancel
150 # define CDISABLE bl __libc_disable_asynccancel
151 # define __local_multiple_threads __libc_multiple_threads
152 # elif defined IS_IN_librt
153 # define CENABLE bl __librt_enable_asynccancel
154 # define CDISABLE bl __librt_disable_asynccancel
155 # else
156 # error Unsupported library
157 # endif
158
159 # if defined IS_IN_libpthread || !defined NOT_IN_libc
160 # ifndef __ASSEMBLER__
161 extern int __local_multiple_threads attribute_hidden;
162 # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
163 # else
164 # define SINGLE_THREAD_P \
165 adrp x16, __local_multiple_threads; \
166 ldr w16, [x16, :lo12:__local_multiple_threads]; \
167 cmp w16, 0;
168 # endif
169 # else
170 /* There is no __local_multiple_threads for librt, so use the TCB. */
171 # ifndef __ASSEMBLER__
172 # define SINGLE_THREAD_P \
173 __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
174 header.multiple_threads) == 0, 1)
175 # else
176 # define SINGLE_THREAD_P \
177 stp x0, x30, [sp, -16]!; \
178 cfi_adjust_cfa_offset (16); \
179 cfi_rel_offset (x0, 0); \
180 cfi_rel_offset (x30, 8); \
181 bl __read_tp; \
182 sub x0, x0, PTHREAD_SIZEOF; \
183 ldr w16, [x0, PTHREAD_MULTIPLE_THREADS_OFFSET]; \
184 ldp x0, x30, [sp], 16; \
185 cfi_restore (x0); \
186 cfi_restore (x30); \
187 cfi_adjust_cfa_offset (-16); \
188 cmp w16, 0;
189 # endif
190 # endif
191
192 #elif !defined __ASSEMBLER__
193
194 /* For rtld, et cetera. */
195 # define SINGLE_THREAD_P 1
196 # define NO_CANCELLATION 1
197
198 #endif
199
200 #ifndef __ASSEMBLER__
201 # define RTLD_SINGLE_THREAD_P \
202 __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
203 header.multiple_threads) == 0, 1)
204 #endif