register-atfork.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Internal pthread_atfork definitions.
  2. Copyright (C) 2021-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  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. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifndef _REGISTER_ATFORK_H
  16. #define _REGISTER_ATFORK_H
  17. /* Elements of the fork handler lists. */
  18. struct fork_handler
  19. {
  20. void (*prepare_handler) (void);
  21. void (*parent_handler) (void);
  22. void (*child_handler) (void);
  23. void *dso_handle;
  24. uint64_t id;
  25. };
  26. /* Function to call to unregister fork handlers. */
  27. extern void __unregister_atfork (void *dso_handle) attribute_hidden;
  28. #define UNREGISTER_ATFORK(dso_handle) __unregister_atfork (dso_handle)
  29. enum __run_fork_handler_type
  30. {
  31. atfork_run_prepare,
  32. atfork_run_child,
  33. atfork_run_parent
  34. };
  35. /* Run the atfork prepare handlers in the reverse order of registration and
  36. return the ID of the last registered handler. If DO_LOCKING is true, the
  37. internal lock is held locked upon return. */
  38. extern uint64_t __run_prefork_handlers (_Bool do_locking) attribute_hidden;
  39. /* Given a handler type (parent or child), run all the atfork handlers in
  40. the order of registration up to and including the handler with id equal
  41. to LASTRUN. If DO_LOCKING is true, the internal lock is unlocked prior
  42. to return. */
  43. extern void __run_postfork_handlers (enum __run_fork_handler_type who,
  44. _Bool do_locking,
  45. uint64_t lastrun) attribute_hidden;
  46. /* C library side function to register new fork handlers. */
  47. extern int __register_atfork (void (*__prepare) (void),
  48. void (*__parent) (void),
  49. void (*__child) (void),
  50. void *dso_handle);
  51. libc_hidden_proto (__register_atfork)
  52. #endif