Skip to content

Commit 61552db

Browse files
committed
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 1266392 commit 61552db

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

libraries/rtos/rtx/TARGET_CORTEX_M/RTX_CM_lib.h

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

450450
#ifdef __MICROLIB
451+
452+
int main(void);
451453
void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF")));
454+
void $Super$$__cpp_initialize__aeabi_(void);
455+
452456
void _main_init (void) {
453457
osKernelInitialize();
454458
#ifdef __MBED_CMSIS_RTOS_CM
@@ -458,6 +462,19 @@ void _main_init (void) {
458462
osKernelStart();
459463
for (;;);
460464
}
465+
466+
void $Sub$$__cpp_initialize__aeabi_(void)
467+
{
468+
// this should invoke C++ initializers prior _main_init, we keep this empty and
469+
// invoke them after _main_init (=starts RTX kernel)
470+
}
471+
472+
void pre_main()
473+
{
474+
$Super$$__cpp_initialize__aeabi_();
475+
main();
476+
}
477+
461478
#else
462479

463480
void * armcc_heap_base;

0 commit comments

Comments
 (0)