Enable WASI feature, enhance security and add SGX sample (#142)

Change emcc to clang
Refine interpreter to improve perforamnce
This commit is contained in:
Weining
2019-11-20 21:16:36 +08:00
committed by wenyongh
parent 29c7c743e9
commit 27f246b5f3
159 changed files with 9543 additions and 3789 deletions

View File

@ -6,6 +6,7 @@
#include "app_manager_export.h"
#include "coap_ext.h"
#include "wasm_export.h"
#include "bh_assert.h"
extern void module_request_handler(request_t *request, void *user_data);
@ -47,6 +48,7 @@ wasm_register_resource(wasm_module_inst_t module_inst, int32 url_offset)
if (url != NULL) {
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App,
module_inst);
bh_assert(mod_id != ID_NONE);
am_register_resource(url, module_request_handler, mod_id);
}
}
@ -73,6 +75,7 @@ wasm_post_request(wasm_module_inst_t module_inst,
// set sender to help dispatch the response to the sender ap
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App,
module_inst);
bh_assert(mod_id != ID_NONE);
req->sender = mod_id;
if (req->action == COAP_EVENT) {
@ -98,6 +101,7 @@ wasm_sub_event(wasm_module_inst_t module_inst, int32 url_offset)
unsigned int mod_id = app_manager_get_module_id(Module_WASM_App,
module_inst);
bh_assert(mod_id != ID_NONE);
am_register_event(url, mod_id);
}
}

View File

@ -143,27 +143,34 @@ 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(module_inst), interval, is_period,
auto_start);
timer_ctx_t timer_ctx = get_wasm_timer_ctx(module_inst);
bh_assert(timer_ctx);
return sys_create_timer(timer_ctx, 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(module_inst), timer_id);
timer_ctx_t timer_ctx = get_wasm_timer_ctx(module_inst);
bh_assert(timer_ctx);
sys_timer_destroy(timer_ctx, timer_id);
}
void
wasm_timer_cancel(wasm_module_inst_t module_inst, timer_id_t timer_id)
{
sys_timer_cancel(get_wasm_timer_ctx(module_inst), timer_id);
timer_ctx_t timer_ctx = get_wasm_timer_ctx(module_inst);
bh_assert(timer_ctx);
sys_timer_cancel(timer_ctx, 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(module_inst), timer_id, interval);
timer_ctx_t timer_ctx = get_wasm_timer_ctx(module_inst);
bh_assert(timer_ctx);
sys_timer_restart(timer_ctx, timer_id, interval);
}
extern uint32 get_sys_tick_ms();

View File

@ -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));

View File

@ -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) {

View File

@ -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));

View File

@ -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})

View File

@ -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)

View File

@ -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;

View File

@ -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:

View File

@ -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;

View File

@ -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;

View File

@ -7,6 +7,10 @@
#include "wasm_export.h"
#include "wasm_log.h"
#include "wasm_platform_log.h"
#include "bh_common.h"
#if WASM_ENABLE_WASI != 0
#include "wasi_wrapper.h"
#endif
void
wasm_runtime_set_exception(wasm_module_inst_t module, const char *exception);
@ -52,7 +56,7 @@ enum pad_type {
typedef char *_va_list;
#define _INTSIZEOF(n) \
((sizeof(n) + 3) & ~3)
(((uint32)sizeof(n) + 3) & (uint32)~3)
#define _va_arg(ap, t) \
(*(t*)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)))
@ -86,7 +90,7 @@ _printf_hex_uint(out_func_t out, void *ctx,
if (nibble || found_largest_digit || size == 1) {
found_largest_digit = 1;
nibble += nibble > 9 ? 87 : 48;
nibble = (char)(nibble + (nibble > 9 ? 87 : 48));
out((int) nibble, ctx);
digits++;
continue;
@ -250,7 +254,7 @@ _vprintf_wa(out_func_t out, void *ctx, const char *fmt, _va_list ap,
d = -d;
min_width--;
}
_printf_dec_uint(out, ctx, d, padding, min_width);
_printf_dec_uint(out, ctx, (uint32)d, padding, min_width);
break;
}
case 'u': {
@ -301,8 +305,8 @@ _vprintf_wa(out_func_t out, void *ctx, const char *fmt, _va_list ap,
char *start;
int32 s_offset;
CHECK_VA_ARG(ap, uint32);
s_offset = _va_arg(ap, uint32);
CHECK_VA_ARG(ap, int32);
s_offset = _va_arg(ap, int32);
if (!validate_app_str_addr(s_offset)) {
return false;
@ -314,7 +318,7 @@ _vprintf_wa(out_func_t out, void *ctx, const char *fmt, _va_list ap,
out((int) (*s++), ctx);
if (padding == PAD_SPACE_AFTER) {
int remaining = min_width - (s - start);
int remaining = min_width - (int32)(s - start);
while (remaining-- > 0) {
out(' ', ctx);
}
@ -356,8 +360,8 @@ fail:
struct str_context {
char *str;
int max;
int count;
uint32 max;
uint32 count;
};
static int
@ -371,7 +375,7 @@ sprintf_out(int c, struct str_context *ctx)
if (ctx->count == ctx->max - 1) {
ctx->str[ctx->count++] = '\0';
} else {
ctx->str[ctx->count++] = c;
ctx->str[ctx->count++] = (char)c;
}
return c;
@ -432,7 +436,7 @@ _printf_wrapper(wasm_module_inst_t module_inst,
if (!_vprintf_wa((out_func_t)printf_out, &ctx, fmt, va_args, module_inst))
return 0;
return ctx.count;
return (int)ctx.count;
}
static int
@ -457,7 +461,7 @@ _sprintf_wrapper(wasm_module_inst_t module_inst,
return 0;
ctx.str = str;
ctx.max = app_end_offset - str_offset;
ctx.max = (uint32)(app_end_offset - str_offset);
ctx.count = 0;
if (!_vprintf_wa((out_func_t)sprintf_out, &ctx, fmt, va_args, module_inst))
@ -467,12 +471,12 @@ _sprintf_wrapper(wasm_module_inst_t module_inst,
str[ctx.count] = '\0';
}
return ctx.count;
return (int)ctx.count;
}
static int
_snprintf_wrapper(wasm_module_inst_t module_inst,
int32 str_offset, int32 size, int32 fmt_offset,
int32 str_offset, uint32 size, int32 fmt_offset,
int32 va_list_offset)
{
struct str_context ctx;
@ -499,7 +503,7 @@ _snprintf_wrapper(wasm_module_inst_t module_inst,
str[ctx.count] = '\0';
}
return ctx.count;
return (int)ctx.count;
}
static int
@ -536,21 +540,28 @@ _strdup_wrapper(wasm_module_inst_t module_inst,
str = addr_app_to_native(str_offset);
if (str) {
len = strlen(str) + 1;
len = (uint32)strlen(str) + 1;
str_ret_offset = module_malloc(len);
if (str_ret_offset) {
str_ret = addr_app_to_native(str_ret_offset);
memcpy(str_ret, str, len);
bh_memcpy_s(str_ret, len, str, len);
}
}
return str_ret_offset;
}
static int32
__strdup_wrapper(wasm_module_inst_t module_inst,
int32 str_offset)
{
return _strdup_wrapper(module_inst, str_offset);
}
static int32
_memcmp_wrapper(wasm_module_inst_t module_inst,
int32 s1_offset, int32 s2_offset, int32 size)
int32 s1_offset, int32 s2_offset, uint32 size)
{
void *s1, *s2;
@ -565,7 +576,7 @@ _memcmp_wrapper(wasm_module_inst_t module_inst,
static int32
_memcpy_wrapper(wasm_module_inst_t module_inst,
int32 dst_offset, int32 src_offset, int32 size)
int32 dst_offset, int32 src_offset, uint32 size)
{
void *dst, *src;
@ -578,13 +589,13 @@ _memcpy_wrapper(wasm_module_inst_t module_inst,
dst = addr_app_to_native(dst_offset);
src = addr_app_to_native(src_offset);
memcpy(dst, src, size);
bh_memcpy_s(dst, size, src, size);
return dst_offset;
}
static int32
_memmove_wrapper(wasm_module_inst_t module_inst,
int32 dst_offset, int32 src_offset, int32 size)
int32 dst_offset, int32 src_offset, uint32 size)
{
void *dst, *src;
@ -600,7 +611,7 @@ _memmove_wrapper(wasm_module_inst_t module_inst,
static int32
_memset_wrapper(wasm_module_inst_t module_inst,
int32 s_offset, int32 c, int32 size)
int32 s_offset, int32 c, uint32 size)
{
void *s;
@ -668,7 +679,7 @@ _strcpy_wrapper(wasm_module_inst_t module_inst,
return 0;
src = addr_app_to_native(src_offset);
len = strlen(src);
len = (uint32)strlen(src);
if (!validate_app_addr(dst_offset, len + 1))
return 0;
@ -704,7 +715,7 @@ _strlen_wrapper(wasm_module_inst_t module_inst,
return 0;
s = addr_app_to_native(s_offset);
return strlen(s);
return (uint32)strlen(s);
}
static int32
@ -719,13 +730,13 @@ _calloc_wrapper(wasm_module_inst_t module_inst,
uint32 nmemb, uint32 size)
{
uint64 total_size = (uint64) nmemb * (uint64) size;
uint32 ret_offset = 0;
int32 ret_offset = 0;
uint8 *ret_ptr;
if (total_size > UINT32_MAX)
total_size = UINT32_MAX;
if (total_size >= UINT32_MAX)
return 0;
ret_offset = module_malloc((uint32 )total_size);
ret_offset = module_malloc((uint32)total_size);
if (ret_offset) {
ret_ptr = addr_app_to_native(ret_offset);
memset(ret_ptr, 0, (uint32) total_size);
@ -743,6 +754,245 @@ _free_wrapper(wasm_module_inst_t module_inst,
return module_free(ptr_offset);
}
static int32
_atoi_wrapper(wasm_module_inst_t module_inst,
int32 s_offset)
{
char *str;
if (!validate_app_str_addr(s_offset))
return 0;
str = addr_app_to_native(s_offset);
return atoi(str);
}
static int32
_bsearch_wrapper(wasm_module_inst_t module_inst,
int32 key_offset, /* const void * */
int32 array_offset, /* const void * */
uint32 count,
uint32 size,
int32 cmp_index)
{
wasm_runtime_set_exception(module_inst, "bsearch not implemented.");
return 0;
}
static void
_exit_wrapper(wasm_module_inst_t module_inst,
int32 status)
{
char buf[32];
snprintf(buf, sizeof(buf), "env.exit(%i)", status);
wasm_runtime_set_exception(module_inst, buf);
}
static int32
_strtol_wrapper(wasm_module_inst_t module_inst,
int32 nptr_offset, /* const char * */
int32 endptr_offset, /* char ** */
int32 base)
{
char *nptr, **endptr;
int32 num = 0;
if (!validate_app_str_addr(nptr_offset)
|| !validate_app_addr(endptr_offset, sizeof(int32)))
return 0;
nptr = addr_app_to_native(nptr_offset);
endptr = addr_app_to_native(endptr_offset);
num = (int32)strtol(nptr, endptr, base);
*(int32 *)endptr = addr_native_to_app(*endptr);
return num;
}
static uint32
_strtoul_wrapper(wasm_module_inst_t module_inst,
int32 nptr_offset, /* const char * */
int32 endptr_offset, /* char ** */
int32 base)
{
char *nptr, **endptr;
uint32 num = 0;
if (!validate_app_str_addr(nptr_offset)
|| !validate_app_addr(endptr_offset, sizeof(int32)))
return 0;
nptr = addr_app_to_native(nptr_offset);
endptr = addr_app_to_native(endptr_offset);
num = (uint32)strtoul(nptr, endptr, base);
*(int32 *)endptr = addr_native_to_app(*endptr);
return num;
}
static int32
_memchr_wrapper(wasm_module_inst_t module_inst,
int32 s_offset, /* const void * */
int32 c,
uint32 n)
{
void *s, *res;
if (!validate_app_addr(s_offset, n))
return 0;
s = (void*)addr_app_to_native(s_offset);
res = memchr(s, c, n);
return addr_native_to_app(res);
}
static int32
_strncasecmp_wrapper(wasm_module_inst_t module_inst,
int32 s1_offset, /* const char * */
int32 s2_offset, /* const char * */
uint32 n)
{
char *s1, *s2;
if (!validate_app_str_addr(s1_offset)
|| !validate_app_str_addr(s2_offset))
return 0;
s1 = addr_app_to_native(s1_offset);
s2 = addr_app_to_native(s2_offset);
return strncasecmp(s1, s2, n);
}
static uint32
_strspn_wrapper(wasm_module_inst_t module_inst,
int32 s_offset, /* const char * */
int32 accept_offset) /* const char * */
{
char *s, *accept;
if (!validate_app_str_addr(s_offset)
|| !validate_app_str_addr(accept_offset))
return 0;
s = addr_app_to_native(s_offset);
accept = addr_app_to_native(accept_offset);
return (uint32)strspn(s, accept);
}
static uint32
_strcspn_wrapper(wasm_module_inst_t module_inst,
int32 s_offset, /* const char * */
int32 reject_offset) /* const char * */
{
char *s, *reject;
if (!validate_app_str_addr(s_offset)
|| !validate_app_str_addr(reject_offset))
return 0;
s = addr_app_to_native(s_offset);
reject = addr_app_to_native(reject_offset);
return (uint32)strcspn(s, reject);
}
static int32
_strstr_wrapper(wasm_module_inst_t module_inst,
int32 s_offset, /* const char * */
int32 find_offset) /* const char * */
{
char *s, *find, *res;
if (!validate_app_str_addr(s_offset)
|| !validate_app_str_addr(find_offset))
return 0;
s = addr_app_to_native(s_offset);
find = addr_app_to_native(find_offset);
res = strstr(s, find);
return addr_native_to_app(res);
}
static int32
_isupper_wrapper(wasm_module_inst_t module_inst,
int32 c)
{
return isupper(c);
}
static int32
_isalpha_wrapper(wasm_module_inst_t module_inst,
int32 c)
{
return isalpha(c);
}
static int32
_isspace_wrapper(wasm_module_inst_t module_inst,
int32 c)
{
return isspace(c);
}
static int32
_isgraph_wrapper(wasm_module_inst_t module_inst,
int32 c)
{
return isgraph(c);
}
static int32
_isprint_wrapper(wasm_module_inst_t module_inst,
int32 c)
{
return isprint(c);
}
static int32
_isdigit_wrapper(wasm_module_inst_t module_inst,
int32 c)
{
return isdigit(c);
}
static int32
_isxdigit_wrapper(wasm_module_inst_t module_inst,
int32 c)
{
return isxdigit(c);
}
static int32
_tolower_wrapper(wasm_module_inst_t module_inst,
int32 c)
{
return tolower(c);
}
static int32
_toupper_wrapper(wasm_module_inst_t module_inst,
int32 c)
{
return toupper(c);
}
static int32
_isalnum_wrapper(wasm_module_inst_t module_inst,
int32 c)
{
return isalnum(c);
}
static void
setTempRet0_wrapper(wasm_module_inst_t module_inst,
uint32 temp_ret)
@ -842,7 +1092,7 @@ _emscripten_memcpy_big_wrapper(wasm_module_inst_t module_inst,
dst = addr_app_to_native(dst_offset);
src = addr_app_to_native(src_offset);
memcpy(dst, src, size);
bh_memcpy_s(dst, size, src, size);
return dst_offset;
}
@ -873,6 +1123,36 @@ nullFunc_X_wrapper(wasm_module_inst_t module_inst,
wasm_runtime_set_exception(module_inst, buf);
}
static int32
__cxa_allocate_exception_wrapper(wasm_module_inst_t module_inst,
uint32 thrown_size)
{
int32 exception = module_malloc(thrown_size);
if (!exception)
return 0;
return exception;
}
static void
__cxa_begin_catch_wrapper(wasm_module_inst_t module_inst,
int32 exception_object_offset)
{
}
static void
__cxa_throw_wrapper(wasm_module_inst_t module_inst,
int32 thrown_exception_offset,
int32 tinfo_offset,
uint32 table_elem_idx)
{
char buf[32];
snprintf(buf, sizeof(buf), "%s", "exception thrown by stdc++");
wasm_runtime_set_exception(module_inst, buf);
}
/*#define ENABLE_SPEC_TEST 1*/
#ifdef ENABLE_SPEC_TEST
@ -922,7 +1202,29 @@ static WASMNativeFuncDef native_func_defs[] = {
REG_NATIVE_FUNC(env, _malloc),
REG_NATIVE_FUNC(env, _calloc),
REG_NATIVE_FUNC(env, _strdup),
/* clang may introduce __strdup */
REG_NATIVE_FUNC(env, __strdup),
REG_NATIVE_FUNC(env, _free),
REG_NATIVE_FUNC(env, _atoi),
REG_NATIVE_FUNC(env, _bsearch),
REG_NATIVE_FUNC(env, _exit),
REG_NATIVE_FUNC(env, _strtol),
REG_NATIVE_FUNC(env, _strtoul),
REG_NATIVE_FUNC(env, _memchr),
REG_NATIVE_FUNC(env, _strncasecmp),
REG_NATIVE_FUNC(env, _strspn),
REG_NATIVE_FUNC(env, _strcspn),
REG_NATIVE_FUNC(env, _strstr),
REG_NATIVE_FUNC(env, _isupper),
REG_NATIVE_FUNC(env, _isalpha),
REG_NATIVE_FUNC(env, _isspace),
REG_NATIVE_FUNC(env, _isgraph),
REG_NATIVE_FUNC(env, _isprint),
REG_NATIVE_FUNC(env, _isdigit),
REG_NATIVE_FUNC(env, _isxdigit),
REG_NATIVE_FUNC(env, _tolower),
REG_NATIVE_FUNC(env, _toupper),
REG_NATIVE_FUNC(env, _isalnum),
REG_NATIVE_FUNC(env, setTempRet0),
REG_NATIVE_FUNC(env, getTempRet0),
REG_NATIVE_FUNC(env, _llvm_bswap_i16),
@ -934,7 +1236,10 @@ static WASMNativeFuncDef native_func_defs[] = {
REG_NATIVE_FUNC(env, _emscripten_memcpy_big),
REG_NATIVE_FUNC(env, abort),
REG_NATIVE_FUNC(env, abortStackOverflow),
REG_NATIVE_FUNC(env, nullFunc_X)
REG_NATIVE_FUNC(env, nullFunc_X),
REG_NATIVE_FUNC(env, __cxa_allocate_exception),
REG_NATIVE_FUNC(env, __cxa_begin_catch),
REG_NATIVE_FUNC(env, __cxa_throw)
};
void*
@ -960,6 +1265,11 @@ wasm_native_func_lookup(const char *module_name, const char *func_name)
if ((ret = wasm_platform_native_func_lookup(module_name, func_name)))
return ret;
#if WASM_ENABLE_WASI != 0
if ((ret = wasi_native_func_lookup(module_name, func_name)))
return ret;
#endif
return NULL;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,54 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#ifndef _WASI_WRAPPER_H
#define _WASI_WRAPPER_H
#include "wasmtime_ssp.h"
#include "posix.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef __wasi_errno_t wasi_errno_t;
typedef __wasi_fd_t wasi_fd_t;
typedef __wasi_clockid_t wasi_clockid_t;
typedef __wasi_timestamp_t wasi_timestamp_t;
typedef __wasi_prestat_t wasi_prestat_t;
typedef __wasi_iovec_t wasi_iovec_t;
typedef __wasi_ciovec_t wasi_ciovec_t;
typedef __wasi_filetype_t wasi_filetype_t;
typedef __wasi_filesize_t wasi_filesize_t;
typedef __wasi_filedelta_t wasi_filedelta_t;
typedef __wasi_whence_t wasi_whence_t;
typedef __wasi_fdstat_t wasi_fdstat_t;
typedef __wasi_fdflags_t wasi_fdflags_t;
typedef __wasi_rights_t wasi_rights_t;
typedef __wasi_advice_t wasi_advice_t;
typedef __wasi_lookupflags_t wasi_lookupflags_t;
typedef __wasi_oflags_t wasi_oflags_t;
typedef __wasi_dircookie_t wasi_dircookie_t;
typedef __wasi_filestat_t wasi_filestat_t;
typedef __wasi_fstflags_t wasi_fstflags_t;
typedef __wasi_subscription_t wasi_subscription_t;
typedef __wasi_event_t wasi_event_t;
typedef __wasi_exitcode_t wasi_exitcode_t;
typedef __wasi_signal_t wasi_signal_t;
typedef __wasi_riflags_t wasi_riflags_t;
typedef __wasi_roflags_t wasi_roflags_t;
typedef __wasi_siflags_t wasi_siflags_t;
typedef __wasi_sdflags_t wasi_sdflags_t;
typedef __wasi_dircookie_t wasi_dircookie_t;
typedef __wasi_preopentype_t wasi_preopentype_t;
void*
wasi_native_func_lookup(const char *module_name, const char *func_name);
#ifdef __cplusplus
}
#endif
#endif /* end of _WASI_WRAPPER_H */