Test for stack alignment.
[glibc.git] / linuxthreads / sysdeps / unix / sysv / linux / i386 / sysdep-cancel.h
blob7865f7165e0ec105615b97f4e443f75e12a394a5
1 /* Copyright (C) 2002, 2003, 2004 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;
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; PUSHCARGS_0
66 # define DOCARGS_1 _DOARGS_1 (4)
67 # define POPCARGS_1 POPCARGS_0; movl %edx, %ebx
68 # define _PUSHCARGS_1 pushl %ebx; L(PUSHBX2): _PUSHCARGS_0
69 # define _POPCARGS_1 _POPCARGS_0; popl %ebx; L(POPBX2):
71 # define PUSHCARGS_2 PUSHCARGS_1
72 # define DOCARGS_2 _DOARGS_2 (12)
73 # define POPCARGS_2 POPCARGS_1
74 # define _PUSHCARGS_2 _PUSHCARGS_1
75 # define _POPCARGS_2 _POPCARGS_1
77 # define PUSHCARGS_3 _PUSHCARGS_2
78 # define DOCARGS_3 _DOARGS_3 (20)
79 # define POPCARGS_3 _POPCARGS_3
80 # define _PUSHCARGS_3 _PUSHCARGS_2
81 # define _POPCARGS_3 _POPCARGS_2
83 # define PUSHCARGS_4 _PUSHCARGS_4
84 # define DOCARGS_4 _DOARGS_4 (28)
85 # define POPCARGS_4 _POPCARGS_4
86 # define _PUSHCARGS_4 pushl %esi; L(PUSHSI2): _PUSHCARGS_3
87 # define _POPCARGS_4 _POPCARGS_3; popl %esi; L(POPSI2):
89 # define PUSHCARGS_5 _PUSHCARGS_5
90 # define DOCARGS_5 _DOARGS_5 (36)
91 # define POPCARGS_5 _POPCARGS_5
92 # define _PUSHCARGS_5 pushl %edi; L(PUSHDI2): _PUSHCARGS_4
93 # define _POPCARGS_5 _POPCARGS_4; popl %edi; L(POPDI2):
95 # ifdef IS_IN_libpthread
96 # define CENABLE call __pthread_enable_asynccancel;
97 # define CDISABLE call __pthread_disable_asynccancel
98 # elif defined IS_IN_librt
99 # ifdef PIC
100 # define CENABLE pushl %ebx; \
101 call __i686.get_pc_thunk.bx; \
102 addl $_GLOBAL_OFFSET_TABLE_, %ebx; \
103 call __librt_enable_asynccancel@PLT; \
104 popl %ebx;
105 # define CDISABLE pushl %ebx; \
106 call __i686.get_pc_thunk.bx; \
107 addl $_GLOBAL_OFFSET_TABLE_, %ebx; \
108 call __librt_disable_asynccancel@PLT; \
109 popl %ebx;
110 # else
111 # define CENABLE call __librt_enable_asynccancel;
112 # define CDISABLE call __librt_disable_asynccancel
113 # endif
114 # else
115 # define CENABLE call __libc_enable_asynccancel;
116 # define CDISABLE call __libc_disable_asynccancel
117 # endif
118 # define POPSTATE_0 pushl %eax; movl %ecx, %eax; CDISABLE; popl %eax;
119 # define POPSTATE_1 POPSTATE_0
120 # define POPSTATE_2 xchgl (%esp), %eax; CDISABLE; popl %eax;
121 # define POPSTATE_3 POPSTATE_2
122 # define POPSTATE_4 POPSTATE_2
123 # define POPSTATE_5 POPSTATE_2
125 #if !defined NOT_IN_libc
126 # define __local_multiple_threads __libc_multiple_threads
127 #elif defined IS_IN_libpthread
128 # define __local_multiple_threads __pthread_multiple_threads
129 #else
130 # define __local_multiple_threads __librt_multiple_threads
131 #endif
133 # ifndef __ASSEMBLER__
134 # if defined FLOATING_STACKS && USE___THREAD && defined PIC
135 # define SINGLE_THREAD_P \
136 __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
137 p_header.data.multiple_threads) == 0, 1)
138 # else
139 extern int __local_multiple_threads
140 # if !defined NOT_IN_libc || defined IS_IN_libpthread
141 attribute_hidden;
142 # else
144 # endif
145 # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
146 # endif
147 # else
148 # if !defined PIC
149 # define SINGLE_THREAD_P cmpl $0, __local_multiple_threads
150 # elif defined FLOATING_STACKS && USE___THREAD
151 # define SINGLE_THREAD_P cmpl $0, %gs:MULTIPLE_THREADS_OFFSET
152 # else
153 # if !defined NOT_IN_libc || defined IS_IN_libpthread
154 # define __SINGLE_THREAD_CMP cmpl $0, __local_multiple_threads@GOTOFF(%ecx)
155 # else
156 # define __SINGLE_THREAD_CMP \
157 movl __local_multiple_threads@GOT(%ecx), %ecx;\
158 cmpl $0, (%ecx)
159 # endif
160 # if !defined HAVE_HIDDEN || !USE___THREAD
161 # define SINGLE_THREAD_P \
162 SETUP_PIC_REG (cx); \
163 addl $_GLOBAL_OFFSET_TABLE_, %ecx; \
164 __SINGLE_THREAD_CMP
165 # else
166 # define SINGLE_THREAD_P \
167 call __i686.get_pc_thunk.cx; \
168 addl $_GLOBAL_OFFSET_TABLE_, %ecx; \
169 __SINGLE_THREAD_CMP
170 # endif
171 # endif
172 # endif
174 #elif !defined __ASSEMBLER__
176 /* This code should never be used but we define it anyhow. */
177 # define SINGLE_THREAD_P (1)
179 #endif