1414#include "../common/libc_wasi.c"
1515#endif
1616
17+ #include "../common/wasm_proposal.c"
18+
1719static int app_argc ;
1820static char * * app_argv ;
1921
20- #define MODULE_PATH ("--module-path=")
21-
2222/* clang-format off */
2323static int
24- print_help ()
24+ print_help (void )
2525{
2626 printf ("Usage: iwasm [-options] wasm_file [args...]\n" );
2727 printf ("options:\n" );
28- printf (" -f|--function name Specify a function name of the module to run rather\n"
29- " than main\n" );
28+ printf (" -f|--function name Specify a function name of the module to run rather\n"
29+ " than main\n" );
3030#if WASM_ENABLE_LOG != 0
31- printf (" -v=n Set log verbose level (0 to 5, default is 2) larger\n"
32- " level with more log\n" );
31+ printf (" -v=n Set log verbose level (0 to 5, default is 2) larger\n"
32+ " level with more log\n" );
3333#endif
3434#if WASM_ENABLE_INTERP != 0
35- printf (" --interp Run the wasm app with interpreter mode\n" );
35+ printf (" --interp Run the wasm app with interpreter mode\n" );
3636#endif
3737#if WASM_ENABLE_FAST_JIT != 0
38- printf (" --fast-jit Run the wasm app with fast jit mode\n" );
38+ printf (" --fast-jit Run the wasm app with fast jit mode\n" );
3939#endif
4040#if WASM_ENABLE_JIT != 0
41- printf (" --llvm-jit Run the wasm app with llvm jit mode\n" );
41+ printf (" --llvm-jit Run the wasm app with llvm jit mode\n" );
4242#endif
4343#if WASM_ENABLE_JIT != 0 && WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_LAZY_JIT != 0
44- printf (" --multi-tier-jit Run the wasm app with multi-tier jit mode\n" );
44+ printf (" --multi-tier-jit Run the wasm app with multi-tier jit mode\n" );
4545#endif
46- printf (" --stack-size=n Set maximum stack size in bytes, default is 64 KB\n" );
46+ printf (" --stack-size=n Set maximum stack size in bytes, default is 64 KB\n" );
4747#if WASM_ENABLE_LIBC_WASI != 0
4848 printf (" --heap-size=n Set maximum heap size in bytes, default is 0 KB when libc wasi is enabled\n" );
4949#else
5050 printf (" --heap-size=n Set maximum heap size in bytes, default is 16 KB when libc wasi is diabled\n" );
5151#endif
52- #if WASM_ENABLE_GC != 0
53- printf (" --gc-heap-size=n Set maximum gc heap size in bytes,\n" );
54- printf (" default is %u KB\n" , GC_HEAP_SIZE_DEFAULT / 1024 );
55- #endif
5652#if WASM_ENABLE_SHARED_HEAP != 0
5753 printf (" --shared-heap-size=n Create shared heap of n bytes and attach to the wasm app.\n" );
5854 printf (" The size n will be adjusted to a minumum number aligned to page size\n" );
5955#endif
56+ #if WASM_ENABLE_FAST_JIT != 0
57+ printf (" --jit-codecache-size=n Set fast jit maximum code cache size in bytes,\n" );
58+ printf (" default is %u KB\n" , FAST_JIT_DEFAULT_CODE_CACHE_SIZE / 1024 );
59+ #endif
60+ #if WASM_ENABLE_GC != 0
61+ printf (" --gc-heap-size=n Set maximum gc heap size in bytes,\n" );
62+ printf (" default is %u KB\n" , GC_HEAP_SIZE_DEFAULT / 1024 );
63+ #endif
6064#if WASM_ENABLE_JIT != 0
6165 printf (" --llvm-jit-size-level=n Set LLVM JIT size level, default is 3\n" );
6266 printf (" --llvm-jit-opt-level=n Set LLVM JIT optimization level, default is 3\n" );
67+ #endif /* WASM_ENABLE_JIT != 0 */
68+ printf (" --repl Start a very simple REPL (read-eval-print-loop) mode\n"
69+ " that runs commands in the form of `FUNC ARG...`\n" );
70+ #if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
71+ printf (" --disable-bounds-checks Disable bounds checks for memory accesses\n" );
6372#endif
64- printf (" --repl Start a very simple REPL (read-eval-print-loop) mode\n"
65- " that runs commands in the form of `FUNC ARG...`\n" );
6673#if WASM_ENABLE_LIBC_WASI != 0
6774 libc_wasi_print_help ();
6875#endif
6976#if WASM_ENABLE_MULTI_MODULE != 0
70- printf (" --module-path=<path> Indicate a module search path. default is current\n"
71- " directory('./')\n" );
77+ printf (" --module-path=<path> Indicate a module search path. default is current\n"
78+ " directory('./')\n" );
7279#endif
7380#if WASM_ENABLE_LIB_PTHREAD != 0 || WASM_ENABLE_LIB_WASI_THREADS != 0
74- printf (" --max-threads=n Set maximum thread number per cluster, default is 4\n" );
81+ printf (" --max-threads=n Set maximum thread number per cluster, default is 4\n" );
7582#endif
7683#if WASM_ENABLE_DEBUG_INTERP != 0
77- printf (" -g=ip:port Set the debug sever address, default is debug disabled\n" );
84+ printf (" -g=ip:port Set the debug sever address, default is debug disabled\n" );
7885 printf (" if port is 0, then a random port will be used\n" );
7986#endif
80- printf (" --version Show version information\n" );
87+ printf (" --version Show version information\n" );
8188 return 1 ;
8289}
8390/* clang-format on */
@@ -190,6 +197,9 @@ static char global_heap_buf[WASM_GLOBAL_HEAP_SIZE] = { 0 };
190197#else
191198static void *
192199malloc_func (
200+ #if WASM_MEM_ALLOC_WITH_USAGE != 0
201+ mem_alloc_usage_t usage ,
202+ #endif
193203#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
194204 void * user_data ,
195205#endif
@@ -200,6 +210,9 @@ malloc_func(
200210
201211static void *
202212realloc_func (
213+ #if WASM_MEM_ALLOC_WITH_USAGE != 0
214+ mem_alloc_usage_t usage , bool full_size_mmaped ,
215+ #endif
203216#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
204217 void * user_data ,
205218#endif
@@ -210,6 +223,9 @@ realloc_func(
210223
211224static void
212225free_func (
226+ #if WASM_MEM_ALLOC_WITH_USAGE != 0
227+ mem_alloc_usage_t usage ,
228+ #endif
213229#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
214230 void * user_data ,
215231#endif
@@ -228,6 +244,7 @@ handle_module_path(const char *module_path)
228244}
229245
230246static char * module_search_path = "." ;
247+
231248static bool
232249module_reader_callback (package_type_t module_type , const char * module_name ,
233250 uint8 * * p_buffer , uint32 * p_size )
@@ -283,6 +300,14 @@ main(int argc, char *argv[])
283300#else
284301 uint32 heap_size = 16 * 1024 ;
285302#endif
303+ #if WASM_ENABLE_SHARED_HEAP != 0
304+ SharedHeapInitArgs shared_heap_init_args ;
305+ uint32 shared_heap_size = 0 ;
306+ void * shared_heap = NULL ;
307+ #endif
308+ #if WASM_ENABLE_FAST_JIT != 0
309+ uint32 jit_code_cache_size = FAST_JIT_DEFAULT_CODE_CACHE_SIZE ;
310+ #endif
286311#if WASM_ENABLE_GC != 0
287312 uint32 gc_heap_size = GC_HEAP_SIZE_DEFAULT ;
288313#endif
@@ -294,12 +319,16 @@ main(int argc, char *argv[])
294319 wasm_module_inst_t wasm_module_inst = NULL ;
295320 RunningMode running_mode = 0 ;
296321 RuntimeInitArgs init_args ;
322+ struct InstantiationArgs2 * inst_args ;
297323 char error_buf [128 ] = { 0 };
298324#if WASM_ENABLE_LOG != 0
299325 int log_verbose_level = 2 ;
300326#endif
301327 bool is_repl_mode = false;
302328 bool is_xip_file = false;
329+ #if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
330+ bool disable_bounds_checks = false;
331+ #endif
303332#if WASM_ENABLE_LIBC_WASI != 0
304333 libc_wasi_parse_context_t wasi_parse_ctx ;
305334#endif
@@ -351,6 +380,11 @@ main(int argc, char *argv[])
351380 else if (!strcmp (argv [0 ], "-- repl ")) {
352381 is_repl_mode = true;
353382 }
383+ #if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
384+ else if (!strcmp (argv [0 ], "-- disable - bounds - checks ")) {
385+ disable_bounds_checks = true;
386+ }
387+ #endif
354388 else if (!strncmp (argv [0 ], "--stack-size=" , 13 )) {
355389 if (argv [0 ][13 ] == '\0' )
356390 return print_help ();
@@ -361,20 +395,27 @@ main(int argc, char *argv[])
361395 return print_help ();
362396 heap_size = atoi (argv [0 ] + 12 );
363397 }
364- #if WASM_ENABLE_GC != 0
365- else if (!strncmp (argv [0 ], "--gc-heap-size=" , 15 )) {
366- if (argv [0 ][15 ] == '\0' )
367- return print_help ();
368- gc_heap_size = atoi (argv [0 ] + 15 );
369- }
370- #endif
371398#if WASM_ENABLE_SHARED_HEAP != 0
372399 else if (!strncmp (argv [0 ], "--shared-heap-size=" , 19 )) {
373400 if (argv [0 ][19 ] == '\0' )
374401 return print_help ();
375402 shared_heap_size = atoi (argv [0 ] + 19 );
376403 }
377404#endif
405+ #if WASM_ENABLE_FAST_JIT != 0
406+ else if (!strncmp (argv [0 ], "--jit-codecache-size=" , 21 )) {
407+ if (argv [0 ][21 ] == '\0' )
408+ return print_help ();
409+ jit_code_cache_size = atoi (argv [0 ] + 21 );
410+ }
411+ #endif
412+ #if WASM_ENABLE_GC != 0
413+ else if (!strncmp (argv [0 ], "--gc-heap-size=" , 15 )) {
414+ if (argv [0 ][15 ] == '\0' )
415+ return print_help ();
416+ gc_heap_size = atoi (argv [0 ] + 15 );
417+ }
418+ #endif
378419#if WASM_ENABLE_JIT != 0
379420 else if (!strncmp (argv [0 ], "--llvm-jit-size-level=" , 22 )) {
380421 if (argv [0 ][22 ] == '\0' )
@@ -408,7 +449,8 @@ main(int argc, char *argv[])
408449 }
409450#endif
410451#if WASM_ENABLE_MULTI_MODULE != 0
411- else if (!strncmp (argv [0 ], MODULE_PATH , strlen (MODULE_PATH ))) {
452+ else if (!strncmp (argv [0 ],
453+ "--module-path=" , strlen ("--module-path=" ))) {
412454 module_search_path = handle_module_path (argv [0 ]);
413455 if (!strlen (module_search_path )) {
414456 return print_help ();
@@ -440,6 +482,8 @@ main(int argc, char *argv[])
440482 wasm_runtime_get_version (& major , & minor , & patch );
441483 printf ("iwasm %" PRIu32 ".%" PRIu32 ".%" PRIu32 "\n" , major , minor ,
442484 patch );
485+ printf ("\n" );
486+ wasm_proposal_print_status ();
443487 return 0 ;
444488 }
445489 else {
@@ -485,6 +529,10 @@ main(int argc, char *argv[])
485529 init_args .mem_alloc_option .allocator .free_func = free_func ;
486530#endif
487531
532+ #if WASM_ENABLE_FAST_JIT != 0
533+ init_args .fast_jit_code_cache_size = jit_code_cache_size ;
534+ #endif
535+
488536#if WASM_ENABLE_GC != 0
489537 init_args .gc_heap_size = gc_heap_size ;
490538#endif
@@ -554,28 +602,27 @@ main(int argc, char *argv[])
554602 libc_wasi_init (wasm_module , argc , argv , & wasi_parse_ctx );
555603#endif
556604
605+ if (!wasm_runtime_instantiation_args_create (& inst_args )) {
606+ printf ("failed to create instantiate args\n" );
607+ goto fail3 ;
608+ }
609+ wasm_runtime_instantiation_args_set_default_stack_size (inst_args ,
610+ stack_size );
611+ wasm_runtime_instantiation_args_set_host_managed_heap_size (inst_args ,
612+ heap_size );
613+
557614 /* instantiate the module */
558- if (!(wasm_module_inst =
559- wasm_runtime_instantiate (wasm_module , stack_size , heap_size ,
560- error_buf , sizeof (error_buf )))) {
615+ wasm_module_inst = wasm_runtime_instantiate_ex2 (
616+ wasm_module , inst_args , error_buf , sizeof (error_buf ));
617+ wasm_runtime_instantiation_args_destroy (inst_args );
618+ if (!wasm_module_inst ) {
561619 printf ("%s\n" , error_buf );
562620 goto fail3 ;
563621 }
564622
565- #if WASM_ENABLE_SHARED_HEAP != 0
566- if (shared_heap_size > 0 ) {
567- memset (& shared_heap_init_args , 0 , sizeof (shared_heap_init_args ));
568- shared_heap_init_args .size = shared_heap_size ;
569- shared_heap = wasm_runtime_create_shared_heap (& shared_heap_init_args );
570-
571- if (!shared_heap ) {
572- printf ("Create shared heap failed.\n" );
573- goto fail5 ;
574- }
575- if (!wasm_runtime_attach_shared_heap (wasm_module_inst , shared_heap )) {
576- printf ("Attach shared heap failed.\n" );
577- goto fail5 ;
578- }
623+ #if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
624+ if (disable_bounds_checks ) {
625+ wasm_runtime_set_bounds_checks (wasm_module_inst , false);
579626 }
580627#endif
581628
@@ -596,6 +643,25 @@ main(int argc, char *argv[])
596643 }
597644#endif
598645
646+ #if WASM_ENABLE_SHARED_HEAP != 0
647+ if (shared_heap_size > 0 ) {
648+ memset (& shared_heap_init_args , 0 , sizeof (shared_heap_init_args ));
649+ shared_heap_init_args .size = shared_heap_size ;
650+ shared_heap = wasm_runtime_create_shared_heap (& shared_heap_init_args );
651+
652+ if (!shared_heap ) {
653+ printf ("Create preallocated shared heap failed\n" );
654+ goto fail6 ;
655+ }
656+
657+ /* attach module instance to the shared heap */
658+ if (!wasm_runtime_attach_shared_heap (wasm_module_inst , shared_heap )) {
659+ printf ("Attach shared heap failed.\n" );
660+ goto fail6 ;
661+ }
662+ }
663+ #endif
664+
599665 ret = 0 ;
600666 const char * exception = NULL ;
601667 if (is_repl_mode ) {
@@ -627,8 +693,11 @@ main(int argc, char *argv[])
627693 printf ("%s\n" , exception );
628694
629695#if WASM_ENABLE_SHARED_HEAP != 0
630- fail5 :
696+ fail6 :
631697#endif
698+
699+ /* fail5: label is used by posix/main.c */
700+
632701#if WASM_ENABLE_DEBUG_INTERP != 0
633702fail4 :
634703#endif
0 commit comments