1 /* Copyright (C) 2002-2021 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18 #include <stdlib.h>
19 #include "pthreadP.h"
20 #include <shlib-compat.h>
21
22 void
23 __cleanup_fct_attribute
___pthread_register_cancel_defer(__pthread_unwind_buf_t * buf)24 ___pthread_register_cancel_defer (__pthread_unwind_buf_t *buf)
25 {
26 struct pthread_unwind_buf *ibuf = (struct pthread_unwind_buf *) buf;
27 struct pthread *self = THREAD_SELF;
28
29 /* Store old info. */
30 ibuf->priv.data.prev = THREAD_GETMEM (self, cleanup_jmp_buf);
31 ibuf->priv.data.cleanup = THREAD_GETMEM (self, cleanup);
32
33 /* Disable asynchronous cancellation for now. */
34 ibuf->priv.data.canceltype = THREAD_GETMEM (self, canceltype);
35 THREAD_SETMEM (self, canceltype, PTHREAD_CANCEL_DEFERRED);
36
37 /* Store the new cleanup handler info. */
38 THREAD_SETMEM (self, cleanup_jmp_buf, (struct pthread_unwind_buf *) buf);
39 }
40 versioned_symbol (libc, ___pthread_register_cancel_defer,
41 __pthread_register_cancel_defer, GLIBC_2_34);
42
43 #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_34)
44 compat_symbol (libpthread, ___pthread_register_cancel_defer,
45 __pthread_register_cancel_defer, GLIBC_2_3_3);
46 #endif
47
48 void
49 __cleanup_fct_attribute
___pthread_unregister_cancel_restore(__pthread_unwind_buf_t * buf)50 ___pthread_unregister_cancel_restore (__pthread_unwind_buf_t *buf)
51 {
52 struct pthread *self = THREAD_SELF;
53 struct pthread_unwind_buf *ibuf = (struct pthread_unwind_buf *) buf;
54
55 THREAD_SETMEM (self, cleanup_jmp_buf, ibuf->priv.data.prev);
56
57 THREAD_SETMEM (self, canceltype, ibuf->priv.data.canceltype);
58 if (ibuf->priv.data.canceltype == PTHREAD_CANCEL_ASYNCHRONOUS)
59 __pthread_testcancel ();
60 }
61 versioned_symbol (libc, ___pthread_unregister_cancel_restore,
62 __pthread_unregister_cancel_restore, GLIBC_2_34);
63
64 #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_34)
65 compat_symbol (libpthread, ___pthread_unregister_cancel_restore,
66 __pthread_unregister_cancel_restore, GLIBC_2_3_3);
67 #endif
68