Implement register/call native API with raw (unextracted) arguments (#222)
This commit is contained in:
@ -137,8 +137,11 @@ typedef struct WASMFunctionImport {
|
||||
WASMType *func_type;
|
||||
/* function pointer after linked */
|
||||
void *func_ptr_linked;
|
||||
/* signature from registered native symbols */
|
||||
/* signature from registered native symbols */
|
||||
const char *signature;
|
||||
/* attachment */
|
||||
void *attachment;
|
||||
bool call_conv_raw;
|
||||
} WASMFunctionImport;
|
||||
|
||||
typedef struct WASMGlobalImport {
|
||||
|
||||
@ -748,9 +748,18 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
|
||||
return;
|
||||
}
|
||||
|
||||
ret = wasm_runtime_invoke_native(exec_env, func_import->func_ptr_linked,
|
||||
func_import->func_type, func_import->signature,
|
||||
frame->lp, cur_func->param_cell_num, argv_ret);
|
||||
if (!func_import->call_conv_raw) {
|
||||
ret = wasm_runtime_invoke_native(exec_env, func_import->func_ptr_linked,
|
||||
func_import->func_type, func_import->signature,
|
||||
func_import->attachment,
|
||||
frame->lp, cur_func->param_cell_num, argv_ret);
|
||||
}
|
||||
else {
|
||||
ret = wasm_runtime_invoke_native_raw(exec_env, func_import->func_ptr_linked,
|
||||
func_import->func_type, func_import->signature,
|
||||
func_import->attachment,
|
||||
frame->lp, cur_func->param_cell_num, argv_ret);
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
return;
|
||||
|
||||
@ -651,6 +651,7 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
|
||||
WASMFunctionInstance *cur_func,
|
||||
WASMInterpFrame *prev_frame)
|
||||
{
|
||||
WASMFunctionImport *func_import = cur_func->u.func_import;
|
||||
unsigned local_cell_num = 2;
|
||||
WASMInterpFrame *frame;
|
||||
uint32 argv_ret[2];
|
||||
@ -667,20 +668,27 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
|
||||
|
||||
wasm_exec_env_set_cur_frame(exec_env, frame);
|
||||
|
||||
if (!cur_func->u.func_import->func_ptr_linked) {
|
||||
if (!func_import->func_ptr_linked) {
|
||||
char buf[128];
|
||||
snprintf(buf,
|
||||
sizeof(buf), "fail to call unlinked import function (%s, %s)",
|
||||
cur_func->u.func_import->module_name,
|
||||
cur_func->u.func_import->field_name);
|
||||
func_import->module_name, func_import->field_name);
|
||||
wasm_set_exception((WASMModuleInstance*)module_inst, buf);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = wasm_runtime_invoke_native(exec_env, cur_func->u.func_import->func_ptr_linked,
|
||||
cur_func->u.func_import->func_type,
|
||||
cur_func->u.func_import->signature,
|
||||
frame->lp, cur_func->param_cell_num, argv_ret);
|
||||
if (!func_import->call_conv_raw) {
|
||||
ret = wasm_runtime_invoke_native(exec_env, func_import->func_ptr_linked,
|
||||
func_import->func_type, func_import->signature,
|
||||
func_import->attachment,
|
||||
frame->lp, cur_func->param_cell_num, argv_ret);
|
||||
}
|
||||
else {
|
||||
ret = wasm_runtime_invoke_native_raw(exec_env, func_import->func_ptr_linked,
|
||||
func_import->func_type, func_import->signature,
|
||||
func_import->attachment,
|
||||
frame->lp, cur_func->param_cell_num, argv_ret);
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
return;
|
||||
|
||||
@ -721,7 +721,9 @@ load_import_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
||||
if (!(import->u.function.func_ptr_linked =
|
||||
wasm_native_resolve_symbol(module_name, field_name,
|
||||
import->u.function.func_type,
|
||||
&import->u.function.signature))) {
|
||||
&import->u.function.signature,
|
||||
&import->u.function.attachment,
|
||||
&import->u.function.call_conv_raw))) {
|
||||
#if WASM_ENABLE_WAMR_COMPILER == 0 /* Output warning except running aot compiler */
|
||||
LOG_WARNING("warning: fail to link import function (%s, %s)\n",
|
||||
module_name, field_name);
|
||||
|
||||
Reference in New Issue
Block a user