ptatfork.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*++
  2. Copyright (c) 2015 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. ptatfork.c
  9. Abstract:
  10. This module implements the dynamic-object aware version of the
  11. pthread_atfork function.
  12. Author:
  13. Evan Green 4-May-2015
  14. Environment:
  15. User Mode C Library
  16. --*/
  17. //
  18. // ------------------------------------------------------------------- Includes
  19. //
  20. #include <pthread.h>
  21. //
  22. // ---------------------------------------------------------------- Definitions
  23. //
  24. //
  25. // ------------------------------------------------------ Data Type Definitions
  26. //
  27. //
  28. // ----------------------------------------------- Internal Function Prototypes
  29. //
  30. //
  31. // -------------------------------------------------------------------- Globals
  32. //
  33. //
  34. // There exists a per-module pointer, whose address is unique to each dynamic
  35. // module (or executable).
  36. //
  37. extern void *__dso_handle;
  38. //
  39. // ------------------------------------------------------------------ Functions
  40. //
  41. //
  42. // This routine must be statically linked in to any shared library or
  43. // application, as it references an object that is unique per dynamic library.
  44. //
  45. __HIDDEN
  46. int
  47. pthread_atfork (
  48. void (*PrepareRoutine)(void),
  49. void (*ParentRoutine)(void),
  50. void (*ChildRoutine)(void)
  51. )
  52. /*++
  53. Routine Description:
  54. This routine is called to register an at-fork handler, whose callbacks are
  55. called immediately before and after any fork operation.
  56. Arguments:
  57. PrepareRoutine - Supplies an optional pointer to a routine to be called
  58. immediately before a fork operation.
  59. ParentRoutine - Supplies an optional pointer to a routine to be called
  60. after a fork in the parent process.
  61. ChildRoutine - Supplies an optional pointer to ao routine to be called
  62. after a fork in the child process.
  63. Return Value:
  64. 0 on success.
  65. Returns an error number on failure.
  66. --*/
  67. {
  68. int Status;
  69. Status = __register_atfork(PrepareRoutine,
  70. ParentRoutine,
  71. ChildRoutine,
  72. &__dso_handle);
  73. return Status;
  74. }
  75. //
  76. // --------------------------------------------------------- Internal Functions
  77. //