Skip to content

Commit 78c525d

Browse files
authored
platforms/nuttx: Add support for custom name sections & configurable heap pool (#407)
Co-authored-by: Huang Qi <[email protected]>
1 parent c13746c commit 78c525d

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

product-mini/platforms/nuttx/main.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ static char **app_argv;
2121
static int
2222
print_help()
2323
{
24+
/* clang-format off */
2425
printf("Usage: iwasm [-options] wasm_file [args...]\n");
2526
printf("options:\n");
2627
printf(" -f|--function name Specify a function name of the module to run rather\n"
@@ -46,6 +47,7 @@ print_help()
4647
#if WASM_ENABLE_LIB_PTHREAD != 0
4748
printf(" --max-threads=n Set maximum thread number per cluster, default is 4\n");
4849
#endif
50+
/* clang-format on */
4951
return 1;
5052
}
5153

@@ -89,10 +91,8 @@ validate_env_str(char *env)
8991
}
9092
#endif
9193

92-
#define USE_GLOBAL_HEAP_BUF 1
93-
94-
#if USE_GLOBAL_HEAP_BUF != 0
95-
static char global_heap_buf[164 * 1024] = { 0 };
94+
#if WASM_ENABLE_GLOBAL_HEAP_POOL != 0
95+
static char global_heap_buf[WASM_GLOBAL_HEAP_SIZE * BH_KB] = { 0 };
9696
#endif
9797

9898
#if WASM_ENABLE_MULTI_MODULE != 0
@@ -105,12 +105,13 @@ handle_module_path(const char *module_path)
105105

106106
static char *module_search_path = ".";
107107
static bool
108-
module_reader_callback(const char *module_name, uint8 **p_buffer,
108+
module_reader_callback(const char *module_name,
109+
uint8 **p_buffer,
109110
uint32 *p_size)
110111
{
111112
const char *format = "%s/%s.wasm";
112-
int sz = strlen(module_search_path) + strlen("/") + strlen(module_name) +
113-
strlen(".wasm") + 1;
113+
int sz = strlen(module_search_path) + strlen("/") + strlen(module_name)
114+
+ strlen(".wasm") + 1;
114115
char *wasm_file_name = BH_MALLOC(sz);
115116
if (!wasm_file_name) {
116117
return false;
@@ -245,7 +246,7 @@ main(int argc, char *argv[])
245246

246247
memset(&init_args, 0, sizeof(RuntimeInitArgs));
247248

248-
#if USE_GLOBAL_HEAP_BUF != 0
249+
#if WASM_ENABLE_GLOBAL_HEAP_POOL != 0
249250
init_args.mem_alloc_type = Alloc_With_Pool;
250251
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
251252
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);

product-mini/platforms/nuttx/wamr.mk

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ else
113113
CFLAGS += -DWASM_DISABLE_HW_BOUND_CHECK=0
114114
endif
115115

116+
ifeq ($(CONFIG_INTERPRETERS_WAMR_CUSTOM_NAME_SECTIONS),y)
117+
CFLAGS += -DWASM_ENABLE_CUSTOM_NAME_SECTION=1
118+
else
119+
CFLAGS += -DWASM_ENABLE_CUSTOM_NAME_SECTION=0
120+
endif
121+
122+
ifeq ($(CONFIG_INTERPRETERS_WAMR_GLOBAL_HEAP_POOL),y)
123+
CFLAGS += -DWASM_ENABLE_GLOBAL_HEAP_POOL=1
124+
CFLAGS += -DWASM_GLOBAL_HEAP_SIZE=$(CONFIG_INTERPRETERS_WAMR_GLOBAL_HEAP_POOL_SIZE)
125+
else
126+
CFLAGS += -DWASM_ENABLE_GLOBAL_HEAP_POOL=0
127+
endif
128+
116129
CFLAGS += -DBH_ENABLE_MEMORY_PROFILING=0
117130

118131
CFLAGS += -Wno-strict-prototypes -Wno-shadow -Wno-unused-variable

0 commit comments

Comments
 (0)