Skip to content

Commit 11657db

Browse files
committed
core: thread_init_threads(): replace dummy thread ctx
When configuring paging, a thread context is needed to keep the VFP state, but thread context might not have been allocated yet with CFG_DYN_CONFIG=y so a dummy thread context might be needed until then. When thread_init_threads() assigns and initializes the real thread context, update the pointer and count variables using an unpaged function to make sure that pager code doesn't access the thread context while it's being replaced. This is needed in later patches with CFG_DYN_CONFIG=y and CFG_WITH_PAGER=y. Signed-off-by: Jens Wiklander <[email protected]>
1 parent 7017d1c commit 11657db

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

core/kernel/thread.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,16 +580,26 @@ static void init_thread_stacks(void)
580580
}
581581
#endif /*CFG_WITH_PAGER*/
582582

583+
static struct thread_ctx *swap_thread_ctx(struct thread_ctx *thr, size_t count)
584+
{
585+
struct thread_ctx *t = threads;
586+
587+
if (!thr)
588+
panic();
589+
threads = thr;
590+
thread_count = count;
591+
592+
return t;
593+
}
594+
DECLARE_KEEP_PAGER(swap_thread_ctx);
595+
583596
void thread_init_threads(size_t count)
584597
{
585598
size_t n = 0;
586599

587600
if (IS_ENABLED(CFG_DYN_CONFIG)) {
588601
assert(count <= CFG_NUM_THREADS);
589-
threads = calloc(count, sizeof(*threads));
590-
if (!threads)
591-
panic();
592-
thread_count = count;
602+
free(swap_thread_ctx(calloc(count, sizeof(*threads)), count));
593603
} else {
594604
assert(count == CFG_NUM_THREADS);
595605
}

0 commit comments

Comments
 (0)