cpp_ctors.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) 2012-2014 Wind River Systems, Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file - Constructor module
  8. * @brief
  9. * The ctors section contains a list of function pointers that execute the
  10. * C++ constructors of static global objects. These must be executed before
  11. * the application's main() routine.
  12. *
  13. * NOTE: Not all compilers put those function pointers into the ctors section;
  14. * some put them into the init_array section instead.
  15. */
  16. /* What a constructor function pointer looks like */
  17. typedef void (*CtorFuncPtr)(void);
  18. /* Constructor function pointer list is generated by the linker script. */
  19. extern CtorFuncPtr __CTOR_LIST__[];
  20. extern CtorFuncPtr __CTOR_END__[];
  21. /**
  22. *
  23. * @brief Invoke all C++ style global object constructors
  24. *
  25. * This routine is invoked by the kernel prior to the execution of the
  26. * application's main().
  27. */
  28. void __do_global_ctors_aux(void)
  29. {
  30. unsigned int nCtors;
  31. nCtors = (unsigned long)__CTOR_LIST__[0];
  32. while (nCtors >= 1U) {
  33. __CTOR_LIST__[nCtors--]();
  34. }
  35. }