From fe129f97b9c7b1f3ffd5333e873660ae4fe8349c Mon Sep 17 00:00:00 2001 From: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> Date: Mon, 6 Oct 2025 12:25:40 +0200 Subject: [PATCH 1/4] Remove warnings relevant to Zephyr platform Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> --- .../libc-wasi/sandboxed-system-primitives/src/posix.c | 2 +- core/shared/platform/zephyr/zephyr_file.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c index 3d90811bca..eea4dc32f8 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c @@ -2213,7 +2213,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds, // Temporary workaround (see PR#4377) #ifdef BH_PLATFORM_ZEPHYR - os_file_handle tfd = fos[i]->file_handle->fd; + int tfd = fos[i]->file_handle->fd; #else os_file_handle tfd = fos[i]->file_handle; #endif diff --git a/core/shared/platform/zephyr/zephyr_file.c b/core/shared/platform/zephyr/zephyr_file.c index 1f48bc010c..79b6756e3f 100644 --- a/core/shared/platform/zephyr/zephyr_file.c +++ b/core/shared/platform/zephyr/zephyr_file.c @@ -6,6 +6,7 @@ #include "platform_api_vmcore.h" #include "platform_api_extension.h" #include "libc_errno.h" +#include "bh_common.h" #include #include @@ -1195,4 +1196,4 @@ bool os_is_stderr_handle(os_file_handle handle) { return (handle == (os_file_handle)stderr); -} \ No newline at end of file +} From 81c0e0fc6425f36df3d5db74c3c171e21c7142a1 Mon Sep 17 00:00:00 2001 From: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> Date: Mon, 6 Oct 2025 12:49:14 +0200 Subject: [PATCH 2/4] Revert changing os_file_handle to int on Zephyr Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> --- .../libraries/libc-wasi/sandboxed-system-primitives/src/posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c index eea4dc32f8..3d90811bca 100644 --- a/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c +++ b/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c @@ -2213,7 +2213,7 @@ wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds, // Temporary workaround (see PR#4377) #ifdef BH_PLATFORM_ZEPHYR - int tfd = fos[i]->file_handle->fd; + os_file_handle tfd = fos[i]->file_handle->fd; #else os_file_handle tfd = fos[i]->file_handle; #endif From 08a8e0ec886bc46c2962c47c24e4b7b8a735e72f Mon Sep 17 00:00:00 2001 From: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> Date: Tue, 21 Oct 2025 12:39:16 +0200 Subject: [PATCH 3/4] Replace bh_* to generic solution Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> --- core/shared/platform/zephyr/zephyr_file.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/shared/platform/zephyr/zephyr_file.c b/core/shared/platform/zephyr/zephyr_file.c index 79b6756e3f..6e805a9131 100644 --- a/core/shared/platform/zephyr/zephyr_file.c +++ b/core/shared/platform/zephyr/zephyr_file.c @@ -6,7 +6,6 @@ #include "platform_api_vmcore.h" #include "platform_api_extension.h" #include "libc_errno.h" -#include "bh_common.h" #include #include @@ -121,13 +120,15 @@ zephyr_fs_alloc_obj(bool is_dir, const char *path, int *index) ptr = &desc_array[i]; ptr->used = true; ptr->is_dir = is_dir; - ptr->path = bh_strdup(path); ptr->dir_index = 0; + size_t path_len = strlen(path) + 1; + ptr->path = BH_MALLOC(path_len); if (ptr->path == NULL) { ptr->used = false; k_mutex_unlock(&desc_array_mutex); return NULL; } + strcpy(ptr->path, path); *index = i + 3; break; } @@ -851,8 +852,10 @@ os_renameat(os_file_handle old_handle, const char *old_path, for (int i = 0; i < CONFIG_WASI_MAX_OPEN_FILES; i++) { struct zephyr_fs_desc *ptr = &desc_array[i]; if (ptr->used && ptr->path && strcmp(ptr->path, abs_old_path) == 0) { - char *new_path_copy = bh_strdup(new_path); + size_t new_path_len = strlen(abs_new_path) + 1; + char *new_path_copy = BH_MALLOC(new_path_len); if (new_path_copy != NULL) { + strcpy(new_path_copy, abs_new_path); BH_FREE(ptr->path); ptr->path = new_path_copy; } From 50d92d36f2695d9684386a738c3af6d7d76a25b3 Mon Sep 17 00:00:00 2001 From: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> Date: Tue, 28 Oct 2025 07:48:00 +0100 Subject: [PATCH 4/4] Add failing branch to malloc check Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> --- core/shared/platform/zephyr/zephyr_file.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/shared/platform/zephyr/zephyr_file.c b/core/shared/platform/zephyr/zephyr_file.c index 6e805a9131..58d23e2d6d 100644 --- a/core/shared/platform/zephyr/zephyr_file.c +++ b/core/shared/platform/zephyr/zephyr_file.c @@ -859,6 +859,10 @@ os_renameat(os_file_handle old_handle, const char *old_path, BH_FREE(ptr->path); ptr->path = new_path_copy; } + else { + k_mutex_unlock(&desc_array_mutex); + return __WASI_ENOMEM; + } break; // Only one descriptor should match } }