2.9
[glibc/nacl-glibc.git] / nptl / sysdeps / unix / sysv / linux / sh / sysdep-cancel.h
bloba8065c6a8c8d6c4a456b4dde5890682111eb5334
1 /* Copyright (C) 2003, 2004, 2005, 2006 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, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #include <sysdep.h>
20 #include <tls.h>
21 #ifndef __ASSEMBLER__
22 # include <nptl/pthreadP.h>
23 #endif
25 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
27 # define _IMM12 #-12
28 # define _IMM16 #-16
29 # define _IMP16 #16
30 # undef PSEUDO
31 # define PSEUDO(name, syscall_name, args) \
32 .text; \
33 ENTRY (name); \
34 .Lpseudo_start: \
35 SINGLE_THREAD_P; \
36 bf .Lpseudo_cancel; \
37 .type __##syscall_name##_nocancel,@function; \
38 .globl __##syscall_name##_nocancel; \
39 __##syscall_name##_nocancel: \
40 DO_CALL (syscall_name, args); \
41 mov r0,r1; \
42 mov _IMM12,r2; \
43 shad r2,r1; \
44 not r1,r1; \
45 tst r1,r1; \
46 bt .Lsyscall_error; \
47 bra .Lpseudo_end; \
48 nop; \
49 .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
50 .Lpseudo_cancel: \
51 sts.l pr,@-r15; \
52 cfi_adjust_cfa_offset (4); \
53 cfi_rel_offset (pr, 0); \
54 add _IMM16,r15; \
55 cfi_adjust_cfa_offset (16); \
56 SAVE_ARGS_##args; \
57 CENABLE; \
58 LOAD_ARGS_##args; \
59 add _IMP16,r15; \
60 cfi_adjust_cfa_offset (-16); \
61 lds.l @r15+,pr; \
62 cfi_adjust_cfa_offset (-4); \
63 cfi_restore (pr); \
64 DO_CALL(syscall_name, args); \
65 SYSCALL_INST_PAD; \
66 sts.l pr,@-r15; \
67 cfi_adjust_cfa_offset (4); \
68 cfi_rel_offset (pr, 0); \
69 mov.l r0,@-r15; \
70 cfi_adjust_cfa_offset (4); \
71 cfi_rel_offset (r0, 0); \
72 CDISABLE; \
73 mov.l @r15+,r0; \
74 cfi_adjust_cfa_offset (-4); \
75 lds.l @r15+,pr; \
76 cfi_adjust_cfa_offset (-4); \
77 cfi_restore (pr); \
78 mov r0,r1; \
79 mov _IMM12,r2; \
80 shad r2,r1; \
81 not r1,r1; \
82 tst r1,r1; \
83 bf .Lpseudo_end; \
84 .Lsyscall_error: \
85 SYSCALL_ERROR_HANDLER; \
86 .Lpseudo_end:
88 # undef PSEUDO_END
89 # define PSEUDO_END(sym) \
90 END (sym)
92 # define SAVE_ARGS_0 /* Nothing. */
93 # define SAVE_ARGS_1 SAVE_ARGS_0; mov.l r4,@(0,r15); cfi_offset (r4,-4)
94 # define SAVE_ARGS_2 SAVE_ARGS_1; mov.l r5,@(4,r15); cfi_offset (r5,-8)
95 # define SAVE_ARGS_3 SAVE_ARGS_2; mov.l r6,@(8,r15); cfi_offset (r6,-12)
96 # define SAVE_ARGS_4 SAVE_ARGS_3; mov.l r7,@(12,r15); cfi_offset (r7,-16)
97 # define SAVE_ARGS_5 SAVE_ARGS_4
98 # define SAVE_ARGS_6 SAVE_ARGS_5
100 # define LOAD_ARGS_0 /* Nothing. */
101 # define LOAD_ARGS_1 LOAD_ARGS_0; mov.l @(0,r15),r4
102 # define LOAD_ARGS_2 LOAD_ARGS_1; mov.l @(4,r15),r5
103 # define LOAD_ARGS_3 LOAD_ARGS_2; mov.l @(8,r15),r6
104 # define LOAD_ARGS_4 LOAD_ARGS_3; mov.l @(12,r15),r7
105 # define LOAD_ARGS_5 LOAD_ARGS_4
106 # define LOAD_ARGS_6 LOAD_ARGS_5
108 # ifdef IS_IN_libpthread
109 # define __local_enable_asynccancel __pthread_enable_asynccancel
110 # define __local_disable_asynccancel __pthread_disable_asynccancel
111 # elif !defined NOT_IN_libc
112 # define __local_enable_asynccancel __libc_enable_asynccancel
113 # define __local_disable_asynccancel __libc_disable_asynccancel
114 # elif defined IS_IN_librt
115 # define __local_enable_asynccancel __librt_enable_asynccancel
116 # define __local_disable_asynccancel __librt_disable_asynccancel
117 # else
118 # error Unsupported library
119 # endif
121 # define CENABLE \
122 mov.l 1f,r0; \
123 bsrf r0; \
124 nop; \
125 0: bra 2f; \
126 mov r0,r2; \
127 .align 2; \
128 1: .long __local_enable_asynccancel - 0b; \
131 # define CDISABLE \
132 mov.l 1f,r0; \
133 bsrf r0; \
134 mov r2,r4; \
135 0: bra 2f; \
136 nop; \
137 .align 2; \
138 1: .long __local_disable_asynccancel - 0b; \
141 # ifndef __ASSEMBLER__
142 # define SINGLE_THREAD_P \
143 __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
144 header.multiple_threads) == 0, 1)
145 # else
146 # define SINGLE_THREAD_P \
147 stc gbr,r0; \
148 mov.w 0f,r1; \
149 sub r1,r0; \
150 mov.l @(MULTIPLE_THREADS_OFFSET,r0),r0; \
151 bra 1f; \
152 tst r0,r0; \
153 0: .word TLS_PRE_TCB_SIZE; \
156 # endif
158 #elif !defined __ASSEMBLER__
160 # define SINGLE_THREAD_P (1)
161 # define NO_CANCELLATION 1
163 #endif
165 #ifndef __ASSEMBLER__
166 # define RTLD_SINGLE_THREAD_P \
167 __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
168 header.multiple_threads) == 0, 1)
169 #endif