diff options
Diffstat (limited to 'sysdeps')
-rw-r--r-- | sysdeps/generic/fork.h | 19 | ||||
-rw-r--r-- | sysdeps/htl/fork.h | 29 | ||||
-rw-r--r-- | sysdeps/htl/pt-atfork.c | 1 | ||||
-rw-r--r-- | sysdeps/mach/hurd/fork.c | 15 | ||||
-rw-r--r-- | sysdeps/nptl/fork.h | 42 |
5 files changed, 25 insertions, 81 deletions
diff --git a/sysdeps/generic/fork.h b/sysdeps/generic/fork.h index 623cae28df..6cc842a425 100644 --- a/sysdeps/generic/fork.h +++ b/sysdeps/generic/fork.h @@ -6,3 +6,22 @@ parameter which is the DSO handle for the DSO which gets unloaded. The function so called has to remove the atfork handlers registered by this module. */ + + +/* System specific fork definition. Generic version. + Copyright (C) 2002-2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ diff --git a/sysdeps/htl/fork.h b/sysdeps/htl/fork.h deleted file mode 100644 index 0fccc309f8..0000000000 --- a/sysdeps/htl/fork.h +++ /dev/null @@ -1,29 +0,0 @@ -/* Register fork handlers. Generic version. - Copyright (C) 2002-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -/* Function to call to unregister fork handlers. */ -extern void __unregister_atfork (void *dso_handle) attribute_hidden; -#define UNREGISTER_ATFORK(dso_handle) __unregister_atfork (dso_handle) - - -/* C library side function to register new fork handlers. */ -extern int __register_atfork (void (*__prepare) (void), - void (*__parent) (void), - void (*__child) (void), - void *dso_handle); -libc_hidden_proto (__register_atfork) diff --git a/sysdeps/htl/pt-atfork.c b/sysdeps/htl/pt-atfork.c index 3d115d3819..dbb3b8f0cc 100644 --- a/sysdeps/htl/pt-atfork.c +++ b/sysdeps/htl/pt-atfork.c @@ -20,6 +20,7 @@ #include <pt-internal.h> #include <fork.h> #include <dso_handle.h> +#include <register-atfork.h> /* Hide the symbol so that no definition but the one locally in the executable or DSO is used. */ diff --git a/sysdeps/mach/hurd/fork.c b/sysdeps/mach/hurd/fork.c index 2b39f4e8b5..1c5299e686 100644 --- a/sysdeps/mach/hurd/fork.c +++ b/sysdeps/mach/hurd/fork.c @@ -30,6 +30,7 @@ #include <malloc/malloc-internal.h> #include <nss/nss_database.h> #include <unwind-link.h> +#include <register-atfork.h> #undef __fork @@ -37,12 +38,6 @@ /* Things that want to be locked while forking. */ symbol_set_declare (_hurd_fork_locks) - -/* Application callbacks registered through pthread_atfork. */ -DEFINE_HOOK (_hurd_atfork_prepare_hook, (void)); -DEFINE_HOOK (_hurd_atfork_child_hook, (void)); -DEFINE_HOOK (_hurd_atfork_parent_hook, (void)); - /* Things that want to be called before we fork, to prepare the parent for task_create, when the new child task will inherit our address space. */ DEFINE_HOOK (_hurd_fork_prepare_hook, (void)); @@ -72,7 +67,7 @@ __fork (void) struct hurd_sigstate *volatile ss; struct nss_database_data nss_database_data; - RUN_HOOK (_hurd_atfork_prepare_hook, ()); + __run_fork_handlers (atfork_run_prepare, true); ss = _hurd_self_sigstate (); __spin_lock (&ss->critical_section_lock); @@ -726,10 +721,8 @@ __fork (void) if (!err) { - if (pid != 0) - RUN_HOOK (_hurd_atfork_parent_hook, ()); - else - RUN_HOOK (_hurd_atfork_child_hook, ()); + __run_fork_handlers (pid == 0 ? atfork_run_child : atfork_run_parent, + true); } return err ? __hurd_fail (err) : pid; diff --git a/sysdeps/nptl/fork.h b/sysdeps/nptl/fork.h index 25002287b1..5246754290 100644 --- a/sysdeps/nptl/fork.h +++ b/sysdeps/nptl/fork.h @@ -17,50 +17,10 @@ <https://www.gnu.org/licenses/>. */ #include <lowlevellock.h> +#include <register-atfork.h> /* The fork generation counter, defined in libpthread. */ extern unsigned long int __fork_generation attribute_hidden; /* Pointer to the fork generation counter in the thread library. */ extern unsigned long int *__fork_generation_pointer attribute_hidden; - -/* Elements of the fork handler lists. */ -struct fork_handler -{ - void (*prepare_handler) (void); - void (*parent_handler) (void); - void (*child_handler) (void); - void *dso_handle; -}; - -/* Function to call to unregister fork handlers. */ -extern void __unregister_atfork (void *dso_handle) attribute_hidden; -#define UNREGISTER_ATFORK(dso_handle) __unregister_atfork (dso_handle) - -enum __run_fork_handler_type -{ - atfork_run_prepare, - atfork_run_child, - atfork_run_parent -}; - -/* Run the atfork handlers and lock/unlock the internal lock depending - of the WHO argument: - - - atfork_run_prepare: run all the PREPARE_HANDLER in reverse order of - insertion and locks the internal lock. - - atfork_run_child: run all the CHILD_HANDLER and unlocks the internal - lock. - - atfork_run_parent: run all the PARENT_HANDLER and unlocks the internal - lock. - - Perform locking only if DO_LOCKING. */ -extern void __run_fork_handlers (enum __run_fork_handler_type who, - _Bool do_locking) attribute_hidden; - -/* C library side function to register new fork handlers. */ -extern int __register_atfork (void (*__prepare) (void), - void (*__parent) (void), - void (*__child) (void), - void *dso_handle); -libc_hidden_proto (__register_atfork) |