Skip to content

Commit ebbaf7e

Browse files
committed
stmhal/pendsv: Disable interrupts during a thread switch.
We can actually handle interrupts during a thread switch (because we always have a valid stack), but only if those interrupts don't access any of the thread state (because the state may not correspond to the stack pointer). So to be on the safe side we disable interrupts during the very short period of the thread state+stack switch.
1 parent 1a5c8d1 commit ebbaf7e

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

stmhal/pendsv.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,14 @@ void pendsv_isr_handler(void) {
106106
".no_obj:\n" // pendsv_object==NULL
107107
"push {r4-r11, lr}\n"
108108
"vpush {s16-s31}\n"
109+
"mrs r5, primask\n" // save PRIMASK in r5
110+
"cpsid i\n" // disable interrupts while we change stacks
109111
"mov r0, sp\n" // pass sp to save
110112
"mov r4, lr\n" // save lr because we are making a call
111113
"bl pyb_thread_next\n" // get next thread to execute
112114
"mov lr, r4\n" // restore lr
113115
"mov sp, r0\n" // switch stacks
116+
"msr primask, r5\n" // reenable interrupts
114117
"vpop {s16-s31}\n"
115118
"pop {r4-r11, lr}\n"
116119
"bx lr\n" // return from interrupt; will return to new thread

0 commit comments

Comments
 (0)