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

@ -4,6 +4,7 @@
*/
#include "bh_platform.h"
#include "bh_common.h"
#include <sys/stat.h>
#include <fcntl.h>
@ -11,9 +12,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;
}
@ -23,11 +29,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) {
@ -48,7 +54,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");
@ -56,7 +62,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

@ -20,8 +20,9 @@
#include <stdarg.h>
#include <ctype.h>
#include <pthread.h>
#include <limits.h>
#include <semaphore.h>
#include <limits.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
@ -98,7 +99,7 @@ int b_strcpy_s(char * s1, size_t s1max, const char * s2);
int fopen_s(FILE ** pFile, const char *filename, const char *mode);
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

@ -16,7 +16,7 @@
*/
uint64 _bh_time_get_tick_millisecond()
{
return sysconf(_SC_CLK_TCK);
return (uint64)sysconf(_SC_CLK_TCK);
}
/*
@ -30,12 +30,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);
}
/*
@ -48,12 +48,13 @@ uint64 _bh_time_get_millisecond_from_1970()
ftime(&tp);
return ((uint64) tp.time) * 1000 + tp.millitm
- (tp.dstflag == 0 ? 0 : 60 * 60 * 1000) + tp.timezone * 60 * 1000;
- (tp.dstflag == 0 ? 0 : 60 * 60 * 1000)
+ ((uint64)tp.timezone) * 60 * 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 timeb tp;
struct tm *ltp;