@@ -53,6 +53,10 @@ print_help()
53
53
printf (" --gc-heap-size=n Set maximum gc heap size in bytes,\n" );
54
54
printf (" default is %u KB\n" , GC_HEAP_SIZE_DEFAULT / 1024 );
55
55
#endif
56
+ #if WASM_ENABLE_SHARED_HEAP != 0
57
+ printf (" --shared-heap-size=n Create shared heap of n bytes and attach to the wasm app.\n" );
58
+ printf (" The size n will be adjusted to a minumum number aligned to page size\n" );
59
+ #endif
56
60
#if WASM_ENABLE_JIT != 0
57
61
printf (" --llvm-jit-size-level=n Set LLVM JIT size level, default is 3\n" );
58
62
printf (" --llvm-jit-opt-level=n Set LLVM JIT optimization level, default is 3\n" );
@@ -364,6 +368,13 @@ main(int argc, char *argv[])
364
368
gc_heap_size = atoi (argv [0 ] + 15 );
365
369
}
366
370
#endif
371
+ #if WASM_ENABLE_SHARED_HEAP != 0
372
+ else if (!strncmp (argv [0 ], "--shared-heap-size=" , 19 )) {
373
+ if (argv [0 ][19 ] == '\0' )
374
+ return print_help ();
375
+ shared_heap_size = atoi (argv [0 ] + 19 );
376
+ }
377
+ #endif
367
378
#if WASM_ENABLE_JIT != 0
368
379
else if (!strncmp (argv [0 ], "--llvm-jit-size-level=" , 22 )) {
369
380
if (argv [0 ][22 ] == '\0' )
@@ -551,6 +562,24 @@ main(int argc, char *argv[])
551
562
goto fail3 ;
552
563
}
553
564
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
+
570
+ shared_heap = wasm_runtime_create_shared_heap (& shared_heap_init_args );
571
+ if (!shared_heap ) {
572
+ printf ("Create shared heap failed.\n" );
573
+ goto fail5 ;
574
+ }
575
+
576
+ if (!wasm_runtime_attach_shared_heap (wasm_module_inst , shared_heap )) {
577
+ printf ("Attach shared heap failed.\n" );
578
+ goto fail5 ;
579
+ }
580
+ }
581
+ #endif
582
+
554
583
#if WASM_ENABLE_DEBUG_INTERP != 0
555
584
if (ip_addr != NULL ) {
556
585
wasm_exec_env_t exec_env =
@@ -598,6 +627,9 @@ main(int argc, char *argv[])
598
627
if (exception )
599
628
printf ("%s\n" , exception );
600
629
630
+ #if WASM_ENABLE_SHARED_HEAP != 0
631
+ fail5 :
632
+ #endif
601
633
#if WASM_ENABLE_DEBUG_INTERP != 0
602
634
fail4 :
603
635
#endif
0 commit comments