Advertisement
Guest User

crtstuff.c

a guest
Jan 24th, 2022
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. /* C++ CTOR / DTOR handling */
  2.  
  3. #include <stdlib.h>
  4.  
  5.  
  6. /* Used by exit procs */
  7. void *__dso_handle = 0;
  8. extern void __call_exitprocs (int code, void *ptr);
  9.  
  10. typedef void (*func_ptr) (void);
  11.  
  12. extern func_ptr __CTOR_LIST__[];
  13. extern func_ptr __DTOR_LIST__[];
  14.  
  15. /* Do all constructors. */
  16. static void __attribute__((used)) __do_global_ctors (void)
  17. {
  18. do
  19. {
  20. unsigned int i, n = (unsigned int) __CTOR_LIST__[0];
  21. for (i = n; i >= 1; i--)
  22. __CTOR_LIST__[i] ();
  23. } while (0);
  24. }
  25.  
  26. /* Do all destructors. */
  27. static void __attribute__((used)) __do_global_dtors (void)
  28. {
  29. do
  30. {
  31. unsigned int i, n = (unsigned int) __DTOR_LIST__[0];
  32. for (i = 0; i < n; i++)
  33. __DTOR_LIST__[i + 1] ();
  34. } while (0);
  35. }
  36.  
  37. /* Add function to .init section. */
  38. static void __attribute__((used, section (".init"))) __std_startup (void)
  39. {
  40. atexit (__do_global_dtors); /* First added, last called. */
  41. __do_global_ctors (); /* Do all constructors. */
  42. }
  43.  
  44. /* Add function to .fini section. */
  45. static void __attribute__((used, section (".fini"))) __std_cleanup (void)
  46. {
  47. __call_exitprocs (0, NULL);
  48. }
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement