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