@@ -57,6 +57,10 @@ print_help(void)
5757#else
5858 printf (" --heap-size=n Set maximum heap size in bytes, default is 16 KB when libc wasi is diabled\n" );
5959#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
6064#if WASM_ENABLE_FAST_JIT != 0
6165 printf (" --jit-codecache-size=n Set fast jit maximum code cache size in bytes,\n" );
6266 printf (" default is %u KB\n" , FAST_JIT_DEFAULT_CODE_CACHE_SIZE / 1024 );
@@ -578,6 +582,11 @@ main(int argc, char *argv[])
578582#else
579583 uint32 heap_size = 16 * 1024 ;
580584#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
581590#if WASM_ENABLE_FAST_JIT != 0
582591 uint32 jit_code_cache_size = FAST_JIT_DEFAULT_CODE_CACHE_SIZE ;
583592#endif
@@ -685,6 +694,13 @@ main(int argc, char *argv[])
685694 return print_help ();
686695 heap_size = atoi (argv [0 ] + 12 );
687696 }
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
688704#if WASM_ENABLE_FAST_JIT != 0
689705 else if (!strncmp (argv [0 ], "--jit-codecache-size=" , 21 )) {
690706 if (argv [0 ][21 ] == '\0' )
@@ -1007,6 +1023,24 @@ main(int argc, char *argv[])
10071023 }
10081024#endif
10091025
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+
10101044 ret = 0 ;
10111045 const char * exception = NULL ;
10121046 if (is_repl_mode ) {
@@ -1050,6 +1084,9 @@ main(int argc, char *argv[])
10501084 }
10511085#endif
10521086
1087+ #if WASM_ENABLE_SHARED_HEAP != 0
1088+ fail6 :
1089+ #endif
10531090#if WASM_ENABLE_THREAD_MGR != 0
10541091fail5 :
10551092#endif
0 commit comments