Skip to content

Commit 409ecf6

Browse files
Patatermeriac
authored andcommitted
Call the pre-start event unprivileged
1 parent 1e18ea2 commit 409ecf6

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

rtos/rtx/TARGET_CORTEX_M/rt_CMSIS.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,6 @@ osStatus svcKernelStart (void) {
505505

506506
if (os_running) { return osOK; }
507507

508-
if (osEventObs && osEventObs->pre_start) {
509-
osEventObs->pre_start();
510-
}
511-
512508
rt_tsk_prio(0U, os_tsk.run->prio_base); // Restore priority
513509
if (os_tsk.run->task_id == 0xFFU) { // Idle Thread
514510
__set_PSP(os_tsk.run->tsk_stack + (8U*4U)); // Setup PSP
@@ -567,6 +563,15 @@ osStatus osKernelStart (void) {
567563
if (__get_IPSR() != 0U) {
568564
return osErrorISR; // Not allowed in ISR
569565
}
566+
567+
/* Call the pre-start event (from unprivileged mode) if the handler exists
568+
* and the kernel is not running. */
569+
/* FIXME osEventObs needs to be readable but not writable from unprivileged
570+
* code. */
571+
if (!osKernelRunning() && osEventObs && osEventObs->pre_start) {
572+
osEventObs->pre_start();
573+
}
574+
570575
switch (__get_CONTROL() & 0x03U) {
571576
case 0x00U: // Privileged Thread mode & MSP
572577
__set_PSP((uint32_t)(stack + 8)); // Initial PSP

rtos/rtx/TARGET_CORTEX_M/rt_OsEventObserver.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,11 @@ const OsEventObserver *osEventObs;
5151

5252
void osRegisterForOsEvents(const OsEventObserver *observer)
5353
{
54+
static uint8_t has_been_called = 0;
55+
if (has_been_called) {
56+
return;
57+
}
58+
has_been_called = 1;
59+
5460
osEventObs = observer;
5561
}

0 commit comments

Comments
 (0)