Add parameter module inst for native wrapper functions (#117)

And add asm code of em64/arm/mips version to call native wrapper functions;
Fix some issues of calling wrapper functions;
This commit is contained in:
wenyongh
2019-09-10 10:23:46 +08:00
committed by GitHub
parent 2294f52e3a
commit 26149021ff
58 changed files with 1287 additions and 494 deletions

View File

@ -26,19 +26,17 @@
#endif
static uint64
wasm_runtime_get_current_module_inst_wrapper()
wasm_runtime_get_current_module_inst_wrapper(wasm_module_inst_t module_inst)
{
return (uint64)(uintptr_t)
wasm_runtime_get_current_module_inst();
return (uint64)(uintptr_t)module_inst;
}
static bool
wasm_runtime_validate_app_addr_wrapper(uint32 inst_part0, uint32 inst_part1,
wasm_runtime_validate_app_addr_wrapper(wasm_module_inst_t module_inst,
uint32 inst_part0, uint32 inst_part1,
int32 app_offset, uint32 size)
{
bool ret;
wasm_module_inst_t module_inst =
wasm_runtime_get_current_module_inst();
union { uint64 u64; uint32 parts[2]; } inst;
inst.parts[0] = inst_part0;
@ -56,14 +54,13 @@ wasm_runtime_validate_app_addr_wrapper(uint32 inst_part0, uint32 inst_part1,
}
static bool
wasm_runtime_validate_native_addr_wrapper(uint32 inst_part0, uint32 inst_part1,
wasm_runtime_validate_native_addr_wrapper(wasm_module_inst_t module_inst,
uint32 inst_part0, uint32 inst_part1,
uint32 native_ptr_part0,
uint32 native_ptr_part1,
uint32 size)
{
bool ret;
wasm_module_inst_t module_inst =
wasm_runtime_get_current_module_inst();
union { uint64 u64; uint32 parts[2]; } inst;
union { uint64 u64; uint32 parts[2]; } native_ptr;
@ -86,11 +83,10 @@ wasm_runtime_validate_native_addr_wrapper(uint32 inst_part0, uint32 inst_part1,
}
static uint64
wasm_runtime_addr_app_to_native_wrapper(uint32 inst_part0, uint32 inst_part1,
wasm_runtime_addr_app_to_native_wrapper(wasm_module_inst_t module_inst,
uint32 inst_part0, uint32 inst_part1,
int32 app_offset)
{
wasm_module_inst_t module_inst =
wasm_runtime_get_current_module_inst();
union { uint64 u64; uint32 parts[2]; } inst;
inst.parts[0] = inst_part0;
@ -105,12 +101,11 @@ wasm_runtime_addr_app_to_native_wrapper(uint32 inst_part0, uint32 inst_part1,
}
static int32
wasm_runtime_addr_native_to_app_wrapper(uint32 inst_part0, uint32 inst_part1,
wasm_runtime_addr_native_to_app_wrapper(wasm_module_inst_t module_inst,
uint32 inst_part0, uint32 inst_part1,
uint32 native_ptr_part0,
uint32 native_ptr_part1)
{
wasm_module_inst_t module_inst =
wasm_runtime_get_current_module_inst();
union { uint64 u64; uint32 parts[2]; } inst;
union { uint64 u64; uint32 parts[2]; } native_ptr;

View File

@ -14,16 +14,16 @@
* limitations under the License.
*/
#include "native_interface.h"
#include "app_manager_export.h"
#include "coap_ext.h"
#include "wasm_export.h"
extern void module_request_handler(request_t *request, void *user_data);
bool wasm_response_send(int32 buffer_offset, int size)
bool
wasm_response_send(wasm_module_inst_t module_inst,
int32 buffer_offset, int size)
{
wasm_module_inst_t module_inst = get_module_inst();
char *buffer = NULL;
if (!validate_app_addr(buffer_offset, size))
@ -45,9 +45,9 @@ bool wasm_response_send(int32 buffer_offset, int size)
return false;
}
void wasm_register_resource(int32 url_offset)
void
wasm_register_resource(wasm_module_inst_t module_inst, int32 url_offset)
{
wasm_module_inst_t module_inst = get_module_inst();
char *url = NULL;
if (!validate_app_addr(url_offset, 1))
@ -61,9 +61,10 @@ void wasm_register_resource(int32 url_offset)
}
}
void wasm_post_request(int32 buffer_offset, int size)
void
wasm_post_request(wasm_module_inst_t module_inst,
int32 buffer_offset, int size)
{
wasm_module_inst_t module_inst = get_module_inst();
char *buffer = NULL;
if (!validate_app_addr(buffer_offset, size))
@ -92,9 +93,9 @@ void wasm_post_request(int32 buffer_offset, int size)
}
}
void wasm_sub_event(int32 url_offset)
void
wasm_sub_event(wasm_module_inst_t module_inst, int32 url_offset)
{
wasm_module_inst_t module_inst = get_module_inst();
char *url = NULL;
if (!validate_app_addr(url_offset, 1))

View File

@ -17,7 +17,6 @@
#ifndef LIB_BASE_RUNTIME_LIB_H_
#define LIB_BASE_RUNTIME_LIB_H_
#include "native_interface.h"
#include "runtime_timer.h"

View File

@ -37,7 +37,7 @@ void wasm_timer_callback(timer_id_t id, unsigned int mod_id)
// !!! the length parameter must be 0, so the receiver will
// not free the payload pointer.
bh_post_msg(module->queue, TIMER_EVENT_WASM, (char *) id, 0);
bh_post_msg(module->queue, TIMER_EVENT_WASM, (char *)(uintptr_t)id, 0);
}
///
@ -149,30 +149,37 @@ timer_ctx_t get_wasm_timer_ctx()
return m->timer_ctx;
}
timer_id_t wasm_create_timer(int interval, bool is_period, bool auto_start)
timer_id_t
wasm_create_timer(wasm_module_inst_t module_inst,
int interval, bool is_period, bool auto_start)
{
return sys_create_timer(get_wasm_timer_ctx(), interval, is_period,
auto_start);
}
void wasm_timer_destory(timer_id_t timer_id)
void
wasm_timer_destory(wasm_module_inst_t module_inst, timer_id_t timer_id)
{
sys_timer_destory(get_wasm_timer_ctx(), timer_id);
}
void wasm_timer_cancel(timer_id_t timer_id)
void
wasm_timer_cancel(wasm_module_inst_t module_inst, timer_id_t timer_id)
{
sys_timer_cancel(get_wasm_timer_ctx(), timer_id);
}
void wasm_timer_restart(timer_id_t timer_id, int interval)
void
wasm_timer_restart(wasm_module_inst_t module_inst,
timer_id_t timer_id, int interval)
{
sys_timer_restart(get_wasm_timer_ctx(), timer_id, interval);
}
extern uint32 get_sys_tick_ms();
uint32 wasm_get_sys_tick_ms(void)
uint32
wasm_get_sys_tick_ms(wasm_module_inst_t module_inst)
{
return (uint32) bh_get_tick_ms();
}