chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / linuxthreads / sysdeps / unix / sysv / linux / x86_64 / sysdep-cancel.h
1 /* Copyright (C) 2002, 2003, 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 <sysdep.h>
21 #include <tls.h>
22 #include <pt-machine.h>
23 #ifndef __ASSEMBLER__
24 # include <linuxthreads/internals.h>
25 #endif
26
27 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
28
29 # undef PSEUDO
30 # define PSEUDO(name, syscall_name, args)                                     \
31   .text;                                                                      \
32   ENTRY (name)                                                                \
33     SINGLE_THREAD_P;                                                          \
34     jne L(pseudo_cancel);                                                     \
35     DO_CALL (syscall_name, args);                                             \
36     cmpq $-4095, %rax;                                                        \
37     jae SYSCALL_ERROR_LABEL;                                                  \
38     ret;                                                                      \
39   L(pseudo_cancel):                                                           \
40     /* Save registers that might get destroyed.  */                           \
41     SAVESTK_##args                                                            \
42     PUSHARGS_##args                                                           \
43     CENABLE                                                                   \
44     /* Restore registers.  */                                                 \
45     POPARGS_##args                                                            \
46     /* The return value from CENABLE is argument for CDISABLE.  */            \
47     movq %rax, (%rsp);                                                        \
48     movl $SYS_ify (syscall_name), %eax;                                       \
49     syscall;                                                                  \
50     movq (%rsp), %rdi;                                                        \
51     /* Save %rax since it's the error code from the syscall.  */              \
52     movq %rax, 8(%rsp);                                                       \
53     CDISABLE                                                                  \
54     movq 8(%rsp), %rax;                                                       \
55     RESTSTK_##args                                                            \
56     cmpq $-4095, %rax;                                                        \
57     jae SYSCALL_ERROR_LABEL;                                                  \
58   L(pseudo_end):
59
60 # define PUSHARGS_0     /* Nothing.  */
61 # define PUSHARGS_1     PUSHARGS_0 movq %rdi, 8(%rsp);
62 # define PUSHARGS_2     PUSHARGS_1 movq %rsi, 16(%rsp);
63 # define PUSHARGS_3     PUSHARGS_2 movq %rdx, 24(%rsp);
64 # define PUSHARGS_4     PUSHARGS_3 movq %rcx, 32(%rsp);
65 # define PUSHARGS_5     PUSHARGS_4 movq %r8, 40(%rsp);
66 # define PUSHARGS_6     PUSHARGS_5 movq %r9, 48(%rsp);
67
68 # define POPARGS_0      /* Nothing.  */
69 # define POPARGS_1      POPARGS_0 movq 8(%rsp), %rdi;
70 # define POPARGS_2      POPARGS_1 movq 16(%rsp), %rsi;
71 # define POPARGS_3      POPARGS_2 movq 24(%rsp), %rdx;
72 # define POPARGS_4      POPARGS_3 movq 32(%rsp), %r10;
73 # define POPARGS_5      POPARGS_4 movq 40(%rsp), %r8;
74 # define POPARGS_6      POPARGS_5 movq 48(%rsp), %r9;
75
76 /* We always have to align the stack before calling a function.  */
77 # define SAVESTK_0      subq $24, %rsp;cfi_adjust_cfa_offset(24);
78 # define SAVESTK_1      SAVESTK_0
79 # define SAVESTK_2      SAVESTK_1
80 # define SAVESTK_3      subq $40, %rsp;cfi_adjust_cfa_offset(40);
81 # define SAVESTK_4      SAVESTK_3
82 # define SAVESTK_5      subq $56, %rsp;cfi_adjust_cfa_offset(56);
83 # define SAVESTK_6      SAVESTK_5
84
85 # define RESTSTK_0      addq $24,%rsp;cfi_adjust_cfa_offset(-24);
86 # define RESTSTK_1      RESTSTK_0
87 # define RESTSTK_2      RESTSTK_1
88 # define RESTSTK_3      addq $40, %rsp;cfi_adjust_cfa_offset(-40);
89 # define RESTSTK_4      RESTSTK_3
90 # define RESTSTK_5      addq $56, %rsp;cfi_adjust_cfa_offset(-56);
91 # define RESTSTK_6      RESTSTK_5
92
93 # ifdef IS_IN_libpthread
94 #  define CENABLE       call __pthread_enable_asynccancel;
95 #  define CDISABLE      call __pthread_disable_asynccancel;
96 #  define __local_multiple_threads __pthread_multiple_threads
97 # elif !defined NOT_IN_libc
98 #  define CENABLE       call __libc_enable_asynccancel;
99 #  define CDISABLE      call __libc_disable_asynccancel;
100 #  define __local_multiple_threads __libc_multiple_threads
101 # else
102 #  define CENABLE       call __librt_enable_asynccancel@plt;
103 #  define CDISABLE      call __librt_disable_asynccancel@plt;
104 # endif
105
106 # if defined IS_IN_libpthread || !defined NOT_IN_libc
107 #  ifndef __ASSEMBLER__
108 extern int __local_multiple_threads attribute_hidden;
109 #   define SINGLE_THREAD_P \
110   __builtin_expect (__local_multiple_threads == 0, 1)
111 #  else
112 #   define SINGLE_THREAD_P cmpl $0, __local_multiple_threads(%rip)
113 #  endif
114
115 # else
116
117 #  ifndef __ASSEMBLER__
118 #   define SINGLE_THREAD_P \
119   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
120                                    p_header.data.multiple_threads) == 0, 1)
121 #  else
122 #   define SINGLE_THREAD_P cmpl $0, %fs:MULTIPLE_THREADS_OFFSET
123 #  endif
124
125 # endif
126
127 #elif !defined __ASSEMBLER__
128
129 /* This code should never be used but we define it anyhow.  */
130 # define SINGLE_THREAD_P (1)
131
132 #endif