Skip to content

Generic exceptions handling callback included #4271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ wasm_runtime_destroy_registered_module_list(void);

#define E_TYPE_XIP 4

static generic_error_callback_t generic_error_cb;
static void *generic_error_user_data;

static uint8
val_type_to_val_kind(uint8 value_type);

Expand Down Expand Up @@ -3016,6 +3019,9 @@ wasm_set_exception_local(WASMModuleInstance *module_inst, const char *exception)
module_inst->cur_exception[0] = '\0';
}
exception_unlock(module_inst);
if (generic_error_cb)
generic_error_cb((WASMModuleInstanceCommon *)module_inst,
((AOTModuleInstance *)module_inst)->cur_exec_env, "");
}

void
Expand Down Expand Up @@ -7870,3 +7876,11 @@ wasm_runtime_is_underlying_binary_freeable(WASMModuleCommon *const module)

return true;
}

void
wasm_runtime_set_generic_error_callback(const generic_error_callback_t callback,
void *user_data)
{
generic_error_cb = callback;
generic_error_user_data = user_data;
}
7 changes: 7 additions & 0 deletions core/iwasm/include/wasm_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -2102,13 +2102,20 @@ typedef void (*enlarge_memory_error_callback_t)(
uint32_t memory_index, enlarge_memory_error_reason_t failure_reason,
wasm_module_inst_t instance, wasm_exec_env_t exec_env, void *user_data);

typedef void (*generic_error_callback_t)(wasm_module_inst_t instance,
wasm_exec_env_t exec_env,
void *user_data);
/**
* Setup callback invoked when memory.grow fails
*/
WASM_RUNTIME_API_EXTERN void
wasm_runtime_set_enlarge_mem_error_callback(
const enlarge_memory_error_callback_t callback, void *user_data);

WASM_RUNTIME_API_EXTERN void
wasm_runtime_set_generic_error_callback(const generic_error_callback_t callback,
void *user_data);

/*
* module instance context APIs
* wasm_runtime_create_context_key
Expand Down
Loading