OSDN Git Service

Replace FSF snail mail address with URLs
[uclinux-h8/uClibc.git] / libpthread / linuxthreads / sysdeps / unix / sysv / linux / i386 / sysdep-cancel.h
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.
4
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.
9
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.
14
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/>.  */
18
19 #include <tls.h>
20 #include <pt-machine.h>
21 #ifndef __ASSEMBLER__
22 # include <linuxthreads/internals.h>
23 #endif
24
25 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
26
27 # undef PSEUDO
28 # define PSEUDO(name, syscall_name, args)                                     \
29   .text;                                                                      \
30   ENTRY (name)                                                                \
31     SINGLE_THREAD_P;                                                          \
32     jne L(pseudo_cancel);                                                     \
33     DO_CALL (syscall_name, args);                                             \
34     cmpl $-4095, %eax;                                                        \
35     jae SYSCALL_ERROR_LABEL;                                                  \
36     ret;                                                                      \
37   L(pseudo_cancel):                                                           \
38     CENABLE                                                                   \
39     SAVE_OLDTYPE_##args                                                       \
40     PUSHCARGS_##args                                                          \
41     DOCARGS_##args                                                            \
42     movl $SYS_ify (syscall_name), %eax;                                       \
43     int $0x80                                                                 \
44     POPCARGS_##args;                                                          \
45     POPSTATE_##args                                                           \
46     cmpl $-4095, %eax;                                                        \
47     jae SYSCALL_ERROR_LABEL;                                                  \
48   L(pseudo_end):
49
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
56
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.  */
62
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);
70
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
76
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
82
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);
90
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);
98
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
103 #  ifdef __PIC__
104 #   define CENABLE      pushl %ebx; \
105                         call __i686.get_pc_thunk.bx; \
106                         addl     $_GLOBAL_OFFSET_TABLE_, %ebx; \
107                         call __librt_enable_asynccancel@PLT; \
108                         popl %ebx;
109 #   define CDISABLE     pushl %ebx; \
110                         call __i686.get_pc_thunk.bx; \
111                         addl     $_GLOBAL_OFFSET_TABLE_, %ebx; \
112                         call __librt_disable_asynccancel@PLT; \
113                         popl %ebx;
114 #  else
115 #   define CENABLE      call __librt_enable_asynccancel;
116 #   define CDISABLE     call __librt_disable_asynccancel
117 #  endif
118 # else
119 #  define CENABLE       call __libc_enable_asynccancel;
120 #  define CDISABLE      call __libc_disable_asynccancel
121 # endif
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
131
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
136 #else
137 # define __local_multiple_threads __librt_multiple_threads
138 #endif
139
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)
145 #  else
146 extern int __local_multiple_threads
147 #   if !defined NOT_IN_libc || defined IS_IN_libpthread
148   attribute_hidden;
149 #   else
150   ;
151 #   endif
152 #   define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
153 #  endif
154 # else
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
159 #  else
160 #   if !defined NOT_IN_libc || defined IS_IN_libpthread
161 #    define __SINGLE_THREAD_CMP cmpl $0, __local_multiple_threads@GOTOFF(%ecx)
162 #   else
163 #    define __SINGLE_THREAD_CMP \
164   movl __local_multiple_threads@GOT(%ecx), %ecx;\
165   cmpl $0, (%ecx)
166 #   endif
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;            \
171   __SINGLE_THREAD_CMP
172 #   else
173 #    define SINGLE_THREAD_P \
174   call __i686.get_pc_thunk.cx;                  \
175   addl $_GLOBAL_OFFSET_TABLE_, %ecx;            \
176   __SINGLE_THREAD_CMP
177 #   endif
178 #  endif
179 # endif
180
181 #elif !defined __ASSEMBLER__
182
183 /* This code should never be used but we define it anyhow.  */
184 # define SINGLE_THREAD_P (1)
185
186 #endif