Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
b389628
Merge pull request #82 from bytecodealliance/master
wenyongh Mar 16, 2020
62a1992
Merge pull request #83 from bytecodealliance/master
wenyongh Mar 16, 2020
00c5daf
Merge pull request #84 from bytecodealliance/master
wenyongh Mar 17, 2020
7a46018
Merge pull request #85 from bytecodealliance/master
wenyongh Mar 18, 2020
6ed452c
Sync with internal feature
wenyongh Mar 18, 2020
632d63a
Merge pull request #86 from bytecodealliance/master
wenyongh Mar 20, 2020
ee37497
Merge pull request #87 from bytecodealliance/master
wenyongh Mar 23, 2020
44d041d
Merge pull request #88 from bytecodealliance/master
wenyongh Mar 24, 2020
b382a7f
Enable aarch64 support, add component test framework and test suite, …
wenyongh Mar 24, 2020
0a6cef7
Merge pull request #89 from bytecodealliance/master
wenyongh Mar 24, 2020
6df54ce
Merge pull request #90 from bytecodealliance/master
wenyongh Mar 27, 2020
5009206
Merge pull request #91 from bytecodealliance/master
wenyongh Mar 30, 2020
0ab53e6
Implement register/call native API with raw arguments
wenyongh Apr 1, 2020
f890529
Merge pull request #92 from bytecodealliance/master
wenyongh Apr 1, 2020
9d5bfda
Merge pull request #93 from bytecodealliance/master
wenyongh Apr 1, 2020
3b36fb8
Merge pull request #94 from bytecodealliance/master
wenyongh Apr 2, 2020
908c5f7
Merge pull request #95 from bytecodealliance/master
wenyongh Apr 9, 2020
5336e35
Merge pull request #96 from bytecodealliance/master
wenyongh Apr 12, 2020
21275d3
Merge pull request #97 from bytecodealliance/master
wenyongh Apr 13, 2020
4c56eb9
Make heap and linear memory contiguous to refine compilation time and…
wenyongh Apr 13, 2020
f984e20
Modify aot version
wenyongh Apr 13, 2020
5076b77
Merge pull request #98 from bytecodealliance/master
wenyongh Apr 13, 2020
1cf823d
Merge pull request #99 from bytecodealliance/master
wenyongh Apr 22, 2020
33a9f85
Refine aot memory boundary check, add more llvm passes
wenyongh Apr 22, 2020
be5d033
Merge pull request #100 from bytecodealliance/master
wenyongh Apr 22, 2020
aa69a45
Merge pull request #101 from bytecodealliance/master
wenyongh Apr 25, 2020
59f4d15
Sync with internal/feature
wenyongh Apr 30, 2020
af0e324
Merge pull request #102 from bytecodealliance/master
wenyongh Apr 30, 2020
4fa4bad
Sync with internal feature
wenyongh May 8, 2020
9ea9457
Merge pull request #103 from bytecodealliance/master
wenyongh May 8, 2020
54863ed
Fix issues of condition settings of app boundary check
wenyongh May 8, 2020
03ec08f
Merge pull request #104 from bytecodealliance/master
wenyongh May 8, 2020
87151ea
Replace llvm void ptr type with int8 ptr type to avoid assert failed
wenyongh May 8, 2020
ff5e90b
Merge pull request #105 from bytecodealliance/master
wenyongh May 8, 2020
23af40d
Merge pull request #106 from bytecodealliance/master
wenyongh May 15, 2020
f544940
Update API comments, refine footprint of wasm loader
wenyongh May 15, 2020
5568b52
Merge pull request #107 from bytecodealliance/master
wenyongh May 15, 2020
475669d
Merge pull request #108 from bytecodealliance/master
wenyongh May 28, 2020
0cc8c99
Merge pull request #109 from bytecodealliance/master
wenyongh Jun 1, 2020
75533fa
Sync with internal feature
wenyongh Jun 2, 2020
916a86f
update gitignore and clang-format
wenyongh Jun 2, 2020
55eee4c
Merge pull request #110 from bytecodealliance/master
wenyongh Jun 2, 2020
26515b0
Merge pull request #111 from bytecodealliance/master
wenyongh Jun 8, 2020
3c8251f
Sync with internal feature
wenyongh Jun 8, 2020
3de35d5
Merge pull request #112 from bytecodealliance/master
wenyongh Jun 8, 2020
71096fd
Sync with internal feature
wenyongh Jun 11, 2020
f5909d5
Merge pull request #113 from bytecodealliance/master
wenyongh Jun 11, 2020
4c4f8da
Merge pull request #114 from bytecodealliance/master
wenyongh Jun 12, 2020
c5d6754
Merge pull request #115 from bytecodealliance/master
wenyongh Jun 15, 2020
d371e9c
Merge pull request #116 from bytecodealliance/main
wenyongh Jun 27, 2020
c062708
Sync with internal/feature
wenyongh Jun 28, 2020
21d8754
Merge pull request #117 from bytecodealliance/main
wenyongh Jun 28, 2020
16df501
Refine opcode get/set_global for interpreter
wenyongh Jun 29, 2020
f4eb8b2
Merge pull request #118 from bytecodealliance/main
wenyongh Jun 29, 2020
5f56872
Fix issue of aot
wenyongh Jul 1, 2020
499fc94
Merge pull request #119 from bytecodealliance/main
wenyongh Jul 1, 2020
cb3dd0c
Merge pull request #120 from bytecodealliance/main
wenyongh Jul 1, 2020
47d08d0
Merge pull request #121 from bytecodealliance/main
wenyongh Jul 1, 2020
4fcf740
Enhance the native stack overflow check
wenyongh Jul 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions core/iwasm/aot/aot_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ aot_lookup_function(const AOTModuleInstance *module_inst,

#ifdef OS_ENABLE_HW_BOUND_CHECK

#define STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT 3

static os_thread_local_attribute WASMExecEnv *aot_exec_env = NULL;

static inline uint8 *
Expand All @@ -567,6 +569,7 @@ aot_signal_handler(void *sig_addr)
uint8 *mapped_mem_start_addr, *mapped_mem_end_addr;
uint8 *stack_min_addr;
uint32 page_size;
uint32 guard_page_count = STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT;

/* Check whether current thread is running aot function */
if (aot_exec_env
Expand All @@ -591,7 +594,8 @@ aot_signal_handler(void *sig_addr)
os_longjmp(jmpbuf_node->jmpbuf, 1);
}
else if (stack_min_addr - page_size <= (uint8*)sig_addr
&& (uint8*)sig_addr < stack_min_addr + page_size * 3) {
&& (uint8*)sig_addr < stack_min_addr
+ page_size * guard_page_count) {
/* The address which causes segmentation fault is inside
native thread's guard page */
aot_set_exception_with_id(module_inst, EXCE_NATIVE_STACK_OVERFLOW);
Expand Down Expand Up @@ -621,11 +625,13 @@ touch_pages(uint8 *stack_min_addr, uint32 page_size)
{
uint8 sum = 0;
while (1) {
uint8 *touch_addr = os_alloca(page_size / 2);
sum += *touch_addr;
volatile uint8 *touch_addr =
(volatile uint8*)os_alloca(page_size / 2);
if (touch_addr < stack_min_addr + page_size) {
sum += *(stack_min_addr + page_size - 1);
break;
}
sum += *touch_addr;
}
return sum;
}
Expand All @@ -640,9 +646,19 @@ invoke_native_with_hw_bound_check(WASMExecEnv *exec_env, void *func_ptr,
WASMExecEnv **p_aot_exec_env = &aot_exec_env;
WASMJmpBuf *jmpbuf_node, *jmpbuf_node_pop;
uint32 page_size = os_getpagesize();
uint32 guard_page_count = STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT;
uint8 *stack_min_addr = get_stack_min_addr(exec_env, page_size);
bool ret;

/* Check native stack overflow firstly to ensure we have enough
native stack to run the following codes before actually calling
the aot function in invokeNative function. */
if ((uint8*)&module_inst < exec_env->native_stack_boundary
+ page_size * (guard_page_count + 1)) {
aot_set_exception_with_id(module_inst, EXCE_NATIVE_STACK_OVERFLOW);
return false;
}

if (aot_exec_env
&& (aot_exec_env != exec_env)) {
aot_set_exception(module_inst, "Invalid exec env.");
Expand All @@ -654,7 +670,8 @@ invoke_native_with_hw_bound_check(WASMExecEnv *exec_env, void *func_ptr,
lazily grow the stack mapping as a guard page is hit. */
touch_pages(stack_min_addr, page_size);
/* First time to call aot function, protect one page */
if (os_mprotect(stack_min_addr, page_size * 3, MMAP_PROT_NONE) != 0) {
if (os_mprotect(stack_min_addr, page_size * guard_page_count,
MMAP_PROT_NONE) != 0) {
aot_set_exception(module_inst, "Set protected page failed.");
return false;
}
Expand All @@ -671,7 +688,7 @@ invoke_native_with_hw_bound_check(WASMExecEnv *exec_env, void *func_ptr,
if (os_setjmp(jmpbuf_node->jmpbuf) == 0) {
ret = wasm_runtime_invoke_native(exec_env, func_ptr, func_type,
signature, attachment,
argv, argc, argv);
argv, argc, argv_ret);
}
else {
/* Exception has been set in signal handler before calling longjmp */
Expand All @@ -683,7 +700,7 @@ invoke_native_with_hw_bound_check(WASMExecEnv *exec_env, void *func_ptr,
wasm_runtime_free(jmpbuf_node);
if (!exec_env->jmpbuf_stack_top) {
/* Unprotect the guard page when the nested call depth is zero */
os_mprotect(stack_min_addr, page_size * 3,
os_mprotect(stack_min_addr, page_size * guard_page_count,
MMAP_PROT_READ | MMAP_PROT_WRITE);
*p_aot_exec_env = NULL;
}
Expand Down Expand Up @@ -1113,6 +1130,19 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx,
void *attachment;
char buf[128];

#ifdef OS_ENABLE_HW_BOUND_CHECK
uint32 page_size = os_getpagesize();
uint32 guard_page_count = STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT;
/* Check native stack overflow firstly to ensure we have enough
native stack to run the following codes before actually calling
the aot function in invokeNative function. */
if ((uint8*)&module_inst < exec_env->native_stack_boundary
+ page_size * (guard_page_count + 1)) {
aot_set_exception_with_id(module_inst, EXCE_NATIVE_STACK_OVERFLOW);
return false;
}
#endif

bh_assert(func_idx < aot_module->import_func_count);

import_func = aot_module->import_funcs + func_idx;
Expand Down
7 changes: 4 additions & 3 deletions core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2797,6 +2797,10 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
return ret;
}

#endif /* end of defined(BUILD_TARGET_X86_64) \
|| defined(BUILD_TARGET_AMD_64) \
|| defined(BUILD_TARGET_AARCH64) */

bool
wasm_runtime_call_indirect(WASMExecEnv *exec_env,
uint32_t element_indices,
Expand Down Expand Up @@ -2825,6 +2829,3 @@ wasm_runtime_call_indirect(WASMExecEnv *exec_env,
return false;
}

#endif /* end of defined(BUILD_TARGET_X86_64) \
|| defined(BUILD_TARGET_AMD_64) \
|| defined(BUILD_TARGET_AARCH64) */