Remove the binding between current thread and module instance and bugs fix (#131)
Remove wasm_export_api.h that may confuse Implement wasm_runtime_validate_app_str_addr() Fix bugs of loader and pass more spec cases Signed-off-by: Weining Lu <weining.x.lu@intel.com>
This commit is contained in:
@ -246,11 +246,13 @@ static int get_module_type(char *kv_str)
|
||||
|
||||
/* Queue callback of App Manager */
|
||||
|
||||
static void app_manager_queue_callback(void *message)
|
||||
static void app_manager_queue_callback(void *message, void *arg)
|
||||
{
|
||||
request_t *request = (request_t *) bh_message_payload((bh_message_t)message);
|
||||
int mid = request->mid, module_type, offset;
|
||||
|
||||
(void)arg;
|
||||
|
||||
if ((offset = check_url_start(request->url, strlen(request->url), "/applet"))
|
||||
> 0) {
|
||||
module_type = get_module_type(request->url + offset);
|
||||
@ -376,7 +378,7 @@ void app_manager_startup(host_interface *interface)
|
||||
app_manager_printf("App Manager started.\n");
|
||||
|
||||
/* Enter loop run */
|
||||
bh_queue_enter_loop_run(g_app_mgr_queue, app_manager_queue_callback);
|
||||
bh_queue_enter_loop_run(g_app_mgr_queue, app_manager_queue_callback, NULL);
|
||||
|
||||
fail2: module_data_list_destroy();
|
||||
|
||||
|
||||
@ -65,7 +65,7 @@ void
|
||||
module_data_list_destroy();
|
||||
|
||||
bool
|
||||
app_manager_is_interrupting_module(uint32 module_type);
|
||||
app_manager_is_interrupting_module(uint32 module_type, void *module_inst);
|
||||
|
||||
void release_module(module_data *m_data);
|
||||
|
||||
|
||||
@ -130,35 +130,35 @@ module_data_list_lookup_id(unsigned int module_id)
|
||||
}
|
||||
|
||||
module_data *
|
||||
app_manager_get_module_data(uint32 module_type)
|
||||
app_manager_get_module_data(uint32 module_type, void *module_inst)
|
||||
{
|
||||
if (g_module_interfaces[module_type]
|
||||
&& g_module_interfaces[module_type]->module_get_module_data)
|
||||
return g_module_interfaces[module_type]->module_get_module_data();
|
||||
return g_module_interfaces[module_type]->module_get_module_data(module_inst);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void*
|
||||
app_manager_get_module_queue(uint32 module_type)
|
||||
app_manager_get_module_queue(uint32 module_type, void *module_inst)
|
||||
{
|
||||
return app_manager_get_module_data(module_type)->queue;
|
||||
return app_manager_get_module_data(module_type, module_inst)->queue;
|
||||
}
|
||||
|
||||
const char*
|
||||
app_manager_get_module_name(uint32 module_type)
|
||||
app_manager_get_module_name(uint32 module_type, void *module_inst)
|
||||
{
|
||||
return app_manager_get_module_data(module_type)->module_name;
|
||||
return app_manager_get_module_data(module_type, module_inst)->module_name;
|
||||
}
|
||||
|
||||
unsigned int app_manager_get_module_id(uint32 module_type)
|
||||
unsigned int app_manager_get_module_id(uint32 module_type, void *module_inst)
|
||||
{
|
||||
return app_manager_get_module_data(module_type)->id;
|
||||
return app_manager_get_module_data(module_type, module_inst)->id;
|
||||
}
|
||||
|
||||
void*
|
||||
app_manager_get_module_heap(uint32 module_type)
|
||||
app_manager_get_module_heap(uint32 module_type, void *module_inst)
|
||||
{
|
||||
return app_manager_get_module_data(module_type)->heap;
|
||||
return app_manager_get_module_data(module_type, module_inst)->heap;
|
||||
}
|
||||
|
||||
module_data*
|
||||
@ -179,9 +179,9 @@ void app_manager_del_module_data(module_data *m_data)
|
||||
release_module(m_data);
|
||||
}
|
||||
|
||||
bool app_manager_is_interrupting_module(uint32 module_type)
|
||||
bool app_manager_is_interrupting_module(uint32 module_type, void *module_inst)
|
||||
{
|
||||
return app_manager_get_module_data(module_type)->wd_timer.is_interrupting;
|
||||
return app_manager_get_module_data(module_type, module_inst)->wd_timer.is_interrupting;
|
||||
}
|
||||
|
||||
extern void destroy_module_timer_ctx(unsigned int module_id);
|
||||
|
||||
@ -81,7 +81,7 @@ static bool wasm_app_module_install(request_t *msg);
|
||||
static bool wasm_app_module_uninstall(request_t *msg);
|
||||
static void wasm_app_module_watchdog_kill(module_data *module_data);
|
||||
static bool wasm_app_module_handle_host_url(void *queue_msg);
|
||||
static module_data *wasm_app_module_get_module_data(void);
|
||||
static module_data *wasm_app_module_get_module_data(void *inst);
|
||||
static bool
|
||||
wasm_app_module_on_install_request_byte_arrive(uint8 ch, int request_total_size,
|
||||
int *received_size);
|
||||
@ -110,14 +110,13 @@ static unsigned align_uint(unsigned v, unsigned b)
|
||||
return (v + m) & ~m;
|
||||
}
|
||||
|
||||
static void app_instance_queue_callback(void *queue_msg)
|
||||
static void app_instance_queue_callback(void *queue_msg, void *arg)
|
||||
{
|
||||
uint32 argv[2];
|
||||
wasm_function_inst_t func_onRequest, func_onTimer;
|
||||
|
||||
module_data *m_data = app_manager_get_module_data(Module_WASM_App);
|
||||
wasm_data *wasm_app_data = (wasm_data*) m_data->internal_data;
|
||||
wasm_module_inst_t inst = wasm_app_data->wasm_module_inst;
|
||||
wasm_module_inst_t inst = (wasm_module_inst_t)arg;
|
||||
module_data *m_data = app_manager_get_module_data(Module_WASM_App, inst);
|
||||
int message_type = bh_message_type(queue_msg);
|
||||
|
||||
switch (message_type) {
|
||||
@ -262,17 +261,16 @@ wasm_app_routine(void *arg)
|
||||
wasm_module_inst_t inst = wasm_app_data->wasm_module_inst;
|
||||
korp_tid thread = wasm_app_data->thread_id;
|
||||
|
||||
/* attach newly created thread to the VM managed instance */
|
||||
if (!wasm_runtime_attach_current_thread(inst, m_data)) {
|
||||
goto fail1;
|
||||
}
|
||||
/* Set m_data to the VM managed instance's custom data */
|
||||
wasm_runtime_set_custom_data(inst, m_data);
|
||||
|
||||
app_manager_printf("WASM app '%s' started\n", m_data->module_name);
|
||||
|
||||
/* Call app's onInit() method */
|
||||
func_onInit = wasm_runtime_lookup_function(inst, "_on_init", "()");
|
||||
if (!func_onInit) {
|
||||
app_manager_printf("Cannot find function on_init().\n");
|
||||
goto fail2;
|
||||
goto fail1;
|
||||
}
|
||||
|
||||
if (!wasm_runtime_call_wasm(inst, NULL, func_onInit, 0, NULL)) {
|
||||
@ -281,23 +279,21 @@ wasm_app_routine(void *arg)
|
||||
wasm_runtime_clear_exception(inst);
|
||||
/* call on_destroy() in case some resources are opened in on_init()
|
||||
* and then exception thrown */
|
||||
goto fail3;
|
||||
goto fail2;
|
||||
}
|
||||
|
||||
/* Enter queue loop run to receive and process applet queue message */
|
||||
bh_queue_enter_loop_run(m_data->queue, app_instance_queue_callback);
|
||||
bh_queue_enter_loop_run(m_data->queue, app_instance_queue_callback, inst);
|
||||
|
||||
app_manager_printf("App instance main thread exit.\n");
|
||||
|
||||
fail3:
|
||||
fail2:
|
||||
/* Call WASM app onDestroy() method if there is */
|
||||
func_onDestroy = wasm_runtime_lookup_function(inst, "_on_destroy", "()");
|
||||
if (func_onDestroy)
|
||||
wasm_runtime_call_wasm(inst, NULL, func_onDestroy, 0, NULL);
|
||||
|
||||
fail2: wasm_runtime_detach_current_thread(inst);
|
||||
|
||||
fail1:
|
||||
fail1:
|
||||
vm_thread_detach(thread);
|
||||
vm_thread_exit(NULL);
|
||||
|
||||
@ -548,8 +544,7 @@ static bool wasm_app_module_install(request_t * msg)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* create a thread. This thread may not dedicate for this WASM app.
|
||||
WASM app instance needs to attach to one thread */
|
||||
/* Create WASM app thread. */
|
||||
if (vm_thread_create(&wasm_app_data->thread_id, wasm_app_routine,
|
||||
(void*) m_data, APP_THREAD_STACK_SIZE_DEFAULT) != 0) {
|
||||
module_data_list_remove(m_data);
|
||||
@ -648,9 +643,10 @@ static bool wasm_app_module_handle_host_url(void *queue_msg)
|
||||
}
|
||||
|
||||
static module_data*
|
||||
wasm_app_module_get_module_data(void)
|
||||
wasm_app_module_get_module_data(void *inst)
|
||||
{
|
||||
return wasm_runtime_get_current_thread_data();
|
||||
wasm_module_inst_t module_inst = (wasm_module_inst_t)inst;
|
||||
return (module_data *)wasm_runtime_get_custom_data(module_inst);
|
||||
}
|
||||
|
||||
static void wasm_app_module_watchdog_kill(module_data *m_data)
|
||||
|
||||
@ -46,8 +46,9 @@ static bool wasm_lib_module_handle_host_url(void *queue_msg)
|
||||
}
|
||||
|
||||
static module_data*
|
||||
wasm_lib_module_get_module_data(void)
|
||||
wasm_lib_module_get_module_data(void *inst)
|
||||
{
|
||||
(void) inst;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -105,7 +105,7 @@ typedef bool (*module_install_func)(request_t *msg);
|
||||
typedef bool (*module_uninstall_func)(request_t *msg);
|
||||
typedef void (*module_watchdog_kill_func)(module_data *module_data);
|
||||
typedef bool (*module_handle_host_url_func)(void *queue_msg);
|
||||
typedef module_data *(*module_get_module_data_func)(void);
|
||||
typedef module_data *(*module_get_module_data_func)(void *inst);
|
||||
|
||||
/**
|
||||
* @typedef module_on_install_request_byte_arrive_func
|
||||
@ -194,24 +194,24 @@ app_manager_startup(host_interface *interface);
|
||||
|
||||
/* Get queue of current applet */
|
||||
void *
|
||||
app_manager_get_module_queue(uint32 module_type);
|
||||
app_manager_get_module_queue(uint32 module_type, void *module_inst);
|
||||
|
||||
/* Get applet name of current applet */
|
||||
const char *
|
||||
app_manager_get_module_name(uint32 module_type);
|
||||
app_manager_get_module_name(uint32 module_type, void *module_inst);
|
||||
|
||||
/* Get heap of current applet */
|
||||
void *
|
||||
app_manager_get_module_heap(uint32 module_type);
|
||||
app_manager_get_module_heap(uint32 module_type, void *module_inst);
|
||||
|
||||
void*
|
||||
get_app_manager_queue();
|
||||
|
||||
module_data*
|
||||
app_manager_get_module_data(uint32 module_type);
|
||||
app_manager_get_module_data(uint32 module_type, void *module_inst);
|
||||
|
||||
unsigned int
|
||||
app_manager_get_module_id(uint32 module_type);
|
||||
app_manager_get_module_id(uint32 module_type, void *module_inst);
|
||||
|
||||
module_data*
|
||||
app_manager_lookup_module_data(const char *name);
|
||||
|
||||
Reference in New Issue
Block a user