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