1 /* Copyright (C) 2003-2013 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library. If not, see
16 <http://www.gnu.org/licenses/>. */
21 # include <nptl/pthreadP.h>
24 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
26 /* NOTE: We do mark syscalls with unwind annotations, for the benefit of
27 cancellation; but they're really only accurate at the point of the
28 syscall. The ARM unwind directives are not rich enough without adding
29 a custom personality function. */
32 # define PSEUDO(name, syscall_name, args) \
34 ENTRY (__##syscall_name##_nocancel); \
36 DO_CALL (syscall_name, args); \
39 END (__##syscall_name##_nocancel); \
43 bne .Lpseudo_cancel; \
45 ldr r7, =SYS_ify (syscall_name); \
52 .fnstart; /* matched by the .fnend in UNDOARGS below. */ \
53 DOCARGS_##args; /* save syscall args etc. around CENABLE. */ \
55 mov ip, r0; /* put mask in safe place. */ \
56 UNDOCARGS_##args; /* restore syscall args. */ \
57 ldr r7, =SYS_ify (syscall_name); \
58 swi 0x0; /* do the call. */ \
59 mov r7, r0; /* save syscall return value. */ \
60 mov r0, ip; /* get mask back. */ \
62 mov r0, r7; /* retrieve return value. */ \
67 /* DOARGS pushes eight bytes on the stack for five arguments, twelve bytes for
68 six arguments, and four bytes for fewer. In order to preserve doubleword
69 alignment, sometimes we must save an extra register. */
71 # define RESTART_UNWIND \
80 cfi_adjust_cfa_offset (4); \
81 cfi_rel_offset (lr, 0); \
84 # define RESTORE_LR_0 \
86 cfi_adjust_cfa_offset (-4); \
91 stmfd sp!, {r0, r1, lr}; \
92 cfi_adjust_cfa_offset (12); \
93 cfi_rel_offset (lr, 8); \
96 # define UNDOCARGS_1 \
98 cfi_adjust_cfa_offset (-8); \
100 # define RESTORE_LR_1 \
105 stmfd sp!, {r0, r1, lr}; \
106 cfi_adjust_cfa_offset (12); \
107 cfi_rel_offset (lr, 8); \
110 # define UNDOCARGS_2 \
111 ldmfd sp!, {r0, r1}; \
112 cfi_adjust_cfa_offset (-8); \
114 # define RESTORE_LR_2 \
119 stmfd sp!, {r0, r1, r2, r3, lr}; \
120 cfi_adjust_cfa_offset (20); \
121 cfi_rel_offset (lr, 16); \
124 # define UNDOCARGS_3 \
125 ldmfd sp!, {r0, r1, r2, r3}; \
126 cfi_adjust_cfa_offset (-16); \
128 # define RESTORE_LR_3 \
133 stmfd sp!, {r0, r1, r2, r3, lr}; \
134 cfi_adjust_cfa_offset (20); \
135 cfi_rel_offset (lr, 16); \
138 # define UNDOCARGS_4 \
139 ldmfd sp!, {r0, r1, r2, r3}; \
140 cfi_adjust_cfa_offset (-16); \
142 # define RESTORE_LR_4 \
145 /* r4 is only stmfd'ed for correct stack alignment. */
148 stmfd sp!, {r0, r1, r2, r3, r4, lr}; \
149 cfi_adjust_cfa_offset (24); \
150 cfi_rel_offset (lr, 20); \
153 # define UNDOCARGS_5 \
154 ldmfd sp!, {r0, r1, r2, r3}; \
155 cfi_adjust_cfa_offset (-16); \
161 # define RESTORE_LR_5 \
162 ldmfd sp!, {r4, lr}; \
163 cfi_adjust_cfa_offset (-8); \
164 /* r4 will be marked as restored later. */ \
168 .save {r4, r5, r7}; \
169 stmfd sp!, {r0, r1, r2, r3, lr}; \
170 cfi_adjust_cfa_offset (20); \
171 cfi_rel_offset (lr, 16); \
174 # define UNDOCARGS_6 \
175 ldmfd sp!, {r0, r1, r2, r3}; \
176 cfi_adjust_cfa_offset (-16); \
179 .save {r4, r5, r7}; \
181 # define RESTORE_LR_6 \
184 # ifdef IS_IN_libpthread
185 # define CENABLE bl PLTJMP(__pthread_enable_asynccancel)
186 # define CDISABLE bl PLTJMP(__pthread_disable_asynccancel)
187 # define __local_multiple_threads __pthread_multiple_threads
188 # elif !defined NOT_IN_libc
189 # define CENABLE bl PLTJMP(__libc_enable_asynccancel)
190 # define CDISABLE bl PLTJMP(__libc_disable_asynccancel)
191 # define __local_multiple_threads __libc_multiple_threads
192 # elif defined IS_IN_librt
193 # define CENABLE bl PLTJMP(__librt_enable_asynccancel)
194 # define CDISABLE bl PLTJMP(__librt_disable_asynccancel)
196 # error Unsupported library
199 # if defined IS_IN_libpthread || !defined NOT_IN_libc
200 # ifndef __ASSEMBLER__
201 extern int __local_multiple_threads attribute_hidden
;
202 # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
204 # define SINGLE_THREAD_P \
205 LDST_PCREL(ldr, ip, ip, __local_multiple_threads); \
209 /* There is no __local_multiple_threads for librt, so use the TCB. */
210 # ifndef __ASSEMBLER__
211 # define SINGLE_THREAD_P \
212 __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
213 header.multiple_threads) == 0, 1)
215 # define SINGLE_THREAD_P \
216 stmfd sp!, {r0, lr}; \
217 cfi_adjust_cfa_offset (8); \
218 cfi_rel_offset (lr, 4); \
219 bl __aeabi_read_tp; \
220 ldr ip, [r0, #MULTIPLE_THREADS_OFFSET]; \
221 ldmfd sp!, {r0, lr}; \
222 cfi_adjust_cfa_offset (-8); \
225 # define SINGLE_THREAD_P_PIC(x) SINGLE_THREAD_P
229 #elif !defined __ASSEMBLER__
231 /* For rtld, et cetera. */
232 # define SINGLE_THREAD_P 1
233 # define NO_CANCELLATION 1
237 #ifndef __ASSEMBLER__
238 # define RTLD_SINGLE_THREAD_P \
239 __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
240 header.multiple_threads) == 0, 1)