From 16bdb09ca4dec492415e5beb41dd32eada671430 Mon Sep 17 00:00:00 2001 From: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> Date: Thu, 13 Nov 2025 21:07:15 +0100 Subject: [PATCH 1/8] Initial changes Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> --- Kconfig | 21 +++++++++- boards/b_u585i_iot02a.conf | 6 +++ .../container_supervisor/cs_sm_impl.c | 41 ++++++++++++++++++- 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/Kconfig b/Kconfig index bf2d4a01..134381b0 100644 --- a/Kconfig +++ b/Kconfig @@ -224,5 +224,24 @@ config OCRE_NETWORKING default n help Enable networking support for containers. - + +config OCRE_SHARED_HEAP + bool "Enable container shared heap support" + default n + help + Enable shared heap support for containers. + +config OCRE_SHARED_HEAP_BUF_SIZE + int "Shared heap buffer size in bytes" + default 65536 + depends on OCRE_SHARED_HEAP + help + Size of the pre-allocated buffer for the shared heap. + This memory is shared between WebAssembly modules. + +config OCRE_SHARED_HEAP_BUF_ADDRESS + int + help + Shared heap buffer address. + endmenu diff --git a/boards/b_u585i_iot02a.conf b/boards/b_u585i_iot02a.conf index 90d47674..58063b8f 100644 --- a/boards/b_u585i_iot02a.conf +++ b/boards/b_u585i_iot02a.conf @@ -57,3 +57,9 @@ CONFIG_NET_SOCKETS_POLL_MAX=10 # Enable container networking support CONFIG_OCRE_NETWORKING=y + + +#CONFIG_OCRE_SHARED_HEAP=y +#CONFIG_OCRE_SHARED_HEAP_BUF_SIZE=4096*3 # Each GPIO bank is 1K, and there are 10 banks. Allocate 12k to align with 4096-byte pages. +#CONFIG_OCRE_SHARED_HEAP_BUF_ADDRESS=0x42021c14 # U585 GPIO register +#CONFIG_OCRE_SHARED_HEAP_BUF_ADDRESS=0x42020000 # U585 GPIO register base (GPIOA) diff --git a/src/ocre/components/container_supervisor/cs_sm_impl.c b/src/ocre/components/container_supervisor/cs_sm_impl.c index 04ba07ae..e77b9904 100644 --- a/src/ocre/components/container_supervisor/cs_sm_impl.c +++ b/src/ocre/components/container_supervisor/cs_sm_impl.c @@ -73,6 +73,12 @@ static size_t ocre_get_available_memory(void) { } #endif +#ifdef CONFIG_OCRE_SHARED_HEAP +// Shared heap for memory-mapped GPIO access +wasm_shared_heap_t _shared_heap = NULL; +uint8 preallocated_buf[CONFIG_OCRE_SHARED_HEAP_BUF_SIZE]; +#endif + static bool validate_container_memory(ocre_container_t *container) { #ifdef CONFIG_OCRE_MEMORY_CHECK_ENABLED size_t requested_heap = container->ocre_container_data.heap_size; @@ -266,6 +272,19 @@ ocre_container_runtime_status_t CS_runtime_init(ocre_cs_ctx *ctx, ocre_container #ifdef CONFIG_OCRE_CONTAINER_MESSAGING ocre_messaging_init(); #endif +#ifdef CONFIG_OCRE_SHARED_HEAP + SharedHeapInitArgs heap_init_args; + memset(&heap_init_args, 0, sizeof(heap_init_args)); + heap_init_args.pre_allocated_addr = (void *)CONFIG_OCRE_SHARED_HEAP_BUF_ADDRESS; + heap_init_args.size = CONFIG_OCRE_SHARED_HEAP_BUF_SIZE; + _shared_heap = wasm_runtime_create_shared_heap(&heap_init_args); + + if (!_shared_heap) { + LOG_ERR("Create preallocated shared heap failed"); + return RUNTIME_STATUS_ERROR; + } +#endif + storage_heap_init(); return RUNTIME_STATUS_INITIALIZED; } @@ -352,6 +371,15 @@ ocre_container_status_t CS_run_container(ocre_container_t *container) { "0.0.0.0/0", }; wasm_runtime_set_wasi_addr_pool(curr_container_arguments->module, addr_pool, ADDRESS_POOL_SIZE); + /** + * Configure which domain names a WebAssembly module is allowed to resolve via DNS lookups + * ns_lookup_pool: An array of domain name patterns (e.g., "example.com", "*.example.com", or "*" for any domain) + */ + + const char *ns_lookup_pool[] = { + "*" + }; + wasm_runtime_set_wasi_ns_lookup_pool(curr_container_arguments->module, ns_lookup_pool, sizeof(ns_lookup_pool) / sizeof(ns_lookup_pool[0])); #endif #ifdef CONFIG_OCRE_CONTAINER_FILESYSTEM @@ -387,8 +415,19 @@ ocre_container_status_t CS_run_container(ocre_container_t *container) { defined(CONFIG_OCRE_CONTAINER_MESSAGING) ocre_register_module(curr_container_arguments->module_inst); #endif - } +#ifdef CONFIG_OCRE_SHARED_HEAP + LOG_INF("Attaching shared heap to container %d", curr_container_ID); + /* attach module instance to the shared heap */ + if (!wasm_runtime_attach_shared_heap(curr_container_arguments->module_inst, _shared_heap)) { + LOG_ERR("Attach shared heap failed."); + return CONTAINER_STATUS_ERROR; + } + uint32 shared_heap_base_addr = wasm_runtime_addr_native_to_app(curr_container_arguments->module_inst, preallocated_buf); + LOG_INF("Shared heap base address in app: 0x%x", shared_heap_base_addr); + } +#endif +} core_mutex_lock(&container_mutex); int thread_idx = get_available_thread(); if (thread_idx == -1) { From d5d3d0b529bc663e383ede86343e1f4081f310df Mon Sep 17 00:00:00 2001 From: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> Date: Thu, 13 Nov 2025 21:43:15 +0100 Subject: [PATCH 2/8] Update wamr's hash to feature/branch temporarely Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> --- wasm-micro-runtime | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasm-micro-runtime b/wasm-micro-runtime index ce279ef9..0936a04d 160000 --- a/wasm-micro-runtime +++ b/wasm-micro-runtime @@ -1 +1 @@ -Subproject commit ce279ef9c45158c6fd4c6816f87581b1175c3818 +Subproject commit 0936a04daaa08e65ddda9ab5ff271f600c09b896 From d9c267b6c89634378eea0fe446548827bbd8ed7a Mon Sep 17 00:00:00 2001 From: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> Date: Thu, 13 Nov 2025 22:07:35 +0100 Subject: [PATCH 3/8] Minor cleanup Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> --- Kconfig | 8 ++++++-- boards/b_u585i_iot02a.conf | 6 ------ src/ocre/components/container_supervisor/cs_sm_impl.c | 5 ++--- src/shared/platform/posix/ocre_internal.cmake | 1 + src/shared/platform/zephyr/ocre_internal.cmake | 1 + 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Kconfig b/Kconfig index 134381b0..9c17269d 100644 --- a/Kconfig +++ b/Kconfig @@ -240,8 +240,12 @@ config OCRE_SHARED_HEAP_BUF_SIZE This memory is shared between WebAssembly modules. config OCRE_SHARED_HEAP_BUF_ADDRESS - int + hex "Shared heap buffer address" + default 0x00 + depends on OCRE_SHARED_HEAP help - Shared heap buffer address. + Shared heap buffer address for memory-mapped hardware access. + This should be set to the physical address of the hardware registers + that containers need to access directly. endmenu diff --git a/boards/b_u585i_iot02a.conf b/boards/b_u585i_iot02a.conf index 58063b8f..90d47674 100644 --- a/boards/b_u585i_iot02a.conf +++ b/boards/b_u585i_iot02a.conf @@ -57,9 +57,3 @@ CONFIG_NET_SOCKETS_POLL_MAX=10 # Enable container networking support CONFIG_OCRE_NETWORKING=y - - -#CONFIG_OCRE_SHARED_HEAP=y -#CONFIG_OCRE_SHARED_HEAP_BUF_SIZE=4096*3 # Each GPIO bank is 1K, and there are 10 banks. Allocate 12k to align with 4096-byte pages. -#CONFIG_OCRE_SHARED_HEAP_BUF_ADDRESS=0x42021c14 # U585 GPIO register -#CONFIG_OCRE_SHARED_HEAP_BUF_ADDRESS=0x42020000 # U585 GPIO register base (GPIOA) diff --git a/src/ocre/components/container_supervisor/cs_sm_impl.c b/src/ocre/components/container_supervisor/cs_sm_impl.c index e77b9904..39f029e7 100644 --- a/src/ocre/components/container_supervisor/cs_sm_impl.c +++ b/src/ocre/components/container_supervisor/cs_sm_impl.c @@ -74,7 +74,7 @@ static size_t ocre_get_available_memory(void) { #endif #ifdef CONFIG_OCRE_SHARED_HEAP -// Shared heap for memory-mapped GPIO access +// Shared heap for memory-mapped access wasm_shared_heap_t _shared_heap = NULL; uint8 preallocated_buf[CONFIG_OCRE_SHARED_HEAP_BUF_SIZE]; #endif @@ -425,9 +425,8 @@ ocre_container_status_t CS_run_container(ocre_container_t *container) { uint32 shared_heap_base_addr = wasm_runtime_addr_native_to_app(curr_container_arguments->module_inst, preallocated_buf); LOG_INF("Shared heap base address in app: 0x%x", shared_heap_base_addr); - } #endif -} + } core_mutex_lock(&container_mutex); int thread_idx = get_available_thread(); if (thread_idx == -1) { diff --git a/src/shared/platform/posix/ocre_internal.cmake b/src/shared/platform/posix/ocre_internal.cmake index 03ec062b..675dbb3e 100644 --- a/src/shared/platform/posix/ocre_internal.cmake +++ b/src/shared/platform/posix/ocre_internal.cmake @@ -43,6 +43,7 @@ set (WAMR_BUILD_LIBC_WASI 1) set (WAMR_BUILD_LIB_PTHREAD 1) set (WAMR_BUILD_REF_TYPES 1) set (WASM_ENABLE_LOG 1) +set (WAMR_BUILD_SHARED_HEAP 1) if (NOT DEFINED WAMR_BUILD_GLOBAL_HEAP_POOL) set (WAMR_BUILD_GLOBAL_HEAP_POOL 1) diff --git a/src/shared/platform/zephyr/ocre_internal.cmake b/src/shared/platform/zephyr/ocre_internal.cmake index 38fbcd16..cccf6375 100644 --- a/src/shared/platform/zephyr/ocre_internal.cmake +++ b/src/shared/platform/zephyr/ocre_internal.cmake @@ -40,6 +40,7 @@ set(WAMR_BUILD_LIBC_WASI 1) set(WAMR_BUILD_LIB_PTHREAD 1) set(WAMR_BUILD_REF_TYPES 1) set(WASM_ENABLE_LOG 1) +set (WAMR_BUILD_SHARED_HEAP 1) if(NOT DEFINED WAMR_BUILD_GLOBAL_HEAP_POOL) set(WAMR_BUILD_GLOBAL_HEAP_POOL 1) From 9d3b77698104cc0be143697faf0b8224c240b9ff Mon Sep 17 00:00:00 2001 From: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> Date: Fri, 14 Nov 2025 18:23:39 +0100 Subject: [PATCH 4/8] Update wamr's hash Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> --- wasm-micro-runtime | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasm-micro-runtime b/wasm-micro-runtime index 0936a04d..8a6dadfb 160000 --- a/wasm-micro-runtime +++ b/wasm-micro-runtime @@ -1 +1 @@ -Subproject commit 0936a04daaa08e65ddda9ab5ff271f600c09b896 +Subproject commit 8a6dadfb24064c60fcbef43c10f4574fcaf5dc0b From 7503618363158c6149fef3ec9d0b723550c62d0b Mon Sep 17 00:00:00 2001 From: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> Date: Fri, 14 Nov 2025 20:03:48 +0100 Subject: [PATCH 5/8] Update wamr's hash Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> --- wasm-micro-runtime | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasm-micro-runtime b/wasm-micro-runtime index 8a6dadfb..c434c946 160000 --- a/wasm-micro-runtime +++ b/wasm-micro-runtime @@ -1 +1 @@ -Subproject commit 8a6dadfb24064c60fcbef43c10f4574fcaf5dc0b +Subproject commit c434c946566ef12be62918fb06520a393da099c8 From 196c30a49bea0da5d51429f80e517c102e01ccf7 Mon Sep 17 00:00:00 2001 From: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> Date: Mon, 17 Nov 2025 15:03:56 +0100 Subject: [PATCH 6/8] Improve shared memory Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> --- Kconfig | 31 ++++++++++++++-- .../container_supervisor/cs_sm_impl.c | 35 +++++++++++++++++-- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/Kconfig b/Kconfig index 9c17269d..b6c78320 100644 --- a/Kconfig +++ b/Kconfig @@ -239,13 +239,38 @@ config OCRE_SHARED_HEAP_BUF_SIZE Size of the pre-allocated buffer for the shared heap. This memory is shared between WebAssembly modules. +choice OCRE_SHARED_HEAP_MODE + prompt "Shared heap mode" + depends on OCRE_SHARED_HEAP + default OCRE_SHARED_HEAP_BUF_VIRTUAL + help + Select the shared heap memory mode: + - Physical: Map physical hardware registers (e.g., GPIO) to WASM address space + - Virtual: Allocate shared heap from regular RAM + +config OCRE_SHARED_HEAP_BUF_PHYSICAL + bool "Physical (hardware register mapping)" + help + Enable physical memory mapping for hardware access. + Maps physical hardware registers (like GPIO at 0x42020000) to WASM address space. + Use this when containers need direct access to hardware peripherals. + +config OCRE_SHARED_HEAP_BUF_VIRTUAL + bool "Virtual (RAM allocation)" + help + Enable virtual shared heap allocated from regular RAM. + Use this for normal inter-module communication without + direct hardware access. + +endchoice + config OCRE_SHARED_HEAP_BUF_ADDRESS hex "Shared heap buffer address" default 0x00 depends on OCRE_SHARED_HEAP help - Shared heap buffer address for memory-mapped hardware access. - This should be set to the physical address of the hardware registers - that containers need to access directly. + Shared heap buffer address. + - For physical mode: Physical address of hardware registers + - For virtual mode: Leave as 0x00 to auto-allocate from RAM endmenu diff --git a/src/ocre/components/container_supervisor/cs_sm_impl.c b/src/ocre/components/container_supervisor/cs_sm_impl.c index 39f029e7..51578e98 100644 --- a/src/ocre/components/container_supervisor/cs_sm_impl.c +++ b/src/ocre/components/container_supervisor/cs_sm_impl.c @@ -76,8 +76,10 @@ static size_t ocre_get_available_memory(void) { #ifdef CONFIG_OCRE_SHARED_HEAP // Shared heap for memory-mapped access wasm_shared_heap_t _shared_heap = NULL; +#ifdef CONFIG_OCRE_SHARED_HEAP_BUF_VIRTUAL uint8 preallocated_buf[CONFIG_OCRE_SHARED_HEAP_BUF_SIZE]; #endif +#endif static bool validate_container_memory(ocre_container_t *container) { #ifdef CONFIG_OCRE_MEMORY_CHECK_ENABLED @@ -275,7 +277,18 @@ ocre_container_runtime_status_t CS_runtime_init(ocre_cs_ctx *ctx, ocre_container #ifdef CONFIG_OCRE_SHARED_HEAP SharedHeapInitArgs heap_init_args; memset(&heap_init_args, 0, sizeof(heap_init_args)); + +#ifdef CONFIG_OCRE_SHARED_HEAP_BUF_PHYSICAL + // Physical mode - map hardware register address heap_init_args.pre_allocated_addr = (void *)CONFIG_OCRE_SHARED_HEAP_BUF_ADDRESS; + LOG_INF("Creating physical memory mapping at 0x%08X (hardware registers)", + CONFIG_OCRE_SHARED_HEAP_BUF_ADDRESS); +#elif CONFIG_OCRE_SHARED_HEAP_BUF_VIRTUAL + // Virtual mode - allocate from RAM + heap_init_args.pre_allocated_addr = preallocated_buf; + LOG_INF("Creating virtual shared heap in RAM, size=%d bytes", + CONFIG_OCRE_SHARED_HEAP_BUF_SIZE); +#endif heap_init_args.size = CONFIG_OCRE_SHARED_HEAP_BUF_SIZE; _shared_heap = wasm_runtime_create_shared_heap(&heap_init_args); @@ -423,8 +436,26 @@ ocre_container_status_t CS_run_container(ocre_container_t *container) { return CONTAINER_STATUS_ERROR; } - uint32 shared_heap_base_addr = wasm_runtime_addr_native_to_app(curr_container_arguments->module_inst, preallocated_buf); - LOG_INF("Shared heap base address in app: 0x%x", shared_heap_base_addr); +#ifdef CONFIG_OCRE_SHARED_HEAP_BUF_PHYSICAL + // For physical mode, get the base address from the shared heap itself + // The WASM address space already knows about the physical mapping + uint32 shared_heap_base_addr = wasm_runtime_shared_heap_get_wasm_addr(_shared_heap); + LOG_INF("Physical shared heap base address in app: 0x%x", shared_heap_base_addr); +#elif CONFIG_OCRE_SHARED_HEAP_BUF_VIRTUAL + // For virtual mode, convert the allocated buffer address + uint32 shared_heap_base_addr = wasm_runtime_addr_native_to_app( + curr_container_arguments->module_inst, + preallocated_buf); + LOG_INF("Virtual shared heap base address in app: 0x%x", shared_heap_base_addr); +#endif + + if (shared_heap_base_addr == 0) { + LOG_ERR("Failed to get shared heap WASM address!"); + return CONTAINER_STATUS_ERROR; + } + + LOG_INF("GPIO registers mapped: physical 0x%08X -> WASM 0x%08X", + CONFIG_OCRE_SHARED_HEAP_BUF_ADDRESS, shared_heap_base_addr); #endif } core_mutex_lock(&container_mutex); From 5faa476df3d6d82644aa70df1b596fb683528783 Mon Sep 17 00:00:00 2001 From: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> Date: Mon, 17 Nov 2025 15:14:01 +0100 Subject: [PATCH 7/8] Fix shared memory conv Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> --- src/ocre/components/container_supervisor/cs_sm_impl.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ocre/components/container_supervisor/cs_sm_impl.c b/src/ocre/components/container_supervisor/cs_sm_impl.c index 51578e98..e7bc3312 100644 --- a/src/ocre/components/container_supervisor/cs_sm_impl.c +++ b/src/ocre/components/container_supervisor/cs_sm_impl.c @@ -439,7 +439,9 @@ ocre_container_status_t CS_run_container(ocre_container_t *container) { #ifdef CONFIG_OCRE_SHARED_HEAP_BUF_PHYSICAL // For physical mode, get the base address from the shared heap itself // The WASM address space already knows about the physical mapping - uint32 shared_heap_base_addr = wasm_runtime_shared_heap_get_wasm_addr(_shared_heap); + uint32 shared_heap_base_addr = wasm_runtime_addr_native_to_app( + curr_container_arguments->module_inst, + (void*)CONFIG_OCRE_SHARED_HEAP_BUF_ADDRESS); LOG_INF("Physical shared heap base address in app: 0x%x", shared_heap_base_addr); #elif CONFIG_OCRE_SHARED_HEAP_BUF_VIRTUAL // For virtual mode, convert the allocated buffer address @@ -453,9 +455,6 @@ ocre_container_status_t CS_run_container(ocre_container_t *container) { LOG_ERR("Failed to get shared heap WASM address!"); return CONTAINER_STATUS_ERROR; } - - LOG_INF("GPIO registers mapped: physical 0x%08X -> WASM 0x%08X", - CONFIG_OCRE_SHARED_HEAP_BUF_ADDRESS, shared_heap_base_addr); #endif } core_mutex_lock(&container_mutex); From 6ecf642e5ee16f4438e2f4c30ba538912bdc2ad9 Mon Sep 17 00:00:00 2001 From: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> Date: Wed, 19 Nov 2025 10:25:16 +0100 Subject: [PATCH 8/8] Fix WAMR's hash Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> --- wasm-micro-runtime | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasm-micro-runtime b/wasm-micro-runtime index c434c946..c9cf93fb 160000 --- a/wasm-micro-runtime +++ b/wasm-micro-runtime @@ -1 +1 @@ -Subproject commit c434c946566ef12be62918fb06520a393da099c8 +Subproject commit c9cf93fb10fe31e229658937a9afa2fbb41fb009