Support cancellation in librt.
[kopensolaris-gnu/glibc.git] / linuxthreads / sysdeps / unix / sysv / linux / s390 / s390-64 / sysdep-cancel.h
1 /* Copyright (C) 2003 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
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 <sysdep.h>
21 #include <tls.h>
22 #ifndef __ASSEMBLER__
23 # include <linuxthreads/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 L(pseudo_cancel):                                                             \
32         STM_##args                                                            \
33         stmg    %r13,%r15,104(%r15);                                          \
34         lgr     %r14,%r15;                                                    \
35         aghi    %r15,-160;                                                    \
36         stg     %r14,0(%r15);                                                 \
37         brasl   %r14,CENABLE;                                                 \
38         lgr     %r0,%r2;                                                      \
39         LM_##args                                                             \
40         DO_CALL(syscall_name, args);                                          \
41         lgr     %r13,%r2;                                                     \
42         lgr     %r2,%r0;                                                      \
43         brasl   %r14,CDISABLE;                                                \
44         lgr     %r2,%r13;                                                     \
45         lmg     %r13,%r15,104+160(%r15);                                      \
46         j       L(pseudo_check);                                              \
47 ENTRY(name)                                                                   \
48         SINGLE_THREAD_P                                                       \
49         jne     L(pseudo_cancel);                                             \
50         DO_CALL(syscall_name, args);                                          \
51 L(pseudo_check):                                                              \
52         lghi    %r4,-4095;                                                    \
53         clgr    %r2,%r4;                                                      \
54         jgnl    SYSCALL_ERROR_LABEL;                                          \
55 L(pseudo_end):
56
57 # ifdef IS_IN_libpthread
58 #  define CENABLE       __pthread_enable_asynccancel
59 #  define CDISABLE      __pthread_disable_asynccancel
60 #  define __local_multiple_threads      __pthread_multiple_threads
61 # elif !defined NOT_IN_libc
62 #  define CENABLE       __libc_enable_asynccancel
63 #  define CDISABLE      __libc_disable_asynccancel
64 #  define __local_multiple_threads      __libc_multiple_threads
65 # else
66 #  define CENABLE       __librt_enable_asynccancel
67 #  define CDISABLE      __librt_disable_asynccancel
68 # endif
69
70 #define STM_0           /* Nothing */
71 #define STM_1           stg %r2,16(%r15);
72 #define STM_2           stmg %r2,%r3,16(%r15);
73 #define STM_3           stmg %r2,%r4,16(%r15);
74 #define STM_4           stmg %r2,%r5,16(%r15);
75 #define STM_5           stmg %r2,%r5,16(%r15);
76
77 #define LM_0            /* Nothing */
78 #define LM_1            lg %r2,16+160(%r15);
79 #define LM_2            lmg %r2,%r3,16+160(%r15);
80 #define LM_3            lmg %r2,%r4,16+160(%r15);
81 #define LM_4            lmg %r2,%r5,16+160(%r15);
82 #define LM_5            lmg %r2,%r5,16+160(%r15);
83
84 # if !defined NOT_IN_libc || defined IS_IN_libpthread
85 #  ifndef __ASSEMBLER__
86 extern int __local_multiple_threads attribute_hidden;
87 #   define SINGLE_THREAD_P \
88   __builtin_expect (__local_multiple_threads == 0, 1)
89 #  else
90 #   define SINGLE_THREAD_P \
91         larl    %r1,__local_multiple_threads;                                 \
92         icm     %r0,15,0(%r1);
93 #  endif
94
95 # else
96
97 #  ifndef __ASSEMBLER__
98 #   define SINGLE_THREAD_P \
99   __builtin_expect (THREAD_GETMEM (THREAD_SELF,                               \
100                                    p_header.data.multiple_threads) == 0, 1)
101 #  else
102 #   define SINGLE_THREAD_P \
103         ear     %r1,%a0;                                                      \
104         sllg    %r1,%r1,32;                                                   \
105         ear     %r1,%a1;                                                      \
106         icm     %r1,15,MULTIPLE_THREADS_OFFSET(%r1);
107 #  endif
108
109 # endif
110
111 #elif !defined __ASSEMBLER__
112
113 /* This code should never be used but we define it anyhow.  */
114 # define SINGLE_THREAD_P (1)
115
116 #endif