1 | /* Internal pthread_atfork definitions. |
2 | Copyright (C) 2021-2022 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
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, see |
17 | <https://www.gnu.org/licenses/>. */ |
18 | |
19 | #ifndef _REGISTER_ATFORK_H |
20 | #define _REGISTER_ATFORK_H |
21 | |
22 | /* Elements of the fork handler lists. */ |
23 | struct fork_handler |
24 | { |
25 | void (*prepare_handler) (void); |
26 | void (*parent_handler) (void); |
27 | void (*child_handler) (void); |
28 | void *dso_handle; |
29 | }; |
30 | |
31 | /* Function to call to unregister fork handlers. */ |
32 | extern void __unregister_atfork (void *dso_handle) attribute_hidden; |
33 | #define UNREGISTER_ATFORK(dso_handle) __unregister_atfork (dso_handle) |
34 | |
35 | enum __run_fork_handler_type |
36 | { |
37 | atfork_run_prepare, |
38 | atfork_run_child, |
39 | atfork_run_parent |
40 | }; |
41 | |
42 | /* Run the atfork handlers and lock/unlock the internal lock depending |
43 | of the WHO argument: |
44 | |
45 | - atfork_run_prepare: run all the PREPARE_HANDLER in reverse order of |
46 | insertion and locks the internal lock. |
47 | - atfork_run_child: run all the CHILD_HANDLER and unlocks the internal |
48 | lock. |
49 | - atfork_run_parent: run all the PARENT_HANDLER and unlocks the internal |
50 | lock. |
51 | |
52 | Perform locking only if DO_LOCKING. */ |
53 | extern void __run_fork_handlers (enum __run_fork_handler_type who, |
54 | _Bool do_locking) attribute_hidden; |
55 | |
56 | /* C library side function to register new fork handlers. */ |
57 | extern int __register_atfork (void (*__prepare) (void), |
58 | void (*__parent) (void), |
59 | void (*__child) (void), |
60 | void *dso_handle); |
61 | libc_hidden_proto (__register_atfork) |
62 | |
63 | #endif |
64 | |