Back to index

glibc  2.9
sysdep-cancel.h
Go to the documentation of this file.
00001 /* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <sysdep.h>
00020 #include <tls.h>
00021 #include <pt-machine.h>
00022 #ifndef __ASSEMBLER__
00023 # include <linuxthreads/internals.h>
00024 #endif
00025 
00026 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
00027 
00028 # define _IMM12 #-12
00029 # define _IMM16 #-16
00030 # define _IMP16 #16
00031 # undef PSEUDO
00032 # define PSEUDO(name, syscall_name, args) \
00033   .text; \
00034   ENTRY (name); \
00035     SINGLE_THREAD_P; \
00036     bf .Lpseudo_cancel; \
00037     DO_CALL (syscall_name, args); \
00038     mov r0,r1; \
00039     mov _IMM12,r2; \
00040     shad r2,r1; \
00041     not r1,r1; \
00042     tst r1,r1; \
00043     bt .Lsyscall_error; \
00044     bra .Lpseudo_end; \
00045      nop; \
00046  .Lpseudo_cancel: \
00047     sts.l pr,@-r15; \
00048     add _IMM16,r15; \
00049     SAVE_ARGS_##args; \
00050     CENABLE; \
00051     LOAD_ARGS_##args; \
00052     add _IMP16,r15; \
00053     lds.l @r15+,pr; \
00054     DO_CALL(syscall_name, args); \
00055     SYSCALL_INST_PAD; \
00056     sts.l pr,@-r15; \
00057     mov.l r0,@-r15; \
00058     CDISABLE; \
00059     mov.l @r15+,r0; \
00060     lds.l @r15+,pr; \
00061     mov r0,r1; \
00062     mov _IMM12,r2; \
00063     shad r2,r1; \
00064     not r1,r1; \
00065     tst r1,r1; \
00066     bf .Lpseudo_end; \
00067  .Lsyscall_error: \
00068     SYSCALL_ERROR_HANDLER; \
00069  .Lpseudo_end:
00070 
00071 # undef PSEUDO_END
00072 # define PSEUDO_END(sym) \
00073   END (sym)
00074 
00075 # define SAVE_ARGS_0 /* Nothing.  */
00076 # define SAVE_ARGS_1 SAVE_ARGS_0; mov.l r4,@(0,r15)
00077 # define SAVE_ARGS_2 SAVE_ARGS_1; mov.l r5,@(4,r15)
00078 # define SAVE_ARGS_3 SAVE_ARGS_2; mov.l r6,@(8,r15)
00079 # define SAVE_ARGS_4 SAVE_ARGS_3; mov.l r7,@(12,r15)
00080 # define SAVE_ARGS_5 SAVE_ARGS_4
00081 # define SAVE_ARGS_6 SAVE_ARGS_5
00082 
00083 # define LOAD_ARGS_0 /* Nothing.  */
00084 # define LOAD_ARGS_1 LOAD_ARGS_0; mov.l @(0,r15),r4
00085 # define LOAD_ARGS_2 LOAD_ARGS_1; mov.l @(4,r15),r5
00086 # define LOAD_ARGS_3 LOAD_ARGS_2; mov.l @(8,r15),r6
00087 # define LOAD_ARGS_4 LOAD_ARGS_3; mov.l @(12,r15),r7
00088 # define LOAD_ARGS_5 LOAD_ARGS_4
00089 # define LOAD_ARGS_6 LOAD_ARGS_5
00090 
00091 # ifdef IS_IN_libpthread
00092 #  define __local_enable_asynccancel      __pthread_enable_asynccancel
00093 #  define __local_disable_asynccancel     __pthread_disable_asynccancel
00094 #  define __local_multiple_threads __pthread_multiple_threads
00095 # elif !defined NOT_IN_libc
00096 #  define __local_enable_asynccancel      __libc_enable_asynccancel
00097 #  define __local_disable_asynccancel     __libc_disable_asynccancel
00098 #  define __local_multiple_threads __libc_multiple_threads
00099 # else
00100 #  define __local_enable_asynccancel      __librt_enable_asynccancel
00101 #  define __local_disable_asynccancel     __librt_disable_asynccancel
00102 #  define __local_multiple_threads __librt_multiple_threads
00103 # endif
00104 
00105 # if defined IS_IN_librt && defined PIC
00106 #  define CENABLE \
00107        mov.l r12,@-r15; \
00108        mov.l 1f,r12; \
00109        mova 1f,r0; \
00110        add r0,r12; \
00111        mov.l 2f,r0; \
00112        bsrf r0; \
00113         nop; \
00114      0: bra 3f; \
00115         mov r0,r2; \
00116        .align 2; \
00117      1: .long _GLOBAL_OFFSET_TABLE_; \
00118      2: .long __local_enable_asynccancel@PLT - (0b-.); \
00119      3: mov.l @r15+,r12
00120 
00121 #  define CDISABLE \
00122        mov.l r12,@-r15; \
00123        mov.l 1f,r12; \
00124        mova 1f,r0; \
00125        add r0,r12; \
00126        mov.l 2f,r0; \
00127        bsrf r0; \
00128         mov r2,r4; \
00129      0: bra 3f; \
00130         nop; \
00131        .align 2; \
00132      1: .long _GLOBAL_OFFSET_TABLE_; \
00133      2: .long __local_disable_asynccancel@PLT - (0b-.); \
00134      3: mov.l @r15+,r12
00135 # else
00136 #  define CENABLE \
00137        mov.l 1f,r0; \
00138        bsrf r0; \
00139         nop; \
00140      0: bra 2f; \
00141         mov r0,r2; \
00142        .align 2; \
00143      1: .long __local_enable_asynccancel - 0b; \
00144      2:
00145 
00146 #  define CDISABLE \
00147        mov.l 1f,r0; \
00148        bsrf r0; \
00149         mov r2,r4; \
00150      0: bra 2f; \
00151         nop; \
00152        .align 2; \
00153      1: .long __local_disable_asynccancel - 0b; \
00154      2:
00155 # endif
00156 
00157 # ifndef __ASSEMBLER__
00158 #  if defined FLOATING_STACKS && USE___THREAD && defined PIC
00159 #   define SINGLE_THREAD_P \
00160   __builtin_expect (THREAD_GETMEM (THREAD_SELF, p_multiple_threads) == 0, 1)
00161 #  else
00162 extern int __local_multiple_threads attribute_hidden;
00163 #   define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
00164 #  endif
00165 # else
00166 #  if !defined PIC
00167 #   define SINGLE_THREAD_P \
00168        mov.l 1f,r0; \
00169        mov.l @r0,r0; \
00170        bra 2f; \
00171         tst r0,r0; \
00172        .align 2; \
00173      1: .long __local_multiple_threads; \
00174      2:
00175 #  elif defined FLOATING_STACKS && USE___THREAD
00176 #   define SINGLE_THREAD_P \
00177        stc gbr,r0; \
00178        mov.w 0f,r1; \
00179        sub r1,r0; \
00180        mov.l @(MULTIPLE_THREADS_OFFSET,r0),r0; \
00181        bra 1f; \
00182         tst r0,r0; \
00183      0: .word TLS_PRE_TCB_SIZE; \
00184      1:
00185 
00186 #  else
00187 #   if !defined NOT_IN_libc || defined IS_IN_libpthread
00188 #    define SINGLE_THREAD_P \
00189        mov r12,r2; \
00190        mov.l 0f,r12; \
00191        mova 0f,r0; \
00192        add r0,r12; \
00193        mov.l 1f,r0; \
00194        mov.l @(r0,r12),r0; \
00195        mov r2,r12; \
00196        bra 2f; \
00197         tst r0,r0; \
00198        .align 2; \
00199      0: .long _GLOBAL_OFFSET_TABLE_; \
00200      1: .long __local_multiple_threads@GOTOFF; \
00201      2:
00202 #   else
00203 #    define SINGLE_THREAD_P \
00204        mov r12,r2; \
00205        mov.l 0f,r12; \
00206        mova 0f,r0; \
00207        add r0,r12; \
00208        mov.l 1f,r0; \
00209        mov.l @(r0,r12),r0; \
00210        mov.l @r0,r0; \
00211        mov r2,r12; \
00212        bra 2f; \
00213         tst r0,r0; \
00214        .align 2; \
00215      0: .long _GLOBAL_OFFSET_TABLE_; \
00216      1: .long __local_multiple_threads@GOT; \
00217      2:
00218 #   endif
00219 #  endif
00220 # endif
00221 
00222 #elif !defined __ASSEMBLER__
00223 
00224 /* This code should never be used but we define it anyhow.  */
00225 # define SINGLE_THREAD_P (1)
00226 
00227 #endif