shared_flat_initfini.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (C) 2006 CodeSourcery Inc
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. *
  6. * This file defines the main initialisation and finalisation code for
  7. * shared flat libraries. It in turn calls the initialisation and
  8. * finalisation code for each registered library.
  9. */
  10. #include "shared_flat_lib.h"
  11. /* A doubly-linked list of shared libraries. Those nearer the head
  12. * of the list should be initialised first and finalised last. */
  13. struct shared_flat_lib *__first_shared_lib;
  14. struct shared_flat_lib *__last_shared_lib;
  15. void __shared_flat_init(void)
  16. {
  17. struct shared_flat_lib *lib;
  18. void (**start)(void);
  19. void (**end)(void);
  20. for (lib = __first_shared_lib; lib; lib = lib->next) {
  21. end = lib->preinit_array_end;
  22. for (start = lib->preinit_array_start; start < end; start++)
  23. (*start)();
  24. }
  25. for (lib = __first_shared_lib; lib; lib = lib->next) {
  26. if (lib->init)
  27. lib->init();
  28. end = lib->init_array_end;
  29. for (start = lib->init_array_start; start < end; start++)
  30. (*start)();
  31. }
  32. }
  33. void __shared_flat_fini(void)
  34. {
  35. struct shared_flat_lib *lib;
  36. void (**start)(void);
  37. void (**end)(void);
  38. for (lib = __last_shared_lib; lib; lib = lib->prev) {
  39. start = lib->fini_array_start;
  40. for (end = lib->fini_array_end; end > start;)
  41. (*--end)();
  42. if (lib->fini)
  43. lib->fini();
  44. }
  45. }