wasm_native.c 53 KB

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