Enhance wasm loader and interpreter, enhance code security and update document (#149)

This commit is contained in:
wenyongh
2019-12-13 15:30:30 +08:00
committed by GitHub
parent 1c81ad6da5
commit 631b7a2403
45 changed files with 678 additions and 646 deletions

View File

@ -29,6 +29,8 @@
#define MAX_EVENTS 10
#define IO_BUF_SIZE 256
static bool polling_thread_run = true;
/* Connection type */
typedef enum conn_type {
CONN_TYPE_TCP,
@ -436,7 +438,7 @@ static void post_msg_to_module(sys_connection_t *conn,
static void* polling_thread_routine (void *arg)
{
while (true) {
while (polling_thread_run) {
int i, n;
n = epoll_wait(epollfd, epoll_events, MAX_EVENTS, -1);
@ -500,8 +502,10 @@ void app_mgr_connection_event_callback(module_data *m_data, bh_message_t msg)
argv[1] = 0;
argv[2] = 0;
if (!wasm_runtime_call_wasm(inst, NULL, func_on_conn_data, 3, argv)) {
const char *exception = wasm_runtime_get_exception(inst);
bh_assert(exception);
printf(":Got exception running wasm code: %s\n",
wasm_runtime_get_exception(inst));
exception);
wasm_runtime_clear_exception(inst);
return;
}
@ -510,9 +514,12 @@ void app_mgr_connection_event_callback(module_data *m_data, bh_message_t msg)
conn_event->data,
conn_event->len);
if (data_offset == 0) {
printf("Got exception running wasm code: %s\n",
wasm_runtime_get_exception(inst));
wasm_runtime_clear_exception(inst);
const char *exception = wasm_runtime_get_exception(inst);
if (exception) {
printf("Got exception running wasm code: %s\n",
exception);
wasm_runtime_clear_exception(inst);
}
return;
}
@ -520,8 +527,10 @@ void app_mgr_connection_event_callback(module_data *m_data, bh_message_t msg)
argv[1] = (uint32) data_offset;
argv[2] = conn_event->len;
if (!wasm_runtime_call_wasm(inst, NULL, func_on_conn_data, 3, argv)) {
const char *exception = wasm_runtime_get_exception(inst);
bh_assert(exception);
printf(":Got exception running wasm code: %s\n",
wasm_runtime_get_exception(inst));
exception);
wasm_runtime_clear_exception(inst);
wasm_runtime_module_free(inst, data_offset);
return;
@ -566,3 +575,8 @@ fail:
close(epollfd);
return false;
}
void exit_connection_framework()
{
polling_thread_run = false;
}

View File

@ -0,0 +1,20 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef WAMR_GRAPHIC_LIBRARY_H
#define WAMR_GRAPHIC_LIBRARY_H
#ifdef __cplusplus
extern "C" {
#endif
void wgl_init(void);
void wgl_exit(void);
#ifdef __cplusplus
}
#endif
#endif /* WAMR_GRAPHIC_LIBRARY_H */

View File

@ -1,4 +1,7 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef WAMR_GRAPHIC_LIBRARY_NATIVE_UTILS_H
#define WAMR_GRAPHIC_LIBRARY_NATIVE_UTILS_H

View File

@ -9,6 +9,7 @@
#include "bh_list.h"
#include "bh_thread.h"
#include "wgl_native_utils.h"
#include "wgl.h"
typedef struct {
@ -36,6 +37,8 @@ static bh_list g_object_list;
static korp_mutex g_object_list_mutex;
static bool lv_task_handler_thread_run = true;
static void app_mgr_object_event_callback(module_data *m_data, bh_message_t msg)
{
uint32 argv[2];
@ -62,8 +65,10 @@ static void app_mgr_object_event_callback(module_data *m_data, bh_message_t msg)
argv[0] = object_event->obj_id;
argv[1] = object_event->event;
if (!wasm_runtime_call_wasm(inst, NULL, func_on_object_event, 2, argv)) {
const char *exception = wasm_runtime_get_exception(inst);
bh_assert(exception);
printf(":Got exception running wasm code: %s\n",
wasm_runtime_get_exception(inst));
exception);
wasm_runtime_clear_exception(inst);
return;
}
@ -270,11 +275,13 @@ static void* lv_task_handler_thread_routine (void *arg)
vm_sem_init(&sem, 0);
while (true) {
while (lv_task_handler_thread_run) {
vm_sem_reltimedwait(&sem, 100);
lv_task_handler();
}
vm_sem_destroy(&sem);
return NULL;
}
@ -295,6 +302,11 @@ void wgl_init(void)
BH_APPLET_PRESERVED_STACK_SIZE);
}
void wgl_exit(void)
{
lv_task_handler_thread_run = false;
}
/* -------------------------------------------------------------------------
* Obj native function wrappers
* -------------------------------------------------------------------------*/

View File

@ -19,6 +19,7 @@
*/
static korp_cond cond;
static korp_mutex mutex;
static bool sensor_check_thread_run = true;
void app_mgr_sensor_event_callback(module_data *m_data, bh_message_t msg)
{
@ -52,9 +53,12 @@ void app_mgr_sensor_event_callback(module_data *m_data, bh_message_t msg)
sensor_data_offset = wasm_runtime_module_dup_data(inst, payload->data,
sensor_data_len);
if (sensor_data_offset == 0) {
printf("Got exception running wasm code: %s\n",
wasm_runtime_get_exception(inst));
wasm_runtime_clear_exception(inst);
const char *exception = wasm_runtime_get_exception(inst);
if (exception) {
printf("Got exception running wasm code: %s\n",
exception);
wasm_runtime_clear_exception(inst);
}
return;
}
@ -63,8 +67,10 @@ void app_mgr_sensor_event_callback(module_data *m_data, bh_message_t msg)
argv[2] = sensor_data_len;
if (!wasm_runtime_call_wasm(inst, NULL, func_onSensorEvent, 3, argv)) {
const char *exception = wasm_runtime_get_exception(inst);
bh_assert(exception);
printf(":Got exception running wasm code: %s\n",
wasm_runtime_get_exception(inst));
exception);
wasm_runtime_clear_exception(inst);
wasm_runtime_module_free(inst, sensor_data_offset);
return;
@ -92,7 +98,7 @@ static bool config_test_sensor(void * s, void * config)
static void thread_sensor_check(void * arg)
{
while (1) {
while (sensor_check_thread_run) {
int ms_to_expiry = check_sensor_timers();
if (ms_to_expiry == -1)
ms_to_expiry = 5000;
@ -131,3 +137,8 @@ void init_sensor_framework()
BH_APPLET_PRESERVED_STACK_SIZE);
}
void exit_sensor_framework()
{
sensor_check_thread_run = false;
}