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

@ -41,8 +41,9 @@ int b_strcat_s(char * s1, size_t s1max, const char * s2)
int b_strcpy_s(char * s1, size_t s1max, const char * s2)
{
if (NULL == s1|| NULL == s2
|| s1max < (strlen(s2) + 1) || s1max > RSIZE_MAX) {
if (NULL == s1 || NULL == s2
|| s1max < (strlen(s2) + 1)
|| s1max > RSIZE_MAX) {
return -1;
}

View File

@ -4,6 +4,7 @@
*/
#include "bh_platform.h"
#include "bh_common.h"
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
@ -15,9 +16,14 @@
char *bh_strdup(const char *s)
{
uint32 size;
char *s1 = NULL;
if (s && (s1 = bh_malloc(strlen(s) + 1)))
memcpy(s1, s, strlen(s) + 1);
if (s) {
size = (uint32)(strlen(s) + 1);
if ((s1 = bh_malloc(size)))
bh_memcpy_s(s1, size, s, size);
}
return s1;
}
@ -27,11 +33,11 @@ int bh_platform_init()
}
char*
bh_read_file_to_buffer(const char *filename, int *ret_size)
bh_read_file_to_buffer(const char *filename, uint32 *ret_size)
{
char *buffer;
int file;
int file_size, read_size;
uint32 file_size, read_size;
struct stat stat_buf;
if (!filename || !ret_size) {
@ -52,7 +58,7 @@ bh_read_file_to_buffer(const char *filename, int *ret_size)
return NULL;
}
file_size = stat_buf.st_size;
file_size = (uint32)stat_buf.st_size;
if (!(buffer = bh_malloc(file_size))) {
printf("Read file to buffer failed: alloc memory failed.\n");
@ -60,7 +66,7 @@ bh_read_file_to_buffer(const char *filename, int *ret_size)
return NULL;
}
read_size = read(file, buffer, file_size);
read_size = (uint32)read(file, buffer, file_size);
close(file);
if (read_size < file_size) {

View File

@ -22,6 +22,7 @@
#include <ctype.h>
#include <pthread.h>
#include <limits.h>
#include <fcntl.h>
#include <semaphore.h>
#include <errno.h>
@ -96,7 +97,7 @@ int b_memcpy_s(void * s1, unsigned int s1max, const void * s2,
int b_strcat_s(char * s1, size_t s1max, const char * s2);
int b_strcpy_s(char * s1, size_t s1max, const char * s2);
char *bh_read_file_to_buffer(const char *filename, int *ret_size);
char *bh_read_file_to_buffer(const char *filename, uint32 *ret_size);
char *bh_strdup(const char *s);

View File

@ -56,7 +56,7 @@ void vm_thread_sys_destroy(void)
typedef struct {
thread_start_routine_t start;
void* stack;
int stack_size;
uint32 stack_size;
void* arg;
} thread_wrapper_arg;
@ -64,7 +64,7 @@ static void *vm_thread_wrapper(void *arg)
{
thread_wrapper_arg * targ = arg;
LOG_VERBOSE("THREAD CREATE 0x%08x\n", &targ);
targ->stack = (void *)((uintptr_t)(&arg) & ~0xfff);
targ->stack = (void *)((uintptr_t)(&arg) & (uintptr_t)~0xfff);
_vm_tls_put(1, targ);
targ->start(targ->arg);
bh_free(targ);
@ -73,7 +73,7 @@ static void *vm_thread_wrapper(void *arg)
}
int _vm_thread_create_with_prio(korp_tid *tid, thread_start_routine_t start,
void *arg, unsigned int stack_size, int prio)
void *arg, unsigned int stack_size, int prio)
{
pthread_attr_t tattr;
thread_wrapper_arg *targ;
@ -114,7 +114,7 @@ int _vm_thread_create_with_prio(korp_tid *tid, thread_start_routine_t start,
}
int _vm_thread_create(korp_tid *tid, thread_start_routine_t start, void *arg,
unsigned int stack_size)
unsigned int stack_size)
{
return _vm_thread_create_with_prio(tid, start, arg, stack_size,
BH_THREAD_DEFAULT_PRIORITY);
@ -261,7 +261,7 @@ int _vm_sem_reltimedwait(korp_sem *sem, int mills)
bh_assert(sem);
if (mills == BHT_WAIT_FOREVER) {
if (mills == (int)BHT_WAIT_FOREVER) {
ret = sem_wait(sem);
} else {
@ -329,8 +329,8 @@ static void msec_nsec_to_abstime(struct timespec *ts, int64 msec, int32 nsec)
gettimeofday(&tv, NULL);
ts->tv_sec = tv.tv_sec + msec / 1000;
ts->tv_nsec = tv.tv_usec * 1000 + (msec % 1000) * 1000000 + nsec;
ts->tv_sec = (long int)(tv.tv_sec + msec / 1000);
ts->tv_nsec = (long int)(tv.tv_usec * 1000 + (msec % 1000) * 1000000 + nsec);
if (ts->tv_nsec >= 1000000000L) {
ts->tv_sec++;
@ -343,7 +343,7 @@ int _vm_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, int mills)
int ret;
struct timespec abstime;
if (mills == BHT_WAIT_FOREVER)
if (mills == (int)BHT_WAIT_FOREVER)
ret = pthread_cond_wait(cond, mutex);
else {
msec_nsec_to_abstime(&abstime, mills, 0);

View File

@ -15,7 +15,7 @@
*/
uint64 _bh_time_get_tick_millisecond()
{
return sysconf(_SC_CLK_TCK);
return (uint64)sysconf(_SC_CLK_TCK);
}
/*
@ -29,12 +29,12 @@ uint64 _bh_time_get_boot_millisecond()
return 0;
}
return ((uint64) ts.tv_sec) * 1000 + ts.tv_nsec / (1000 * 1000);
return ((uint64) ts.tv_sec) * 1000 + ((uint64)ts.tv_nsec) / (1000 * 1000);
}
uint32 bh_get_tick_sec()
{
return _bh_time_get_boot_millisecond() / 1000;
return (uint32)(_bh_time_get_boot_millisecond() / 1000);
}
/*
@ -49,12 +49,12 @@ uint64 _bh_time_get_millisecond_from_1970()
return 0;
}
return ((uint64) ts.tv_sec) * 1000 + ts.tv_nsec / (1000 * 1000);
return ((uint64) ts.tv_sec) * 1000 + ((uint64)ts.tv_nsec) / (1000 * 1000);
}
size_t _bh_time_strftime(char *s, size_t max, const char *format, int64 time)
{
time_t time_sec = time / 1000;
time_t time_sec = (time_t)(time / 1000);
struct tm *ltp;
ltp = localtime(&time_sec);