Apply clang-format for core/iwasm compilation and libraries (#784)
Apply clang-format for core/iwasm/compilation and core/iwasm/libraries files. Add wasm-c-api empty_imports sample to workflow test. And enable triggering workflow when core/config.h changes.
This commit is contained in:
@ -29,9 +29,10 @@ void
|
||||
wasm_runtime_set_llvm_stack(wasm_module_inst_t module, uint32 llvm_stack);
|
||||
|
||||
uint32
|
||||
wasm_runtime_module_realloc(wasm_module_inst_t module, uint32 ptr,
|
||||
uint32 size, void **p_native_addr);
|
||||
wasm_runtime_module_realloc(wasm_module_inst_t module, uint32 ptr, uint32 size,
|
||||
void **p_native_addr);
|
||||
|
||||
/* clang-format off */
|
||||
#define get_module_inst(exec_env) \
|
||||
wasm_runtime_get_module_inst(exec_env)
|
||||
|
||||
@ -55,6 +56,7 @@ wasm_runtime_module_realloc(wasm_module_inst_t module, uint32 ptr,
|
||||
|
||||
#define module_free(offset) \
|
||||
wasm_runtime_module_free(module_inst, offset)
|
||||
/* clang-format on */
|
||||
|
||||
typedef int (*out_func_t)(int c, void *ctx);
|
||||
|
||||
@ -66,15 +68,14 @@ enum pad_type {
|
||||
};
|
||||
|
||||
typedef char *_va_list;
|
||||
#define _INTSIZEOF(n) \
|
||||
(((uint32)sizeof(n) + 3) & (uint32)~3)
|
||||
#define _va_arg(ap, t) \
|
||||
(*(t*)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)))
|
||||
#define _INTSIZEOF(n) (((uint32)sizeof(n) + 3) & (uint32)~3)
|
||||
#define _va_arg(ap, t) (*(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)))
|
||||
|
||||
#define CHECK_VA_ARG(ap, t) do { \
|
||||
if ((uint8*)ap + _INTSIZEOF(t) > native_end_addr) \
|
||||
goto fail; \
|
||||
} while (0)
|
||||
#define CHECK_VA_ARG(ap, t) \
|
||||
do { \
|
||||
if ((uint8 *)ap + _INTSIZEOF(t) > native_end_addr) \
|
||||
goto fail; \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* @brief Output an unsigned int in hex format
|
||||
@ -86,10 +87,8 @@ typedef char *_va_list;
|
||||
* @return N/A
|
||||
*/
|
||||
static void
|
||||
_printf_hex_uint(out_func_t out, void *ctx,
|
||||
const uint64 num, bool is_u64,
|
||||
enum pad_type padding,
|
||||
int min_width)
|
||||
_printf_hex_uint(out_func_t out, void *ctx, const uint64 num, bool is_u64,
|
||||
enum pad_type padding, int min_width)
|
||||
{
|
||||
int shift = sizeof(num) * 8;
|
||||
int found_largest_digit = 0;
|
||||
@ -97,14 +96,14 @@ _printf_hex_uint(out_func_t out, void *ctx,
|
||||
int digits = 0;
|
||||
char nibble;
|
||||
|
||||
while (shift >= 4) {
|
||||
shift -= 4;
|
||||
nibble = (num >> shift) & 0xf;
|
||||
while (shift >= 4) {
|
||||
shift -= 4;
|
||||
nibble = (num >> shift) & 0xf;
|
||||
|
||||
if (nibble || found_largest_digit || shift == 0) {
|
||||
found_largest_digit = 1;
|
||||
nibble = (char)(nibble + (nibble > 9 ? 87 : 48));
|
||||
out((int) nibble, ctx);
|
||||
out((int)nibble, ctx);
|
||||
digits++;
|
||||
continue;
|
||||
}
|
||||
@ -112,7 +111,8 @@ _printf_hex_uint(out_func_t out, void *ctx,
|
||||
if (remaining-- <= min_width) {
|
||||
if (padding == PAD_ZERO_BEFORE) {
|
||||
out('0', ctx);
|
||||
} else if (padding == PAD_SPACE_BEFORE) {
|
||||
}
|
||||
else if (padding == PAD_SPACE_BEFORE) {
|
||||
out(' ', ctx);
|
||||
}
|
||||
}
|
||||
@ -136,10 +136,8 @@ _printf_hex_uint(out_func_t out, void *ctx,
|
||||
* @return N/A
|
||||
*/
|
||||
static void
|
||||
_printf_dec_uint(out_func_t out, void *ctx,
|
||||
const uint32 num,
|
||||
enum pad_type padding,
|
||||
int min_width)
|
||||
_printf_dec_uint(out_func_t out, void *ctx, const uint32 num,
|
||||
enum pad_type padding, int min_width)
|
||||
{
|
||||
uint32 pos = 999999999;
|
||||
uint32 remainder = num;
|
||||
@ -155,17 +153,18 @@ _printf_dec_uint(out_func_t out, void *ctx,
|
||||
while (pos >= 9) {
|
||||
if (found_largest_digit || remainder > pos) {
|
||||
found_largest_digit = 1;
|
||||
out((int) ((remainder / (pos + 1)) + 48), ctx);
|
||||
out((int)((remainder / (pos + 1)) + 48), ctx);
|
||||
digits++;
|
||||
} else if (remaining <= min_width && padding < PAD_SPACE_AFTER) {
|
||||
out((int) (padding == PAD_ZERO_BEFORE ? '0' : ' '), ctx);
|
||||
}
|
||||
else if (remaining <= min_width && padding < PAD_SPACE_AFTER) {
|
||||
out((int)(padding == PAD_ZERO_BEFORE ? '0' : ' '), ctx);
|
||||
digits++;
|
||||
}
|
||||
remaining--;
|
||||
remainder %= (pos + 1);
|
||||
pos /= 10;
|
||||
}
|
||||
out((int) (remainder + 48), ctx);
|
||||
out((int)(remainder + 48), ctx);
|
||||
|
||||
if (padding == PAD_SPACE_AFTER) {
|
||||
remaining = min_width - digits;
|
||||
@ -193,8 +192,8 @@ _vprintf_wa(out_func_t out, void *ctx, const char *fmt, _va_list ap,
|
||||
int long_ctr = 0;
|
||||
uint8 *native_end_addr;
|
||||
|
||||
if (!wasm_runtime_get_native_addr_range(module_inst, (uint8*)ap,
|
||||
NULL, &native_end_addr))
|
||||
if (!wasm_runtime_get_native_addr_range(module_inst, (uint8 *)ap, NULL,
|
||||
&native_end_addr))
|
||||
goto fail;
|
||||
|
||||
/* fmt has already been adjusted if needed */
|
||||
@ -202,7 +201,7 @@ _vprintf_wa(out_func_t out, void *ctx, const char *fmt, _va_list ap,
|
||||
while (*fmt) {
|
||||
if (!might_format) {
|
||||
if (*fmt != '%') {
|
||||
out((int) *fmt, ctx);
|
||||
out((int)*fmt, ctx);
|
||||
}
|
||||
else {
|
||||
might_format = 1;
|
||||
@ -213,179 +212,188 @@ _vprintf_wa(out_func_t out, void *ctx, const char *fmt, _va_list ap,
|
||||
}
|
||||
else {
|
||||
switch (*fmt) {
|
||||
case '-':
|
||||
padding = PAD_SPACE_AFTER;
|
||||
goto still_might_format;
|
||||
|
||||
case '0':
|
||||
if (min_width < 0 && padding == PAD_NONE) {
|
||||
padding = PAD_ZERO_BEFORE;
|
||||
case '-':
|
||||
padding = PAD_SPACE_AFTER;
|
||||
goto still_might_format;
|
||||
|
||||
case '0':
|
||||
if (min_width < 0 && padding == PAD_NONE) {
|
||||
padding = PAD_ZERO_BEFORE;
|
||||
goto still_might_format;
|
||||
}
|
||||
goto handle_1_to_9;
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
handle_1_to_9:
|
||||
if (min_width < 0) {
|
||||
min_width = *fmt - '0';
|
||||
}
|
||||
else {
|
||||
min_width = 10 * min_width + *fmt - '0';
|
||||
}
|
||||
|
||||
if (padding == PAD_NONE) {
|
||||
padding = PAD_SPACE_BEFORE;
|
||||
}
|
||||
goto still_might_format;
|
||||
|
||||
case 'l':
|
||||
long_ctr++;
|
||||
/* Fall through */
|
||||
case 'z':
|
||||
case 'h':
|
||||
/* FIXME: do nothing for these modifiers */
|
||||
goto still_might_format;
|
||||
|
||||
case 'd':
|
||||
case 'i':
|
||||
{
|
||||
int32 d;
|
||||
|
||||
if (long_ctr < 2) {
|
||||
CHECK_VA_ARG(ap, int32);
|
||||
d = _va_arg(ap, int32);
|
||||
}
|
||||
else {
|
||||
int64 lld;
|
||||
CHECK_VA_ARG(ap, int64);
|
||||
lld = _va_arg(ap, int64);
|
||||
if (lld > INT32_MAX || lld < INT32_MIN) {
|
||||
print_err(out, ctx);
|
||||
break;
|
||||
}
|
||||
d = (int32)lld;
|
||||
}
|
||||
|
||||
if (d < 0) {
|
||||
out((int)'-', ctx);
|
||||
d = -d;
|
||||
min_width--;
|
||||
}
|
||||
_printf_dec_uint(out, ctx, (uint32)d, padding, min_width);
|
||||
break;
|
||||
}
|
||||
goto handle_1_to_9;
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
handle_1_to_9:
|
||||
if (min_width < 0) {
|
||||
min_width = *fmt - '0';
|
||||
} else {
|
||||
min_width = 10 * min_width + *fmt - '0';
|
||||
case 'u':
|
||||
{
|
||||
uint32 u;
|
||||
|
||||
if (long_ctr < 2) {
|
||||
CHECK_VA_ARG(ap, uint32);
|
||||
u = _va_arg(ap, uint32);
|
||||
}
|
||||
else {
|
||||
uint64 llu;
|
||||
CHECK_VA_ARG(ap, uint64);
|
||||
llu = _va_arg(ap, uint64);
|
||||
if (llu > INT32_MAX) {
|
||||
print_err(out, ctx);
|
||||
break;
|
||||
}
|
||||
u = (uint32)llu;
|
||||
}
|
||||
_printf_dec_uint(out, ctx, u, padding, min_width);
|
||||
break;
|
||||
}
|
||||
case 'p':
|
||||
out('0', ctx);
|
||||
out('x', ctx);
|
||||
/* left-pad pointers with zeros */
|
||||
padding = PAD_ZERO_BEFORE;
|
||||
min_width = 8;
|
||||
/* Fall through */
|
||||
case 'x':
|
||||
case 'X':
|
||||
{
|
||||
uint64 x;
|
||||
bool is_ptr = (*fmt == 'p') ? true : false;
|
||||
|
||||
if (long_ctr < 2) {
|
||||
CHECK_VA_ARG(ap, uint32);
|
||||
x = _va_arg(ap, uint32);
|
||||
}
|
||||
else {
|
||||
CHECK_VA_ARG(ap, uint64);
|
||||
x = _va_arg(ap, uint64);
|
||||
}
|
||||
_printf_hex_uint(out, ctx, x, !is_ptr, padding, min_width);
|
||||
break;
|
||||
}
|
||||
|
||||
if (padding == PAD_NONE) {
|
||||
padding = PAD_SPACE_BEFORE;
|
||||
}
|
||||
goto still_might_format;
|
||||
case 's':
|
||||
{
|
||||
char *s;
|
||||
char *start;
|
||||
uint32 s_offset;
|
||||
|
||||
case 'l':
|
||||
long_ctr++;
|
||||
/* Fall through */
|
||||
case 'z':
|
||||
case 'h':
|
||||
/* FIXME: do nothing for these modifiers */
|
||||
goto still_might_format;
|
||||
|
||||
case 'd':
|
||||
case 'i': {
|
||||
int32 d;
|
||||
|
||||
if (long_ctr < 2) {
|
||||
CHECK_VA_ARG(ap, int32);
|
||||
d = _va_arg(ap, int32);
|
||||
}
|
||||
else {
|
||||
int64 lld;
|
||||
CHECK_VA_ARG(ap, int64);
|
||||
lld = _va_arg(ap, int64);
|
||||
if (lld > INT32_MAX || lld < INT32_MIN) {
|
||||
print_err(out, ctx);
|
||||
break;
|
||||
s_offset = _va_arg(ap, uint32);
|
||||
|
||||
if (!validate_app_str_addr(s_offset)) {
|
||||
return false;
|
||||
}
|
||||
d = (int32)lld;
|
||||
}
|
||||
|
||||
if (d < 0) {
|
||||
out((int)'-', ctx);
|
||||
d = -d;
|
||||
min_width--;
|
||||
}
|
||||
_printf_dec_uint(out, ctx, (uint32)d, padding, min_width);
|
||||
break;
|
||||
}
|
||||
case 'u': {
|
||||
uint32 u;
|
||||
s = start = addr_app_to_native(s_offset);
|
||||
|
||||
if (long_ctr < 2) {
|
||||
CHECK_VA_ARG(ap, uint32);
|
||||
u = _va_arg(ap, uint32);
|
||||
}
|
||||
else {
|
||||
uint64 llu;
|
||||
CHECK_VA_ARG(ap, uint64);
|
||||
llu = _va_arg(ap, uint64);
|
||||
if (llu > INT32_MAX) {
|
||||
print_err(out, ctx);
|
||||
break;
|
||||
while (*s)
|
||||
out((int)(*s++), ctx);
|
||||
|
||||
if (padding == PAD_SPACE_AFTER) {
|
||||
int remaining = min_width - (int32)(s - start);
|
||||
while (remaining-- > 0) {
|
||||
out(' ', ctx);
|
||||
}
|
||||
}
|
||||
u = (uint32)llu;
|
||||
}
|
||||
_printf_dec_uint(out, ctx, u, padding, min_width);
|
||||
break;
|
||||
}
|
||||
case 'p':
|
||||
out('0', ctx);
|
||||
out('x', ctx);
|
||||
/* left-pad pointers with zeros */
|
||||
padding = PAD_ZERO_BEFORE;
|
||||
min_width = 8;
|
||||
/* Fall through */
|
||||
case 'x':
|
||||
case 'X': {
|
||||
uint64 x;
|
||||
bool is_ptr = (*fmt == 'p') ? true : false;
|
||||
|
||||
if (long_ctr < 2) {
|
||||
CHECK_VA_ARG(ap, uint32);
|
||||
x = _va_arg(ap, uint32);
|
||||
} else {
|
||||
CHECK_VA_ARG(ap, uint64);
|
||||
x = _va_arg(ap, uint64);
|
||||
}
|
||||
_printf_hex_uint(out, ctx, x, !is_ptr, padding, min_width);
|
||||
break;
|
||||
}
|
||||
|
||||
case 's': {
|
||||
char *s;
|
||||
char *start;
|
||||
uint32 s_offset;
|
||||
|
||||
CHECK_VA_ARG(ap, int32);
|
||||
s_offset = _va_arg(ap, uint32);
|
||||
|
||||
if (!validate_app_str_addr(s_offset)) {
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
s = start = addr_app_to_native(s_offset);
|
||||
|
||||
while (*s)
|
||||
out((int) (*s++), ctx);
|
||||
|
||||
if (padding == PAD_SPACE_AFTER) {
|
||||
int remaining = min_width - (int32)(s - start);
|
||||
while (remaining-- > 0) {
|
||||
out(' ', ctx);
|
||||
}
|
||||
case 'c':
|
||||
{
|
||||
int c;
|
||||
CHECK_VA_ARG(ap, int);
|
||||
c = _va_arg(ap, int);
|
||||
out(c, ctx);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'c': {
|
||||
int c;
|
||||
CHECK_VA_ARG(ap, int);
|
||||
c = _va_arg(ap, int);
|
||||
out(c, ctx);
|
||||
break;
|
||||
}
|
||||
case '%':
|
||||
{
|
||||
out((int)'%', ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
case '%': {
|
||||
out((int) '%', ctx);
|
||||
break;
|
||||
}
|
||||
case 'f':
|
||||
{
|
||||
float64 f64;
|
||||
char buf[16], *s;
|
||||
|
||||
case 'f': {
|
||||
float64 f64;
|
||||
char buf[16], *s;
|
||||
/* Make 8-byte aligned */
|
||||
ap = (_va_list)(((uintptr_t)ap + 7) & ~(uintptr_t)7);
|
||||
CHECK_VA_ARG(ap, float64);
|
||||
f64 = _va_arg(ap, float64);
|
||||
snprintf(buf, sizeof(buf), "%f", f64);
|
||||
s = buf;
|
||||
while (*s)
|
||||
out((int)(*s++), ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Make 8-byte aligned */
|
||||
ap = (_va_list)(((uintptr_t)ap + 7) & ~(uintptr_t)7);
|
||||
CHECK_VA_ARG(ap, float64);
|
||||
f64 = _va_arg(ap, float64);
|
||||
snprintf(buf, sizeof(buf), "%f", f64);
|
||||
s = buf;
|
||||
while (*s)
|
||||
out((int) (*s++), ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
out((int) '%', ctx);
|
||||
out((int) *fmt, ctx);
|
||||
break;
|
||||
default:
|
||||
out((int)'%', ctx);
|
||||
out((int)*fmt, ctx);
|
||||
break;
|
||||
}
|
||||
|
||||
might_format = 0;
|
||||
}
|
||||
|
||||
still_might_format:
|
||||
still_might_format:
|
||||
++fmt;
|
||||
}
|
||||
return true;
|
||||
@ -411,7 +419,8 @@ sprintf_out(int c, struct str_context *ctx)
|
||||
|
||||
if (ctx->count == ctx->max - 1) {
|
||||
ctx->str[ctx->count++] = '\0';
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
ctx->str[ctx->count++] = (char)c;
|
||||
}
|
||||
|
||||
@ -453,8 +462,7 @@ printf_out(int c, struct str_context *ctx)
|
||||
#endif
|
||||
|
||||
static int
|
||||
printf_wrapper(wasm_exec_env_t exec_env,
|
||||
const char * format, _va_list va_args)
|
||||
printf_wrapper(wasm_exec_env_t exec_env, const char *format, _va_list va_args)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
struct str_context ctx = { NULL, 0, 0 };
|
||||
@ -463,15 +471,16 @@ printf_wrapper(wasm_exec_env_t exec_env,
|
||||
if (!validate_native_addr(va_args, sizeof(int32)))
|
||||
return 0;
|
||||
|
||||
if (!_vprintf_wa((out_func_t)printf_out, &ctx, format, va_args, module_inst))
|
||||
if (!_vprintf_wa((out_func_t)printf_out, &ctx, format, va_args,
|
||||
module_inst))
|
||||
return 0;
|
||||
|
||||
return (int)ctx.count;
|
||||
}
|
||||
|
||||
static int
|
||||
sprintf_wrapper(wasm_exec_env_t exec_env,
|
||||
char *str, const char *format, _va_list va_args)
|
||||
sprintf_wrapper(wasm_exec_env_t exec_env, char *str, const char *format,
|
||||
_va_list va_args)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint8 *native_end_offset;
|
||||
@ -481,17 +490,18 @@ sprintf_wrapper(wasm_exec_env_t exec_env,
|
||||
if (!validate_native_addr(va_args, sizeof(uint32)))
|
||||
return 0;
|
||||
|
||||
if (!wasm_runtime_get_native_addr_range(module_inst, (uint8*)str,
|
||||
NULL, &native_end_offset)) {
|
||||
if (!wasm_runtime_get_native_addr_range(module_inst, (uint8 *)str, NULL,
|
||||
&native_end_offset)) {
|
||||
wasm_runtime_set_exception(module_inst, "out of bounds memory access");
|
||||
return false;
|
||||
}
|
||||
|
||||
ctx.str = str;
|
||||
ctx.max = (uint32)(native_end_offset - (uint8*)str);
|
||||
ctx.max = (uint32)(native_end_offset - (uint8 *)str);
|
||||
ctx.count = 0;
|
||||
|
||||
if (!_vprintf_wa((out_func_t)sprintf_out, &ctx, format, va_args, module_inst))
|
||||
if (!_vprintf_wa((out_func_t)sprintf_out, &ctx, format, va_args,
|
||||
module_inst))
|
||||
return 0;
|
||||
|
||||
if (ctx.count < ctx.max) {
|
||||
@ -516,7 +526,8 @@ snprintf_wrapper(wasm_exec_env_t exec_env, char *str, uint32 size,
|
||||
ctx.max = size;
|
||||
ctx.count = 0;
|
||||
|
||||
if (!_vprintf_wa((out_func_t)sprintf_out, &ctx, format, va_args, module_inst))
|
||||
if (!_vprintf_wa((out_func_t)sprintf_out, &ctx, format, va_args,
|
||||
module_inst))
|
||||
return 0;
|
||||
|
||||
if (ctx.count < ctx.max) {
|
||||
@ -551,7 +562,7 @@ strdup_wrapper(wasm_exec_env_t exec_env, const char *str)
|
||||
if (str) {
|
||||
len = (uint32)strlen(str) + 1;
|
||||
|
||||
str_ret_offset = module_malloc(len, (void**)&str_ret);
|
||||
str_ret_offset = module_malloc(len, (void **)&str_ret);
|
||||
if (str_ret_offset) {
|
||||
bh_memcpy_s(str_ret, len, str, len);
|
||||
}
|
||||
@ -567,21 +578,21 @@ _strdup_wrapper(wasm_exec_env_t exec_env, const char *str)
|
||||
}
|
||||
|
||||
static int32
|
||||
memcmp_wrapper(wasm_exec_env_t exec_env,
|
||||
const void *s1, const void *s2, uint32 size)
|
||||
memcmp_wrapper(wasm_exec_env_t exec_env, const void *s1, const void *s2,
|
||||
uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
|
||||
/* s2 has been checked by runtime */
|
||||
if (!validate_native_addr((void*)s1, size))
|
||||
if (!validate_native_addr((void *)s1, size))
|
||||
return 0;
|
||||
|
||||
return memcmp(s1, s2, size);
|
||||
}
|
||||
|
||||
static uint32
|
||||
memcpy_wrapper(wasm_exec_env_t exec_env,
|
||||
void *dst, const void *src, uint32 size)
|
||||
memcpy_wrapper(wasm_exec_env_t exec_env, void *dst, const void *src,
|
||||
uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 dst_offset = addr_native_to_app(dst);
|
||||
@ -598,8 +609,7 @@ memcpy_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static uint32
|
||||
memmove_wrapper(wasm_exec_env_t exec_env,
|
||||
void *dst, void *src, uint32 size)
|
||||
memmove_wrapper(wasm_exec_env_t exec_env, void *dst, void *src, uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 dst_offset = addr_native_to_app(dst);
|
||||
@ -616,8 +626,7 @@ memmove_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static uint32
|
||||
memset_wrapper(wasm_exec_env_t exec_env,
|
||||
void *s, int32 c, uint32 size)
|
||||
memset_wrapper(wasm_exec_env_t exec_env, void *s, int32 c, uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 s_offset = addr_native_to_app(s);
|
||||
@ -630,8 +639,7 @@ memset_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static uint32
|
||||
strchr_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *s, int32 c)
|
||||
strchr_wrapper(wasm_exec_env_t exec_env, const char *s, int32 c)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
char *ret;
|
||||
@ -642,21 +650,20 @@ strchr_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static int32
|
||||
strcmp_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *s1, const char *s2)
|
||||
strcmp_wrapper(wasm_exec_env_t exec_env, const char *s1, const char *s2)
|
||||
{
|
||||
/* s1 and s2 have been checked by runtime */
|
||||
return strcmp(s1, s2);
|
||||
}
|
||||
|
||||
static int32
|
||||
strncmp_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *s1, const char *s2, uint32 size)
|
||||
strncmp_wrapper(wasm_exec_env_t exec_env, const char *s1, const char *s2,
|
||||
uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
|
||||
/* s2 has been checked by runtime */
|
||||
if (!validate_native_addr((void*)s1, size))
|
||||
if (!validate_native_addr((void *)s1, size))
|
||||
return 0;
|
||||
|
||||
return strncmp(s1, s2, size);
|
||||
@ -681,8 +688,8 @@ strcpy_wrapper(wasm_exec_env_t exec_env, char *dst, const char *src)
|
||||
}
|
||||
|
||||
static uint32
|
||||
strncpy_wrapper(wasm_exec_env_t exec_env,
|
||||
char *dst, const char *src, uint32 size)
|
||||
strncpy_wrapper(wasm_exec_env_t exec_env, char *dst, const char *src,
|
||||
uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
|
||||
@ -716,14 +723,14 @@ static uint32
|
||||
calloc_wrapper(wasm_exec_env_t exec_env, uint32 nmemb, uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint64 total_size = (uint64) nmemb * (uint64) size;
|
||||
uint64 total_size = (uint64)nmemb * (uint64)size;
|
||||
uint32 ret_offset = 0;
|
||||
uint8 *ret_ptr;
|
||||
|
||||
if (total_size >= UINT32_MAX)
|
||||
return 0;
|
||||
|
||||
ret_offset = module_malloc((uint32)total_size, (void**)&ret_ptr);
|
||||
ret_offset = module_malloc((uint32)total_size, (void **)&ret_ptr);
|
||||
if (ret_offset) {
|
||||
memset(ret_ptr, 0, (uint32)total_size);
|
||||
}
|
||||
@ -767,8 +774,8 @@ exit_wrapper(wasm_exec_env_t exec_env, int32 status)
|
||||
}
|
||||
|
||||
static int32
|
||||
strtol_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *nptr, char **endptr, int32 base)
|
||||
strtol_wrapper(wasm_exec_env_t exec_env, const char *nptr, char **endptr,
|
||||
int32 base)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
int32 num = 0;
|
||||
@ -778,14 +785,14 @@ strtol_wrapper(wasm_exec_env_t exec_env,
|
||||
return 0;
|
||||
|
||||
num = (int32)strtol(nptr, endptr, base);
|
||||
*(uint32*)endptr = addr_native_to_app(*endptr);
|
||||
*(uint32 *)endptr = addr_native_to_app(*endptr);
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
static uint32
|
||||
strtoul_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *nptr, char **endptr, int32 base)
|
||||
strtoul_wrapper(wasm_exec_env_t exec_env, const char *nptr, char **endptr,
|
||||
int32 base)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 num = 0;
|
||||
@ -801,13 +808,12 @@ strtoul_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static uint32
|
||||
memchr_wrapper(wasm_exec_env_t exec_env,
|
||||
const void *s, int32 c, uint32 n)
|
||||
memchr_wrapper(wasm_exec_env_t exec_env, const void *s, int32 c, uint32 n)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
void *res;
|
||||
|
||||
if (!validate_native_addr((void*)s, n))
|
||||
if (!validate_native_addr((void *)s, n))
|
||||
return 0;
|
||||
|
||||
res = memchr(s, c, n);
|
||||
@ -815,32 +821,29 @@ memchr_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static int32
|
||||
strncasecmp_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *s1, const char *s2, uint32 n)
|
||||
strncasecmp_wrapper(wasm_exec_env_t exec_env, const char *s1, const char *s2,
|
||||
uint32 n)
|
||||
{
|
||||
/* s1 and s2 have been checked by runtime */
|
||||
return strncasecmp(s1, s2, n);
|
||||
}
|
||||
|
||||
static uint32
|
||||
strspn_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *s, const char *accept)
|
||||
strspn_wrapper(wasm_exec_env_t exec_env, const char *s, const char *accept)
|
||||
{
|
||||
/* s and accept have been checked by runtime */
|
||||
return (uint32)strspn(s, accept);
|
||||
}
|
||||
|
||||
static uint32
|
||||
strcspn_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *s, const char *reject)
|
||||
strcspn_wrapper(wasm_exec_env_t exec_env, const char *s, const char *reject)
|
||||
{
|
||||
/* s and reject have been checked by runtime */
|
||||
return (uint32)strcspn(s, reject);
|
||||
}
|
||||
|
||||
static uint32
|
||||
strstr_wrapper(wasm_exec_env_t exec_env,
|
||||
const char *s, const char *find)
|
||||
strstr_wrapper(wasm_exec_env_t exec_env, const char *s, const char *find)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
/* s and find have been checked by runtime */
|
||||
@ -925,24 +928,19 @@ getTempRet0_wrapper(wasm_exec_env_t exec_env)
|
||||
static uint32
|
||||
llvm_bswap_i16_wrapper(wasm_exec_env_t exec_env, uint32 data)
|
||||
{
|
||||
return (data & 0xFFFF0000)
|
||||
| ((data & 0xFF) << 8)
|
||||
| ((data & 0xFF00) >> 8);
|
||||
return (data & 0xFFFF0000) | ((data & 0xFF) << 8) | ((data & 0xFF00) >> 8);
|
||||
}
|
||||
|
||||
static uint32
|
||||
llvm_bswap_i32_wrapper(wasm_exec_env_t exec_env, uint32 data)
|
||||
{
|
||||
return ((data & 0xFF) << 24)
|
||||
| ((data & 0xFF00) << 8)
|
||||
| ((data & 0xFF0000) >> 8)
|
||||
| ((data & 0xFF000000) >> 24);
|
||||
return ((data & 0xFF) << 24) | ((data & 0xFF00) << 8)
|
||||
| ((data & 0xFF0000) >> 8) | ((data & 0xFF000000) >> 24);
|
||||
}
|
||||
|
||||
static uint32
|
||||
bitshift64Lshr_wrapper(wasm_exec_env_t exec_env,
|
||||
uint32 uint64_part0, uint32 uint64_part1,
|
||||
uint32 bits)
|
||||
bitshift64Lshr_wrapper(wasm_exec_env_t exec_env, uint32 uint64_part0,
|
||||
uint32 uint64_part1, uint32 bits)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
union {
|
||||
@ -955,14 +953,13 @@ bitshift64Lshr_wrapper(wasm_exec_env_t exec_env,
|
||||
|
||||
u.value >>= bits;
|
||||
/* return low 32bit and save high 32bit to temp ret */
|
||||
wasm_runtime_set_temp_ret(module_inst, (uint32) (u.value >> 32));
|
||||
return (uint32) u.value;
|
||||
wasm_runtime_set_temp_ret(module_inst, (uint32)(u.value >> 32));
|
||||
return (uint32)u.value;
|
||||
}
|
||||
|
||||
static uint32
|
||||
bitshift64Shl_wrapper(wasm_exec_env_t exec_env,
|
||||
uint32 int64_part0, uint32 int64_part1,
|
||||
uint32 bits)
|
||||
bitshift64Shl_wrapper(wasm_exec_env_t exec_env, uint32 int64_part0,
|
||||
uint32 int64_part1, uint32 bits)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
union {
|
||||
@ -975,8 +972,8 @@ bitshift64Shl_wrapper(wasm_exec_env_t exec_env,
|
||||
|
||||
u.value <<= bits;
|
||||
/* return low 32bit and save high 32bit to temp ret */
|
||||
wasm_runtime_set_temp_ret(module_inst, (uint32) (u.value >> 32));
|
||||
return (uint32) u.value;
|
||||
wasm_runtime_set_temp_ret(module_inst, (uint32)(u.value >> 32));
|
||||
return (uint32)u.value;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -996,8 +993,8 @@ llvm_stacksave_wrapper(wasm_exec_env_t exec_env)
|
||||
}
|
||||
|
||||
static uint32
|
||||
emscripten_memcpy_big_wrapper(wasm_exec_env_t exec_env,
|
||||
void *dst, const void *src, uint32 size)
|
||||
emscripten_memcpy_big_wrapper(wasm_exec_env_t exec_env, void *dst,
|
||||
const void *src, uint32 size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 dst_offset = addr_native_to_app(dst);
|
||||
@ -1038,8 +1035,7 @@ nullFunc_X_wrapper(wasm_exec_env_t exec_env, int32 code)
|
||||
}
|
||||
|
||||
static uint32
|
||||
__cxa_allocate_exception_wrapper(wasm_exec_env_t exec_env,
|
||||
uint32 thrown_size)
|
||||
__cxa_allocate_exception_wrapper(wasm_exec_env_t exec_env, uint32 thrown_size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint32 exception = module_malloc(thrown_size, NULL);
|
||||
@ -1050,16 +1046,12 @@ __cxa_allocate_exception_wrapper(wasm_exec_env_t exec_env,
|
||||
}
|
||||
|
||||
static void
|
||||
__cxa_begin_catch_wrapper(wasm_exec_env_t exec_env,
|
||||
void *exception_object)
|
||||
{
|
||||
}
|
||||
__cxa_begin_catch_wrapper(wasm_exec_env_t exec_env, void *exception_object)
|
||||
{}
|
||||
|
||||
static void
|
||||
__cxa_throw_wrapper(wasm_exec_env_t exec_env,
|
||||
void *thrown_exception,
|
||||
void *tinfo,
|
||||
uint32 table_elem_idx)
|
||||
__cxa_throw_wrapper(wasm_exec_env_t exec_env, void *thrown_exception,
|
||||
void *tinfo, uint32 table_elem_idx)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
char buf[32];
|
||||
@ -1074,8 +1066,8 @@ struct timespec_app {
|
||||
};
|
||||
|
||||
static uint32
|
||||
clock_gettime_wrapper(wasm_exec_env_t exec_env,
|
||||
uint32 clk_id, struct timespec_app *ts_app)
|
||||
clock_gettime_wrapper(wasm_exec_env_t exec_env, uint32 clk_id,
|
||||
struct timespec_app *ts_app)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
uint64 time;
|
||||
@ -1103,7 +1095,6 @@ static void
|
||||
print_wrapper(wasm_exec_env_t exec_env)
|
||||
{
|
||||
os_printf("in specttest.print()\n");
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1137,8 +1128,10 @@ print_f64_wrapper(wasm_exec_env_t exec_env, double f64)
|
||||
}
|
||||
#endif /* WASM_ENABLE_SPEC_TEST */
|
||||
|
||||
#define REG_NATIVE_FUNC(func_name, signature) \
|
||||
{ #func_name, func_name##_wrapper, signature, NULL }
|
||||
#define REG_NATIVE_FUNC(func_name, signature) \
|
||||
{ \
|
||||
#func_name, func_name##_wrapper, signature, NULL \
|
||||
}
|
||||
|
||||
static NativeSymbol native_symbols_libc_builtin[] = {
|
||||
REG_NATIVE_FUNC(printf, "($*)i"),
|
||||
@ -1281,4 +1274,3 @@ wasm_native_lookup_libc_builtin_global(const char *module_name,
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user