]>
Commit | Line | Data |
---|---|---|
f7a9f785 | 1 | /* Copyright (C) 2002-2016 Free Software Foundation, Inc. |
7b44a5e0 UD |
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 | |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
7b44a5e0 UD |
18 | |
19 | #include <sysdep.h> | |
20 | #include <tls.h> | |
21 | #ifndef __ASSEMBLER__ | |
22 | # include <nptl/pthreadP.h> | |
23 | #endif | |
24 | ||
4f41c682 | 25 | #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt) |
7b44a5e0 | 26 | |
421665c4 UD |
27 | /* The code to disable cancellation depends on the fact that the called |
28 | functions are special. They don't modify registers other than %rax | |
29 | and %r11 if they return. Therefore we don't have to preserve other | |
30 | registers around these calls. */ | |
7b44a5e0 UD |
31 | # undef PSEUDO |
32 | # define PSEUDO(name, syscall_name, args) \ | |
33 | .text; \ | |
34 | ENTRY (name) \ | |
35 | SINGLE_THREAD_P; \ | |
36 | jne L(pseudo_cancel); \ | |
8348dcc8 UD |
37 | .type __##syscall_name##_nocancel,@function; \ |
38 | .globl __##syscall_name##_nocancel; \ | |
39 | __##syscall_name##_nocancel: \ | |
7b44a5e0 UD |
40 | DO_CALL (syscall_name, args); \ |
41 | cmpq $-4095, %rax; \ | |
42 | jae SYSCALL_ERROR_LABEL; \ | |
43 | ret; \ | |
8348dcc8 | 44 | .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \ |
7b44a5e0 | 45 | L(pseudo_cancel): \ |
421665c4 UD |
46 | /* We always have to align the stack before calling a function. */ \ |
47 | subq $8, %rsp; cfi_adjust_cfa_offset (8); \ | |
7b44a5e0 | 48 | CENABLE \ |
7b44a5e0 UD |
49 | /* The return value from CENABLE is argument for CDISABLE. */ \ |
50 | movq %rax, (%rsp); \ | |
421665c4 | 51 | DO_CALL (syscall_name, args); \ |
7b44a5e0 UD |
52 | movq (%rsp), %rdi; \ |
53 | /* Save %rax since it's the error code from the syscall. */ \ | |
421665c4 | 54 | movq %rax, %rdx; \ |
7b44a5e0 | 55 | CDISABLE \ |
421665c4 UD |
56 | movq %rdx, %rax; \ |
57 | addq $8,%rsp; cfi_adjust_cfa_offset (-8); \ | |
7b44a5e0 | 58 | cmpq $-4095, %rax; \ |
842a39cd | 59 | jae SYSCALL_ERROR_LABEL |
3e36c37d | 60 | |
7b44a5e0 | 61 | |
ce9f10f7 | 62 | # if IS_IN (libpthread) |
7b44a5e0 UD |
63 | # define CENABLE call __pthread_enable_asynccancel; |
64 | # define CDISABLE call __pthread_disable_asynccancel; | |
65 | # define __local_multiple_threads __pthread_multiple_threads | |
4f41c682 | 66 | # elif IS_IN (libc) |
7b44a5e0 UD |
67 | # define CENABLE call __libc_enable_asynccancel; |
68 | # define CDISABLE call __libc_disable_asynccancel; | |
69 | # define __local_multiple_threads __libc_multiple_threads | |
016afc75 | 70 | # elif IS_IN (librt) |
bbde8527 UD |
71 | # define CENABLE call __librt_enable_asynccancel; |
72 | # define CDISABLE call __librt_disable_asynccancel; | |
73 | # else | |
74 | # error Unsupported library | |
7b44a5e0 UD |
75 | # endif |
76 | ||
4f41c682 | 77 | # if IS_IN (libpthread) || IS_IN (libc) |
bbde8527 | 78 | # ifndef __ASSEMBLER__ |
7b44a5e0 UD |
79 | extern int __local_multiple_threads attribute_hidden; |
80 | # define SINGLE_THREAD_P \ | |
81 | __builtin_expect (__local_multiple_threads == 0, 1) | |
bbde8527 UD |
82 | # else |
83 | # define SINGLE_THREAD_P cmpl $0, __local_multiple_threads(%rip) | |
84 | # endif | |
85 | ||
7b44a5e0 | 86 | # else |
bbde8527 UD |
87 | |
88 | # ifndef __ASSEMBLER__ | |
89 | # define SINGLE_THREAD_P \ | |
90 | __builtin_expect (THREAD_GETMEM (THREAD_SELF, \ | |
91 | header.multiple_threads) == 0, 1) | |
92 | # else | |
93 | # define SINGLE_THREAD_P cmpl $0, %fs:MULTIPLE_THREADS_OFFSET | |
94 | # endif | |
95 | ||
7b44a5e0 UD |
96 | # endif |
97 | ||
98 | #elif !defined __ASSEMBLER__ | |
99 | ||
6e627806 | 100 | # define SINGLE_THREAD_P (1) |
ce6e047f | 101 | # define NO_CANCELLATION 1 |
7b44a5e0 UD |
102 | |
103 | #endif | |
6e627806 UD |
104 | |
105 | #ifndef __ASSEMBLER__ | |
106 | # define RTLD_SINGLE_THREAD_P \ | |
107 | __builtin_expect (THREAD_GETMEM (THREAD_SELF, \ | |
108 | header.multiple_threads) == 0, 1) | |
109 | #endif |