wasm_application.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "bh_platform.h"
  6. #if WASM_ENABLE_INTERP != 0
  7. #include "../interpreter/wasm_runtime.h"
  8. #endif
  9. #if WASM_ENABLE_AOT != 0
  10. #include "../aot/aot_runtime.h"
  11. #endif
  12. #if WASM_ENABLE_THREAD_MGR != 0
  13. #include "../libraries/thread-mgr/thread_manager.h"
  14. #endif
  15. static void
  16. set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
  17. {
  18. if (error_buf != NULL)
  19. snprintf(error_buf, error_buf_size, "%s", string);
  20. }
  21. static void *
  22. runtime_malloc(uint64 size, WASMModuleInstanceCommon *module_inst,
  23. char *error_buf, uint32 error_buf_size)
  24. {
  25. void *mem;
  26. if (size >= UINT32_MAX || !(mem = wasm_runtime_malloc((uint32)size))) {
  27. if (module_inst != NULL) {
  28. wasm_runtime_set_exception(module_inst, "allocate memory failed");
  29. }
  30. else if (error_buf != NULL) {
  31. set_error_buf(error_buf, error_buf_size, "allocate memory failed");
  32. }
  33. return NULL;
  34. }
  35. memset(mem, 0, (uint32)size);
  36. return mem;
  37. }
  38. static union {
  39. int a;
  40. char b;
  41. } __ue = { .a = 1 };
  42. #define is_little_endian() (__ue.b == 1) /* NOLINT */
  43. /**
  44. * Implementation of wasm_application_execute_main()
  45. */
  46. static bool
  47. check_main_func_type(const WASMType *type)
  48. {
  49. if (!(type->param_count == 0 || type->param_count == 2)
  50. || type->result_count > 1) {
  51. LOG_ERROR(
  52. "WASM execute application failed: invalid main function type.\n");
  53. return false;
  54. }
  55. if (type->param_count == 2
  56. && !(type->types[0] == VALUE_TYPE_I32
  57. && type->types[1] == VALUE_TYPE_I32)) {
  58. LOG_ERROR(
  59. "WASM execute application failed: invalid main function type.\n");
  60. return false;
  61. }
  62. if (type->result_count
  63. && type->types[type->param_count] != VALUE_TYPE_I32) {
  64. LOG_ERROR(
  65. "WASM execute application failed: invalid main function type.\n");
  66. return false;
  67. }
  68. return true;
  69. }
  70. static bool
  71. execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, char *argv[])
  72. {
  73. WASMFunctionInstanceCommon *func;
  74. WASMType *func_type = NULL;
  75. WASMExecEnv *exec_env = NULL;
  76. uint32 argc1 = 0, argv1[2] = { 0 };
  77. uint32 total_argv_size = 0;
  78. uint64 total_size;
  79. uint32 argv_buf_offset = 0;
  80. int32 i;
  81. char *argv_buf, *p, *p_end;
  82. uint32 *argv_offsets, module_type;
  83. bool ret, is_import_func = true;
  84. exec_env = wasm_runtime_get_exec_env_singleton(module_inst);
  85. if (!exec_env) {
  86. wasm_runtime_set_exception(module_inst,
  87. "create singleton exec_env failed");
  88. return false;
  89. }
  90. #if WASM_ENABLE_LIBC_WASI != 0
  91. /* In wasi mode, we should call the function named "_start"
  92. which initializes the wasi envrionment and then calls
  93. the actual main function. Directly calling main function
  94. may cause exception thrown. */
  95. if ((func = wasm_runtime_lookup_wasi_start_function(module_inst))) {
  96. const char *wasi_proc_exit_exception = "wasi proc exit";
  97. ret = wasm_runtime_call_wasm(exec_env, func, 0, NULL);
  98. #if WASM_ENABLE_THREAD_MGR != 0
  99. if (ret) {
  100. /* On a successful return from the `_start` function,
  101. we terminate other threads by mimicing wasi:proc_exit(0).
  102. Note:
  103. - A return from the `main` function is an equivalent of
  104. exit(). (C standard)
  105. - When exit code is 0, wasi-libc's `_start` function just
  106. returns w/o calling `proc_exit`.
  107. - A process termination should terminate threads in
  108. the process. */
  109. wasm_runtime_set_exception(module_inst, wasi_proc_exit_exception);
  110. /* exit_code is zero-initialized */
  111. ret = false;
  112. }
  113. #endif
  114. /* report wasm proc exit as a success */
  115. WASMModuleInstance *inst = (WASMModuleInstance *)module_inst;
  116. if (!ret && strstr(inst->cur_exception, wasi_proc_exit_exception)) {
  117. inst->cur_exception[0] = 0;
  118. ret = true;
  119. }
  120. return ret;
  121. }
  122. #endif /* end of WASM_ENABLE_LIBC_WASI */
  123. if (!(func = wasm_runtime_lookup_function(module_inst, "main", NULL))
  124. && !(func = wasm_runtime_lookup_function(module_inst,
  125. "__main_argc_argv", NULL))
  126. && !(func = wasm_runtime_lookup_function(module_inst, "_main", NULL))) {
  127. #if WASM_ENABLE_LIBC_WASI != 0
  128. wasm_runtime_set_exception(
  129. module_inst, "lookup the entry point symbol (like _start, main, "
  130. "_main, __main_argc_argv) failed");
  131. #else
  132. wasm_runtime_set_exception(module_inst,
  133. "lookup the entry point symbol (like main, "
  134. "_main, __main_argc_argv) failed");
  135. #endif
  136. return false;
  137. }
  138. #if WASM_ENABLE_INTERP != 0
  139. if (module_inst->module_type == Wasm_Module_Bytecode) {
  140. is_import_func = ((WASMFunctionInstance *)func)->is_import_func;
  141. }
  142. #endif
  143. #if WASM_ENABLE_AOT != 0
  144. if (module_inst->module_type == Wasm_Module_AoT) {
  145. is_import_func = ((AOTFunctionInstance *)func)->is_import_func;
  146. }
  147. #endif
  148. if (is_import_func) {
  149. wasm_runtime_set_exception(module_inst, "lookup main function failed");
  150. return false;
  151. }
  152. module_type = module_inst->module_type;
  153. func_type = wasm_runtime_get_function_type(func, module_type);
  154. if (!func_type) {
  155. LOG_ERROR("invalid module instance type");
  156. return false;
  157. }
  158. if (!check_main_func_type(func_type)) {
  159. wasm_runtime_set_exception(module_inst,
  160. "invalid function type of main function");
  161. return false;
  162. }
  163. if (func_type->param_count) {
  164. for (i = 0; i < argc; i++)
  165. total_argv_size += (uint32)(strlen(argv[i]) + 1);
  166. total_argv_size = align_uint(total_argv_size, 4);
  167. total_size = (uint64)total_argv_size + sizeof(int32) * (uint64)argc;
  168. if (total_size >= UINT32_MAX
  169. || !(argv_buf_offset = wasm_runtime_module_malloc(
  170. module_inst, (uint32)total_size, (void **)&argv_buf))) {
  171. wasm_runtime_set_exception(module_inst, "allocate memory failed");
  172. return false;
  173. }
  174. p = argv_buf;
  175. argv_offsets = (uint32 *)(p + total_argv_size);
  176. p_end = p + total_size;
  177. for (i = 0; i < argc; i++) {
  178. bh_memcpy_s(p, (uint32)(p_end - p), argv[i],
  179. (uint32)(strlen(argv[i]) + 1));
  180. argv_offsets[i] = argv_buf_offset + (uint32)(p - argv_buf);
  181. p += strlen(argv[i]) + 1;
  182. }
  183. argc1 = 2;
  184. argv1[0] = (uint32)argc;
  185. argv1[1] =
  186. (uint32)wasm_runtime_addr_native_to_app(module_inst, argv_offsets);
  187. }
  188. ret = wasm_runtime_call_wasm(exec_env, func, argc1, argv1);
  189. if (ret && func_type->result_count > 0 && argc > 0 && argv)
  190. /* copy the return value */
  191. *(int *)argv = (int)argv1[0];
  192. if (argv_buf_offset)
  193. wasm_runtime_module_free(module_inst, argv_buf_offset);
  194. return ret;
  195. }
  196. bool
  197. wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
  198. char *argv[])
  199. {
  200. bool ret;
  201. #if (WASM_ENABLE_MEMORY_PROFILING != 0)
  202. WASMExecEnv *exec_env;
  203. #endif
  204. ret = execute_main(module_inst, argc, argv);
  205. #if WASM_ENABLE_MEMORY_PROFILING != 0
  206. exec_env = wasm_runtime_get_exec_env_singleton(module_inst);
  207. if (exec_env) {
  208. wasm_runtime_dump_mem_consumption(exec_env);
  209. }
  210. #endif
  211. #if WASM_ENABLE_PERF_PROFILING != 0
  212. wasm_runtime_dump_perf_profiling(module_inst);
  213. #endif
  214. if (ret)
  215. ret = wasm_runtime_get_exception(module_inst) == NULL;
  216. return ret;
  217. }
  218. /**
  219. * Implementation of wasm_application_execute_func()
  220. */
  221. union ieee754_float {
  222. float f;
  223. /* This is the IEEE 754 single-precision format. */
  224. union {
  225. struct {
  226. unsigned int negative : 1;
  227. unsigned int exponent : 8;
  228. unsigned int mantissa : 23;
  229. } ieee_big_endian;
  230. struct {
  231. unsigned int mantissa : 23;
  232. unsigned int exponent : 8;
  233. unsigned int negative : 1;
  234. } ieee_little_endian;
  235. } ieee;
  236. };
  237. union ieee754_double {
  238. double d;
  239. /* This is the IEEE 754 double-precision format. */
  240. union {
  241. struct {
  242. unsigned int negative : 1;
  243. unsigned int exponent : 11;
  244. /* Together these comprise the mantissa. */
  245. unsigned int mantissa0 : 20;
  246. unsigned int mantissa1 : 32;
  247. } ieee_big_endian;
  248. struct {
  249. /* Together these comprise the mantissa. */
  250. unsigned int mantissa1 : 32;
  251. unsigned int mantissa0 : 20;
  252. unsigned int exponent : 11;
  253. unsigned int negative : 1;
  254. } ieee_little_endian;
  255. } ieee;
  256. };
  257. static bool
  258. execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
  259. int32 argc, char *argv[])
  260. {
  261. WASMFunctionInstanceCommon *target_func;
  262. WASMType *type = NULL;
  263. WASMExecEnv *exec_env = NULL;
  264. uint32 argc1, *argv1 = NULL, cell_num = 0, j, k = 0;
  265. #if WASM_ENABLE_REF_TYPES != 0
  266. uint32 param_size_in_double_world = 0, result_size_in_double_world = 0;
  267. #endif
  268. int32 i, p, module_type;
  269. uint64 total_size;
  270. char buf[128];
  271. bh_assert(argc >= 0);
  272. LOG_DEBUG("call a function \"%s\" with %d arguments", name, argc);
  273. if (!(target_func =
  274. wasm_runtime_lookup_function(module_inst, name, NULL))) {
  275. snprintf(buf, sizeof(buf), "lookup function %s failed", name);
  276. wasm_runtime_set_exception(module_inst, buf);
  277. goto fail;
  278. }
  279. module_type = module_inst->module_type;
  280. type = wasm_runtime_get_function_type(target_func, module_type);
  281. if (!type) {
  282. LOG_ERROR("invalid module instance type");
  283. return false;
  284. }
  285. if (type->param_count != (uint32)argc) {
  286. wasm_runtime_set_exception(module_inst, "invalid input argument count");
  287. goto fail;
  288. }
  289. #if WASM_ENABLE_REF_TYPES != 0
  290. for (i = 0; i < type->param_count; i++) {
  291. param_size_in_double_world +=
  292. wasm_value_type_cell_num_outside(type->types[i]);
  293. }
  294. for (i = 0; i < type->result_count; i++) {
  295. result_size_in_double_world += wasm_value_type_cell_num_outside(
  296. type->types[type->param_count + i]);
  297. }
  298. argc1 = param_size_in_double_world;
  299. cell_num = (param_size_in_double_world >= result_size_in_double_world)
  300. ? param_size_in_double_world
  301. : result_size_in_double_world;
  302. #else
  303. argc1 = type->param_cell_num;
  304. cell_num = (argc1 > type->ret_cell_num) ? argc1 : type->ret_cell_num;
  305. #endif
  306. total_size = sizeof(uint32) * (uint64)(cell_num > 2 ? cell_num : 2);
  307. if ((!(argv1 = runtime_malloc((uint32)total_size, module_inst, NULL, 0)))) {
  308. goto fail;
  309. }
  310. /* Parse arguments */
  311. for (i = 0, p = 0; i < argc; i++) {
  312. char *endptr = NULL;
  313. bh_assert(argv[i] != NULL);
  314. if (argv[i][0] == '\0') {
  315. snprintf(buf, sizeof(buf), "invalid input argument %" PRId32, i);
  316. wasm_runtime_set_exception(module_inst, buf);
  317. goto fail;
  318. }
  319. switch (type->types[i]) {
  320. case VALUE_TYPE_I32:
  321. argv1[p++] = (uint32)strtoul(argv[i], &endptr, 0);
  322. break;
  323. case VALUE_TYPE_I64:
  324. {
  325. union {
  326. uint64 val;
  327. uint32 parts[2];
  328. } u;
  329. u.val = strtoull(argv[i], &endptr, 0);
  330. argv1[p++] = u.parts[0];
  331. argv1[p++] = u.parts[1];
  332. break;
  333. }
  334. case VALUE_TYPE_F32:
  335. {
  336. float32 f32 = strtof(argv[i], &endptr);
  337. if (isnan(f32)) {
  338. #ifdef _MSC_VER
  339. /*
  340. * Spec tests require the binary representation of NaN to be
  341. * 0x7fc00000 for float and 0x7ff8000000000000 for float;
  342. * however, in MSVC compiler, strtof doesn't return this
  343. * exact value, causing some of the spec test failures. We
  344. * use the value returned by nan/nanf as it is the one
  345. * expected by spec tests.
  346. *
  347. */
  348. f32 = nanf("");
  349. #endif
  350. if (argv[i][0] == '-') {
  351. union ieee754_float u;
  352. u.f = f32;
  353. if (is_little_endian())
  354. u.ieee.ieee_little_endian.negative = 1;
  355. else
  356. u.ieee.ieee_big_endian.negative = 1;
  357. bh_memcpy_s(&f32, sizeof(float), &u.f, sizeof(float));
  358. }
  359. if (endptr[0] == ':') {
  360. uint32 sig;
  361. union ieee754_float u;
  362. sig = (uint32)strtoul(endptr + 1, &endptr, 0);
  363. u.f = f32;
  364. if (is_little_endian())
  365. u.ieee.ieee_little_endian.mantissa = sig;
  366. else
  367. u.ieee.ieee_big_endian.mantissa = sig;
  368. bh_memcpy_s(&f32, sizeof(float), &u.f, sizeof(float));
  369. }
  370. }
  371. bh_memcpy_s(&argv1[p], (uint32)total_size - p, &f32,
  372. (uint32)sizeof(float));
  373. p++;
  374. break;
  375. }
  376. case VALUE_TYPE_F64:
  377. {
  378. union {
  379. float64 val;
  380. uint32 parts[2];
  381. } u;
  382. u.val = strtod(argv[i], &endptr);
  383. if (isnan(u.val)) {
  384. #ifdef _MSC_VER
  385. u.val = nan("");
  386. #endif
  387. if (argv[i][0] == '-') {
  388. union ieee754_double ud;
  389. ud.d = u.val;
  390. if (is_little_endian())
  391. ud.ieee.ieee_little_endian.negative = 1;
  392. else
  393. ud.ieee.ieee_big_endian.negative = 1;
  394. bh_memcpy_s(&u.val, sizeof(double), &ud.d,
  395. sizeof(double));
  396. }
  397. if (endptr[0] == ':') {
  398. uint64 sig;
  399. union ieee754_double ud;
  400. sig = strtoull(endptr + 1, &endptr, 0);
  401. ud.d = u.val;
  402. if (is_little_endian()) {
  403. ud.ieee.ieee_little_endian.mantissa0 = sig >> 32;
  404. ud.ieee.ieee_little_endian.mantissa1 = (uint32)sig;
  405. }
  406. else {
  407. ud.ieee.ieee_big_endian.mantissa0 = sig >> 32;
  408. ud.ieee.ieee_big_endian.mantissa1 = (uint32)sig;
  409. }
  410. bh_memcpy_s(&u.val, sizeof(double), &ud.d,
  411. sizeof(double));
  412. }
  413. }
  414. argv1[p++] = u.parts[0];
  415. argv1[p++] = u.parts[1];
  416. break;
  417. }
  418. #if WASM_ENABLE_SIMD != 0
  419. case VALUE_TYPE_V128:
  420. {
  421. /* it likes 0x123\0x234 or 123\234 */
  422. /* retrive first i64 */
  423. *(uint64 *)(argv1 + p) = strtoull(argv[i], &endptr, 0);
  424. /* skip \ */
  425. endptr++;
  426. /* retrive second i64 */
  427. *(uint64 *)(argv1 + p + 2) = strtoull(endptr, &endptr, 0);
  428. p += 4;
  429. break;
  430. }
  431. #endif /* WASM_ENABLE_SIMD != 0 */
  432. #if WASM_ENABLE_REF_TYPES != 0
  433. case VALUE_TYPE_FUNCREF:
  434. {
  435. if (strncasecmp(argv[i], "null", 4) == 0) {
  436. argv1[p++] = (uint32)-1;
  437. }
  438. else {
  439. argv1[p++] = (uint32)strtoul(argv[i], &endptr, 0);
  440. }
  441. break;
  442. }
  443. case VALUE_TYPE_EXTERNREF:
  444. {
  445. #if UINTPTR_MAX == UINT32_MAX
  446. if (strncasecmp(argv[i], "null", 4) == 0) {
  447. argv1[p++] = (uint32)-1;
  448. }
  449. else {
  450. argv1[p++] = strtoul(argv[i], &endptr, 0);
  451. }
  452. #else
  453. union {
  454. uintptr_t val;
  455. uint32 parts[2];
  456. } u;
  457. if (strncasecmp(argv[i], "null", 4) == 0) {
  458. u.val = (uintptr_t)-1LL;
  459. }
  460. else {
  461. u.val = strtoull(argv[i], &endptr, 0);
  462. }
  463. argv1[p++] = u.parts[0];
  464. argv1[p++] = u.parts[1];
  465. #endif
  466. break;
  467. }
  468. #endif /* WASM_ENABLE_REF_TYPES */
  469. default:
  470. bh_assert(0);
  471. break;
  472. }
  473. if (endptr && *endptr != '\0' && *endptr != '_') {
  474. snprintf(buf, sizeof(buf), "invalid input argument %" PRId32 ": %s",
  475. i, argv[i]);
  476. wasm_runtime_set_exception(module_inst, buf);
  477. goto fail;
  478. }
  479. }
  480. wasm_runtime_set_exception(module_inst, NULL);
  481. #if WASM_ENABLE_REF_TYPES == 0
  482. bh_assert(p == (int32)argc1);
  483. #endif
  484. exec_env = wasm_runtime_get_exec_env_singleton(module_inst);
  485. if (!exec_env) {
  486. wasm_runtime_set_exception(module_inst,
  487. "create singleton exec_env failed");
  488. goto fail;
  489. }
  490. if (!wasm_runtime_call_wasm(exec_env, target_func, argc1, argv1)) {
  491. goto fail;
  492. }
  493. /* print return value */
  494. for (j = 0; j < type->result_count; j++) {
  495. switch (type->types[type->param_count + j]) {
  496. case VALUE_TYPE_I32:
  497. {
  498. os_printf("0x%" PRIx32 ":i32", argv1[k]);
  499. k++;
  500. break;
  501. }
  502. case VALUE_TYPE_I64:
  503. {
  504. union {
  505. uint64 val;
  506. uint32 parts[2];
  507. } u;
  508. u.parts[0] = argv1[k];
  509. u.parts[1] = argv1[k + 1];
  510. k += 2;
  511. os_printf("0x%" PRIx64 ":i64", u.val);
  512. break;
  513. }
  514. case VALUE_TYPE_F32:
  515. {
  516. os_printf("%.7g:f32", *(float32 *)(argv1 + k));
  517. k++;
  518. break;
  519. }
  520. case VALUE_TYPE_F64:
  521. {
  522. union {
  523. float64 val;
  524. uint32 parts[2];
  525. } u;
  526. u.parts[0] = argv1[k];
  527. u.parts[1] = argv1[k + 1];
  528. k += 2;
  529. os_printf("%.7g:f64", u.val);
  530. break;
  531. }
  532. #if WASM_ENABLE_REF_TYPES != 0
  533. case VALUE_TYPE_FUNCREF:
  534. {
  535. if (argv1[k] != NULL_REF)
  536. os_printf("%" PRIu32 ":ref.func", argv1[k]);
  537. else
  538. os_printf("func:ref.null");
  539. k++;
  540. break;
  541. }
  542. case VALUE_TYPE_EXTERNREF:
  543. {
  544. #if UINTPTR_MAX == UINT32_MAX
  545. if (argv1[k] != 0 && argv1[k] != (uint32)-1)
  546. os_printf("0x%" PRIxPTR ":ref.extern", (uintptr_t)argv1[k]);
  547. else
  548. os_printf("extern:ref.null");
  549. k++;
  550. #else
  551. union {
  552. uintptr_t val;
  553. uint32 parts[2];
  554. } u;
  555. u.parts[0] = argv1[k];
  556. u.parts[1] = argv1[k + 1];
  557. k += 2;
  558. if (u.val && u.val != (uintptr_t)-1LL)
  559. os_printf("0x%" PRIxPTR ":ref.extern", u.val);
  560. else
  561. os_printf("extern:ref.null");
  562. #endif
  563. break;
  564. }
  565. #endif
  566. #if WASM_ENABLE_SIMD != 0
  567. case VALUE_TYPE_V128:
  568. {
  569. uint64 *v = (uint64 *)(argv1 + k);
  570. os_printf("<0x%016" PRIx64 " 0x%016" PRIx64 ">:v128", *v,
  571. *(v + 1));
  572. k += 4;
  573. break;
  574. }
  575. #endif /* WASM_ENABLE_SIMD != 0 */
  576. default:
  577. bh_assert(0);
  578. break;
  579. }
  580. if (j < (uint32)(type->result_count - 1))
  581. os_printf(",");
  582. }
  583. os_printf("\n");
  584. wasm_runtime_free(argv1);
  585. return true;
  586. fail:
  587. if (argv1)
  588. wasm_runtime_free(argv1);
  589. bh_assert(wasm_runtime_get_exception(module_inst));
  590. return false;
  591. }
  592. bool
  593. wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
  594. const char *name, int32 argc, char *argv[])
  595. {
  596. bool ret;
  597. #if WASM_ENABLE_MEMORY_PROFILING != 0
  598. WASMExecEnv *exec_env;
  599. #endif
  600. ret = execute_func(module_inst, name, argc, argv);
  601. #if WASM_ENABLE_MEMORY_PROFILING != 0
  602. exec_env = wasm_runtime_get_exec_env_singleton(module_inst);
  603. if (exec_env) {
  604. wasm_runtime_dump_mem_consumption(exec_env);
  605. }
  606. #endif
  607. #if WASM_ENABLE_PERF_PROFILING != 0
  608. wasm_runtime_dump_perf_profiling(module_inst);
  609. #endif
  610. return (ret && !wasm_runtime_get_exception(module_inst)) ? true : false;
  611. }