| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519 |
- /*
- * Copyright (C) 2019 Intel Corporation. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- */
- #include "wasm_native.h"
- #include "wasm_runtime_common.h"
- #include "bh_log.h"
- #if WASM_ENABLE_INTERP != 0
- #include "../interpreter/wasm_runtime.h"
- #endif
- #if WASM_ENABLE_AOT != 0
- #include "../aot/aot_runtime.h"
- #endif
- #if WASM_ENABLE_THREAD_MGR != 0
- #include "../libraries/thread-mgr/thread_manager.h"
- #endif
- #if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
- #include "wasi_nn_host.h"
- #endif
- static NativeSymbolsList g_native_symbols_list = NULL;
- #if WASM_ENABLE_LIBC_WASI != 0
- static void *g_wasi_context_key;
- #endif /* WASM_ENABLE_LIBC_WASI */
- uint32
- get_libc_builtin_export_apis(NativeSymbol **p_libc_builtin_apis);
- #if WASM_ENABLE_SPEC_TEST != 0
- uint32
- get_spectest_export_apis(NativeSymbol **p_libc_builtin_apis);
- #endif
- uint32
- get_libc_wasi_export_apis(NativeSymbol **p_libc_wasi_apis);
- uint32
- get_base_lib_export_apis(NativeSymbol **p_base_lib_apis);
- uint32
- get_ext_lib_export_apis(NativeSymbol **p_ext_lib_apis);
- #if WASM_ENABLE_LIB_PTHREAD != 0
- bool
- lib_pthread_init();
- void
- lib_pthread_destroy();
- uint32
- get_lib_pthread_export_apis(NativeSymbol **p_lib_pthread_apis);
- #endif
- #if WASM_ENABLE_LIB_WASI_THREADS != 0
- bool
- lib_wasi_threads_init(void);
- void
- lib_wasi_threads_destroy(void);
- uint32
- get_lib_wasi_threads_export_apis(NativeSymbol **p_lib_wasi_threads_apis);
- #endif
- uint32
- get_libc_emcc_export_apis(NativeSymbol **p_libc_emcc_apis);
- uint32
- get_lib_rats_export_apis(NativeSymbol **p_lib_rats_apis);
- static bool
- compare_type_with_signature(uint8 type, const char signature)
- {
- const char num_sig_map[] = { 'F', 'f', 'I', 'i' };
- if (VALUE_TYPE_F64 <= type && type <= VALUE_TYPE_I32
- && signature == num_sig_map[type - VALUE_TYPE_F64]) {
- return true;
- }
- #if WASM_ENABLE_REF_TYPES != 0
- if ('r' == signature
- #if WASM_ENABLE_GC != 0
- #if WASM_ENABLE_STRINGREF != 0
- && (type >= REF_TYPE_STRINGVIEWITER && type <= REF_TYPE_NULLFUNCREF)
- #else
- && (type >= REF_TYPE_HT_NULLABLE && type <= REF_TYPE_NULLFUNCREF)
- #endif
- #else
- && type == VALUE_TYPE_EXTERNREF
- #endif
- )
- return true;
- #endif
- /* TODO: a v128 parameter */
- return false;
- }
- static bool
- check_symbol_signature(const WASMFuncType *type, const char *signature)
- {
- const char *p = signature, *p_end;
- char sig;
- uint32 i = 0;
- if (!p || strlen(p) < 2)
- return false;
- p_end = p + strlen(signature);
- if (*p++ != '(')
- return false;
- if ((uint32)(p_end - p) < (uint32)(type->param_count + 1))
- /* signatures of parameters, and ')' */
- return false;
- for (i = 0; i < type->param_count; i++) {
- sig = *p++;
- /* a f64/f32/i64/i32/externref parameter */
- if (compare_type_with_signature(type->types[i], sig))
- continue;
- /* a pointer/string parameter */
- if (type->types[i] != VALUE_TYPE_I32)
- /* pointer and string must be i32 type */
- return false;
- if (sig == '*') {
- /* it is a pointer */
- if (i + 1 < type->param_count
- && type->types[i + 1] == VALUE_TYPE_I32 && *p == '~') {
- /* pointer length followed */
- i++;
- p++;
- }
- }
- else if (sig == '$') {
- /* it is a string */
- }
- else {
- /* invalid signature */
- return false;
- }
- }
- if (*p++ != ')')
- return false;
- if (type->result_count) {
- if (p >= p_end)
- return false;
- /* result types includes: f64,f32,i64,i32,externref */
- if (!compare_type_with_signature(type->types[i], *p))
- return false;
- p++;
- }
- if (*p != '\0')
- return false;
- return true;
- }
- static int
- native_symbol_cmp(const void *native_symbol1, const void *native_symbol2)
- {
- return strcmp(((const NativeSymbol *)native_symbol1)->symbol,
- ((const NativeSymbol *)native_symbol2)->symbol);
- }
- static void *
- lookup_symbol(NativeSymbol *native_symbols, uint32 n_native_symbols,
- const char *symbol, const char **p_signature, void **p_attachment)
- {
- NativeSymbol *native_symbol, key = { 0 };
- key.symbol = symbol;
- if ((native_symbol = bsearch(&key, native_symbols, n_native_symbols,
- sizeof(NativeSymbol), native_symbol_cmp))) {
- *p_signature = native_symbol->signature;
- *p_attachment = native_symbol->attachment;
- return native_symbol->func_ptr;
- }
- return NULL;
- }
- /**
- * allow func_type and all outputs, like p_signature, p_attachment and
- * p_call_conv_raw to be NULL
- */
- void *
- wasm_native_resolve_symbol(const char *module_name, const char *field_name,
- const WASMFuncType *func_type,
- const char **p_signature, void **p_attachment,
- bool *p_call_conv_raw)
- {
- NativeSymbolsNode *node, *node_next;
- const char *signature = NULL;
- void *func_ptr = NULL, *attachment = NULL;
- node = g_native_symbols_list;
- while (node) {
- node_next = node->next;
- if (!strcmp(node->module_name, module_name)) {
- if ((func_ptr =
- lookup_symbol(node->native_symbols, node->n_native_symbols,
- field_name, &signature, &attachment))
- || (field_name[0] == '_'
- && (func_ptr = lookup_symbol(
- node->native_symbols, node->n_native_symbols,
- field_name + 1, &signature, &attachment))))
- break;
- }
- node = node_next;
- }
- if (!p_signature || !p_attachment || !p_call_conv_raw)
- return func_ptr;
- if (func_ptr) {
- if (signature && signature[0] != '\0') {
- /* signature is not empty, check its format */
- if (!func_type || !check_symbol_signature(func_type, signature)) {
- #if WASM_ENABLE_WAMR_COMPILER == 0
- /* Output warning except running aot compiler */
- LOG_WARNING("failed to check signature '%s' and resolve "
- "pointer params for import function (%s, %s)\n",
- signature, module_name, field_name);
- #endif
- return NULL;
- }
- else
- /* Save signature for runtime to do pointer check and
- address conversion */
- *p_signature = signature;
- }
- else
- /* signature is empty */
- *p_signature = NULL;
- *p_attachment = attachment;
- *p_call_conv_raw = node->call_conv_raw;
- }
- return func_ptr;
- }
- static bool
- register_natives(const char *module_name, NativeSymbol *native_symbols,
- uint32 n_native_symbols, bool call_conv_raw)
- {
- NativeSymbolsNode *node;
- if (!(node = wasm_runtime_malloc(sizeof(NativeSymbolsNode))))
- return false;
- #if WASM_ENABLE_MEMORY_TRACING != 0
- os_printf("Register native, size: %u\n", sizeof(NativeSymbolsNode));
- #endif
- node->module_name = module_name;
- node->native_symbols = native_symbols;
- node->n_native_symbols = n_native_symbols;
- node->call_conv_raw = call_conv_raw;
- /* Add to list head */
- node->next = g_native_symbols_list;
- g_native_symbols_list = node;
- qsort(native_symbols, n_native_symbols, sizeof(NativeSymbol),
- native_symbol_cmp);
- return true;
- }
- bool
- wasm_native_register_natives(const char *module_name,
- NativeSymbol *native_symbols,
- uint32 n_native_symbols)
- {
- return register_natives(module_name, native_symbols, n_native_symbols,
- false);
- }
- bool
- wasm_native_register_natives_raw(const char *module_name,
- NativeSymbol *native_symbols,
- uint32 n_native_symbols)
- {
- return register_natives(module_name, native_symbols, n_native_symbols,
- true);
- }
- bool
- wasm_native_unregister_natives(const char *module_name,
- NativeSymbol *native_symbols)
- {
- NativeSymbolsNode **prevp;
- NativeSymbolsNode *node;
- prevp = &g_native_symbols_list;
- while ((node = *prevp) != NULL) {
- if (node->native_symbols == native_symbols
- && !strcmp(node->module_name, module_name)) {
- *prevp = node->next;
- wasm_runtime_free(node);
- return true;
- }
- prevp = &node->next;
- }
- return false;
- }
- #if WASM_ENABLE_MODULE_INST_CONTEXT != 0
- static uint32
- context_key_to_idx(void *key)
- {
- bh_assert(key != NULL);
- uint32 idx = (uint32)(uintptr_t)key;
- bh_assert(idx > 0);
- bh_assert(idx <= WASM_MAX_INSTANCE_CONTEXTS);
- return idx - 1;
- }
- static void *
- context_idx_to_key(uint32 idx)
- {
- bh_assert(idx < WASM_MAX_INSTANCE_CONTEXTS);
- return (void *)(uintptr_t)(idx + 1);
- }
- typedef void (*dtor_t)(WASMModuleInstanceCommon *, void *);
- static dtor_t g_context_dtors[WASM_MAX_INSTANCE_CONTEXTS];
- static void
- dtor_noop(WASMModuleInstanceCommon *inst, void *ctx)
- {}
- void *
- wasm_native_create_context_key(void (*dtor)(WASMModuleInstanceCommon *inst,
- void *ctx))
- {
- uint32 i;
- for (i = 0; i < WASM_MAX_INSTANCE_CONTEXTS; i++) {
- if (g_context_dtors[i] == NULL) {
- if (dtor == NULL) {
- dtor = dtor_noop;
- }
- g_context_dtors[i] = dtor;
- return context_idx_to_key(i);
- }
- }
- LOG_ERROR("failed to allocate instance context key");
- return NULL;
- }
- void
- wasm_native_destroy_context_key(void *key)
- {
- uint32 idx = context_key_to_idx(key);
- bh_assert(g_context_dtors[idx] != NULL);
- g_context_dtors[idx] = NULL;
- }
- static WASMModuleInstanceExtraCommon *
- wasm_module_inst_extra_common(WASMModuleInstanceCommon *inst)
- {
- #if WASM_ENABLE_INTERP != 0
- if (inst->module_type == Wasm_Module_Bytecode) {
- return &((WASMModuleInstance *)inst)->e->common;
- }
- #endif
- #if WASM_ENABLE_AOT != 0
- if (inst->module_type == Wasm_Module_AoT) {
- return &((AOTModuleInstanceExtra *)((AOTModuleInstance *)inst)->e)
- ->common;
- }
- #endif
- bh_assert(false);
- return NULL;
- }
- void
- wasm_native_set_context(WASMModuleInstanceCommon *inst, void *key, void *ctx)
- {
- uint32 idx = context_key_to_idx(key);
- WASMModuleInstanceExtraCommon *common = wasm_module_inst_extra_common(inst);
- common->contexts[idx] = ctx;
- }
- void
- wasm_native_set_context_spread(WASMModuleInstanceCommon *inst, void *key,
- void *ctx)
- {
- #if WASM_ENABLE_THREAD_MGR != 0
- wasm_cluster_set_context(inst, key, ctx);
- #else
- wasm_native_set_context(inst, key, ctx);
- #endif
- }
- void *
- wasm_native_get_context(WASMModuleInstanceCommon *inst, void *key)
- {
- uint32 idx = context_key_to_idx(key);
- WASMModuleInstanceExtraCommon *common = wasm_module_inst_extra_common(inst);
- return common->contexts[idx];
- }
- void
- wasm_native_call_context_dtors(WASMModuleInstanceCommon *inst)
- {
- WASMModuleInstanceExtraCommon *common = wasm_module_inst_extra_common(inst);
- uint32 i;
- for (i = 0; i < WASM_MAX_INSTANCE_CONTEXTS; i++) {
- dtor_t dtor = g_context_dtors[i];
- if (dtor != NULL) {
- dtor(inst, common->contexts[i]);
- }
- }
- }
- void
- wasm_native_inherit_contexts(WASMModuleInstanceCommon *child,
- WASMModuleInstanceCommon *parent)
- {
- WASMModuleInstanceExtraCommon *parent_common =
- wasm_module_inst_extra_common(parent);
- WASMModuleInstanceExtraCommon *child_common =
- wasm_module_inst_extra_common(child);
- bh_memcpy_s(child_common->contexts,
- sizeof(*child_common->contexts) * WASM_MAX_INSTANCE_CONTEXTS,
- parent_common->contexts,
- sizeof(*parent_common->contexts) * WASM_MAX_INSTANCE_CONTEXTS);
- }
- #endif /* WASM_ENABLE_MODULE_INST_CONTEXT != 0 */
- #if WASM_ENABLE_LIBC_WASI != 0
- WASIContext *
- wasm_runtime_get_wasi_ctx(WASMModuleInstanceCommon *module_inst_comm)
- {
- return wasm_native_get_context(module_inst_comm, g_wasi_context_key);
- }
- void
- wasm_runtime_set_wasi_ctx(WASMModuleInstanceCommon *module_inst_comm,
- WASIContext *wasi_ctx)
- {
- wasm_native_set_context(module_inst_comm, g_wasi_context_key, wasi_ctx);
- }
- static void
- wasi_context_dtor(WASMModuleInstanceCommon *inst, void *ctx)
- {
- if (ctx == NULL) {
- return;
- }
- wasm_runtime_destroy_wasi(inst);
- }
- #endif /* end of WASM_ENABLE_LIBC_WASI */
- #if WASM_ENABLE_QUICK_AOT_ENTRY != 0
- static bool
- quick_aot_entry_init(void);
- #endif
- bool
- wasm_native_init()
- {
- #if WASM_ENABLE_SPEC_TEST != 0 || WASM_ENABLE_LIBC_BUILTIN != 0 \
- || WASM_ENABLE_BASE_LIB != 0 || WASM_ENABLE_LIBC_EMCC != 0 \
- || WASM_ENABLE_LIB_RATS != 0 || WASM_ENABLE_WASI_NN != 0 \
- || WASM_ENABLE_APP_FRAMEWORK != 0 || WASM_ENABLE_LIBC_WASI != 0 \
- || WASM_ENABLE_LIB_PTHREAD != 0 || WASM_ENABLE_LIB_WASI_THREADS != 0 \
- || WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
- NativeSymbol *native_symbols;
- uint32 n_native_symbols;
- #endif
- #if WASM_ENABLE_LIBC_BUILTIN != 0
- n_native_symbols = get_libc_builtin_export_apis(&native_symbols);
- if (!wasm_native_register_natives("env", native_symbols, n_native_symbols))
- goto fail;
- #endif /* WASM_ENABLE_LIBC_BUILTIN */
- #if WASM_ENABLE_SPEC_TEST
- n_native_symbols = get_spectest_export_apis(&native_symbols);
- if (!wasm_native_register_natives("spectest", native_symbols,
- n_native_symbols))
- goto fail;
- #endif /* WASM_ENABLE_SPEC_TEST */
- #if WASM_ENABLE_LIBC_WASI != 0
- g_wasi_context_key = wasm_native_create_context_key(wasi_context_dtor);
- if (g_wasi_context_key == NULL) {
- goto fail;
- }
- n_native_symbols = get_libc_wasi_export_apis(&native_symbols);
- if (!wasm_native_register_natives("wasi_unstable", native_symbols,
- n_native_symbols))
- goto fail;
- if (!wasm_native_register_natives("wasi_snapshot_preview1", native_symbols,
- n_native_symbols))
- goto fail;
- #endif
- #if WASM_ENABLE_BASE_LIB != 0
- n_native_symbols = get_base_lib_export_apis(&native_symbols);
- if (n_native_symbols > 0
- && !wasm_native_register_natives("env", native_symbols,
- n_native_symbols))
- goto fail;
- #endif
- #if WASM_ENABLE_APP_FRAMEWORK != 0
- n_native_symbols = get_ext_lib_export_apis(&native_symbols);
- if (n_native_symbols > 0
- && !wasm_native_register_natives("env", native_symbols,
- n_native_symbols))
- goto fail;
- #endif
- #if WASM_ENABLE_LIB_PTHREAD != 0
- if (!lib_pthread_init())
- goto fail;
- n_native_symbols = get_lib_pthread_export_apis(&native_symbols);
- if (n_native_symbols > 0
- && !wasm_native_register_natives("env", native_symbols,
- n_native_symbols))
- goto fail;
- #endif
- #if WASM_ENABLE_LIB_WASI_THREADS != 0
- if (!lib_wasi_threads_init())
- goto fail;
- n_native_symbols = get_lib_wasi_threads_export_apis(&native_symbols);
- if (n_native_symbols > 0
- && !wasm_native_register_natives("wasi", native_symbols,
- n_native_symbols))
- goto fail;
- #endif
- #if WASM_ENABLE_LIBC_EMCC != 0
- n_native_symbols = get_libc_emcc_export_apis(&native_symbols);
- if (n_native_symbols > 0
- && !wasm_native_register_natives("env", native_symbols,
- n_native_symbols))
- goto fail;
- #endif /* WASM_ENABLE_LIBC_EMCC */
- #if WASM_ENABLE_LIB_RATS != 0
- n_native_symbols = get_lib_rats_export_apis(&native_symbols);
- if (n_native_symbols > 0
- && !wasm_native_register_natives("env", native_symbols,
- n_native_symbols))
- goto fail;
- #endif /* WASM_ENABLE_LIB_RATS */
- #if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
- if (!wasi_nn_initialize())
- goto fail;
- n_native_symbols = get_wasi_nn_export_apis(&native_symbols);
- if (n_native_symbols > 0
- && !wasm_native_register_natives(
- #if WASM_ENABLE_WASI_EPHEMERAL_NN != 0
- "wasi_ephemeral_nn",
- #else
- "wasi_nn",
- #endif /* WASM_ENABLE_WASI_EPHEMERAL_NN != 0 */
- native_symbols, n_native_symbols))
- goto fail;
- #endif /* WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0 */
- #if WASM_ENABLE_QUICK_AOT_ENTRY != 0
- if (!quick_aot_entry_init()) {
- #if WASM_ENABLE_SPEC_TEST != 0 || WASM_ENABLE_LIBC_BUILTIN != 0 \
- || WASM_ENABLE_BASE_LIB != 0 || WASM_ENABLE_LIBC_EMCC != 0 \
- || WASM_ENABLE_LIB_RATS != 0 || WASM_ENABLE_WASI_NN != 0 \
- || WASM_ENABLE_APP_FRAMEWORK != 0 || WASM_ENABLE_LIBC_WASI != 0 \
- || WASM_ENABLE_LIB_PTHREAD != 0 || WASM_ENABLE_LIB_WASI_THREADS != 0 \
- || WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
- goto fail;
- #else
- return false;
- #endif
- }
- #endif
- return true;
- #if WASM_ENABLE_SPEC_TEST != 0 || WASM_ENABLE_LIBC_BUILTIN != 0 \
- || WASM_ENABLE_BASE_LIB != 0 || WASM_ENABLE_LIBC_EMCC != 0 \
- || WASM_ENABLE_LIB_RATS != 0 || WASM_ENABLE_WASI_NN != 0 \
- || WASM_ENABLE_APP_FRAMEWORK != 0 || WASM_ENABLE_LIBC_WASI != 0 \
- || WASM_ENABLE_LIB_PTHREAD != 0 || WASM_ENABLE_LIB_WASI_THREADS != 0 \
- || WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
- fail:
- wasm_native_destroy();
- return false;
- #endif
- }
- void
- wasm_native_destroy()
- {
- NativeSymbolsNode *node, *node_next;
- #if WASM_ENABLE_LIBC_WASI != 0
- if (g_wasi_context_key != NULL) {
- wasm_native_destroy_context_key(g_wasi_context_key);
- g_wasi_context_key = NULL;
- }
- #endif
- #if WASM_ENABLE_LIB_PTHREAD != 0
- lib_pthread_destroy();
- #endif
- #if WASM_ENABLE_LIB_WASI_THREADS != 0
- lib_wasi_threads_destroy();
- #endif
- #if WASM_ENABLE_WASI_NN != 0 || WASM_ENABLE_WASI_EPHEMERAL_NN != 0
- wasi_nn_destroy();
- #endif
- node = g_native_symbols_list;
- while (node) {
- node_next = node->next;
- wasm_runtime_free(node);
- node = node_next;
- }
- g_native_symbols_list = NULL;
- }
- #if WASM_ENABLE_QUICK_AOT_ENTRY != 0
- static void
- invoke_no_args_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *) = func_ptr;
- native_code(exec_env);
- }
- static void
- invoke_no_args_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *) = func_ptr;
- argv_ret[0] = native_code(exec_env);
- }
- static void
- invoke_no_args_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *) = func_ptr;
- int64 ret = native_code(exec_env);
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_i_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int32) = func_ptr;
- native_code(exec_env, argv[0]);
- }
- static void
- invoke_i_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int32) = func_ptr;
- argv_ret[0] = native_code(exec_env, argv[0]);
- }
- static void
- invoke_i_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int32) = func_ptr;
- int64 ret = native_code(exec_env, argv[0]);
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_I_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int64) = func_ptr;
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv));
- }
- static void
- invoke_I_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int64) = func_ptr;
- argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv));
- }
- static void
- invoke_I_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int64) = func_ptr;
- int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv));
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_ii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int32, int32) = func_ptr;
- native_code(exec_env, argv[0], argv[1]);
- }
- static void
- invoke_ii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int32, int32) = func_ptr;
- argv_ret[0] = native_code(exec_env, argv[0], argv[1]);
- }
- static void
- invoke_ii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int32, int32) = func_ptr;
- int64 ret = native_code(exec_env, argv[0], argv[1]);
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_iI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int32, int64) = func_ptr;
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1));
- }
- static void
- invoke_iI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int32, int64) = func_ptr;
- argv_ret[0] =
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1));
- }
- static void
- invoke_iI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int32, int64) = func_ptr;
- int64 ret =
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1));
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_Ii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int64, int32) = func_ptr;
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2]);
- }
- static void
- invoke_Ii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int64, int32) = func_ptr;
- argv_ret[0] =
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2]);
- }
- static void
- invoke_Ii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int64, int32) = func_ptr;
- int64 ret =
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2]);
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_II_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int64, int64) = func_ptr;
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2));
- }
- static void
- invoke_II_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int64, int64) = func_ptr;
- argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2));
- }
- static void
- invoke_II_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int64, int64) = func_ptr;
- int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2));
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_iii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int32, int32, int32) = func_ptr;
- native_code(exec_env, argv[0], argv[1], argv[2]);
- }
- static void
- invoke_iii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int32, int32, int32) = func_ptr;
- argv_ret[0] = native_code(exec_env, argv[0], argv[1], argv[2]);
- }
- static void
- invoke_iii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int32, int32, int32) = func_ptr;
- int64 ret = native_code(exec_env, argv[0], argv[1], argv[2]);
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_iiI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int32, int32, int64) = func_ptr;
- native_code(exec_env, argv[0], argv[1],
- GET_I64_FROM_ADDR((uint32 *)argv + 2));
- }
- static void
- invoke_iiI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int32, int32, int64) = func_ptr;
- argv_ret[0] = native_code(exec_env, argv[0], argv[1],
- GET_I64_FROM_ADDR((uint32 *)argv + 2));
- }
- static void
- invoke_iiI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int32, int32, int64) = func_ptr;
- int64 ret = native_code(exec_env, argv[0], argv[1],
- GET_I64_FROM_ADDR((uint32 *)argv + 2));
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_iIi_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int32, int64, int32) = func_ptr;
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
- argv[3]);
- }
- static void
- invoke_iIi_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int32, int64, int32) = func_ptr;
- argv_ret[0] = native_code(exec_env, argv[0],
- GET_I64_FROM_ADDR((uint32 *)argv + 1), argv[3]);
- }
- static void
- invoke_iIi_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int32, int64, int32) = func_ptr;
- int64 ret = native_code(exec_env, argv[0],
- GET_I64_FROM_ADDR((uint32 *)argv + 1), argv[3]);
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_iII_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int32, int64, int64) = func_ptr;
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
- GET_I64_FROM_ADDR((uint32 *)argv + 3));
- }
- static void
- invoke_iII_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int32, int64, int64) = func_ptr;
- argv_ret[0] =
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
- GET_I64_FROM_ADDR((uint32 *)argv + 3));
- }
- static void
- invoke_iII_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int32, int64, int64) = func_ptr;
- int64 ret =
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
- GET_I64_FROM_ADDR((uint32 *)argv + 3));
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_Iii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int64, int32, int32) = func_ptr;
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2], argv[3]);
- }
- static void
- invoke_Iii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int64, int32, int32) = func_ptr;
- argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- argv[2], argv[3]);
- }
- static void
- invoke_Iii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int64, int32, int32) = func_ptr;
- int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- argv[2], argv[3]);
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_IiI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int64, int32, int64) = func_ptr;
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
- GET_I64_FROM_ADDR((uint32 *)argv + 3));
- }
- static void
- invoke_IiI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int64, int32, int64) = func_ptr;
- argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- argv[2], GET_I64_FROM_ADDR((uint32 *)argv + 3));
- }
- static void
- invoke_IiI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int64, int32, int64) = func_ptr;
- int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- argv[2], GET_I64_FROM_ADDR((uint32 *)argv + 3));
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_IIi_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int64, int64, int32) = func_ptr;
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4]);
- }
- static void
- invoke_IIi_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int64, int64, int32) = func_ptr;
- argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4]);
- }
- static void
- invoke_IIi_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int64, int64, int32) = func_ptr;
- int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4]);
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_III_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int64, int64, int64) = func_ptr;
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2),
- GET_I64_FROM_ADDR((uint32 *)argv + 4));
- }
- static void
- invoke_III_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int64, int64, int64) = func_ptr;
- argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2),
- GET_I64_FROM_ADDR((uint32 *)argv + 4));
- }
- static void
- invoke_III_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int64, int64, int64) = func_ptr;
- int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2),
- GET_I64_FROM_ADDR((uint32 *)argv + 4));
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_iiii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int32, int32, int32, int32) = func_ptr;
- native_code(exec_env, argv[0], argv[1], argv[2], argv[3]);
- }
- static void
- invoke_iiii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int32, int32, int32, int32) = func_ptr;
- argv_ret[0] = native_code(exec_env, argv[0], argv[1], argv[2], argv[3]);
- }
- static void
- invoke_iiii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int32, int32, int32, int32) = func_ptr;
- int64 ret = native_code(exec_env, argv[0], argv[1], argv[2], argv[3]);
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_iiiI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int32, int32, int32, int64) = func_ptr;
- native_code(exec_env, argv[0], argv[1], argv[2],
- GET_I64_FROM_ADDR((uint32 *)argv + 3));
- }
- static void
- invoke_iiiI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int32, int32, int32, int64) = func_ptr;
- argv_ret[0] = native_code(exec_env, argv[0], argv[1], argv[2],
- GET_I64_FROM_ADDR((uint32 *)argv + 3));
- }
- static void
- invoke_iiiI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int32, int32, int32, int64) = func_ptr;
- int64 ret = native_code(exec_env, argv[0], argv[1], argv[2],
- GET_I64_FROM_ADDR((uint32 *)argv + 3));
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_iiIi_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int32, int32, int64, int32) = func_ptr;
- native_code(exec_env, argv[0], argv[1],
- GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4]);
- }
- static void
- invoke_iiIi_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int32, int32, int64, int32) = func_ptr;
- argv_ret[0] = native_code(exec_env, argv[0], argv[1],
- GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4]);
- }
- static void
- invoke_iiIi_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int32, int32, int64, int32) = func_ptr;
- int64 ret = native_code(exec_env, argv[0], argv[1],
- GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4]);
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_iiII_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int32, int32, int64, int64) = func_ptr;
- native_code(exec_env, argv[0], argv[1],
- GET_I64_FROM_ADDR((uint32 *)argv + 2),
- GET_I64_FROM_ADDR((uint32 *)argv + 4));
- }
- static void
- invoke_iiII_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int32, int32, int64, int64) = func_ptr;
- argv_ret[0] = native_code(exec_env, argv[0], argv[1],
- GET_I64_FROM_ADDR((uint32 *)argv + 2),
- GET_I64_FROM_ADDR((uint32 *)argv + 4));
- }
- static void
- invoke_iiII_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int32, int32, int64, int64) = func_ptr;
- int64 ret = native_code(exec_env, argv[0], argv[1],
- GET_I64_FROM_ADDR((uint32 *)argv + 2),
- GET_I64_FROM_ADDR((uint32 *)argv + 4));
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_iIii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int32, int64, int32, int32) = func_ptr;
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
- argv[3], argv[4]);
- }
- static void
- invoke_iIii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int32, int64, int32, int32) = func_ptr;
- argv_ret[0] =
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
- argv[3], argv[4]);
- }
- static void
- invoke_iIii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int32, int64, int32, int32) = func_ptr;
- int64 ret =
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
- argv[3], argv[4]);
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_iIiI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int32, int64, int32, int64) = func_ptr;
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
- argv[3], GET_I64_FROM_ADDR((uint32 *)argv + 4));
- }
- static void
- invoke_iIiI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int32, int64, int32, int64) = func_ptr;
- argv_ret[0] =
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
- argv[3], GET_I64_FROM_ADDR((uint32 *)argv + 4));
- }
- static void
- invoke_iIiI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int32, int64, int32, int64) = func_ptr;
- int64 ret =
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
- argv[3], GET_I64_FROM_ADDR((uint32 *)argv + 4));
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_iIIi_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int32, int64, int64, int32) = func_ptr;
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
- GET_I64_FROM_ADDR((uint32 *)argv + 3), argv[5]);
- }
- static void
- invoke_iIIi_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int32, int64, int64, int32) = func_ptr;
- argv_ret[0] =
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
- GET_I64_FROM_ADDR((uint32 *)argv + 3), argv[5]);
- }
- static void
- invoke_iIIi_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int32, int64, int64, int32) = func_ptr;
- int64 ret =
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
- GET_I64_FROM_ADDR((uint32 *)argv + 3), argv[5]);
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_iIII_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int32, int64, int64, int64) = func_ptr;
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
- GET_I64_FROM_ADDR((uint32 *)argv + 3),
- GET_I64_FROM_ADDR((uint32 *)argv + 5));
- }
- static void
- invoke_iIII_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int32, int64, int64, int64) = func_ptr;
- argv_ret[0] =
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
- GET_I64_FROM_ADDR((uint32 *)argv + 3),
- GET_I64_FROM_ADDR((uint32 *)argv + 5));
- }
- static void
- invoke_iIII_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int32, int64, int64, int64) = func_ptr;
- int64 ret =
- native_code(exec_env, argv[0], GET_I64_FROM_ADDR((uint32 *)argv + 1),
- GET_I64_FROM_ADDR((uint32 *)argv + 3),
- GET_I64_FROM_ADDR((uint32 *)argv + 5));
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_Iiii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int64, int32, int32, int32) = func_ptr;
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2], argv[3],
- argv[4]);
- }
- static void
- invoke_Iiii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int64, int32, int32, int32) = func_ptr;
- argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- argv[2], argv[3], argv[4]);
- }
- static void
- invoke_Iiii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int64, int32, int32, int32) = func_ptr;
- int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- argv[2], argv[3], argv[4]);
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_IiiI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int64, int32, int32, int64) = func_ptr;
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2], argv[3],
- GET_I64_FROM_ADDR((uint32 *)argv + 4));
- }
- static void
- invoke_IiiI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int64, int32, int32, int64) = func_ptr;
- argv_ret[0] =
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
- argv[3], GET_I64_FROM_ADDR((uint32 *)argv + 4));
- }
- static void
- invoke_IiiI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int64, int32, int32, int64) = func_ptr;
- int64 ret =
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
- argv[3], GET_I64_FROM_ADDR((uint32 *)argv + 4));
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_IiIi_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int64, int32, int64, int32) = func_ptr;
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
- GET_I64_FROM_ADDR((uint32 *)argv + 3), argv[5]);
- }
- static void
- invoke_IiIi_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int64, int32, int64, int32) = func_ptr;
- argv_ret[0] =
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
- GET_I64_FROM_ADDR((uint32 *)argv + 3), argv[5]);
- }
- static void
- invoke_IiIi_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int64, int32, int64, int32) = func_ptr;
- int64 ret =
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
- GET_I64_FROM_ADDR((uint32 *)argv + 3), argv[5]);
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_IiII_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int64, int32, int64, int64) = func_ptr;
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv), argv[2],
- GET_I64_FROM_ADDR((uint32 *)argv + 3),
- GET_I64_FROM_ADDR((uint32 *)argv + 5));
- }
- static void
- invoke_IiII_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int64, int32, int64, int64) = func_ptr;
- argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- argv[2], GET_I64_FROM_ADDR((uint32 *)argv + 3),
- GET_I64_FROM_ADDR((uint32 *)argv + 5));
- }
- static void
- invoke_IiII_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int64, int32, int64, int64) = func_ptr;
- int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- argv[2], GET_I64_FROM_ADDR((uint32 *)argv + 3),
- GET_I64_FROM_ADDR((uint32 *)argv + 5));
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_IIii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int64, int64, int32, int32) = func_ptr;
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4], argv[5]);
- }
- static void
- invoke_IIii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int64, int64, int32, int32) = func_ptr;
- argv_ret[0] =
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4], argv[5]);
- }
- static void
- invoke_IIii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int64, int64, int32, int32) = func_ptr;
- int64 ret =
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4], argv[5]);
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_IIiI_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int64, int64, int32, int64) = func_ptr;
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4],
- GET_I64_FROM_ADDR((uint32 *)argv + 5));
- }
- static void
- invoke_IIiI_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int64, int64, int32, int64) = func_ptr;
- argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4],
- GET_I64_FROM_ADDR((uint32 *)argv + 5));
- }
- static void
- invoke_IIiI_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int64, int64, int32, int64) = func_ptr;
- int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2), argv[4],
- GET_I64_FROM_ADDR((uint32 *)argv + 5));
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_IIIi_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int64, int64, int64, int32) = func_ptr;
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2),
- GET_I64_FROM_ADDR((uint32 *)argv + 4), argv[6]);
- }
- static void
- invoke_IIIi_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int64, int64, int64, int32) = func_ptr;
- argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2),
- GET_I64_FROM_ADDR((uint32 *)argv + 4), argv[6]);
- }
- static void
- invoke_IIIi_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int64, int64, int64, int32) = func_ptr;
- int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2),
- GET_I64_FROM_ADDR((uint32 *)argv + 4), argv[6]);
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_IIII_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int64, int64, int64, int64) = func_ptr;
- native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2),
- GET_I64_FROM_ADDR((uint32 *)argv + 4),
- GET_I64_FROM_ADDR((uint32 *)argv + 6));
- }
- static void
- invoke_IIII_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int64, int64, int64, int64) = func_ptr;
- argv_ret[0] = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2),
- GET_I64_FROM_ADDR((uint32 *)argv + 4),
- GET_I64_FROM_ADDR((uint32 *)argv + 6));
- }
- static void
- invoke_IIII_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int64, int64, int64, int64) = func_ptr;
- int64 ret = native_code(exec_env, GET_I64_FROM_ADDR((uint32 *)argv),
- GET_I64_FROM_ADDR((uint32 *)argv + 2),
- GET_I64_FROM_ADDR((uint32 *)argv + 4),
- GET_I64_FROM_ADDR((uint32 *)argv + 6));
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- static void
- invoke_iiiii_v(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- void (*native_code)(WASMExecEnv *, int32, int32, int32, int32, int32) =
- func_ptr;
- native_code(exec_env, argv[0], argv[1], argv[2], argv[3], argv[4]);
- }
- static void
- invoke_iiiii_i(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int32 (*native_code)(WASMExecEnv *, int32, int32, int32, int32, int32) =
- func_ptr;
- argv_ret[0] =
- native_code(exec_env, argv[0], argv[1], argv[2], argv[3], argv[4]);
- }
- static void
- invoke_iiiii_I(void *func_ptr, void *exec_env, int32 *argv, int32 *argv_ret)
- {
- int64 (*native_code)(WASMExecEnv *, int32, int32, int32, int32, int32) =
- func_ptr;
- int64 ret =
- native_code(exec_env, argv[0], argv[1], argv[2], argv[3], argv[4]);
- PUT_I64_TO_ADDR(argv_ret, ret);
- }
- typedef struct QuickAOTEntry {
- const char *signature;
- void *func_ptr;
- } QuickAOTEntry;
- /* clang-format off */
- static QuickAOTEntry quick_aot_entries[] = {
- { "()v", invoke_no_args_v },
- { "()i", invoke_no_args_i },
- { "()I", invoke_no_args_I },
- { "(i)v", invoke_i_v }, { "(i)i", invoke_i_i }, { "(i)I", invoke_i_I },
- { "(I)v", invoke_I_v }, { "(I)i", invoke_I_i }, { "(I)I", invoke_I_I },
- { "(ii)v", invoke_ii_v }, { "(ii)i", invoke_ii_i }, { "(ii)I", invoke_ii_I },
- { "(iI)v", invoke_iI_v }, { "(iI)i", invoke_iI_i }, { "(iI)I", invoke_iI_I },
- { "(Ii)v", invoke_Ii_v }, { "(Ii)i", invoke_Ii_i }, { "(Ii)I", invoke_Ii_I },
- { "(II)v", invoke_II_v }, { "(II)i", invoke_II_i }, { "(II)I", invoke_II_I },
- { "(iii)v", invoke_iii_v }, { "(iii)i", invoke_iii_i }, { "(iii)I", invoke_iii_I },
- { "(iiI)v", invoke_iiI_v }, { "(iiI)i", invoke_iiI_i }, { "(iiI)I", invoke_iiI_I },
- { "(iIi)v", invoke_iIi_v }, { "(iIi)i", invoke_iIi_i }, { "(iIi)I", invoke_iIi_I },
- { "(iII)v", invoke_iII_v }, { "(iII)i", invoke_iII_i }, { "(iII)I", invoke_iII_I },
- { "(Iii)v", invoke_Iii_v }, { "(Iii)i", invoke_Iii_i }, { "(Iii)I", invoke_Iii_I },
- { "(IiI)v", invoke_IiI_v }, { "(IiI)i", invoke_IiI_i }, { "(IiI)I", invoke_IiI_I },
- { "(IIi)v", invoke_IIi_v }, { "(IIi)i", invoke_IIi_i }, { "(IIi)I", invoke_IIi_I },
- { "(III)v", invoke_III_v }, { "(III)i", invoke_III_i }, { "(III)I", invoke_III_I },
- { "(iiii)v", invoke_iiii_v }, { "(iiii)i", invoke_iiii_i }, { "(iiii)I", invoke_iiii_I },
- { "(iiiI)v", invoke_iiiI_v }, { "(iiiI)i", invoke_iiiI_i }, { "(iiiI)I", invoke_iiiI_I },
- { "(iiIi)v", invoke_iiIi_v }, { "(iiIi)i", invoke_iiIi_i }, { "(iiIi)I", invoke_iiIi_I },
- { "(iiII)v", invoke_iiII_v }, { "(iiII)i", invoke_iiII_i }, { "(iiII)I", invoke_iiII_I },
- { "(iIii)v", invoke_iIii_v }, { "(iIii)i", invoke_iIii_i }, { "(iIii)I", invoke_iIii_I },
- { "(iIiI)v", invoke_iIiI_v }, { "(iIiI)i", invoke_iIiI_i }, { "(iIiI)I", invoke_iIiI_I },
- { "(iIIi)v", invoke_iIIi_v }, { "(iIIi)i", invoke_iIIi_i }, { "(iIIi)I", invoke_iIIi_I },
- { "(iIII)v", invoke_iIII_v }, { "(iIII)i", invoke_iIII_i }, { "(iIII)I", invoke_iIII_I },
- { "(Iiii)v", invoke_Iiii_v }, { "(Iiii)i", invoke_Iiii_i }, { "(Iiii)I", invoke_Iiii_I },
- { "(IiiI)v", invoke_IiiI_v }, { "(IiiI)i", invoke_IiiI_i }, { "(IiiI)I", invoke_IiiI_I },
- { "(IiIi)v", invoke_IiIi_v }, { "(IiIi)i", invoke_IiIi_i }, { "(IiIi)I", invoke_IiIi_I },
- { "(IiII)v", invoke_IiII_v }, { "(IiII)i", invoke_IiII_i }, { "(IiII)I", invoke_IiII_I },
- { "(IIii)v", invoke_IIii_v }, { "(IIii)i", invoke_IIii_i }, { "(IIii)I", invoke_IIii_I },
- { "(IIiI)v", invoke_IIiI_v }, { "(IIiI)i", invoke_IIiI_i }, { "(IIiI)I", invoke_IIiI_I },
- { "(IIIi)v", invoke_IIIi_v }, { "(IIIi)i", invoke_IIIi_i }, { "(IIIi)I", invoke_IIIi_I },
- { "(IIII)v", invoke_IIII_v }, { "(IIII)i", invoke_IIII_i }, { "(IIII)I", invoke_IIII_I },
- { "(iiiii)v", invoke_iiiii_v }, { "(iiiii)i", invoke_iiiii_i }, { "(iiiii)I", invoke_iiiii_I },
- };
- /* clang-format on */
- static int
- quick_aot_entry_cmp(const void *quick_aot_entry1, const void *quick_aot_entry2)
- {
- return strcmp(((const QuickAOTEntry *)quick_aot_entry1)->signature,
- ((const QuickAOTEntry *)quick_aot_entry2)->signature);
- }
- static bool
- quick_aot_entry_init(void)
- {
- qsort(quick_aot_entries, sizeof(quick_aot_entries) / sizeof(QuickAOTEntry),
- sizeof(QuickAOTEntry), quick_aot_entry_cmp);
- return true;
- }
- void *
- wasm_native_lookup_quick_aot_entry(const WASMFuncType *func_type)
- {
- char signature[16] = { 0 };
- uint32 param_count = func_type->param_count;
- uint32 result_count = func_type->result_count, i, j = 0;
- const uint8 *types = func_type->types;
- QuickAOTEntry *quick_aot_entry, key = { 0 };
- if (param_count > 5 || result_count > 1)
- return NULL;
- signature[j++] = '(';
- for (i = 0; i < param_count; i++) {
- if (types[i] == VALUE_TYPE_I32)
- signature[j++] = 'i';
- else if (types[i] == VALUE_TYPE_I64)
- signature[j++] = 'I';
- else
- return NULL;
- }
- signature[j++] = ')';
- if (result_count == 0) {
- signature[j++] = 'v';
- }
- else {
- if (types[i] == VALUE_TYPE_I32)
- signature[j++] = 'i';
- else if (types[i] == VALUE_TYPE_I64)
- signature[j++] = 'I';
- else
- return NULL;
- }
- key.signature = signature;
- if ((quick_aot_entry =
- bsearch(&key, quick_aot_entries,
- sizeof(quick_aot_entries) / sizeof(QuickAOTEntry),
- sizeof(QuickAOTEntry), quick_aot_entry_cmp))) {
- return quick_aot_entry->func_ptr;
- }
- return NULL;
- }
- #endif /* end of WASM_ENABLE_QUICK_AOT_ENTRY != 0 */
|