14
14
#include "../common/libc_wasi.c"
15
15
#endif
16
16
17
+ #include "../common/wasm_proposal.c"
18
+
17
19
static int app_argc ;
18
20
static char * * app_argv ;
19
21
20
- #define MODULE_PATH ("--module-path=")
21
-
22
22
/* clang-format off */
23
23
static int
24
- print_help ()
24
+ print_help (void )
25
25
{
26
26
printf ("Usage: iwasm [-options] wasm_file [args...]\n" );
27
27
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" );
30
30
#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" );
33
33
#endif
34
34
#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" );
36
36
#endif
37
37
#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" );
39
39
#endif
40
40
#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" );
42
42
#endif
43
43
#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" );
45
45
#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" );
47
47
#if WASM_ENABLE_LIBC_WASI != 0
48
48
printf (" --heap-size=n Set maximum heap size in bytes, default is 0 KB when libc wasi is enabled\n" );
49
49
#else
50
50
printf (" --heap-size=n Set maximum heap size in bytes, default is 16 KB when libc wasi is diabled\n" );
51
51
#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
56
52
#if WASM_ENABLE_SHARED_HEAP != 0
57
53
printf (" --shared-heap-size=n Create shared heap of n bytes and attach to the wasm app.\n" );
58
54
printf (" The size n will be adjusted to a minumum number aligned to page size\n" );
59
55
#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
60
64
#if WASM_ENABLE_JIT != 0
61
65
printf (" --llvm-jit-size-level=n Set LLVM JIT size level, default is 3\n" );
62
66
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" );
63
72
#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" );
66
73
#if WASM_ENABLE_LIBC_WASI != 0
67
74
libc_wasi_print_help ();
68
75
#endif
69
76
#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" );
72
79
#endif
73
80
#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" );
75
82
#endif
76
83
#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" );
78
85
printf (" if port is 0, then a random port will be used\n" );
79
86
#endif
80
- printf (" --version Show version information\n" );
87
+ printf (" --version Show version information\n" );
81
88
return 1 ;
82
89
}
83
90
/* clang-format on */
@@ -190,6 +197,9 @@ static char global_heap_buf[WASM_GLOBAL_HEAP_SIZE] = { 0 };
190
197
#else
191
198
static void *
192
199
malloc_func (
200
+ #if WASM_MEM_ALLOC_WITH_USAGE != 0
201
+ mem_alloc_usage_t usage ,
202
+ #endif
193
203
#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
194
204
void * user_data ,
195
205
#endif
@@ -200,6 +210,9 @@ malloc_func(
200
210
201
211
static void *
202
212
realloc_func (
213
+ #if WASM_MEM_ALLOC_WITH_USAGE != 0
214
+ mem_alloc_usage_t usage , bool full_size_mmaped ,
215
+ #endif
203
216
#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
204
217
void * user_data ,
205
218
#endif
@@ -210,6 +223,9 @@ realloc_func(
210
223
211
224
static void
212
225
free_func (
226
+ #if WASM_MEM_ALLOC_WITH_USAGE != 0
227
+ mem_alloc_usage_t usage ,
228
+ #endif
213
229
#if WASM_MEM_ALLOC_WITH_USER_DATA != 0
214
230
void * user_data ,
215
231
#endif
@@ -228,6 +244,7 @@ handle_module_path(const char *module_path)
228
244
}
229
245
230
246
static char * module_search_path = "." ;
247
+
231
248
static bool
232
249
module_reader_callback (package_type_t module_type , const char * module_name ,
233
250
uint8 * * p_buffer , uint32 * p_size )
@@ -283,6 +300,14 @@ main(int argc, char *argv[])
283
300
#else
284
301
uint32 heap_size = 16 * 1024 ;
285
302
#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
286
311
#if WASM_ENABLE_GC != 0
287
312
uint32 gc_heap_size = GC_HEAP_SIZE_DEFAULT ;
288
313
#endif
@@ -294,12 +319,16 @@ main(int argc, char *argv[])
294
319
wasm_module_inst_t wasm_module_inst = NULL ;
295
320
RunningMode running_mode = 0 ;
296
321
RuntimeInitArgs init_args ;
322
+ struct InstantiationArgs2 * inst_args ;
297
323
char error_buf [128 ] = { 0 };
298
324
#if WASM_ENABLE_LOG != 0
299
325
int log_verbose_level = 2 ;
300
326
#endif
301
327
bool is_repl_mode = false;
302
328
bool is_xip_file = false;
329
+ #if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
330
+ bool disable_bounds_checks = false;
331
+ #endif
303
332
#if WASM_ENABLE_LIBC_WASI != 0
304
333
libc_wasi_parse_context_t wasi_parse_ctx ;
305
334
#endif
@@ -351,6 +380,11 @@ main(int argc, char *argv[])
351
380
else if (!strcmp (argv [0 ], "-- repl ")) {
352
381
is_repl_mode = true;
353
382
}
383
+ #if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
384
+ else if (!strcmp (argv [0 ], "-- disable - bounds - checks ")) {
385
+ disable_bounds_checks = true;
386
+ }
387
+ #endif
354
388
else if (!strncmp (argv [0 ], "--stack-size=" , 13 )) {
355
389
if (argv [0 ][13 ] == '\0' )
356
390
return print_help ();
@@ -361,20 +395,27 @@ main(int argc, char *argv[])
361
395
return print_help ();
362
396
heap_size = atoi (argv [0 ] + 12 );
363
397
}
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
371
398
#if WASM_ENABLE_SHARED_HEAP != 0
372
399
else if (!strncmp (argv [0 ], "--shared-heap-size=" , 19 )) {
373
400
if (argv [0 ][19 ] == '\0' )
374
401
return print_help ();
375
402
shared_heap_size = atoi (argv [0 ] + 19 );
376
403
}
377
404
#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
378
419
#if WASM_ENABLE_JIT != 0
379
420
else if (!strncmp (argv [0 ], "--llvm-jit-size-level=" , 22 )) {
380
421
if (argv [0 ][22 ] == '\0' )
@@ -408,7 +449,8 @@ main(int argc, char *argv[])
408
449
}
409
450
#endif
410
451
#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=" ))) {
412
454
module_search_path = handle_module_path (argv [0 ]);
413
455
if (!strlen (module_search_path )) {
414
456
return print_help ();
@@ -440,6 +482,8 @@ main(int argc, char *argv[])
440
482
wasm_runtime_get_version (& major , & minor , & patch );
441
483
printf ("iwasm %" PRIu32 ".%" PRIu32 ".%" PRIu32 "\n" , major , minor ,
442
484
patch );
485
+ printf ("\n" );
486
+ wasm_proposal_print_status ();
443
487
return 0 ;
444
488
}
445
489
else {
@@ -485,6 +529,10 @@ main(int argc, char *argv[])
485
529
init_args .mem_alloc_option .allocator .free_func = free_func ;
486
530
#endif
487
531
532
+ #if WASM_ENABLE_FAST_JIT != 0
533
+ init_args .fast_jit_code_cache_size = jit_code_cache_size ;
534
+ #endif
535
+
488
536
#if WASM_ENABLE_GC != 0
489
537
init_args .gc_heap_size = gc_heap_size ;
490
538
#endif
@@ -554,28 +602,27 @@ main(int argc, char *argv[])
554
602
libc_wasi_init (wasm_module , argc , argv , & wasi_parse_ctx );
555
603
#endif
556
604
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
+
557
614
/* 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 ) {
561
619
printf ("%s\n" , error_buf );
562
620
goto fail3 ;
563
621
}
564
622
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);
579
626
}
580
627
#endif
581
628
@@ -596,6 +643,25 @@ main(int argc, char *argv[])
596
643
}
597
644
#endif
598
645
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
+
599
665
ret = 0 ;
600
666
const char * exception = NULL ;
601
667
if (is_repl_mode ) {
@@ -627,8 +693,11 @@ main(int argc, char *argv[])
627
693
printf ("%s\n" , exception );
628
694
629
695
#if WASM_ENABLE_SHARED_HEAP != 0
630
- fail5 :
696
+ fail6 :
631
697
#endif
698
+
699
+ /* fail5: label is used by posix/main.c */
700
+
632
701
#if WASM_ENABLE_DEBUG_INTERP != 0
633
702
fail4 :
634
703
#endif
0 commit comments