From fa3267165c211055a1d3af6f50167aa7cff03720 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Tue, 3 Aug 2021 14:08:49 -0700 Subject: [PATCH] samples: prod_consumer: don't reuse main stack for app_b With demand paging, the main stack is not user mode capable and it would fail k_thread_user_mode_enter() under app_b_entry(). So create another thread and stack for app_b as this stack can be used in user mode. Signed-off-by: Daniel Leung --- samples/userspace/prod_consumer/src/main.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/samples/userspace/prod_consumer/src/main.c b/samples/userspace/prod_consumer/src/main.c index 156533e8177..6253077845c 100644 --- a/samples/userspace/prod_consumer/src/main.c +++ b/samples/userspace/prod_consumer/src/main.c @@ -17,6 +17,7 @@ #include "app_b.h" #define APP_A_STACKSIZE 2048 +#define APP_B_STACKSIZE 2048 LOG_MODULE_REGISTER(app_main); @@ -45,8 +46,13 @@ K_QUEUE_DEFINE(shared_queue_outgoing); struct k_thread app_a_thread; K_THREAD_STACK_DEFINE(app_a_stack, APP_A_STACKSIZE); +struct k_thread app_b_thread; +K_THREAD_STACK_DEFINE(app_b_stack, APP_B_STACKSIZE); + void main(void) { + k_tid_t thread_a, thread_b; + LOG_INF("APP A partition: %p %zu", (void *)app_a_partition.start, (size_t)app_a_partition.size); LOG_INF("Shared partition: %p %zu", (void *)shared_partition.start, @@ -58,10 +64,15 @@ void main(void) sys_heap_init(&shared_pool, shared_pool_mem, HEAP_BYTES); /* Spawn supervisor entry for application A */ - k_thread_create(&app_a_thread, app_a_stack, APP_A_STACKSIZE, - app_a_entry, NULL, NULL, NULL, - -1, K_INHERIT_PERMS, K_NO_WAIT); + thread_a = k_thread_create(&app_a_thread, app_a_stack, APP_A_STACKSIZE, + app_a_entry, NULL, NULL, NULL, + -1, K_INHERIT_PERMS, K_NO_WAIT); - /* Re-use main for app B supervisor mode setup */ - app_b_entry(NULL, NULL, NULL); + /* Spawn supervisor entry for application B */ + thread_b = k_thread_create(&app_b_thread, app_b_stack, APP_A_STACKSIZE, + app_b_entry, NULL, NULL, NULL, + -1, K_INHERIT_PERMS, K_NO_WAIT); + + k_thread_join(thread_a, K_FOREVER); + k_thread_join(thread_b, K_FOREVER); }