Enable WASI feature, enhance security and add SGX sample (#142)
Change emcc to clang Refine interpreter to improve perforamnce
This commit is contained in:
@ -60,7 +60,7 @@ int uart_open(char* device, int baudrate)
|
||||
|
||||
uart_fd = open(device, O_RDWR | O_NOCTTY);
|
||||
|
||||
if (uart_fd <= 0)
|
||||
if (uart_fd < 0)
|
||||
return -1;
|
||||
|
||||
memset(&uart_term, 0, sizeof(uart_term));
|
||||
|
||||
@ -26,8 +26,10 @@ int udp_open(uint16 port)
|
||||
addr.sin_port = htons(port);
|
||||
|
||||
ret = bind(sock, (struct sockaddr*)&addr, sizeof(addr));
|
||||
if (ret == -1)
|
||||
if (ret == -1) {
|
||||
close(sock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Put the socket in non-blocking mode */
|
||||
if (fcntl(sock, F_SETFL, fcntl(sock, F_GETFL) | O_NONBLOCK) < 0) {
|
||||
|
||||
@ -17,6 +17,8 @@
|
||||
#include "conn_tcp.h"
|
||||
#include "conn_udp.h"
|
||||
#include "conn_uart.h"
|
||||
#include "bh_common.h"
|
||||
#include "bh_assert.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/epoll.h>
|
||||
@ -214,6 +216,7 @@ static uint32 _conn_open(wasm_module_inst_t module_inst,
|
||||
struct epoll_event ev;
|
||||
uint32 module_id = app_manager_get_module_id(Module_WASM_App,
|
||||
module_inst);
|
||||
bh_assert(module_id != ID_NONE);
|
||||
|
||||
if (get_app_conns_num(module_id) >= MAX_CONNECTION_PER_APP)
|
||||
return -1;
|
||||
@ -242,7 +245,7 @@ static uint32 _conn_open(wasm_module_inst_t module_inst,
|
||||
port = attr_container_get_as_uint16(args, "port");
|
||||
|
||||
/* Connect to TCP server */
|
||||
if ((fd = tcp_open(address, port)) == -1)
|
||||
if (!address || (fd = tcp_open(address, port)) == -1)
|
||||
goto fail;
|
||||
|
||||
} else if (conn->type == CONN_TYPE_UDP) {
|
||||
@ -269,9 +272,10 @@ static uint32 _conn_open(wasm_module_inst_t module_inst,
|
||||
baud = attr_container_get_as_int(args, "baudrate");
|
||||
|
||||
/* Open device */
|
||||
if ((fd = uart_open(device, baud)) == -1)
|
||||
if (!device || (fd = uart_open(device, baud)) == -1)
|
||||
goto fail;
|
||||
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
conn->fd = fd;
|
||||
@ -345,7 +349,8 @@ static bool _conn_config(uint32 handle, attr_container_t *cfg)
|
||||
if (!attr_container_contain_key(cfg, "address") ||
|
||||
!attr_container_contain_key(cfg, "port"))
|
||||
return false;
|
||||
address = attr_container_get_as_string(cfg, "address");
|
||||
if (!(address = attr_container_get_as_string(cfg, "address")))
|
||||
return false;
|
||||
port = attr_container_get_as_uint16(cfg, "port");
|
||||
|
||||
if (conn->arg == NULL) {
|
||||
@ -409,7 +414,7 @@ static void post_msg_to_module(sys_connection_t *conn,
|
||||
bh_free(conn_data_event);
|
||||
return;
|
||||
}
|
||||
memcpy(data_copy, data, len);
|
||||
bh_memcpy_s(data_copy, len, data, len);
|
||||
}
|
||||
|
||||
memset(conn_data_event, 0, sizeof(*conn_data_event));
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
set (WASM_LIB_CONN_MGR_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
include_directories(${WASM_LIB_CONN_MGR_DIR})
|
||||
|
||||
|
||||
file (GLOB_RECURSE source_all ${WASM_LIB_CONN_MGR_DIR}/*.c)
|
||||
|
||||
set (WASM_LIB_CONN_MGR_SOURCE ${source_all})
|
||||
|
||||
|
||||
@ -5,7 +5,10 @@ set (WASM_LIB_GUI_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
set (THIRD_PARTY_DIR ${WASM_LIB_GUI_DIR}/../../../3rdparty)
|
||||
|
||||
include_directories(${WASM_LIB_GUI_DIR} ${THIRD_PARTY_DIR} ${THIRD_PARTY_DIR}/lvgl)
|
||||
include_directories(${WASM_LIB_GUI_DIR}
|
||||
${THIRD_PARTY_DIR}
|
||||
${THIRD_PARTY_DIR}/lvgl
|
||||
${THIRD_PARTY_DIR}/lvgl/src)
|
||||
|
||||
file (GLOB_RECURSE lvgl_source ${THIRD_PARTY_DIR}/lvgl/*.c)
|
||||
file (GLOB_RECURSE wrapper_source ${WASM_LIB_GUI_DIR}/*.c)
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include "lvgl.h"
|
||||
#include "module_wasm_app.h"
|
||||
#include "wgl_native_utils.h"
|
||||
#include "bh_assert.h"
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
* List widget native function wrappers
|
||||
@ -24,16 +25,17 @@ lv_list_add_btn_wrapper(wasm_module_inst_t module_inst,
|
||||
{
|
||||
uint32 btn_obj_id;
|
||||
lv_obj_t *btn;
|
||||
uint32 mod_id;
|
||||
|
||||
btn = lv_list_add_btn(list, NULL, text);
|
||||
|
||||
if (btn == NULL)
|
||||
return 0;
|
||||
|
||||
if (wgl_native_add_object(btn,
|
||||
app_manager_get_module_id(Module_WASM_App,
|
||||
module_inst),
|
||||
&btn_obj_id))
|
||||
mod_id = app_manager_get_module_id(Module_WASM_App, module_inst);
|
||||
bh_assert(mod_id != ID_NONE);
|
||||
|
||||
if (wgl_native_add_object(btn, mod_id, &btn_obj_id))
|
||||
return btn_obj_id; /* success return */
|
||||
|
||||
return 0;
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#include "lvgl.h"
|
||||
#include "module_wasm_app.h"
|
||||
#include "wasm_export.h"
|
||||
#include "wasm_assert.h"
|
||||
#include "bh_assert.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@ -17,7 +17,8 @@ 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;
|
||||
lv_obj_t *wigdet = NULL;
|
||||
uint32 mod_id;
|
||||
|
||||
//TODO: limit total widget number
|
||||
|
||||
@ -38,10 +39,10 @@ uint32 wgl_native_wigdet_create(int8 widget_type, lv_obj_t *par, lv_obj_t *copy,
|
||||
if (wigdet == NULL)
|
||||
return 0;
|
||||
|
||||
if (wgl_native_add_object(wigdet,
|
||||
app_manager_get_module_id(Module_WASM_App,
|
||||
module_inst),
|
||||
&obj_id))
|
||||
mod_id = app_manager_get_module_id(Module_WASM_App, module_inst);
|
||||
bh_assert(mod_id != ID_NONE);
|
||||
|
||||
if (wgl_native_add_object(wigdet, mod_id, &obj_id))
|
||||
return obj_id; /* success return */
|
||||
|
||||
return 0;
|
||||
@ -49,7 +50,7 @@ uint32 wgl_native_wigdet_create(int8 widget_type, lv_obj_t *par, lv_obj_t *copy,
|
||||
|
||||
static void invokeNative(intptr_t argv[], uint32 argc, void (*native_code)())
|
||||
{
|
||||
wasm_assert(argc >= 1);
|
||||
bh_assert(argc >= 1);
|
||||
|
||||
switch(argc) {
|
||||
case 1:
|
||||
|
||||
@ -50,7 +50,10 @@ static void app_mgr_object_event_callback(module_data *m_data, bh_message_t msg)
|
||||
return;
|
||||
|
||||
func_on_object_event = wasm_runtime_lookup_function(inst, "_on_widget_event",
|
||||
"(i32i32)");
|
||||
"(i32i32)");
|
||||
if (!func_on_object_event)
|
||||
func_on_object_event = wasm_runtime_lookup_function(inst, "on_widget_event",
|
||||
"(i32i32)");
|
||||
if (!func_on_object_event) {
|
||||
printf("Cannot find function _on_object_event\n");
|
||||
return;
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
#include "module_wasm_app.h"
|
||||
#include "bh_thread.h"
|
||||
#include "bh_time.h"
|
||||
#include "bh_common.h"
|
||||
#include "bh_assert.h"
|
||||
|
||||
static sys_sensor_t * g_sys_sensors = NULL;
|
||||
static int g_sensor_id_max = 0;
|
||||
@ -59,7 +61,8 @@ wasm_sensor_callback(void *client, uint32 sensor_id, void *user_data)
|
||||
return;
|
||||
|
||||
/* multiple sensor clients may use/free the sensor data, so make a copy */
|
||||
memcpy(sensor_data_clone, sensor_data, sensor_data_len);
|
||||
bh_memcpy_s(sensor_data_clone, sensor_data_len,
|
||||
sensor_data, sensor_data_len);
|
||||
|
||||
sensor_event = (sensor_event_data_t *)bh_malloc(sizeof(*sensor_event));
|
||||
if (sensor_event == NULL) {
|
||||
@ -97,6 +100,7 @@ wasm_sensor_config(wasm_module_inst_t module_inst,
|
||||
|
||||
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App,
|
||||
module_inst);
|
||||
bh_assert(mod_id != ID_NONE);
|
||||
|
||||
vm_mutex_lock(&s->lock);
|
||||
|
||||
@ -147,6 +151,7 @@ wasm_sensor_open(wasm_module_inst_t module_inst,
|
||||
|
||||
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App,
|
||||
module_inst);
|
||||
bh_assert(mod_id != ID_NONE);
|
||||
|
||||
vm_mutex_lock(&s->lock);
|
||||
|
||||
@ -219,6 +224,8 @@ wasm_sensor_close(wasm_module_inst_t module_inst, uint32 sensor)
|
||||
sensor_obj_t s = find_sys_sensor_id(sensor);
|
||||
sensor_client_t *c;
|
||||
|
||||
bh_assert(mod_id != ID_NONE);
|
||||
|
||||
if (s == NULL)
|
||||
return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user