@@ -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,23 @@ 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
+ 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
+ }
579
+ }
580
+ #endif
581
+
554
582
#if WASM_ENABLE_DEBUG_INTERP != 0
555
583
if (ip_addr != NULL ) {
556
584
wasm_exec_env_t exec_env =
@@ -598,6 +626,9 @@ main(int argc, char *argv[])
598
626
if (exception )
599
627
printf ("%s\n" , exception );
600
628
629
+ #if WASM_ENABLE_SHARED_HEAP != 0
630
+ fail5 :
631
+ #endif
601
632
#if WASM_ENABLE_DEBUG_INTERP != 0
602
633
fail4 :
603
634
#endif
0 commit comments