Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Enhance wasm with checkpoint and restore support (#2333) #3289

Open
wants to merge 18 commits into
base: dev/checkpoint_and_restore
Choose a base branch
from

Conversation

victoryang00
Copy link

  • Add wasm_runtime_checkpoint/wasm_runtime_restore API
  • Support AOT and Classic Interpreter mode checkpoint and debug through OS signal, tested on windows/mac/linux aarch64/x64
  • Static instrument the AOT to have the checkpoint and restore switches
  • Add sub extra library folder for implementing the ckpt-restore
  • Include extra dependency of yalantinglib

Create a one-commit PR for adding the functionality for now, which requires more code reviews and testing in the future, like when ther I could better organize the third-party yalantings library and test functionality for Classic Interpreter mode and AOT mode.

@victoryang00 victoryang00 changed the base branch from main to dev/checkpoint_and_restore April 8, 2024 16:55
@victoryang00 victoryang00 changed the title Enhance wasm with checkpoint and restore support (#2333) [WIP] Enhance wasm with checkpoint and restore support (#2333) Apr 8, 2024
@victoryang00 victoryang00 force-pushed the main branch 17 times, most recently from 0d74ae0 to 861d6a3 Compare May 2, 2024 00:19
@tamaroning
Copy link

Hi @victoryang00 !
What is the current status of this pr?
I am interested in the implementation and interfaces of this feature.
(There is no intention to rush you.)

@victoryang00
Copy link
Author

Hi @victoryang00 ! What is the current status of this pr? I am interested in the implementation and interfaces of this feature. (There is no intention to rush you.)

You can now use https://github.com/Multi-V-VM/MVVM first, this PR requires a lot more work to be accepted.

@tamaroning
Copy link

@victoryang00
Thank you!

@victoryang00
Copy link
Author

@wenyongh This PR is ready for review, but the history commit c670c3b has some syntax error, could you help me revert the file in that history commit and amend the commit?

Also, I'm not sure why compilation on windows-latest / test (fast-interp, $MULTI_MODULES_TEST_OPTIONS) fails.

victoryang00 and others added 17 commits May 27, 2024 12:13
- Add wasm_runtime_checkpoint/wasm_runtime_restore API
- Support AOT and Classic Interpreter mode checkpoint and debug through OS signal, tested on windows/mac/linux aarch64/x64
- Static instrument the AOT to have the checkpoint and restore switches
- Add sub extra library folder for implementing the ckpt-restore
- Include extra dependency of yalantinglib

Co-authored-by: Aibo Hu <i@sustech.moe>
Co-authored-by: kikispace <xzhangkiki@gmail.com>
Co-authored-by: Brian Zhao <bwzhao@ucsc.edu>
Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
Signed-off-by: victoryang00 <yangyiwei2000@gmail.com>
Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
bytecodealliance#3190)

Also, print the function name on argument mismatch.

Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
- Address values in call stack dump are relative to file beginning
- If running under fast-interp mode, address values are relative to
  every pre-compiled function beginning, which is not compatible
  with addr2line

Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
…alliance#3206)

Update the `addr2line` script so that:
- line info is printed in a more convenient format, e.g.
```
0: c
        at wasm-micro-runtime/test-tools/addr2line/trap.c:5:1
1: b
        at wasm-micro-runtime/test-tools/addr2line/trap.c:11:12
2: a
        at wasm-micro-runtime/test-tools/addr2line/trap.c:17:12
```
similar to how Rust prints stack traces when there's a panic. In an IDE, the user
can conveniently click on the printed path and be redirected to the file line.
- a new `--no-addr` argument can be provided to the script

It can be used in fast interpreter mode (that is not supported by the script otherwise)
or with older wamr versions (where the stack trace only had the function index info
and not the function address). In that case, `wasm-objdump` is used to get the function
name from the index and `llvm-dwarfdump` to obtain the location info (where the line
refers to the start of the function).

Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
…ytecodealliance#3209)

- (Export)wasm_runtime_module_malloc
  - wasm_module_malloc
    - wasm_module_malloc_internal
  - aot_module_malloc
    - aot_module_malloc_internal
- wasm_runtime_module_realloc
  - wasm_module_realloc
    - wasm_module_realloc_internal
  - aot_module_realloc
    - aot_module_realloc_internal
- (Export)wasm_runtime_module_free
  - wasm_module_free
    - wasm_module_free_internal
  - aot_module_malloc
    - aot_module_free_internal
- (Export)wasm_runtime_module_dup_data
  - wasm_module_dup_data
  - aot_module_dup_data
- (Export)wasm_runtime_validate_app_addr
- (Export)wasm_runtime_validate_app_str_addr
- (Export)wasm_runtime_validate_native_addr
- (Export)wasm_runtime_addr_app_to_native
- (Export)wasm_runtime_addr_native_to_app
- (Export)wasm_runtime_get_app_addr_range
- aot_set_aux_stack
- aot_get_aux_stack
- wasm_set_aux_stack
- wasm_get_aux_stack
- aot_check_app_addr_and_convert, wasm_check_app_addr_and_convert
  and jit_check_app_addr_and_convert
- wasm_exec_env_set_aux_stack
- wasm_exec_env_get_aux_stack
- wasm_cluster_create_thread
- wasm_cluster_allocate_aux_stack
- wasm_cluster_free_aux_stack

- WASMModule and AOTModule
  - field aux_data_end, aux_heap_base and aux_stack_bottom
- WASMExecEnv
  - field aux_stack_boundary and aux_stack_bottom
- AOTCompData
  - field aux_data_end, aux_heap_base and aux_stack_bottom
- WASMMemoryInstance(AOTMemoryInstance)
  - field memory_data_size and change __padding to is_memory64
- WASMModuleInstMemConsumption
  - field total_size and memories_size
- WASMDebugExecutionMemory
  - field start_offset and current_pos
- WASMCluster
  - field stack_tops

- libc-builtin
- libc-emcc
- libc-uvwasi
- libc-wasi
- Python and Go Language Embedding
- Interpreter Debug engine
- Multi-thread: lib-pthread, wasi-threads and thread manager

Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
…ytecodealliance#3232)

Adding the N from "aot_func#N" with the import function count is the correct
wasm function index.

Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
Add CodeQL Workflow for Code Security Analysis

This pull request introduces a CodeQL workflow to enhance the security analysis of our repository.
CodeQL is a powerful static analysis tool that helps identify and mitigate security vulnerabilities in
our codebase. By integrating this workflow into our GitHub Actions, we can proactively identify
and address potential issues before they become security threats.

We added a new CodeQL workflow file (.github/workflows/codeql.yml) that
- Runs on nightly-run, and consider runs on every pull request to the main branch in the future.
- Excludes queries with a high false positive rate or low-severity findings.
- Does not display results for third-party code, focusing only on our own codebase.

Testing:
To validate the functionality of this workflow, we have run several test scans on the codebase and
reviewed the results. The workflow successfully compiles the project, identifies issues, and provides
actionable insights while reducing noise by excluding certain queries and third-party code.

Deployment:
Once this pull request is merged, the CodeQL workflow will be active and automatically run on
every push and pull request to the main branch. To view the results of these code scans, please
follow these steps:
1. Under the repository name, click on the Security tab.
2. In the left sidebar, click Code scanning alerts.

Additional Information:
- You can further customize the workflow to adapt to your specific needs by modifying the workflow file.
- For more information on CodeQL and how to interpret its results, refer to the GitHub documentation
and the CodeQL documentation.

Signed-off-by: Brian <bayuan@purdue.edu>
Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
…liance#3246)

Enhance CodeQL Code Security Analysis:
- Add more compilation combinations to build iwasm with different kinds of features
- Disable run on PR created and keep nightly run, since the whole time is very long,
   and will check how to restore run on PR created in the future

Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
Adding a new cmake flag (cache variable) `WAMR_BUILD_MEMORY64` to enable
the memory64 feature, it can only be enabled on the 64-bit platform/target and
can only use software boundary check. And when it is enabled, it can support both
i32 and i64 linear memory types. The main modifications are:

- wasm loader & mini-loader: loading and bytecode validating process
- wasm runtime: memory instantiating process
- classic-interpreter: wasm code executing process
- Support memory64 memory in related runtime APIs
- Modify main function type check when it's memory64 wasm file
- Modify `wasm_runtime_invoke_native` and `wasm_runtime_invoke_native_raw` to
  handle registered native function pointer argument when memory64 is enabled
- memory64 classic-interpreter spec test in `test_wamr.sh` and in CI

Currently, it supports memory64 memory wasm file that uses core spec
(including bulk memory proposal) opcodes and threads opcodes.

ps.
bytecodealliance#3091
bytecodealliance#3240
bytecodealliance#3260

Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
…+ methods (bytecodealliance#3190)" (bytecodealliance#3281)

This reverts commit 0e8d949.

Because it doesn't make much sense anymore after we disabled debug info
processing on C++ functions in:
"aot debug: process lldb_function_to_function_dbi only for C".

Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
…alliance#3265)

- Add new API wasm_runtime_load_ex() in wasm_export.h
  and wasm_module_new_ex in wasm_c_api.h
- Put aot_create_perf_map() into a separated file aot_perf_map.c
- In perf.map, function names include user specified module name
- Enhance the script to help flamegraph generations

Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
…ce#3282)

When thread manager is enabled, the aux stack of exec_env may be allocated
by wasm_cluster_allocate_aux_stack or disabled by setting aux_stack_bottom
as UINTPTR_MAX directly. For the latter, no need to free it.

And fix an issue when paring `--gc-heap-size=n` argument for iwasm, and
fix a variable shadowed warning in fast-jit.

Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
…ance#3327)

And enable code format check for wasm_export.h and add '\n' in os_printf
in sgx platform source files.

Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
…3355)

- Add a few API (bytecodealliance#3325)
   ```c
   wasm_runtime_detect_native_stack_overflow_size
   wasm_runtime_detect_native_stack_overflow
   ```
- Adapt the runtime to use them
- Adapt samples/native-stack-overflow to use them
- Add a few missing overflow checks in the interpreters
- Build and run the sample on the CI

Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
- Add wasm_runtime_checkpoint/wasm_runtime_restore API
- Support AOT and Classic Interpreter mode checkpoint and debug through OS signal, tested on windows/mac/linux aarch64/x64
- Static instrument the AOT to have the checkpoint and restore switches
- Add sub extra library folder for implementing the ckpt-restore
- Include extra dependency of yalantinglib

Co-authored-by: Aibo Hu <i@sustech.moe>
Co-authored-by: kikispace <xzhangkiki@gmail.com>
Co-authored-by: Brian Zhao <bwzhao@ucsc.edu>
Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants