Skip to content

Commit e01bcdc

Browse files
0xc0170c1728p9
authored andcommitted
ARMCC ulib - initalize RTOS before the standard library C++ init
Initialize the RTOS before initializing the standard library. This allows C++ constructors to be called in a well defined thread context.
1 parent 02ba7ea commit e01bcdc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

core/mbed-rtos/rtx/TARGET_CORTEX_M/RTX_CM_lib.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,11 @@ void set_main_stack(void) {
433433
#if defined (__CC_ARM)
434434

435435
#ifdef __MICROLIB
436+
437+
int main(void);
436438
void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF")));
439+
void $Super$$__cpp_initialize__aeabi_(void);
440+
437441
void _main_init (void) {
438442
osKernelInitialize();
439443
#ifdef __MBED_CMSIS_RTOS_CM
@@ -443,6 +447,19 @@ void _main_init (void) {
443447
osKernelStart();
444448
for (;;);
445449
}
450+
451+
void $Sub$$__cpp_initialize__aeabi_(void)
452+
{
453+
// this should invoke C++ initializers prior _main_init, we keep this empty and
454+
// invoke them after _main_init (=starts RTX kernel)
455+
}
456+
457+
void pre_main()
458+
{
459+
$Super$$__cpp_initialize__aeabi_();
460+
main();
461+
}
462+
446463
#else
447464

448465
void * armcc_heap_base;

0 commit comments

Comments
 (0)