]> git.ipfire.org Git - thirdparty/glibc.git/blob - nptl/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h
1e92de1dccc6020d3d9c392d6fdacbad462e2d87
[thirdparty/glibc.git] / nptl / sysdeps / unix / sysv / linux / x86_64 / sysdep-cancel.h
1 /* Copyright (C) 2002-2006, 2009 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 /* The code to disable cancellation depends on the fact that the called
29 functions are special. They don't modify registers other than %rax
30 and %r11 if they return. Therefore we don't have to preserve other
31 registers around these calls. */
32 # undef PSEUDO
33 # define PSEUDO(name, syscall_name, args) \
34 .text; \
35 ENTRY (name) \
36 SINGLE_THREAD_P; \
37 jne L(pseudo_cancel); \
38 .type __##syscall_name##_nocancel,@function; \
39 .globl __##syscall_name##_nocancel; \
40 __##syscall_name##_nocancel: \
41 DO_CALL (syscall_name, args); \
42 cmpq $-4095, %rax; \
43 jae SYSCALL_ERROR_LABEL; \
44 ret; \
45 .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
46 L(pseudo_cancel): \
47 /* We always have to align the stack before calling a function. */ \
48 subq $8, %rsp; cfi_adjust_cfa_offset (8); \
49 CENABLE \
50 /* The return value from CENABLE is argument for CDISABLE. */ \
51 movq %rax, (%rsp); \
52 DO_CALL (syscall_name, args); \
53 movq (%rsp), %rdi; \
54 /* Save %rax since it's the error code from the syscall. */ \
55 movq %rax, %rdx; \
56 CDISABLE \
57 movq %rdx, %rax; \
58 addq $8,%rsp; cfi_adjust_cfa_offset (-8); \
59 cmpq $-4095, %rax; \
60 jae SYSCALL_ERROR_LABEL; \
61 L(pseudo_end):
62
63
64 # ifdef IS_IN_libpthread
65 # define CENABLE call __pthread_enable_asynccancel;
66 # define CDISABLE call __pthread_disable_asynccancel;
67 # define __local_multiple_threads __pthread_multiple_threads
68 # elif !defined NOT_IN_libc
69 # define CENABLE call __libc_enable_asynccancel;
70 # define CDISABLE call __libc_disable_asynccancel;
71 # define __local_multiple_threads __libc_multiple_threads
72 # elif defined IS_IN_librt
73 # define CENABLE call __librt_enable_asynccancel;
74 # define CDISABLE call __librt_disable_asynccancel;
75 # else
76 # error Unsupported library
77 # endif
78
79 # if defined IS_IN_libpthread || !defined NOT_IN_libc
80 # ifndef __ASSEMBLER__
81 extern int __local_multiple_threads attribute_hidden;
82 # define SINGLE_THREAD_P \
83 __builtin_expect (__local_multiple_threads == 0, 1)
84 # else
85 # define SINGLE_THREAD_P cmpl $0, __local_multiple_threads(%rip)
86 # endif
87
88 # else
89
90 # ifndef __ASSEMBLER__
91 # define SINGLE_THREAD_P \
92 __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
93 header.multiple_threads) == 0, 1)
94 # else
95 # define SINGLE_THREAD_P cmpl $0, %fs:MULTIPLE_THREADS_OFFSET
96 # endif
97
98 # endif
99
100 #elif !defined __ASSEMBLER__
101
102 # define SINGLE_THREAD_P (1)
103 # define NO_CANCELLATION 1
104
105 #endif
106
107 #ifndef __ASSEMBLER__
108 # define RTLD_SINGLE_THREAD_P \
109 __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
110 header.multiple_threads) == 0, 1)
111 #endif