wasm_native.c 52 KB

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