Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 21 additions & 10 deletions .github/workflows/compilation_on_android_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ concurrency:

env:
# For BUILD
AOT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
CLASSIC_INTERP_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
FAST_INTERP_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
LLVM_LAZY_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1"
LLVM_EAGER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=0"
AOT_BUILD_OPTIONS: " -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 _DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
CLASSIC_INTERP_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 _DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
FAST_INTERP_BUILD_OPTIONS: " -DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=1 -DWAMR_BUILD_INTERP=1 _DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
FAST_JIT_BUILD_OPTIONS: " -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 _DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=0"
LLVM_LAZY_JIT_BUILD_OPTIONS: " -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 _DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1"
LLVM_EAGER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 _DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=0"
# LLVM
LLVM_CACHE_SUFFIX: "build-llvm_libraries_ex"
# For Spec Test
Expand Down Expand Up @@ -110,6 +111,7 @@ jobs:
$AOT_BUILD_OPTIONS,
$CLASSIC_INTERP_BUILD_OPTIONS,
$FAST_INTERP_BUILD_OPTIONS,
$FAST_JIT_BUILD_OPTIONS,
$LLVM_LAZY_JIT_BUILD_OPTIONS,
$LLVM_EAGER_JIT_BUILD_OPTIONS,
]
Expand All @@ -136,12 +138,14 @@ jobs:
# uncompatiable feature and platform
# uncompatiable mode and feature
# MULTI_MODULE only on INTERP mode
- make_options_run_mode: $AOT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
- make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
- make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
- make_options_run_mode: $AOT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MULTI_MODULE=1"
# SIMD only on JIT/AOT mode
- make_options_run_mode: $CLASSIC_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_SIMD=1"
Expand All @@ -150,25 +154,31 @@ jobs:
# DEBUG_INTERP only on CLASSIC INTERP mode
- make_options_run_mode: $AOT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
- make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
- make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
- make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
- make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_INTERP=1"
# DEBUG_AOT only on JIT/AOT mode
- make_options_run_mode: $CLASSIC_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
- make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
# TODO: DEBUG_AOT on JIT
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
- make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
- make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_DEBUG_AOT=1"
# MINI_LOADER only on INTERP mode
- make_options_run_mode: $AOT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
- make_options_run_mode: $FAST_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
- make_options_run_mode: $LLVM_LAZY_JIT_BUILD_OPTIONS
make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
- make_options_run_mode: $LLVM_EAGER_JIT_BUILD_OPTIONS
Expand Down Expand Up @@ -209,11 +219,12 @@ jobs:
matrix:
make_options: [
# Running mode
$AOT_BUILD_OPTIONS,
$CLASSIC_INTERP_BUILD_OPTIONS,
$FAST_INTERP_BUILD_OPTIONS,
$FAST_JIT_BUILD_OPTIONS,
$LLVM_LAZY_JIT_BUILD_OPTIONS,
$LLVM_EAGER_JIT_BUILD_OPTIONS,
$AOT_BUILD_OPTIONS,
]
os: [ubuntu-20.04, ubuntu-22.04]
wasi_sdk_release:
Expand Down
12 changes: 0 additions & 12 deletions core/iwasm/interpreter/wasm_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@ wasm_interp_call_wasm(struct WASMModuleInstance *module_inst,
struct WASMFunctionInstance *function, uint32 argc,
uint32 argv[]);

/**
* @brief Restore the wasm stack frame to the last native frame or the begging
* of the whole stack
* @note e.g. for stack "begin --> interp --> interp", it will back to the
* "begin", for stack "begin --> interp --> native --> interp", it will become
* "begin --> interp --> native"
*
* @param exec_env the execution environment
*/
void
wasm_interp_restore_wasm_frame(struct WASMExecEnv *exec_env);

#ifdef __cplusplus
}
#endif
Expand Down
20 changes: 0 additions & 20 deletions core/iwasm/interpreter/wasm_interp_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,26 +805,6 @@ FREE_FRAME(WASMExecEnv *exec_env, WASMInterpFrame *frame)
wasm_exec_env_free_wasm_frame(exec_env, frame);
}

void
wasm_interp_restore_wasm_frame(WASMExecEnv *exec_env)
{
WASMInterpFrame *cur_frame, *prev_frame;

cur_frame = wasm_exec_env_get_cur_frame(exec_env);
while (cur_frame) {
prev_frame = cur_frame->prev_frame;
if (cur_frame->ip) {
/* FREE_FRAME just set the wasm_stack.s.top pointer, we only need to
* call it once */
FREE_FRAME(exec_env, cur_frame);
break;
}
cur_frame = prev_frame;
}

wasm_exec_env_set_cur_frame(exec_env, cur_frame);
}

static void
wasm_interp_call_func_native(WASMModuleInstance *module_inst,
WASMExecEnv *exec_env,
Expand Down
20 changes: 0 additions & 20 deletions core/iwasm/interpreter/wasm_interp_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,26 +869,6 @@ FREE_FRAME(WASMExecEnv *exec_env, WASMInterpFrame *frame)
wasm_exec_env_free_wasm_frame(exec_env, frame);
}

void
wasm_interp_restore_wasm_frame(WASMExecEnv *exec_env)
{
WASMInterpFrame *cur_frame, *prev_frame;

cur_frame = wasm_exec_env_get_cur_frame(exec_env);
while (cur_frame) {
prev_frame = cur_frame->prev_frame;
if (cur_frame->ip) {
/* FREE_FRAME just set the wasm_stack.s.top pointer, we only need to
* call it once */
FREE_FRAME(exec_env, cur_frame);
break;
}
cur_frame = prev_frame;
}

wasm_exec_env_set_cur_frame(exec_env, cur_frame);
}

static void
wasm_interp_call_func_native(WASMModuleInstance *module_inst,
WASMExecEnv *exec_env,
Expand Down
11 changes: 9 additions & 2 deletions core/iwasm/interpreter/wasm_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,8 @@ call_wasm_with_hw_bound_check(WASMModuleInstance *module_inst,
WASMJmpBuf jmpbuf_node = { 0 }, *jmpbuf_node_pop;
uint32 page_size = os_getpagesize();
uint32 guard_page_count = STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT;
WASMRuntimeFrame *prev_frame = wasm_exec_env_get_cur_frame(exec_env);
uint8 *prev_top = exec_env->wasm_stack.s.top;
#ifdef BH_PLATFORM_WINDOWS
const char *exce;
int result;
Expand Down Expand Up @@ -2081,13 +2083,18 @@ call_wasm_with_hw_bound_check(WASMModuleInstance *module_inst,
ret = false;
}

if (wasm_get_exception(module_inst)) {
/* Note: can't check wasm_get_exception(module_inst) here, there may be
* exception which is not caught by hardware (e.g. uninitialized elements),
* then the stack-frame is already freed inside wasm_interp_call_wasm */
if (!ret) {
#if WASM_ENABLE_DUMP_CALL_STACK != 0
if (wasm_interp_create_call_stack(exec_env)) {
wasm_interp_dump_call_stack(exec_env, true, NULL, 0);
}
#endif
wasm_interp_restore_wasm_frame(exec_env);
/* Restore operand frames */
wasm_exec_env_set_cur_frame(exec_env, prev_frame);
exec_env->wasm_stack.s.top = prev_top;
}

jmpbuf_node_pop = wasm_exec_env_pop_jmpbuf(exec_env);
Expand Down
8 changes: 5 additions & 3 deletions doc/build_wasm_app.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ If we want to build the wasm app with wasi mode, we may build the wasm app with
to generate a wasm binary with wasi mode, the auxiliary stack size is 8192 bytes, initial memory size is 64 KB, heap base global and data end global are exported, wasi entry function exported (_start function), and all symbols are stripped. Note that it is wasi mode, so libc-wasi should be enabled by runtime embedder or iwasm (with `cmake -DWAMR_BUILD_LIBC_WASI=1`, enabled by iwasm in Linux by default), and normally no need to export main function, by default _start function is executed by iwasm.

> Note: for the Rust project, we can set these flags by setting the `rustflags` in the Cargo configuration file, e.g. `<project_dir>/.cargo/config.toml` or `$CARGO_HOME/config.toml`, for example:
> ```
> ```toml
> [build]
> rustflags = [
> "-C", "link-arg=--initial-memory=65536",
Expand All @@ -151,7 +151,7 @@ Firstly if libc-builtin (-nostdlib) mode meets the requirements, e.g. there are
If the two globals are exported, and there are no memory.grow and memory.size opcodes (normally nostdlib mode doesn't introduce these opcodes since the libc malloc function isn't built into wasm bytecode), WAMR runtime will truncate the linear memory at the place of \__heap_base and append app heap to the end, so we don't need to allocate the memory specified by `-Wl,--initial-memory=n` which must be at least 64 KB. This is helpful for some embedded devices whose memory resource might be limited.

> For the Rust project, please set the flags in the Cargo configuration file, for example:
> ```
> ```toml
> [build]
> rustflags = [
> "-C", "link-arg=--export=__heap_base",
Expand All @@ -165,15 +165,17 @@ Firstly if libc-builtin (-nostdlib) mode meets the requirements, e.g. there are
The auxiliary stack is an area of linear memory, normally the size is 64 KB by default which might be a little large for embedded devices and partly used, we can use `-z stack-size=n` to set its size.

> For the Rust project, please set the flag in the Cargo configuration file, for example:
> ```toml
> [build]
> rustflags = [
> "-C", "link-arg=-zstack-size=8192"
> ]
> ```

- use -O3 and -Wl,--strip-all

> For the Rust project, please set the flag in the Cargo configuration file, for example:
> ```
> ```toml
> [build]
> rustflags = [
> "-C", "link-arg=--strip-all"
Expand Down
6 changes: 6 additions & 0 deletions product-mini/platforms/nuttx/wamr.mk
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ else
CFLAGS += -DWASM_ENABLE_SPEC_TEST=0
endif

ifeq ($(CONFIG_INTERPRETERS_WAMR_REF_TYPES),y)
CFLAGS += -DWASM_ENABLE_REF_TYPES=1
else
CFLAGS += -DWASM_ENABLE_REF_TYPES=0
endif

CFLAGS += -Wno-strict-prototypes -Wno-shadow -Wno-unused-variable
CFLAGS += -Wno-int-conversion -Wno-implicit-function-declaration

Expand Down
21 changes: 20 additions & 1 deletion test-tools/build-wasi-sdk/build_wasi_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,26 @@ def unpack(tar_file, strip_prefix, dest_dir):
with tempfile.TemporaryDirectory() as tmp:
with tarfile.open(tar_file) as tar:
logger.debug(f"extract to {tmp}")
tar.extractall(tmp)
def is_within_directory(directory, target):

abs_directory = os.path.abspath(directory)
abs_target = os.path.abspath(target)

prefix = os.path.commonprefix([abs_directory, abs_target])

return prefix == abs_directory

def safe_extract(tar, path=".", members=None, *, numeric_owner=False):

for member in tar.getmembers():
member_path = os.path.join(path, member.name)
if not is_within_directory(path, member_path):
raise Exception("Attempted Path Traversal in Tar File")

tar.extractall(path, members, numeric_owner=numeric_owner)


safe_extract(tar, tmp)

strip_prefix_dir = (
pathlib.Path(tmp).joinpath(strip_prefix + os.path.sep).resolve()
Expand Down