Back to index

glibc  2.9
sysdep-cancel.h
Go to the documentation of this file.
00001 /* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <sysdep.h>
00021 #include <tls.h>
00022 #include <pt-machine.h>
00023 #ifndef __ASSEMBLER__
00024 # include <linuxthreads/internals.h>
00025 #endif
00026 
00027 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
00028 
00029 # undef PSEUDO
00030 # define PSEUDO(name, syscall_name, args)                            \
00031   .text;                                                             \
00032   ENTRY (name)                                                              \
00033     SINGLE_THREAD_P;                                                 \
00034     jne L(pseudo_cancel);                                            \
00035     DO_CALL (syscall_name, args);                                    \
00036     cmpl $-4095, %eax;                                                      \
00037     jae SYSCALL_ERROR_LABEL;                                                \
00038     ret;                                                             \
00039   L(pseudo_cancel):                                                  \
00040     CENABLE                                                          \
00041     SAVE_OLDTYPE_##args                                                     \
00042     PUSHCARGS_##args                                                 \
00043     DOCARGS_##args                                                   \
00044     movl $SYS_ify (syscall_name), %eax;                                     \
00045     int $0x80                                                        \
00046     POPCARGS_##args;                                                 \
00047     POPSTATE_##args                                                  \
00048     cmpl $-4095, %eax;                                                      \
00049     jae SYSCALL_ERROR_LABEL;                                                \
00050   L(pseudo_end):
00051 
00052 # define SAVE_OLDTYPE_0     movl %eax, %ecx;
00053 # define SAVE_OLDTYPE_1     SAVE_OLDTYPE_0
00054 # define SAVE_OLDTYPE_2     pushl %eax; cfi_adjust_cfa_offset (4);
00055 # define SAVE_OLDTYPE_3     SAVE_OLDTYPE_2
00056 # define SAVE_OLDTYPE_4     SAVE_OLDTYPE_2
00057 # define SAVE_OLDTYPE_5     SAVE_OLDTYPE_2
00058 
00059 # define PUSHCARGS_0 /* No arguments to push.  */
00060 # define DOCARGS_0   /* No arguments to frob.  */
00061 # define POPCARGS_0  /* No arguments to pop.  */
00062 # define _PUSHCARGS_0       /* No arguments to push.  */
00063 # define _POPCARGS_0 /* No arguments to pop.  */
00064 
00065 # define PUSHCARGS_1 movl %ebx, %edx; cfi_register (ebx, edx); PUSHCARGS_0
00066 # define DOCARGS_1   _DOARGS_1 (4)
00067 # define POPCARGS_1  POPCARGS_0; movl %edx, %ebx; cfi_restore (ebx);
00068 # define _PUSHCARGS_1       pushl %ebx; cfi_adjust_cfa_offset (4); \
00069                      cfi_rel_offset (ebx, 0); _PUSHCARGS_0
00070 # define _POPCARGS_1 _POPCARGS_0; popl %ebx; \
00071                      cfi_adjust_cfa_offset (-4); cfi_restore (ebx);
00072 
00073 # define PUSHCARGS_2 PUSHCARGS_1
00074 # define DOCARGS_2   _DOARGS_2 (12)
00075 # define POPCARGS_2  POPCARGS_1
00076 # define _PUSHCARGS_2       _PUSHCARGS_1
00077 # define _POPCARGS_2 _POPCARGS_1
00078 
00079 # define PUSHCARGS_3 _PUSHCARGS_2
00080 # define DOCARGS_3   _DOARGS_3 (20)
00081 # define POPCARGS_3  _POPCARGS_3
00082 # define _PUSHCARGS_3       _PUSHCARGS_2
00083 # define _POPCARGS_3 _POPCARGS_2
00084 
00085 # define PUSHCARGS_4 _PUSHCARGS_4
00086 # define DOCARGS_4   _DOARGS_4 (28)
00087 # define POPCARGS_4  _POPCARGS_4
00088 # define _PUSHCARGS_4       pushl %esi; cfi_adjust_cfa_offset (4); \
00089                      cfi_rel_offset (esi, 0); _PUSHCARGS_3
00090 # define _POPCARGS_4 _POPCARGS_3; popl %esi; \
00091                      cfi_adjust_cfa_offset (-4); cfi_restore (esi);
00092 
00093 # define PUSHCARGS_5 _PUSHCARGS_5
00094 # define DOCARGS_5   _DOARGS_5 (36)
00095 # define POPCARGS_5  _POPCARGS_5
00096 # define _PUSHCARGS_5       pushl %edi; cfi_adjust_cfa_offset (4); \
00097                      cfi_rel_offset (edi, 0); _PUSHCARGS_4
00098 # define _POPCARGS_5 _POPCARGS_4; popl %edi; \
00099                      cfi_adjust_cfa_offset (-4); cfi_restore (edi);
00100 
00101 # ifdef IS_IN_libpthread
00102 #  define CENABLE    call __pthread_enable_asynccancel;
00103 #  define CDISABLE   call __pthread_disable_asynccancel
00104 # elif defined IS_IN_librt
00105 #  ifdef PIC
00106 #   define CENABLE   pushl %ebx; \
00107                      call __i686.get_pc_thunk.bx; \
00108                      addl     $_GLOBAL_OFFSET_TABLE_, %ebx; \
00109                      call __librt_enable_asynccancel@PLT; \
00110                      popl %ebx;
00111 #   define CDISABLE  pushl %ebx; \
00112                      call __i686.get_pc_thunk.bx; \
00113                      addl     $_GLOBAL_OFFSET_TABLE_, %ebx; \
00114                      call __librt_disable_asynccancel@PLT; \
00115                      popl %ebx;
00116 #  else
00117 #   define CENABLE   call __librt_enable_asynccancel;
00118 #   define CDISABLE  call __librt_disable_asynccancel
00119 #  endif
00120 # else
00121 #  define CENABLE    call __libc_enable_asynccancel;
00122 #  define CDISABLE   call __libc_disable_asynccancel
00123 # endif
00124 # define POPSTATE_0 \
00125  pushl %eax; cfi_adjust_cfa_offset (4); movl %ecx, %eax; \
00126  CDISABLE; popl %eax; cfi_adjust_cfa_offset (-4);
00127 # define POPSTATE_1  POPSTATE_0
00128 # define POPSTATE_2  xchgl (%esp), %eax; CDISABLE; popl %eax; \
00129                      cfi_adjust_cfa_offset (-4);
00130 # define POPSTATE_3  POPSTATE_2
00131 # define POPSTATE_4  POPSTATE_3
00132 # define POPSTATE_5  POPSTATE_4
00133 
00134 #if !defined NOT_IN_libc
00135 # define __local_multiple_threads __libc_multiple_threads
00136 #elif defined IS_IN_libpthread
00137 # define __local_multiple_threads __pthread_multiple_threads
00138 #else
00139 # define __local_multiple_threads __librt_multiple_threads
00140 #endif
00141 
00142 # ifndef __ASSEMBLER__
00143 #  if defined FLOATING_STACKS && USE___THREAD && defined PIC
00144 #   define SINGLE_THREAD_P \
00145   __builtin_expect (THREAD_GETMEM (THREAD_SELF,                             \
00146                                p_header.data.multiple_threads) == 0, 1)
00147 #  else
00148 extern int __local_multiple_threads
00149 #   if !defined NOT_IN_libc || defined IS_IN_libpthread
00150   attribute_hidden;
00151 #   else
00152   ;
00153 #   endif
00154 #   define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
00155 #  endif
00156 # else
00157 #  if !defined PIC
00158 #   define SINGLE_THREAD_P cmpl $0, __local_multiple_threads
00159 #  elif defined FLOATING_STACKS && USE___THREAD
00160 #   define SINGLE_THREAD_P cmpl $0, %gs:MULTIPLE_THREADS_OFFSET
00161 #  else
00162 #   if !defined NOT_IN_libc || defined IS_IN_libpthread
00163 #    define __SINGLE_THREAD_CMP cmpl $0, __local_multiple_threads@GOTOFF(%ecx)
00164 #   else
00165 #    define __SINGLE_THREAD_CMP \
00166   movl __local_multiple_threads@GOT(%ecx), %ecx;\
00167   cmpl $0, (%ecx)
00168 #   endif
00169 #   if !defined HAVE_HIDDEN || !USE___THREAD
00170 #    define SINGLE_THREAD_P \
00171   SETUP_PIC_REG (cx);                            \
00172   addl $_GLOBAL_OFFSET_TABLE_, %ecx;             \
00173   __SINGLE_THREAD_CMP
00174 #   else
00175 #    define SINGLE_THREAD_P \
00176   call __i686.get_pc_thunk.cx;                   \
00177   addl $_GLOBAL_OFFSET_TABLE_, %ecx;             \
00178   __SINGLE_THREAD_CMP
00179 #   endif
00180 #  endif
00181 # endif
00182 
00183 #elif !defined __ASSEMBLER__
00184 
00185 /* This code should never be used but we define it anyhow.  */
00186 # define SINGLE_THREAD_P (1)
00187 
00188 #endif