exit.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Copyright (C) 1991-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #ifndef _EXIT_H
  15. #define _EXIT_H 1
  16. #include <stdbool.h>
  17. #include <stdint.h>
  18. #include <libc-lock.h>
  19. enum
  20. {
  21. ef_free, /* `ef_free' MUST be zero! */
  22. ef_us,
  23. ef_on,
  24. ef_at,
  25. ef_cxa
  26. };
  27. struct exit_function
  28. {
  29. /* `flavour' should be of type of the `enum' above but since we need
  30. this element in an atomic operation we have to use `long int'. */
  31. long int flavor;
  32. union
  33. {
  34. void (*at) (void);
  35. struct
  36. {
  37. void (*fn) (int status, void *arg);
  38. void *arg;
  39. } on;
  40. struct
  41. {
  42. void (*fn) (void *arg, int status);
  43. void *arg;
  44. void *dso_handle;
  45. } cxa;
  46. } func;
  47. };
  48. struct exit_function_list
  49. {
  50. struct exit_function_list *next;
  51. size_t idx;
  52. struct exit_function fns[32];
  53. };
  54. extern struct exit_function_list *__exit_funcs attribute_hidden;
  55. extern struct exit_function_list *__quick_exit_funcs attribute_hidden;
  56. extern uint64_t __new_exitfn_called attribute_hidden;
  57. /* True once all registered atexit/at_quick_exit/onexit handlers have been
  58. called */
  59. extern bool __exit_funcs_done attribute_hidden;
  60. /* This lock protects __exit_funcs, __quick_exit_funcs, __exit_funcs_done
  61. and __new_exitfn_called globals against simultaneous access from
  62. atexit/on_exit/at_quick_exit in multiple threads, and also from
  63. simultaneous access while another thread is in the middle of calling
  64. exit handlers. See BZ#14333. Note: for lists, the entire list, and
  65. each associated entry in the list, is protected for all access by this
  66. lock. */
  67. __libc_lock_define (extern, __exit_funcs_lock);
  68. extern struct exit_function *__new_exitfn (struct exit_function_list **listp)
  69. attribute_hidden;
  70. extern void __run_exit_handlers (int status,
  71. struct exit_function_list **listp,
  72. bool run_list_atexit, bool run_dtors)
  73. attribute_hidden __attribute__ ((__noreturn__));
  74. extern int __internal_atexit (void (*func) (void *), void *arg, void *d,
  75. struct exit_function_list **listp)
  76. attribute_hidden;
  77. extern int __cxa_at_quick_exit (void (*func) (void *), void *d);
  78. #endif /* exit.h */