@@ -73,6 +73,14 @@ static size_t ocre_get_available_memory(void) {
7373}
7474#endif
7575
76+ #ifdef CONFIG_OCRE_SHARED_HEAP
77+ // Shared heap for memory-mapped access
78+ wasm_shared_heap_t _shared_heap = NULL ;
79+ #ifdef CONFIG_OCRE_SHARED_HEAP_BUF_VIRTUAL
80+ uint8 preallocated_buf [CONFIG_OCRE_SHARED_HEAP_BUF_SIZE ];
81+ #endif
82+ #endif
83+
7684static bool validate_container_memory (ocre_container_t * container ) {
7785#ifdef CONFIG_OCRE_MEMORY_CHECK_ENABLED
7886 size_t requested_heap = container -> ocre_container_data .heap_size ;
@@ -266,6 +274,30 @@ ocre_container_runtime_status_t CS_runtime_init(ocre_cs_ctx *ctx, ocre_container
266274#ifdef CONFIG_OCRE_CONTAINER_MESSAGING
267275 ocre_messaging_init ();
268276#endif
277+ #ifdef CONFIG_OCRE_SHARED_HEAP
278+ SharedHeapInitArgs heap_init_args ;
279+ memset (& heap_init_args , 0 , sizeof (heap_init_args ));
280+
281+ #ifdef CONFIG_OCRE_SHARED_HEAP_BUF_PHYSICAL
282+ // Physical mode - map hardware register address
283+ heap_init_args .pre_allocated_addr = (void * )CONFIG_OCRE_SHARED_HEAP_BUF_ADDRESS ;
284+ LOG_INF ("Creating physical memory mapping at 0x%08X (hardware registers)" ,
285+ CONFIG_OCRE_SHARED_HEAP_BUF_ADDRESS );
286+ #elif CONFIG_OCRE_SHARED_HEAP_BUF_VIRTUAL
287+ // Virtual mode - allocate from RAM
288+ heap_init_args .pre_allocated_addr = preallocated_buf ;
289+ LOG_INF ("Creating virtual shared heap in RAM, size=%d bytes" ,
290+ CONFIG_OCRE_SHARED_HEAP_BUF_SIZE );
291+ #endif
292+ heap_init_args .size = CONFIG_OCRE_SHARED_HEAP_BUF_SIZE ;
293+ _shared_heap = wasm_runtime_create_shared_heap (& heap_init_args );
294+
295+ if (!_shared_heap ) {
296+ LOG_ERR ("Create preallocated shared heap failed" );
297+ return RUNTIME_STATUS_ERROR ;
298+ }
299+ #endif
300+
269301 storage_heap_init ();
270302 return RUNTIME_STATUS_INITIALIZED ;
271303}
@@ -352,6 +384,15 @@ ocre_container_status_t CS_run_container(ocre_container_t *container) {
352384 "0.0.0.0/0" ,
353385 };
354386 wasm_runtime_set_wasi_addr_pool (curr_container_arguments -> module , addr_pool , ADDRESS_POOL_SIZE );
387+ /**
388+ * Configure which domain names a WebAssembly module is allowed to resolve via DNS lookups
389+ * ns_lookup_pool: An array of domain name patterns (e.g., "example.com", "*.example.com", or "*" for any domain)
390+ */
391+
392+ const char * ns_lookup_pool [] = {
393+ "*"
394+ };
395+ wasm_runtime_set_wasi_ns_lookup_pool (curr_container_arguments -> module , ns_lookup_pool , sizeof (ns_lookup_pool ) / sizeof (ns_lookup_pool [0 ]));
355396 #endif
356397
357398 #ifdef CONFIG_OCRE_CONTAINER_FILESYSTEM
@@ -387,8 +428,35 @@ ocre_container_status_t CS_run_container(ocre_container_t *container) {
387428 defined(CONFIG_OCRE_CONTAINER_MESSAGING )
388429 ocre_register_module (curr_container_arguments -> module_inst );
389430#endif
390- }
431+ #ifdef CONFIG_OCRE_SHARED_HEAP
432+ LOG_INF ("Attaching shared heap to container %d" , curr_container_ID );
433+ /* attach module instance to the shared heap */
434+ if (!wasm_runtime_attach_shared_heap (curr_container_arguments -> module_inst , _shared_heap )) {
435+ LOG_ERR ("Attach shared heap failed." );
436+ return CONTAINER_STATUS_ERROR ;
437+ }
391438
439+ #ifdef CONFIG_OCRE_SHARED_HEAP_BUF_PHYSICAL
440+ // For physical mode, get the base address from the shared heap itself
441+ // The WASM address space already knows about the physical mapping
442+ uint32 shared_heap_base_addr = wasm_runtime_addr_native_to_app (
443+ curr_container_arguments -> module_inst ,
444+ (void * )CONFIG_OCRE_SHARED_HEAP_BUF_ADDRESS );
445+ LOG_INF ("Physical shared heap base address in app: 0x%x" , shared_heap_base_addr );
446+ #elif CONFIG_OCRE_SHARED_HEAP_BUF_VIRTUAL
447+ // For virtual mode, convert the allocated buffer address
448+ uint32 shared_heap_base_addr = wasm_runtime_addr_native_to_app (
449+ curr_container_arguments -> module_inst ,
450+ preallocated_buf );
451+ LOG_INF ("Virtual shared heap base address in app: 0x%x" , shared_heap_base_addr );
452+ #endif
453+
454+ if (shared_heap_base_addr == 0 ) {
455+ LOG_ERR ("Failed to get shared heap WASM address!" );
456+ return CONTAINER_STATUS_ERROR ;
457+ }
458+ #endif
459+ }
392460 core_mutex_lock (& container_mutex );
393461 int thread_idx = get_available_thread ();
394462 if (thread_idx == -1 ) {
0 commit comments