1616#ifdef CONFIG_OCRE_CONTAINER_MESSAGING
1717#include "ocre_messaging/ocre_messaging.h"
1818#endif
19- #if defined(CONFIG_OCRE_TIMER ) || defined(CONFIG_OCRE_GPIO ) || defined(CONFIG_OCRE_SENSORS )
19+ #if defined(CONFIG_OCRE_TIMER ) || defined(CONFIG_OCRE_GPIO ) || defined(CONFIG_OCRE_SENSORS ) || \
20+ defined(CONFIG_OCRE_CONTAINER_MESSAGING )
2021#include "api/ocre_common.h"
2122#endif
2223
@@ -33,6 +34,16 @@ LOG_MODULE_DECLARE(ocre_cs_component, OCRE_LOG_LEVEL);
3334#include "cs_sm.h"
3435#include "cs_sm_impl.h"
3536
37+ // External RAM support for WAMR heap on boards that have it
38+ #if defined(CONFIG_MEMC )
39+ #if defined(CONFIG_BOARD_ARDUINO_PORTENTA_H7 )
40+ __attribute__((section ("SDRAM1" ), aligned (32 )))
41+ #elif defined(CONFIG_BOARD_B_U585I_IOT02A )
42+ __attribute__((section (".stm32_psram" ), aligned (32 )))
43+ #elif defined(CONFIG_BOARD_MIMXRT1064_EVK )
44+ __attribute__((section ("SDRAM" ), aligned (32 )))
45+ #endif // defined (<board>)
46+ #endif // defined(CONFIG_MEMC)
3647static char wamr_heap_buf [CONFIG_OCRE_WAMR_HEAP_BUFFER_SIZE ] = {0 };
3748
3849// Thread pool for container execution
@@ -329,36 +340,35 @@ ocre_container_status_t CS_run_container(ocre_container_t *container) {
329340 return CONTAINER_STATUS_RUNNING ;
330341 }
331342
332- #ifdef CONFIG_OCRE_NETWORKING
333- #define ADDRESS_POOL_SIZE 1
334- const char * addr_pool [ADDRESS_POOL_SIZE ] = {
335- "0.0.0.0/0" ,
336- };
337- wasm_runtime_set_wasi_addr_pool (curr_container_arguments -> module , addr_pool , ADDRESS_POOL_SIZE );
338- #endif
339-
340- #ifdef CONFIG_OCRE_CONTAINER_FILESYSTEM
341- // Simple for now: map CONTAINER_FS_PATH to /
342- // TODO: eventually every container should probably have its own root folder,
343- // however wasm_runtime_set_wasi_args expects constant values.
344- #define DIR_LIST_SIZE 1
345- static const char * dir_map_list [DIR_LIST_SIZE ] = {
346- "/::" CONTAINER_FS_PATH
347- };
348- wasm_runtime_set_wasi_args (curr_container_arguments -> module ,
349- NULL , 0 ,
350- dir_map_list , DIR_LIST_SIZE ,
351- NULL , 0 , NULL , 0 );
352- #endif
353-
354-
355343 if (container -> container_runtime_status != CONTAINER_STATUS_CREATED &&
356344 container -> container_runtime_status != CONTAINER_STATUS_STOPPED ) {
357345 LOG_ERR ("Container (ID: %d), is not in a valid state to run" , curr_container_ID );
358346 container -> container_runtime_status = CONTAINER_STATUS_ERROR ;
359347 return CONTAINER_STATUS_ERROR ;
360348 }
361349
350+ #ifdef CONFIG_OCRE_NETWORKING
351+ #define ADDRESS_POOL_SIZE 1
352+ const char * addr_pool [ADDRESS_POOL_SIZE ] = {
353+ "0.0.0.0/0" ,
354+ };
355+ wasm_runtime_set_wasi_addr_pool (curr_container_arguments -> module , addr_pool , ADDRESS_POOL_SIZE );
356+ #endif
357+
358+ #ifdef CONFIG_OCRE_CONTAINER_FILESYSTEM
359+ // Simple for now: map CONTAINER_FS_PATH to /
360+ // TODO: eventually every container should probably have its own root folder,
361+ // however wasm_runtime_set_wasi_args expects constant values.
362+ #define DIR_LIST_SIZE 1
363+ static const char * dir_map_list [DIR_LIST_SIZE ] = {
364+ "/::" CONTAINER_FS_PATH
365+ };
366+ wasm_runtime_set_wasi_args (curr_container_arguments -> module ,
367+ NULL , 0 ,
368+ dir_map_list , DIR_LIST_SIZE ,
369+ NULL , 0 , NULL , 0 );
370+ #endif
371+
362372 if (curr_container_arguments -> module_inst ) {
363373 LOG_INF ("WASM runtime already instantiated for container:%d" , curr_container_ID );
364374 } else {
@@ -446,7 +456,17 @@ ocre_container_status_t CS_stop_container(ocre_container_t *container, ocre_cont
446456
447457 for (int i = 0 ; i < CONTAINER_THREAD_POOL_SIZE ; i ++ ) {
448458 if (container_thread_active [i ] && container_threads [i ].user_options == curr_container_ID ) {
459+ #if defined(CONFIG_OCRE_CONTAINER_WAMR_TERMINATION )
460+ /**
461+ * wasm_runtime_terminate uses POSIX signals to terminate the thread from the outside; calling core_thread_destroy
462+ * would try to destroy again the thread, and pthread_join() will never return, while freeing the stack would cause
463+ * segfault. This separation is needed to distinguish platform supported by wamr with this features,
464+ * from those which aren't. Since this function exists on those platforms, but stubbed, config parameter is used.
465+ */
466+ wasm_runtime_terminate (curr_container_arguments -> module_inst );
467+ #else
449468 core_thread_destroy (& container_threads [i ]);
469+ #endif
450470 container_thread_active [i ] = false;
451471 }
452472 }
0 commit comments