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, see
17 <http://www.gnu.org/licenses/>. */
20 #include <pt-machine.h>
22 # include <linuxthreads/internals.h>
25 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
28 # define PSEUDO(name, syscall_name, args) \
32 jne L(pseudo_cancel); \
33 DO_CALL (syscall_name, args); \
35 jae SYSCALL_ERROR_LABEL; \
42 movl $SYS_ify (syscall_name), %eax; \
47 jae SYSCALL_ERROR_LABEL; \
50 # define SAVE_OLDTYPE_0 movl %eax, %ecx;
51 # define SAVE_OLDTYPE_1 SAVE_OLDTYPE_0
52 # define SAVE_OLDTYPE_2 pushl %eax; cfi_adjust_cfa_offset (4);
53 # define SAVE_OLDTYPE_3 SAVE_OLDTYPE_2
54 # define SAVE_OLDTYPE_4 SAVE_OLDTYPE_2
55 # define SAVE_OLDTYPE_5 SAVE_OLDTYPE_2
57 # define PUSHCARGS_0 /* No arguments to push. */
58 # define DOCARGS_0 /* No arguments to frob. */
59 # define POPCARGS_0 /* No arguments to pop. */
60 # define _PUSHCARGS_0 /* No arguments to push. */
61 # define _POPCARGS_0 /* No arguments to pop. */
63 # define PUSHCARGS_1 movl %ebx, %edx; cfi_register (ebx, edx); PUSHCARGS_0
64 # define DOCARGS_1 _DOARGS_1 (4)
65 # define POPCARGS_1 POPCARGS_0; movl %edx, %ebx; cfi_restore (ebx);
66 # define _PUSHCARGS_1 pushl %ebx; cfi_adjust_cfa_offset (4); \
67 cfi_rel_offset (ebx, 0); _PUSHCARGS_0
68 # define _POPCARGS_1 _POPCARGS_0; popl %ebx; \
69 cfi_adjust_cfa_offset (-4); cfi_restore (ebx);
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; cfi_adjust_cfa_offset (4); \
87 cfi_rel_offset (esi, 0); _PUSHCARGS_3
88 # define _POPCARGS_4 _POPCARGS_3; popl %esi; \
89 cfi_adjust_cfa_offset (-4); cfi_restore (esi);
91 # define PUSHCARGS_5 _PUSHCARGS_5
92 # define DOCARGS_5 _DOARGS_5 (36)
93 # define POPCARGS_5 _POPCARGS_5
94 # define _PUSHCARGS_5 pushl %edi; cfi_adjust_cfa_offset (4); \
95 cfi_rel_offset (edi, 0); _PUSHCARGS_4
96 # define _POPCARGS_5 _POPCARGS_4; popl %edi; \
97 cfi_adjust_cfa_offset (-4); cfi_restore (edi);
99 # ifdef IS_IN_libpthread
100 # define CENABLE call __pthread_enable_asynccancel;
101 # define CDISABLE call __pthread_disable_asynccancel
102 # elif defined IS_IN_librt
104 # define CENABLE pushl %ebx; \
105 call __i686.get_pc_thunk.bx; \
106 addl $_GLOBAL_OFFSET_TABLE_, %ebx; \
107 call __librt_enable_asynccancel@PLT; \
109 # define CDISABLE pushl %ebx; \
110 call __i686.get_pc_thunk.bx; \
111 addl $_GLOBAL_OFFSET_TABLE_, %ebx; \
112 call __librt_disable_asynccancel@PLT; \
115 # define CENABLE call __librt_enable_asynccancel;
116 # define CDISABLE call __librt_disable_asynccancel
119 # define CENABLE call __libc_enable_asynccancel;
120 # define CDISABLE call __libc_disable_asynccancel
122 # define POPSTATE_0 \
123 pushl %eax; cfi_adjust_cfa_offset (4); movl %ecx, %eax; \
124 CDISABLE; popl %eax; cfi_adjust_cfa_offset (-4);
125 # define POPSTATE_1 POPSTATE_0
126 # define POPSTATE_2 xchgl (%esp), %eax; CDISABLE; popl %eax; \
127 cfi_adjust_cfa_offset (-4);
128 # define POPSTATE_3 POPSTATE_2
129 # define POPSTATE_4 POPSTATE_3
130 # define POPSTATE_5 POPSTATE_4
132 #if !defined NOT_IN_libc
133 # define __local_multiple_threads __libc_multiple_threads
134 #elif defined IS_IN_libpthread
135 # define __local_multiple_threads __pthread_multiple_threads
137 # define __local_multiple_threads __librt_multiple_threads
140 # ifndef __ASSEMBLER__
141 # if defined FLOATING_STACKS && defined __UCLIBC_HAS_TLS__ && defined __PIC__
142 # define SINGLE_THREAD_P \
143 __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
144 p_header.data.multiple_threads) == 0, 1)
146 extern int __local_multiple_threads
147 # if !defined NOT_IN_libc || defined IS_IN_libpthread
152 # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
155 # if !defined __PIC__
156 # define SINGLE_THREAD_P cmpl $0, __local_multiple_threads
157 # elif defined FLOATING_STACKS && defined __UCLIBC_HAS_TLS__
158 # define SINGLE_THREAD_P cmpl $0, %gs:MULTIPLE_THREADS_OFFSET
160 # if !defined NOT_IN_libc || defined IS_IN_libpthread
161 # define __SINGLE_THREAD_CMP cmpl $0, __local_multiple_threads@GOTOFF(%ecx)
163 # define __SINGLE_THREAD_CMP \
164 movl __local_multiple_threads@GOT(%ecx), %ecx;\
167 # if !defined HAVE_HIDDEN || !defined __UCLIBC_HAS_TLS__
168 # define SINGLE_THREAD_P \
169 SETUP_PIC_REG (cx); \
170 addl $_GLOBAL_OFFSET_TABLE_, %ecx; \
173 # define SINGLE_THREAD_P \
174 call __i686.get_pc_thunk.cx; \
175 addl $_GLOBAL_OFFSET_TABLE_, %ecx; \
181 #elif !defined __ASSEMBLER__
183 /* This code should never be used but we define it anyhow. */
184 # define SINGLE_THREAD_P (1)