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:
@ -18,132 +18,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "lib_export.h"
|
||||
#include "bh_platform.h"
|
||||
#include "wasm_export.h"
|
||||
|
||||
#ifdef WASM_ENABLE_BASE_LIB
|
||||
#include "base_lib_export.h"
|
||||
#endif
|
||||
|
||||
static void
|
||||
wasm_runtime_get_current_module_inst1(wasm_module_inst_t module_inst,
|
||||
int32 inst_offset)
|
||||
{
|
||||
uint64 *p_module_inst;
|
||||
|
||||
if (!wasm_runtime_validate_app_addr(module_inst, inst_offset, 8))
|
||||
return;
|
||||
|
||||
p_module_inst =
|
||||
wasm_runtime_addr_app_to_native(module_inst, inst_offset);
|
||||
*p_module_inst = (uint64)(uintptr_t)module_inst;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
wasm_runtime_validate_app_addr1(wasm_module_inst_t module_inst,
|
||||
uint32 inst_part0, uint32 inst_part1,
|
||||
int32 app_offset, uint32 size)
|
||||
{
|
||||
bool ret;
|
||||
union { uint64 u64; uint32 parts[2]; } inst;
|
||||
|
||||
inst.parts[0] = inst_part0;
|
||||
inst.parts[1] = inst_part1;
|
||||
|
||||
if (inst.u64 != (uint64)(uintptr_t)module_inst) {
|
||||
bh_printf("Invalid module instance\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = wasm_runtime_validate_app_addr(module_inst, app_offset, size);
|
||||
if (!ret)
|
||||
wasm_runtime_clear_exception(module_inst);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool
|
||||
wasm_runtime_validate_native_addr1(wasm_module_inst_t module_inst,
|
||||
uint32 inst_part0, uint32 inst_part1,
|
||||
uint32 native_ptr_part0,
|
||||
uint32 native_ptr_part1,
|
||||
uint32 size)
|
||||
{
|
||||
bool ret;
|
||||
union { uint64 u64; uint32 parts[2]; } inst;
|
||||
union { uint64 u64; uint32 parts[2]; } native_ptr;
|
||||
|
||||
inst.parts[0] = inst_part0;
|
||||
inst.parts[1] = inst_part1;
|
||||
|
||||
if (inst.u64 != (uint64)(uintptr_t)module_inst) {
|
||||
printf("Invalid module instance\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
native_ptr.parts[0] = native_ptr_part0;
|
||||
native_ptr.parts[1] = native_ptr_part1;
|
||||
ret = wasm_runtime_validate_native_addr(module_inst,
|
||||
(void*)(uintptr_t)native_ptr.u64,
|
||||
size);
|
||||
if (!ret)
|
||||
wasm_runtime_clear_exception(module_inst);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool
|
||||
wasm_runtime_addr_app_to_native1(wasm_module_inst_t module_inst,
|
||||
uint32 inst_part0, uint32 inst_part1,
|
||||
int32 app_offset,
|
||||
int32 native_ptr_offset)
|
||||
|
||||
{
|
||||
union { uint64 u64; uint32 parts[2]; } inst;
|
||||
uint64 *p_native_ptr;
|
||||
|
||||
inst.parts[0] = inst_part0;
|
||||
inst.parts[1] = inst_part1;
|
||||
|
||||
if (inst.u64 != (uint64)(uintptr_t)module_inst) {
|
||||
printf("Invalid module instance\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!wasm_runtime_validate_app_addr(module_inst, native_ptr_offset, 8)) {
|
||||
wasm_runtime_clear_exception(module_inst);
|
||||
return false;
|
||||
}
|
||||
|
||||
p_native_ptr =
|
||||
wasm_runtime_addr_app_to_native(module_inst, native_ptr_offset);
|
||||
*p_native_ptr = (uint64)(uintptr_t)
|
||||
wasm_runtime_addr_app_to_native(module_inst, app_offset);
|
||||
return true;
|
||||
}
|
||||
|
||||
static int32
|
||||
wasm_runtime_addr_native_to_app1(wasm_module_inst_t module_inst,
|
||||
uint32 inst_part0, uint32 inst_part1,
|
||||
uint32 native_ptr_part0,
|
||||
uint32 native_ptr_part1)
|
||||
{
|
||||
union { uint64 u64; uint32 parts[2]; } inst;
|
||||
union { uint64 u64; uint32 parts[2]; } native_ptr;
|
||||
|
||||
inst.parts[0] = inst_part0;
|
||||
inst.parts[1] = inst_part1;
|
||||
|
||||
if (inst.u64 != (uint64)(uintptr_t)module_inst) {
|
||||
printf("Invalid module instance\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
native_ptr.parts[0] = native_ptr_part0;
|
||||
native_ptr.parts[1] = native_ptr_part1;
|
||||
return wasm_runtime_addr_native_to_app(module_inst,
|
||||
(void*)(uintptr_t)native_ptr.u64);
|
||||
}
|
||||
|
||||
static NativeSymbol extended_native_symbol_defs[] = {
|
||||
/* TODO: use macro EXPORT_WASM_API() or EXPORT_WASM_API2() to
|
||||
add functions to register. */
|
||||
@ -159,11 +38,6 @@ static NativeSymbol extended_native_symbol_defs[] = {
|
||||
EXPORT_WASM_API(wasm_timer_restart),
|
||||
EXPORT_WASM_API(wasm_get_sys_tick_ms),
|
||||
#endif
|
||||
EXPORT_WASM_API(wasm_runtime_get_current_module_inst1),
|
||||
EXPORT_WASM_API(wasm_runtime_validate_app_addr1),
|
||||
EXPORT_WASM_API(wasm_runtime_validate_native_addr1),
|
||||
EXPORT_WASM_API(wasm_runtime_addr_app_to_native1),
|
||||
EXPORT_WASM_API(wasm_runtime_addr_native_to_app1),
|
||||
};
|
||||
|
||||
int get_base_lib_export_apis(NativeSymbol **p_base_lib_apis)
|
||||
|
||||
@ -50,13 +50,14 @@ wasm_register_resource(wasm_module_inst_t module_inst, int32 url_offset)
|
||||
{
|
||||
char *url = NULL;
|
||||
|
||||
if (!validate_app_addr(url_offset, 1))
|
||||
if (!validate_app_str_addr(url_offset))
|
||||
return;
|
||||
|
||||
url = addr_app_to_native(url_offset);
|
||||
|
||||
if (url != NULL) {
|
||||
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App);
|
||||
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App,
|
||||
module_inst);
|
||||
am_register_resource(url, module_request_handler, mod_id);
|
||||
}
|
||||
}
|
||||
@ -81,7 +82,8 @@ wasm_post_request(wasm_module_inst_t module_inst,
|
||||
// TODO: add permission check, ensure app can't do harm
|
||||
|
||||
// set sender to help dispatch the response to the sender ap
|
||||
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App);
|
||||
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App,
|
||||
module_inst);
|
||||
req->sender = mod_id;
|
||||
|
||||
if (req->action == COAP_EVENT) {
|
||||
@ -98,13 +100,14 @@ wasm_sub_event(wasm_module_inst_t module_inst, int32 url_offset)
|
||||
{
|
||||
char *url = NULL;
|
||||
|
||||
if (!validate_app_addr(url_offset, 1))
|
||||
if (!validate_app_str_addr(url_offset))
|
||||
return;
|
||||
|
||||
url = addr_app_to_native(url_offset);
|
||||
|
||||
if (url != NULL) {
|
||||
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App);
|
||||
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App,
|
||||
module_inst);
|
||||
|
||||
am_register_event(url, mod_id);
|
||||
}
|
||||
|
||||
@ -141,9 +141,10 @@ void destroy_module_timer_ctx(unsigned int module_id)
|
||||
vm_mutex_unlock(&g_timer_ctx_list_mutex);
|
||||
}
|
||||
|
||||
timer_ctx_t get_wasm_timer_ctx()
|
||||
timer_ctx_t get_wasm_timer_ctx(wasm_module_inst_t module_inst)
|
||||
{
|
||||
module_data * m = app_manager_get_module_data(Module_WASM_App);
|
||||
module_data * m = app_manager_get_module_data(Module_WASM_App,
|
||||
module_inst);
|
||||
if (m == NULL)
|
||||
return NULL;
|
||||
return m->timer_ctx;
|
||||
@ -153,27 +154,27 @@ 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,
|
||||
return sys_create_timer(get_wasm_timer_ctx(module_inst), interval, is_period,
|
||||
auto_start);
|
||||
}
|
||||
|
||||
void
|
||||
wasm_timer_destroy(wasm_module_inst_t module_inst, timer_id_t timer_id)
|
||||
{
|
||||
sys_timer_destroy(get_wasm_timer_ctx(), timer_id);
|
||||
sys_timer_destroy(get_wasm_timer_ctx(module_inst), 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);
|
||||
sys_timer_cancel(get_wasm_timer_ctx(module_inst), timer_id);
|
||||
}
|
||||
|
||||
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);
|
||||
sys_timer_restart(get_wasm_timer_ctx(module_inst), timer_id, interval);
|
||||
}
|
||||
|
||||
extern uint32 get_sys_tick_ms();
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
#define CONNECTION_LIB_H_
|
||||
|
||||
#include "attr_container.h"
|
||||
#include "wasm_export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -37,7 +38,8 @@ extern "C" {
|
||||
*
|
||||
* @return 0~0xFFFFFFFE means id of the connection, otherwise(-1) means fail
|
||||
*/
|
||||
typedef uint32 (*connection_open_f)(const char *name, attr_container_t *args);
|
||||
typedef uint32 (*connection_open_f)(wasm_module_inst_t module_inst,
|
||||
const char *name, attr_container_t *args);
|
||||
|
||||
/*
|
||||
* @brief Close a connection.
|
||||
|
||||
@ -30,7 +30,7 @@ wasm_open_connection(wasm_module_inst_t module_inst,
|
||||
attr_container_t *args;
|
||||
char *name, *args_buf;
|
||||
|
||||
if (!validate_app_addr(name_offset, 1) ||
|
||||
if (!validate_app_str_addr(name_offset) ||
|
||||
!validate_app_addr(args_offset, len) ||
|
||||
!(name = addr_app_to_native(name_offset)) ||
|
||||
!(args_buf = addr_app_to_native(args_offset)))
|
||||
@ -39,7 +39,7 @@ wasm_open_connection(wasm_module_inst_t module_inst,
|
||||
args = (attr_container_t *)args_buf;
|
||||
|
||||
if (connection_impl._open != NULL)
|
||||
return connection_impl._open(name, args);
|
||||
return connection_impl._open(module_inst, name, args);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -86,7 +86,8 @@ static struct epoll_event epoll_events[MAX_EVENTS];
|
||||
/* Buffer to receive data */
|
||||
static char io_buf[IO_BUF_SIZE];
|
||||
|
||||
static uint32 _conn_open(const char *name, attr_container_t *args);
|
||||
static uint32 _conn_open(wasm_module_inst_t module_inst,
|
||||
const char *name, attr_container_t *args);
|
||||
static void _conn_close(uint32 handle);
|
||||
static int _conn_send(uint32 handle, const char *data, int len);
|
||||
static bool _conn_config(uint32 handle, attr_container_t *cfg);
|
||||
@ -217,12 +218,14 @@ static conn_type_t get_conn_type(const char *name)
|
||||
}
|
||||
|
||||
/* --- connection lib function --- */
|
||||
static uint32 _conn_open(const char *name, attr_container_t *args)
|
||||
static uint32 _conn_open(wasm_module_inst_t module_inst,
|
||||
const char *name, attr_container_t *args)
|
||||
{
|
||||
int fd;
|
||||
sys_connection_t *conn;
|
||||
struct epoll_event ev;
|
||||
uint32 module_id = app_manager_get_module_id(Module_WASM_App);
|
||||
uint32 module_id = app_manager_get_module_id(Module_WASM_App,
|
||||
module_inst);
|
||||
|
||||
if (get_app_conns_num(module_id) >= MAX_CONNECTION_PER_APP)
|
||||
return -1;
|
||||
|
||||
@ -22,25 +22,115 @@
|
||||
/* -------------------------------------------------------------------------
|
||||
* Button widget native function wrappers
|
||||
* -------------------------------------------------------------------------*/
|
||||
static int32 _btn_create(lv_obj_t *par, lv_obj_t *copy)
|
||||
static int32
|
||||
lv_btn_create_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t *par, lv_obj_t *copy)
|
||||
{
|
||||
return wgl_native_wigdet_create(WIDGET_TYPE_BTN, par, copy);
|
||||
return wgl_native_wigdet_create(WIDGET_TYPE_BTN, par, copy, module_inst);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_btn_set_toggle_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn, bool tgl)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_btn_set_toggle(btn, tgl);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_btn_set_state_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn, lv_btn_state_t state)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_btn_set_state(btn, state);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_btn_set_ink_in_time_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn, uint16_t time)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_btn_set_ink_in_time(btn, time);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_btn_set_ink_out_time_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn, uint16_t time)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_btn_set_ink_out_time(btn, time);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_btn_set_ink_wait_time_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn, uint16_t time)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_btn_set_ink_wait_time(btn, time);
|
||||
}
|
||||
|
||||
static uint16_t
|
||||
lv_btn_get_ink_in_time_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn)
|
||||
{
|
||||
(void)module_inst;
|
||||
return lv_btn_get_ink_in_time(btn);
|
||||
}
|
||||
|
||||
static uint16_t
|
||||
lv_btn_get_ink_out_time_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn)
|
||||
{
|
||||
(void)module_inst;
|
||||
return lv_btn_get_ink_out_time(btn);
|
||||
}
|
||||
|
||||
static uint16_t
|
||||
lv_btn_get_ink_wait_time_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn)
|
||||
{
|
||||
(void)module_inst;
|
||||
return lv_btn_get_ink_wait_time(btn);
|
||||
}
|
||||
|
||||
static lv_btn_state_t
|
||||
lv_btn_get_state_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn)
|
||||
{
|
||||
(void)module_inst;
|
||||
return lv_btn_get_state(btn);
|
||||
}
|
||||
|
||||
static bool
|
||||
lv_btn_get_toggle_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn)
|
||||
{
|
||||
(void)module_inst;
|
||||
return lv_btn_get_toggle(btn);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_btn_toggle_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * btn)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_btn_toggle(btn);
|
||||
}
|
||||
|
||||
static WGLNativeFuncDef btn_native_func_defs[] = {
|
||||
{ BTN_FUNC_ID_CREATE, _btn_create, HAS_RET, 2, {0 | NULL_OK, 1 | NULL_OK, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_SET_TOGGLE, lv_btn_set_toggle, NO_RET, 2, {0, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_SET_STATE, lv_btn_set_state, NO_RET, 2, {0, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_CREATE, lv_btn_create_wrapper, HAS_RET, 3, {1 | NULL_OK, 2 | NULL_OK, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_SET_TOGGLE, lv_btn_set_toggle_wrapper, NO_RET, 3, {1, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_SET_STATE, lv_btn_set_state_wrapper, NO_RET, 3, {1, -1}, {-1} },
|
||||
// { BTN_FUNC_ID_SET_STYLE, _btn_set_style, NO_RET, 2, {0, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_SET_INK_IN_TIME, lv_btn_set_ink_in_time, NO_RET, 2, {0, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_SET_INK_OUT_TIME, lv_btn_set_ink_out_time, NO_RET, 2, {0, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_SET_INK_WAIT_TIME, lv_btn_set_ink_wait_time, NO_RET, 2, {0, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_GET_INK_IN_TIME, lv_btn_get_ink_in_time, HAS_RET, 1, {0, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_GET_INK_OUT_TIME, lv_btn_get_ink_out_time, HAS_RET, 1, {0, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_GET_INK_WAIT_TIME, lv_btn_get_ink_wait_time, HAS_RET, 1, {0, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_GET_STATE, lv_btn_get_state, HAS_RET, 1, {0, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_GET_TOGGLE, lv_btn_get_toggle, HAS_RET, 1, {0, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_TOGGLE, lv_btn_toggle, NO_RET, 1, {0, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_SET_INK_IN_TIME, lv_btn_set_ink_in_time_wrapper, NO_RET, 3, {1, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_SET_INK_OUT_TIME, lv_btn_set_ink_out_time_wrapper, NO_RET, 3, {1, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_SET_INK_WAIT_TIME, lv_btn_set_ink_wait_time_wrapper, NO_RET, 3, {1, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_GET_INK_IN_TIME, lv_btn_get_ink_in_time_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_GET_INK_OUT_TIME, lv_btn_get_ink_out_time_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_GET_INK_WAIT_TIME, lv_btn_get_ink_wait_time_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_GET_STATE, lv_btn_get_state_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_GET_TOGGLE, lv_btn_get_toggle_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
||||
{ BTN_FUNC_ID_TOGGLE, lv_btn_toggle_wrapper, NO_RET, 2, {1, -1}, {-1} },
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -24,13 +24,31 @@
|
||||
* Label widget native function wrappers
|
||||
* -------------------------------------------------------------------------*/
|
||||
static int32
|
||||
_cb_create(lv_obj_t *par, lv_obj_t *copy)
|
||||
lv_cb_create_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t *par, lv_obj_t *copy)
|
||||
{
|
||||
return wgl_native_wigdet_create(WIDGET_TYPE_CB, par, copy);
|
||||
return wgl_native_wigdet_create(WIDGET_TYPE_CB, par, copy, module_inst);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_cb_set_text_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * cb, const char * txt)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_cb_set_text(cb, txt);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_cb_set_static_text_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * cb, const char * txt)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_cb_set_static_text(cb, txt);
|
||||
}
|
||||
|
||||
static int32
|
||||
_cb_get_text_length(lv_obj_t *cb)
|
||||
lv_cb_get_text_length_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t *cb)
|
||||
{
|
||||
const char *text = lv_cb_get_text(cb);
|
||||
|
||||
@ -41,7 +59,8 @@ _cb_get_text_length(lv_obj_t *cb)
|
||||
}
|
||||
|
||||
static char *
|
||||
_cb_get_text(lv_obj_t *cb, char *buffer, int buffer_len)
|
||||
lv_cb_get_text_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t *cb, char *buffer, int buffer_len)
|
||||
{
|
||||
const char *text = lv_cb_get_text(cb);
|
||||
|
||||
@ -55,11 +74,11 @@ _cb_get_text(lv_obj_t *cb, char *buffer, int buffer_len)
|
||||
}
|
||||
|
||||
static WGLNativeFuncDef cb_native_func_defs[] = {
|
||||
{ CB_FUNC_ID_CREATE, _cb_create, HAS_RET, 2, {0 | NULL_OK, 1 | NULL_OK, -1}, {-1} },
|
||||
{ CB_FUNC_ID_SET_TEXT, lv_cb_set_text, NO_RET, 2, {0, -1}, {1, -1} },
|
||||
{ CB_FUNC_ID_SET_STATIC_TEXT, lv_cb_set_static_text, NO_RET, 2, {0, -1}, {1, -1} },
|
||||
{ CB_FUNC_ID_GET_TEXT_LENGTH, _cb_get_text_length, HAS_RET, 1, {0, -1}, {-1} },
|
||||
{ CB_FUNC_ID_GET_TEXT, _cb_get_text, RET_PTR, 3, {0, -1}, {1, -1} },
|
||||
{ CB_FUNC_ID_CREATE, lv_cb_create_wrapper, HAS_RET, 3, {1 | NULL_OK, 2 | NULL_OK, -1}, {-1} },
|
||||
{ CB_FUNC_ID_SET_TEXT, lv_cb_set_text_wrapper, NO_RET, 3, {1, -1}, {2, -1} },
|
||||
{ CB_FUNC_ID_SET_STATIC_TEXT, lv_cb_set_static_text_wrapper, NO_RET, 3, {1, -1}, {2, -1} },
|
||||
{ CB_FUNC_ID_GET_TEXT_LENGTH, lv_cb_get_text_length_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
||||
{ CB_FUNC_ID_GET_TEXT, lv_cb_get_text_wrapper, RET_PTR, 4, {1, -1}, {2, -1} },
|
||||
};
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
|
||||
@ -24,13 +24,23 @@
|
||||
* Label widget native function wrappers
|
||||
* -------------------------------------------------------------------------*/
|
||||
static int32
|
||||
_label_create(lv_obj_t *par, lv_obj_t *copy)
|
||||
lv_label_create_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t *par, lv_obj_t *copy)
|
||||
{
|
||||
return wgl_native_wigdet_create(WIDGET_TYPE_LABEL, par, copy);
|
||||
return wgl_native_wigdet_create(WIDGET_TYPE_LABEL, par, copy, module_inst);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_label_set_text_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * label, const char * text)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_label_set_text(label, text);
|
||||
}
|
||||
|
||||
static int32
|
||||
_label_get_text_length(lv_obj_t *label)
|
||||
lv_label_get_text_length_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t *label)
|
||||
{
|
||||
char *text = lv_label_get_text(label);
|
||||
|
||||
@ -41,7 +51,8 @@ _label_get_text_length(lv_obj_t *label)
|
||||
}
|
||||
|
||||
static char *
|
||||
_label_get_text(lv_obj_t *label, char *buffer, int buffer_len)
|
||||
lv_label_get_text_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t *label, char *buffer, int buffer_len)
|
||||
{
|
||||
char *text = lv_label_get_text(label);
|
||||
|
||||
@ -55,10 +66,10 @@ _label_get_text(lv_obj_t *label, char *buffer, int buffer_len)
|
||||
}
|
||||
|
||||
static WGLNativeFuncDef label_native_func_defs[] = {
|
||||
{ LABEL_FUNC_ID_CREATE, _label_create, HAS_RET, 2, {0 | NULL_OK, 1 | NULL_OK, -1}, {-1} },
|
||||
{ LABEL_FUNC_ID_SET_TEXT, lv_label_set_text, NO_RET, 2, {0, -1}, {1, -1} },
|
||||
{ LABEL_FUNC_ID_GET_TEXT_LENGTH, _label_get_text_length, HAS_RET, 1, {0, -1}, {-1} },
|
||||
{ LABEL_FUNC_ID_GET_TEXT, _label_get_text, RET_PTR, 3, {0, -1}, {1, -1} },
|
||||
{ LABEL_FUNC_ID_CREATE, lv_label_create_wrapper, HAS_RET, 3, {1 | NULL_OK, 2 | NULL_OK, -1}, {-1} },
|
||||
{ LABEL_FUNC_ID_SET_TEXT, lv_label_set_text_wrapper, NO_RET, 3, {1, -1}, {2, -1} },
|
||||
{ LABEL_FUNC_ID_GET_TEXT_LENGTH, lv_label_get_text_length_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
||||
{ LABEL_FUNC_ID_GET_TEXT, lv_label_get_text_wrapper, RET_PTR, 4, {1, -1}, {2, -1} },
|
||||
};
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
|
||||
@ -22,12 +22,16 @@
|
||||
/* -------------------------------------------------------------------------
|
||||
* List widget native function wrappers
|
||||
* -------------------------------------------------------------------------*/
|
||||
static int32 _list_create(lv_obj_t *par, lv_obj_t *copy)
|
||||
static int32
|
||||
lv_list_create_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t *par, lv_obj_t *copy)
|
||||
{
|
||||
return wgl_native_wigdet_create(WIDGET_TYPE_LIST, par, copy);
|
||||
return wgl_native_wigdet_create(WIDGET_TYPE_LIST, par, copy, module_inst);
|
||||
}
|
||||
|
||||
static int32 _list_add_btn(lv_obj_t *list, const char *text)
|
||||
static int32
|
||||
lv_list_add_btn_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t *list, const char *text)
|
||||
{
|
||||
uint32 btn_obj_id;
|
||||
lv_obj_t *btn;
|
||||
@ -38,7 +42,8 @@ static int32 _list_add_btn(lv_obj_t *list, const char *text)
|
||||
return 0;
|
||||
|
||||
if (wgl_native_add_object(btn,
|
||||
app_manager_get_module_id(Module_WASM_App),
|
||||
app_manager_get_module_id(Module_WASM_App,
|
||||
module_inst),
|
||||
&btn_obj_id))
|
||||
return btn_obj_id; /* success return */
|
||||
|
||||
@ -46,8 +51,8 @@ static int32 _list_add_btn(lv_obj_t *list, const char *text)
|
||||
}
|
||||
|
||||
static WGLNativeFuncDef list_native_func_defs[] = {
|
||||
{ LIST_FUNC_ID_CREATE, _list_create, HAS_RET, 2, {0 | NULL_OK, 1 | NULL_OK, -1}, {-1} },
|
||||
{ LIST_FUNC_ID_ADD_BTN, _list_add_btn, HAS_RET, 2, {0, -1}, {1, -1} },
|
||||
{ LIST_FUNC_ID_CREATE, lv_list_create_wrapper, HAS_RET, 3, {1 | NULL_OK, 2 | NULL_OK, -1}, {-1} },
|
||||
{ LIST_FUNC_ID_ADD_BTN, lv_list_add_btn_wrapper, HAS_RET, 3, {1, -1}, {2, -1} },
|
||||
};
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include "lvgl.h"
|
||||
#include "module_wasm_app.h"
|
||||
#include "wasm_export.h"
|
||||
#include "wasm_assert.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@ -12,7 +13,8 @@
|
||||
void
|
||||
wasm_runtime_set_exception(wasm_module_inst_t module, const char *exception);
|
||||
|
||||
uint32 wgl_native_wigdet_create(int8 widget_type, lv_obj_t *par, lv_obj_t *copy)
|
||||
uint32 wgl_native_wigdet_create(int8 widget_type, lv_obj_t *par, lv_obj_t *copy,
|
||||
wasm_module_inst_t module_inst)
|
||||
{
|
||||
uint32 obj_id;
|
||||
lv_obj_t *wigdet;
|
||||
@ -37,20 +39,19 @@ uint32 wgl_native_wigdet_create(int8 widget_type, lv_obj_t *par, lv_obj_t *copy)
|
||||
return 0;
|
||||
|
||||
if (wgl_native_add_object(wigdet,
|
||||
app_manager_get_module_id(Module_WASM_App),
|
||||
app_manager_get_module_id(Module_WASM_App,
|
||||
module_inst),
|
||||
&obj_id))
|
||||
return obj_id; /* success return */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void invokeNative(wasm_module_inst_t module_inst,
|
||||
intptr_t argv[], uint32 argc, void (*native_code)())
|
||||
static void invokeNative(intptr_t argv[], uint32 argc, void (*native_code)())
|
||||
{
|
||||
wasm_assert(argc >= 1);
|
||||
|
||||
switch(argc) {
|
||||
case 0:
|
||||
native_code();
|
||||
break;
|
||||
case 1:
|
||||
native_code(argv[0]);
|
||||
break;
|
||||
@ -87,15 +88,18 @@ static void invokeNative(wasm_module_inst_t module_inst,
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
/* FIXME: If this happen, add more cases. */
|
||||
wasm_module_inst_t module_inst = (wasm_module_inst_t)argv[0];
|
||||
THROW_EXC("the argument number of native function exceeds maximum");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typedef void (*GenericFunctionPointer)();
|
||||
typedef int32 (*Int32FuncPtr)(wasm_module_inst_t, intptr_t *, uint32, GenericFunctionPointer);
|
||||
typedef void (*VoidFuncPtr)(wasm_module_inst_t, intptr_t *, uint32, GenericFunctionPointer);
|
||||
typedef int32 (*Int32FuncPtr)(intptr_t *, uint32, GenericFunctionPointer);
|
||||
typedef void (*VoidFuncPtr)(intptr_t *, uint32, GenericFunctionPointer);
|
||||
|
||||
static Int32FuncPtr invokeNative_Int32 = (Int32FuncPtr)invokeNative;
|
||||
static VoidFuncPtr invokeNative_Void = (VoidFuncPtr)invokeNative;
|
||||
@ -118,11 +122,13 @@ void wgl_native_func_call(wasm_module_inst_t module_inst,
|
||||
|
||||
while (func_def < func_def_end) {
|
||||
if (func_def->func_id == func_id) {
|
||||
int i, obj_arg_num = 0, ptr_arg_num = 0;
|
||||
int i, obj_arg_num = 0, ptr_arg_num = 0, argc1 = 0;
|
||||
intptr_t argv_copy_buf[16];
|
||||
intptr_t *argv_copy = argv_copy_buf;
|
||||
|
||||
if (func_def->arg_num > 16) {
|
||||
argc1++; /* module_inst */
|
||||
argc1 += func_def->arg_num;
|
||||
if (argc1 > 16) {
|
||||
argv_copy = (intptr_t *)bh_malloc(func_def->arg_num *
|
||||
sizeof(intptr_t));
|
||||
if (argv_copy == NULL)
|
||||
@ -130,8 +136,9 @@ void wgl_native_func_call(wasm_module_inst_t module_inst,
|
||||
}
|
||||
|
||||
/* Init argv_copy */
|
||||
argv_copy[0] = (intptr_t)module_inst;
|
||||
for (i = 0; i < func_def->arg_num; i++)
|
||||
argv_copy[i] = (intptr_t)argv[i];
|
||||
argv_copy[i + 1] = (intptr_t)argv[i];
|
||||
|
||||
/* Validate object arguments */
|
||||
i = 0;
|
||||
@ -143,7 +150,7 @@ void wgl_native_func_call(wasm_module_inst_t module_inst,
|
||||
index = index & (~NULL_OK);
|
||||
|
||||
/* Some API's allow to pass NULL obj, such as xxx_create() */
|
||||
if (argv[index] == 0) {
|
||||
if (argv_copy[index] == 0) {
|
||||
if (!null_ok) {
|
||||
THROW_EXC("the object id is 0 and invalid");
|
||||
goto fail;
|
||||
@ -152,7 +159,8 @@ void wgl_native_func_call(wasm_module_inst_t module_inst,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!wgl_native_validate_object(argv[index], (lv_obj_t **)&argv_copy[index])) {
|
||||
if (!wgl_native_validate_object(argv_copy[index],
|
||||
(lv_obj_t **)&argv_copy[index])) {
|
||||
THROW_EXC("the object is invalid");
|
||||
goto fail;
|
||||
}
|
||||
@ -165,22 +173,20 @@ void wgl_native_func_call(wasm_module_inst_t module_inst,
|
||||
uint8 index = func_def->ptr_arg_indexes[i];
|
||||
|
||||
/* The index+1 arg is the data size to be validated */
|
||||
if (!validate_app_addr(argv[index], argv[index + 1]))
|
||||
if (!validate_app_addr(argv_copy[index], argv_copy[index + 1]))
|
||||
goto fail;
|
||||
|
||||
/* Convert to native address before call lvgl function */
|
||||
argv_copy[index] = (intptr_t)addr_app_to_native(argv[index]);
|
||||
argv_copy[index] = (intptr_t)addr_app_to_native(argv_copy[index]);
|
||||
}
|
||||
|
||||
if (func_def->has_ret == NO_RET)
|
||||
invokeNative_Void(module_inst,
|
||||
argv_copy,
|
||||
func_def->arg_num,
|
||||
invokeNative_Void(argv_copy,
|
||||
argc1,
|
||||
func_def->func_ptr);
|
||||
else {
|
||||
argv[0] = invokeNative_Int32(module_inst,
|
||||
argv_copy,
|
||||
func_def->arg_num,
|
||||
argv[0] = invokeNative_Int32(argv_copy,
|
||||
argc1,
|
||||
func_def->func_ptr);
|
||||
/* Convert to app memory offset if return value is a
|
||||
* native address pointer */
|
||||
|
||||
@ -63,7 +63,8 @@ bool wgl_native_add_object(lv_obj_t *obj, uint32 module_id, uint32 *obj_id);
|
||||
|
||||
uint32 wgl_native_wigdet_create(int8 widget_type,
|
||||
lv_obj_t *par,
|
||||
lv_obj_t *copy);
|
||||
lv_obj_t *copy,
|
||||
wasm_module_inst_t module_inst);
|
||||
|
||||
void wgl_native_func_call(wasm_module_inst_t module_inst,
|
||||
WGLNativeFuncDef *funcs,
|
||||
|
||||
@ -306,8 +306,11 @@ void wgl_init(void)
|
||||
/* -------------------------------------------------------------------------
|
||||
* Obj native function wrappers
|
||||
* -------------------------------------------------------------------------*/
|
||||
static lv_res_t _obj_del(lv_obj_t *obj)
|
||||
static lv_res_t
|
||||
lv_obj_del_wrapper(wasm_module_inst_t module_inst, lv_obj_t *obj)
|
||||
{
|
||||
(void)module_inst;
|
||||
|
||||
/* Recursively delete object node in the list belong to this
|
||||
* parent object including itself */
|
||||
_obj_del_recursive(obj);
|
||||
@ -315,8 +318,18 @@ static lv_res_t _obj_del(lv_obj_t *obj)
|
||||
return lv_obj_del(obj);
|
||||
}
|
||||
|
||||
static void _obj_clean(lv_obj_t *obj)
|
||||
static void
|
||||
lv_obj_del_async_wrapper(wasm_module_inst_t module_inst, lv_obj_t * obj)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_obj_del_async(obj);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_obj_clean_wrapper(wasm_module_inst_t module_inst, lv_obj_t *obj)
|
||||
{
|
||||
(void)module_inst;
|
||||
|
||||
/* Recursively delete child object node in the list belong to this
|
||||
* parent object */
|
||||
_obj_clean_recursive(obj);
|
||||
@ -325,19 +338,33 @@ static void _obj_clean(lv_obj_t *obj)
|
||||
lv_obj_clean(obj);
|
||||
}
|
||||
|
||||
static void _obj_set_event_cb(lv_obj_t *obj)
|
||||
static void
|
||||
lv_obj_align_wrapper(wasm_module_inst_t module_inst,
|
||||
lv_obj_t * obj,
|
||||
const lv_obj_t * base,
|
||||
lv_align_t align,
|
||||
lv_coord_t x_mod,
|
||||
lv_coord_t y_mod)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_obj_align(obj, base, align, x_mod, y_mod);
|
||||
}
|
||||
|
||||
static void
|
||||
lv_obj_set_event_cb_wrapper(wasm_module_inst_t module_inst, lv_obj_t *obj)
|
||||
{
|
||||
(void)module_inst;
|
||||
lv_obj_set_event_cb(obj, internal_lv_obj_event_cb);
|
||||
}
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
static WGLNativeFuncDef obj_native_func_defs[] = {
|
||||
{ OBJ_FUNC_ID_DEL, _obj_del, HAS_RET, 1, {0, -1}, {-1} },
|
||||
{ OBJ_FUNC_ID_DEL_ASYNC, lv_obj_del_async, NO_RET, 1, {0, -1}, {-1} },
|
||||
{ OBJ_FUNC_ID_CLEAN, _obj_clean, NO_RET, 1, {0, -1}, {-1} },
|
||||
{ OBJ_FUNC_ID_ALIGN, lv_obj_align, NO_RET, 5, {0, 1 | NULL_OK, -1}, {-1} },
|
||||
{ OBJ_FUNC_ID_SET_EVT_CB, _obj_set_event_cb, NO_RET, 1, {0, -1}, {-1} },
|
||||
{ OBJ_FUNC_ID_DEL, lv_obj_del_wrapper, HAS_RET, 2, {1, -1}, {-1} },
|
||||
{ OBJ_FUNC_ID_DEL_ASYNC, lv_obj_del_async_wrapper, NO_RET, 2, {1, -1}, {-1} },
|
||||
{ OBJ_FUNC_ID_CLEAN, lv_obj_clean_wrapper, NO_RET, 2, {1, -1}, {-1} },
|
||||
{ OBJ_FUNC_ID_ALIGN, lv_obj_align_wrapper, NO_RET, 6, {1, 2 | NULL_OK, -1}, {-1} },
|
||||
{ OBJ_FUNC_ID_SET_EVT_CB, lv_obj_set_event_cb_wrapper, NO_RET, 2, {1, -1}, {-1} },
|
||||
};
|
||||
|
||||
/*************** Native Interface to Wasm App ***********/
|
||||
|
||||
@ -106,7 +106,8 @@ wasm_sensor_config(wasm_module_inst_t module_inst,
|
||||
if (s == NULL)
|
||||
return false;
|
||||
|
||||
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App);
|
||||
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App,
|
||||
module_inst);
|
||||
|
||||
vm_mutex_lock(&s->lock);
|
||||
|
||||
@ -144,7 +145,7 @@ wasm_sensor_open(wasm_module_inst_t module_inst,
|
||||
{
|
||||
char *name = NULL;
|
||||
|
||||
if (!validate_app_addr(name_offset, 1))
|
||||
if (!validate_app_str_addr(name_offset))
|
||||
return -1;
|
||||
|
||||
name = addr_app_to_native(name_offset);
|
||||
@ -155,7 +156,8 @@ wasm_sensor_open(wasm_module_inst_t module_inst,
|
||||
if (s == NULL)
|
||||
return -1;
|
||||
|
||||
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App);
|
||||
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App,
|
||||
module_inst);
|
||||
|
||||
vm_mutex_lock(&s->lock);
|
||||
|
||||
@ -222,7 +224,8 @@ wasm_sensor_config_with_attr_container(wasm_module_inst_t module_inst,
|
||||
bool
|
||||
wasm_sensor_close(wasm_module_inst_t module_inst, uint32 sensor)
|
||||
{
|
||||
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App);
|
||||
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App,
|
||||
module_inst);
|
||||
unsigned int client_id = mod_id;
|
||||
sensor_obj_t s = find_sys_sensor_id(sensor);
|
||||
sensor_client_t *c;
|
||||
|
||||
@ -37,6 +37,9 @@ wasm_runtime_set_llvm_stack(wasm_module_inst_t module, uint32 llvm_stack);
|
||||
#define validate_app_addr(offset, size) \
|
||||
wasm_runtime_validate_app_addr(module_inst, offset, size)
|
||||
|
||||
#define validate_app_str_addr(offset) \
|
||||
wasm_runtime_validate_app_str_addr(module_inst, offset)
|
||||
|
||||
#define addr_app_to_native(offset) \
|
||||
wasm_runtime_addr_app_to_native(module_inst, offset)
|
||||
|
||||
@ -49,29 +52,6 @@ wasm_runtime_set_llvm_stack(wasm_module_inst_t module, uint32 llvm_stack);
|
||||
#define module_free(offset) \
|
||||
wasm_runtime_module_free(module_inst, offset)
|
||||
|
||||
static bool
|
||||
validate_str_addr(wasm_module_inst_t module_inst, int32 str_offset)
|
||||
{
|
||||
int32 app_end_offset;
|
||||
char *str, *str_end;
|
||||
|
||||
if (!wasm_runtime_get_app_addr_range(module_inst, str_offset,
|
||||
NULL, &app_end_offset))
|
||||
goto fail;
|
||||
|
||||
str = addr_app_to_native(str_offset);
|
||||
str_end = str + (app_end_offset - str_offset);
|
||||
while (str < str_end && *str != '\0')
|
||||
str++;
|
||||
if (str == str_end)
|
||||
goto fail;
|
||||
return true;
|
||||
|
||||
fail:
|
||||
wasm_runtime_set_exception(module_inst, "out of bounds memory access");
|
||||
return false;
|
||||
}
|
||||
|
||||
typedef int (*out_func_t)(int c, void *ctx);
|
||||
|
||||
enum pad_type {
|
||||
@ -335,7 +315,7 @@ _vprintf_wa(out_func_t out, void *ctx, const char *fmt, _va_list ap,
|
||||
CHECK_VA_ARG(ap, uint32);
|
||||
s_offset = _va_arg(ap, uint32);
|
||||
|
||||
if (!validate_str_addr(module_inst, s_offset)) {
|
||||
if (!validate_app_str_addr(s_offset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -438,7 +418,7 @@ parse_printf_args(wasm_module_inst_t module_inst, int32 fmt_offset,
|
||||
_va_list v;
|
||||
} u;
|
||||
|
||||
if (!validate_str_addr(module_inst, fmt_offset)
|
||||
if (!validate_app_str_addr(fmt_offset)
|
||||
|| !validate_app_addr(va_list_offset, sizeof(int32)))
|
||||
return false;
|
||||
|
||||
@ -539,7 +519,7 @@ _puts_wrapper(wasm_module_inst_t module_inst,
|
||||
{
|
||||
const char *str;
|
||||
|
||||
if (!validate_str_addr(module_inst, str_offset))
|
||||
if (!validate_app_str_addr(str_offset))
|
||||
return 0;
|
||||
|
||||
str = addr_app_to_native(str_offset);
|
||||
@ -561,7 +541,7 @@ _strdup_wrapper(wasm_module_inst_t module_inst,
|
||||
uint32 len;
|
||||
int32 str_ret_offset = 0;
|
||||
|
||||
if (!validate_str_addr(module_inst, str_offset))
|
||||
if (!validate_app_str_addr(str_offset))
|
||||
return 0;
|
||||
|
||||
str = addr_app_to_native(str_offset);
|
||||
@ -650,7 +630,7 @@ _strchr_wrapper(wasm_module_inst_t module_inst,
|
||||
const char *s;
|
||||
char *ret;
|
||||
|
||||
if (!validate_str_addr(module_inst, s_offset))
|
||||
if (!validate_app_str_addr(s_offset))
|
||||
return s_offset;
|
||||
|
||||
s = addr_app_to_native(s_offset);
|
||||
@ -664,8 +644,8 @@ _strcmp_wrapper(wasm_module_inst_t module_inst,
|
||||
{
|
||||
void *s1, *s2;
|
||||
|
||||
if (!validate_str_addr(module_inst, s1_offset)
|
||||
|| !validate_str_addr(module_inst, s2_offset))
|
||||
if (!validate_app_str_addr(s1_offset)
|
||||
|| !validate_app_str_addr(s2_offset))
|
||||
return 0;
|
||||
|
||||
s1 = addr_app_to_native(s1_offset);
|
||||
@ -695,7 +675,7 @@ _strcpy_wrapper(wasm_module_inst_t module_inst,
|
||||
char *dst, *src;
|
||||
uint32 len;
|
||||
|
||||
if (!validate_str_addr(module_inst, src_offset))
|
||||
if (!validate_app_str_addr(src_offset))
|
||||
return 0;
|
||||
|
||||
src = addr_app_to_native(src_offset);
|
||||
@ -731,7 +711,7 @@ _strlen_wrapper(wasm_module_inst_t module_inst,
|
||||
{
|
||||
char *s;
|
||||
|
||||
if (!validate_str_addr(module_inst, s_offset))
|
||||
if (!validate_app_str_addr(s_offset))
|
||||
return 0;
|
||||
|
||||
s = addr_app_to_native(s_offset);
|
||||
|
||||
Reference in New Issue
Block a user