]> git.ipfire.org Git - thirdparty/glibc.git/blob - nptl/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h
Update.
[thirdparty/glibc.git] / nptl / sysdeps / unix / sysv / linux / x86_64 / sysdep-cancel.h
1 /* Copyright (C) 2002, 2003 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 #ifndef __ASSEMBLER__
23 # include <nptl/pthreadP.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 cmpq $-4095, %rax; \
36 jae SYSCALL_ERROR_LABEL; \
37 ret; \
38 L(pseudo_cancel): \
39 /* Save registers that might get destroyed. */ \
40 SAVESTK_##args \
41 PUSHARGS_##args \
42 CENABLE \
43 /* Restore registers. */ \
44 POPARGS_##args \
45 /* The return value from CENABLE is argument for CDISABLE. */ \
46 movq %rax, (%rsp); \
47 movq $SYS_ify (syscall_name), %rax; \
48 syscall; \
49 movq (%rsp), %rdi; \
50 /* Save %rax since it's the error code from the syscall. */ \
51 movq %rax, 8(%rsp); \
52 CDISABLE \
53 movq 8(%rsp), %rax; \
54 RESTSTK_##args \
55 cmpq $-4095, %rax; \
56 jae SYSCALL_ERROR_LABEL; \
57 L(pseudo_end):
58
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 # else
98 # define CENABLE call __libc_enable_asynccancel;
99 # define CDISABLE call __libc_disable_asynccancel;
100 # define __local_multiple_threads __libc_multiple_threads
101 # endif
102
103 # ifndef __ASSEMBLER__
104 extern int __local_multiple_threads attribute_hidden;
105 # define SINGLE_THREAD_P \
106 __builtin_expect (__local_multiple_threads == 0, 1)
107 # else
108 # define SINGLE_THREAD_P cmpl $0, __local_multiple_threads(%rip)
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