From 286ea35508f382d628f0d41a060105829f1eaa10 Mon Sep 17 00:00:00 2001 From: tkernelcn <90441159+tkernelcn@users.noreply.github.com> Date: Tue, 2 Jan 2024 17:32:09 +0800 Subject: [PATCH] fixed(freertos): Fix crash when wasm app call pthread_exit(NULL) (#2970) before the change, only support wasm app exit like: ```c void *thread_routine(void *arg) { printf("Enter thread\n"); return NULL; } ``` if call pthread_exit, it will crash: ```c void *thread_routine(void *arg) { printf("Enter thread\n"); pthread_exit(NULL); return NULL; } ``` This commit lets both upstairs work correctly, test pass on stm32f103 mcu. --- .../common/freertos/freertos_thread.c | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/core/shared/platform/common/freertos/freertos_thread.c b/core/shared/platform/common/freertos/freertos_thread.c index 0356c3ed..e3524ac6 100644 --- a/core/shared/platform/common/freertos/freertos_thread.c +++ b/core/shared/platform/common/freertos/freertos_thread.c @@ -205,7 +205,6 @@ os_thread_wrapper(void *arg) thread_data->start_routine(thread_data->arg); os_thread_cleanup(); - vTaskDelete(NULL); } int @@ -301,6 +300,22 @@ os_thread_join(korp_tid thread, void **value_ptr) return BHT_OK; } +int +os_thread_detach(korp_tid thread) +{ + /* Do nothing */ + (void)thread; + return BHT_OK; +} + +void +os_thread_exit(void *retval) +{ + (void)retval; + os_thread_cleanup(); + vTaskDelete(NULL); +} + int os_mutex_init(korp_mutex *mutex) { @@ -469,3 +484,16 @@ os_cond_broadcast(korp_cond *cond) return BHT_OK; } + +uint8 * +os_thread_get_stack_boundary() +{ + /* TODO: get freertos stack boundary */ + return NULL; +} + +void +os_thread_jit_write_protect_np(bool enabled) +{ + (void)enabled; +}