re-org platform APIs, simplify porting process (#201)
Co-authored-by: Xu Jun <jun1.xu@intel.com>
This commit is contained in:
@ -829,7 +829,7 @@ destroy_object_data_sections(AOTObjectDataSection *data_sections,
|
||||
AOTObjectDataSection *data_section = data_sections;
|
||||
for (i = 0; i < data_section_count; i++, data_section++)
|
||||
if (data_section->data)
|
||||
bh_munmap(data_section->data, data_section->size);
|
||||
os_munmap(data_section->data, data_section->size);
|
||||
wasm_runtime_free(data_sections);
|
||||
}
|
||||
|
||||
@ -872,7 +872,7 @@ load_object_data_sections(const uint8 **p_buf, const uint8 *buf_end,
|
||||
|
||||
/* Allocate memory for data */
|
||||
if (!(data_sections[i].data =
|
||||
bh_mmap(NULL, data_sections[i].size, map_prot, map_flags))) {
|
||||
os_mmap(NULL, data_sections[i].size, map_prot, map_flags))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"AOT module load failed: "
|
||||
"allocate memory failed.");
|
||||
@ -1594,7 +1594,7 @@ load_from_sections(AOTModule *module, AOTSection *sections,
|
||||
|
||||
/* Flush data cache before executing AOT code,
|
||||
* otherwise unpredictable behavior can occur. */
|
||||
bh_dcache_flush();
|
||||
os_dcache_flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1668,7 +1668,7 @@ destroy_sections(AOTSection *section_list, bool destroy_aot_text)
|
||||
if (destroy_aot_text
|
||||
&& section->section_type == AOT_SECTION_TYPE_TEXT
|
||||
&& section->section_body)
|
||||
bh_munmap((uint8*)section->section_body, section->section_body_size);
|
||||
os_munmap((uint8*)section->section_body, section->section_body_size);
|
||||
wasm_runtime_free(section);
|
||||
section = next;
|
||||
}
|
||||
@ -1719,7 +1719,7 @@ create_sections(const uint8 *buf, uint32 size,
|
||||
total_size = (uint64)section_size + aot_get_plt_table_size();
|
||||
total_size = (total_size + 3) & ~((uint64)3);
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(aot_text = bh_mmap(NULL, (uint32)total_size,
|
||||
|| !(aot_text = os_mmap(NULL, (uint32)total_size,
|
||||
map_prot, map_flags))) {
|
||||
wasm_runtime_free(section);
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
@ -2075,7 +2075,7 @@ aot_unload(AOTModule *module)
|
||||
bh_hash_map_destroy(module->const_str_set);
|
||||
|
||||
if (module->code)
|
||||
bh_munmap(module->code, module->code_size);
|
||||
os_munmap(module->code, module->code_size);
|
||||
|
||||
if (module->data_sections)
|
||||
destroy_object_data_sections(module->data_sections,
|
||||
|
||||
@ -751,7 +751,7 @@ aot_enlarge_memory(AOTModuleInstance *module_inst, uint32 inc_page_count)
|
||||
uint32 max_page_count = module_inst->mem_max_page_count;
|
||||
uint32 total_page_count = cur_page_count + inc_page_count;
|
||||
uint64 total_size = (uint64)num_bytes_per_page * total_page_count;
|
||||
uint32 total_size_old;
|
||||
uint32 total_size_old = module_inst->memory_data_size;
|
||||
|
||||
if (inc_page_count <= 0)
|
||||
/* No need to enlarge memory */
|
||||
@ -773,14 +773,14 @@ aot_enlarge_memory(AOTModuleInstance *module_inst, uint32 inc_page_count)
|
||||
aot_set_exception(module_inst, "fail to enlarge memory.");
|
||||
return false;
|
||||
}
|
||||
total_size_old = module_inst->memory_data_size;
|
||||
bh_memcpy_s(mem_data_new, (uint32)total_size,
|
||||
mem_data_old, total_size_old);
|
||||
memset(mem_data_new + total_size_old,
|
||||
0, (uint32)total_size - total_size_old);
|
||||
wasm_runtime_free(mem_data_old);
|
||||
}
|
||||
|
||||
memset(mem_data_new + total_size_old,
|
||||
0, (uint32)total_size - total_size_old);
|
||||
|
||||
module_inst->mem_cur_page_count = total_page_count;
|
||||
module_inst->memory_data_size = (uint32)total_size;
|
||||
module_inst->memory_data.ptr = mem_data_new;
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
#ifndef _WASM_EXEC_ENV_H
|
||||
#define _WASM_EXEC_ENV_H
|
||||
|
||||
#include "bh_thread.h"
|
||||
#include "bh_assert.h"
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
#include "../interpreter/wasm.h"
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
#include "wasm_runtime_common.h"
|
||||
#include "bh_platform.h"
|
||||
#include "mem_alloc.h"
|
||||
#include "bh_thread.h"
|
||||
|
||||
#if BEIHAI_ENABLE_MEMORY_PROFILING != 0
|
||||
|
||||
@ -60,12 +59,12 @@ wasm_memory_init_with_pool(void *mem, unsigned int bytes)
|
||||
memory_mode = MEMORY_MODE_POOL;
|
||||
pool_allocator = _allocator;
|
||||
#if BEIHAI_ENABLE_MEMORY_PROFILING != 0
|
||||
vm_mutex_init(&profile_lock);
|
||||
os_mutex_init(&profile_lock);
|
||||
#endif
|
||||
global_pool_size = bytes;
|
||||
return true;
|
||||
}
|
||||
bh_printf("Init memory with pool (%p, %u) failed.\n", mem, bytes);
|
||||
LOG_ERROR("Init memory with pool (%p, %u) failed.\n", mem, bytes);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -80,11 +79,11 @@ wasm_memory_init_with_allocator(void *_malloc_func,
|
||||
realloc_func = _realloc_func;
|
||||
free_func = _free_func;
|
||||
#if BEIHAI_ENABLE_MEMORY_PROFILING != 0
|
||||
vm_mutex_init(&profile_lock);
|
||||
os_mutex_init(&profile_lock);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
bh_printf("Init memory with allocator (%p, %p, %p) failed.\n",
|
||||
LOG_ERROR("Init memory with allocator (%p, %p, %p) failed.\n",
|
||||
_malloc_func, _realloc_func, _free_func);
|
||||
return false;
|
||||
}
|
||||
@ -110,7 +109,7 @@ void
|
||||
wasm_runtime_memory_destroy()
|
||||
{
|
||||
#if BEIHAI_ENABLE_MEMORY_PROFILING != 0
|
||||
vm_mutex_destroy(&profile_lock);
|
||||
os_mutex_destroy(&profile_lock);
|
||||
#endif
|
||||
if (memory_mode == MEMORY_MODE_POOL)
|
||||
mem_allocator_destroy(pool_allocator);
|
||||
@ -130,7 +129,7 @@ void *
|
||||
wasm_runtime_malloc(unsigned int size)
|
||||
{
|
||||
if (memory_mode == MEMORY_MODE_UNKNOWN) {
|
||||
bh_printf("wasm_runtime_malloc failed: memory hasn't been initialize.\n");
|
||||
LOG_WARNING("wasm_runtime_malloc failed: memory hasn't been initialize.\n");
|
||||
return NULL;
|
||||
} else if (memory_mode == MEMORY_MODE_POOL) {
|
||||
return mem_allocator_malloc(pool_allocator, size);
|
||||
@ -143,7 +142,7 @@ void *
|
||||
wasm_runtime_realloc(void *ptr, unsigned int size)
|
||||
{
|
||||
if (memory_mode == MEMORY_MODE_UNKNOWN) {
|
||||
bh_printf("wasm_runtime_realloc failed: memory hasn't been initialize.\n");
|
||||
LOG_WARNING("wasm_runtime_realloc failed: memory hasn't been initialize.\n");
|
||||
return NULL;
|
||||
} else if (memory_mode == MEMORY_MODE_POOL) {
|
||||
return mem_allocator_realloc(pool_allocator, ptr, size);
|
||||
@ -159,7 +158,7 @@ void
|
||||
wasm_runtime_free(void *ptr)
|
||||
{
|
||||
if (memory_mode == MEMORY_MODE_UNKNOWN) {
|
||||
bh_printf("wasm_runtime_free failed: memory hasn't been initialize.\n");
|
||||
LOG_WARNING("wasm_runtime_free failed: memory hasn't been initialize.\n");
|
||||
} else if (memory_mode == MEMORY_MODE_POOL) {
|
||||
mem_allocator_free(pool_allocator, ptr);
|
||||
} else {
|
||||
@ -177,7 +176,7 @@ wasm_runtime_malloc_profile(const char *file, int line,
|
||||
if (p) {
|
||||
memory_profile_t *profile;
|
||||
|
||||
vm_mutex_lock(&profile_lock);
|
||||
os_mutex_lock(&profile_lock);
|
||||
|
||||
profile = memory_profiles_list;
|
||||
while (profile) {
|
||||
@ -194,7 +193,7 @@ wasm_runtime_malloc_profile(const char *file, int line,
|
||||
} else {
|
||||
profile = wasm_runtime_malloc(sizeof(memory_profile_t));
|
||||
if (!profile) {
|
||||
vm_mutex_unlock(&profile_lock);
|
||||
os_mutex_unlock(&profile_lock);
|
||||
bh_memcpy_s(p, size + 8, &size, sizeof(size));
|
||||
return (char *)p + 8;
|
||||
}
|
||||
@ -209,7 +208,7 @@ wasm_runtime_malloc_profile(const char *file, int line,
|
||||
memory_profiles_list = profile;
|
||||
}
|
||||
|
||||
vm_mutex_unlock(&profile_lock);
|
||||
os_mutex_unlock(&profile_lock);
|
||||
|
||||
bh_memcpy_s(p, size + 8, &size, sizeof(size));
|
||||
memory_in_use += size;
|
||||
@ -234,7 +233,7 @@ wasm_runtime_free_profile(const char *file, int line,
|
||||
if (memory_in_use >= size)
|
||||
memory_in_use -= size;
|
||||
|
||||
vm_mutex_lock(&profile_lock);
|
||||
os_mutex_lock(&profile_lock);
|
||||
|
||||
profile = memory_profiles_list;
|
||||
while (profile) {
|
||||
@ -251,7 +250,7 @@ wasm_runtime_free_profile(const char *file, int line,
|
||||
} else {
|
||||
profile = wasm_runtime_malloc(sizeof(memory_profile_t));
|
||||
if (!profile) {
|
||||
vm_mutex_unlock(&profile_lock);
|
||||
os_mutex_unlock(&profile_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -265,7 +264,7 @@ wasm_runtime_free_profile(const char *file, int line,
|
||||
memory_profiles_list = profile;
|
||||
}
|
||||
|
||||
vm_mutex_unlock(&profile_lock);
|
||||
os_mutex_unlock(&profile_lock);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -277,11 +276,11 @@ void memory_usage_summarize()
|
||||
{
|
||||
memory_profile_t *profile;
|
||||
|
||||
vm_mutex_lock(&profile_lock);
|
||||
os_mutex_lock(&profile_lock);
|
||||
|
||||
profile = memory_profiles_list;
|
||||
while (profile) {
|
||||
bh_printf("malloc:%d:malloc_num:%d:free:%d:free_num:%d:%s\n",
|
||||
os_printf("malloc:%d:malloc_num:%d:free:%d:free_num:%d:%s\n",
|
||||
profile->total_malloc,
|
||||
profile->malloc_num,
|
||||
profile->total_free,
|
||||
@ -290,14 +289,14 @@ void memory_usage_summarize()
|
||||
profile = profile->next;
|
||||
}
|
||||
|
||||
vm_mutex_unlock(&profile_lock);
|
||||
os_mutex_unlock(&profile_lock);
|
||||
}
|
||||
|
||||
void
|
||||
memory_profile_print(const char *file, int line,
|
||||
const char *func, int alloc)
|
||||
{
|
||||
bh_printf("location:%s@%d:used:%d:contribution:%d\n",
|
||||
os_printf("location:%s@%d:used:%d:contribution:%d\n",
|
||||
func, line, memory_in_use, alloc);
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "bh_platform.h"
|
||||
#include "bh_common.h"
|
||||
#include "bh_assert.h"
|
||||
@ -30,14 +29,10 @@ wasm_runtime_env_init()
|
||||
if (bh_platform_init() != 0)
|
||||
return false;
|
||||
|
||||
if (bh_log_init() != 0)
|
||||
return false;
|
||||
|
||||
if (vm_thread_sys_init() != 0)
|
||||
return false;
|
||||
|
||||
if (wasm_native_init() == false)
|
||||
if (wasm_native_init() == false) {
|
||||
bh_platform_destroy();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -60,7 +55,7 @@ void
|
||||
wasm_runtime_destroy()
|
||||
{
|
||||
wasm_native_destroy();
|
||||
vm_thread_sys_destroy();
|
||||
bh_platform_destroy();
|
||||
wasm_runtime_memory_destroy();
|
||||
}
|
||||
|
||||
@ -273,7 +268,7 @@ wasm_runtime_call_wasm(WASMExecEnv *exec_env,
|
||||
return false;
|
||||
}
|
||||
|
||||
exec_env->handle = vm_self_thread();
|
||||
exec_env->handle = os_self_thread();
|
||||
|
||||
#if WASM_ENABLE_INTERP != 0
|
||||
if (exec_env->module_inst->module_type == Wasm_Module_Bytecode)
|
||||
@ -1375,7 +1370,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
||||
/* print return value */
|
||||
switch (type->types[type->param_count]) {
|
||||
case VALUE_TYPE_I32:
|
||||
bh_printf("0x%x:i32", argv1[0]);
|
||||
os_printf("0x%x:i32", argv1[0]);
|
||||
break;
|
||||
case VALUE_TYPE_I64:
|
||||
{
|
||||
@ -1387,22 +1382,22 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
|
||||
snprintf(buf, sizeof(buf), "%s", "0x%llx:i64");
|
||||
else
|
||||
snprintf(buf, sizeof(buf), "%s", "0x%lx:i64");
|
||||
bh_printf(buf, u.val);
|
||||
os_printf(buf, u.val);
|
||||
break;
|
||||
}
|
||||
case VALUE_TYPE_F32:
|
||||
bh_printf("%.7g:f32", *(float32*)argv1);
|
||||
os_printf("%.7g:f32", *(float32*)argv1);
|
||||
break;
|
||||
case VALUE_TYPE_F64:
|
||||
{
|
||||
union { float64 val; uint32 parts[2]; } u;
|
||||
u.parts[0] = argv1[0];
|
||||
u.parts[1] = argv1[1];
|
||||
bh_printf("%.7g:f64", u.val);
|
||||
os_printf("%.7g:f64", u.val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
bh_printf("\n");
|
||||
os_printf("\n");
|
||||
|
||||
wasm_runtime_free(argv1);
|
||||
return true;
|
||||
@ -1413,7 +1408,7 @@ fail:
|
||||
|
||||
exception = wasm_runtime_get_exception(module_inst);
|
||||
bh_assert(exception);
|
||||
bh_printf("%s\n", exception);
|
||||
os_printf("%s\n", exception);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
|
||||
#include "bh_platform.h"
|
||||
#include "bh_common.h"
|
||||
#include "bh_thread.h"
|
||||
#include "wasm_exec_env.h"
|
||||
#include "wasm_native.h"
|
||||
#include "../include/wasm_export.h"
|
||||
|
||||
@ -789,23 +789,23 @@ static void
|
||||
print_supported_targets()
|
||||
{
|
||||
uint32 i;
|
||||
bh_printf("Supported targets:\n");
|
||||
os_printf("Supported targets:\n");
|
||||
for (i = 0; i < sizeof(valid_archs) / sizeof(ArchItem); i++) {
|
||||
bh_printf("%s ", valid_archs[i].arch);
|
||||
os_printf("%s ", valid_archs[i].arch);
|
||||
if (valid_archs[i].support_eb)
|
||||
bh_printf("%seb ", valid_archs[i].arch);
|
||||
os_printf("%seb ", valid_archs[i].arch);
|
||||
}
|
||||
bh_printf("\n");
|
||||
os_printf("\n");
|
||||
}
|
||||
|
||||
static void
|
||||
print_supported_abis()
|
||||
{
|
||||
uint32 i;
|
||||
bh_printf("Supported ABI: ");
|
||||
os_printf("Supported ABI: ");
|
||||
for (i = 0; i < sizeof(valid_abis) / sizeof(const char *); i++)
|
||||
bh_printf("%s ", valid_abis[i]);
|
||||
bh_printf("\n");
|
||||
os_printf("%s ", valid_abis[i]);
|
||||
os_printf("\n");
|
||||
}
|
||||
|
||||
static bool
|
||||
@ -917,6 +917,8 @@ aot_create_comp_context(AOTCompData *comp_data,
|
||||
goto fail;
|
||||
}
|
||||
comp_ctx->is_jit_mode = true;
|
||||
comp_ctx->target_machine =
|
||||
LLVMGetExecutionEngineTargetMachine(comp_ctx->exec_engine);
|
||||
}
|
||||
else {
|
||||
/* Create LLVM target machine */
|
||||
@ -1026,24 +1028,24 @@ aot_create_comp_context(AOTCompData *comp_data,
|
||||
get_target_arch_from_triple(triple_norm, comp_ctx->target_arch,
|
||||
sizeof(comp_ctx->target_arch));
|
||||
|
||||
bh_printf("Create AoT compiler with:\n");
|
||||
bh_printf(" target: %s\n", comp_ctx->target_arch);
|
||||
bh_printf(" target cpu: %s\n", cpu);
|
||||
bh_printf(" cpu features: %s\n", features);
|
||||
bh_printf(" opt level: %d\n", opt_level);
|
||||
bh_printf(" size level: %d\n", size_level);
|
||||
os_printf("Create AoT compiler with:\n");
|
||||
os_printf(" target: %s\n", comp_ctx->target_arch);
|
||||
os_printf(" target cpu: %s\n", cpu);
|
||||
os_printf(" cpu features: %s\n", features);
|
||||
os_printf(" opt level: %d\n", opt_level);
|
||||
os_printf(" size level: %d\n", size_level);
|
||||
switch (option->output_format) {
|
||||
case AOT_LLVMIR_UNOPT_FILE:
|
||||
bh_printf(" output format: unoptimized LLVM IR\n");
|
||||
os_printf(" output format: unoptimized LLVM IR\n");
|
||||
break;
|
||||
case AOT_LLVMIR_OPT_FILE:
|
||||
bh_printf(" output format: optimized LLVM IR\n");
|
||||
os_printf(" output format: optimized LLVM IR\n");
|
||||
break;
|
||||
case AOT_FORMAT_FILE:
|
||||
bh_printf(" output format: AoT file\n");
|
||||
os_printf(" output format: AoT file\n");
|
||||
break;
|
||||
case AOT_OBJECT_FILE:
|
||||
bh_printf(" output format: native object file\n");
|
||||
os_printf(" output format: native object file\n");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1155,7 +1157,7 @@ aot_destroy_comp_context(AOTCompContext *comp_ctx)
|
||||
if (comp_ctx->pass_mgr)
|
||||
LLVMDisposePassManager(comp_ctx->pass_mgr);
|
||||
|
||||
if (comp_ctx->target_machine)
|
||||
if (comp_ctx->target_machine && !comp_ctx->is_jit_mode)
|
||||
LLVMDisposeTargetMachine(comp_ctx->target_machine);
|
||||
|
||||
if (comp_ctx->builder)
|
||||
|
||||
@ -15,6 +15,29 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define get_module_inst(exec_env) \
|
||||
wasm_runtime_get_module_inst(exec_env)
|
||||
|
||||
#define validate_app_addr(offset, size) \
|
||||
wasm_runtime_validate_app_addr(module_inst, offset, size)
|
||||
|
||||
#define validate_app_str_addr(offset) \
|
||||
wasm_runtime_validate_app_str_addr(module_inst, offset)
|
||||
|
||||
#define addr_app_to_native(offset) \
|
||||
wasm_runtime_addr_app_to_native(module_inst, offset)
|
||||
|
||||
#define addr_native_to_app(ptr) \
|
||||
wasm_runtime_addr_native_to_app(module_inst, ptr)
|
||||
|
||||
#define module_malloc(size, p_native_addr) \
|
||||
wasm_runtime_module_malloc(module_inst, size, p_native_addr)
|
||||
|
||||
#define module_free(offset) \
|
||||
wasm_runtime_module_free(module_inst, offset)
|
||||
|
||||
|
||||
|
||||
/* Uninstantiated WASM module loaded from WASM binary file
|
||||
or AoT binary file*/
|
||||
struct WASMModuleCommon;
|
||||
|
||||
@ -1401,7 +1401,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
/* fail to memory.grow, return -1 */
|
||||
PUSH_I32(-1);
|
||||
if (wasm_get_exception(module)) {
|
||||
bh_printf("%s\n", wasm_get_exception(module));
|
||||
os_printf("%s\n", wasm_get_exception(module));
|
||||
wasm_set_exception(module, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -729,7 +729,7 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
|
||||
#endif /* end of WASM_ENABLE_LABELS_AS_VALUES */
|
||||
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
static void *global_handle_table[WASM_INSTRUCTION_NUM] = { 0 };
|
||||
static void **global_handle_table;
|
||||
#endif
|
||||
|
||||
static void
|
||||
@ -769,8 +769,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
#undef HANDLE_OPCODE
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
if (exec_env == NULL) {
|
||||
bh_memcpy_s(global_handle_table, sizeof(void*) * WASM_INSTRUCTION_NUM,
|
||||
handle_table, sizeof(void*) * WASM_INSTRUCTION_NUM);
|
||||
global_handle_table = (void **)handle_table;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@ -1240,7 +1239,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
/* fail to memory.grow, return -1 */
|
||||
frame_lp[addr_ret] = -1;
|
||||
if (wasm_get_exception(module)) {
|
||||
bh_printf("%s\n", wasm_get_exception(module));
|
||||
os_printf("%s\n", wasm_get_exception(module));
|
||||
wasm_set_exception(module, NULL);
|
||||
}
|
||||
}
|
||||
@ -2035,19 +2034,20 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
HANDLE_OP (WASM_OP_TEE_LOCAL):
|
||||
{
|
||||
GET_LOCAL_INDEX_TYPE_AND_OFFSET();
|
||||
addr1 = GET_OFFSET();
|
||||
|
||||
switch (local_type) {
|
||||
case VALUE_TYPE_I32:
|
||||
case VALUE_TYPE_F32:
|
||||
*(int32*)(frame_lp + local_offset) = GET_OPERAND(uint32, 0);
|
||||
break;
|
||||
case VALUE_TYPE_I64:
|
||||
case VALUE_TYPE_F64:
|
||||
PUT_I64_TO_ADDR((uint32*)(frame_lp + local_offset), GET_OPERAND(uint64, 0));
|
||||
break;
|
||||
default:
|
||||
wasm_set_exception(module, "invalid local type");
|
||||
goto got_exception;
|
||||
if (local_type == VALUE_TYPE_I32
|
||||
|| local_type == VALUE_TYPE_F32) {
|
||||
*(int32*)(frame_lp + local_offset) = frame_lp[addr1];
|
||||
}
|
||||
else if (local_type == VALUE_TYPE_I32
|
||||
|| local_type == VALUE_TYPE_F32) {
|
||||
PUT_I64_TO_ADDR((uint32*)(frame_lp + local_offset),
|
||||
GET_I64_FROM_ADDR(frame_lp + addr1));
|
||||
}
|
||||
else {
|
||||
wasm_set_exception(module, "invalid local type");
|
||||
goto got_exception;
|
||||
}
|
||||
|
||||
HANDLE_OP_END ();
|
||||
|
||||
@ -2311,7 +2311,7 @@ wasm_loader_find_block_addr(BlockAddr *block_addr_cache,
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
|
||||
#if WASM_DEBUG_PREPROCESSOR != 0
|
||||
#define LOG_OP(...) bh_printf(__VA_ARGS__)
|
||||
#define LOG_OP(...) os_printf(__VA_ARGS__)
|
||||
#else
|
||||
#define LOG_OP(...)
|
||||
#endif
|
||||
@ -3886,6 +3886,7 @@ handle_next_reachable_block:
|
||||
}
|
||||
|
||||
case WASM_OP_DROP:
|
||||
case WASM_OP_DROP_64:
|
||||
{
|
||||
if (loader_ctx->stack_cell_num <= 0) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
@ -3915,7 +3916,7 @@ handle_next_reachable_block:
|
||||
}
|
||||
loader_ctx->frame_ref -= 2;
|
||||
loader_ctx->stack_cell_num -= 2;
|
||||
#if WASM_ENABLE_FAST_INTERP == 0
|
||||
#if (WASM_ENABLE_FAST_INTERP == 0) || (WASM_ENABLE_JIT != 0)
|
||||
*(p - 1) = WASM_OP_DROP_64;
|
||||
#endif
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
@ -3930,6 +3931,7 @@ handle_next_reachable_block:
|
||||
}
|
||||
|
||||
case WASM_OP_SELECT:
|
||||
case WASM_OP_SELECT_64:
|
||||
{
|
||||
uint8 ref_type;
|
||||
|
||||
@ -3948,7 +3950,7 @@ handle_next_reachable_block:
|
||||
break;
|
||||
case REF_I64_2:
|
||||
case REF_F64_2:
|
||||
#if WASM_ENABLE_FAST_INTERP == 0
|
||||
#if (WASM_ENABLE_FAST_INTERP == 0) || (WASM_ENABLE_JIT != 0)
|
||||
*(p - 1) = WASM_OP_SELECT_64;
|
||||
#endif
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
|
||||
@ -1108,7 +1108,8 @@ wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count)
|
||||
{
|
||||
#if WASM_ENABLE_MEMORY_GROW != 0
|
||||
WASMMemoryInstance *memory = module->default_memory, *new_memory;
|
||||
uint32 old_page_count = memory->cur_page_count, total_size_old;
|
||||
uint32 old_page_count = memory->cur_page_count;
|
||||
uint32 total_size_old = memory->end_addr - (uint8*)memory;
|
||||
uint32 total_page_count = inc_page_count + memory->cur_page_count;
|
||||
uint64 total_size = offsetof(WASMMemoryInstance, base_addr) +
|
||||
memory->num_bytes_per_page * (uint64)total_page_count +
|
||||
@ -1135,14 +1136,14 @@ wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count)
|
||||
wasm_set_exception(module, "fail to enlarge memory.");
|
||||
return false;
|
||||
}
|
||||
total_size_old = memory->end_addr - (uint8*)memory;
|
||||
bh_memcpy_s((uint8*)new_memory, (uint32)total_size,
|
||||
(uint8*)memory, total_size_old);
|
||||
memset((uint8*)new_memory + total_size_old,
|
||||
0, (uint32)total_size - total_size_old);
|
||||
wasm_runtime_free(memory);
|
||||
}
|
||||
|
||||
memset((uint8*)new_memory + total_size_old,
|
||||
0, (uint32)total_size - total_size_old);
|
||||
|
||||
new_memory->cur_page_count = total_page_count;
|
||||
new_memory->memory_data = new_memory->base_addr;
|
||||
new_memory->global_data = new_memory->memory_data +
|
||||
|
||||
@ -388,7 +388,7 @@ sprintf_out(int c, struct str_context *ctx)
|
||||
static int
|
||||
printf_out(int c, struct str_context *ctx)
|
||||
{
|
||||
bh_printf("%c", c);
|
||||
os_printf("%c", c);
|
||||
ctx->count++;
|
||||
return c;
|
||||
}
|
||||
@ -470,13 +470,13 @@ snprintf_wrapper(wasm_exec_env_t exec_env, char *str, uint32 size,
|
||||
static int
|
||||
puts_wrapper(wasm_exec_env_t exec_env, const char *str)
|
||||
{
|
||||
return bh_printf("%s\n", str);
|
||||
return os_printf("%s\n", str);
|
||||
}
|
||||
|
||||
static int
|
||||
putchar_wrapper(wasm_exec_env_t exec_env, int c)
|
||||
{
|
||||
bh_printf("%c", c);
|
||||
os_printf("%c", c);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -908,7 +908,7 @@ static void
|
||||
llvm_stackrestore_wrapper(wasm_exec_env_t exec_env, uint32 llvm_stack)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
bh_printf("_llvm_stackrestore called!\n");
|
||||
os_printf("_llvm_stackrestore called!\n");
|
||||
wasm_runtime_set_llvm_stack(module_inst, llvm_stack);
|
||||
}
|
||||
|
||||
@ -916,7 +916,7 @@ static uint32
|
||||
llvm_stacksave_wrapper(wasm_exec_env_t exec_env)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
bh_printf("_llvm_stacksave called!\n");
|
||||
os_printf("_llvm_stacksave called!\n");
|
||||
return wasm_runtime_get_llvm_stack(module_inst);
|
||||
}
|
||||
|
||||
@ -996,7 +996,7 @@ __cxa_throw_wrapper(wasm_exec_env_t exec_env,
|
||||
static void
|
||||
print_i32_wrapper(wasm_exec_env_t exec_env, int32 i32)
|
||||
{
|
||||
bh_printf("%d\n", i32);
|
||||
os_printf("%d\n", i32);
|
||||
}
|
||||
|
||||
#define REG_NATIVE_FUNC(func_name, signature) \
|
||||
@ -1028,7 +1028,7 @@ static NativeSymbol native_symbols_libc_builtin[] = {
|
||||
REG_NATIVE_FUNC(exit, "(i)"),
|
||||
REG_NATIVE_FUNC(strtol, "($*i)i"),
|
||||
REG_NATIVE_FUNC(strtoul, "($*i)i"),
|
||||
REG_NATIVE_FUNC(memchr, "(*ii)"),
|
||||
REG_NATIVE_FUNC(memchr, "(*ii)i"),
|
||||
REG_NATIVE_FUNC(strncasecmp, "($$i)"),
|
||||
REG_NATIVE_FUNC(strspn, "($$)i"),
|
||||
REG_NATIVE_FUNC(strcspn, "($$)i"),
|
||||
|
||||
@ -47,6 +47,7 @@
|
||||
#include "str.h"
|
||||
|
||||
#include "bh_common.h"
|
||||
#include "bh_assert.h"
|
||||
|
||||
#if 0 /* TODO: -std=gnu99 causes compile error, comment them first */
|
||||
// struct iovec must have the same layout as __wasi_iovec_t.
|
||||
|
||||
Reference in New Issue
Block a user