nptl: Remove __ASSUME_PRIVATE_FUTEX
[glibc.git] / sysdeps / unix / sysv / linux / x86_64 / cancellation.S
blob53dbabd6d28e1475bb7380bc44fedbe24092c4f1
1 /* Copyright (C) 2009-2018 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Ulrich Drepper <drepper@redhat.com>, 2009.
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.
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.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <http://www.gnu.org/licenses/>.  */
19 #include <sysdep.h>
20 #include <tcb-offsets.h>
21 #include <kernel-features.h>
22 #include "lowlevellock.h"
24 #define PTHREAD_UNWIND JUMPTARGET(__pthread_unwind)
25 #if IS_IN (libpthread)
26 # if defined SHARED && !defined NO_HIDDEN
27 #  undef PTHREAD_UNWIND
28 #  define PTHREAD_UNWIND __GI___pthread_unwind
29 # endif
30 #else
31 # ifndef SHARED
32         .weak __pthread_unwind
33 # endif
34 #endif
37 #define LOAD_PRIVATE_FUTEX_WAIT(reg) \
38         movl    $(FUTEX_WAIT | FUTEX_PRIVATE_FLAG), reg
40 /* It is crucial that the functions in this file don't modify registers
41    other than %rax and %r11.  The syscall wrapper code depends on this
42    because it doesn't explicitly save the other registers which hold
43    relevant values.  */
44         .text
46         .hidden __pthread_enable_asynccancel
47 ENTRY(__pthread_enable_asynccancel)
48         movl    %fs:CANCELHANDLING, %eax
49 2:      movl    %eax, %r11d
50         orl     $TCB_CANCELTYPE_BITMASK, %r11d
51         cmpl    %eax, %r11d
52         je      1f
54         lock
55         cmpxchgl %r11d, %fs:CANCELHANDLING
56         jnz     2b
58         andl    $(TCB_CANCELSTATE_BITMASK|TCB_CANCELTYPE_BITMASK|TCB_CANCELED_BITMASK|TCB_EXITING_BITMASK|TCB_CANCEL_RESTMASK|TCB_TERMINATED_BITMASK), %r11d
59         cmpl    $(TCB_CANCELTYPE_BITMASK|TCB_CANCELED_BITMASK), %r11d
60         je      3f
62 1:      ret
64 3:      subq    $8, %rsp
65         cfi_adjust_cfa_offset(8)
66         LP_OP(mov) $TCB_PTHREAD_CANCELED, %fs:RESULT
67         lock
68         orl     $TCB_EXITING_BITMASK, %fs:CANCELHANDLING
69         mov     %fs:CLEANUP_JMP_BUF, %RDI_LP
70         call    PTHREAD_UNWIND
71         hlt
72 END(__pthread_enable_asynccancel)
75         .hidden __pthread_disable_asynccancel
76 ENTRY(__pthread_disable_asynccancel)
77         testl   $TCB_CANCELTYPE_BITMASK, %edi
78         jnz     1f
80         movl    %fs:CANCELHANDLING, %eax
81 2:      movl    %eax, %r11d
82         andl    $~TCB_CANCELTYPE_BITMASK, %r11d
83         lock
84         cmpxchgl %r11d, %fs:CANCELHANDLING
85         jnz     2b
87         movl    %r11d, %eax
88 3:      andl    $(TCB_CANCELING_BITMASK|TCB_CANCELED_BITMASK), %eax
89         cmpl    $TCB_CANCELING_BITMASK, %eax
90         je      4f
91 1:      ret
93         /* Performance doesn't matter in this loop.  We will
94            delay until the thread is canceled.  And we will unlikely
95            enter the loop twice.  */
96 4:      mov     %fs:0, %RDI_LP
97         movl    $__NR_futex, %eax
98         xorq    %r10, %r10
99         addq    $CANCELHANDLING, %rdi
100         LOAD_PRIVATE_FUTEX_WAIT (%esi)
101         syscall
102         movl    %fs:CANCELHANDLING, %eax
103         jmp     3b
104 END(__pthread_disable_asynccancel)