wasm_native.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "wasm_native.h"
  6. #include "wasm_runtime_common.h"
  7. #include "bh_log.h"
  8. #if WASM_ENABLE_INTERP != 0
  9. #include "../interpreter/wasm_runtime.h"
  10. #endif
  11. #if WASM_ENABLE_AOT != 0
  12. #include "../aot/aot_runtime.h"
  13. #endif
  14. #if WASM_ENABLE_THREAD_MGR != 0
  15. #include "../libraries/thread-mgr/thread_manager.h"
  16. #endif
  17. static NativeSymbolsList g_native_symbols_list = NULL;
  18. #if WASM_ENABLE_LIBC_WASI != 0
  19. static void *g_wasi_context_key;
  20. #endif /* WASM_ENABLE_LIBC_WASI */
  21. uint32
  22. get_libc_builtin_export_apis(NativeSymbol **p_libc_builtin_apis);
  23. #if WASM_ENABLE_SPEC_TEST != 0
  24. uint32
  25. get_spectest_export_apis(NativeSymbol **p_libc_builtin_apis);
  26. #endif
  27. uint32
  28. get_libc_wasi_export_apis(NativeSymbol **p_libc_wasi_apis);
  29. uint32_t
  30. get_wasi_nn_export_apis(NativeSymbol **p_libc_wasi_apis);
  31. uint32
  32. get_base_lib_export_apis(NativeSymbol **p_base_lib_apis);
  33. uint32
  34. get_ext_lib_export_apis(NativeSymbol **p_ext_lib_apis);
  35. #if WASM_ENABLE_LIB_PTHREAD != 0
  36. bool
  37. lib_pthread_init();
  38. void
  39. lib_pthread_destroy();
  40. uint32
  41. get_lib_pthread_export_apis(NativeSymbol **p_lib_pthread_apis);
  42. #endif
  43. #if WASM_ENABLE_LIB_WASI_THREADS != 0
  44. bool
  45. lib_wasi_threads_init(void);
  46. void
  47. lib_wasi_threads_destroy(void);
  48. uint32
  49. get_lib_wasi_threads_export_apis(NativeSymbol **p_lib_wasi_threads_apis);
  50. #endif
  51. uint32
  52. get_libc_emcc_export_apis(NativeSymbol **p_libc_emcc_apis);
  53. uint32
  54. get_lib_rats_export_apis(NativeSymbol **p_lib_rats_apis);
  55. static bool
  56. compare_type_with_signautre(uint8 type, const char signature)
  57. {
  58. const char num_sig_map[] = { 'F', 'f', 'I', 'i' };
  59. if (VALUE_TYPE_F64 <= type && type <= VALUE_TYPE_I32
  60. && signature == num_sig_map[type - VALUE_TYPE_F64]) {
  61. return true;
  62. }
  63. #if WASM_ENABLE_REF_TYPES != 0
  64. if ('r' == signature && type == VALUE_TYPE_EXTERNREF)
  65. return true;
  66. #endif
  67. /* TODO: a v128 parameter */
  68. return false;
  69. }
  70. static bool
  71. check_symbol_signature(const WASMType *type, const char *signature)
  72. {
  73. const char *p = signature, *p_end;
  74. char sig;
  75. uint32 i = 0;
  76. if (!p || strlen(p) < 2)
  77. return false;
  78. p_end = p + strlen(signature);
  79. if (*p++ != '(')
  80. return false;
  81. if ((uint32)(p_end - p) < (uint32)(type->param_count + 1))
  82. /* signatures of parameters, and ')' */
  83. return false;
  84. for (i = 0; i < type->param_count; i++) {
  85. sig = *p++;
  86. /* a f64/f32/i64/i32/externref parameter */
  87. if (compare_type_with_signautre(type->types[i], sig))
  88. continue;
  89. /* a pointer/string paramter */
  90. if (type->types[i] != VALUE_TYPE_I32)
  91. /* pointer and string must be i32 type */
  92. return false;
  93. if (sig == '*') {
  94. /* it is a pointer */
  95. if (i + 1 < type->param_count
  96. && type->types[i + 1] == VALUE_TYPE_I32 && *p == '~') {
  97. /* pointer length followed */
  98. i++;
  99. p++;
  100. }
  101. }
  102. else if (sig == '$') {
  103. /* it is a string */
  104. }
  105. else {
  106. /* invalid signature */
  107. return false;
  108. }
  109. }
  110. if (*p++ != ')')
  111. return false;
  112. if (type->result_count) {
  113. if (p >= p_end)
  114. return false;
  115. /* result types includes: f64,f32,i64,i32,externref */
  116. if (!compare_type_with_signautre(type->types[i], *p))
  117. return false;
  118. p++;
  119. }
  120. if (*p != '\0')
  121. return false;
  122. return true;
  123. }
  124. static int
  125. native_symbol_cmp(const void *native_symbol1, const void *native_symbol2)
  126. {
  127. return strcmp(((const NativeSymbol *)native_symbol1)->symbol,
  128. ((const NativeSymbol *)native_symbol2)->symbol);
  129. }
  130. static void *
  131. lookup_symbol(NativeSymbol *native_symbols, uint32 n_native_symbols,
  132. const char *symbol, const char **p_signature, void **p_attachment)
  133. {
  134. NativeSymbol *native_symbol, key = { 0 };
  135. key.symbol = symbol;
  136. if ((native_symbol = bsearch(&key, native_symbols, n_native_symbols,
  137. sizeof(NativeSymbol), native_symbol_cmp))) {
  138. *p_signature = native_symbol->signature;
  139. *p_attachment = native_symbol->attachment;
  140. return native_symbol->func_ptr;
  141. }
  142. return NULL;
  143. }
  144. /**
  145. * allow func_type and all outputs, like p_signature, p_attachment and
  146. * p_call_conv_raw to be NULL
  147. */
  148. void *
  149. wasm_native_resolve_symbol(const char *module_name, const char *field_name,
  150. const WASMType *func_type, const char **p_signature,
  151. void **p_attachment, bool *p_call_conv_raw)
  152. {
  153. NativeSymbolsNode *node, *node_next;
  154. const char *signature = NULL;
  155. void *func_ptr = NULL, *attachment = NULL;
  156. node = g_native_symbols_list;
  157. while (node) {
  158. node_next = node->next;
  159. if (!strcmp(node->module_name, module_name)) {
  160. if ((func_ptr =
  161. lookup_symbol(node->native_symbols, node->n_native_symbols,
  162. field_name, &signature, &attachment))
  163. || (field_name[0] == '_'
  164. && (func_ptr = lookup_symbol(
  165. node->native_symbols, node->n_native_symbols,
  166. field_name + 1, &signature, &attachment))))
  167. break;
  168. }
  169. node = node_next;
  170. }
  171. if (!p_signature || !p_attachment || !p_call_conv_raw)
  172. return func_ptr;
  173. if (func_ptr) {
  174. if (signature && signature[0] != '\0') {
  175. /* signature is not empty, check its format */
  176. if (!func_type || !check_symbol_signature(func_type, signature)) {
  177. #if WASM_ENABLE_WAMR_COMPILER == 0
  178. /* Output warning except running aot compiler */
  179. LOG_WARNING("failed to check signature '%s' and resolve "
  180. "pointer params for import function (%s %s)\n",
  181. signature, module_name, field_name);
  182. #endif
  183. return NULL;
  184. }
  185. else
  186. /* Save signature for runtime to do pointer check and
  187. address conversion */
  188. *p_signature = signature;
  189. }
  190. else
  191. /* signature is empty */
  192. *p_signature = NULL;
  193. *p_attachment = attachment;
  194. *p_call_conv_raw = node->call_conv_raw;
  195. }
  196. return func_ptr;
  197. }
  198. static bool
  199. register_natives(const char *module_name, NativeSymbol *native_symbols,
  200. uint32 n_native_symbols, bool call_conv_raw)
  201. {
  202. NativeSymbolsNode *node;
  203. if (!(node = wasm_runtime_malloc(sizeof(NativeSymbolsNode))))
  204. return false;
  205. #if WASM_ENABLE_MEMORY_TRACING != 0
  206. os_printf("Register native, size: %u\n", sizeof(NativeSymbolsNode));
  207. #endif
  208. node->module_name = module_name;
  209. node->native_symbols = native_symbols;
  210. node->n_native_symbols = n_native_symbols;
  211. node->call_conv_raw = call_conv_raw;
  212. /* Add to list head */
  213. node->next = g_native_symbols_list;
  214. g_native_symbols_list = node;
  215. qsort(native_symbols, n_native_symbols, sizeof(NativeSymbol),
  216. native_symbol_cmp);
  217. return true;
  218. }
  219. bool
  220. wasm_native_register_natives(const char *module_name,
  221. NativeSymbol *native_symbols,
  222. uint32 n_native_symbols)
  223. {
  224. return register_natives(module_name, native_symbols, n_native_symbols,
  225. false);
  226. }
  227. bool
  228. wasm_native_register_natives_raw(const char *module_name,
  229. NativeSymbol *native_symbols,
  230. uint32 n_native_symbols)
  231. {
  232. return register_natives(module_name, native_symbols, n_native_symbols,
  233. true);
  234. }
  235. bool
  236. wasm_native_unregister_natives(const char *module_name,
  237. NativeSymbol *native_symbols)
  238. {
  239. NativeSymbolsNode **prevp;
  240. NativeSymbolsNode *node;
  241. prevp = &g_native_symbols_list;
  242. while ((node = *prevp) != NULL) {
  243. if (node->native_symbols == native_symbols
  244. && !strcmp(node->module_name, module_name)) {
  245. *prevp = node->next;
  246. wasm_runtime_free(node);
  247. return true;
  248. }
  249. prevp = &node->next;
  250. }
  251. return false;
  252. }
  253. #if WASM_ENABLE_MODULE_INST_CONTEXT != 0
  254. static uint32
  255. context_key_to_idx(void *key)
  256. {
  257. bh_assert(key != NULL);
  258. uint32 idx = (uint32)(uintptr_t)key;
  259. bh_assert(idx > 0);
  260. bh_assert(idx <= WASM_MAX_INSTANCE_CONTEXTS);
  261. return idx - 1;
  262. }
  263. static void *
  264. context_idx_to_key(uint32 idx)
  265. {
  266. bh_assert(idx < WASM_MAX_INSTANCE_CONTEXTS);
  267. return (void *)(uintptr_t)(idx + 1);
  268. }
  269. typedef void (*dtor_t)(WASMModuleInstanceCommon *, void *);
  270. static dtor_t g_context_dtors[WASM_MAX_INSTANCE_CONTEXTS];
  271. static void
  272. dtor_noop(WASMModuleInstanceCommon *inst, void *ctx)
  273. {}
  274. void *
  275. wasm_native_create_context_key(void (*dtor)(WASMModuleInstanceCommon *inst,
  276. void *ctx))
  277. {
  278. uint32 i;
  279. for (i = 0; i < WASM_MAX_INSTANCE_CONTEXTS; i++) {
  280. if (g_context_dtors[i] == NULL) {
  281. if (dtor == NULL) {
  282. dtor = dtor_noop;
  283. }
  284. g_context_dtors[i] = dtor;
  285. return context_idx_to_key(i);
  286. }
  287. }
  288. LOG_ERROR("failed to allocate instance context key");
  289. return NULL;
  290. }
  291. void
  292. wasm_native_destroy_context_key(void *key)
  293. {
  294. uint32 idx = context_key_to_idx(key);
  295. bh_assert(g_context_dtors[idx] != NULL);
  296. g_context_dtors[idx] = NULL;
  297. }
  298. static WASMModuleInstanceExtraCommon *
  299. wasm_module_inst_extra_common(WASMModuleInstanceCommon *inst)
  300. {
  301. #if WASM_ENABLE_INTERP != 0
  302. if (inst->module_type == Wasm_Module_Bytecode) {
  303. return &((WASMModuleInstance *)inst)->e->common;
  304. }
  305. #endif
  306. #if WASM_ENABLE_AOT != 0
  307. if (inst->module_type == Wasm_Module_AoT) {
  308. return &((AOTModuleInstanceExtra *)((AOTModuleInstance *)inst)->e)
  309. ->common;
  310. }
  311. #endif
  312. bh_assert(false);
  313. return NULL;
  314. }
  315. void
  316. wasm_native_set_context(WASMModuleInstanceCommon *inst, void *key, void *ctx)
  317. {
  318. uint32 idx = context_key_to_idx(key);
  319. WASMModuleInstanceExtraCommon *common = wasm_module_inst_extra_common(inst);
  320. common->contexts[idx] = ctx;
  321. }
  322. void
  323. wasm_native_set_context_spread(WASMModuleInstanceCommon *inst, void *key,
  324. void *ctx)
  325. {
  326. #if WASM_ENABLE_THREAD_MGR != 0
  327. wasm_cluster_set_context(inst, key, ctx);
  328. #else
  329. wasm_native_set_context(inst, key, ctx);
  330. #endif
  331. }
  332. void *
  333. wasm_native_get_context(WASMModuleInstanceCommon *inst, void *key)
  334. {
  335. uint32 idx = context_key_to_idx(key);
  336. WASMModuleInstanceExtraCommon *common = wasm_module_inst_extra_common(inst);
  337. return common->contexts[idx];
  338. }
  339. void
  340. wasm_native_call_context_dtors(WASMModuleInstanceCommon *inst)
  341. {
  342. WASMModuleInstanceExtraCommon *common = wasm_module_inst_extra_common(inst);
  343. uint32 i;
  344. for (i = 0; i < WASM_MAX_INSTANCE_CONTEXTS; i++) {
  345. dtor_t dtor = g_context_dtors[i];
  346. if (dtor != NULL) {
  347. dtor(inst, common->contexts[i]);
  348. }
  349. }
  350. }
  351. void
  352. wasm_native_inherit_contexts(WASMModuleInstanceCommon *child,
  353. WASMModuleInstanceCommon *parent)
  354. {
  355. WASMModuleInstanceExtraCommon *parent_common =
  356. wasm_module_inst_extra_common(parent);
  357. WASMModuleInstanceExtraCommon *child_common =
  358. wasm_module_inst_extra_common(child);
  359. bh_memcpy_s(child_common->contexts,
  360. sizeof(*child_common->contexts) * WASM_MAX_INSTANCE_CONTEXTS,
  361. parent_common->contexts,
  362. sizeof(*parent_common->contexts) * WASM_MAX_INSTANCE_CONTEXTS);
  363. }
  364. #endif /* WASM_ENABLE_MODULE_INST_CONTEXT != 0 */
  365. #if WASM_ENABLE_LIBC_WASI != 0
  366. WASIContext *
  367. wasm_runtime_get_wasi_ctx(WASMModuleInstanceCommon *module_inst_comm)
  368. {
  369. return wasm_native_get_context(module_inst_comm, g_wasi_context_key);
  370. }
  371. void
  372. wasm_runtime_set_wasi_ctx(WASMModuleInstanceCommon *module_inst_comm,
  373. WASIContext *wasi_ctx)
  374. {
  375. wasm_native_set_context(module_inst_comm, g_wasi_context_key, wasi_ctx);
  376. }
  377. static void
  378. wasi_context_dtor(WASMModuleInstanceCommon *inst, void *ctx)
  379. {
  380. if (ctx == NULL) {
  381. return;
  382. }
  383. wasm_runtime_destroy_wasi(inst);
  384. }
  385. #endif /* end of WASM_ENABLE_LIBC_WASI */
  386. #if WASM_ENABLE_QUICK_AOT_ENTRY != 0
  387. static bool
  388. quick_aot_entry_init();
  389. #endif
  390. bool
  391. wasm_native_init()
  392. {
  393. #if WASM_ENABLE_SPEC_TEST != 0 || WASM_ENABLE_LIBC_BUILTIN != 0 \
  394. || WASM_ENABLE_BASE_LIB != 0 || WASM_ENABLE_LIBC_EMCC != 0 \
  395. || WASM_ENABLE_LIB_RATS != 0 || WASM_ENABLE_WASI_NN != 0 \
  396. || WASM_ENABLE_APP_FRAMEWORK != 0 || WASM_ENABLE_LIBC_WASI != 0 \
  397. || WASM_ENABLE_LIB_PTHREAD != 0 || WASM_ENABLE_LIB_WASI_THREADS != 0
  398. NativeSymbol *native_symbols;
  399. uint32 n_native_symbols;
  400. #endif
  401. #if WASM_ENABLE_LIBC_BUILTIN != 0
  402. n_native_symbols = get_libc_builtin_export_apis(&native_symbols);
  403. if (!wasm_native_register_natives("env", native_symbols, n_native_symbols))
  404. goto fail;
  405. #endif /* WASM_ENABLE_LIBC_BUILTIN */
  406. #if WASM_ENABLE_SPEC_TEST
  407. n_native_symbols = get_spectest_export_apis(&native_symbols);
  408. if (!wasm_native_register_natives("spectest", native_symbols,
  409. n_native_symbols))
  410. goto fail;
  411. #endif /* WASM_ENABLE_SPEC_TEST */
  412. #if WASM_ENABLE_LIBC_WASI != 0
  413. g_wasi_context_key = wasm_native_create_context_key(wasi_context_dtor);
  414. if (g_wasi_context_key == NULL) {
  415. goto fail;
  416. }
  417. n_native_symbols = get_libc_wasi_export_apis(&native_symbols);
  418. if (!wasm_native_register_natives("wasi_unstable", native_symbols,
  419. n_native_symbols))
  420. goto fail;
  421. if (!wasm_native_register_natives("wasi_snapshot_preview1", native_symbols,
  422. n_native_symbols))
  423. goto fail;
  424. #endif
  425. #if WASM_ENABLE_BASE_LIB != 0
  426. n_native_symbols = get_base_lib_export_apis(&native_symbols);
  427. if (n_native_symbols > 0
  428. && !wasm_native_register_natives("env", native_symbols,
  429. n_native_symbols))
  430. goto fail;
  431. #endif
  432. #if WASM_ENABLE_APP_FRAMEWORK != 0
  433. n_native_symbols = get_ext_lib_export_apis(&native_symbols);
  434. if (n_native_symbols > 0
  435. && !wasm_native_register_natives("env", native_symbols,
  436. n_native_symbols))
  437. goto fail;
  438. #endif
  439. #if WASM_ENABLE_LIB_PTHREAD != 0
  440. if (!lib_pthread_init())
  441. goto fail;
  442. n_native_symbols = get_lib_pthread_export_apis(&native_symbols);
  443. if (n_native_symbols > 0
  444. && !wasm_native_register_natives("env", native_symbols,
  445. n_native_symbols))
  446. goto fail;
  447. #endif
  448. #if WASM_ENABLE_LIB_WASI_THREADS != 0
  449. if (!lib_wasi_threads_init())
  450. goto fail;
  451. n_native_symbols = get_lib_wasi_threads_export_apis(&native_symbols);
  452. if (n_native_symbols > 0
  453. && !wasm_native_register_natives("wasi", native_symbols,
  454. n_native_symbols))
  455. goto fail;
  456. #endif
  457. #if WASM_ENABLE_LIBC_EMCC != 0
  458. n_native_symbols = get_libc_emcc_export_apis(&native_symbols);
  459. if (n_native_symbols > 0
  460. && !wasm_native_register_natives("env", native_symbols,
  461. n_native_symbols))
  462. goto fail;
  463. #endif /* WASM_ENABLE_LIBC_EMCC */
  464. #if WASM_ENABLE_LIB_RATS != 0
  465. n_native_symbols = get_lib_rats_export_apis(&native_symbols);
  466. if (n_native_symbols > 0
  467. && !wasm_native_register_natives("env", native_symbols,
  468. n_native_symbols))
  469. goto fail;
  470. #endif /* WASM_ENABLE_LIB_RATS */
  471. #if WASM_ENABLE_WASI_NN != 0
  472. n_native_symbols = get_wasi_nn_export_apis(&native_symbols);
  473. if (!wasm_native_register_natives("wasi_nn", native_symbols,
  474. n_native_symbols))
  475. goto fail;
  476. #endif
  477. #if WASM_ENABLE_QUICK_AOT_ENTRY != 0
  478. if (!quick_aot_entry_init()) {
  479. #if WASM_ENABLE_SPEC_TEST != 0 || WASM_ENABLE_LIBC_BUILTIN != 0 \
  480. || WASM_ENABLE_BASE_LIB != 0 || WASM_ENABLE_LIBC_EMCC != 0 \
  481. || WASM_ENABLE_LIB_RATS != 0 || WASM_ENABLE_WASI_NN != 0 \
  482. || WASM_ENABLE_APP_FRAMEWORK != 0 || WASM_ENABLE_LIBC_WASI != 0 \
  483. || WASM_ENABLE_LIB_PTHREAD != 0 || WASM_ENABLE_LIB_WASI_THREADS != 0
  484. goto fail;
  485. #else
  486. return false;
  487. #endif
  488. }
  489. #endif
  490. return true;
  491. #if WASM_ENABLE_SPEC_TEST != 0 || WASM_ENABLE_LIBC_BUILTIN != 0 \
  492. || WASM_ENABLE_BASE_LIB != 0 || WASM_ENABLE_LIBC_EMCC != 0 \
  493. || WASM_ENABLE_LIB_RATS != 0 || WASM_ENABLE_WASI_NN != 0 \
  494. || WASM_ENABLE_APP_FRAMEWORK != 0 || WASM_ENABLE_LIBC_WASI != 0 \
  495. || WASM_ENABLE_LIB_PTHREAD != 0 || WASM_ENABLE_LIB_WASI_THREADS != 0
  496. fail:
  497. wasm_native_destroy();
  498. return false;
  499. #endif
  500. }
  501. void
  502. wasm_native_destroy()
  503. {
  504. NativeSymbolsNode *node, *node_next;
  505. #if WASM_ENABLE_LIBC_WASI != 0
  506. if (g_wasi_context_key != NULL) {
  507. wasm_native_destroy_context_key(g_wasi_context_key);
  508. g_wasi_context_key = NULL;
  509. }
  510. #endif
  511. #if WASM_ENABLE_LIB_PTHREAD != 0
  512. lib_pthread_destroy();
  513. #endif
  514. #if WASM_ENABLE_LIB_WASI_THREADS != 0
  515. lib_wasi_threads_destroy();
  516. #endif
  517. node = g_native_symbols_list;
  518. while (node) {
  519. node_next = node->next;
  520. wasm_runtime_free(node);
  521. node = node_next;
  522. }
  523. g_native_symbols_list = NULL;
  524. }
  525. #if WASM_ENABLE_QUICK_AOT_ENTRY != 0
  526. static void
  527. invoke_no_args_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  528. {
  529. void (*native_code)(WASMExecEnv *) = func_ptr;
  530. native_code(exec_env);
  531. }
  532. static void
  533. invoke_no_args_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  534. {
  535. int32 (*native_code)(WASMExecEnv *) = func_ptr;
  536. argv_ret[0] = native_code(exec_env);
  537. }
  538. static void
  539. invoke_no_args_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  540. {
  541. int64 (*native_code)(WASMExecEnv *) = func_ptr;
  542. int64 ret = native_code(exec_env);
  543. PUT_I64_TO_ADDR(argv_ret, ret);
  544. }
  545. static void
  546. invoke_i_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  547. {
  548. void (*native_code)(WASMExecEnv *, int32) = func_ptr;
  549. native_code(exec_env, argv[0]);
  550. }
  551. static void
  552. invoke_i_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  553. {
  554. int32 (*native_code)(WASMExecEnv *, int32) = func_ptr;
  555. argv_ret[0] = native_code(exec_env, argv[0]);
  556. }
  557. static void
  558. invoke_i_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  559. {
  560. int64 (*native_code)(WASMExecEnv *, int32) = func_ptr;
  561. int64 ret = native_code(exec_env, argv[0]);
  562. PUT_I64_TO_ADDR(argv_ret, ret);
  563. }
  564. static void
  565. invoke_I_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  566. {
  567. void (*native_code)(WASMExecEnv *, int64) = func_ptr;
  568. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv));
  569. }
  570. static void
  571. invoke_I_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  572. {
  573. int32 (*native_code)(WASMExecEnv *, int64) = func_ptr;
  574. argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv));
  575. }
  576. static void
  577. invoke_I_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  578. {
  579. int64 (*native_code)(WASMExecEnv *, int64) = func_ptr;
  580. int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv));
  581. PUT_I64_TO_ADDR(argv_ret, ret);
  582. }
  583. static void
  584. invoke_ii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  585. {
  586. void (*native_code)(WASMExecEnv *, int32, int32) = func_ptr;
  587. native_code(exec_env, argv[0], argv[1]);
  588. }
  589. static void
  590. invoke_ii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  591. {
  592. int32 (*native_code)(WASMExecEnv *, int32, int32) = func_ptr;
  593. argv_ret[0] = native_code(exec_env, argv[0], argv[1]);
  594. }
  595. static void
  596. invoke_ii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  597. {
  598. int64 (*native_code)(WASMExecEnv *, int32, int32) = func_ptr;
  599. int64 ret = native_code(exec_env, argv[0], argv[1]);
  600. PUT_I64_TO_ADDR(argv_ret, ret);
  601. }
  602. static void
  603. invoke_iI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  604. {
  605. void (*native_code)(WASMExecEnv *, int32, int64) = func_ptr;
  606. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1));
  607. }
  608. static void
  609. invoke_iI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  610. {
  611. int32 (*native_code)(WASMExecEnv *, int32, int64) = func_ptr;
  612. argv_ret[0] =
  613. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1));
  614. }
  615. static void
  616. invoke_iI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  617. {
  618. int64 (*native_code)(WASMExecEnv *, int32, int64) = func_ptr;
  619. int64 ret =
  620. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1));
  621. PUT_I64_TO_ADDR(argv_ret, ret);
  622. }
  623. static void
  624. invoke_Ii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  625. {
  626. void (*native_code)(WASMExecEnv *, int64, int32) = func_ptr;
  627. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2]);
  628. }
  629. static void
  630. invoke_Ii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  631. {
  632. int32 (*native_code)(WASMExecEnv *, int64, int32) = func_ptr;
  633. argv_ret[0] =
  634. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2]);
  635. }
  636. static void
  637. invoke_Ii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  638. {
  639. int64 (*native_code)(WASMExecEnv *, int64, int32) = func_ptr;
  640. int64 ret =
  641. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2]);
  642. PUT_I64_TO_ADDR(argv_ret, ret);
  643. }
  644. static void
  645. invoke_II_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  646. {
  647. void (*native_code)(WASMExecEnv *, int64, int64) = func_ptr;
  648. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  649. GET_I64_FROM_ADDR((uint32 *)argv + 2));
  650. }
  651. static void
  652. invoke_II_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  653. {
  654. int32 (*native_code)(WASMExecEnv *, int64, int64) = func_ptr;
  655. argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  656. GET_I64_FROM_ADDR((uint32 *)argv + 2));
  657. }
  658. static void
  659. invoke_II_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  660. {
  661. int64 (*native_code)(WASMExecEnv *, int64, int64) = func_ptr;
  662. int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  663. GET_I64_FROM_ADDR((uint32 *)argv + 2));
  664. PUT_I64_TO_ADDR(argv_ret, ret);
  665. }
  666. static void
  667. invoke_iii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  668. {
  669. void (*native_code)(WASMExecEnv *, int32, int32, int32) = func_ptr;
  670. native_code(exec_env, argv[0], argv[1], argv[2]);
  671. }
  672. static void
  673. invoke_iii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  674. {
  675. int32 (*native_code)(WASMExecEnv *, int32, int32, int32) = func_ptr;
  676. argv_ret[0] = native_code(exec_env, argv[0], argv[1], argv[2]);
  677. }
  678. static void
  679. invoke_iii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  680. {
  681. int64 (*native_code)(WASMExecEnv *, int32, int32, int32) = func_ptr;
  682. int64 ret = native_code(exec_env, argv[0], argv[1], argv[2]);
  683. PUT_I64_TO_ADDR(argv_ret, ret);
  684. }
  685. static void
  686. invoke_iiI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  687. {
  688. void (*native_code)(WASMExecEnv *, int32, int32, int64) = func_ptr;
  689. native_code(exec_env, argv[0], argv[1],
  690. GET_I64_FROM_ADDR((uint32 *)argv + 2));
  691. }
  692. static void
  693. invoke_iiI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  694. {
  695. int32 (*native_code)(WASMExecEnv *, int32, int32, int64) = func_ptr;
  696. argv_ret[0] = native_code(exec_env, argv[0], argv[1],
  697. GET_I64_FROM_ADDR((uint32 *)argv + 2));
  698. }
  699. static void
  700. invoke_iiI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  701. {
  702. int64 (*native_code)(WASMExecEnv *, int32, int32, int64) = func_ptr;
  703. int64 ret = native_code(exec_env, argv[0], argv[1],
  704. GET_I64_FROM_ADDR((uint32 *)argv + 2));
  705. PUT_I64_TO_ADDR(argv_ret, ret);
  706. }
  707. static void
  708. invoke_iIi_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  709. {
  710. void (*native_code)(WASMExecEnv *, int32, int64, int32) = func_ptr;
  711. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
  712. argv[3]);
  713. }
  714. static void
  715. invoke_iIi_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  716. {
  717. int32 (*native_code)(WASMExecEnv *, int32, int64, int32) = func_ptr;
  718. argv_ret[0] = native_code(exec_env, argv[0],
  719. GET_I64_FROM_ADDR((uint32 *)argv + 1), argv[3]);
  720. }
  721. static void
  722. invoke_iIi_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  723. {
  724. int64 (*native_code)(WASMExecEnv *, int32, int64, int32) = func_ptr;
  725. int64 ret = native_code(exec_env, argv[0],
  726. GET_I64_FROM_ADDR((uint32 *)argv + 1), argv[3]);
  727. PUT_I64_TO_ADDR(argv_ret, ret);
  728. }
  729. static void
  730. invoke_iII_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  731. {
  732. void (*native_code)(WASMExecEnv *, int32, int64, int64) = func_ptr;
  733. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
  734. GET_I64_FROM_ADDR((uint32 *)argv + 3));
  735. }
  736. static void
  737. invoke_iII_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  738. {
  739. int32 (*native_code)(WASMExecEnv *, int32, int64, int64) = func_ptr;
  740. argv_ret[0] =
  741. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
  742. GET_I64_FROM_ADDR((uint32 *)argv + 3));
  743. }
  744. static void
  745. invoke_iII_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  746. {
  747. int64 (*native_code)(WASMExecEnv *, int32, int64, int64) = func_ptr;
  748. int64 ret =
  749. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
  750. GET_I64_FROM_ADDR((uint32 *)argv + 3));
  751. PUT_I64_TO_ADDR(argv_ret, ret);
  752. }
  753. static void
  754. invoke_Iii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  755. {
  756. void (*native_code)(WASMExecEnv *, int64, int32, int32) = func_ptr;
  757. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2], argv[3]);
  758. }
  759. static void
  760. invoke_Iii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  761. {
  762. int32 (*native_code)(WASMExecEnv *, int64, int32, int32) = func_ptr;
  763. argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  764. argv[2], argv[3]);
  765. }
  766. static void
  767. invoke_Iii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  768. {
  769. int64 (*native_code)(WASMExecEnv *, int64, int32, int32) = func_ptr;
  770. int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  771. argv[2], argv[3]);
  772. PUT_I64_TO_ADDR(argv_ret, ret);
  773. }
  774. static void
  775. invoke_IiI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  776. {
  777. void (*native_code)(WASMExecEnv *, int64, int32, int64) = func_ptr;
  778. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
  779. GET_I64_FROM_ADDR((uint32 *)argv + 3));
  780. }
  781. static void
  782. invoke_IiI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  783. {
  784. int32 (*native_code)(WASMExecEnv *, int64, int32, int64) = func_ptr;
  785. argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  786. argv[2], GET_I64_FROM_ADDR((uint32 *)argv + 3));
  787. }
  788. static void
  789. invoke_IiI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  790. {
  791. int64 (*native_code)(WASMExecEnv *, int64, int32, int64) = func_ptr;
  792. int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  793. argv[2], GET_I64_FROM_ADDR((uint32 *)argv + 3));
  794. PUT_I64_TO_ADDR(argv_ret, ret);
  795. }
  796. static void
  797. invoke_IIi_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  798. {
  799. void (*native_code)(WASMExecEnv *, int64, int64, int32) = func_ptr;
  800. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  801. GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4]);
  802. }
  803. static void
  804. invoke_IIi_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  805. {
  806. int32 (*native_code)(WASMExecEnv *, int64, int64, int32) = func_ptr;
  807. argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  808. GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4]);
  809. }
  810. static void
  811. invoke_IIi_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  812. {
  813. int64 (*native_code)(WASMExecEnv *, int64, int64, int32) = func_ptr;
  814. int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  815. GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4]);
  816. PUT_I64_TO_ADDR(argv_ret, ret);
  817. }
  818. static void
  819. invoke_III_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  820. {
  821. void (*native_code)(WASMExecEnv *, int64, int64, int64) = func_ptr;
  822. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  823. GET_I64_FROM_ADDR((uint32 *)argv + 2),
  824. GET_I64_FROM_ADDR((uint32 *)argv + 4));
  825. }
  826. static void
  827. invoke_III_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  828. {
  829. int32 (*native_code)(WASMExecEnv *, int64, int64, int64) = func_ptr;
  830. argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  831. GET_I64_FROM_ADDR((uint32 *)argv + 2),
  832. GET_I64_FROM_ADDR((uint32 *)argv + 4));
  833. }
  834. static void
  835. invoke_III_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  836. {
  837. int64 (*native_code)(WASMExecEnv *, int64, int64, int64) = func_ptr;
  838. int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  839. GET_I64_FROM_ADDR((uint32 *)argv + 2),
  840. GET_I64_FROM_ADDR((uint32 *)argv + 4));
  841. PUT_I64_TO_ADDR(argv_ret, ret);
  842. }
  843. static void
  844. invoke_iiii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  845. {
  846. void (*native_code)(WASMExecEnv *, int32, int32, int32, int32) = func_ptr;
  847. native_code(exec_env, argv[0], argv[1], argv[2], argv[3]);
  848. }
  849. static void
  850. invoke_iiii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  851. {
  852. int32 (*native_code)(WASMExecEnv *, int32, int32, int32, int32) = func_ptr;
  853. argv_ret[0] = native_code(exec_env, argv[0], argv[1], argv[2], argv[3]);
  854. }
  855. static void
  856. invoke_iiii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  857. {
  858. int64 (*native_code)(WASMExecEnv *, int32, int32, int32, int32) = func_ptr;
  859. int64 ret = native_code(exec_env, argv[0], argv[1], argv[2], argv[3]);
  860. PUT_I64_TO_ADDR(argv_ret, ret);
  861. }
  862. static void
  863. invoke_iiiI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  864. {
  865. void (*native_code)(WASMExecEnv *, int32, int32, int32, int64) = func_ptr;
  866. native_code(exec_env, argv[0], argv[1], argv[2],
  867. GET_I64_FROM_ADDR((uint32 *)argv + 3));
  868. }
  869. static void
  870. invoke_iiiI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  871. {
  872. int32 (*native_code)(WASMExecEnv *, int32, int32, int32, int64) = func_ptr;
  873. argv_ret[0] = native_code(exec_env, argv[0], argv[1], argv[2],
  874. GET_I64_FROM_ADDR((uint32 *)argv + 3));
  875. }
  876. static void
  877. invoke_iiiI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  878. {
  879. int64 (*native_code)(WASMExecEnv *, int32, int32, int32, int64) = func_ptr;
  880. int64 ret = native_code(exec_env, argv[0], argv[1], argv[2],
  881. GET_I64_FROM_ADDR((uint32 *)argv + 3));
  882. PUT_I64_TO_ADDR(argv_ret, ret);
  883. }
  884. static void
  885. invoke_iiIi_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  886. {
  887. void (*native_code)(WASMExecEnv *, int32, int32, int64, int32) = func_ptr;
  888. native_code(exec_env, argv[0], argv[1],
  889. GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4]);
  890. }
  891. static void
  892. invoke_iiIi_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  893. {
  894. int32 (*native_code)(WASMExecEnv *, int32, int32, int64, int32) = func_ptr;
  895. argv_ret[0] = native_code(exec_env, argv[0], argv[1],
  896. GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4]);
  897. }
  898. static void
  899. invoke_iiIi_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  900. {
  901. int64 (*native_code)(WASMExecEnv *, int32, int32, int64, int32) = func_ptr;
  902. int64 ret = native_code(exec_env, argv[0], argv[1],
  903. GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4]);
  904. PUT_I64_TO_ADDR(argv_ret, ret);
  905. }
  906. static void
  907. invoke_iiII_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  908. {
  909. void (*native_code)(WASMExecEnv *, int32, int32, int64, int64) = func_ptr;
  910. native_code(exec_env, argv[0], argv[1],
  911. GET_I64_FROM_ADDR((uint32 *)argv + 2),
  912. GET_I64_FROM_ADDR((uint32 *)argv + 4));
  913. }
  914. static void
  915. invoke_iiII_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  916. {
  917. int32 (*native_code)(WASMExecEnv *, int32, int32, int64, int64) = func_ptr;
  918. argv_ret[0] = native_code(exec_env, argv[0], argv[1],
  919. GET_I64_FROM_ADDR((uint32 *)argv + 2),
  920. GET_I64_FROM_ADDR((uint32 *)argv + 4));
  921. }
  922. static void
  923. invoke_iiII_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  924. {
  925. int64 (*native_code)(WASMExecEnv *, int32, int32, int64, int64) = func_ptr;
  926. int64 ret = native_code(exec_env, argv[0], argv[1],
  927. GET_I64_FROM_ADDR((uint32 *)argv + 2),
  928. GET_I64_FROM_ADDR((uint32 *)argv + 4));
  929. PUT_I64_TO_ADDR(argv_ret, ret);
  930. }
  931. static void
  932. invoke_iIii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  933. {
  934. void (*native_code)(WASMExecEnv *, int32, int64, int32, int32) = func_ptr;
  935. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
  936. argv[3], argv[4]);
  937. }
  938. static void
  939. invoke_iIii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  940. {
  941. int32 (*native_code)(WASMExecEnv *, int32, int64, int32, int32) = func_ptr;
  942. argv_ret[0] =
  943. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
  944. argv[3], argv[4]);
  945. }
  946. static void
  947. invoke_iIii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  948. {
  949. int64 (*native_code)(WASMExecEnv *, int32, int64, int32, int32) = func_ptr;
  950. int64 ret =
  951. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
  952. argv[3], argv[4]);
  953. PUT_I64_TO_ADDR(argv_ret, ret);
  954. }
  955. static void
  956. invoke_iIiI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  957. {
  958. void (*native_code)(WASMExecEnv *, int32, int64, int32, int64) = func_ptr;
  959. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
  960. argv[3], GET_I64_FROM_ADDR((uint32 *)argv + 4));
  961. }
  962. static void
  963. invoke_iIiI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  964. {
  965. int32 (*native_code)(WASMExecEnv *, int32, int64, int32, int64) = func_ptr;
  966. argv_ret[0] =
  967. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
  968. argv[3], GET_I64_FROM_ADDR((uint32 *)argv + 4));
  969. }
  970. static void
  971. invoke_iIiI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  972. {
  973. int64 (*native_code)(WASMExecEnv *, int32, int64, int32, int64) = func_ptr;
  974. int64 ret =
  975. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
  976. argv[3], GET_I64_FROM_ADDR((uint32 *)argv + 4));
  977. PUT_I64_TO_ADDR(argv_ret, ret);
  978. }
  979. static void
  980. invoke_iIIi_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  981. {
  982. void (*native_code)(WASMExecEnv *, int32, int64, int64, int32) = func_ptr;
  983. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
  984. GET_I64_FROM_ADDR((uint32 *)argv + 3), argv[5]);
  985. }
  986. static void
  987. invoke_iIIi_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  988. {
  989. int32 (*native_code)(WASMExecEnv *, int32, int64, int64, int32) = func_ptr;
  990. argv_ret[0] =
  991. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
  992. GET_I64_FROM_ADDR((uint32 *)argv + 3), argv[5]);
  993. }
  994. static void
  995. invoke_iIIi_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  996. {
  997. int64 (*native_code)(WASMExecEnv *, int32, int64, int64, int32) = func_ptr;
  998. int64 ret =
  999. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
  1000. GET_I64_FROM_ADDR((uint32 *)argv + 3), argv[5]);
  1001. PUT_I64_TO_ADDR(argv_ret, ret);
  1002. }
  1003. static void
  1004. invoke_iIII_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1005. {
  1006. void (*native_code)(WASMExecEnv *, int32, int64, int64, int64) = func_ptr;
  1007. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
  1008. GET_I64_FROM_ADDR((uint32 *)argv + 3),
  1009. GET_I64_FROM_ADDR((uint32 *)argv + 5));
  1010. }
  1011. static void
  1012. invoke_iIII_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1013. {
  1014. int32 (*native_code)(WASMExecEnv *, int32, int64, int64, int64) = func_ptr;
  1015. argv_ret[0] =
  1016. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
  1017. GET_I64_FROM_ADDR((uint32 *)argv + 3),
  1018. GET_I64_FROM_ADDR((uint32 *)argv + 5));
  1019. }
  1020. static void
  1021. invoke_iIII_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1022. {
  1023. int64 (*native_code)(WASMExecEnv *, int32, int64, int64, int64) = func_ptr;
  1024. int64 ret =
  1025. native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
  1026. GET_I64_FROM_ADDR((uint32 *)argv + 3),
  1027. GET_I64_FROM_ADDR((uint32 *)argv + 5));
  1028. PUT_I64_TO_ADDR(argv_ret, ret);
  1029. }
  1030. static void
  1031. invoke_Iiii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1032. {
  1033. void (*native_code)(WASMExecEnv *, int64, int32, int32, int32) = func_ptr;
  1034. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2], argv[3],
  1035. argv[4]);
  1036. }
  1037. static void
  1038. invoke_Iiii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1039. {
  1040. int32 (*native_code)(WASMExecEnv *, int64, int32, int32, int32) = func_ptr;
  1041. argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  1042. argv[2], argv[3], argv[4]);
  1043. }
  1044. static void
  1045. invoke_Iiii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1046. {
  1047. int64 (*native_code)(WASMExecEnv *, int64, int32, int32, int32) = func_ptr;
  1048. int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  1049. argv[2], argv[3], argv[4]);
  1050. PUT_I64_TO_ADDR(argv_ret, ret);
  1051. }
  1052. static void
  1053. invoke_IiiI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1054. {
  1055. void (*native_code)(WASMExecEnv *, int64, int32, int32, int64) = func_ptr;
  1056. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2], argv[3],
  1057. GET_I64_FROM_ADDR((uint32 *)argv + 4));
  1058. }
  1059. static void
  1060. invoke_IiiI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1061. {
  1062. int32 (*native_code)(WASMExecEnv *, int64, int32, int32, int64) = func_ptr;
  1063. argv_ret[0] =
  1064. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
  1065. argv[3], GET_I64_FROM_ADDR((uint32 *)argv + 4));
  1066. }
  1067. static void
  1068. invoke_IiiI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1069. {
  1070. int64 (*native_code)(WASMExecEnv *, int64, int32, int32, int64) = func_ptr;
  1071. int64 ret =
  1072. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
  1073. argv[3], GET_I64_FROM_ADDR((uint32 *)argv + 4));
  1074. PUT_I64_TO_ADDR(argv_ret, ret);
  1075. }
  1076. static void
  1077. invoke_IiIi_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1078. {
  1079. void (*native_code)(WASMExecEnv *, int64, int32, int64, int32) = func_ptr;
  1080. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
  1081. GET_I64_FROM_ADDR((uint32 *)argv + 3), argv[5]);
  1082. }
  1083. static void
  1084. invoke_IiIi_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1085. {
  1086. int32 (*native_code)(WASMExecEnv *, int64, int32, int64, int32) = func_ptr;
  1087. argv_ret[0] =
  1088. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
  1089. GET_I64_FROM_ADDR((uint32 *)argv + 3), argv[5]);
  1090. }
  1091. static void
  1092. invoke_IiIi_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1093. {
  1094. int64 (*native_code)(WASMExecEnv *, int64, int32, int64, int32) = func_ptr;
  1095. int64 ret =
  1096. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
  1097. GET_I64_FROM_ADDR((uint32 *)argv + 3), argv[5]);
  1098. PUT_I64_TO_ADDR(argv_ret, ret);
  1099. }
  1100. static void
  1101. invoke_IiII_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1102. {
  1103. void (*native_code)(WASMExecEnv *, int64, int32, int64, int64) = func_ptr;
  1104. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
  1105. GET_I64_FROM_ADDR((uint32 *)argv + 3),
  1106. GET_I64_FROM_ADDR((uint32 *)argv + 5));
  1107. }
  1108. static void
  1109. invoke_IiII_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1110. {
  1111. int32 (*native_code)(WASMExecEnv *, int64, int32, int64, int64) = func_ptr;
  1112. argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  1113. argv[2], GET_I64_FROM_ADDR((uint32 *)argv + 3),
  1114. GET_I64_FROM_ADDR((uint32 *)argv + 5));
  1115. }
  1116. static void
  1117. invoke_IiII_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1118. {
  1119. int64 (*native_code)(WASMExecEnv *, int64, int32, int64, int64) = func_ptr;
  1120. int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  1121. argv[2], GET_I64_FROM_ADDR((uint32 *)argv + 3),
  1122. GET_I64_FROM_ADDR((uint32 *)argv + 5));
  1123. PUT_I64_TO_ADDR(argv_ret, ret);
  1124. }
  1125. static void
  1126. invoke_IIii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1127. {
  1128. void (*native_code)(WASMExecEnv *, int64, int64, int32, int32) = func_ptr;
  1129. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  1130. GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4], argv[5]);
  1131. }
  1132. static void
  1133. invoke_IIii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1134. {
  1135. int32 (*native_code)(WASMExecEnv *, int64, int64, int32, int32) = func_ptr;
  1136. argv_ret[0] =
  1137. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  1138. GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4], argv[5]);
  1139. }
  1140. static void
  1141. invoke_IIii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1142. {
  1143. int64 (*native_code)(WASMExecEnv *, int64, int64, int32, int32) = func_ptr;
  1144. int64 ret =
  1145. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  1146. GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4], argv[5]);
  1147. PUT_I64_TO_ADDR(argv_ret, ret);
  1148. }
  1149. static void
  1150. invoke_IIiI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1151. {
  1152. void (*native_code)(WASMExecEnv *, int64, int64, int32, int64) = func_ptr;
  1153. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  1154. GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4],
  1155. GET_I64_FROM_ADDR((uint32 *)argv + 5));
  1156. }
  1157. static void
  1158. invoke_IIiI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1159. {
  1160. int32 (*native_code)(WASMExecEnv *, int64, int64, int32, int64) = func_ptr;
  1161. argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  1162. GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4],
  1163. GET_I64_FROM_ADDR((uint32 *)argv + 5));
  1164. }
  1165. static void
  1166. invoke_IIiI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1167. {
  1168. int64 (*native_code)(WASMExecEnv *, int64, int64, int32, int64) = func_ptr;
  1169. int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  1170. GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4],
  1171. GET_I64_FROM_ADDR((uint32 *)argv + 5));
  1172. PUT_I64_TO_ADDR(argv_ret, ret);
  1173. }
  1174. static void
  1175. invoke_IIIi_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1176. {
  1177. void (*native_code)(WASMExecEnv *, int64, int64, int64, int32) = func_ptr;
  1178. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  1179. GET_I64_FROM_ADDR((uint32 *)argv + 2),
  1180. GET_I64_FROM_ADDR((uint32 *)argv + 4), argv[6]);
  1181. }
  1182. static void
  1183. invoke_IIIi_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1184. {
  1185. int32 (*native_code)(WASMExecEnv *, int64, int64, int64, int32) = func_ptr;
  1186. argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  1187. GET_I64_FROM_ADDR((uint32 *)argv + 2),
  1188. GET_I64_FROM_ADDR((uint32 *)argv + 4), argv[6]);
  1189. }
  1190. static void
  1191. invoke_IIIi_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1192. {
  1193. int64 (*native_code)(WASMExecEnv *, int64, int64, int64, int32) = func_ptr;
  1194. int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  1195. GET_I64_FROM_ADDR((uint32 *)argv + 2),
  1196. GET_I64_FROM_ADDR((uint32 *)argv + 4), argv[6]);
  1197. PUT_I64_TO_ADDR(argv_ret, ret);
  1198. }
  1199. static void
  1200. invoke_IIII_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1201. {
  1202. void (*native_code)(WASMExecEnv *, int64, int64, int64, int64) = func_ptr;
  1203. native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  1204. GET_I64_FROM_ADDR((uint32 *)argv + 2),
  1205. GET_I64_FROM_ADDR((uint32 *)argv + 4),
  1206. GET_I64_FROM_ADDR((uint32 *)argv + 6));
  1207. }
  1208. static void
  1209. invoke_IIII_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1210. {
  1211. int32 (*native_code)(WASMExecEnv *, int64, int64, int64, int64) = func_ptr;
  1212. argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  1213. GET_I64_FROM_ADDR((uint32 *)argv + 2),
  1214. GET_I64_FROM_ADDR((uint32 *)argv + 4),
  1215. GET_I64_FROM_ADDR((uint32 *)argv + 6));
  1216. }
  1217. static void
  1218. invoke_IIII_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1219. {
  1220. int64 (*native_code)(WASMExecEnv *, int64, int64, int64, int64) = func_ptr;
  1221. int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
  1222. GET_I64_FROM_ADDR((uint32 *)argv + 2),
  1223. GET_I64_FROM_ADDR((uint32 *)argv + 4),
  1224. GET_I64_FROM_ADDR((uint32 *)argv + 6));
  1225. PUT_I64_TO_ADDR(argv_ret, ret);
  1226. }
  1227. static void
  1228. invoke_iiiii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1229. {
  1230. void (*native_code)(WASMExecEnv *, int32, int32, int32, int32, int32) =
  1231. func_ptr;
  1232. native_code(exec_env, argv[0], argv[1], argv[2], argv[3], argv[4]);
  1233. }
  1234. static void
  1235. invoke_iiiii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1236. {
  1237. int32 (*native_code)(WASMExecEnv *, int32, int32, int32, int32, int32) =
  1238. func_ptr;
  1239. argv_ret[0] =
  1240. native_code(exec_env, argv[0], argv[1], argv[2], argv[3], argv[4]);
  1241. }
  1242. static void
  1243. invoke_iiiii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
  1244. {
  1245. int64 (*native_code)(WASMExecEnv *, int32, int32, int32, int32, int32) =
  1246. func_ptr;
  1247. int64 ret =
  1248. native_code(exec_env, argv[0], argv[1], argv[2], argv[3], argv[4]);
  1249. PUT_I64_TO_ADDR(argv_ret, ret);
  1250. }
  1251. typedef struct QuickAOTEntry {
  1252. const char *signature;
  1253. void *func_ptr;
  1254. } QuickAOTEntry;
  1255. /* clang-format off */
  1256. static QuickAOTEntry quick_aot_entries[] = {
  1257. { "()v", invoke_no_args_v },
  1258. { "()i", invoke_no_args_i },
  1259. { "()I", invoke_no_args_I },
  1260. { "(i)v", invoke_i_v }, { "(i)i", invoke_i_i }, { "(i)I", invoke_i_I },
  1261. { "(I)v", invoke_I_v }, { "(I)i", invoke_I_i }, { "(I)I", invoke_I_I },
  1262. { "(ii)v", invoke_ii_v }, { "(ii)i", invoke_ii_i }, { "(ii)I", invoke_ii_I },
  1263. { "(iI)v", invoke_iI_v }, { "(iI)i", invoke_iI_i }, { "(iI)I", invoke_iI_I },
  1264. { "(Ii)v", invoke_Ii_v }, { "(Ii)i", invoke_Ii_i }, { "(Ii)I", invoke_Ii_I },
  1265. { "(II)v", invoke_II_v }, { "(II)i", invoke_II_i }, { "(II)I", invoke_II_I },
  1266. { "(iii)v", invoke_iii_v }, { "(iii)i", invoke_iii_i }, { "(iii)I", invoke_iii_I },
  1267. { "(iiI)v", invoke_iiI_v }, { "(iiI)i", invoke_iiI_i }, { "(iiI)I", invoke_iiI_I },
  1268. { "(iIi)v", invoke_iIi_v }, { "(iIi)i", invoke_iIi_i }, { "(iIi)I", invoke_iIi_I },
  1269. { "(iII)v", invoke_iII_v }, { "(iII)i", invoke_iII_i }, { "(iII)I", invoke_iII_I },
  1270. { "(Iii)v", invoke_Iii_v }, { "(Iii)i", invoke_Iii_i }, { "(Iii)I", invoke_Iii_I },
  1271. { "(IiI)v", invoke_IiI_v }, { "(IiI)i", invoke_IiI_i }, { "(IiI)I", invoke_IiI_I },
  1272. { "(IIi)v", invoke_IIi_v }, { "(IIi)i", invoke_IIi_i }, { "(IIi)I", invoke_IIi_I },
  1273. { "(III)v", invoke_III_v }, { "(III)i", invoke_III_i }, { "(III)I", invoke_III_I },
  1274. { "(iiii)v", invoke_iiii_v }, { "(iiii)i", invoke_iiii_i }, { "(iiii)I", invoke_iiii_I },
  1275. { "(iiiI)v", invoke_iiiI_v }, { "(iiiI)i", invoke_iiiI_i }, { "(iiiI)I", invoke_iiiI_I },
  1276. { "(iiIi)v", invoke_iiIi_v }, { "(iiIi)i", invoke_iiIi_i }, { "(iiIi)I", invoke_iiIi_I },
  1277. { "(iiII)v", invoke_iiII_v }, { "(iiII)i", invoke_iiII_i }, { "(iiII)I", invoke_iiII_I },
  1278. { "(iIii)v", invoke_iIii_v }, { "(iIii)i", invoke_iIii_i }, { "(iIii)I", invoke_iIii_I },
  1279. { "(iIiI)v", invoke_iIiI_v }, { "(iIiI)i", invoke_iIiI_i }, { "(iIiI)I", invoke_iIiI_I },
  1280. { "(iIIi)v", invoke_iIIi_v }, { "(iIIi)i", invoke_iIIi_i }, { "(iIIi)I", invoke_iIIi_I },
  1281. { "(iIII)v", invoke_iIII_v }, { "(iIII)i", invoke_iIII_i }, { "(iIII)I", invoke_iIII_I },
  1282. { "(Iiii)v", invoke_Iiii_v }, { "(Iiii)i", invoke_Iiii_i }, { "(Iiii)I", invoke_Iiii_I },
  1283. { "(IiiI)v", invoke_IiiI_v }, { "(IiiI)i", invoke_IiiI_i }, { "(IiiI)I", invoke_IiiI_I },
  1284. { "(IiIi)v", invoke_IiIi_v }, { "(IiIi)i", invoke_IiIi_i }, { "(IiIi)I", invoke_IiIi_I },
  1285. { "(IiII)v", invoke_IiII_v }, { "(IiII)i", invoke_IiII_i }, { "(IiII)I", invoke_IiII_I },
  1286. { "(IIii)v", invoke_IIii_v }, { "(IIii)i", invoke_IIii_i }, { "(IIii)I", invoke_IIii_I },
  1287. { "(IIiI)v", invoke_IIiI_v }, { "(IIiI)i", invoke_IIiI_i }, { "(IIiI)I", invoke_IIiI_I },
  1288. { "(IIIi)v", invoke_IIIi_v }, { "(IIIi)i", invoke_IIIi_i }, { "(IIIi)I", invoke_IIIi_I },
  1289. { "(IIII)v", invoke_IIII_v }, { "(IIII)i", invoke_IIII_i }, { "(IIII)I", invoke_IIII_I },
  1290. { "(iiiii)v", invoke_iiiii_v }, { "(iiiii)i", invoke_iiiii_i }, { "(iiiii)I", invoke_iiiii_I },
  1291. };
  1292. /* clang-format on */
  1293. static int
  1294. quick_aot_entry_cmp(const void *quick_aot_entry1, const void *quick_aot_entry2)
  1295. {
  1296. return strcmp(((const QuickAOTEntry *)quick_aot_entry1)->signature,
  1297. ((const QuickAOTEntry *)quick_aot_entry2)->signature);
  1298. }
  1299. static bool
  1300. quick_aot_entry_init()
  1301. {
  1302. qsort(quick_aot_entries, sizeof(quick_aot_entries) / sizeof(QuickAOTEntry),
  1303. sizeof(QuickAOTEntry), quick_aot_entry_cmp);
  1304. return true;
  1305. }
  1306. void *
  1307. wasm_native_lookup_quick_aot_entry(const WASMType *func_type)
  1308. {
  1309. char signature[16] = { 0 };
  1310. uint32 param_count = func_type->param_count;
  1311. uint32 result_count = func_type->result_count, i, j = 0;
  1312. const uint8 *types = func_type->types;
  1313. QuickAOTEntry *quick_aot_entry, key = { 0 };
  1314. if (param_count > 5 || result_count > 1)
  1315. return NULL;
  1316. signature[j++] = '(';
  1317. for (i = 0; i < param_count; i++) {
  1318. if (types[i] == VALUE_TYPE_I32)
  1319. signature[j++] = 'i';
  1320. else if (types[i] == VALUE_TYPE_I64)
  1321. signature[j++] = 'I';
  1322. else
  1323. return NULL;
  1324. }
  1325. signature[j++] = ')';
  1326. if (result_count == 0) {
  1327. signature[j++] = 'v';
  1328. }
  1329. else {
  1330. if (types[i] == VALUE_TYPE_I32)
  1331. signature[j++] = 'i';
  1332. else if (types[i] == VALUE_TYPE_I64)
  1333. signature[j++] = 'I';
  1334. else
  1335. return NULL;
  1336. }
  1337. key.signature = signature;
  1338. if ((quick_aot_entry =
  1339. bsearch(&key, quick_aot_entries,
  1340. sizeof(quick_aot_entries) / sizeof(QuickAOTEntry),
  1341. sizeof(QuickAOTEntry), quick_aot_entry_cmp))) {
  1342. return quick_aot_entry->func_ptr;
  1343. }
  1344. return NULL;
  1345. }
  1346. #endif /* end of WASM_ENABLE_QUICK_AOT_ENTRY != 0 */