* sysdeps/unix/sysv/linux/i386/sysdep-cancel.h: Remove explicit
[glibc.git] / linuxthreads / sysdeps / unix / sysv / linux / i386 / sysdep-cancel.h
blobc8be0fdd395f70e7631fba39ab7c03c4e646ffe7
1 /* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <sysdep.h>
21 #include <tls.h>
22 #include <pt-machine.h>
23 #ifndef __ASSEMBLER__
24 # include <linuxthreads/internals.h>
25 #endif
27 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
29 # undef PSEUDO
30 # define PSEUDO(name, syscall_name, args) \
31 .text; \
32 ENTRY (name) \
33 SINGLE_THREAD_P; \
34 jne L(pseudo_cancel); \
35 DO_CALL (syscall_name, args); \
36 cmpl $-4095, %eax; \
37 jae SYSCALL_ERROR_LABEL; \
38 ret; \
39 L(pseudo_cancel): \
40 CENABLE \
41 SAVE_OLDTYPE_##args \
42 PUSHCARGS_##args \
43 DOCARGS_##args \
44 movl $SYS_ify (syscall_name), %eax; \
45 int $0x80 \
46 POPCARGS_##args; \
47 POPSTATE_##args \
48 cmpl $-4095, %eax; \
49 jae SYSCALL_ERROR_LABEL; \
50 L(pseudo_end):
52 # define SAVE_OLDTYPE_0 movl %eax, %ecx;
53 # define SAVE_OLDTYPE_1 SAVE_OLDTYPE_0
54 # define SAVE_OLDTYPE_2 pushl %eax; cfi_adjust_cfa_offset (4);
55 # define SAVE_OLDTYPE_3 SAVE_OLDTYPE_2
56 # define SAVE_OLDTYPE_4 SAVE_OLDTYPE_2
57 # define SAVE_OLDTYPE_5 SAVE_OLDTYPE_2
59 # define PUSHCARGS_0 /* No arguments to push. */
60 # define DOCARGS_0 /* No arguments to frob. */
61 # define POPCARGS_0 /* No arguments to pop. */
62 # define _PUSHCARGS_0 /* No arguments to push. */
63 # define _POPCARGS_0 /* No arguments to pop. */
65 # define PUSHCARGS_1 movl %ebx, %edx; cfi_register (ebx, edx); PUSHCARGS_0
66 # define DOCARGS_1 _DOARGS_1 (4)
67 # define POPCARGS_1 POPCARGS_0; movl %edx, %ebx; cfi_restore (ebx);
68 # define _PUSHCARGS_1 pushl %ebx; cfi_adjust_cfa_offset (4); \
69 cfi_rel_offset (ebx, 0); _PUSHCARGS_0
70 # define _POPCARGS_1 _POPCARGS_0; popl %ebx; \
71 cfi_adjust_cfa_offset (-4); cfi_restore (ebx);
73 # define PUSHCARGS_2 PUSHCARGS_1
74 # define DOCARGS_2 _DOARGS_2 (12)
75 # define POPCARGS_2 POPCARGS_1
76 # define _PUSHCARGS_2 _PUSHCARGS_1
77 # define _POPCARGS_2 _POPCARGS_1
79 # define PUSHCARGS_3 _PUSHCARGS_2
80 # define DOCARGS_3 _DOARGS_3 (20)
81 # define POPCARGS_3 _POPCARGS_3
82 # define _PUSHCARGS_3 _PUSHCARGS_2
83 # define _POPCARGS_3 _POPCARGS_2
85 # define PUSHCARGS_4 _PUSHCARGS_4
86 # define DOCARGS_4 _DOARGS_4 (28)
87 # define POPCARGS_4 _POPCARGS_4
88 # define _PUSHCARGS_4 pushl %esi; cfi_adjust_cfa_offset (4); \
89 cfi_rel_offset (esi, 0); _PUSHCARGS_3
90 # define _POPCARGS_4 _POPCARGS_3; popl %esi; \
91 cfi_adjust_cfa_offset (-4); cfi_restore (esi);
93 # define PUSHCARGS_5 _PUSHCARGS_5
94 # define DOCARGS_5 _DOARGS_5 (36)
95 # define POPCARGS_5 _POPCARGS_5
96 # define _PUSHCARGS_5 pushl %edi; cfi_adjust_cfa_offset (4); \
97 cfi_rel_offset (edi, 0); _PUSHCARGS_4
98 # define _POPCARGS_5 _POPCARGS_4; popl %edi; \
99 cfi_adjust_cfa_offset (-4); cfi_restore (edi);
101 # ifdef IS_IN_libpthread
102 # define CENABLE call __pthread_enable_asynccancel;
103 # define CDISABLE call __pthread_disable_asynccancel
104 # elif defined IS_IN_librt
105 # ifdef PIC
106 # define CENABLE pushl %ebx; \
107 call __i686.get_pc_thunk.bx; \
108 addl $_GLOBAL_OFFSET_TABLE_, %ebx; \
109 call __librt_enable_asynccancel@PLT; \
110 popl %ebx;
111 # define CDISABLE pushl %ebx; \
112 call __i686.get_pc_thunk.bx; \
113 addl $_GLOBAL_OFFSET_TABLE_, %ebx; \
114 call __librt_disable_asynccancel@PLT; \
115 popl %ebx;
116 # else
117 # define CENABLE call __librt_enable_asynccancel;
118 # define CDISABLE call __librt_disable_asynccancel
119 # endif
120 # else
121 # define CENABLE call __libc_enable_asynccancel;
122 # define CDISABLE call __libc_disable_asynccancel
123 # endif
124 # define POPSTATE_0 \
125 pushl %eax; cfi_adjust_cfa_offset (4); movl %ecx, %eax; \
126 CDISABLE; popl %eax; cfi_adjust_cfa_offset (-4);
127 # define POPSTATE_1 POPSTATE_0
128 # define POPSTATE_2 xchgl (%esp), %eax; CDISABLE; popl %eax; \
129 cfi_adjust_cfa_offset (-4);
130 # define POPSTATE_3 POPSTATE_2
131 # define POPSTATE_4 POPSTATE_3
132 # define POPSTATE_5 POPSTATE_4
134 #if !defined NOT_IN_libc
135 # define __local_multiple_threads __libc_multiple_threads
136 #elif defined IS_IN_libpthread
137 # define __local_multiple_threads __pthread_multiple_threads
138 #else
139 # define __local_multiple_threads __librt_multiple_threads
140 #endif
142 # ifndef __ASSEMBLER__
143 # if defined FLOATING_STACKS && USE___THREAD && defined PIC
144 # define SINGLE_THREAD_P \
145 __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
146 p_header.data.multiple_threads) == 0, 1)
147 # else
148 extern int __local_multiple_threads
149 # if !defined NOT_IN_libc || defined IS_IN_libpthread
150 attribute_hidden;
151 # else
153 # endif
154 # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
155 # endif
156 # else
157 # if !defined PIC
158 # define SINGLE_THREAD_P cmpl $0, __local_multiple_threads
159 # elif defined FLOATING_STACKS && USE___THREAD
160 # define SINGLE_THREAD_P cmpl $0, %gs:MULTIPLE_THREADS_OFFSET
161 # else
162 # if !defined NOT_IN_libc || defined IS_IN_libpthread
163 # define __SINGLE_THREAD_CMP cmpl $0, __local_multiple_threads@GOTOFF(%ecx)
164 # else
165 # define __SINGLE_THREAD_CMP \
166 movl __local_multiple_threads@GOT(%ecx), %ecx;\
167 cmpl $0, (%ecx)
168 # endif
169 # if !defined HAVE_HIDDEN || !USE___THREAD
170 # define SINGLE_THREAD_P \
171 SETUP_PIC_REG (cx); \
172 addl $_GLOBAL_OFFSET_TABLE_, %ecx; \
173 __SINGLE_THREAD_CMP
174 # else
175 # define SINGLE_THREAD_P \
176 call __i686.get_pc_thunk.cx; \
177 addl $_GLOBAL_OFFSET_TABLE_, %ecx; \
178 __SINGLE_THREAD_CMP
179 # endif
180 # endif
181 # endif
183 #elif !defined __ASSEMBLER__
185 /* This code should never be used but we define it anyhow. */
186 # define SINGLE_THREAD_P (1)
188 #endif