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 uint64_t id; 30 }; 31 32 /* Function to call to unregister fork handlers. */ 33 extern void __unregister_atfork (void *dso_handle) attribute_hidden; 34 #define UNREGISTER_ATFORK(dso_handle) __unregister_atfork (dso_handle) 35 36 enum __run_fork_handler_type 37 { 38 atfork_run_prepare, 39 atfork_run_child, 40 atfork_run_parent 41 }; 42 43 /* Run the atfork prepare handlers in the reverse order of registration and 44 return the ID of the last registered handler. If DO_LOCKING is true, the 45 internal lock is held locked upon return. */ 46 extern uint64_t __run_prefork_handlers (_Bool do_locking) attribute_hidden; 47 48 /* Given a handler type (parent or child), run all the atfork handlers in 49 the order of registration up to and including the handler with id equal 50 to LASTRUN. If DO_LOCKING is true, the internal lock is unlocked prior 51 to return. */ 52 extern void __run_postfork_handlers (enum __run_fork_handler_type who, 53 _Bool do_locking, 54 uint64_t lastrun) 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