@@ -57,6 +57,10 @@ print_help(void)
57
57
#else
58
58
printf (" --heap-size=n Set maximum heap size in bytes, default is 16 KB when libc wasi is diabled\n" );
59
59
#endif
60
+ #if WASM_ENABLE_SHARED_HEAP != 0
61
+ printf (" --shared-heap-size=n Create shared heap of n bytes and attach to the wasm app.\n" );
62
+ printf (" The size n will be adjusted to a minumum number aligned to page size\n" );
63
+ #endif
60
64
#if WASM_ENABLE_FAST_JIT != 0
61
65
printf (" --jit-codecache-size=n Set fast jit maximum code cache size in bytes,\n" );
62
66
printf (" default is %u KB\n" , FAST_JIT_DEFAULT_CODE_CACHE_SIZE / 1024 );
@@ -578,6 +582,11 @@ main(int argc, char *argv[])
578
582
#else
579
583
uint32 heap_size = 16 * 1024 ;
580
584
#endif
585
+ #if WASM_ENABLE_SHARED_HEAP != 0
586
+ SharedHeapInitArgs heap_init_args ;
587
+ uint32 shared_heap_size = 0 ;
588
+ void * shared_heap = NULL ;
589
+ #endif
581
590
#if WASM_ENABLE_FAST_JIT != 0
582
591
uint32 jit_code_cache_size = FAST_JIT_DEFAULT_CODE_CACHE_SIZE ;
583
592
#endif
@@ -685,6 +694,13 @@ main(int argc, char *argv[])
685
694
return print_help ();
686
695
heap_size = atoi (argv [0 ] + 12 );
687
696
}
697
+ #if WASM_ENABLE_SHARED_HEAP != 0
698
+ else if (!strncmp (argv [0 ], "--shared-heap-size=" , 19 )) {
699
+ if (argv [0 ][19 ] == '\0' )
700
+ return print_help ();
701
+ shared_heap_size = atoi (argv [0 ] + 19 );
702
+ }
703
+ #endif
688
704
#if WASM_ENABLE_FAST_JIT != 0
689
705
else if (!strncmp (argv [0 ], "--jit-codecache-size=" , 21 )) {
690
706
if (argv [0 ][21 ] == '\0' )
@@ -1007,6 +1023,24 @@ main(int argc, char *argv[])
1007
1023
}
1008
1024
#endif
1009
1025
1026
+ #if WASM_ENABLE_SHARED_HEAP != 0
1027
+ if (shared_heap_size > 0 ) {
1028
+ memset (& heap_init_args , 0 , sizeof (heap_init_args ));
1029
+ heap_init_args .size = shared_heap_size ;
1030
+ shared_heap = wasm_runtime_create_shared_heap (& heap_init_args );
1031
+ if (!shared_heap ) {
1032
+ printf ("Create preallocated shared heap failed\n" );
1033
+ goto fail6 ;
1034
+ }
1035
+
1036
+ /* attach module instance 2 to the shared heap */
1037
+ if (!wasm_runtime_attach_shared_heap (wasm_module_inst , shared_heap )) {
1038
+ printf ("Attach shared heap failed.\n" );
1039
+ goto fail6 ;
1040
+ }
1041
+ }
1042
+ #endif
1043
+
1010
1044
ret = 0 ;
1011
1045
const char * exception = NULL ;
1012
1046
if (is_repl_mode ) {
@@ -1050,6 +1084,9 @@ main(int argc, char *argv[])
1050
1084
}
1051
1085
#endif
1052
1086
1087
+ #if WASM_ENABLE_SHARED_HEAP != 0
1088
+ fail6 :
1089
+ #endif
1053
1090
#if WASM_ENABLE_THREAD_MGR != 0
1054
1091
fail5 :
1055
1092
#endif
0 commit comments