From a3349cc8c1ff97e3f138571f773deada93c8efce Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Thu, 16 Nov 2023 18:39:41 +0800 Subject: [PATCH] Fix compilation errors on zephyr platform (#2777) Add dummy korp_rwlock struct and fix os_dir_stream definition on platform zephyr/riot/rt-thread/alios to fix the compilation errors. --- core/shared/platform/alios/platform_internal.h | 10 +++++++++- core/shared/platform/riot/platform_internal.h | 10 +++++++++- core/shared/platform/rt-thread/platform_internal.h | 10 +++++++++- core/shared/platform/zephyr/platform_internal.h | 10 +++++++++- product-mini/platforms/zephyr/simple/src/main.c | 10 ++++++++++ 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/core/shared/platform/alios/platform_internal.h b/core/shared/platform/alios/platform_internal.h index dbdf74953..d2897a6b5 100644 --- a/core/shared/platform/alios/platform_internal.h +++ b/core/shared/platform/alios/platform_internal.h @@ -32,6 +32,12 @@ typedef aos_task_t *aos_tid_t; typedef aos_mutex_t korp_mutex; typedef aos_sem_t korp_sem; +/* korp_rwlock is used in platform_api_extension.h, + we just define the type to make the compiler happy */ +typedef struct { + int dummy; +} korp_rwlock; + struct os_thread_wait_node; typedef struct os_thread_wait_node *os_thread_wait_list; typedef struct korp_cond { @@ -64,8 +70,10 @@ int signbit(double x); int isnan(double x); /* clang-format on */ +/* The below types are used in platform_api_extension.h, + we just define them to make the compiler happy */ typedef int os_file_handle; -typedef DIR *os_dir_stream; +typedef void *os_dir_stream; typedef int os_raw_file_handle; static inline os_file_handle diff --git a/core/shared/platform/riot/platform_internal.h b/core/shared/platform/riot/platform_internal.h index 1f71ffdb2..e88b25d40 100644 --- a/core/shared/platform/riot/platform_internal.h +++ b/core/shared/platform/riot/platform_internal.h @@ -40,6 +40,12 @@ typedef kernel_pid_t korp_tid; typedef mutex_t korp_mutex; typedef unsigned int korp_sem; +/* korp_rwlock is used in platform_api_extension.h, + we just define the type to make the compiler happy */ +typedef struct { + int dummy; +} korp_rwlock; + /* typedef sema_t korp_sem; */ struct os_thread_wait_node; @@ -52,8 +58,10 @@ typedef struct korp_cond { #define os_printf printf #define os_vprintf vprintf +/* The below types are used in platform_api_extension.h, + we just define them to make the compiler happy */ typedef int os_file_handle; -typedef DIR *os_dir_stream; +typedef void *os_dir_stream; typedef int os_raw_file_handle; #if WA_MATH diff --git a/core/shared/platform/rt-thread/platform_internal.h b/core/shared/platform/rt-thread/platform_internal.h index 0c2e1d82b..4ebdabb10 100644 --- a/core/shared/platform/rt-thread/platform_internal.h +++ b/core/shared/platform/rt-thread/platform_internal.h @@ -38,6 +38,12 @@ typedef struct rt_thread korp_cond; typedef struct rt_thread korp_thread; typedef unsigned int korp_sem; +/* korp_rwlock is used in platform_api_extension.h, + we just define the type to make the compiler happy */ +typedef struct { + int dummy; +} korp_rwlock; + typedef rt_uint8_t uint8_t; typedef rt_int8_t int8_t; typedef rt_uint16_t uint16_t; @@ -45,8 +51,10 @@ typedef rt_int16_t int16_t; typedef rt_uint64_t uint64_t; typedef rt_int64_t int64_t; +/* The below types are used in platform_api_extension.h, + we just define them to make the compiler happy */ typedef int os_file_handle; -typedef DIR *os_dir_stream; +typedef void *os_dir_stream; typedef int os_raw_file_handle; static inline os_file_handle diff --git a/core/shared/platform/zephyr/platform_internal.h b/core/shared/platform/zephyr/platform_internal.h index 048387817..2306fa06b 100644 --- a/core/shared/platform/zephyr/platform_internal.h +++ b/core/shared/platform/zephyr/platform_internal.h @@ -74,6 +74,12 @@ typedef korp_thread *korp_tid; typedef struct k_mutex korp_mutex; typedef unsigned int korp_sem; +/* korp_rwlock is used in platform_api_extension.h, + we just define the type to make the compiler happy */ +typedef struct { + int dummy; +} korp_rwlock; + struct os_thread_wait_node; typedef struct os_thread_wait_node *os_thread_wait_list; typedef struct korp_cond { @@ -148,8 +154,10 @@ void set_exec_mem_alloc_func(exec_mem_alloc_func_t alloc_func, exec_mem_free_func_t free_func); +/* The below types are used in platform_api_extension.h, + we just define them to make the compiler happy */ typedef int os_file_handle; -typedef DIR *os_dir_stream; +typedef void *os_dir_stream; typedef int os_raw_file_handle; static inline os_file_handle diff --git a/product-mini/platforms/zephyr/simple/src/main.c b/product-mini/platforms/zephyr/simple/src/main.c index a6479ba75..6c0b8fc82 100644 --- a/product-mini/platforms/zephyr/simple/src/main.c +++ b/product-mini/platforms/zephyr/simple/src/main.c @@ -265,8 +265,18 @@ iwasm_init(void) iwasm_main, NULL, NULL, NULL, MAIN_THREAD_PRIORITY, 0, K_NO_WAIT); return tid ? true : false; } + +#if KERNEL_VERSION_NUMBER < 0x030400 /* version 3.4.0 */ void main(void) { iwasm_init(); } +#else +int +main(void) +{ + iwasm_init(); + return 0; +} +#endif