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

@ -88,7 +88,8 @@ CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item) {
CJSON_PUBLIC(const char*) cJSON_Version(void)
{
static char version[15];
sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, CJSON_VERSION_PATCH);
snprintf(version, sizeof(version), "%i.%i.%i",
CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, CJSON_VERSION_PATCH);
return version;
}
@ -446,20 +447,20 @@ static cJSON_bool print_number(const cJSON * const item,
/* This checks for NaN and Infinity */
if ((d * 0) != 0) {
length = sprintf((char*) number_buffer, "null");
length = snprintf((char*) number_buffer, sizeof(number_buffer), "null");
} else {
/* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */
length = sprintf((char*) number_buffer, "%1.15g", d);
length = snprintf((char*) number_buffer, sizeof(number_buffer), "%1.15g", d);
/* Check whether the original double can be recovered */
if ((sscanf((char*) number_buffer, "%lg", &test) != 1)
|| ((double) test != d)) {
/* If not, print with 17 decimal places of precision */
length = sprintf((char*) number_buffer, "%1.17g", d);
length = snprintf((char*) number_buffer, sizeof(number_buffer), "%1.17g", d);
}
}
/* sprintf failed or buffer overrun occured */
/* snprintf failed or buffer overrun occured */
if ((length < 0) || (length > (int) (sizeof(number_buffer) - 1))) {
return false;
}
@ -748,7 +749,7 @@ static cJSON_bool print_string_ptr(const unsigned char * const input,
printbuffer * const output_buffer)
{
const unsigned char *input_pointer = NULL;
unsigned char *output = NULL;
unsigned char *output = NULL, *output_end;
unsigned char *output_pointer = NULL;
size_t output_length = 0;
/* numbers of additional characters needed for escaping */
@ -796,6 +797,7 @@ static cJSON_bool print_string_ptr(const unsigned char * const input,
if (output == NULL) {
return false;
}
output_end = output + output_length + sizeof("\"\"");
/* no characters have to be escaped */
if (escape_characters == 0) {
@ -843,7 +845,8 @@ static cJSON_bool print_string_ptr(const unsigned char * const input,
break;
default:
/* escape and print as unicode codepoint */
sprintf((char*) output_pointer, "u%04x", *input_pointer);
snprintf((char*) output_pointer, output_end - output_pointer,
"u%04x", *input_pointer);
output_pointer += 4;
break;
}

View File

@ -298,7 +298,7 @@ static int subscribe(reg_info *info)
p = strtok(info->urls, ",");
while(p != NULL) {
char url[URL_MAX_LEN] = {0};
sprintf(url, "%s%s", "/event/", p);
snprintf(url, URL_MAX_LEN, "%s%s", "/event/", p);
init_request(request,
url,
COAP_PUT,
@ -312,7 +312,7 @@ static int subscribe(reg_info *info)
#else
char url[URL_MAX_LEN] = { 0 };
char *prefix = info->urls[0] == '/' ? "/event" : "/event/";
sprintf(url, "%s%s", prefix, info->urls);
snprintf(url, URL_MAX_LEN, "%s%s", prefix, info->urls);
init_request(request, url, COAP_PUT,
FMT_ATTR_CONTAINER,
NULL, 0);
@ -332,7 +332,7 @@ static int unsubscribe(unreg_info *info)
p = strtok(info->urls, ",");
while(p != NULL) {
char url[URL_MAX_LEN] = {0};
sprintf(url, "%s%s", "/event/", p);
snprintf(url, URL_MAX_LEN, "%s%s", "/event/", p);
init_request(request,
url,
COAP_DELETE,
@ -345,7 +345,7 @@ static int unsubscribe(unreg_info *info)
}
#else
char url[URL_MAX_LEN] = { 0 };
sprintf(url, "%s%s", "/event/", info->urls);
snprintf(url, URL_MAX_LEN, "%s%s", "/event/", info->urls);
init_request(request, url, COAP_DELETE,
FMT_ATTR_CONTAINER,
NULL, 0);
@ -777,7 +777,7 @@ int main(int argc, char *argv[])
int ret;
imrt_link_recv_context_t recv_ctx = { 0 };
char buffer[BUF_SIZE] = { 0 };
uint32_t last_check, total_elpased_ms = 0;
uint32_t last_check = 0, total_elpased_ms = 0;
bool is_responsed = false;
operation op;

View File

@ -10,8 +10,16 @@
extern "C" {
#endif
int isupper(int c);
int isalpha(int c);
int isspace(int c);
int isgraph(int c);
int isprint(int c);
int isdigit(int c);
int isxdigit(int c);
int tolower(int c);
int toupper(int c);
int isalnum(int c);
#ifdef __cplusplus
}

View File

@ -10,8 +10,22 @@
extern "C" {
#endif
#define CHAR_BIT 8
#define SCHAR_MIN -128
#define SCHAR_MAX 127
#define UCHAR_MAX 255
#define CHAR_MIN 0
#define CHAR_MAX 127
#define MB_LEN_MAX 1
#define SHRT_MIN -32768
#define SHRT_MAX +32767
#define USHRT_MAX 65535
#define INT_MIN -32768
#define INT_MAX +32767
#define UINT_MAX 65535
#define LONG_MIN -2147483648
#define LONG_MAX +2147483647
#define ULONG_MAX 4294967295
#ifdef __cplusplus
}

View File

@ -10,6 +10,10 @@
extern "C" {
#endif
#ifndef NULL
# define NULL ((void*) 0)
#endif
typedef unsigned int size_t;
int printf(const char *format, ...);

View File

@ -12,6 +12,10 @@ extern "C" {
typedef unsigned int size_t;
int atoi(const char *s);
void exit(int status);
long strtol(const char *nptr, char **endptr, register int base);
unsigned long strtoul(const char *nptr, char **endptr, register int base)
void *malloc(size_t size);
void *calloc(size_t n, size_t size);
void free(void *ptr);

View File

@ -16,6 +16,11 @@ int memcmp(const void *s1, const void *s2, size_t n);
void *memcpy(void *dest, const void *src, size_t n);
void *memmove(void *dest, const void *src, size_t n);
void *memset(void *s, int c, size_t n);
void *memchr(const void *s, int c, size_t n);
int strncasecmp(const char *s1, const char *s2, size_t n);
size_t strspn(const char *s, const char *accept);
size_t strcspn(const char *s, const char *reject);
char *strstr(const char *s, const char *find);
char *strchr(const char *s, int c);
int strcmp(const char *s1, const char *s2);
char *strcpy(char *dest, const char *src);

View File

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

View File

@ -47,10 +47,30 @@ malloc
calloc
strdup
free
atoi
bsearch
exit
strtol
strtoul
memchr
strncasecmp
strspn
strcspn
strstr
isupper
isalpha
isspace
isgraph
isprint
isdigit
isxdigit
tolower
toupper
isalnum
llvm_bswap_i16
llvm_bswap_i32
bitshift64Lshr
bitshift64Shl
llvm_stackrestore
llvm_stacksave
emscripten_memcpy_big
emscripten_memcpy_big