Skip to content

Commit

Permalink
cpu/native: fix race condition in thread_yield_higher()
Browse files Browse the repository at this point in the history
Error case:
1. thread_yield_higher() stores the thread's ucontext
2. creates an "isr ucontext" for isr_thread_yield, switches to it

Case 1: no signals are pending, continues in isr_thread_yield()
3a. sched_run is called
4a. return to sched_active_thread ucontext

Case 2: signals pending (the crashing scenario), continues in native_irq_handler()
3b. handles signals
4b. if sched_context_switch_request is set, call sched_run
5b. return to sched_active_thread ucontext

4b misses the call to sched_run(), leading to a possible return into a
non-ready thread.

(cherry picked from commit 62bb4cc)
  • Loading branch information
kaspar030 authored and miri64 committed Feb 1, 2019
1 parent 85d49d0 commit 84a5c4f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions cpu/native/native_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ void isr_thread_yield(void)

void thread_yield_higher(void)
{
sched_context_switch_request = 1;

if (_native_in_isr == 0) {
ucontext_t *ctx = (ucontext_t *)(sched_active_thread->sp);
_native_in_isr = 1;
Expand All @@ -224,9 +226,6 @@ void thread_yield_higher(void)
}
irq_enable();
}
else {
sched_context_switch_request = 1;
}
}

void native_cpu_init(void)
Expand Down

0 comments on commit 84a5c4f

Please sign in to comment.