From f39a31b7cdf17f6e522490378cb68a28659bc173 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 20 Dec 2023 17:14:53 +0900 Subject: [PATCH 1/2] lib: Upgrade wasm-micro-runtime to v1.3.0 Signed-off-by: Hiroshi Hatake --- cmake/libraries.cmake | 2 +- .../.github/workflows/spec_test_on_nuttx.yml | 145 - .../build-scripts/requirements.txt | 1 - .../core/app-mgr/README.md | 8 - .../core/iwasm/aot/iwasm_aot.cmake | 40 - .../core/iwasm/common/wasm_memory.h | 41 - .../core/iwasm/common/wasm_shared_memory.h | 70 - .../core/iwasm/fast-jit/jit_utils.c | 19 - .../iwasm/libraries/lib-socket/test/tcp_udp.c | 193 -- .../libraries/lib-wasi-threads/test/build.sh | 35 - .../test/trap_after_main_thread_finishes.json | 3 - .../libraries/libc-uvwasi/libc_uvwasi.cmake | 44 - .../include/wasmtime_ssp.h | 1508 ---------- .../wasi-nn/cmake/Findtensorflow_lite.cmake | 41 - .../iwasm/libraries/wasi-nn/wasi_nn.cmake | 22 - .../common/posix/platform_api_posix.cmake | 8 - .../shared/platform/esp-idf/espidf_memmap.c | 51 - lib/wasm-micro-runtime-WAMR-1.2.2/doc/xip.md | 14 - .../language-bindings/go/go.mod | 5 - .../language-bindings/go/samples/build.sh | 23 - .../platforms/zephyr/simple/README_docker.md | 25 - .../platforms/zephyr/simple/boards/esp32.conf | 8 - .../zephyr/simple/boards/qemu_riscv32.conf | 6 - .../zephyr/simple/boards/qemu_riscv64.conf | 6 - .../zephyr/simple/boards/qemu_x86_nommu.conf | 6 - .../zephyr/simple/boards/qemu_xtensa.conf | 6 - .../zephyr/simple/esp32_custom_linker.ld | 274 -- .../samples/workload/XNNPACK/CMakeLists.txt | 147 - .../samples/workload/XNNPACK/xnnpack.patch | 141 - .../wamr-ide/VSCode-Extension/.gitignore | 7 - .../VSCode-Extension/.vscode/extensions.json | 5 - .../VSCode-Extension/.vscode/launch.json | 15 - .../VSCode-Extension/.vscode/tasks.json | 20 - .../wamr-ide/VSCode-Extension/.vscodeignore | 11 - .../VSCode-Extension/resource/debug/README.md | 15 - .../resource/debug/darwin/.placeholder | 0 .../resource/debug/linux/.placeholder | 0 .../resource/debug/windows/.placeholder | 0 .../tests/benchmarks/coremark/run.sh | 16 - .../tests/benchmarks/jetstream/build.sh | 74 - .../tests/benchmarks/libsodium/test_aot.sh | 59 - .../wasi-test-script/run_wasi_tests.sh | 80 - .../.clang-tidy | 0 .../.devcontainer/Dockerfile | 150 + .../.devcontainer/devcontainer.json | 23 +- .../scripts/extract_from_release_notes.py | 0 .../scripts/fetch_and_compare_version.py | 0 .../scripts/reuse_latest_release_binaries.py | 0 .../.github/workflows/build_docker_images.yml | 0 .../.github/workflows/build_iwasm_release.yml | 0 .../workflows/build_llvm_libraries.yml | 0 .../.github/workflows/build_wamr_lldb.yml | 95 +- .../.github/workflows/build_wamr_sdk.yml | 0 .../workflows/build_wamr_vscode_ext.yml | 4 +- .../.github/workflows/build_wamrc.yml | 0 .../.github/workflows/coding_guidelines.yml | 2 +- .../compilation_on_android_ubuntu.yml | 713 +++++ .../workflows/compilation_on_macos.yml | 14 +- .../workflows/compilation_on_nuttx.yml | 6 +- .../.github/workflows/compilation_on_sgx.yml | 207 +- .../workflows/compilation_on_windows.yml | 61 +- .../.github/workflows/create_tag.yml | 0 .../workflows/hadolint_dockerfiles.yml | 47 + .../.github/workflows/nightly_run.yml} | 344 ++- .../.github/workflows/release_process.yml | 6 +- .../reuse_latest_release_binaries.yml | 0 .../.github/workflows/spec_test_on_nuttx.yml | 211 ++ .../.gitignore | 1 + .../ATTRIBUTIONS.md | 14 +- .../CMakeLists.txt | 0 .../CODE_OF_CONDUCT.md | 0 .../CONTRIBUTING.md | 0 .../LICENSE | 0 .../ORG_CODE_OF_CONDUCT.md | 0 .../README.md | 3 + .../RELEASE_NOTES.md | 305 ++ .../SConscript | 0 .../SECURITY.md | 0 .../TSC_Charter.md | 0 .../assembly-script/.gitignore | 0 .../assembly-script/README.md | 0 .../assembly-script/package-lock.json | 0 .../assembly-script/package.json | 0 .../samples/event_publisher.ts | 0 .../samples/event_subscriber.ts | 0 .../samples/request_handler.ts | 0 .../assembly-script/samples/request_sender.ts | 0 .../assembly-script/samples/timer.ts | 0 .../assembly-script/samples/tsconfig.json | 0 .../assembly-script/wamr_app_lib/console.ts | 0 .../assembly-script/wamr_app_lib/request.ts | 0 .../assembly-script/wamr_app_lib/timer.ts | 0 .../wamr_app_lib/tsconfig.json | 0 .../build-scripts/SConscript | 0 .../build-scripts/SConscript_config | 0 .../build-scripts/build_llvm.py | 18 +- .../build-scripts/config_common.cmake | 86 +- .../build-scripts/esp-idf/README.md | 0 .../build-scripts/esp-idf/wamr/CMakeLists.txt | 0 .../build-scripts/involve_boringssl.cmake | 0 .../build-scripts/lldb_wasm.patch} | 155 +- .../build-scripts/requirements.txt | 1 + .../build-scripts/runtime_lib.cmake | 12 +- .../ci/build_wamr.sh | 0 .../ci/coding_guidelines_check.py | 0 .../ci/pre_commit_hook_sample | 32 + lib/wasm-micro-runtime-WAMR-1.3.0/ci/setup.sh | 15 + .../ci/validate_lldb.py | 128 + .../core/app-framework/README.md | 0 .../app-framework/app-native-shared/README.md | 0 .../app-native-shared/attr_container.c | 0 .../app-native-shared/bi-inc/attr_container.h | 0 .../app-native-shared/bi-inc/shared_utils.h | 0 .../bi-inc/wgl_shared_utils.h | 0 .../app-native-shared/native_interface.cmake | 0 .../app-native-shared/native_interface.h | 0 .../app-native-shared/restful_utils.c | 0 .../core/app-framework/app_ext_lib_export.c | 0 .../core/app-framework/app_framework.cmake | 0 .../core/app-framework/base/app/bh_platform.c | 0 .../core/app-framework/base/app/bh_platform.h | 0 .../app-framework/base/app/req_resp_api.h | 0 .../core/app-framework/base/app/request.c | 0 .../core/app-framework/base/app/timer.c | 0 .../core/app-framework/base/app/timer_api.h | 0 .../app-framework/base/app/wa-inc/request.h | 0 .../base/app/wa-inc/timer_wasm_app.h | 0 .../app-framework/base/app/wasm_app.cmake | 0 .../core/app-framework/base/app/wasm_app.h | 0 .../app-framework/base/native/base_lib.inl | 0 .../base/native/base_lib_export.c | 0 .../base/native/req_resp_native_api.h | 0 .../base/native/request_response.c | 0 .../app-framework/base/native/runtime_lib.h | 0 .../base/native/timer_native_api.h | 0 .../app-framework/base/native/timer_wrapper.c | 0 .../app-framework/base/native/wasm_lib.cmake | 0 .../app-framework/connection/app/connection.c | 0 .../connection/app/connection_api.h | 0 .../connection/app/wa-inc/connection.h | 0 .../connection/app/wasm_app.cmake | 0 .../connection/native/connection.inl | 0 .../connection/native/connection_lib.h | 0 .../connection/native/connection_native_api.h | 0 .../connection/native/connection_wrapper.c | 0 .../connection/native/linux/conn_tcp.c | 0 .../connection/native/linux/conn_tcp.h | 0 .../connection/native/linux/conn_uart.c | 0 .../connection/native/linux/conn_uart.h | 0 .../connection/native/linux/conn_udp.c | 0 .../connection/native/linux/conn_udp.h | 0 .../connection/native/linux/connection_mgr.c | 0 .../native/linux/connection_mgr.cmake | 0 .../connection/native/wasm_lib.cmake | 0 .../native/zephyr/connection_lib_impl.c | 0 .../native/zephyr/connection_mgr.cmake | 0 .../core/app-framework/sensor/app/sensor.c | 0 .../app-framework/sensor/app/sensor_api.h | 0 .../app-framework/sensor/app/wa-inc/sensor.h | 0 .../app-framework/sensor/app/wasm_app.cmake | 0 .../sensor/native/runtime_sensor.c | 0 .../sensor/native/runtime_sensor.h | 0 .../sensor/native/runtime_sensor.inl | 0 .../sensor/native/sensor_mgr_ref.c | 0 .../sensor/native/sensor_native_api.h | 0 .../sensor/native/wasm_lib.cmake | 0 .../template/app/wa-inc/app_xxx.h | 0 .../app-framework/template/app/wasm_app.cmake | 0 .../app-framework/template/native/app_xxx.inl | 0 .../template/native/wasm_lib.cmake | 0 .../core/app-mgr/README.md | 8 + .../core/app-mgr/app-manager/app_manager.c | 0 .../core/app-mgr/app-manager/app_manager.h | 0 .../app-mgr/app-manager/app_manager_host.c | 0 .../app-mgr/app-manager/app_manager_host.h | 0 .../core/app-mgr/app-manager/app_mgr.cmake | 0 .../core/app-mgr/app-manager/ble_msg.c | 0 .../core/app-mgr/app-manager/coding_rule.txt | 0 .../core/app-mgr/app-manager/event.c | 0 .../core/app-mgr/app-manager/event.h | 0 .../core/app-mgr/app-manager/message.c | 0 .../core/app-mgr/app-manager/module_config.h | 0 .../core/app-mgr/app-manager/module_jeff.c | 0 .../core/app-mgr/app-manager/module_jeff.h | 0 .../core/app-mgr/app-manager/module_utils.c | 0 .../app-mgr/app-manager/module_wasm_app.c | 2 +- .../app-mgr/app-manager/module_wasm_app.h | 0 .../app-mgr/app-manager/module_wasm_lib.c | 0 .../app-mgr/app-manager/module_wasm_lib.h | 0 .../platform/darwin/app_mgr_darwin.c | 0 .../platform/linux/app_mgr_linux.c | 0 .../platform/zephyr/app_mgr_zephyr.c | 0 .../core/app-mgr/app-manager/resource_reg.c | 0 .../core/app-mgr/app-manager/watchdog.c | 0 .../core/app-mgr/app-manager/watchdog.h | 0 .../app-mgr-shared/app_manager_export.h | 0 .../app-mgr-shared/app_mgr_shared.cmake | 0 .../core/app-mgr/app-mgr-shared/host_link.h | 0 .../core/app-mgr/module.json | 0 .../core/config.h | 47 +- .../core/iwasm/README.md | 0 .../core/iwasm/aot/SConscript | 0 .../core/iwasm/aot/aot_intrinsic.c | 129 + .../core/iwasm/aot/aot_intrinsic.h | 0 .../core/iwasm/aot/aot_loader.c | 511 +++- .../core/iwasm/aot/aot_reloc.h | 9 + .../core/iwasm/aot/aot_runtime.c | 980 +++++-- .../core/iwasm/aot/aot_runtime.h | 152 +- .../core/iwasm/aot/arch/aot_reloc_aarch64.c | 5 + .../core/iwasm/aot/arch/aot_reloc_arc.c | 0 .../core/iwasm/aot/arch/aot_reloc_arm.c | 2 + .../core/iwasm/aot/arch/aot_reloc_mips.c | 0 .../core/iwasm/aot/arch/aot_reloc_riscv.c | 111 +- .../core/iwasm/aot/arch/aot_reloc_thumb.c | 0 .../core/iwasm/aot/arch/aot_reloc_x86_32.c | 33 +- .../core/iwasm/aot/arch/aot_reloc_x86_64.c | 40 +- .../core/iwasm/aot/arch/aot_reloc_xtensa.c | 20 +- .../core/iwasm/aot/debug/LICENSE_NUTTX | 0 .../core/iwasm/aot/debug/NOTICE_NUTTX | 0 .../core/iwasm/aot/debug/elf.h | 0 .../core/iwasm/aot/debug/elf32.h | 0 .../core/iwasm/aot/debug/elf64.h | 0 .../core/iwasm/aot/debug/elf_parser.c | 0 .../core/iwasm/aot/debug/elf_parser.h | 0 .../core/iwasm/aot/debug/jit_debug.c | 0 .../core/iwasm/aot/debug/jit_debug.h | 0 .../core/iwasm/aot/iwasm_aot.cmake | 84 + .../core/iwasm/common/SConscript | 0 .../iwasm/common/arch/invokeNative_aarch64.s | 0 .../common/arch/invokeNative_aarch64_simd.s | 0 .../core/iwasm/common/arch/invokeNative_arc.s | 0 .../core/iwasm/common/arch/invokeNative_arm.s | 0 .../iwasm/common/arch/invokeNative_arm_vfp.s | 0 .../iwasm/common/arch/invokeNative_em64.asm | 0 .../iwasm/common/arch/invokeNative_em64.s | 0 .../common/arch/invokeNative_em64_simd.asm | 0 .../common/arch/invokeNative_em64_simd.s | 0 .../iwasm/common/arch/invokeNative_general.c | 0 .../iwasm/common/arch/invokeNative_ia32.asm | 0 .../iwasm/common/arch/invokeNative_ia32.s | 0 .../common/arch/invokeNative_mingw_x64.s | 0 .../common/arch/invokeNative_mingw_x64_simd.s | 0 .../iwasm/common/arch/invokeNative_mips.s | 0 .../common/arch/invokeNative_osx_universal.s | 0 .../iwasm/common/arch/invokeNative_riscv.S | 0 .../iwasm/common/arch/invokeNative_thumb.s | 0 .../common/arch/invokeNative_thumb_vfp.s | 0 .../iwasm/common/arch/invokeNative_xtensa.s | 0 .../core/iwasm/common/iwasm_common.cmake | 0 .../core/iwasm/common/wasm_application.c | 63 +- .../core/iwasm/common/wasm_blocking_op.c | 92 + .../core/iwasm/common/wasm_c_api.c | 124 +- .../core/iwasm/common/wasm_c_api_internal.h | 0 .../core/iwasm/common/wasm_exec_env.c | 48 +- .../core/iwasm/common/wasm_exec_env.h | 16 +- .../core/iwasm/common/wasm_memory.c | 316 ++- .../core/iwasm/common/wasm_memory.h | 49 + .../core/iwasm/common/wasm_native.c | 171 ++ .../core/iwasm/common/wasm_native.h | 30 + .../core/iwasm/common/wasm_runtime_common.c | 1005 +++++-- .../core/iwasm/common/wasm_runtime_common.h | 189 +- .../core/iwasm/common/wasm_shared_memory.c | 192 +- .../core/iwasm/common/wasm_shared_memory.h | 63 + .../core/iwasm/common/wasm_suspend_flags.h | 50 + .../core/iwasm/compilation/aot.c | 1 - .../core/iwasm/compilation/aot.h | 24 +- .../core/iwasm/compilation/aot_compiler.c | 193 +- .../core/iwasm/compilation/aot_compiler.h | 21 + .../iwasm/compilation/aot_emit_aot_file.c | 825 +++++- .../core/iwasm/compilation/aot_emit_compare.c | 0 .../core/iwasm/compilation/aot_emit_compare.h | 0 .../core/iwasm/compilation/aot_emit_const.c | 0 .../core/iwasm/compilation/aot_emit_const.h | 0 .../core/iwasm/compilation/aot_emit_control.c | 65 +- .../core/iwasm/compilation/aot_emit_control.h | 0 .../iwasm/compilation/aot_emit_conversion.c | 0 .../iwasm/compilation/aot_emit_conversion.h | 0 .../iwasm/compilation/aot_emit_exception.c | 0 .../iwasm/compilation/aot_emit_exception.h | 0 .../iwasm/compilation/aot_emit_function.c | 218 +- .../iwasm/compilation/aot_emit_function.h | 1 + .../core/iwasm/compilation/aot_emit_memory.c | 251 +- .../core/iwasm/compilation/aot_emit_memory.h | 2 +- .../iwasm/compilation/aot_emit_numberic.c | 36 +- .../iwasm/compilation/aot_emit_numberic.h | 0 .../iwasm/compilation/aot_emit_parametric.c | 0 .../iwasm/compilation/aot_emit_parametric.h | 0 .../core/iwasm/compilation/aot_emit_table.c | 0 .../core/iwasm/compilation/aot_emit_table.h | 0 .../iwasm/compilation/aot_emit_variable.c | 2 +- .../iwasm/compilation/aot_emit_variable.h | 0 .../core/iwasm/compilation/aot_llvm.c | 1073 ++++++- .../core/iwasm/compilation/aot_llvm.h | 83 +- .../core/iwasm/compilation/aot_llvm_extra.cpp | 280 +- .../iwasm/compilation/aot_llvm_extra2.cpp | 53 + .../core/iwasm/compilation/aot_llvm_extra2.h | 17 + .../core/iwasm/compilation/aot_orc_extra.cpp | 56 +- .../core/iwasm/compilation/aot_orc_extra.h | 8 + .../core/iwasm/compilation/aot_orc_extra2.cpp | 145 + .../compilation/debug/dwarf_extractor.cpp | 57 +- .../iwasm/compilation/debug/dwarf_extractor.h | 22 +- .../core/iwasm/compilation/iwasm_compl.cmake | 0 .../compilation/simd/simd_access_lanes.c | 0 .../compilation/simd/simd_access_lanes.h | 0 .../iwasm/compilation/simd/simd_bit_shifts.c | 20 +- .../iwasm/compilation/simd/simd_bit_shifts.h | 0 .../compilation/simd/simd_bitmask_extracts.c | 0 .../compilation/simd/simd_bitmask_extracts.h | 0 .../iwasm/compilation/simd/simd_bitwise_ops.c | 0 .../iwasm/compilation/simd/simd_bitwise_ops.h | 0 .../compilation/simd/simd_bool_reductions.c | 0 .../compilation/simd/simd_bool_reductions.h | 0 .../core/iwasm/compilation/simd/simd_common.c | 0 .../core/iwasm/compilation/simd/simd_common.h | 0 .../iwasm/compilation/simd/simd_comparisons.c | 0 .../iwasm/compilation/simd/simd_comparisons.h | 0 .../compilation/simd/simd_construct_values.c | 0 .../compilation/simd/simd_construct_values.h | 0 .../iwasm/compilation/simd/simd_conversions.c | 0 .../iwasm/compilation/simd/simd_conversions.h | 0 .../compilation/simd/simd_floating_point.c | 235 +- .../compilation/simd/simd_floating_point.h | 0 .../iwasm/compilation/simd/simd_int_arith.c | 0 .../iwasm/compilation/simd/simd_int_arith.h | 0 .../iwasm/compilation/simd/simd_load_store.c | 74 +- .../iwasm/compilation/simd/simd_load_store.h | 0 .../compilation/simd/simd_sat_int_arith.c | 0 .../compilation/simd/simd_sat_int_arith.h | 0 .../core/iwasm/doc/classic_interpreter.MD | 0 .../doc/images/export_function.excalidraw | 0 .../doc/images/stack_format_ci.excalidraw | 0 .../core/iwasm/doc/images/stack_format_ci.svg | 0 .../core/iwasm/doc/images/wasm_exports.svg | 0 .../iwasm/doc/images/wasm_function.excalidraw | 0 .../core/iwasm/doc/images/wasm_function.svg | 0 .../iwasm/doc/images/wasm_globals.excalidraw | 0 .../core/iwasm/doc/images/wasm_globals.svg | 0 .../core/iwasm/doc/wasm_exports.MD | 0 .../core/iwasm/doc/wasm_function.MD | 0 .../core/iwasm/doc/wasm_globals.MD | 0 .../core/iwasm/fast-jit/asmjit_sgx_patch.diff | 0 .../core/iwasm/fast-jit/cg/LICENSE_ASMJIT | 0 .../core/iwasm/fast-jit/cg/LICENSE_ZYDIS | 0 .../fast-jit/cg/x86-64/jit_codegen_x86_64.cpp | 0 .../core/iwasm/fast-jit/fe/jit_emit_compare.c | 4 +- .../core/iwasm/fast-jit/fe/jit_emit_compare.h | 0 .../core/iwasm/fast-jit/fe/jit_emit_const.c | 0 .../core/iwasm/fast-jit/fe/jit_emit_const.h | 0 .../core/iwasm/fast-jit/fe/jit_emit_control.c | 2 +- .../core/iwasm/fast-jit/fe/jit_emit_control.h | 0 .../iwasm/fast-jit/fe/jit_emit_conversion.c | 49 + .../iwasm/fast-jit/fe/jit_emit_conversion.h | 0 .../iwasm/fast-jit/fe/jit_emit_exception.c | 0 .../iwasm/fast-jit/fe/jit_emit_exception.h | 0 .../iwasm/fast-jit/fe/jit_emit_function.c | 34 +- .../iwasm/fast-jit/fe/jit_emit_function.h | 0 .../core/iwasm/fast-jit/fe/jit_emit_memory.c | 70 +- .../core/iwasm/fast-jit/fe/jit_emit_memory.h | 0 .../iwasm/fast-jit/fe/jit_emit_numberic.c | 8 + .../iwasm/fast-jit/fe/jit_emit_numberic.h | 0 .../iwasm/fast-jit/fe/jit_emit_parametric.c | 0 .../iwasm/fast-jit/fe/jit_emit_parametric.h | 0 .../core/iwasm/fast-jit/fe/jit_emit_table.c | 64 +- .../core/iwasm/fast-jit/fe/jit_emit_table.h | 0 .../iwasm/fast-jit/fe/jit_emit_variable.c | 0 .../iwasm/fast-jit/fe/jit_emit_variable.h | 0 .../core/iwasm/fast-jit/iwasm_fast_jit.cmake | 0 .../core/iwasm/fast-jit/jit_codecache.c | 4 +- .../core/iwasm/fast-jit/jit_codecache.h | 0 .../core/iwasm/fast-jit/jit_codegen.c | 0 .../core/iwasm/fast-jit/jit_codegen.h | 0 .../core/iwasm/fast-jit/jit_compiler.c | 0 .../core/iwasm/fast-jit/jit_compiler.h | 1 + .../core/iwasm/fast-jit/jit_dump.c | 0 .../core/iwasm/fast-jit/jit_dump.h | 0 .../core/iwasm/fast-jit/jit_frontend.c | 478 +++- .../core/iwasm/fast-jit/jit_frontend.h | 6 + .../core/iwasm/fast-jit/jit_ir.c | 0 .../core/iwasm/fast-jit/jit_ir.def | 0 .../core/iwasm/fast-jit/jit_ir.h | 2 + .../core/iwasm/fast-jit/jit_regalloc.c | 0 .../core/iwasm/fast-jit/jit_utils.h | 42 + .../core/iwasm/include/aot_export.h | 11 +- .../core/iwasm/include/lib_export.h | 0 .../core/iwasm/include/wasm_c_api.h | 80 +- .../core/iwasm/include/wasm_export.h | 279 +- .../core/iwasm/interpreter/SConscript | 0 .../core/iwasm/interpreter/iwasm_interp.cmake | 0 .../core/iwasm/interpreter/wasm.h | 22 +- .../core/iwasm/interpreter/wasm_interp.h | 0 .../iwasm/interpreter/wasm_interp_classic.c | 330 ++- .../core/iwasm/interpreter/wasm_interp_fast.c | 308 +- .../core/iwasm/interpreter/wasm_loader.c | 424 +-- .../core/iwasm/interpreter/wasm_loader.h | 0 .../core/iwasm/interpreter/wasm_mini_loader.c | 136 +- .../core/iwasm/interpreter/wasm_opcode.h | 0 .../core/iwasm/interpreter/wasm_runtime.c | 511 ++-- .../core/iwasm/interpreter/wasm_runtime.h | 65 +- .../libraries/debug-engine/debug_engine.c | 0 .../libraries/debug-engine/debug_engine.cmake | 0 .../libraries/debug-engine/debug_engine.h | 0 .../iwasm/libraries/debug-engine/gdbserver.c | 0 .../iwasm/libraries/debug-engine/gdbserver.h | 0 .../iwasm/libraries/debug-engine/handler.c | 0 .../iwasm/libraries/debug-engine/handler.h | 0 .../iwasm/libraries/debug-engine/packets.c | 0 .../iwasm/libraries/debug-engine/packets.h | 0 .../core/iwasm/libraries/debug-engine/utils.c | 0 .../core/iwasm/libraries/debug-engine/utils.h | 0 .../iwasm/libraries/lib-pthread/SConscript | 0 .../libraries/lib-pthread/lib_pthread.cmake | 0 .../lib-pthread/lib_pthread_wrapper.c | 28 +- .../iwasm/libraries/lib-rats/lib_rats.cmake | 10 + .../libraries/lib-rats/lib_rats_common.h | 0 .../libraries/lib-rats/lib_rats_wrapper.c | 16 +- .../libraries/lib-rats/lib_rats_wrapper.h | 3 + .../lib-socket/inc/wasi_socket_ext.h | 4 +- .../lib-socket/lib_socket_wasi.cmake | 0 .../lib-socket/src/wasi/wasi_socket_ext.c | 5 + .../iwasm/libraries/lib-socket/test/build.sh | 0 .../libraries/lib-socket/test/manifest.json | 3 + .../libraries/lib-socket/test/nslookup.c | 23 +- .../iwasm/libraries/lib-socket/test/tcp_udp.c | 192 ++ .../lib-wasi-threads/lib_wasi_threads.cmake | 0 .../lib_wasi_threads_wrapper.c | 11 +- .../lib-wasi-threads/stress-test/build.sh | 66 + .../errorcheck_mutex_stress_test.c | 34 + .../stress-test/manifest.json | 3 + .../stress-test/mutex_common.h | 229 ++ .../stress-test/normal_mutex_stress_test.c | 27 + .../stress-test/recursive_mutex_stress_test.c | 72 + .../stress-test/spawn_stress_test.c | 125 + .../stress_test_threads_creation.c | 101 + .../libraries/lib-wasi-threads/test/build.sh | 75 + .../libraries/lib-wasi-threads/test/common.h | 0 .../test/create_threads_until_limit.c | 2 +- .../lib-wasi-threads/test/global_atomic.c | 2 +- .../lib-wasi-threads/test/global_lock.c | 2 +- .../test/linear_memory_size_update.c | 0 .../test/main_proc_exit_busy.c | 0 .../test/main_proc_exit_busy.json | 0 .../test/main_proc_exit_sleep.c | 0 .../test/main_proc_exit_sleep.json | 0 .../test/main_proc_exit_wait.c | 0 .../test/main_proc_exit_wait.json | 0 .../lib-wasi-threads/test/main_trap_busy.c | 0 .../lib-wasi-threads/test/main_trap_busy.json | 0 .../lib-wasi-threads/test/main_trap_sleep.c | 0 .../test/main_trap_sleep.json | 0 .../lib-wasi-threads/test/main_trap_wait.c | 0 .../lib-wasi-threads/test/main_trap_wait.json | 0 .../lib-wasi-threads/test/manifest.json | 3 + .../test/nonmain_proc_exit_busy.c | 0 .../test/nonmain_proc_exit_busy.json | 0 .../test/nonmain_proc_exit_sleep.c | 0 .../test/nonmain_proc_exit_sleep.json | 0 .../test/nonmain_proc_exit_wait.c | 0 .../test/nonmain_proc_exit_wait.json | 0 .../lib-wasi-threads/test/nonmain_trap_busy.c | 0 .../test/nonmain_trap_busy.json | 0 .../test/nonmain_trap_sleep.c | 0 .../test/nonmain_trap_sleep.json | 0 .../lib-wasi-threads/test/nonmain_trap_wait.c | 0 .../test/nonmain_trap_wait.json | 0 .../test/spawn_multiple_times.c | 0 .../lib-wasi-threads/test/sync_primitives.h | 0 .../test/trap_after_main_thread_finishes.c | 2 +- .../test/update_shared_data_and_alloc_heap.c | 2 +- .../lib-wasi-threads/tid_allocator.c | 11 +- .../lib-wasi-threads/tid_allocator.h | 10 + .../lib_wasi_threads_unit_tests.cmake | 6 + .../unit-test/test_tid_allocator.cpp | 62 + .../iwasm/libraries/libc-builtin/SConscript | 0 .../libraries/libc-builtin/libc_builtin.cmake | 0 .../libc-builtin/libc_builtin_wrapper.c | 0 .../core/iwasm/libraries/libc-emcc/SConscript | 0 .../iwasm/libraries/libc-emcc/libc_emcc.cmake | 0 .../libraries/libc-emcc/libc_emcc_wrapper.c | 0 .../libraries/libc-uvwasi/FindLIBUV.cmake | 28 + .../libraries/libc-uvwasi/FindUVWASI.cmake | 25 + .../iwasm/libraries/libc-uvwasi/LICENSE_LIBUV | 0 .../libraries/libc-uvwasi/LICENSE_UVWASI | 0 .../libraries/libc-uvwasi/libc_uvwasi.cmake | 61 + .../libc-uvwasi/libc_uvwasi_wrapper.c | 11 +- .../core/iwasm/libraries/libc-wasi/SConscript | 0 .../iwasm/libraries/libc-wasi/libc_wasi.cmake | 0 .../libraries/libc-wasi/libc_wasi_wrapper.c | 223 +- .../libraries/libc-wasi/libc_wasi_wrapper.h | 12 +- .../sandboxed-system-primitives/LICENSE | 0 .../include/LICENSE | 0 .../include/wasmtime_ssp.h | 606 ++++ .../sandboxed-system-primitives/src/LICENSE | 0 .../sandboxed-system-primitives/src/README.md | 0 .../src/blocking_op.c | 172 ++ .../src/blocking_op.h | 53 + .../sandboxed-system-primitives/src/locking.h | 54 +- .../sandboxed-system-primitives/src/posix.c | 2465 ++++++----------- .../sandboxed-system-primitives/src/posix.h | 3 +- .../sandboxed-system-primitives/src/queue.h | 0 .../sandboxed-system-primitives/src/random.c | 79 +- .../sandboxed-system-primitives/src/random.h | 8 +- .../src/refcount.h | 0 .../sandboxed-system-primitives/src/rights.h | 0 .../src/ssp_config.h | 63 +- .../sandboxed-system-primitives/src/str.c | 0 .../sandboxed-system-primitives/src/str.h | 0 .../iwasm/libraries/thread-mgr/SConscript | 0 .../libraries/thread-mgr/thread_manager.c | 231 +- .../libraries/thread-mgr/thread_manager.h | 12 +- .../libraries/thread-mgr/thread_mgr.cmake | 0 .../core/iwasm/libraries/wasi-nn/.gitignore | 2 + .../core/iwasm/libraries/wasi-nn/README.md | 42 +- .../wasi-nn/cmake/Findtensorflow_lite.cmake | 42 + .../wasi-nn/cmake/iwasm_helper.cmake | 46 + .../libraries/wasi-nn/cmake/wasi_nn.cmake | 22 + .../libraries/wasi-nn/external/CMakeLists.txt | 58 + .../libraries/wasi-nn/external/README.md | 13 + .../libraries/wasi-nn/include}/wasi_nn.h | 0 .../wasi-nn/include}/wasi_nn_types.h | 3 + .../libraries/wasi-nn/src/utils/logger.h | 0 .../wasi-nn/src/utils/wasi_nn_app_native.c | 0 .../wasi-nn/src/utils/wasi_nn_app_native.h | 0 .../iwasm/libraries/wasi-nn/src/wasi_nn.c | 197 +- .../libraries/wasi-nn/src/wasi_nn_private.h | 11 +- .../wasi-nn/src/wasi_nn_tensorflowlite.cpp | 136 +- .../wasi-nn/src/wasi_nn_tensorflowlite.hpp | 0 .../libraries/wasi-nn/test/Dockerfile.compile | 26 + .../libraries/wasi-nn/test/Dockerfile.cpu | 35 + .../wasi-nn/test/Dockerfile.nvidia-gpu | 49 + .../libraries/wasi-nn/test/Dockerfile.tpu | 37 + .../wasi-nn/test/Dockerfile.vx-delegate | 113 + .../iwasm/libraries/wasi-nn/test/build.sh | 24 +- .../libraries/wasi-nn/test/models/average.py | 0 .../libraries/wasi-nn/test/models/max.py | 0 .../wasi-nn/test/models/mult_dimension.py | 0 .../wasi-nn/test/models/mult_outputs.py | 0 .../wasi-nn/test/models/quantized.py | 30 + .../libraries/wasi-nn/test/models/sum.py | 0 .../libraries/wasi-nn/test/models/utils.py | 0 .../libraries/wasi-nn/test/requirements.txt | 0 .../libraries/wasi-nn/test/test_tensorflow.c | 19 +- .../wasi-nn/test/test_tensorflow_quantized.c | 63 + .../core/iwasm/libraries/wasi-nn/test/utils.c | 4 +- .../core/iwasm/libraries/wasi-nn/test/utils.h | 2 +- .../core/shared/coap/er-coap/LICENSE.md | 0 .../core/shared/coap/er-coap/coap-constants.h | 0 .../core/shared/coap/extension/coap_ext.h | 0 .../core/shared/coap/lib_coap.cmake | 0 .../core/shared/mem-alloc/SConscript | 0 .../core/shared/mem-alloc/ems/ems_alloc.c | 57 +- .../core/shared/mem-alloc/ems/ems_gc.h | 0 .../shared/mem-alloc/ems/ems_gc_internal.h | 7 +- .../core/shared/mem-alloc/ems/ems_hmu.c | 2 + .../core/shared/mem-alloc/ems/ems_kfc.c | 19 +- .../core/shared/mem-alloc/mem_alloc.c | 0 .../core/shared/mem-alloc/mem_alloc.cmake | 8 + .../core/shared/mem-alloc/mem_alloc.h | 0 .../core/shared/platform/README.md | 0 .../shared/platform/alios/alios_platform.c | 6 +- .../core/shared/platform/alios/alios_thread.c | 4 + .../core/shared/platform/alios/alios_time.c | 0 .../shared/platform/alios/platform_internal.h | 18 + .../platform/alios/shared_platform.cmake | 0 .../shared/platform/android/platform_init.c | 0 .../platform/android/platform_internal.h | 14 +- .../platform/android/shared_platform.cmake | 0 .../common/freertos/freertos_malloc.c | 0 .../common/freertos/freertos_thread.c | 0 .../platform/common/freertos/freertos_time.c | 0 .../freertos/platform_api_freertos.cmake | 0 .../platform/common/libc-util/libc_errno.c | 256 ++ .../platform/common/libc-util/libc_errno.h | 15 + .../libc-util/platform_common_libc_util.cmake | 8 + .../shared/platform/common/math/COPYRIGHT | 0 .../core/shared/platform/common/math/math.c | 0 .../common/math/platform_api_math.cmake | 0 .../common/posix/platform_api_posix.cmake | 19 + .../platform/common/posix/posix_blocking_op.c | 69 + .../platform/common/posix/posix_clock.c | 86 + .../shared/platform/common/posix/posix_file.c | 1007 +++++++ .../platform/common/posix/posix_malloc.c | 0 .../platform/common/posix/posix_memmap.c | 22 +- .../platform/common/posix/posix_sleep.c | 20 + .../platform/common/posix/posix_socket.c | 32 +- .../platform/common/posix/posix_thread.c | 103 +- .../shared/platform/common/posix/posix_time.c | 0 .../platform/cosmopolitan}/platform_init.c | 0 .../cosmopolitan}/platform_internal.h | 26 +- .../cosmopolitan/shared_platform.cmake | 19 + .../shared/platform/darwin}/platform_init.c | 0 .../platform/darwin/platform_internal.h | 17 + .../platform/darwin/shared_platform.cmake | 0 .../core/shared/platform/ego/platform_init.c | 0 .../shared/platform/ego/platform_internal.h | 0 .../shared/platform/ego/shared_platform.cmake | 0 .../shared/platform/esp-idf/espidf_malloc.c | 0 .../shared/platform/esp-idf/espidf_memmap.c | 118 + .../shared/platform/esp-idf/espidf_platform.c | 4 + .../shared/platform/esp-idf/espidf_socket.c | 11 +- .../shared/platform/esp-idf/espidf_thread.c | 0 .../platform/esp-idf/platform_internal.h | 11 + .../platform/esp-idf/shared_platform.cmake | 6 + .../shared/platform/freebsd}/platform_init.c | 0 .../platform/freebsd/platform_internal.h | 19 + .../platform/freebsd/shared_platform.cmake | 0 .../platform/include/platform_api_extension.h | 606 +++- .../platform/include/platform_api_vmcore.h | 20 +- .../shared/platform/include/platform_common.h | 0 .../platform/include/platform_wasi_types.h | 610 ++++ .../platform/linux-sgx/platform_internal.h | 11 + .../core/shared/platform/linux-sgx/sgx_file.c | 0 .../core/shared/platform/linux-sgx/sgx_file.h | 0 .../core/shared/platform/linux-sgx/sgx_ipfs.c | 0 .../core/shared/platform/linux-sgx/sgx_ipfs.h | 1 - .../shared/platform/linux-sgx/sgx_platform.c | 13 +- .../shared/platform/linux-sgx/sgx_pthread.c | 0 .../shared/platform/linux-sgx/sgx_pthread.h | 0 .../platform/linux-sgx/sgx_rsrv_mem_mngr.h | 0 .../shared/platform/linux-sgx/sgx_signal.c | 0 .../shared/platform/linux-sgx/sgx_signal.h | 0 .../shared/platform/linux-sgx/sgx_socket.c | 12 +- .../shared/platform/linux-sgx/sgx_socket.h | 0 .../shared/platform/linux-sgx/sgx_thread.c | 69 + .../core/shared/platform/linux-sgx/sgx_time.c | 0 .../core/shared/platform/linux-sgx/sgx_time.h | 0 .../shared/platform/linux-sgx/sgx_wamr.edl | 0 .../platform/linux-sgx/shared_platform.cmake | 15 +- .../platform/linux-sgx/untrusted/file.c | 0 .../platform/linux-sgx/untrusted/pthread.c | 0 .../platform/linux-sgx/untrusted/signal.c | 0 .../platform/linux-sgx/untrusted/socket.c | 0 .../platform/linux-sgx/untrusted/time.c | 0 .../shared/platform/linux}/platform_init.c | 0 .../shared/platform/linux/platform_internal.h | 139 + .../platform/linux/shared_platform.cmake | 0 .../shared/platform/nuttx/nuttx_platform.c | 85 +- .../shared/platform/nuttx/platform_internal.h | 17 + .../platform/nuttx/shared_platform.cmake | 6 + .../shared/platform/riot/platform_internal.h | 18 + .../core/shared/platform/riot/riot_platform.c | 6 +- .../core/shared/platform/riot/riot_thread.c | 4 + .../core/shared/platform/riot/riot_time.c | 0 .../platform/riot/shared_platform.cmake | 0 .../core/shared/platform/rt-thread/SConscript | 0 .../platform/rt-thread/platform_internal.h | 18 + .../shared/platform/rt-thread/rtt_platform.c | 10 +- .../platform/rt-thread/shared_platform.cmake | 0 .../shared/platform/vxworks/platform_init.c | 43 + .../platform/vxworks/platform_internal.h | 11 + .../platform/vxworks/shared_platform.cmake | 0 .../shared/platform/windows/platform_init.c | 4 + .../platform/windows/platform_internal.h | 66 +- .../platform/windows/shared_platform.cmake | 7 + .../shared/platform/windows/win_atomic.cpp | 4 +- .../core/shared/platform/windows/win_clock.c | 143 + .../core/shared/platform/windows/win_file.c | 1447 ++++++++++ .../core/shared/platform/windows/win_malloc.c | 0 .../core/shared/platform/windows/win_memmap.c | 2 +- .../core/shared/platform/windows/win_socket.c | 192 +- .../core/shared/platform/windows/win_thread.c | 60 + .../core/shared/platform/windows/win_time.c | 0 .../core/shared/platform/windows/win_util.c | 146 + .../core/shared/platform/windows/win_util.h | 23 + .../platform/zephyr/platform_internal.h | 34 +- .../platform/zephyr/shared_platform.cmake | 0 .../shared/platform/zephyr/zephyr_platform.c | 6 +- .../shared/platform/zephyr/zephyr_thread.c | 4 + .../core/shared/platform/zephyr/zephyr_time.c | 0 .../core/shared/utils/SConscript | 0 .../core/shared/utils/bh_assert.c | 0 .../core/shared/utils/bh_assert.h | 0 .../core/shared/utils/bh_atomic.h | 221 ++ .../core/shared/utils/bh_bitmap.c | 27 + .../core/shared/utils/bh_bitmap.h} | 54 +- .../core/shared/utils/bh_common.c | 4 + .../core/shared/utils/bh_common.h | 30 +- .../core/shared/utils/bh_hashmap.c | 0 .../core/shared/utils/bh_hashmap.h | 0 .../core/shared/utils/bh_list.c | 0 .../core/shared/utils/bh_list.h | 0 .../core/shared/utils/bh_log.c | 0 .../core/shared/utils/bh_log.h | 0 .../core/shared/utils/bh_platform.h | 0 .../core/shared/utils/bh_queue.c | 0 .../core/shared/utils/bh_queue.h | 0 .../core/shared/utils/bh_vector.c | 0 .../core/shared/utils/bh_vector.h | 0 .../core/shared/utils}/gnuc.h | 0 .../core/shared/utils/runtime_timer.c | 0 .../core/shared/utils/runtime_timer.h | 0 .../core/shared/utils/shared_utils.cmake | 0 .../core/shared/utils/uncommon/SConscript | 0 .../core/shared/utils/uncommon/bh_getopt.c | 0 .../core/shared/utils/uncommon/bh_getopt.h | 0 .../core/shared/utils/uncommon/bh_read_file.c | 0 .../core/shared/utils/uncommon/bh_read_file.h | 0 .../utils/uncommon/shared_uncommon.cmake | 0 .../core/version.h | 4 +- .../doc/build_wamr.md | 24 +- .../doc/build_wasm_app.md | 4 +- .../doc/devcontainer.md | 0 .../doc/embed_wamr.md | 87 +- .../doc/embed_wamr_spawn_api.md | 38 + .../doc/export_native_api.md | 30 +- .../doc/linux_sgx.md | 0 .../doc/memory_tune.md | 2 +- .../doc/memory_usage.md | 0 .../doc/multi_module.md | 0 .../doc/other_wasm_compilers.md | 0 .../doc/perf_tune.md | 179 ++ .../doc/pics/app_framework.PNG | Bin .../doc/pics/embed.PNG | Bin .../doc/pics/extend_library.PNG | Bin .../doc/pics/multi_module_pic1.png | Bin .../doc/pics/native_call_wasm.PNG | Bin .../doc/pics/request.PNG | Bin .../doc/pics/safe.PNG | Bin .../doc/pics/sensor_callflow.PNG | Bin .../doc/pics/sub.PNG | Bin .../doc/pics/vgl_demo.png | Bin .../doc/pics/vgl_demo2.png | Bin .../doc/pics/vgl_demo_linux.png | Bin .../doc/pics/vgl_linux.PNG | Bin .../doc/pics/wamr-arch.JPG | Bin .../doc/pics/wamr_memory_model.png | Bin .../doc/pics/wamr_menu_config.png | Bin .../doc/port_wamr.md | 0 .../doc/pthread_impls.md | 0 .../doc/pthread_library.md | 0 .../doc/ref_types.md | 0 .../doc/release_ack.md | 0 .../doc/roadmap.md | 0 .../doc/semantic_version.md | 0 .../doc/socket_api.md | 2 +- .../doc/source_debugging.md | 2 +- .../doc/wamr_api.md | 0 .../doc/wasm_c_api.md | 0 lib/wasm-micro-runtime-WAMR-1.3.0/doc/xip.md | 131 + .../language-bindings/go/README.md | 0 .../language-bindings/go/build.sh | 0 .../language-bindings/go/go.mod | 5 + .../language-bindings/go/go.sum | 0 .../language-bindings/go/samples/build.sh | 15 + .../language-bindings/go/samples/run.sh | 0 .../language-bindings/go/samples/test.go | 2 +- .../go/samples/wasm-app/build.sh | 0 .../go/samples/wasm-app/main.c | 0 .../language-bindings/go/wamr/cgo.go | 0 .../language-bindings/go/wamr/instance.go | 2 + .../go/wamr/instance_test.go | 0 .../language-bindings/go/wamr/module.go | 0 .../language-bindings/go/wamr/module_test.go | 0 .../go/wamr/packaged/include/dummy.go | 0 .../wamr/packaged/lib/darwin-aarch64/dummy.go | 0 .../wamr/packaged/lib/darwin-amd64/dummy.go | 0 .../go/wamr/packaged/lib/dummy.go | 0 .../go/wamr/packaged/lib/linux-amd64/dummy.go | 0 .../language-bindings/go/wamr/runtime.go | 0 .../language-bindings/go/wamr/runtime_test.go | 0 .../language-bindings/python/.gitignore | 0 .../language-bindings/python/LICENSE | 0 .../language-bindings/python/MANIFEST.in | 0 .../language-bindings/python/README.md | 2 + .../language-bindings/python/pyproject.toml | 0 .../language-bindings/python/setup.py | 1 + .../python/src/wamr/__init__.py | 0 .../python/src/wamr/libs/.placeholder | 0 .../python/src/wamr/wamrapi/__init__.py | 0 .../python/src/wamr/wamrapi/wamr.py | 143 +- .../python/src/wamr/wasmcapi/__init__.py | 0 .../python/src/wamr/wasmcapi/binding.py | 0 .../python/src/wamr/wasmcapi/ffi.py | 0 .../python/utils/create_lib.sh | 7 +- .../python/wamr-api/README.md | 11 +- .../python/wamr-api/requirements.txt | 0 .../python/wamr-api/samples/basic}/compile.sh | 0 .../python/wamr-api/samples/basic}/main.py | 0 .../python/wamr-api/samples/basic}/sum.c | 0 .../wamr-api/samples/native-symbol/README.md | 44 + .../wamr-api/samples/native-symbol/compile.sh | 14 + .../wamr-api/samples/native-symbol/func.c | 30 + .../wamr-api/samples/native-symbol/main.py | 59 + .../python/wasm-c-api/README.md | 0 .../python/wasm-c-api/docs/design.md | 0 .../docs/images/python_package_life_cycle.png | Bin .../python/wasm-c-api/docs/setup_dev_env.md | 0 .../python/wasm-c-api/requirements.txt | 0 .../python/wasm-c-api/samples/hello.wat | 0 .../python/wasm-c-api/samples/hello_oop.py | 0 .../wasm-c-api/samples/hello_procedural.py | 0 .../python/wasm-c-api/tests/__init__.py | 0 .../python/wasm-c-api/tests/context.py | 0 .../python/wasm-c-api/tests/test_advanced.py | 0 .../python/wasm-c-api/tests/test_basic.py | 0 .../python/wasm-c-api/utils/bindgen.py | 0 .../product-mini/README.md | 32 +- .../hello-world-cmake/CMakeLists.txt | 0 .../app-samples/hello-world-cmake/build.sh | 0 .../app-samples/hello-world-cmake/main.c | 0 .../app-samples/hello-world-cmake/print.c | 0 .../app-samples/hello-world/build.sh | 0 .../app-samples/hello-world/main.c | 0 .../platforms/alios-things/aos.mk | 1 + .../platforms/alios-things/src/main.c | 0 .../platforms/alios-things/src/test_wasm.h | 0 .../platforms/android/CMakeLists.txt | 0 .../platforms/android/build_jit.sh | 0 .../platforms/android/build_llvm.sh | 0 .../platforms/android/wasm-jni.cpp | 0 .../product-mini/platforms/common/libc_wasi.c | 177 ++ .../platforms/cosmopolitan}/CMakeLists.txt | 62 +- .../platforms/cosmopolitan/build_cosmocc.sh | 10 + .../platforms/cosmopolitan}/main.c | 0 .../platforms/darwin/CMakeLists.txt | 2 +- .../platforms/darwin/build_jit.sh | 0 .../platforms/darwin/build_llvm.sh | 0 .../product-mini/platforms/darwin}/main.c | 0 .../product-mini/platforms/esp-idf/.gitignore | 0 .../platforms/esp-idf/CMakeLists.txt | 0 .../platforms/esp-idf/build_and_run.sh | 4 +- .../platforms/esp-idf/main/CMakeLists.txt | 0 .../platforms/esp-idf/main/main.c | 8 +- .../platforms/esp-idf/main/test_wasm.h | 0 .../platforms/esp-idf/sdkconfig.defaults | 0 .../esp-idf/sdkconfig.defaults.esp32 | 0 .../esp-idf/sdkconfig.defaults.esp32c3 | 0 .../platforms/freebsd/CMakeLists.txt | 2 +- .../platforms/freebsd/build_jit.sh | 0 .../platforms/freebsd/build_llvm.sh | 0 .../product-mini/platforms/freebsd}/main.c | 0 .../product-mini/platforms/ios/CMakeLists.txt | 2 +- .../platforms/ios/generate_xcodeproj.sh | 0 .../platforms/linux-sgx/CMakeLists.txt | 17 + .../linux-sgx/CMakeLists_minimal.txt | 0 .../linux-sgx/enclave-sample/Makefile | 11 +- .../linux-sgx/enclave-sample/Makefile_minimal | 0 .../platforms/linux/CMakeLists.txt | 28 +- .../product-mini/platforms/linux/build_jit.sh | 0 .../platforms/linux/build_llvm.sh | 0 .../product-mini/platforms/linux}/main.c | 0 .../product-mini/platforms/nuttx}/main.c | 0 .../product-mini/platforms/nuttx/wamr.mk | 50 + .../product-mini/platforms/posix/main.c | 624 +++-- .../platforms/riot/CMakeLists.txt | 0 .../product-mini/platforms/riot/Makefile | 0 .../product-mini/platforms/riot/iwasmt.c | 0 .../product-mini/platforms/riot/test_wasm.h | 0 .../platforms/rt-thread/SConscript | 0 .../product-mini/platforms/rt-thread/iwasm.c | 13 +- .../platforms/rt-thread/iwasm.cmake | 0 .../platforms/vxworks/CMakeLists.txt | 0 .../product-mini/platforms/vxworks/main.c | 6 + .../platforms/windows/CMakeLists.txt | 18 +- .../platforms/windows/build_llvm.py | 0 .../product-mini/platforms/windows/main.c | 191 +- .../windows/wasi_filtered_tests.json | 51 + .../platforms/zephyr/simple/CMakeLists.txt | 0 .../platforms/zephyr/simple/Dockerfile | 43 + .../platforms/zephyr/simple/README.md | 108 + .../zephyr/simple/boards/nucleo_f767zi.conf} | 3 - .../zephyr/simple/boards/qemu_cortex_a53.conf | 3 - .../platforms/zephyr/simple/build_and_run.sh | 24 +- .../platforms/zephyr/simple/prj.conf} | 0 .../platforms/zephyr/simple/src/main.c | 86 +- .../platforms/zephyr/simple/src/test_wasm.h | 0 .../zephyr/simple/src/test_wasm_riscv64.h | 0 .../simple/src/wasm-app-riscv64/build.sh | 0 .../zephyr/simple/src/wasm-app-riscv64/main.c | 0 .../samples/README.md | 0 .../samples/basic/.gitignore | 0 .../samples/basic/CMakeLists.txt | 1 - .../samples/basic/README.md | 0 .../samples/basic/build.sh | 0 .../samples/basic/run.sh | 0 .../samples/basic/src/main.c | 0 .../samples/basic/src/native_impl.c | 0 .../samples/basic/wasm-apps/testapp.c | 2 +- .../samples/bh-atomic/CMakeLists.txt | 20 + .../samples/bh-atomic/main.c | 42 + .../samples/file/CMakeLists.txt | 0 .../samples/file/README.md | 0 .../samples/file/src/CMakeLists.txt | 1 - .../samples/file/src/main.c | 0 .../samples/file/wasm-app/CMakeLists.txt | 0 .../samples/file/wasm-app/main.c | 0 .../samples/gui/README.md | 0 .../samples/gui/build.sh | 0 .../samples/gui/lv_config/lv_conf.h | 0 .../samples/gui/lv_config/lv_drv_conf.h | 0 .../samples/gui/lv_config/system_header.h | 0 .../samples/gui/wamr_config_gui.cmake | 0 .../samples/gui/wasm-apps/build_apps.sh | 0 .../samples/gui/wasm-apps/decrease/Makefile | 0 .../samples/gui/wasm-apps/decrease/src/main.c | 16 +- .../gui/wasm-apps/increase/CMakeLists.txt | 0 .../samples/gui/wasm-apps/increase/Makefile | 0 .../samples/gui/wasm-apps/increase/src/main.c | 16 +- .../src/platform/linux/iwasm_main.c | 0 .../src/platform/linux/lv_drv_conf.h | 0 .../src/platform/linux/main.c | 0 .../src/platform/zephyr/LICENSE | 0 .../src/platform/zephyr/XPT2046.c | 0 .../src/platform/zephyr/XPT2046.h | 0 .../src/platform/zephyr/board_config.h | 0 .../src/platform/zephyr/display.h | 0 .../src/platform/zephyr/display_ili9340.c | 0 .../src/platform/zephyr/display_ili9340.h | 0 .../zephyr/display_ili9340_adafruit_1480.c | 0 .../src/platform/zephyr/iwasm_main.c | 0 .../src/platform/zephyr/main.c | 0 .../src/platform/zephyr/pin_config_jlf.h | 0 .../src/platform/zephyr/pin_config_stm32.h | 0 .../samples/inst-context-threads/.gitignore | 1 + .../inst-context-threads/CMakeLists.txt | 91 + .../samples/inst-context-threads/README.md | 5 + .../samples/inst-context-threads/build.sh | 61 + .../samples/inst-context-threads/run.sh | 3 + .../samples/inst-context-threads/src/main.c | 151 + .../inst-context-threads/src/my_context.h | 11 + .../inst-context-threads/src/native_impl.c | 32 + .../inst-context-threads/wasm-apps/testapp.c | 65 + .../samples/inst-context/.gitignore | 1 + .../samples/inst-context/CMakeLists.txt | 90 + .../samples/inst-context/README.md | 4 + .../samples/inst-context/build.sh | 63 + .../samples/inst-context/run.sh | 3 + .../samples/inst-context/src/main.c | 166 ++ .../samples/inst-context/src/my_context.h | 10 + .../samples/inst-context/src/native_impl.c | 15 + .../samples/inst-context/wasm-apps/testapp.c | 19 + .../samples/littlevgl/LICENCE.txt | 0 .../samples/littlevgl/README.md | 0 .../samples/littlevgl/build.sh | 0 .../samples/littlevgl/lv_config/lv_conf.h | 0 .../samples/littlevgl/lv_config/lv_drv_conf.h | 0 .../vgl-native-ui-app/CMakeLists.txt | 0 .../vgl-native-ui-app/CMakeLists.txt.in | 0 .../vgl-native-ui-app/lv-drivers/.gitignore | 0 .../lv-drivers/display_indev.h | 0 .../lv-drivers/indev/mouse.c | 0 .../lv-drivers/indev/mouse.h | 0 .../lv-drivers/linux_display_indev.c | 0 .../lv-drivers/system_header.h | 0 .../littlevgl/vgl-native-ui-app/main.c | 0 .../littlevgl/vgl-wasm-runtime/CMakeLists.txt | 0 .../vgl-wasm-runtime/src/display_indev.h | 0 .../src/platform/linux/display_indev.c | 0 .../src/platform/linux/iwasm_main.c | 0 .../src/platform/linux/main.c | 0 .../src/platform/linux/mouse.c | 0 .../src/platform/zephyr/LICENSE | 0 .../src/platform/zephyr/XPT2046.c | 0 .../src/platform/zephyr/XPT2046.h | 0 .../src/platform/zephyr/board_config.h | 0 .../src/platform/zephyr/display.h | 0 .../src/platform/zephyr/display_ili9340.c | 0 .../src/platform/zephyr/display_ili9340.h | 0 .../zephyr/display_ili9340_adafruit_1480.c | 0 .../src/platform/zephyr/display_indev.c | 0 .../src/platform/zephyr/iwasm_main.c | 0 .../src/platform/zephyr/main.c | 0 .../src/platform/zephyr/pin_config_jlf.h | 0 .../src/platform/zephyr/pin_config_stm32.h | 0 .../littlevgl/wamr_config_littlevgl.cmake | 0 .../littlevgl/wasm-apps/Makefile_wasm_app | 0 .../wasm-apps/Makefile_wasm_app_no_wasi | 0 .../littlevgl/wasm-apps/build_wasm_app.sh | 0 .../littlevgl/wasm-apps/src/display_indev.h | 0 .../samples/littlevgl/wasm-apps/src/main.c | 0 .../littlevgl/wasm-apps/src/system_header.h | 0 .../samples/mem-allocator/CMakeLists.txt | 22 + .../samples/mem-allocator/main.c | 58 + .../samples/multi-module/CMakeLists.txt | 45 +- .../samples/multi-module/README.md | 20 + .../samples/multi-module/src/main.c | 67 +- .../multi-module/wasm-apps/CMakeLists.txt | 0 .../samples/multi-module/wasm-apps/mA.c | 0 .../samples/multi-module/wasm-apps/mB.c | 0 .../samples/multi-module/wasm-apps/mC.c | 0 .../samples/multi-module/wasm-apps/mD.cpp | 0 .../samples/multi-module/wasm-apps/mE.cpp | 0 .../samples/multi-thread/CMakeLists.txt | 0 .../multi-thread/wasm-apps/CMakeLists.txt | 0 .../samples/multi-thread/wasm-apps/main.c | 0 .../wasm-apps/main_global_atomic.c | 0 .../wasm-apps/main_thread_exception.c | 0 .../samples/native-lib/CMakeLists.txt | 0 .../samples/native-lib/README.md | 4 +- .../samples/native-lib/test_add.c | 0 .../samples/native-lib/test_hello.c | 0 .../samples/native-lib/test_hello2.c | 13 + .../samples/native-lib/test_sqrt.c | 0 .../native-lib/wasm-app/CMakeLists.txt | 0 .../samples/native-lib/wasm-app/main.c | 0 .../samples/ref-types/CMakeLists.txt | 1 - .../samples/ref-types/src/hello.c | 4 +- .../samples/ref-types/src/hello.wat | 0 .../samples/sgx-ra/CMakeLists.txt | 0 .../samples/sgx-ra/README.md | 43 +- .../samples/sgx-ra/wasm-app/CMakeLists.txt | 0 .../samples/sgx-ra/wasm-app/main.c | 2 +- .../samples/shared-module/.gitignore | 1 + .../samples/shared-module/CMakeLists.txt | 95 + .../samples/shared-module/README.md | 5 + .../samples/shared-module/build.sh | 63 + .../samples/shared-module/run.sh | 3 + .../samples/shared-module/src/main.c | 206 ++ .../shared-module/wasm-apps/testapp.wat | 22 + .../samples/simple/.gitignore | 0 .../samples/simple/CMakeLists.txt | 0 .../samples/simple/README.md | 0 .../samples/simple/build.sh | 0 .../profiles/arm-interp/toolchain.cmake | 0 .../arm-interp/wamr_config_simple.cmake | 0 .../simple/profiles/arm64-aot/toolchain.cmake | 0 .../arm64-aot/wamr_config_simple.cmake | 0 .../profiles/arm64-interp/toolchain.cmake | 0 .../arm64-interp/wamr_config_simple.cmake | 0 .../host-aot/wamr_config_simple.cmake | 0 .../host-interp/wamr_config_simple.cmake | 0 .../macos-interp/wamr_config_simple.cmake | 0 .../samples/simple/sample_test_run.py | 0 .../samples/simple/src/iwasm_main.c | 0 .../samples/simple/src/main.c | 0 .../samples/simple/wasm-apps/connection.c | 0 .../simple/wasm-apps/event_publisher.c | 0 .../simple/wasm-apps/event_subscriber.c | 0 .../simple/wasm-apps/request_handler.c | 0 .../samples/simple/wasm-apps/request_sender.c | 0 .../samples/simple/wasm-apps/sensor.c | 0 .../samples/simple/wasm-apps/timer.c | 0 .../samples/socket-api/CMakeLists.txt | 0 .../samples/socket-api/README.md | 0 .../samples/socket-api/sample_test_run.py | 0 .../socket-api/wasm-src/CMakeLists.txt | 0 .../socket-api/wasm-src/addr_resolve.c | 0 .../samples/socket-api/wasm-src/inc/.gitkeep | 0 .../socket-api/wasm-src/multicast_client.c | 0 .../socket-api/wasm-src/multicast_server.c | 0 .../samples/socket-api/wasm-src/send_recv.c | 0 .../samples/socket-api/wasm-src/socket_opts.c | 0 .../socket-api/wasm-src/socket_utils.h | 0 .../samples/socket-api/wasm-src/tcp_client.c | 0 .../samples/socket-api/wasm-src/tcp_server.c | 0 .../socket-api/wasm-src/timeout_client.c | 0 .../socket-api/wasm-src/timeout_server.c | 0 .../samples/socket-api/wasm-src/udp_client.c | 0 .../samples/socket-api/wasm-src/udp_server.c | 0 .../samples/spawn-thread/CMakeLists.txt | 0 .../samples/spawn-thread/src/main.c | 0 .../spawn-thread/wasm-apps/CMakeLists.txt | 0 .../samples/spawn-thread/wasm-apps/sum.c | 0 .../samples/wasi-threads/CMakeLists.txt | 0 .../samples/wasi-threads/README.md | 0 .../wasi-threads/wasm-apps/CMakeLists.txt | 0 .../wasi-threads/wasm-apps/no_pthread.c | 10 +- .../wasm-apps/wasi_thread_start.S | 0 .../wasm-apps/wasi_thread_start.h | 4 + .../samples/wasm-c-api-imports/.gitignore | 0 .../samples/wasm-c-api-imports/CMakeLists.txt | 0 .../samples/wasm-c-api-imports/README.md | 0 .../wasm-c-api-imports/host/CMakeLists.txt | 0 .../wasm-c-api-imports/host/example1.c | 0 .../wasm-c-api-imports/wasm/CMakeLists.txt | 0 .../wasm-c-api-imports/wasm/inc/.gitkeep | 0 .../wasm-c-api-imports/wasm/send_recv.c | 0 .../samples/wasm-c-api/CMakeLists.txt | 12 +- .../samples/wasm-c-api/README.md | 0 .../samples/wasm-c-api/src/LICENSE | 0 .../samples/wasm-c-api/src/callback.c | 0 .../samples/wasm-c-api/src/callback.wat | 0 .../samples/wasm-c-api/src/callback_chain.c | 0 .../samples/wasm-c-api/src/callback_chain.wat | 0 .../samples/wasm-c-api/src/clone.c | 0 .../samples/wasm-c-api/src/clone.wat | 0 .../samples/wasm-c-api/src/empty_imports.c | 0 .../samples/wasm-c-api/src/empty_imports.wat | 0 .../samples/wasm-c-api/src/global.c | 0 .../samples/wasm-c-api/src/global.wat | 0 .../wasm-c-api/src/globalexportimport-0.wat | 0 .../wasm-c-api/src/globalexportimport-1.wat | 0 .../wasm-c-api/src/globalexportimport.c | 0 .../samples/wasm-c-api/src/hello.c | 6 + .../samples/wasm-c-api/src/hello.wat | 0 .../samples/wasm-c-api/src/hostref.c | 0 .../samples/wasm-c-api/src/hostref.wat | 0 .../samples/wasm-c-api/src/memory.c | 0 .../samples/wasm-c-api/src/memory.wat | 0 .../samples/wasm-c-api/src/multi.c | 0 .../samples/wasm-c-api/src/multi.wat | 0 .../samples/wasm-c-api/src/reflect.c | 0 .../samples/wasm-c-api/src/reflect.wat | 0 .../samples/wasm-c-api/src/serialize.c | 0 .../samples/wasm-c-api/src/serialize.wat | 0 .../samples/wasm-c-api/src/table.c | 0 .../samples/wasm-c-api/src/table.wat | 0 .../samples/wasm-c-api/src/threads.c | 0 .../samples/wasm-c-api/src/threads.wat | 0 .../samples/wasm-c-api/src/trap.c | 0 .../samples/wasm-c-api/src/trap.wat | 0 .../wasm-c-api/src/utils/multi_module_utils.c | 0 .../samples/workload/CMakeLists.txt | 0 .../samples/workload/README.md | 0 .../samples/workload/XNNPACK/.gitignore | 0 .../samples/workload/XNNPACK/CMakeLists.txt | 198 ++ .../samples/workload/XNNPACK/README.md | 41 +- .../samples/workload/XNNPACK/benchmark.patch | 0 .../samples/workload/XNNPACK/xnnpack.patch | 138 + .../samples/workload/bwa/.gitignore | 0 .../workload/bwa/CMakeLists.bwa_wasm.txt | 0 .../samples/workload/bwa/CMakeLists.txt | 0 .../samples/workload/bwa/README.md | 0 .../samples/workload/bwa/bwa.patch | 0 .../samples/workload/cmake/FindBinaryen.cmake | 0 .../samples/workload/cmake/FindWASISDK.cmake | 0 .../samples/workload/include/.gitkeep | 0 .../samples/workload/meshoptimizer/.gitignore | 0 .../workload/meshoptimizer/CMakeLists.txt | 0 .../samples/workload/meshoptimizer/README.md | 0 .../workload/meshoptimizer/codecbench.patch | 0 .../samples/workload/preparation.sh | 0 .../samples/workload/tensorflow/README.md | 0 .../samples/workload/tensorflow/build.sh | 0 .../samples/workload/tensorflow/tf_lite.patch | 0 .../samples/workload/wasm-av1/.gitignore | 0 .../workload/wasm-av1/CMakeLists.avx_wasm.txt | 0 .../samples/workload/wasm-av1/CMakeLists.txt | 0 .../samples/workload/wasm-av1/README.md | 0 .../samples/workload/wasm-av1/av1-clang.patch | 0 .../samples/workload/wasm-av1/build.sh | 0 .../samples/workload/wasm-av1/wasm-av1.patch | 0 .../test-tools/.gitignore | 0 .../test-tools/IoT-APP-Store-Demo/README.md | 0 .../IoT-APP-Store-Demo/docker-compose.yml | 0 .../IoT-APP-Store-Demo/wasm_django/Dockerfile | 0 .../IoT-APP-Store-Demo/wasm_django/db.sqlite3 | Bin .../wasm_django/devices/__init__.py | 0 .../wasm_django/devices/admin.py | 0 .../wasm_django/devices/apps.py | 0 .../devices/migrations/__init__.py | 0 .../wasm_django/devices/models.py | 0 .../devices/templates/application.html | 0 .../devices/templates/appstore.html | 0 .../wasm_django/devices/templates/empty.html | 0 .../wasm_django/devices/templates/help.html | 0 .../wasm_django/devices/templates/mysite.html | 0 .../wasm_django/devices/tests.py | 0 .../wasm_django/devices/views.py | 0 .../IoT-APP-Store-Demo/wasm_django/manage.py | 0 .../wasm_django/mysite/__init__.py | 0 .../wasm_django/mysite/settings.py | 0 .../wasm_django/mysite/urls.py | 0 .../wasm_django/mysite/wsgi.py | 0 .../wasm_django/server/Dockerfile | 0 .../wasm_django/server/wasm_server.py | 0 .../wasm_django/static/css/application.css | 0 .../wasm_django/static/css/appstore.css | 0 .../wasm_django/static/css/index.css | 0 .../wasm_django/static/js/application.js | 0 .../wasm_django/static/js/appstore.js | 0 .../wasm_django/static/js/index.js | 0 .../wasm_django/static/photo/app(1).png | Bin .../wasm_django/static/photo/application.png | Bin .../wasm_django/static/photo/delete.png | Bin .../wasm_django/static/photo/download(1).png | Bin .../wasm_django/static/photo/menu.png | Bin .../static/photo/milky-way-2695569_1280.jpg | Bin .../wasm_django/static/photo/net_device.png | Bin .../static/photo/software-icon-32081.png | Bin .../wasm_django/static/photo/totalblack.png | Bin .../wasm_django/static/upload/connection.wasm | Bin .../static/upload/event_publisher.wasm | Bin .../static/upload/event_subscriber.wasm | Bin .../static/upload/request_handler.wasm | Bin .../static/upload/request_sender.wasm | Bin .../wasm_django/static/upload/sensor.wasm | Bin .../wasm_django/static/upload/simple | Bin .../static/upload/sys/connection.wasm | Bin .../static/upload/sys/event_publisher.wasm | Bin .../static/upload/sys/event_subscriber.wasm | Bin .../static/upload/sys/request_handler.wasm | Bin .../static/upload/sys/request_sender.wasm | Bin .../wasm_django/static/upload/sys/timer.wasm | Bin .../wasm_django/static/upload/timer.wasm | Bin .../wasm_django/static/upload/ui_app.wasm | Bin .../static/upload/wasm_runtime_wgl | Bin .../test-tools/binarydump-tool/CMakeLists.txt | 0 .../test-tools/binarydump-tool/binarydump.c | 0 .../test-tools/component-test/README.md | 0 .../test-tools/component-test/__init__.py | 0 .../component-test/framework/__init__.py | 0 .../component-test/framework/case_base.py | 0 .../component-test/framework/engine.py | 0 .../component-test/framework/framework.py | 0 .../component-test/framework/suite.py | 0 .../component-test/framework/test_api.py | 0 .../component-test/framework/test_utils.py | 0 .../component-test/harness/__init__.py | 0 .../component-test/harness/harness_api.py | 0 .../host-clients/src/host_app_sample.c | 0 .../component-test/host-clients/src/makefile | 0 .../test-tools/component-test/set_dev_env.sh | 0 .../test-tools/component-test/start.py | 0 .../suites/01-life-cycle/__init__.py | 0 .../cases/01-install/__init__.py | 0 .../01-life-cycle/cases/01-install/case.py | 0 .../cases/02-request/__init__.py | 0 .../01-life-cycle/cases/02-request/case.py | 0 .../01-life-cycle/cases/03-event/__init__.py | 0 .../01-life-cycle/cases/03-event/case.py | 0 .../cases/04-request-internal/__init__.py | 0 .../cases/04-request-internal/case.py | 0 .../cases/05-event-internal/__init__.py | 0 .../cases/05-event-internal/case.py | 0 .../01-life-cycle/cases/06-timer/__init__.py | 0 .../01-life-cycle/cases/06-timer/case.py | 0 .../01-life-cycle/cases/07-sensor/__init__.py | 0 .../01-life-cycle/cases/07-sensor/case.py | 0 .../cases/08-on-destroy/__init__.py | 0 .../01-life-cycle/cases/08-on-destroy/case.py | 0 .../suites/01-life-cycle/cases/__init__.py | 0 .../suites/01-life-cycle/suite_setup.py | 0 .../01-life-cycle/test-app/01_install.c | 0 .../01-life-cycle/test-app/02_request.c | 0 .../suites/01-life-cycle/test-app/03_event.c | 0 .../test-app/04_request_internal_req.c | 0 .../test-app/04_request_internal_resp.c | 0 .../test-app/05_event_internal_provider.c | 0 .../test-app/05_event_internal_subscriber.c | 0 .../suites/01-life-cycle/test-app/06_timer.c | 0 .../suites/01-life-cycle/test-app/07_sensor.c | 0 .../01-life-cycle/test-app/08_on_destroy.c | 0 .../suites/01-life-cycle/test-app/build.sh | 0 .../01-life-cycle/tools/product/start.sh | 0 .../01-life-cycle/tools/product/stop.sh | 0 .../component-test/suites/__init__.py | 0 .../component-test/suites/readme.txt | 0 .../test-tools/host-tool/CMakeLists.txt | 0 .../host-tool/external/cJSON/LICENSE | 0 .../host-tool/external/cJSON/cJSON.c | 494 ++-- .../host-tool/external/cJSON/cJSON.h | 159 +- .../host-tool/external/cJSON/cjson.cmake | 0 .../host-tool/src/host_tool_utils.c | 0 .../host-tool/src/host_tool_utils.h | 0 .../test-tools/host-tool/src/main.c | 0 .../test-tools/host-tool/src/transport.c | 0 .../test-tools/host-tool/src/transport.h | 0 .../collect_files.py | 0 .../test-tools/wamr-ide/.gitattributes | 0 .../wamr-ide/Media/Config_building_target.png | Bin .../wamr-ide/Media/build_folder.png | Bin .../wamr-ide/Media/build_terminal.png | Bin .../Media/change_workspace_dialog.png | Bin .../wamr-ide/Media/compilation_config.png | Bin .../wamr-ide/Media/compilation_config_2.png | Bin .../test-tools/wamr-ide/Media/debug.png | Bin .../wamr-ide/Media/decoration_for_files.png | Bin .../wamr-ide/Media/docker_config.jpg | Bin .../wamr-ide/Media/docker_engine_config.png | Bin .../wamr-ide/Media/docker_images.png | Bin .../wamr-ide/Media/install_from_vsix.png | Bin .../wamr-ide/Media/new_project_page.png | Bin .../wamr-ide/Media/open_project_page.png | Bin .../wamr-ide/Media/project_template.png | Bin .../wamr-ide/Media/right_click_menus_1.png | Bin .../wamr-ide/Media/right_click_menus_2.png | Bin .../test-tools/wamr-ide/Media/run.png | Bin .../wamr-ide/Media/save_configuration.png | Bin .../Media/set_up_workspace_message.png | Bin .../wamr-ide/Media/wamr_ide_main_menu.png | Bin .../test-tools/wamr-ide/README.md | 0 .../test-tools/wamr-ide/Script/build.bat | 0 .../test-tools/wamr-ide/Script/build.sh | 0 .../wamr-ide/VSCode-Extension/.eslintrc.json | 0 .../wamr-ide/VSCode-Extension/.gitignore | 12 + .../wamr-ide/VSCode-Extension/.npmrc | 1 + .../VSCode-Extension/.prettierrc.json | 0 .../wamr-ide/VSCode-Extension/.vscodeignore | 19 + .../wamr-ide/VSCode-Extension/CONTRIBUTING.md | 0 .../wamr-ide/VSCode-Extension/LICENSE | 0 .../wamr-ide/VSCode-Extension/README.md | 0 .../VSCode-Extension/formatters/rust.py | 747 +++++ .../wamr-ide/VSCode-Extension/package.json | 15 +- .../resource/scripts/CMakeLists.txt | 0 .../resource/scripts/boot_debugger_server.bat | 0 .../resource/scripts/boot_debugger_server.sh | 0 .../resource/scripts/build.bat | 0 .../resource/scripts/build.sh | 0 .../resource/scripts/destroy.bat | 0 .../resource/scripts/destroy.sh | 0 .../resource/scripts/project.cmake | 0 .../VSCode-Extension/resource/scripts/run.bat | 0 .../VSCode-Extension/resource/scripts/run.sh | 0 .../VSCode-Extension/resource/test/build.sh | 2 + .../VSCode-Extension/resource/test/test.rs | 35 + .../libc-builtin-sysroot/include/assert.h | 0 .../libc-builtin-sysroot/include/ctype.h | 0 .../libc-builtin-sysroot/include/errno.h | 0 .../libc-builtin-sysroot/include/fcntl.h | 0 .../libc-builtin-sysroot/include/inttypes.h | 0 .../libc-builtin-sysroot/include/limits.h | 0 .../libc-builtin-sysroot/include/pthread.h | 0 .../libc-builtin-sysroot/include/stdarg.h | 0 .../libc-builtin-sysroot/include/stdbool.h | 0 .../libc-builtin-sysroot/include/stdint.h | 0 .../libc-builtin-sysroot/include/stdio.h | 0 .../libc-builtin-sysroot/include/stdlib.h | 0 .../libc-builtin-sysroot/include/string.h | 0 .../libc-builtin-sysroot/include/strings.h | 0 .../resource/webview/css/style.css | 0 .../resource/webview/js/configbuildtarget.js | 0 .../resource/webview/js/newproj.js | 0 .../webview/page/configBuildTarget.html | 0 .../resource/webview/page/newProject.html | 0 .../VSCode-Extension/src/constants.ts | 0 .../src/debugConfigurationProvider.ts | 34 +- .../src/decorationProvider.ts | 0 .../VSCode-Extension/src/extension.ts | 12 +- .../VSCode-Extension/src/taskProvider.ts | 0 .../VSCode-Extension/src/test/runTest.ts | 33 + .../src/test/suite/extension.test.ts | 183 ++ .../VSCode-Extension/src/test/suite/index.ts | 42 + .../VSCode-Extension/src/test/suite/utils.ts | 43 + .../src/utilities/directoryUtilities.ts | 0 .../src/utilities/dockerUtilities.ts | 4 +- .../VSCode-Extension/src/utilities/getUri.ts | 0 .../src/utilities/lldbUtilities.ts | 25 +- .../src/view/NewProjectPanel.ts | 0 .../src/view/TargetConfigPanel.ts | 0 .../wamr-ide/VSCode-Extension/tsconfig.json | 0 .../WASM-Debug-Server/Docker/Dockerfile | 0 .../WASM-Debug-Server/Docker/README.md | 0 .../Docker/build_docker_image.bat | 0 .../Docker/build_docker_image.sh | 0 .../Docker/resource/debug.sh | 0 .../WASM-Debug-Server/Docker/resource/run.sh | 0 .../WASM-Toolchain/Docker/.dockerignore | 0 .../wamr-ide/WASM-Toolchain/Docker/Dockerfile | 0 .../wamr-ide/WASM-Toolchain/Docker/README.md | 0 .../Docker/build_docker_image.bat | 0 .../Docker/build_docker_image.sh | 0 .../Docker/resource/build_wasm.sh | 0 .../Docker/resource/wamr_toolchain.cmake | 0 .../tests/benchmarks/README.md | 62 + .../tests/benchmarks/coremark/README.md | 6 + .../tests/benchmarks/coremark/build.sh | 7 + .../tests/benchmarks/coremark/run.sh | 23 + .../tests/benchmarks/coremark/test_pgo.sh | 55 + .../tests/benchmarks/dhrystone/LICENSE | 7 + .../tests/benchmarks/dhrystone/build.sh | 24 + .../tests/benchmarks/dhrystone/include/dhry.h | 306 ++ .../tests/benchmarks/dhrystone/run.sh | 19 + .../tests/benchmarks/dhrystone/src/dhry_1.c | 485 ++++ .../tests/benchmarks/dhrystone/src/dhry_2.c | 187 ++ .../tests/benchmarks/dhrystone/test_pgo.sh | 55 + .../tests/benchmarks/jetstream/README.md | 6 + .../tests/benchmarks/jetstream/build.sh | 174 ++ .../benchmarks/jetstream/jetstream.patch | 15 +- .../tests/benchmarks/jetstream/run_aot.sh | 18 +- .../tests/benchmarks/jetstream/test_pgo.sh | 92 + .../tests/benchmarks/jetstream/tsf.patch | 36 + .../tests/benchmarks/libsodium/README.md | 6 + .../tests/benchmarks/libsodium/build.sh | 26 +- .../tests/benchmarks/libsodium/run_aot.sh | 92 + .../tests/benchmarks/libsodium/test_pgo.sh | 121 + .../tests/benchmarks/polybench/README.md | 6 + .../tests/benchmarks/polybench/build.sh | 8 + .../tests/benchmarks/polybench/run_aot.sh | 12 +- .../tests/benchmarks/polybench/run_interp.sh | 2 +- .../tests/benchmarks/polybench/test_pgo.sh | 95 + .../tests/benchmarks/sightglass/README.md | 6 + .../tests/benchmarks/sightglass/build.sh | 7 +- .../tests/benchmarks/sightglass/run_aot.sh | 12 +- .../tests/benchmarks/sightglass/run_interp.sh | 4 +- .../tests/benchmarks/sightglass/test_pgo.sh | 94 + .../tests/unit/CMakeLists.txt | 51 + .../tests/unit/main.cpp | 21 + .../tests/wamr-compiler/.gitignore | 2 + .../tests/wamr-compiler/README.md | 3 + .../test_shift_negative_constants.wat | 78 + .../tests/wamr-test-suites/README.md | 0 .../wamr-test-suites/spec-test-script/CHANGES | 0 .../wamr-test-suites/spec-test-script/all.py | 161 +- .../wamr-test-suites/spec-test-script/all.sh | 0 .../spec-test-script/collect_coverage.sh | 0 .../spec-test-script/ignore_cases.patch | 20 - .../multi_module_aot_ignore_cases.patch | 174 ++ .../spec-test-script/runtest.py | 272 +- .../spec-test-script/simd_ignore_cases.patch | 0 .../tail-call/return_call.wast | 0 .../tail-call/return_call_indirect.wast | 0 .../thread_proposal_fix_atomic_case.patch | 0 .../thread_proposal_ignore_cases.patch | 23 +- .../tests/wamr-test-suites/test_wamr.sh | 219 +- .../wamr-test-suites/tsan_suppressions.txt | 7 + .../run_wamr_compiler_tests.sh | 22 + .../wamr-test-suites/wasi-test-script/pipe.py | 19 + .../wasi-test-script/run_wasi_tests.sh | 151 + .../wamr-compiler/CMakeLists.txt | 9 +- .../wamr-compiler/README.md | 0 .../wamr-compiler/build_llvm.py | 0 .../wamr-compiler/build_llvm.sh | 0 .../wamr-compiler/build_llvm_arc.sh | 0 .../wamr-compiler/build_llvm_xtensa.sh | 0 .../wamr-compiler/main.c | 287 +- .../wamr-sdk/Kconfig | 0 .../wamr-sdk/Makefile | 0 .../wamr-sdk/README.md | 0 .../wamr-sdk/app/CMakeLists.txt | 0 .../app/libc-builtin-sysroot/include/assert.h | 0 .../app/libc-builtin-sysroot/include/ctype.h | 0 .../app/libc-builtin-sysroot/include/errno.h | 0 .../app/libc-builtin-sysroot/include/fcntl.h | 0 .../libc-builtin-sysroot/include/inttypes.h | 0 .../app/libc-builtin-sysroot/include/limits.h | 0 .../libc-builtin-sysroot/include/pthread.h | 0 .../libc-builtin-sysroot/include/semaphore.h | 0 .../app/libc-builtin-sysroot/include/stdarg.h | 0 .../libc-builtin-sysroot/include/stdbool.h | 0 .../app/libc-builtin-sysroot/include/stdint.h | 0 .../app/libc-builtin-sysroot/include/stdio.h | 0 .../app/libc-builtin-sysroot/include/stdlib.h | 0 .../app/libc-builtin-sysroot/include/string.h | 0 .../libc-builtin-sysroot/include/strings.h | 0 .../share/defined-symbols.txt | 0 .../wamr-sdk/app/wamr_toolchain.cmake | 0 .../wamr-sdk/app/wasi_toolchain.cmake | 0 .../wamr-sdk/build_sdk.sh | 0 .../wamr-sdk/menuconfig.sh | 0 .../wamr-sdk/runtime/CMakeLists.txt | 0 .../wamr-sdk/wamr_config_default.cmake | 0 .../wamr-sdk/wamr_config_macos_release.cmake | 0 .../wamr-sdk/wamr_config_ubuntu_release.cmake | 0 .../zephyr/module.yml | 0 src/wamrc/CMakeLists.txt | 42 + src/wasm/CMakeLists.txt | 32 + 1436 files changed, 29673 insertions(+), 9714 deletions(-) delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/spec_test_on_nuttx.yml delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/requirements.txt delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/README.md delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/iwasm_aot.cmake delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_memory.h delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_shared_memory.h delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_utils.c delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/test/tcp_udp.c delete mode 100755 lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/build.sh delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.json delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/libc_uvwasi.cmake delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/wasi_nn.cmake delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/platform_api_posix.cmake delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_memmap.c delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/doc/xip.md delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/go.mod delete mode 100755 lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/samples/build.sh delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/README_docker.md delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/esp32.conf delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_riscv32.conf delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_riscv64.conf delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_x86_nommu.conf delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_xtensa.conf delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/esp32_custom_linker.ld delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/CMakeLists.txt delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/xnnpack.patch delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.gitignore delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/extensions.json delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/launch.json delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/tasks.json delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscodeignore delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/README.md delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/darwin/.placeholder delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/linux/.placeholder delete mode 100644 lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/windows/.placeholder delete mode 100755 lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/coremark/run.sh delete mode 100755 lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/jetstream/build.sh delete mode 100755 lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/libsodium/test_aot.sh delete mode 100755 lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/wasi-test-script/run_wasi_tests.sh rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.clang-tidy (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/.devcontainer/Dockerfile rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.devcontainer/devcontainer.json (70%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.github/scripts/extract_from_release_notes.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.github/scripts/fetch_and_compare_version.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.github/scripts/reuse_latest_release_binaries.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.github/workflows/build_docker_images.yml (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.github/workflows/build_iwasm_release.yml (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.github/workflows/build_llvm_libraries.yml (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.github/workflows/build_wamr_lldb.yml (63%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.github/workflows/build_wamr_sdk.yml (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.github/workflows/build_wamr_vscode_ext.yml (97%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.github/workflows/build_wamrc.yml (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.github/workflows/coding_guidelines.yml (96%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_android_ubuntu.yml rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.github/workflows/compilation_on_macos.yml (97%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.github/workflows/compilation_on_nuttx.yml (93%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.github/workflows/compilation_on_sgx.yml (69%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.github/workflows/compilation_on_windows.yml (50%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.github/workflows/create_tag.yml (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/hadolint_dockerfiles.yml rename lib/{wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_android_ubuntu.yml => wasm-micro-runtime-WAMR-1.3.0/.github/workflows/nightly_run.yml} (84%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.github/workflows/release_process.yml (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.github/workflows/reuse_latest_release_binaries.yml (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/spec_test_on_nuttx.yml rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/.gitignore (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/ATTRIBUTIONS.md (92%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/CODE_OF_CONDUCT.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/CONTRIBUTING.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/LICENSE (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/ORG_CODE_OF_CONDUCT.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/README.md (97%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/RELEASE_NOTES.md (52%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/SConscript (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/SECURITY.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/TSC_Charter.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/assembly-script/.gitignore (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/assembly-script/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/assembly-script/package-lock.json (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/assembly-script/package.json (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/assembly-script/samples/event_publisher.ts (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/assembly-script/samples/event_subscriber.ts (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/assembly-script/samples/request_handler.ts (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/assembly-script/samples/request_sender.ts (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/assembly-script/samples/timer.ts (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/assembly-script/samples/tsconfig.json (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/assembly-script/wamr_app_lib/console.ts (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/assembly-script/wamr_app_lib/request.ts (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/assembly-script/wamr_app_lib/timer.ts (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/assembly-script/wamr_app_lib/tsconfig.json (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/build-scripts/SConscript (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/build-scripts/SConscript_config (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/build-scripts/build_llvm.py (96%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/build-scripts/config_common.cmake (78%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/build-scripts/esp-idf/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/build-scripts/esp-idf/wamr/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/build-scripts/involve_boringssl.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2/build-scripts/lldb-wasm.patch => wasm-micro-runtime-WAMR-1.3.0/build-scripts/lldb_wasm.patch} (98%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/requirements.txt rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/build-scripts/runtime_lib.cmake (95%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/ci/build_wamr.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/ci/coding_guidelines_check.py (100%) create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/ci/pre_commit_hook_sample create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/ci/setup.sh create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/ci/validate_lldb.py rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/app-native-shared/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/app-native-shared/attr_container.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/app-native-shared/bi-inc/attr_container.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/app-native-shared/bi-inc/shared_utils.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/app-native-shared/bi-inc/wgl_shared_utils.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/app-native-shared/native_interface.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/app-native-shared/native_interface.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/app-native-shared/restful_utils.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/app_ext_lib_export.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/app_framework.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/base/app/bh_platform.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/base/app/bh_platform.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/base/app/req_resp_api.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/base/app/request.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/base/app/timer.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/base/app/timer_api.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/base/app/wa-inc/request.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/base/app/wa-inc/timer_wasm_app.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/base/app/wasm_app.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/base/app/wasm_app.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/base/native/base_lib.inl (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/base/native/base_lib_export.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/base/native/req_resp_native_api.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/base/native/request_response.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/base/native/runtime_lib.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/base/native/timer_native_api.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/base/native/timer_wrapper.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/base/native/wasm_lib.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/app/connection.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/app/connection_api.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/app/wa-inc/connection.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/app/wasm_app.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/native/connection.inl (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/native/connection_lib.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/native/connection_native_api.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/native/connection_wrapper.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/native/linux/conn_tcp.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/native/linux/conn_tcp.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/native/linux/conn_uart.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/native/linux/conn_uart.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/native/linux/conn_udp.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/native/linux/conn_udp.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/native/linux/connection_mgr.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/native/linux/connection_mgr.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/native/wasm_lib.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/native/zephyr/connection_lib_impl.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/connection/native/zephyr/connection_mgr.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/sensor/app/sensor.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/sensor/app/sensor_api.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/sensor/app/wa-inc/sensor.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/sensor/app/wasm_app.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/sensor/native/runtime_sensor.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/sensor/native/runtime_sensor.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/sensor/native/runtime_sensor.inl (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/sensor/native/sensor_mgr_ref.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/sensor/native/sensor_native_api.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/sensor/native/wasm_lib.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/template/app/wa-inc/app_xxx.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/template/app/wasm_app.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/template/native/app_xxx.inl (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-framework/template/native/wasm_lib.cmake (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/README.md rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/app_manager.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/app_manager.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/app_manager_host.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/app_manager_host.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/app_mgr.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/ble_msg.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/coding_rule.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/event.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/event.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/message.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/module_config.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/module_jeff.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/module_jeff.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/module_utils.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/module_wasm_app.c (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/module_wasm_app.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/module_wasm_lib.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/module_wasm_lib.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/platform/darwin/app_mgr_darwin.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/platform/linux/app_mgr_linux.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/platform/zephyr/app_mgr_zephyr.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/resource_reg.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/watchdog.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-manager/watchdog.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-mgr-shared/app_manager_export.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-mgr-shared/app_mgr_shared.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/app-mgr-shared/host_link.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/app-mgr/module.json (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/config.h (88%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/SConscript (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/aot_intrinsic.c (82%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/aot_intrinsic.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/aot_loader.c (86%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/aot_reloc.h (95%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/aot_runtime.c (73%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/aot_runtime.h (80%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/arch/aot_reloc_aarch64.c (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/arch/aot_reloc_arc.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/arch/aot_reloc_arm.c (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/arch/aot_reloc_mips.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/arch/aot_reloc_riscv.c (80%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/arch/aot_reloc_thumb.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/arch/aot_reloc_x86_32.c (82%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/arch/aot_reloc_x86_64.c (89%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/arch/aot_reloc_xtensa.c (93%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/debug/LICENSE_NUTTX (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/debug/NOTICE_NUTTX (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/debug/elf.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/debug/elf32.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/debug/elf64.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/debug/elf_parser.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/debug/elf_parser.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/debug/jit_debug.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/aot/debug/jit_debug.h (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/iwasm_aot.cmake rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/SConscript (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_aarch64.s (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_aarch64_simd.s (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_arc.s (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_arm.s (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_arm_vfp.s (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_em64.asm (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_em64.s (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_em64_simd.asm (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_em64_simd.s (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_general.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_ia32.asm (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_ia32.s (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_mingw_x64.s (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_mingw_x64_simd.s (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_mips.s (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_osx_universal.s (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_riscv.S (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_thumb.s (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_thumb_vfp.s (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/arch/invokeNative_xtensa.s (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/iwasm_common.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/wasm_application.c (90%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_blocking_op.c rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/wasm_c_api.c (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/wasm_c_api_internal.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/wasm_exec_env.c (81%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/wasm_exec_env.h (96%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/wasm_memory.c (73%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_memory.h rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/wasm_native.c (75%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/wasm_native.h (70%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/wasm_runtime_common.c (85%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/wasm_runtime_common.h (87%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/common/wasm_shared_memory.c (71%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_shared_memory.h create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_suspend_flags.h rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot.c (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot.h (92%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_compiler.c (96%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_compiler.h (95%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_aot_file.c (72%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_compare.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_compare.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_const.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_const.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_control.c (94%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_control.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_conversion.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_conversion.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_exception.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_exception.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_function.c (90%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_function.h (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_memory.c (85%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_memory.h (97%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_numberic.c (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_numberic.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_parametric.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_parametric.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_table.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_table.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_variable.c (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_emit_variable.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_llvm.c (74%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_llvm.h (85%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_llvm_extra.cpp (52%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_llvm_extra2.cpp (76%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_llvm_extra2.h (62%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_orc_extra.cpp (81%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/aot_orc_extra.h (89%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra2.cpp rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/debug/dwarf_extractor.cpp (92%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/debug/dwarf_extractor.h (55%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/iwasm_compl.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_access_lanes.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_access_lanes.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_bit_shifts.c (89%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_bit_shifts.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_bitmask_extracts.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_bitmask_extracts.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_bitwise_ops.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_bitwise_ops.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_bool_reductions.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_bool_reductions.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_common.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_common.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_comparisons.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_comparisons.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_construct_values.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_construct_values.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_conversions.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_conversions.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_floating_point.c (62%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_floating_point.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_int_arith.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_int_arith.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_load_store.c (76%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_load_store.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_sat_int_arith.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/compilation/simd/simd_sat_int_arith.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/doc/classic_interpreter.MD (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/doc/images/export_function.excalidraw (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/doc/images/stack_format_ci.excalidraw (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/doc/images/stack_format_ci.svg (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/doc/images/wasm_exports.svg (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/doc/images/wasm_function.excalidraw (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/doc/images/wasm_function.svg (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/doc/images/wasm_globals.excalidraw (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/doc/images/wasm_globals.svg (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/doc/wasm_exports.MD (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/doc/wasm_function.MD (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/doc/wasm_globals.MD (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/asmjit_sgx_patch.diff (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/cg/LICENSE_ASMJIT (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/cg/LICENSE_ZYDIS (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_compare.c (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_compare.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_const.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_const.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_control.c (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_control.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_conversion.c (87%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_conversion.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_exception.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_exception.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_function.c (96%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_function.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_memory.c (94%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_memory.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_numberic.c (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_numberic.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_parametric.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_parametric.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_table.c (86%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_table.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_variable.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/fe/jit_emit_variable.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/iwasm_fast_jit.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/jit_codecache.c (93%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/jit_codecache.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/jit_codegen.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/jit_codegen.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/jit_compiler.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/jit_compiler.h (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/jit_dump.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/jit_dump.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/jit_frontend.c (86%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/jit_frontend.h (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/jit_ir.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/jit_ir.def (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/jit_ir.h (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/fast-jit/jit_regalloc.c (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_utils.h rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/include/aot_export.h (88%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/include/lib_export.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/include/wasm_c_api.h (96%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/include/wasm_export.h (82%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/interpreter/SConscript (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/interpreter/iwasm_interp.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/interpreter/wasm.h (97%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/interpreter/wasm_interp.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/interpreter/wasm_interp_classic.c (94%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/interpreter/wasm_interp_fast.c (93%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/interpreter/wasm_loader.c (97%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/interpreter/wasm_loader.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/interpreter/wasm_mini_loader.c (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/interpreter/wasm_opcode.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/interpreter/wasm_runtime.c (90%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/interpreter/wasm_runtime.h (93%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/debug-engine/debug_engine.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/debug-engine/debug_engine.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/debug-engine/debug_engine.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/debug-engine/gdbserver.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/debug-engine/gdbserver.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/debug-engine/handler.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/debug-engine/handler.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/debug-engine/packets.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/debug-engine/packets.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/debug-engine/utils.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/debug-engine/utils.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-pthread/SConscript (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-pthread/lib_pthread.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-pthread/lib_pthread_wrapper.c (97%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-rats/lib_rats.cmake (76%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-rats/lib_rats_common.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-rats/lib_rats_wrapper.c (88%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-rats/lib_rats_wrapper.h (96%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-socket/lib_socket_wasi.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-socket/test/build.sh (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/manifest.json rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-socket/test/nslookup.c (64%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/tcp_udp.c rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c (93%) create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/build.sh create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/errorcheck_mutex_stress_test.c create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/manifest.json create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/mutex_common.h create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/normal_mutex_stress_test.c create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/recursive_mutex_stress_test.c create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/spawn_stress_test.c create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/stress_test_threads_creation.c create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/build.sh rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/common.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/create_threads_until_limit.c (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/global_atomic.c (96%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/global_lock.c (96%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/linear_memory_size_update.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_busy.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_busy.json (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_sleep.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_sleep.json (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_wait.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_wait.json (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/main_trap_busy.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/main_trap_busy.json (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/main_trap_sleep.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/main_trap_sleep.json (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/main_trap_wait.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/main_trap_wait.json (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/manifest.json rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_busy.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_busy.json (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_sleep.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_sleep.json (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_wait.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_wait.json (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_busy.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_busy.json (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_sleep.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_sleep.json (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_wait.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_wait.json (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/spawn_multiple_times.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/sync_primitives.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.c (94%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/test/update_shared_data_and_alloc_heap.c (97%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/tid_allocator.c (88%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/lib-wasi-threads/tid_allocator.h (83%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/unit-test/lib_wasi_threads_unit_tests.cmake create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/unit-test/test_tid_allocator.cpp rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-builtin/SConscript (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-builtin/libc_builtin.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-emcc/SConscript (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-emcc/libc_emcc.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/FindLIBUV.cmake create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/FindUVWASI.cmake rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-uvwasi/LICENSE_LIBUV (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-uvwasi/LICENSE_UVWASI (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/libc_uvwasi.cmake rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-uvwasi/libc_uvwasi_wrapper.c (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/SConscript (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/libc_wasi.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c (88%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.h (70%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/LICENSE (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/LICENSE (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/LICENSE (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/README.md (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h (84%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c (58%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.h (94%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/queue.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.c (52%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.h (84%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/refcount.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/rights.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h (68%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/thread-mgr/SConscript (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/thread-mgr/thread_manager.c (87%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/thread-mgr/thread_manager.h (94%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/thread-mgr/thread_mgr.cmake (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/.gitignore rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/README.md (59%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/iwasm_helper.cmake create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/wasi_nn.cmake create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/external/CMakeLists.txt create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/external/README.md rename lib/{wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn => wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/include}/wasi_nn.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn => wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/include}/wasi_nn_types.h (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/src/utils/logger.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/src/wasi_nn.c (76%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/src/wasi_nn_private.h (71%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.cpp (74%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.hpp (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.compile create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.cpu create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.nvidia-gpu create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.tpu create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.vx-delegate rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/test/build.sh (51%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/test/models/average.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/test/models/max.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/test/models/mult_dimension.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/test/models/mult_outputs.py (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/quantized.py rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/test/models/sum.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/test/models/utils.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/test/requirements.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/test/test_tensorflow.c (83%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/test_tensorflow_quantized.c rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/test/utils.c (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/iwasm/libraries/wasi-nn/test/utils.h (96%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/coap/er-coap/LICENSE.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/coap/er-coap/coap-constants.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/coap/extension/coap_ext.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/coap/lib_coap.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/mem-alloc/SConscript (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/mem-alloc/ems/ems_alloc.c (94%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/mem-alloc/ems/ems_gc.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/mem-alloc/ems/ems_gc_internal.h (97%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/mem-alloc/ems/ems_hmu.c (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/mem-alloc/ems/ems_kfc.c (95%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/mem-alloc/mem_alloc.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/mem-alloc/mem_alloc.cmake (69%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/mem-alloc/mem_alloc.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/alios/alios_platform.c (87%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/alios/alios_thread.c (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/alios/alios_time.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/alios/platform_internal.h (78%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/alios/shared_platform.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/android/platform_init.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/android/platform_internal.h (93%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/android/shared_platform.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/common/freertos/freertos_malloc.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/common/freertos/freertos_thread.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/common/freertos/freertos_time.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/common/freertos/platform_api_freertos.cmake (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/libc_errno.c create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/libc_errno.h create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/platform_common_libc_util.cmake rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/common/math/COPYRIGHT (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/common/math/math.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/common/math/platform_api_math.cmake (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/platform_api_posix.cmake create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_blocking_op.c create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_clock.c create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_file.c rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/common/posix/posix_malloc.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/common/posix/posix_memmap.c (93%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_sleep.c rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/common/posix/posix_socket.c (96%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/common/posix/posix_thread.c (86%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/common/posix/posix_time.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/darwin => wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan}/platform_init.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux => wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan}/platform_internal.h (72%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan/shared_platform.cmake rename lib/{wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/freebsd => wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/darwin}/platform_init.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/darwin/platform_internal.h (86%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/darwin/shared_platform.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/ego/platform_init.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/ego/platform_internal.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/ego/shared_platform.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/esp-idf/espidf_malloc.c (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_memmap.c rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/esp-idf/espidf_platform.c (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/esp-idf/espidf_socket.c (95%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/esp-idf/espidf_thread.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/esp-idf/platform_internal.h (92%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/esp-idf/shared_platform.cmake (66%) rename lib/{wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux => wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/freebsd}/platform_init.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/freebsd/platform_internal.h (85%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/freebsd/shared_platform.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/include/platform_api_extension.h (58%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/include/platform_api_vmcore.h (87%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/include/platform_common.h (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_wasi_types.h rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/platform_internal.h (89%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/sgx_file.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/sgx_file.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/sgx_ipfs.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/sgx_ipfs.h (97%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/sgx_platform.c (91%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/sgx_pthread.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/sgx_pthread.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/sgx_rsrv_mem_mngr.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/sgx_signal.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/sgx_signal.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/sgx_socket.c (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/sgx_socket.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/sgx_thread.c (78%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/sgx_time.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/sgx_time.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/sgx_wamr.edl (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/shared_platform.cmake (76%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/untrusted/file.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/untrusted/pthread.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/untrusted/signal.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/untrusted/socket.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux-sgx/untrusted/time.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/vxworks => wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux}/platform_init.c (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux/platform_internal.h rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/linux/shared_platform.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/nuttx/nuttx_platform.c (67%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/nuttx/platform_internal.h (88%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/nuttx/shared_platform.cmake (61%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/riot/platform_internal.h (80%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/riot/riot_platform.c (90%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/riot/riot_thread.c (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/riot/riot_time.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/riot/shared_platform.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/rt-thread/SConscript (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/rt-thread/platform_internal.h (73%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/rt-thread/rtt_platform.c (95%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/rt-thread/shared_platform.cmake (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/vxworks/platform_init.c rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/vxworks/platform_internal.h (91%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/vxworks/shared_platform.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/windows/platform_init.c (95%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/windows/platform_internal.h (64%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/windows/shared_platform.cmake (69%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/windows/win_atomic.cpp (72%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_clock.c create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_file.c rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/windows/win_malloc.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/windows/win_memmap.c (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/windows/win_socket.c (64%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/windows/win_thread.c (95%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/windows/win_time.c (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_util.c create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_util.h rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/zephyr/platform_internal.h (84%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/zephyr/shared_platform.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/zephyr/zephyr_platform.c (97%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/zephyr/zephyr_thread.c (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/platform/zephyr/zephyr_time.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/SConscript (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/bh_assert.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/bh_assert.h (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_atomic.h create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_bitmap.c rename lib/{wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_utils.h => wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_bitmap.h} (66%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/bh_common.c (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/bh_common.h (55%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/bh_hashmap.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/bh_hashmap.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/bh_list.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/bh_list.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/bh_log.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/bh_log.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/bh_platform.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/bh_queue.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/bh_queue.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/bh_vector.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/bh_vector.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src => wasm-micro-runtime-WAMR-1.3.0/core/shared/utils}/gnuc.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/runtime_timer.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/runtime_timer.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/shared_utils.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/uncommon/SConscript (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/uncommon/bh_getopt.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/uncommon/bh_getopt.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/uncommon/bh_read_file.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/uncommon/bh_read_file.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/shared/utils/uncommon/shared_uncommon.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/core/version.h (78%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/build_wamr.md (81%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/build_wasm_app.md (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/devcontainer.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/embed_wamr.md (81%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/doc/embed_wamr_spawn_api.md rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/export_native_api.md (86%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/linux_sgx.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/memory_tune.md (90%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/memory_usage.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/multi_module.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/other_wasm_compilers.md (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/doc/perf_tune.md rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/pics/app_framework.PNG (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/pics/embed.PNG (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/pics/extend_library.PNG (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/pics/multi_module_pic1.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/pics/native_call_wasm.PNG (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/pics/request.PNG (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/pics/safe.PNG (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/pics/sensor_callflow.PNG (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/pics/sub.PNG (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/pics/vgl_demo.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/pics/vgl_demo2.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/pics/vgl_demo_linux.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/pics/vgl_linux.PNG (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/pics/wamr-arch.JPG (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/pics/wamr_memory_model.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/pics/wamr_menu_config.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/port_wamr.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/pthread_impls.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/pthread_library.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/ref_types.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/release_ack.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/roadmap.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/semantic_version.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/socket_api.md (97%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/source_debugging.md (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/wamr_api.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/doc/wasm_c_api.md (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/doc/xip.md rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/build.sh (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/go.mod rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/go.sum (100%) create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/samples/build.sh rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/samples/run.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/samples/test.go (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/samples/wasm-app/build.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/samples/wasm-app/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/wamr/cgo.go (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/wamr/instance.go (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/wamr/instance_test.go (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/wamr/module.go (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/wamr/module_test.go (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/wamr/packaged/include/dummy.go (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/wamr/packaged/lib/darwin-aarch64/dummy.go (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/wamr/packaged/lib/darwin-amd64/dummy.go (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/wamr/packaged/lib/dummy.go (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/wamr/packaged/lib/linux-amd64/dummy.go (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/wamr/runtime.go (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/go/wamr/runtime_test.go (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/.gitignore (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/LICENSE (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/MANIFEST.in (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/README.md (92%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/pyproject.toml (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/setup.py (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/src/wamr/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/src/wamr/libs/.placeholder (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/src/wamr/wamrapi/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/src/wamr/wamrapi/wamr.py (55%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/src/wamr/wasmcapi/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/src/wamr/wasmcapi/binding.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/src/wamr/wasmcapi/ffi.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/utils/create_lib.sh (81%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/wamr-api/README.md (53%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/wamr-api/requirements.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wamr-api/samples => wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/basic}/compile.sh (100%) mode change 100644 => 100755 rename lib/{wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wamr-api/samples => wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/basic}/main.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wamr-api/samples => wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/basic}/sum.c (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/native-symbol/README.md create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/native-symbol/compile.sh create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/native-symbol/func.c create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/native-symbol/main.py rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/wasm-c-api/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/wasm-c-api/docs/design.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/wasm-c-api/docs/images/python_package_life_cycle.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/wasm-c-api/docs/setup_dev_env.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/wasm-c-api/requirements.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/wasm-c-api/samples/hello.wat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/wasm-c-api/samples/hello_oop.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/wasm-c-api/samples/hello_procedural.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/wasm-c-api/tests/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/wasm-c-api/tests/context.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/wasm-c-api/tests/test_advanced.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/wasm-c-api/tests/test_basic.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/language-bindings/python/wasm-c-api/utils/bindgen.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/README.md (94%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/app-samples/hello-world-cmake/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/app-samples/hello-world-cmake/build.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/app-samples/hello-world-cmake/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/app-samples/hello-world-cmake/print.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/app-samples/hello-world/build.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/app-samples/hello-world/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/alios-things/aos.mk (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/alios-things/src/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/alios-things/src/test_wasm.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/android/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/android/build_jit.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/android/build_llvm.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/android/wasm-jni.cpp (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/common/libc_wasi.c rename lib/{wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test => wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/cosmopolitan}/CMakeLists.txt (73%) create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/cosmopolitan/build_cosmocc.sh rename lib/{wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/darwin => wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/cosmopolitan}/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/darwin/CMakeLists.txt (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/darwin/build_jit.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/darwin/build_llvm.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/freebsd => wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/darwin}/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/esp-idf/.gitignore (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/esp-idf/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/esp-idf/build_and_run.sh (80%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/esp-idf/main/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/esp-idf/main/main.c (96%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/esp-idf/main/test_wasm.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/esp-idf/sdkconfig.defaults (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/esp-idf/sdkconfig.defaults.esp32 (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/esp-idf/sdkconfig.defaults.esp32c3 (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/freebsd/CMakeLists.txt (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/freebsd/build_jit.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/freebsd/build_llvm.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux => wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/freebsd}/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/ios/CMakeLists.txt (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/ios/generate_xcodeproj.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/linux-sgx/CMakeLists.txt (89%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/linux-sgx/CMakeLists_minimal.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/linux-sgx/enclave-sample/Makefile (94%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/linux-sgx/enclave-sample/Makefile_minimal (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/linux/CMakeLists.txt (80%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/linux/build_jit.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/linux/build_llvm.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/nuttx => wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux}/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/vxworks => wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/nuttx}/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/nuttx/wamr.mk (87%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/posix/main.c (57%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/riot/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/riot/Makefile (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/riot/iwasmt.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/riot/test_wasm.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/rt-thread/SConscript (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/rt-thread/iwasm.c (97%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/rt-thread/iwasm.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/vxworks/CMakeLists.txt (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/vxworks/main.c rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/windows/CMakeLists.txt (93%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/windows/build_llvm.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/windows/main.c (81%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/windows/wasi_filtered_tests.json rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/zephyr/simple/CMakeLists.txt (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/Dockerfile create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/README.md rename lib/{wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/nucleo767zi.conf => wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/boards/nucleo_f767zi.conf} (72%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/zephyr/simple/boards/qemu_cortex_a53.conf (72%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/zephyr/simple/build_and_run.sh (74%) rename lib/{wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_arc.conf => wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/prj.conf} (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/zephyr/simple/src/main.c (74%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/zephyr/simple/src/test_wasm.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/zephyr/simple/src/test_wasm_riscv64.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/zephyr/simple/src/wasm-app-riscv64/build.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/product-mini/platforms/zephyr/simple/src/wasm-app-riscv64/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/basic/.gitignore (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/basic/CMakeLists.txt (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/basic/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/basic/build.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/basic/run.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/basic/src/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/basic/src/native_impl.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/basic/wasm-apps/testapp.c (96%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/bh-atomic/CMakeLists.txt create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/bh-atomic/main.c rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/file/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/file/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/file/src/CMakeLists.txt (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/file/src/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/file/wasm-app/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/file/wasm-app/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/build.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/lv_config/lv_conf.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/lv_config/lv_drv_conf.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/lv_config/system_header.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wamr_config_gui.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-apps/build_apps.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-apps/decrease/Makefile (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-apps/decrease/src/main.c (84%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-apps/increase/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-apps/increase/Makefile (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-apps/increase/src/main.c (84%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-runtime-wgl/src/platform/linux/iwasm_main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-runtime-wgl/src/platform/linux/lv_drv_conf.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-runtime-wgl/src/platform/linux/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-runtime-wgl/src/platform/zephyr/LICENSE (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-runtime-wgl/src/platform/zephyr/board_config.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340_adafruit_1480.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-runtime-wgl/src/platform/zephyr/iwasm_main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-runtime-wgl/src/platform/zephyr/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-runtime-wgl/src/platform/zephyr/pin_config_jlf.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/gui/wasm-runtime-wgl/src/platform/zephyr/pin_config_stm32.h (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/.gitignore create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/CMakeLists.txt create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/README.md create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/build.sh create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/run.sh create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/src/main.c create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/src/my_context.h create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/src/native_impl.c create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/wasm-apps/testapp.c create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/.gitignore create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/CMakeLists.txt create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/README.md create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/build.sh create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/run.sh create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/src/main.c create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/src/my_context.h create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/src/native_impl.c create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/wasm-apps/testapp.c rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/LICENCE.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/build.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/lv_config/lv_conf.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/lv_config/lv_drv_conf.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt.in (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-native-ui-app/lv-drivers/.gitignore (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-native-ui-app/lv-drivers/display_indev.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-native-ui-app/lv-drivers/indev/mouse.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-native-ui-app/lv-drivers/indev/mouse.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-native-ui-app/lv-drivers/linux_display_indev.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-native-ui-app/lv-drivers/system_header.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-native-ui-app/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/src/display_indev.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/display_indev.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/iwasm_main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/mouse.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/LICENSE (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/board_config.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340_adafruit_1480.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_indev.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/iwasm_main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/pin_config_jlf.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/pin_config_stm32.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/wamr_config_littlevgl.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/wasm-apps/Makefile_wasm_app (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/wasm-apps/Makefile_wasm_app_no_wasi (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/wasm-apps/build_wasm_app.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/wasm-apps/src/display_indev.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/wasm-apps/src/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/littlevgl/wasm-apps/src/system_header.h (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/mem-allocator/CMakeLists.txt create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/mem-allocator/main.c rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/multi-module/CMakeLists.txt (81%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/README.md rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/multi-module/src/main.c (78%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/multi-module/wasm-apps/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/multi-module/wasm-apps/mA.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/multi-module/wasm-apps/mB.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/multi-module/wasm-apps/mC.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/multi-module/wasm-apps/mD.cpp (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/multi-module/wasm-apps/mE.cpp (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/multi-thread/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/multi-thread/wasm-apps/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/multi-thread/wasm-apps/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/multi-thread/wasm-apps/main_global_atomic.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/multi-thread/wasm-apps/main_thread_exception.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/native-lib/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/native-lib/README.md (94%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/native-lib/test_add.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/native-lib/test_hello.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/native-lib/test_hello2.c (90%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/native-lib/test_sqrt.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/native-lib/wasm-app/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/native-lib/wasm-app/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/ref-types/CMakeLists.txt (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/ref-types/src/hello.c (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/ref-types/src/hello.wat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/sgx-ra/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/sgx-ra/README.md (83%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/sgx-ra/wasm-app/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/sgx-ra/wasm-app/main.c (98%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/.gitignore create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/CMakeLists.txt create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/README.md create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/build.sh create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/run.sh create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/src/main.c create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/wasm-apps/testapp.wat rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/.gitignore (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/build.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/profiles/arm-interp/toolchain.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/profiles/arm-interp/wamr_config_simple.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/profiles/arm64-aot/toolchain.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/profiles/arm64-aot/wamr_config_simple.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/profiles/arm64-interp/toolchain.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/profiles/arm64-interp/wamr_config_simple.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/profiles/host-aot/wamr_config_simple.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/profiles/host-interp/wamr_config_simple.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/profiles/macos-interp/wamr_config_simple.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/sample_test_run.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/src/iwasm_main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/src/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/wasm-apps/connection.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/wasm-apps/event_publisher.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/wasm-apps/event_subscriber.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/wasm-apps/request_handler.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/wasm-apps/request_sender.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/wasm-apps/sensor.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/simple/wasm-apps/timer.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/socket-api/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/socket-api/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/socket-api/sample_test_run.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/socket-api/wasm-src/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/socket-api/wasm-src/addr_resolve.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/socket-api/wasm-src/inc/.gitkeep (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/socket-api/wasm-src/multicast_client.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/socket-api/wasm-src/multicast_server.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/socket-api/wasm-src/send_recv.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/socket-api/wasm-src/socket_opts.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/socket-api/wasm-src/socket_utils.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/socket-api/wasm-src/tcp_client.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/socket-api/wasm-src/tcp_server.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/socket-api/wasm-src/timeout_client.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/socket-api/wasm-src/timeout_server.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/socket-api/wasm-src/udp_client.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/socket-api/wasm-src/udp_server.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/spawn-thread/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/spawn-thread/src/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/spawn-thread/wasm-apps/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/spawn-thread/wasm-apps/sum.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasi-threads/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasi-threads/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasi-threads/wasm-apps/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasi-threads/wasm-apps/no_pthread.c (88%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasi-threads/wasm-apps/wasi_thread_start.S (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasi-threads/wasm-apps/wasi_thread_start.h (78%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api-imports/.gitignore (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api-imports/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api-imports/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api-imports/host/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api-imports/host/example1.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api-imports/wasm/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api-imports/wasm/inc/.gitkeep (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api-imports/wasm/send_recv.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/CMakeLists.txt (92%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/LICENSE (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/callback.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/callback.wat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/callback_chain.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/callback_chain.wat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/clone.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/clone.wat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/empty_imports.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/empty_imports.wat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/global.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/global.wat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/globalexportimport-0.wat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/globalexportimport-1.wat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/globalexportimport.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/hello.c (95%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/hello.wat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/hostref.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/hostref.wat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/memory.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/memory.wat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/multi.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/multi.wat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/reflect.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/reflect.wat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/serialize.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/serialize.wat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/table.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/table.wat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/threads.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/threads.wat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/trap.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/trap.wat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/wasm-c-api/src/utils/multi_module_utils.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/XNNPACK/.gitignore (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/XNNPACK/CMakeLists.txt rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/XNNPACK/README.md (62%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/XNNPACK/benchmark.patch (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/XNNPACK/xnnpack.patch rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/bwa/.gitignore (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/bwa/CMakeLists.bwa_wasm.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/bwa/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/bwa/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/bwa/bwa.patch (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/cmake/FindBinaryen.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/cmake/FindWASISDK.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/include/.gitkeep (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/meshoptimizer/.gitignore (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/meshoptimizer/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/meshoptimizer/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/meshoptimizer/codecbench.patch (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/preparation.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/tensorflow/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/tensorflow/build.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/tensorflow/tf_lite.patch (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/wasm-av1/.gitignore (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/wasm-av1/CMakeLists.avx_wasm.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/wasm-av1/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/wasm-av1/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/wasm-av1/av1-clang.patch (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/wasm-av1/build.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/samples/workload/wasm-av1/wasm-av1.patch (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/.gitignore (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/docker-compose.yml (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/Dockerfile (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/db.sqlite3 (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/devices/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/devices/admin.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/devices/apps.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/devices/migrations/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/devices/models.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/application.html (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/appstore.html (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/empty.html (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/help.html (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/mysite.html (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/devices/tests.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/devices/views.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/manage.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/settings.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/urls.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/wsgi.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/server/Dockerfile (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/server/wasm_server.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/css/application.css (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/css/appstore.css (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/css/index.css (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/application.js (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/appstore.js (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/index.js (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/app(1).png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/application.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/delete.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/download(1).png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/menu.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/milky-way-2695569_1280.jpg (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/net_device.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/software-icon-32081.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/totalblack.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/connection.wasm (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_publisher.wasm (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_subscriber.wasm (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_handler.wasm (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_sender.wasm (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sensor.wasm (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/simple (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/connection.wasm (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_publisher.wasm (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_subscriber.wasm (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_handler.wasm (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_sender.wasm (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/timer.wasm (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/timer.wasm (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/ui_app.wasm (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/wasm_runtime_wgl (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/binarydump-tool/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/binarydump-tool/binarydump.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/framework/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/framework/case_base.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/framework/engine.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/framework/framework.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/framework/suite.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/framework/test_api.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/framework/test_utils.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/harness/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/harness/harness_api.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/host-clients/src/host_app_sample.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/host-clients/src/makefile (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/set_dev_env.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/start.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/cases/01-install/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/cases/01-install/case.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/cases/02-request/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/cases/02-request/case.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/cases/03-event/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/cases/03-event/case.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/cases/04-request-internal/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/cases/04-request-internal/case.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/cases/05-event-internal/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/cases/05-event-internal/case.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/cases/06-timer/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/cases/06-timer/case.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/cases/07-sensor/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/cases/07-sensor/case.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/cases/08-on-destroy/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/cases/08-on-destroy/case.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/cases/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/suite_setup.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/test-app/01_install.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/test-app/02_request.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/test-app/03_event.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/test-app/04_request_internal_req.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/test-app/04_request_internal_resp.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/test-app/05_event_internal_provider.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/test-app/05_event_internal_subscriber.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/test-app/06_timer.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/test-app/07_sensor.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/test-app/08_on_destroy.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/test-app/build.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/tools/product/start.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/01-life-cycle/tools/product/stop.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/__init__.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/component-test/suites/readme.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/host-tool/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/host-tool/external/cJSON/LICENSE (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/host-tool/external/cJSON/cJSON.c (87%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/host-tool/external/cJSON/cJSON.h (73%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/host-tool/external/cJSON/cjson.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/host-tool/src/host_tool_utils.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/host-tool/src/host_tool_utils.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/host-tool/src/main.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/host-tool/src/transport.c (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/host-tool/src/transport.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/pick-up-emscripten-headers/collect_files.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/.gitattributes (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/Config_building_target.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/build_folder.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/build_terminal.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/change_workspace_dialog.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/compilation_config.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/compilation_config_2.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/debug.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/decoration_for_files.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/docker_config.jpg (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/docker_engine_config.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/docker_images.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/install_from_vsix.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/new_project_page.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/open_project_page.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/project_template.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/right_click_menus_1.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/right_click_menus_2.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/run.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/save_configuration.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/set_up_workspace_message.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Media/wamr_ide_main_menu.png (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Script/build.bat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/Script/build.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/.eslintrc.json (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/.gitignore create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/.npmrc rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/.prettierrc.json (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/.vscodeignore rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/CONTRIBUTING.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/LICENSE (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/README.md (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/formatters/rust.py rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/package.json (96%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/scripts/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/scripts/boot_debugger_server.bat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/scripts/boot_debugger_server.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/scripts/build.bat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/scripts/build.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/scripts/destroy.bat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/scripts/destroy.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/scripts/project.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/scripts/run.bat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/scripts/run.sh (100%) create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/test/build.sh create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/test/test.rs rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/assert.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/ctype.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/errno.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/fcntl.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/inttypes.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/limits.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/pthread.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdarg.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdbool.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdint.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdio.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdlib.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/string.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/strings.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/webview/css/style.css (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/webview/js/configbuildtarget.js (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/webview/js/newproj.js (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/webview/page/configBuildTarget.html (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/resource/webview/page/newProject.html (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/src/constants.ts (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/src/debugConfigurationProvider.ts (51%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/src/decorationProvider.ts (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/src/extension.ts (99%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/src/taskProvider.ts (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/test/runTest.ts create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/test/suite/extension.test.ts create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/test/suite/index.ts create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/test/suite/utils.ts rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/src/utilities/directoryUtilities.ts (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/src/utilities/dockerUtilities.ts (96%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/src/utilities/getUri.ts (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/src/utilities/lldbUtilities.ts (85%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/src/view/NewProjectPanel.ts (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/src/view/TargetConfigPanel.ts (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/VSCode-Extension/tsconfig.json (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/WASM-Debug-Server/Docker/Dockerfile (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/WASM-Debug-Server/Docker/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/WASM-Debug-Server/Docker/build_docker_image.bat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/WASM-Debug-Server/Docker/build_docker_image.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/WASM-Debug-Server/Docker/resource/debug.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/WASM-Debug-Server/Docker/resource/run.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/WASM-Toolchain/Docker/.dockerignore (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/WASM-Toolchain/Docker/Dockerfile (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/WASM-Toolchain/Docker/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/WASM-Toolchain/Docker/build_docker_image.bat (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/WASM-Toolchain/Docker/build_docker_image.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/WASM-Toolchain/Docker/resource/build_wasm.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/test-tools/wamr-ide/WASM-Toolchain/Docker/resource/wamr_toolchain.cmake (100%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/README.md rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/benchmarks/coremark/README.md (59%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/benchmarks/coremark/build.sh (84%) create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/coremark/run.sh create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/coremark/test_pgo.sh create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/LICENSE create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/build.sh create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/include/dhry.h create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/run.sh create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/src/dhry_1.c create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/src/dhry_2.c create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/test_pgo.sh rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/benchmarks/jetstream/README.md (68%) create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/build.sh rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/benchmarks/jetstream/jetstream.patch (69%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/benchmarks/jetstream/run_aot.sh (62%) create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/test_pgo.sh create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/tsf.patch rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/benchmarks/libsodium/README.md (66%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/benchmarks/libsodium/build.sh (63%) create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/libsodium/run_aot.sh create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/libsodium/test_pgo.sh rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/benchmarks/polybench/README.md (67%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/benchmarks/polybench/build.sh (82%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/benchmarks/polybench/run_aot.sh (77%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/benchmarks/polybench/run_interp.sh (96%) create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/polybench/test_pgo.sh rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/benchmarks/sightglass/README.md (64%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/benchmarks/sightglass/build.sh (84%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/benchmarks/sightglass/run_aot.sh (75%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/benchmarks/sightglass/run_interp.sh (88%) create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/sightglass/test_pgo.sh create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/tests/unit/CMakeLists.txt create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/tests/unit/main.cpp create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-compiler/.gitignore create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-compiler/README.md create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-compiler/test_shift_negative_constants.wat rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/wamr-test-suites/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/wamr-test-suites/spec-test-script/CHANGES (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/wamr-test-suites/spec-test-script/all.py (82%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/wamr-test-suites/spec-test-script/all.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/wamr-test-suites/spec-test-script/collect_coverage.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/wamr-test-suites/spec-test-script/ignore_cases.patch (98%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/multi_module_aot_ignore_cases.patch rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/wamr-test-suites/spec-test-script/runtest.py (85%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/wamr-test-suites/spec-test-script/simd_ignore_cases.patch (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/wamr-test-suites/spec-test-script/tail-call/return_call.wast (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/wamr-test-suites/spec-test-script/tail-call/return_call_indirect.wast (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/wamr-test-suites/spec-test-script/thread_proposal_fix_atomic_case.patch (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/wamr-test-suites/spec-test-script/thread_proposal_ignore_cases.patch (91%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/tests/wamr-test-suites/test_wamr.sh (85%) create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/tsan_suppressions.txt create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/wamr-compiler-test-script/run_wamr_compiler_tests.sh create mode 100644 lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/wasi-test-script/pipe.py create mode 100755 lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/wasi-test-script/run_wasi_tests.sh rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-compiler/CMakeLists.txt (98%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-compiler/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-compiler/build_llvm.py (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-compiler/build_llvm.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-compiler/build_llvm_arc.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-compiler/build_llvm_xtensa.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-compiler/main.c (60%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/Kconfig (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/Makefile (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/README.md (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/libc-builtin-sysroot/include/assert.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/libc-builtin-sysroot/include/ctype.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/libc-builtin-sysroot/include/errno.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/libc-builtin-sysroot/include/fcntl.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/libc-builtin-sysroot/include/inttypes.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/libc-builtin-sysroot/include/limits.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/libc-builtin-sysroot/include/pthread.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/libc-builtin-sysroot/include/semaphore.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/libc-builtin-sysroot/include/stdarg.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/libc-builtin-sysroot/include/stdbool.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/libc-builtin-sysroot/include/stdint.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/libc-builtin-sysroot/include/stdio.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/libc-builtin-sysroot/include/stdlib.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/libc-builtin-sysroot/include/string.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/libc-builtin-sysroot/include/strings.h (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/libc-builtin-sysroot/share/defined-symbols.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/wamr_toolchain.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/app/wasi_toolchain.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/build_sdk.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/menuconfig.sh (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/runtime/CMakeLists.txt (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/wamr_config_default.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/wamr_config_macos_release.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/wamr-sdk/wamr_config_ubuntu_release.cmake (100%) rename lib/{wasm-micro-runtime-WAMR-1.2.2 => wasm-micro-runtime-WAMR-1.3.0}/zephyr/module.yml (100%) diff --git a/cmake/libraries.cmake b/cmake/libraries.cmake index 1b43d523bfa..8cf2ec8b3f0 100644 --- a/cmake/libraries.cmake +++ b/cmake/libraries.cmake @@ -23,4 +23,4 @@ set(FLB_PATH_LIB_CARES "lib/c-ares-1.24.0") set(FLB_PATH_LIB_SNAPPY "lib/snappy-fef67ac") set(FLB_PATH_LIB_RDKAFKA "lib/librdkafka-2.1.0") set(FLB_PATH_LIB_RING_BUFFER "lib/lwrb") -set(FLB_PATH_LIB_WASM_MICRO_RUNTIME "lib/wasm-micro-runtime-WAMR-1.2.2") +set(FLB_PATH_LIB_WASM_MICRO_RUNTIME "lib/wasm-micro-runtime-WAMR-1.3.0") diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/spec_test_on_nuttx.yml b/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/spec_test_on_nuttx.yml deleted file mode 100644 index 7b8403777fa..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/spec_test_on_nuttx.yml +++ /dev/null @@ -1,145 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -name: spec test on nuttx - -on: - schedule: - - cron: '0 0 * * *' - - workflow_dispatch: - -env: - LLVM_CACHE_SUFFIX: "build-llvm_libraries_ex" - WASI_SDK_PATH: "/opt/wasi-sdk" - -jobs: - build_llvm_libraries: - uses: ./.github/workflows/build_llvm_libraries.yml - with: - os: "ubuntu-22.04" - arch: "ARM RISCV AArch64" - - spec_test_on_qemu: - runs-on: ${{ matrix.os }} - needs: [build_llvm_libraries] - strategy: - matrix: - os: [ubuntu-22.04] - nuttx_board_config: [ - # cortex-a9 - "boards/arm/imx6/sabre-6quad/configs/nsh", - # riscv32imac - "boards/risc-v/qemu-rv/rv-virt/configs/nsh", - # riscv64imac - # "boards/risc-v/qemu-rv/rv-virt/configs/nsh64", - ] - wamr_test_option: [ - # "-t fast-interp", - "-t aot", - "-t aot -X" - ] - llvm_cache_key: [ "${{ needs.build_llvm_libraries.outputs.cache_key }}" ] - steps: - - name: Install Utilities - run: | - sudo apt install -y kconfig-frontends-nox genromfs - - - name: Install ARM Compilers - if: contains(matrix.nuttx_board_config, 'arm') - run: sudo apt install -y gcc-arm-none-eabi - - - name: Install RISC-V Compilers - if: contains(matrix.nuttx_board_config, 'risc-v') - run: | - curl -L https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz > riscv.tar.gz - tar xvf riscv.tar.gz - echo "$PWD/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin" >> $GITHUB_PATH - - - name: Install WASI-SDK - run: | - curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz > wasi-sdk.tar.gz - tar xvf wasi-sdk.tar.gz - sudo mv wasi-sdk-* /opt/wasi-sdk - - - name: Checkout NuttX - uses: actions/checkout@v3 - with: - repository: apache/incubator-nuttx - path: nuttx - - - name: Checkout NuttX Apps - uses: actions/checkout@v3 - with: - repository: apache/incubator-nuttx-apps - path: apps - - - name: Checkout WAMR - uses: actions/checkout@v3 - with: - repository: ${{ github.repository }} - path: apps/interpreters/wamr/wamr - - - name: Get LLVM libraries - id: retrieve_llvm_libs - uses: actions/cache@v3 - with: - path: | - ./core/deps/llvm/build/bin - ./core/deps/llvm/build/include - ./core/deps/llvm/build/lib - ./core/deps/llvm/build/libexec - ./core/deps/llvm/build/share - key: ${{ matrix.llvm_cache_key }} - - - name: Quit if cache miss - if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' - run: echo "::error::can not get prebuilt llvm libraries" && exit 1 - - - name: Copy LLVM - run: cp -r core/deps/llvm apps/interpreters/wamr/wamr/core/deps/llvm - - - name: Enable WAMR for NuttX - run: | - find nuttx/boards -name defconfig | xargs sed -i '$a\CONFIG_INTERPRETERS_WAMR=y\nCONFIG_INTERPRETERS_WAMR_STACKSIZE=32768\nCONFIG_INTERPRETERS_WAMR_AOT=y\nCONFIG_INTERPRETERS_WAMR_FAST=y\nCONFIG_INTERPRETERS_WAMR_LOG=y\nCONFIG_INTERPRETERS_WAMR_LIBC_BUILTIN=y\nCONFIG_INTERPRETERS_WAMR_REF_TYPES=y\nCONFIG_INTERPRETERS_WAMR_ENABLE_SPEC_TEST=y\nCONFIG_INTERPRETERS_WAMR_SHARED_MEMORY=y\nCONFIG_INTERPRETERS_WAMR_BULK_MEMORY=y\n' - find nuttx/boards -name defconfig | xargs sed -i '$a\CONFIG_EOL_IS_LF=y\nCONFIG_ARM_SEMIHOSTING_HOSTFS=y\nCONFIG_ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE=y\nCONFIG_RISCV_SEMIHOSTING_HOSTFS=y\nCONFIG_FS_HOSTFS=y\nCONFIG_LIBC_FLOATINGPOINT=y\n' - - - name: Build wamrc - working-directory: apps/interpreters/wamr/wamr/wamr-compiler - run: | - cmake -Bbuild . - cmake --build build - - - name: Build - run: | - cd nuttx - tools/configure.sh ${{ matrix.nuttx_board_config }} - make -j$(nproc) - echo "firmware=$PWD/nuttx" >> $GITHUB_ENV - - - name: Test on ARM - if: endsWith(matrix.nuttx_board_config, 'sabre-6quad/configs/nsh') - run: | - curl -L https://github.com/xpack-dev-tools/qemu-arm-xpack/releases/download/v7.1.0-1/xpack-qemu-arm-7.1.0-1-linux-x64.tar.gz > xpack-qemu-arm.tar.gz - tar xvf xpack-qemu-arm.tar.gz - export PATH=$PATH:$PWD/xpack-qemu-arm-7.1.0-1/bin - cd apps/interpreters/wamr/wamr/tests/wamr-test-suites - ./test_wamr.sh -s spec ${{ matrix.wamr_test_option }} -m thumbv7_vfp -b -Q -P -F ${{ env.firmware }} - - - name: Test on RISCV32 - if: endsWith(matrix.nuttx_board_config, 'rv-virt/configs/nsh') - run: | - curl -L https://github.com/xpack-dev-tools/qemu-riscv-xpack/releases/download/v7.1.0-1/xpack-qemu-riscv-7.1.0-1-linux-x64.tar.gz > xpack-qemu-riscv.tar.gz - tar xvf xpack-qemu-riscv.tar.gz - export PATH=$PATH:$PWD/xpack-qemu-riscv-7.1.0-1/bin - cd apps/interpreters/wamr/wamr/tests/wamr-test-suites - ./test_wamr.sh -s spec ${{ matrix.wamr_test_option }} -m RISCV32 -b -Q -P -F ${{ env.firmware }} - - - name: Test on RISCV64 - if: endsWith(matrix.nuttx_board_config, 'rv-virt/configs/nsh64') - run: | - curl -L https://github.com/xpack-dev-tools/qemu-riscv-xpack/releases/download/v7.1.0-1/xpack-qemu-riscv-7.1.0-1-linux-x64.tar.gz > xpack-qemu-riscv.tar.gz - tar xvf xpack-qemu-riscv.tar.gz - export PATH=$PATH:$PWD/xpack-qemu-riscv-7.1.0-1/bin - cd apps/interpreters/wamr/wamr/tests/wamr-test-suites - ./test_wamr.sh -s spec ${{ matrix.wamr_test_option }} -m riscv64 -b -Q -P -F ${{ env.firmware }} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/requirements.txt b/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/requirements.txt deleted file mode 100644 index bf0d9d41143..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -requests==2.28.2 \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/README.md b/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/README.md deleted file mode 100644 index 31c705e1fb5..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Remote application management - -The WAMR application manager supports [remote application management](../core/app-mgr) from the host environment or the cloud through any physical communications such as TCP, UPD, UART, BLE, etc. Its modular design makes it able to support application management for different managed runtimes. - -The tool [host_tool](../test-tools/host-tool) communicates to the WAMR app manager for installing/uninstalling the WASM applications on companion chip from the host system. And the [IoT App Store Demo](../test-tools/IoT-APP-Store-Demo/) shows the conception of remotely managing the device applications from the cloud. - - - diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/iwasm_aot.cmake b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/iwasm_aot.cmake deleted file mode 100644 index 8014f237216..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/iwasm_aot.cmake +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set (IWASM_AOT_DIR ${CMAKE_CURRENT_LIST_DIR}) - -add_definitions (-DWASM_ENABLE_AOT=1) - -include_directories (${IWASM_AOT_DIR}) - -file (GLOB c_source_all ${IWASM_AOT_DIR}/*.c) - -if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64") - set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_x86_64.c) -elseif (WAMR_BUILD_TARGET STREQUAL "X86_32") - set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_x86_32.c) -elseif (WAMR_BUILD_TARGET MATCHES "AARCH64.*") - set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_aarch64.c) -elseif (WAMR_BUILD_TARGET MATCHES "ARM.*") - set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_arm.c) -elseif (WAMR_BUILD_TARGET MATCHES "THUMB.*") - set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_thumb.c) -elseif (WAMR_BUILD_TARGET STREQUAL "MIPS") - set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_mips.c) -elseif (WAMR_BUILD_TARGET STREQUAL "XTENSA") - set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_xtensa.c) -elseif (WAMR_BUILD_TARGET MATCHES "RISCV*") - set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_riscv.c) -elseif (WAMR_BUILD_TARGET STREQUAL "ARC") - set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_arc.c) -else () - message (FATAL_ERROR "Build target isn't set") -endif () - -if (WAMR_BUILD_DEBUG_AOT EQUAL 1) - add_definitions(-DWASM_ENABLE_DEBUG_AOT=1) - file(GLOB debug_source ${IWASM_AOT_DIR}/debug/*.c) -endif() - -set (IWASM_AOT_SOURCE ${c_source_all} ${arch_source} ${debug_source}) - diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_memory.h b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_memory.h deleted file mode 100644 index 1324742fe34..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_memory.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _WASM_MEMORY_H -#define _WASM_MEMORY_H - -#include "bh_common.h" -#include "../include/wasm_export.h" -#include "../interpreter/wasm_runtime.h" - -#ifdef __cplusplus -extern "C" { -#endif - -bool -wasm_runtime_memory_init(mem_alloc_type_t mem_alloc_type, - const MemAllocOption *alloc_option); - -void -wasm_runtime_memory_destroy(); - -unsigned -wasm_runtime_memory_pool_size(); - -#if !defined(OS_ENABLE_HW_BOUND_CHECK) \ - || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \ - || WASM_ENABLE_BULK_MEMORY != 0 -uint32 -wasm_get_num_bytes_per_page(WASMMemoryInstance *memory, void *node); - -uint32 -wasm_get_linear_memory_size(WASMMemoryInstance *memory, void *node); -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* end of _WASM_MEMORY_H */ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_shared_memory.h b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_shared_memory.h deleted file mode 100644 index 6c1c49210f2..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_shared_memory.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#ifndef _WASM_SHARED_MEMORY_H -#define _WASM_SHARED_MEMORY_H - -#include "bh_common.h" -#if WASM_ENABLE_INTERP != 0 -#include "wasm_runtime.h" -#endif -#if WASM_ENABLE_AOT != 0 -#include "aot_runtime.h" -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct WASMSharedMemNode { - bh_list_link l; - /* Lock */ - korp_mutex lock; - /* The module reference */ - WASMModuleCommon *module; - /* The memory information */ - WASMMemoryInstanceCommon *memory_inst; - /* Lock used for atomic operations */ - korp_mutex shared_mem_lock; - - /* reference count */ - uint32 ref_count; -} WASMSharedMemNode; - -bool -wasm_shared_memory_init(); - -void -wasm_shared_memory_destroy(); - -WASMSharedMemNode * -wasm_module_get_shared_memory(WASMModuleCommon *module); - -int32 -shared_memory_inc_reference(WASMModuleCommon *module); - -int32 -shared_memory_dec_reference(WASMModuleCommon *module); - -WASMMemoryInstanceCommon * -shared_memory_get_memory_inst(WASMSharedMemNode *node); - -WASMSharedMemNode * -shared_memory_set_memory_inst(WASMModuleCommon *module, - WASMMemoryInstanceCommon *memory); - -uint32 -wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address, - uint64 expect, int64 timeout, bool wait64); - -uint32 -wasm_runtime_atomic_notify(WASMModuleInstanceCommon *module, void *address, - uint32 count); - -#ifdef __cplusplus -} -#endif - -#endif /* end of _WASM_SHARED_MEMORY_H */ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_utils.c b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_utils.c deleted file mode 100644 index 57a3e8f678c..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_utils.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2021 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "jit_utils.h" - -JitBitmap * -jit_bitmap_new(uintptr_t begin_index, unsigned bitnum) -{ - JitBitmap *bitmap; - - if ((bitmap = jit_calloc(offsetof(JitBitmap, map) + (bitnum + 7) / 8))) { - bitmap->begin_index = begin_index; - bitmap->end_index = begin_index + bitnum; - } - - return bitmap; -} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/test/tcp_udp.c b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/test/tcp_udp.c deleted file mode 100644 index 49231de8999..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/test/tcp_udp.c +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ -#include -#include -#include -#ifdef __wasi__ -#include -#include -#include -#endif -#include -#include -#define SERVER_MSG "Message from server." -#define PORT 8989 -pthread_mutex_t mut; -pthread_cond_t cond; -int server_init_complete = 0; -char buffer[sizeof(SERVER_MSG) + 1]; - -struct socket_info { - union { - struct sockaddr_in addr_ipv4; - struct sockaddr_in6 addr_ipv6; - } addr; - int sock; -}; - -struct thread_args { - int family; - int protocol; -}; - -struct socket_info -init_socket_addr(int family, int protocol) -{ - int sock = socket(family, protocol, 0); - assert(sock != -1); - - struct socket_info info; - if (family == AF_INET) { - struct sockaddr_in addr; - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_port = htons(PORT); - addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - info.addr.addr_ipv4 = addr; - } - else if (family == AF_INET6) { - struct sockaddr_in6 addr; - memset(&addr, 0, sizeof(addr)); - addr.sin6_family = AF_INET6; - addr.sin6_port = htons(PORT); - addr.sin6_addr = in6addr_loopback; - info.addr.addr_ipv6 = addr; - } - info.sock = sock; - return info; -} - -void -assert_thread_args(struct thread_args *args) -{ - assert(args->family == AF_INET || args->family == AF_INET6); - assert(args->protocol == SOCK_STREAM || args->protocol == SOCK_DGRAM); -} - -void * -server(void *arg) -{ - server_init_complete = 0; - struct thread_args *args = (struct thread_args *)arg; - assert_thread_args(args); - - struct socket_info init_server_sock = - init_socket_addr(args->family, args->protocol); - - int server_sock = init_server_sock.sock; - socklen_t addr_size; - struct sockaddr_storage client_addr; - strcpy(buffer, SERVER_MSG); - - struct sockaddr *server_addr = (struct sockaddr *)&init_server_sock.addr; - int ret = bind(server_sock, server_addr, - args->family == AF_INET ? sizeof(struct sockaddr_in) - : sizeof(struct sockaddr_in6)); - assert(ret == 0); - - (args->protocol == SOCK_STREAM) && listen(server_sock, 1); - pthread_mutex_lock(&mut); - server_init_complete = 1; - pthread_mutex_unlock(&mut); - pthread_cond_signal(&cond); - - addr_size = sizeof(client_addr); - if (args->protocol == SOCK_STREAM) { - int client_sock = - accept(server_sock, (struct sockaddr *)&client_addr, &addr_size); - assert(client_sock >= 0); - sendto(client_sock, buffer, strlen(buffer), 0, - (struct sockaddr *)&client_addr, addr_size); - - assert(close(client_sock) == 0); - } - else { - recvfrom(server_sock, buffer, sizeof(buffer), 0, - (struct sockaddr *)&client_addr, &addr_size); - sendto(server_sock, buffer, strlen(buffer), 0, - (struct sockaddr *)&client_addr, addr_size); - - assert(close(server_sock) == 0); - } - - return NULL; -} - -void * -client(void *arg) -{ - struct thread_args *args = (struct thread_args *)arg; - assert_thread_args(args); - - pthread_mutex_lock(&mut); - - while (server_init_complete == 0) { - pthread_cond_wait(&cond, &mut); - } - - struct socket_info init_client_sock = - init_socket_addr(args->family, args->protocol); - int sock = init_client_sock.sock; - pthread_mutex_unlock(&mut); - - if (args->family == AF_INET) { - struct sockaddr_in addr = init_client_sock.addr.addr_ipv4; - if (args->protocol == SOCK_STREAM) { - assert(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) != -1); - } - else { - assert(sendto(sock, buffer, strlen(buffer), 0, - (struct sockaddr *)&addr, sizeof(addr)) - != -1); - } - } - else { - struct sockaddr_in6 addr = init_client_sock.addr.addr_ipv6; - if (args->protocol == SOCK_STREAM) { - assert(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) != -1); - } - else { - assert(sendto(sock, buffer, strlen(buffer), 0, - (struct sockaddr *)&addr, sizeof(addr)) - != -1); - } - } - - recv(sock, buffer, sizeof(buffer), 0); - assert(strcmp(buffer, SERVER_MSG) == 0); - assert(close(sock) == 0); - return NULL; -} - -void -test_protocol(int family, int protocol) -{ - pthread_t server_thread, client_thread; - assert(pthread_cond_init(&cond, NULL) == 0); - assert(pthread_mutex_init(&mut, NULL) == 0); - - struct thread_args args = { family, protocol }; - assert(pthread_create(&server_thread, NULL, server, (void *)&args) == 0); - assert(pthread_create(&client_thread, NULL, client, (void *)&args) == 0); - assert(pthread_join(server_thread, NULL) == 0); - assert(pthread_join(client_thread, NULL) == 0); - - assert(pthread_mutex_destroy(&mut) == 0); - assert(pthread_cond_destroy(&cond) == 0); -} - -int -main(int argc, char **argv) -{ - /* test tcp with ipv4 and ipv6 */ - test_protocol(AF_INET, SOCK_STREAM); - test_protocol(AF_INET6, SOCK_STREAM); - - /* test udp with ipv4 and ipv6 */ - test_protocol(AF_INET, SOCK_DGRAM); - test_protocol(AF_INET6, SOCK_DGRAM); - - return 0; -} \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/build.sh b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/build.sh deleted file mode 100755 index 32586c20c88..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/build.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -# -# Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -set -eo pipefail -CC=${CC:=/opt/wasi-sdk/bin/clang} -WAMR_DIR=../../../../.. - -for test_c in *.c; do - test_wasm="$(basename $test_c .c).wasm" - - if [ $test_wasm = "linear_memory_size_update.wasm" ]; then - thread_start_file="" - else - thread_start_file=$WAMR_DIR/samples/wasi-threads/wasm-apps/wasi_thread_start.S - fi - - echo "Compiling $test_c to $test_wasm" - $CC \ - -target wasm32-wasi-threads \ - -pthread -ftls-model=local-exec \ - -z stack-size=32768 \ - -Wl,--export=__heap_base \ - -Wl,--export=__data_end \ - -Wl,--shared-memory,--max-memory=1966080 \ - -Wl,--export=wasi_thread_start \ - -Wl,--export=malloc \ - -Wl,--export=free \ - -I $WAMR_DIR/samples/wasi-threads/wasm-apps \ - $thread_start_file \ - $test_c -o $test_wasm -done \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.json b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.json deleted file mode 100644 index 9dc1e30d2b1..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "exit_code": 1 -} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/libc_uvwasi.cmake b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/libc_uvwasi.cmake deleted file mode 100644 index e0c8afa21f3..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/libc_uvwasi.cmake +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set (LIBC_WASI_DIR ${CMAKE_CURRENT_LIST_DIR}) - -set (LIBUV_VERSION v1.44.2) - -add_definitions (-DWASM_ENABLE_LIBC_WASI=1 -DWASM_ENABLE_UVWASI=1) - -include(FetchContent) - -## libuv -FetchContent_Declare( - libuv - GIT_REPOSITORY https://github.com/libuv/libuv.git - GIT_TAG ${LIBUV_VERSION} -) -FetchContent_GetProperties(libuv) -if (NOT libuv_POPULATED) - message("-- Fetching libuv ..") - FetchContent_Populate(libuv) - include_directories("${libuv_SOURCE_DIR}/include") - add_subdirectory(${libuv_SOURCE_DIR} ${libuv_BINARY_DIR} EXCLUDE_FROM_ALL) - set (UV_A_LIBS uv_a) - set_target_properties(uv_a PROPERTIES POSITION_INDEPENDENT_CODE 1) -endif() - -## uvwasi -FetchContent_Declare( - uvwasi - GIT_REPOSITORY https://github.com/nodejs/uvwasi.git - GIT_TAG main -) -FetchContent_GetProperties(uvwasi) -if (NOT uvwasi_POPULATED) - message("-- Fetching uvwasi ..") - FetchContent_Populate(uvwasi) - include_directories("${uvwasi_SOURCE_DIR}/include") - add_subdirectory(${uvwasi_SOURCE_DIR} ${uvwasi_BINARY_DIR} EXCLUDE_FROM_ALL) -endif() - -file (GLOB_RECURSE source_all ${LIBC_WASI_DIR}/*.c ${uvwasi_SOURCE_DIR}/src/*.c) - -set (LIBC_WASI_SOURCE ${source_all}) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h deleted file mode 100644 index feadf2f9586..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h +++ /dev/null @@ -1,1508 +0,0 @@ -/* - * Part of the Wasmtime Project, under the Apache License v2.0 with - * LLVM Exceptions. See - * https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE - * for license information. - * - * This file declares an interface similar to WASI, but augmented to expose - * some implementation details such as the curfds arguments that we pass - * around to avoid storing them in TLS. - */ - -/** - * The defitions of type, macro and structure in this file should be - * consistent with those in wasi-libc: - * https://github.com/WebAssembly/wasi-libc/blob/main/libc-bottom-half/headers/public/wasi/api.h - */ - -#ifndef WASMTIME_SSP_H -#define WASMTIME_SSP_H - -#include -#include -#include - -/* clang-format off */ - -#ifdef __cplusplus -#ifndef _Static_assert -#define _Static_assert static_assert -#endif /* _Static_assert */ - -#ifndef _Alignof -#define _Alignof alignof -#endif /* _Alignof */ - -#ifndef _Noreturn -#define _Noreturn [[ noreturn ]] -#endif /* _Noreturn */ -extern "C" { -#endif - -_Static_assert(_Alignof(int8_t) == 1, "non-wasi data layout"); -_Static_assert(_Alignof(uint8_t) == 1, "non-wasi data layout"); -_Static_assert(_Alignof(int16_t) == 2, "non-wasi data layout"); -_Static_assert(_Alignof(uint16_t) == 2, "non-wasi data layout"); -_Static_assert(_Alignof(int32_t) == 4, "non-wasi data layout"); -_Static_assert(_Alignof(uint32_t) == 4, "non-wasi data layout"); -#if 0 -_Static_assert(_Alignof(int64_t) == 8, "non-wasi data layout"); -_Static_assert(_Alignof(uint64_t) == 8, "non-wasi data layout"); -#endif - -typedef uint32_t __wasi_size_t; -_Static_assert(_Alignof(__wasi_size_t) == 4, "non-wasi data layout"); - -typedef uint8_t __wasi_advice_t; -#define __WASI_ADVICE_NORMAL (0) -#define __WASI_ADVICE_SEQUENTIAL (1) -#define __WASI_ADVICE_RANDOM (2) -#define __WASI_ADVICE_WILLNEED (3) -#define __WASI_ADVICE_DONTNEED (4) -#define __WASI_ADVICE_NOREUSE (5) - -typedef uint32_t __wasi_clockid_t; -#define __WASI_CLOCK_REALTIME (0) -#define __WASI_CLOCK_MONOTONIC (1) -#define __WASI_CLOCK_PROCESS_CPUTIME_ID (2) -#define __WASI_CLOCK_THREAD_CPUTIME_ID (3) - -typedef uint64_t __wasi_device_t; - -typedef uint64_t __wasi_dircookie_t; -#define __WASI_DIRCOOKIE_START (0) - -typedef uint32_t __wasi_dirnamlen_t; - -typedef uint16_t __wasi_errno_t; -#define __WASI_ESUCCESS (0) -#define __WASI_E2BIG (1) -#define __WASI_EACCES (2) -#define __WASI_EADDRINUSE (3) -#define __WASI_EADDRNOTAVAIL (4) -#define __WASI_EAFNOSUPPORT (5) -#define __WASI_EAGAIN (6) -#define __WASI_EALREADY (7) -#define __WASI_EBADF (8) -#define __WASI_EBADMSG (9) -#define __WASI_EBUSY (10) -#define __WASI_ECANCELED (11) -#define __WASI_ECHILD (12) -#define __WASI_ECONNABORTED (13) -#define __WASI_ECONNREFUSED (14) -#define __WASI_ECONNRESET (15) -#define __WASI_EDEADLK (16) -#define __WASI_EDESTADDRREQ (17) -#define __WASI_EDOM (18) -#define __WASI_EDQUOT (19) -#define __WASI_EEXIST (20) -#define __WASI_EFAULT (21) -#define __WASI_EFBIG (22) -#define __WASI_EHOSTUNREACH (23) -#define __WASI_EIDRM (24) -#define __WASI_EILSEQ (25) -#define __WASI_EINPROGRESS (26) -#define __WASI_EINTR (27) -#define __WASI_EINVAL (28) -#define __WASI_EIO (29) -#define __WASI_EISCONN (30) -#define __WASI_EISDIR (31) -#define __WASI_ELOOP (32) -#define __WASI_EMFILE (33) -#define __WASI_EMLINK (34) -#define __WASI_EMSGSIZE (35) -#define __WASI_EMULTIHOP (36) -#define __WASI_ENAMETOOLONG (37) -#define __WASI_ENETDOWN (38) -#define __WASI_ENETRESET (39) -#define __WASI_ENETUNREACH (40) -#define __WASI_ENFILE (41) -#define __WASI_ENOBUFS (42) -#define __WASI_ENODEV (43) -#define __WASI_ENOENT (44) -#define __WASI_ENOEXEC (45) -#define __WASI_ENOLCK (46) -#define __WASI_ENOLINK (47) -#define __WASI_ENOMEM (48) -#define __WASI_ENOMSG (49) -#define __WASI_ENOPROTOOPT (50) -#define __WASI_ENOSPC (51) -#define __WASI_ENOSYS (52) -#define __WASI_ENOTCONN (53) -#define __WASI_ENOTDIR (54) -#define __WASI_ENOTEMPTY (55) -#define __WASI_ENOTRECOVERABLE (56) -#define __WASI_ENOTSOCK (57) -#define __WASI_ENOTSUP (58) -#define __WASI_ENOTTY (59) -#define __WASI_ENXIO (60) -#define __WASI_EOVERFLOW (61) -#define __WASI_EOWNERDEAD (62) -#define __WASI_EPERM (63) -#define __WASI_EPIPE (64) -#define __WASI_EPROTO (65) -#define __WASI_EPROTONOSUPPORT (66) -#define __WASI_EPROTOTYPE (67) -#define __WASI_ERANGE (68) -#define __WASI_EROFS (69) -#define __WASI_ESPIPE (70) -#define __WASI_ESRCH (71) -#define __WASI_ESTALE (72) -#define __WASI_ETIMEDOUT (73) -#define __WASI_ETXTBSY (74) -#define __WASI_EXDEV (75) -#define __WASI_ENOTCAPABLE (76) - -typedef uint16_t __wasi_eventrwflags_t; -#define __WASI_EVENT_FD_READWRITE_HANGUP (0x0001) - -typedef uint8_t __wasi_eventtype_t; -#define __WASI_EVENTTYPE_CLOCK (0) -#define __WASI_EVENTTYPE_FD_READ (1) -#define __WASI_EVENTTYPE_FD_WRITE (2) - -typedef uint32_t __wasi_exitcode_t; - -typedef uint32_t __wasi_fd_t; - -typedef uint16_t __wasi_fdflags_t; -#define __WASI_FDFLAG_APPEND (0x0001) -#define __WASI_FDFLAG_DSYNC (0x0002) -#define __WASI_FDFLAG_NONBLOCK (0x0004) -#define __WASI_FDFLAG_RSYNC (0x0008) -#define __WASI_FDFLAG_SYNC (0x0010) - -typedef int64_t __wasi_filedelta_t; - -typedef uint64_t __wasi_filesize_t; - -typedef uint8_t __wasi_filetype_t; -#define __WASI_FILETYPE_UNKNOWN (0) -#define __WASI_FILETYPE_BLOCK_DEVICE (1) -#define __WASI_FILETYPE_CHARACTER_DEVICE (2) -#define __WASI_FILETYPE_DIRECTORY (3) -#define __WASI_FILETYPE_REGULAR_FILE (4) -#define __WASI_FILETYPE_SOCKET_DGRAM (5) -#define __WASI_FILETYPE_SOCKET_STREAM (6) -#define __WASI_FILETYPE_SYMBOLIC_LINK (7) - -typedef uint16_t __wasi_fstflags_t; -#define __WASI_FILESTAT_SET_ATIM (0x0001) -#define __WASI_FILESTAT_SET_ATIM_NOW (0x0002) -#define __WASI_FILESTAT_SET_MTIM (0x0004) -#define __WASI_FILESTAT_SET_MTIM_NOW (0x0008) - -typedef uint64_t __wasi_inode_t; - -typedef uint64_t __wasi_linkcount_t __attribute__((aligned(8))); - -typedef uint32_t __wasi_lookupflags_t; -#define __WASI_LOOKUP_SYMLINK_FOLLOW (0x00000001) - -typedef uint16_t __wasi_oflags_t; -#define __WASI_O_CREAT (0x0001) -#define __WASI_O_DIRECTORY (0x0002) -#define __WASI_O_EXCL (0x0004) -#define __WASI_O_TRUNC (0x0008) - -typedef uint16_t __wasi_riflags_t; -#define __WASI_SOCK_RECV_PEEK (0x0001) -#define __WASI_SOCK_RECV_WAITALL (0x0002) - -typedef uint64_t __wasi_rights_t; - -/** - * Observe that WASI defines rights in the plural form - * TODO: refactor to use RIGHTS instead of RIGHT - */ -#define __WASI_RIGHT_FD_DATASYNC ((__wasi_rights_t)(UINT64_C(1) << 0)) -#define __WASI_RIGHT_FD_READ ((__wasi_rights_t)(UINT64_C(1) << 1)) -#define __WASI_RIGHT_FD_SEEK ((__wasi_rights_t)(UINT64_C(1) << 2)) -#define __WASI_RIGHT_FD_FDSTAT_SET_FLAGS ((__wasi_rights_t)(UINT64_C(1) << 3)) -#define __WASI_RIGHT_FD_SYNC ((__wasi_rights_t)(UINT64_C(1) << 4)) -#define __WASI_RIGHT_FD_TELL ((__wasi_rights_t)(UINT64_C(1) << 5)) -#define __WASI_RIGHT_FD_WRITE ((__wasi_rights_t)(UINT64_C(1) << 6)) -#define __WASI_RIGHT_FD_ADVISE ((__wasi_rights_t)(UINT64_C(1) << 7)) -#define __WASI_RIGHT_FD_ALLOCATE ((__wasi_rights_t)(UINT64_C(1) << 8)) -#define __WASI_RIGHT_PATH_CREATE_DIRECTORY ((__wasi_rights_t)(UINT64_C(1) << 9)) -#define __WASI_RIGHT_PATH_CREATE_FILE ((__wasi_rights_t)(UINT64_C(1) << 10)) -#define __WASI_RIGHT_PATH_LINK_SOURCE ((__wasi_rights_t)(UINT64_C(1) << 11)) -#define __WASI_RIGHT_PATH_LINK_TARGET ((__wasi_rights_t)(UINT64_C(1) << 12)) -#define __WASI_RIGHT_PATH_OPEN ((__wasi_rights_t)(UINT64_C(1) << 13)) -#define __WASI_RIGHT_FD_READDIR ((__wasi_rights_t)(UINT64_C(1) << 14)) -#define __WASI_RIGHT_PATH_READLINK ((__wasi_rights_t)(UINT64_C(1) << 15)) -#define __WASI_RIGHT_PATH_RENAME_SOURCE ((__wasi_rights_t)(UINT64_C(1) << 16)) -#define __WASI_RIGHT_PATH_RENAME_TARGET ((__wasi_rights_t)(UINT64_C(1) << 17)) -#define __WASI_RIGHT_PATH_FILESTAT_GET ((__wasi_rights_t)(UINT64_C(1) << 18)) -#define __WASI_RIGHT_PATH_FILESTAT_SET_SIZE ((__wasi_rights_t)(UINT64_C(1) << 19)) -#define __WASI_RIGHT_PATH_FILESTAT_SET_TIMES ((__wasi_rights_t)(UINT64_C(1) << 20)) -#define __WASI_RIGHT_FD_FILESTAT_GET ((__wasi_rights_t)(UINT64_C(1) << 21)) -#define __WASI_RIGHT_FD_FILESTAT_SET_SIZE ((__wasi_rights_t)(UINT64_C(1) << 22)) -#define __WASI_RIGHT_FD_FILESTAT_SET_TIMES ((__wasi_rights_t)(UINT64_C(1) << 23)) -#define __WASI_RIGHT_PATH_SYMLINK ((__wasi_rights_t)(UINT64_C(1) << 24)) -#define __WASI_RIGHT_PATH_REMOVE_DIRECTORY ((__wasi_rights_t)(UINT64_C(1) << 25)) -#define __WASI_RIGHT_PATH_UNLINK_FILE ((__wasi_rights_t)(UINT64_C(1) << 26)) -#define __WASI_RIGHT_POLL_FD_READWRITE ((__wasi_rights_t)(UINT64_C(1) << 27)) -#define __WASI_RIGHT_SOCK_CONNECT ((__wasi_rights_t)(UINT64_C(1) << 28)) -#define __WASI_RIGHT_SOCK_LISTEN ((__wasi_rights_t)(UINT64_C(1) << 29)) -#define __WASI_RIGHT_SOCK_BIND ((__wasi_rights_t)(UINT64_C(1) << 30)) -#define __WASI_RIGHT_SOCK_ACCEPT ((__wasi_rights_t)(UINT64_C(1) << 31)) -#define __WASI_RIGHT_SOCK_RECV ((__wasi_rights_t)(UINT64_C(1) << 32)) -#define __WASI_RIGHT_SOCK_SEND ((__wasi_rights_t)(UINT64_C(1) << 33)) -#define __WASI_RIGHT_SOCK_ADDR_LOCAL ((__wasi_rights_t)(UINT64_C(1) << 34)) -#define __WASI_RIGHT_SOCK_ADDR_REMOTE ((__wasi_rights_t)(UINT64_C(1) << 35)) -#define __WASI_RIGHT_SOCK_RECV_FROM ((__wasi_rights_t)(UINT64_C(1) << 36)) -#define __WASI_RIGHT_SOCK_SEND_TO ((__wasi_rights_t)(UINT64_C(1) << 37)) - -typedef uint16_t __wasi_roflags_t; -#define __WASI_SOCK_RECV_DATA_TRUNCATED (0x0001) - -typedef uint8_t __wasi_sdflags_t; -#define __WASI_SHUT_RD (0x01) -#define __WASI_SHUT_WR (0x02) - -typedef uint16_t __wasi_siflags_t; - -typedef uint8_t __wasi_signal_t; -// 0 is reserved; POSIX has special semantics for kill(pid, 0). -#define __WASI_SIGHUP (1) -#define __WASI_SIGINT (2) -#define __WASI_SIGQUIT (3) -#define __WASI_SIGILL (4) -#define __WASI_SIGTRAP (5) -#define __WASI_SIGABRT (6) -#define __WASI_SIGBUS (7) -#define __WASI_SIGFPE (8) -#define __WASI_SIGKILL (9) -#define __WASI_SIGUSR1 (10) -#define __WASI_SIGSEGV (11) -#define __WASI_SIGUSR2 (12) -#define __WASI_SIGPIPE (13) -#define __WASI_SIGALRM (14) -#define __WASI_SIGTERM (15) -#define __WASI_SIGCHLD (16) -#define __WASI_SIGCONT (17) -#define __WASI_SIGSTOP (18) -#define __WASI_SIGTSTP (19) -#define __WASI_SIGTTIN (20) -#define __WASI_SIGTTOU (21) -#define __WASI_SIGURG (22) -#define __WASI_SIGXCPU (23) -#define __WASI_SIGXFSZ (24) -#define __WASI_SIGVTALRM (25) -#define __WASI_SIGPROF (26) -#define __WASI_SIGWINCH (27) -#define __WASI_SIGPOLL (28) -#define __WASI_SIGPWR (29) -#define __WASI_SIGSYS (30) - -typedef uint16_t __wasi_subclockflags_t; -#define __WASI_SUBSCRIPTION_CLOCK_ABSTIME (0x0001) - -typedef uint64_t __wasi_timestamp_t; - -typedef uint64_t __wasi_userdata_t; - -typedef uint8_t __wasi_whence_t; -#define __WASI_WHENCE_SET (0) -#define __WASI_WHENCE_CUR (1) -#define __WASI_WHENCE_END (2) - -typedef uint8_t __wasi_preopentype_t; -#define __WASI_PREOPENTYPE_DIR (0) - -struct fd_table; -struct fd_prestats; -struct argv_environ_values; -struct addr_pool; - -typedef struct __wasi_dirent_t { - __wasi_dircookie_t d_next; - __wasi_inode_t d_ino; - __wasi_dirnamlen_t d_namlen; - __wasi_filetype_t d_type; -} __wasi_dirent_t __attribute__((aligned(8))); -_Static_assert(offsetof(__wasi_dirent_t, d_next) == 0, "non-wasi data layout"); -_Static_assert(offsetof(__wasi_dirent_t, d_ino) == 8, "non-wasi data layout"); -_Static_assert(offsetof(__wasi_dirent_t, d_namlen) == 16, "non-wasi data layout"); -_Static_assert(offsetof(__wasi_dirent_t, d_type) == 20, "non-wasi data layout"); -_Static_assert(sizeof(__wasi_dirent_t) == 24, "non-wasi data layout"); -_Static_assert(_Alignof(__wasi_dirent_t) == 8, "non-wasi data layout"); - -typedef struct __wasi_event_t { - __wasi_userdata_t userdata; - __wasi_errno_t error; - __wasi_eventtype_t type; - uint8_t __paddings[5]; - union __wasi_event_u { - struct __wasi_event_u_fd_readwrite_t { - __wasi_filesize_t nbytes; - __wasi_eventrwflags_t flags; - uint8_t __paddings[6]; - } fd_readwrite; - } u; -} __wasi_event_t __attribute__((aligned(8))); -_Static_assert(offsetof(__wasi_event_t, userdata) == 0, "non-wasi data layout"); -_Static_assert(offsetof(__wasi_event_t, error) == 8, "non-wasi data layout"); -_Static_assert(offsetof(__wasi_event_t, type) == 10, "non-wasi data layout"); -_Static_assert( - offsetof(__wasi_event_t, u.fd_readwrite.nbytes) == 16, "non-wasi data layout"); -_Static_assert( - offsetof(__wasi_event_t, u.fd_readwrite.flags) == 24, "non-wasi data layout"); -_Static_assert(sizeof(__wasi_event_t) == 32, "non-wasi data layout"); -_Static_assert(_Alignof(__wasi_event_t) == 8, "non-wasi data layout"); - -typedef struct __wasi_prestat_t { - __wasi_preopentype_t pr_type; - union __wasi_prestat_u { - struct __wasi_prestat_u_dir_t { - size_t pr_name_len; - } dir; - } u; -} __wasi_prestat_t; -_Static_assert(offsetof(__wasi_prestat_t, pr_type) == 0, "non-wasi data layout"); -_Static_assert(sizeof(void *) != 4 || - offsetof(__wasi_prestat_t, u.dir.pr_name_len) == 4, "non-wasi data layout"); -_Static_assert(sizeof(void *) != 8 || - offsetof(__wasi_prestat_t, u.dir.pr_name_len) == 8, "non-wasi data layout"); -_Static_assert(sizeof(void *) != 4 || - sizeof(__wasi_prestat_t) == 8, "non-wasi data layout"); -_Static_assert(sizeof(void *) != 8 || - sizeof(__wasi_prestat_t) == 16, "non-wasi data layout"); -_Static_assert(sizeof(void *) != 4 || - _Alignof(__wasi_prestat_t) == 4, "non-wasi data layout"); -_Static_assert(sizeof(void *) != 8 || - _Alignof(__wasi_prestat_t) == 8, "non-wasi data layout"); - -typedef struct __wasi_fdstat_t { - __wasi_filetype_t fs_filetype; - __wasi_fdflags_t fs_flags; - uint8_t __paddings[4]; - __wasi_rights_t fs_rights_base; - __wasi_rights_t fs_rights_inheriting; -} __wasi_fdstat_t __attribute__((aligned(8))); -_Static_assert( - offsetof(__wasi_fdstat_t, fs_filetype) == 0, "non-wasi data layout"); -_Static_assert(offsetof(__wasi_fdstat_t, fs_flags) == 2, "non-wasi data layout"); -_Static_assert( - offsetof(__wasi_fdstat_t, fs_rights_base) == 8, "non-wasi data layout"); -_Static_assert( - offsetof(__wasi_fdstat_t, fs_rights_inheriting) == 16, - "non-wasi data layout"); -_Static_assert(sizeof(__wasi_fdstat_t) == 24, "non-wasi data layout"); -_Static_assert(_Alignof(__wasi_fdstat_t) == 8, "non-wasi data layout"); - -typedef struct __wasi_filestat_t { - __wasi_device_t st_dev; - __wasi_inode_t st_ino; - __wasi_filetype_t st_filetype; - __wasi_linkcount_t st_nlink; - __wasi_filesize_t st_size; - __wasi_timestamp_t st_atim; - __wasi_timestamp_t st_mtim; - __wasi_timestamp_t st_ctim; -} __wasi_filestat_t __attribute__((aligned(8))); -_Static_assert(offsetof(__wasi_filestat_t, st_dev) == 0, "non-wasi data layout"); -_Static_assert(offsetof(__wasi_filestat_t, st_ino) == 8, "non-wasi data layout"); -_Static_assert( - offsetof(__wasi_filestat_t, st_filetype) == 16, "non-wasi data layout"); -_Static_assert( - offsetof(__wasi_filestat_t, st_nlink) == 24, "non-wasi data layout"); -_Static_assert( - offsetof(__wasi_filestat_t, st_size) == 32, "non-wasi data layout"); -_Static_assert( - offsetof(__wasi_filestat_t, st_atim) == 40, "non-wasi data layout"); -_Static_assert( - offsetof(__wasi_filestat_t, st_mtim) == 48, "non-wasi data layout"); -_Static_assert( - offsetof(__wasi_filestat_t, st_ctim) == 56, "non-wasi data layout"); -_Static_assert(sizeof(__wasi_filestat_t) == 64, "non-wasi data layout"); -_Static_assert(_Alignof(__wasi_filestat_t) == 8, "non-wasi data layout"); - -typedef struct __wasi_ciovec_t { - const void *buf; - size_t buf_len; -} __wasi_ciovec_t; -_Static_assert(offsetof(__wasi_ciovec_t, buf) == 0, "non-wasi data layout"); -_Static_assert(sizeof(void *) != 4 || - offsetof(__wasi_ciovec_t, buf_len) == 4, "non-wasi data layout"); -_Static_assert(sizeof(void *) != 8 || - offsetof(__wasi_ciovec_t, buf_len) == 8, "non-wasi data layout"); -_Static_assert(sizeof(void *) != 4 || - sizeof(__wasi_ciovec_t) == 8, "non-wasi data layout"); -_Static_assert(sizeof(void *) != 8 || - sizeof(__wasi_ciovec_t) == 16, "non-wasi data layout"); -_Static_assert(sizeof(void *) != 4 || - _Alignof(__wasi_ciovec_t) == 4, "non-wasi data layout"); -_Static_assert(sizeof(void *) != 8 || - _Alignof(__wasi_ciovec_t) == 8, "non-wasi data layout"); - -typedef struct __wasi_iovec_t { - void *buf; - size_t buf_len; -} __wasi_iovec_t; -_Static_assert(offsetof(__wasi_iovec_t, buf) == 0, "non-wasi data layout"); -_Static_assert(sizeof(void *) != 4 || - offsetof(__wasi_iovec_t, buf_len) == 4, "non-wasi data layout"); -_Static_assert(sizeof(void *) != 8 || - offsetof(__wasi_iovec_t, buf_len) == 8, "non-wasi data layout"); -_Static_assert(sizeof(void *) != 4 || - sizeof(__wasi_iovec_t) == 8, "non-wasi data layout"); -_Static_assert(sizeof(void *) != 8 || - sizeof(__wasi_iovec_t) == 16, "non-wasi data layout"); -_Static_assert(sizeof(void *) != 4 || - _Alignof(__wasi_iovec_t) == 4, "non-wasi data layout"); -_Static_assert(sizeof(void *) != 8 || - _Alignof(__wasi_iovec_t) == 8, "non-wasi data layout"); - -/** - * The contents of a `subscription` when type is `eventtype::clock`. - */ -typedef struct __wasi_subscription_clock_t { - /** - * The clock against which to compare the timestamp. - */ - __wasi_clockid_t clock_id; - - uint8_t __paddings1[4]; - - /** - * The absolute or relative timestamp. - */ - __wasi_timestamp_t timeout; - - /** - * The amount of time that the implementation may wait additionally - * to coalesce with other events. - */ - __wasi_timestamp_t precision; - - /** - * Flags specifying whether the timeout is absolute or relative - */ - __wasi_subclockflags_t flags; - - uint8_t __paddings2[4]; - -} __wasi_subscription_clock_t __attribute__((aligned(8))); - -_Static_assert(sizeof(__wasi_subscription_clock_t) == 32, "witx calculated size"); -_Static_assert(_Alignof(__wasi_subscription_clock_t) == 8, "witx calculated align"); -_Static_assert(offsetof(__wasi_subscription_clock_t, clock_id) == 0, "witx calculated offset"); -_Static_assert(offsetof(__wasi_subscription_clock_t, timeout) == 8, "witx calculated offset"); -_Static_assert(offsetof(__wasi_subscription_clock_t, precision) == 16, "witx calculated offset"); -_Static_assert(offsetof(__wasi_subscription_clock_t, flags) == 24, "witx calculated offset"); - -/** - * The contents of a `subscription` when type is type is - * `eventtype::fd_read` or `eventtype::fd_write`. - */ -typedef struct __wasi_subscription_fd_readwrite_t { - /** - * The file descriptor on which to wait for it to become ready for reading or writing. - */ - __wasi_fd_t fd; - -} __wasi_subscription_fd_readwrite_t; - -_Static_assert(sizeof(__wasi_subscription_fd_readwrite_t) == 4, "witx calculated size"); -_Static_assert(_Alignof(__wasi_subscription_fd_readwrite_t) == 4, "witx calculated align"); -_Static_assert(offsetof(__wasi_subscription_fd_readwrite_t, fd) == 0, "witx calculated offset"); - -/** - * The contents of a `subscription`. - */ -typedef union __wasi_subscription_u_u_t { - __wasi_subscription_clock_t clock; - __wasi_subscription_fd_readwrite_t fd_readwrite; -} __wasi_subscription_u_u_t ; - -typedef struct __wasi_subscription_u_t { - __wasi_eventtype_t type; - __wasi_subscription_u_u_t u; -} __wasi_subscription_u_t __attribute__((aligned(8))); - -_Static_assert(sizeof(__wasi_subscription_u_t) == 40, "witx calculated size"); -_Static_assert(_Alignof(__wasi_subscription_u_t) == 8, "witx calculated align"); -_Static_assert(offsetof(__wasi_subscription_u_t, u) == 8, "witx calculated union offset"); -_Static_assert(sizeof(__wasi_subscription_u_u_t) == 32, "witx calculated union size"); -_Static_assert(_Alignof(__wasi_subscription_u_u_t) == 8, "witx calculated union align"); - -/** - * Subscription to an event. - */ -typedef struct __wasi_subscription_t { - /** - * User-provided value that is attached to the subscription in the - * implementation and returned through `event::userdata`. - */ - __wasi_userdata_t userdata; - - /** - * The type of the event to which to subscribe, and its contents - */ - __wasi_subscription_u_t u; - -} __wasi_subscription_t; - -_Static_assert(sizeof(__wasi_subscription_t) == 48, "witx calculated size"); -_Static_assert(_Alignof(__wasi_subscription_t) == 8, "witx calculated align"); -_Static_assert(offsetof(__wasi_subscription_t, userdata) == 0, "witx calculated offset"); -_Static_assert(offsetof(__wasi_subscription_t, u) == 8, "witx calculated offset"); - -/* keep syncing with wasi_socket_ext.h */ -typedef enum { - SOCKET_DGRAM = 0, - SOCKET_STREAM, -} __wasi_sock_type_t; - -typedef uint16_t __wasi_ip_port_t; - -typedef enum { IPv4 = 0, IPv6 } __wasi_addr_type_t; - -/* n0.n1.n2.n3 */ -typedef struct __wasi_addr_ip4_t { - uint8_t n0; - uint8_t n1; - uint8_t n2; - uint8_t n3; -} __wasi_addr_ip4_t; - -typedef struct __wasi_addr_ip4_port_t { - __wasi_addr_ip4_t addr; - __wasi_ip_port_t port; -} __wasi_addr_ip4_port_t; - -typedef struct __wasi_addr_ip6_t { - uint16_t n0; - uint16_t n1; - uint16_t n2; - uint16_t n3; - uint16_t h0; - uint16_t h1; - uint16_t h2; - uint16_t h3; -} __wasi_addr_ip6_t; - -typedef struct __wasi_addr_ip6_port_t { - __wasi_addr_ip6_t addr; - __wasi_ip_port_t port; -} __wasi_addr_ip6_port_t; - -typedef struct __wasi_addr_ip_t { - __wasi_addr_type_t kind; - union { - __wasi_addr_ip4_t ip4; - __wasi_addr_ip6_t ip6; - } addr; -} __wasi_addr_ip_t; - -typedef struct __wasi_addr_t { - __wasi_addr_type_t kind; - union { - __wasi_addr_ip4_port_t ip4; - __wasi_addr_ip6_port_t ip6; - } addr; -} __wasi_addr_t; - -typedef enum { INET4 = 0, INET6 } __wasi_address_family_t; - -typedef struct __wasi_addr_info_t { - __wasi_addr_t addr; - __wasi_sock_type_t type; -} __wasi_addr_info_t; - -typedef struct __wasi_addr_info_hints_t { - __wasi_sock_type_t type; - __wasi_address_family_t family; - // this is to workaround lack of optional parameters - uint8_t hints_enabled; -} __wasi_addr_info_hints_t; - -#if defined(WASMTIME_SSP_WASI_API) -#define WASMTIME_SSP_SYSCALL_NAME(name) \ - asm("__wasi_" #name) -#else -#define WASMTIME_SSP_SYSCALL_NAME(name) -#endif - -__wasi_errno_t wasmtime_ssp_args_get( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct argv_environ_values *arg_environ, -#endif - char **argv, - char *argv_buf -) WASMTIME_SSP_SYSCALL_NAME(args_get) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_args_sizes_get( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct argv_environ_values *arg_environ, -#endif - size_t *argc, - size_t *argv_buf_size -) WASMTIME_SSP_SYSCALL_NAME(args_sizes_get) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_clock_res_get( - __wasi_clockid_t clock_id, - __wasi_timestamp_t *resolution -) WASMTIME_SSP_SYSCALL_NAME(clock_res_get) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_clock_time_get( - __wasi_clockid_t clock_id, - __wasi_timestamp_t precision, - __wasi_timestamp_t *time -) WASMTIME_SSP_SYSCALL_NAME(clock_time_get) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_environ_get( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct argv_environ_values *arg_environ, -#endif - char **environ, - char *environ_buf -) WASMTIME_SSP_SYSCALL_NAME(environ_get) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_environ_sizes_get( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct argv_environ_values *arg_environ, -#endif - size_t *environ_count, - size_t *environ_buf_size -) WASMTIME_SSP_SYSCALL_NAME(environ_sizes_get) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_prestat_get( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_prestats *prestats, -#endif - __wasi_fd_t fd, - __wasi_prestat_t *buf -) WASMTIME_SSP_SYSCALL_NAME(fd_prestat_get) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_prestat_dir_name( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_prestats *prestats, -#endif - __wasi_fd_t fd, - char *path, - size_t path_len -) WASMTIME_SSP_SYSCALL_NAME(fd_prestat_dir_name) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_close( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, - struct fd_prestats *prestats, -#endif - __wasi_fd_t fd -) WASMTIME_SSP_SYSCALL_NAME(fd_close) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_datasync( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd -) WASMTIME_SSP_SYSCALL_NAME(fd_datasync) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_pread( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - const __wasi_iovec_t *iovs, - size_t iovs_len, - __wasi_filesize_t offset, - size_t *nread -) WASMTIME_SSP_SYSCALL_NAME(fd_pread) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_pwrite( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - const __wasi_ciovec_t *iovs, - size_t iovs_len, - __wasi_filesize_t offset, - size_t *nwritten -) WASMTIME_SSP_SYSCALL_NAME(fd_pwrite) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_read( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - const __wasi_iovec_t *iovs, - size_t iovs_len, - size_t *nread -) WASMTIME_SSP_SYSCALL_NAME(fd_read) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_renumber( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, - struct fd_prestats *prestats, -#endif - __wasi_fd_t from, - __wasi_fd_t to -) WASMTIME_SSP_SYSCALL_NAME(fd_renumber) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_seek( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - __wasi_filedelta_t offset, - __wasi_whence_t whence, - __wasi_filesize_t *newoffset -) WASMTIME_SSP_SYSCALL_NAME(fd_seek) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_tell( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - __wasi_filesize_t *newoffset -) WASMTIME_SSP_SYSCALL_NAME(fd_tell) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_fdstat_get( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - __wasi_fdstat_t *buf -) WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_get) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_fdstat_set_flags( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - __wasi_fdflags_t flags -) WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_set_flags) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_fdstat_set_rights( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - __wasi_rights_t fs_rights_base, - __wasi_rights_t fs_rights_inheriting -) WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_set_rights) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_sync( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd -) WASMTIME_SSP_SYSCALL_NAME(fd_sync) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_write( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - const __wasi_ciovec_t *iovs, - size_t iovs_len, - size_t *nwritten -) WASMTIME_SSP_SYSCALL_NAME(fd_write) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_advise( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - __wasi_filesize_t offset, - __wasi_filesize_t len, - __wasi_advice_t advice -) WASMTIME_SSP_SYSCALL_NAME(fd_advise) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_allocate( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - __wasi_filesize_t offset, - __wasi_filesize_t len -) WASMTIME_SSP_SYSCALL_NAME(fd_allocate) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_path_create_directory( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - const char *path, - size_t path_len -) WASMTIME_SSP_SYSCALL_NAME(path_create_directory) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_path_link( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, - struct fd_prestats *prestats, -#endif - __wasi_fd_t old_fd, - __wasi_lookupflags_t old_flags, - const char *old_path, - size_t old_path_len, - __wasi_fd_t new_fd, - const char *new_path, - size_t new_path_len -) WASMTIME_SSP_SYSCALL_NAME(path_link) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_path_open( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t dirfd, - __wasi_lookupflags_t dirflags, - const char *path, - size_t path_len, - __wasi_oflags_t oflags, - __wasi_rights_t fs_rights_base, - __wasi_rights_t fs_rights_inheriting, - __wasi_fdflags_t fs_flags, - __wasi_fd_t *fd -) WASMTIME_SSP_SYSCALL_NAME(path_open) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_readdir( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - void *buf, - size_t buf_len, - __wasi_dircookie_t cookie, - size_t *bufused -) WASMTIME_SSP_SYSCALL_NAME(fd_readdir) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_path_readlink( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - const char *path, - size_t path_len, - char *buf, - size_t buf_len, - size_t *bufused -) WASMTIME_SSP_SYSCALL_NAME(path_readlink) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_path_rename( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t old_fd, - const char *old_path, - size_t old_path_len, - __wasi_fd_t new_fd, - const char *new_path, - size_t new_path_len -) WASMTIME_SSP_SYSCALL_NAME(path_rename) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_filestat_get( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - __wasi_filestat_t *buf -) WASMTIME_SSP_SYSCALL_NAME(fd_filestat_get) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_filestat_set_times( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - __wasi_timestamp_t st_atim, - __wasi_timestamp_t st_mtim, - __wasi_fstflags_t fstflags -) WASMTIME_SSP_SYSCALL_NAME(fd_filestat_set_times) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_fd_filestat_set_size( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - __wasi_filesize_t st_size -) WASMTIME_SSP_SYSCALL_NAME(fd_filestat_set_size) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_path_filestat_get( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - __wasi_lookupflags_t flags, - const char *path, - size_t path_len, - __wasi_filestat_t *buf -) WASMTIME_SSP_SYSCALL_NAME(path_filestat_get) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_path_filestat_set_times( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - __wasi_lookupflags_t flags, - const char *path, - size_t path_len, - __wasi_timestamp_t st_atim, - __wasi_timestamp_t st_mtim, - __wasi_fstflags_t fstflags -) WASMTIME_SSP_SYSCALL_NAME(path_filestat_set_times) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_path_symlink( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, - struct fd_prestats *prestats, -#endif - const char *old_path, - size_t old_path_len, - __wasi_fd_t fd, - const char *new_path, - size_t new_path_len -) WASMTIME_SSP_SYSCALL_NAME(path_symlink) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_path_unlink_file( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - const char *path, - size_t path_len -) WASMTIME_SSP_SYSCALL_NAME(path_unlink_file) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_path_remove_directory( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, - const char *path, - size_t path_len -) WASMTIME_SSP_SYSCALL_NAME(path_remove_directory) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_poll_oneoff( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - const __wasi_subscription_t *in, - __wasi_event_t *out, - size_t nsubscriptions, - size_t *nevents -) WASMTIME_SSP_SYSCALL_NAME(poll_oneoff) __attribute__((__warn_unused_result__)); - -#if 0 -/** - * We throw exception in libc-wasi wrapper function wasi_proc_exit() - * but not call this function. - */ -_Noreturn void wasmtime_ssp_proc_exit( - __wasi_exitcode_t rval -) WASMTIME_SSP_SYSCALL_NAME(proc_exit); -#endif - -__wasi_errno_t wasmtime_ssp_proc_raise( - __wasi_signal_t sig -) WASMTIME_SSP_SYSCALL_NAME(proc_raise) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_random_get( - void *buf, - size_t buf_len -) WASMTIME_SSP_SYSCALL_NAME(random_get) __attribute__((__warn_unused_result__)); - -__wasi_errno_t -wasi_ssp_sock_accept( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_fdflags_t flags, __wasi_fd_t *fd_new -) __attribute__((__warn_unused_result__)); - -__wasi_errno_t -wasi_ssp_sock_addr_local( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_addr_t *addr -) __attribute__((__warn_unused_result__)); - -__wasi_errno_t -wasi_ssp_sock_addr_remote( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_addr_t *addr -) __attribute__((__warn_unused_result__)); - -__wasi_errno_t -wasi_ssp_sock_open( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t poolfd, __wasi_address_family_t af, __wasi_sock_type_t socktype, - __wasi_fd_t *sockfd -) __attribute__((__warn_unused_result__)); - -__wasi_errno_t -wasi_ssp_sock_bind( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, struct addr_pool *addr_pool, -#endif - __wasi_fd_t fd, __wasi_addr_t *addr -) __attribute__((__warn_unused_result__)); - -__wasi_errno_t -wasi_ssp_sock_addr_resolve( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, char **ns_lookup_list, -#endif - const char *host, const char* service, - __wasi_addr_info_hints_t *hints, __wasi_addr_info_t *addr_info, - __wasi_size_t addr_info_size, __wasi_size_t *max_info_size -) __attribute__((__warn_unused_result__)); - -__wasi_errno_t -wasi_ssp_sock_connect( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, struct addr_pool *addr_pool, -#endif - __wasi_fd_t fd, __wasi_addr_t *addr -) __attribute__((__warn_unused_result__)); - -__wasi_errno_t -wasi_ssp_sock_get_recv_buf_size( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_size_t *size -) __attribute__((__warn_unused_result__)); - -__wasi_errno_t -wasi_ssp_sock_get_reuse_addr( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, uint8_t *reuse -) __attribute__((__warn_unused_result__)); - -__wasi_errno_t -wasi_ssp_sock_get_reuse_port( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, uint8_t *reuse -) __attribute__((__warn_unused_result__)); - -__wasi_errno_t -wasi_ssp_sock_get_send_buf_size( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_size_t *size -) __attribute__((__warn_unused_result__)); - -__wasi_errno_t -wasi_ssp_sock_set_recv_buf_size( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_size_t size -) __attribute__((__warn_unused_result__)); - -__wasi_errno_t -wasi_ssp_sock_set_reuse_addr( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, uint8_t reuse -) __attribute__((__warn_unused_result__)); - -__wasi_errno_t -wasi_ssp_sock_set_reuse_port( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, uint8_t reuse -) __attribute__((__warn_unused_result__)); - -__wasi_errno_t -wasi_ssp_sock_set_send_buf_size( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_size_t size -) __attribute__((__warn_unused_result__)); - -__wasi_errno_t -wasi_ssp_sock_listen( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_size_t backlog -) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_recv( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - void *buf, - size_t buf_len, - size_t *recv_len -) WASMTIME_SSP_SYSCALL_NAME(sock_recv) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_recv_from( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - void *buf, - size_t buf_len, - __wasi_riflags_t ri_flags, - __wasi_addr_t *src_addr, - size_t *recv_len -) WASMTIME_SSP_SYSCALL_NAME(sock_recv_from) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_send( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - const void *buf, - size_t buf_len, - size_t *sent_len -) WASMTIME_SSP_SYSCALL_NAME(sock_send) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_send_to( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, struct addr_pool *addr_pool, -#endif - __wasi_fd_t sock, - const void *buf, - size_t buf_len, - __wasi_siflags_t si_flags, - const __wasi_addr_t *dest_addr, - size_t *sent_len -) WASMTIME_SSP_SYSCALL_NAME(sock_send_to) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_shutdown( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock -) WASMTIME_SSP_SYSCALL_NAME(sock_shutdown) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_recv_timeout( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - uint64_t timeout_us -) WASMTIME_SSP_SYSCALL_NAME(sock_set_recv_timeout) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_get_recv_timeout( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - uint64_t *timeout_us -) WASMTIME_SSP_SYSCALL_NAME(sock_get_recv_timeout) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_send_timeout( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - uint64_t timeout_us -) WASMTIME_SSP_SYSCALL_NAME(sock_set_send_timeout) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_get_send_timeout( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - uint64_t *timeout_us -) WASMTIME_SSP_SYSCALL_NAME(sock_get_send_timeout) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_send_buf_size( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - size_t bufsiz -) WASMTIME_SSP_SYSCALL_NAME(sock_set_send_buf_size) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_get_send_buf_size( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - size_t *bufsiz -) WASMTIME_SSP_SYSCALL_NAME(sock_get_send_buf_size) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_recv_buf_size( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - size_t bufsiz -) WASMTIME_SSP_SYSCALL_NAME(sock_set_recv_buf_size) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_get_recv_buf_size( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - size_t *bufsiz -) WASMTIME_SSP_SYSCALL_NAME(sock_get_recv_buf_size) __attribute__((__warn_unused_result__)); - - -__wasi_errno_t wasmtime_ssp_sock_set_keep_alive( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool is_enabled -) WASMTIME_SSP_SYSCALL_NAME(sock_set_keep_alive) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_get_keep_alive( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool *is_enabled -) WASMTIME_SSP_SYSCALL_NAME(sock_get_keep_alive) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_reuse_addr( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool is_enabled -) WASMTIME_SSP_SYSCALL_NAME(sock_set_reuse_addr) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_get_reuse_addr( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool *is_enabled -) WASMTIME_SSP_SYSCALL_NAME(sock_get_reuse_addr) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_reuse_port( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool is_enabled -) WASMTIME_SSP_SYSCALL_NAME(sock_set_reuse_port) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_get_reuse_port( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool *is_enabled -) WASMTIME_SSP_SYSCALL_NAME(sock_get_reuse_port) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_linger( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool is_enabled, - int linger_s -) WASMTIME_SSP_SYSCALL_NAME(sock_set_linger) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_get_linger( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, bool *is_enabled, int *linger_s -) WASMTIME_SSP_SYSCALL_NAME(sock_get_linger) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_broadcast( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool is_enabled -) WASMTIME_SSP_SYSCALL_NAME(sock_set_broadcast) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_get_broadcast( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool *is_enabled -) WASMTIME_SSP_SYSCALL_NAME(sock_get_broadcast) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_tcp_no_delay( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool is_enabled -) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_no_delay) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_get_tcp_no_delay( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool *is_enabled -) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_no_delay) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_tcp_quick_ack( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool is_enabled -) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_quick_ack) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_get_tcp_quick_ack( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool *is_enabled -) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_quick_ack) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_tcp_keep_idle( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - uint32_t time_s -) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_keep_idle) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_get_tcp_keep_idle( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - uint32_t *time_s -) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_keep_idle) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_tcp_keep_intvl( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - uint32_t time_s -) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_keep_intvl) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_get_tcp_keep_intvl( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - uint32_t *time_s -) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_keep_intvl) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_tcp_fastopen_connect( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool is_enabled -) WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_fastopen_connect) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_get_tcp_fastopen_connect( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool *is_enabled -) WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_fastopen_connect) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_ip_multicast_loop( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool ipv6, - bool is_enabled -) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_multicast_loop) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_get_ip_multicast_loop( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool ipv6, - bool *is_enabled -) WASMTIME_SSP_SYSCALL_NAME(sock_get_ip_multicast_loop) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_ip_add_membership( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - __wasi_addr_ip_t *imr_multiaddr, - uint32_t imr_interface -) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_add_membership) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_ip_drop_membership( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - __wasi_addr_ip_t *imr_multiaddr, - uint32_t imr_interface -) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_drop_membership) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_ip_ttl( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - uint8_t ttl_s -) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_ttl) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_get_ip_ttl( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - uint8_t *ttl_s -) WASMTIME_SSP_SYSCALL_NAME(sock_get_ip_ttl) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_ip_multicast_ttl( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - uint8_t ttl_s -) WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_multicast_ttl) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_get_ip_multicast_ttl( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - uint8_t *ttl_s -) WASMTIME_SSP_SYSCALL_NAME(sock_get_ip_multicast_ttl) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_set_ipv6_only( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool is_enabled -) WASMTIME_SSP_SYSCALL_NAME(sock_set_ipv6_only) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sock_get_ipv6_only( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, - bool *is_enabled -) WASMTIME_SSP_SYSCALL_NAME(sock_get_ipv6_only) __attribute__((__warn_unused_result__)); - -__wasi_errno_t wasmtime_ssp_sched_yield(void) - WASMTIME_SSP_SYSCALL_NAME(sched_yield) __attribute__((__warn_unused_result__)); - -#ifdef __cplusplus -} -#endif - -#undef WASMTIME_SSP_SYSCALL_NAME - -/* clang-format on */ - -#endif /* end of WASMTIME_SSP_H */ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake deleted file mode 100644 index bbeac3b148b..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - - -find_library(TENSORFLOW_LITE - NAMES tensorflow-lite -) - -if(NOT EXISTS ${TENSORFLOW_LITE}) - if (NOT EXISTS "${WAMR_ROOT_DIR}/core/deps/tensorflow-src") - execute_process(COMMAND ${WAMR_ROOT_DIR}/core/deps/install_tensorflow.sh - RESULT_VARIABLE TENSORFLOW_RESULT - ) - else () - message("Tensorflow is already downloaded.") - endif() - set(TENSORFLOW_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/tensorflow-src") - - if (WASI_NN_ENABLE_GPU EQUAL 1) - # Tensorflow specific: - # * https://www.tensorflow.org/lite/guide/build_cmake#available_options_to_build_tensorflow_lite - set (TFLITE_ENABLE_GPU ON) - endif () - - include_directories (${CMAKE_CURRENT_BINARY_DIR}/flatbuffers/include) - include_directories (${TENSORFLOW_SOURCE_DIR}) - add_subdirectory( - "${TENSORFLOW_SOURCE_DIR}/tensorflow/lite" - "${CMAKE_CURRENT_BINARY_DIR}/tensorflow-lite" EXCLUDE_FROM_ALL) - -else() - find_path(TENSORFLOW_LITE_INCLUDE_DIR - NAMES tensorflow/lite/interpreter.h - ) - find_path(FLATBUFFER_INCLUDE_DIR - NAMES flatbuffers/flatbuffers.h - ) - include_directories (${TENSORFLOW_LITE_INCLUDE_DIR}) - include_directories (${FLATBUFFER_INCLUDE_DIR}) -endif() - diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/wasi_nn.cmake b/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/wasi_nn.cmake deleted file mode 100644 index 019782c2e42..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/wasi_nn.cmake +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) - -# Find tensorflow-lite -find_package(tensorflow_lite REQUIRED) - -set (WASI_NN_DIR ${CMAKE_CURRENT_LIST_DIR}) - -include_directories (${WASI_NN_DIR}) -include_directories (${WASI_NN_DIR}/src) -include_directories (${WASI_NN_DIR}/src/utils) - -set ( - LIBC_WASI_NN_SOURCE - ${WASI_NN_DIR}/src/wasi_nn.c - ${WASI_NN_DIR}/src/wasi_nn_tensorflowlite.cpp - ${WASI_NN_DIR}/src/utils/wasi_nn_app_native.c -) - -set (TENSORFLOW_LIB tensorflow-lite) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/platform_api_posix.cmake b/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/platform_api_posix.cmake deleted file mode 100644 index 4abefff1ea8..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/platform_api_posix.cmake +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -set (PLATFORM_COMMON_POSIX_DIR ${CMAKE_CURRENT_LIST_DIR}) - -file (GLOB_RECURSE source_all ${PLATFORM_COMMON_POSIX_DIR}/*.c) - -set (PLATFORM_COMMON_POSIX_SOURCE ${source_all} ) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_memmap.c b/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_memmap.c deleted file mode 100644 index 693094a6344..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_memmap.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#include "platform_api_vmcore.h" -#include "platform_api_extension.h" - -void * -os_mmap(void *hint, size_t size, int prot, int flags) -{ - if (prot & MMAP_PROT_EXEC) { - // Memory allocation with MALLOC_CAP_EXEC will return 4-byte aligned - // Reserve extra 4 byte to fixup alignment and size for the pointer to - // the originally allocated address - void *buf_origin = - heap_caps_malloc(size + 4 + sizeof(uintptr_t), MALLOC_CAP_EXEC); - if (!buf_origin) { - return NULL; - } - void *buf_fixed = buf_origin + sizeof(void *); - if ((uintptr_t)buf_fixed & (uintptr_t)0x7) { - buf_fixed = (void *)((uintptr_t)(buf_fixed + 4) & (~(uintptr_t)7)); - } - - uintptr_t *addr_field = buf_fixed - sizeof(uintptr_t); - *addr_field = (uintptr_t)buf_origin; - return buf_fixed; - } - else { - return os_malloc(size); - } -} - -void -os_munmap(void *addr, size_t size) -{ - // We don't need special handling of the executable allocations - // here, free() of esp-idf handles it properly - return os_free(addr); -} - -int -os_mprotect(void *addr, size_t size, int prot) -{ - return 0; -} - -void -os_dcache_flush() -{} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/xip.md b/lib/wasm-micro-runtime-WAMR-1.2.2/doc/xip.md deleted file mode 100644 index d6c5a370124..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/xip.md +++ /dev/null @@ -1,14 +0,0 @@ -# WAMR XIP (Execution In Place) feature introduction - -Some IoT devices may require to run the AOT file from flash or ROM which is read-only, so as to reduce the memory consumption, or resolve the issue that there is no executable memory available to run AOT code. In such case, the AOT code inside the AOT file shouldn't be duplicated into memory and shouldn't be modified (or patched) by the AOT relocations. To address this, WAMR implements the XIP (Execution In Place) feature, which generates the AOT relocations as few as possible: -- In the AOT code, an AOT function calls other functions with indirect mode: it doesn't call other functions directly, but looks up their pointers from the function pointer table passed by its first argument exec_env, and then calls the function pointer found. By this way the relocations to other functions are eliminated. -- Eliminate the calls to the LLVM intrinsic functions, or, replace calling them with calling runtime self implemented functions instead, e.g. the calling to `llvm.experimental.constrained.fadd.f32` is replaced by the calling to `aot_intrinsic_fadd_f32`. - -The XIP file is an AOT file without (or with few) relocations to patch the AOT code (or text section). Developer can use the option `--enable-indirect-mode --disable-llvm-intrinsics` for wamrc to generate the AOT file, e.g.: -```bash -wamrc --enable-indirect-mode --disable-llvm-intrinsics -o -``` - -## Known issues - -There may be some relocations to the ".rodata" like sections which require to patch the AOT code. More work will be done to resolve it in the future. diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/go.mod b/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/go.mod deleted file mode 100644 index 60afebbff6e..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module gitlab.alipay-inc.com/TNT_Runtime/ant-runtime/bindings/go - -go 1.15 - -require github.com/stretchr/testify v1.7.0 diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/samples/build.sh b/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/samples/build.sh deleted file mode 100755 index 1b0a80719c1..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/samples/build.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -PLATFORM=$(uname -s | tr A-Z a-z) -CUR_DIR=$PWD -WAMR_DIR=$PWD/../../.. -WAMR_GO_DIR=$PWD/../wamr - -cp -a ${WAMR_DIR}/core/iwasm/include/*.h ${WAMR_GO_DIR}/packaged/include - -mkdir -p build && cd build -cmake ${WAMR_DIR}/product-mini/platforms/${PLATFORM} \ - -DWAMR_BUILD_LIB_PTHREAD=1 -DWAMR_BUILD_DUMP_CALL_STACK=1 \ - -DWAMR_BUILD_MEMORY_PROFILING=1 -make -j ${nproc} -cp -a libvmlib.a ${WAMR_GO_DIR}/packaged/lib/${PLATFORM}-amd64 - -cd ${CUR_DIR} -rm -f test -go build test.go -./test diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/README_docker.md b/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/README_docker.md deleted file mode 100644 index e02398b0b44..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/README_docker.md +++ /dev/null @@ -1,25 +0,0 @@ -# Build with Docker - -To have a quicker start, a Docker container of the Zephyr setup can be generated. - -## Build Docker container - -``` Bash -docker build --build-arg DOCKER_UID=$(id -u) . -t wamr-zephyr -``` - -## Run Docker container to build images - -Enter the docker container (maps the toplevel wasm-micro-runtime repo as volume): - -``` Bash -docker run -ti -v $PWD/../../../..:/home/wamr/source --device=/dev/ttyUSB0 wamr-zephyr -``` - -Adopt the device or remove if not needed. - -And then in the docker container: - -``` Bash -./build_and_run.sh esp32c3 -``` \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/esp32.conf b/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/esp32.conf deleted file mode 100644 index 5d6a67f9da2..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/esp32.conf +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -CONFIG_STACK_SENTINEL=y -CONFIG_PRINTK=y -CONFIG_LOG=y -CONFIG_HAVE_CUSTOM_LINKER_SCRIPT=y -CONFIG_CUSTOM_LINKER_SCRIPT="esp32_custom_linker.ld" diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_riscv32.conf b/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_riscv32.conf deleted file mode 100644 index f3705504b5a..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_riscv32.conf +++ /dev/null @@ -1,6 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -CONFIG_STACK_SENTINEL=y -CONFIG_PRINTK=y -CONFIG_LOG=n diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_riscv64.conf b/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_riscv64.conf deleted file mode 100644 index f3705504b5a..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_riscv64.conf +++ /dev/null @@ -1,6 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -CONFIG_STACK_SENTINEL=y -CONFIG_PRINTK=y -CONFIG_LOG=n diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_x86_nommu.conf b/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_x86_nommu.conf deleted file mode 100644 index 7f4a3283220..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_x86_nommu.conf +++ /dev/null @@ -1,6 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -CONFIG_STACK_SENTINEL=y -CONFIG_PRINTK=y -CONFIG_LOG=y diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_xtensa.conf b/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_xtensa.conf deleted file mode 100644 index 7f4a3283220..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_xtensa.conf +++ /dev/null @@ -1,6 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -CONFIG_STACK_SENTINEL=y -CONFIG_PRINTK=y -CONFIG_LOG=y diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/esp32_custom_linker.ld b/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/esp32_custom_linker.ld deleted file mode 100644 index 35932050fc9..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/esp32_custom_linker.ld +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright (c) 2016 Cadence Design Systems, Inc. - * Copyright (c) 2017 Intel Corporation - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @file - * @brief Linker command/script file - * - * Linker script for the Xtensa platform. - */ - -#include -#include -#include -#include -#include - -#define RAMABLE_REGION dram0_0_seg :dram0_0_phdr -#define RAMABLE_REGION1 dram0_1_seg :dram0_0_phdr -#define ROMABLE_REGION iram0_0_seg :iram0_0_phdr - -PROVIDE ( __stack = 0x3ffe3f20 ); - -PROVIDE ( esp32_rom_uart_tx_one_char = 0x40009200 ); -PROVIDE ( esp32_rom_uart_rx_one_char = 0x400092d0 ); -PROVIDE ( esp32_rom_uart_attach = 0x40008fd0 ); -PROVIDE ( esp32_rom_intr_matrix_set = 0x4000681c ); -PROVIDE ( esp32_rom_gpio_matrix_in = 0x40009edc ); -PROVIDE ( esp32_rom_gpio_matrix_out = 0x40009f0c ); -PROVIDE ( esp32_rom_Cache_Flush = 0x40009a14 ); -PROVIDE ( esp32_rom_Cache_Read_Enable = 0x40009a84 ); -PROVIDE ( esp32_rom_ets_set_appcpu_boot_addr = 0x4000689c ); - -MEMORY -{ - iram0_0_seg(RX): org = 0x40080000, len = 0x20000 - iram0_2_seg(RX): org = 0x400D0018, len = 0x330000 - dram0_0_seg(RW): org = 0x3FFB0000, len = 0x30000 - dram0_1_seg(RWX):org = 0x400A0000, len = 0x20000 - drom0_0_seg(R): org = 0x3F400010, len = 0x800000 - rtc_iram_seg(RWX): org = 0x400C0000, len = 0x2000 - rtc_slow_seg(RW): org = 0x50000000, len = 0x1000 -#ifdef CONFIG_GEN_ISR_TABLES - IDT_LIST(RW): org = 0x3ebfe010, len = 0x2000 -#endif -} - -PHDRS -{ - iram0_0_phdr PT_LOAD; - dram0_0_phdr PT_LOAD; -} - -/* Default entry point: */ -PROVIDE ( _ResetVector = 0x40000400 ); -ENTRY(CONFIG_KERNEL_ENTRY) - -_rom_store_table = 0; - -PROVIDE(_memmap_vecbase_reset = 0x40000450); -PROVIDE(_memmap_reset_vector = 0x40000400); - -SECTIONS -{ - -#include - - /* RTC fast memory holds RTC wake stub code, - including from any source file named rtc_wake_stub*.c - */ - .rtc.text : - { - . = ALIGN(4); - *(.rtc.literal .rtc.text) - *rtc_wake_stub*.o(.literal .text .literal.* .text.*) - } >rtc_iram_seg - - /* RTC slow memory holds RTC wake stub - data/rodata, including from any source file - named rtc_wake_stub*.c - */ - .rtc.data : - { - _rtc_data_start = ABSOLUTE(.); - *(.rtc.data) - *(.rtc.rodata) - *rtc_wake_stub*.o(.data .rodata .data.* .rodata.* .bss .bss.*) - _rtc_data_end = ABSOLUTE(.); - } > rtc_slow_seg - - /* RTC bss, from any source file named rtc_wake_stub*.c */ - .rtc.bss (NOLOAD) : - { - _rtc_bss_start = ABSOLUTE(.); - *rtc_wake_stub*.o(.bss .bss.*) - *rtc_wake_stub*.o(COMMON) - _rtc_bss_end = ABSOLUTE(.); - } > rtc_slow_seg - - /* Send .iram0 code to iram */ - .iram0.vectors : ALIGN(4) - { - /* Vectors go to IRAM */ - _init_start = ABSOLUTE(.); - /* Vectors according to builds/RF-2015.2-win32/esp108_v1_2_s5_512int_2/config.html */ - . = 0x0; - KEEP(*(.WindowVectors.text)); - . = 0x180; - KEEP(*(.Level2InterruptVector.text)); - . = 0x1c0; - KEEP(*(.Level3InterruptVector.text)); - . = 0x200; - KEEP(*(.Level4InterruptVector.text)); - . = 0x240; - KEEP(*(.Level5InterruptVector.text)); - . = 0x280; - KEEP(*(.DebugExceptionVector.text)); - . = 0x2c0; - KEEP(*(.NMIExceptionVector.text)); - . = 0x300; - KEEP(*(.KernelExceptionVector.text)); - . = 0x340; - KEEP(*(.UserExceptionVector.text)); - . = 0x3C0; - KEEP(*(.DoubleExceptionVector.text)); - . = 0x400; - *(.*Vector.literal) - - *(.UserEnter.literal); - *(.UserEnter.text); - . = ALIGN (16); - *(.entry.text) - *(.init.literal) - *(.init) - _init_end = ABSOLUTE(.); - - /* This goes here, not at top of linker script, so addr2line finds it last, - and uses it in preference to the first symbol in IRAM */ - _iram_start = ABSOLUTE(0); - } GROUP_LINK_IN(ROMABLE_REGION) - -#include -#include - - SECTION_PROLOGUE(_TEXT_SECTION_NAME, , ALIGN(4)) - { - /* Code marked as running out of IRAM */ - _iram_text_start = ABSOLUTE(.); - *(.iram1 .iram1.*) - *(.iram0.literal .iram.literal .iram.text.literal .iram0.text .iram.text) - *(.literal .text .literal.* .text.*) - _iram_text_end = ABSOLUTE(.); - } GROUP_LINK_IN(ROMABLE_REGION) - - .dram0.text : - { - _data_start = ABSOLUTE(.); - *(.aot_code_buf) - _data_end = ABSOLUTE(.); - . = ALIGN(4); - } GROUP_LINK_IN(RAMABLE_REGION1) - - - .dram0.data : - { - _data_start = ABSOLUTE(.); - *(.data) - *(.data.*) - *(.gnu.linkonce.d.*) - *(.data1) - *(.sdata) - *(.sdata.*) - *(.gnu.linkonce.s.*) - *(.sdata2) - *(.sdata2.*) - *(.gnu.linkonce.s2.*) - KEEP(*(.jcr)) - *(.dram1 .dram1.*) - _data_end = ABSOLUTE(.); - . = ALIGN(4); - } GROUP_LINK_IN(RAMABLE_REGION) - - SECTION_PROLOGUE(_RODATA_SECTION_NAME,,ALIGN(4)) - { - _rodata_start = ABSOLUTE(.); - *(.rodata) - *(.rodata.*) - *(.gnu.linkonce.r.*) - *(.rodata1) - __XT_EXCEPTION_TABLE__ = ABSOLUTE(.); - KEEP (*(.xt_except_table)) - KEEP (*(.gcc_except_table .gcc_except_table.*)) - *(.gnu.linkonce.e.*) - *(.gnu.version_r) - KEEP (*(.eh_frame)) - /* C++ constructor and destructor tables, properly ordered: */ - KEEP (*crtbegin.o(.ctors)) - KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) - KEEP (*(SORT(.ctors.*))) - KEEP (*(.ctors)) - KEEP (*crtbegin.o(.dtors)) - KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) - KEEP (*(SORT(.dtors.*))) - KEEP (*(.dtors)) - /* C++ exception handlers table: */ - __XT_EXCEPTION_DESCS__ = ABSOLUTE(.); - *(.xt_except_desc) - *(.gnu.linkonce.h.*) - __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); - *(.xt_except_desc_end) - *(.dynamic) - *(.gnu.version_d) - . = ALIGN(4); /* this table MUST be 4-byte aligned */ - _rodata_end = ABSOLUTE(.); - } GROUP_LINK_IN(RAMABLE_REGION) - - - /* Shared RAM */ - SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),) - { - . = ALIGN (8); - _bss_start = ABSOLUTE(.); - *(.dynsbss) - *(.sbss) - *(.sbss.*) - *(.gnu.linkonce.sb.*) - *(.scommon) - *(.sbss2) - *(.sbss2.*) - *(.gnu.linkonce.sb2.*) - *(.dynbss) - *(.bss) - *(.bss.*) - *(.share.mem) - *(.gnu.linkonce.b.*) - *(COMMON) - . = ALIGN (8); - _bss_end = ABSOLUTE(.); - } GROUP_LINK_IN(RAMABLE_REGION) - - - SECTION_DATA_PROLOGUE(_APP_NOINIT_SECTION_NAME, (NOLOAD),) - { - . = ALIGN (8); - *(.app_noinit) - *("app_noinit.*") - . = ALIGN (8); - _app_end = ABSOLUTE(.); - } GROUP_LINK_IN(RAMABLE_REGION) - - - SECTION_DATA_PROLOGUE(_NOINIT_SECTION_NAME, (NOLOAD),) - { - . = ALIGN (8); - *(.noinit) - *(".noinit.*") - . = ALIGN (8); - _heap_start = ABSOLUTE(.); - } GROUP_LINK_IN(RAMABLE_REGION) - -#ifdef CONFIG_GEN_ISR_TABLES -#include -#endif - -#include - - SECTION_PROLOGUE(.xtensa.info, 0,) - { - *(.xtensa.info) - } - -} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/CMakeLists.txt deleted file mode 100644 index aef138d5e85..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/CMakeLists.txt +++ /dev/null @@ -1,147 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -cmake_minimum_required (VERSION 3.0) - -project(xnnpack_wasm) - -################ EMCC ################ -include(ExternalProject) - -ExternalProject_Add(xnnpack - PREFIX xnnpack - GIT_REPOSITORY https://github.com/google/XNNPACK.git - GIT_TAG 4570a7151aa4f3e57eca14a575eeff6bb13e26be - GIT_PROGRESS ON - SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack - UPDATE_COMMAND git restore . - && cmake -E copy ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack/google3/third_party/XNNPACK/microkernels.bzl - ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack/ - && git apply ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack.patch - CONFIGURE_COMMAND "" - # grep xnnpack_benchmark -A 1 BUILD.bazel \ - # | grep "name =" \ - # | awk '{print $3}' \ - # | sed -e 's/\"//g' -e 's/,//g' -e 's/^/\/\/:/g' - BUILD_COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack - && bazel --output_user_root=build-user-output build -c opt --config=wasm - //:qs8_dwconv_bench.wasm - //:qs8_f32_vcvt_bench.wasm - //:qs8_gemm_bench.wasm - //:qs8_requantization_bench.wasm - //:qs8_vadd_bench.wasm - //:qs8_vaddc_bench.wasm - //:qs8_vcvt_bench.wasm - //:qs8_vlrelu_bench.wasm - //:qs8_vmul_bench.wasm - //:qs8_vmulc_bench.wasm - //:qu8_f32_vcvt_bench.wasm - //:qu8_gemm_bench.wasm - //:qu8_requantization_bench.wasm - //:qu8_vadd_bench.wasm - //:qu8_vaddc_bench.wasm - //:qu8_vcvt_bench.wasm - //:qu8_vlrelu_bench.wasm - //:qu8_vmul_bench.wasm - //:qu8_vmulc_bench.wasm - //:bf16_gemm_bench.wasm - //:f16_igemm_bench.wasm - //:f16_gemm_bench.wasm - //:f16_raddstoreexpminusmax_bench.wasm - //:f16_spmm_bench.wasm - //:f16_vsigmoid_bench.wasm - //:f16_f32_vcvt_bench.wasm - //:f32_igemm_bench.wasm - //:f32_conv_hwc_bench.wasm - //:f16_conv_hwc2chw_bench.wasm - //:f16_gavgpool_cw_bench.wasm - //:f32_gavgpool_cw_bench.wasm - //:f32_conv_hwc2chw_bench.wasm - //:f16_dwconv_bench.wasm - //:f32_dwconv_bench.wasm - //:f32_dwconv2d_chw_bench.wasm - //:f16_dwconv2d_chw_bench.wasm - //:f32_f16_vcvt_bench.wasm - //:xx_transpose_bench.wasm - //:x8_transpose_bench.wasm - //:x16_transpose_bench.wasm - //:x24_transpose_bench.wasm - //:x32_transpose_bench.wasm - //:x64_transpose_bench.wasm - //:f32_gemm_bench.wasm - //:f32_qs8_vcvt_bench.wasm - //:f32_qu8_vcvt_bench.wasm - //:f32_raddexpminusmax_bench.wasm - //:f32_raddextexp_bench.wasm - //:f32_raddstoreexpminusmax_bench.wasm - //:f32_rmax_bench.wasm - //:f32_spmm_bench.wasm - //:f32_softmax_bench.wasm - //:f16_velu_bench.wasm - //:f32_velu_bench.wasm - //:f32_vhswish_bench.wasm - //:f32_vlrelu_bench.wasm - //:f32_vrelu_bench.wasm - //:f32_vscaleexpminusmax_bench.wasm - //:f32_vscaleextexp_bench.wasm - //:f32_vsigmoid_bench.wasm - //:f16_vsqrt_bench.wasm - //:f32_vsqrt_bench.wasm - //:f32_im2col_gemm_bench.wasm - //:rounding_bench.wasm - //:s16_rmaxabs_bench.wasm - //:s16_window_bench.wasm - //:u32_filterbank_accumulate_bench.wasm - //:u32_filterbank_subtract_bench.wasm - //:u32_vlog_bench.wasm - //:u64_u32_vsqrtshift_bench.wasm - //:i16_vlshift_bench.wasm - //:cs16_vsquareabs_bench.wasm - //:cs16_bfly4_bench.wasm - //:cs16_fftr_bench.wasm - //:x8_lut_bench.wasm - //:abs_bench.wasm - //:average_pooling_bench.wasm - //:bankers_rounding_bench.wasm - //:ceiling_bench.wasm - //:channel_shuffle_bench.wasm - //:convert_bench.wasm - //:convolution_bench.wasm - //:deconvolution_bench.wasm - //:elu_bench.wasm - //:floor_bench.wasm - //:global_average_pooling_bench.wasm - //:hardswish_bench.wasm - //:leaky_relu_bench.wasm - //:max_pooling_bench.wasm - //:negate_bench.wasm - //:sigmoid_bench.wasm - //:prelu_bench.wasm - //:softmax_bench.wasm - //:square_bench.wasm - //:square_root_bench.wasm - //:truncation_bench.wasm - //:f16_gemm_e2e_bench.wasm - //:f32_dwconv_e2e_bench.wasm - //:f32_gemm_e2e_bench.wasm - //:qs8_dwconv_e2e_bench.wasm - //:qs8_gemm_e2e_bench.wasm - //:qu8_gemm_e2e_bench.wasm - //:qu8_dwconv_e2e_bench.wasm - //:end2end_bench.wasm - //:f16_exp_ulp_eval.wasm - //:f16_expminus_ulp_eval.wasm - //:f16_expm1minus_ulp_eval.wasm - //:f16_sigmoid_ulp_eval.wasm - //:f16_sqrt_ulp_eval.wasm - //:f32_exp_ulp_eval.wasm - //:f32_expminus_ulp_eval.wasm - //:f32_expm1minus_ulp_eval.wasm - //:f32_extexp_ulp_eval.wasm - //:f32_sigmoid_ulp_eval.wasm - //:f32_sqrt_ulp_eval.wasm - //:f32_tanh_ulp_eval.wasm - INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory - ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack/bazel-out/wasm-opt/bin/ - ${CMAKE_BINARY_DIR}/wasm-opt -) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/xnnpack.patch b/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/xnnpack.patch deleted file mode 100644 index 3fb6b230be9..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/xnnpack.patch +++ /dev/null @@ -1,141 +0,0 @@ -diff --git a/.bazelrc b/.bazelrc -index 688279da1..376996885 100644 ---- a/.bazelrc -+++ b/.bazelrc -@@ -53,4 +53,9 @@ build:ios_fat --watchos_cpus=armv7k - build:macos --apple_platform_type=macos - - build:macos_arm64 --config=macos --build:macos_arm64 --cpu=darwin_arm64 -\ No newline at end of file -+build:macos_arm64 --cpu=darwin_arm64 -+ -+build:wasm --cpu=wasm -+build:wasm --features=wasm_simd -+build:wasm --crosstool_top=@emsdk//emscripten_toolchain:everything -+build:wasm --host_crosstool_top=@bazel_tools//tools/cpp:toolchain -diff --git a/WORKSPACE b/WORKSPACE -index cd8960ffa..787e03ca8 100644 ---- a/WORKSPACE -+++ b/WORKSPACE -@@ -29,8 +29,9 @@ http_archive( - # Google Benchmark library, used in micro-benchmarks. - http_archive( - name = "com_google_benchmark", -- strip_prefix = "benchmark-main", -- urls = ["https://github.com/google/benchmark/archive/main.zip"], -+ sha256 = "1ba14374fddcd9623f126b1a60945e4deac4cdc4fb25a5f25e7f779e36f2db52", -+ strip_prefix = "benchmark-d2a8a4ee41b923876c034afb939c4fc03598e622", -+ urls = ["https://github.com/google/benchmark/archive/d2a8a4ee41b923876c034afb939c4fc03598e622.zip"], - ) - - # FP16 library, used for half-precision conversions -@@ -92,8 +93,25 @@ http_archive( - ], - ) - -+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -+http_archive( -+ name = "emsdk", -+ # Use emsdk-3.0.0 since the larger version may: -+ # - compress the wasm file into a tar file but not directly generate wasm file -+ # - generate incomplete implementation of libc API, e.g. throw exception in getentropy -+ strip_prefix = "emsdk-3.0.0/bazel", -+ url = "https://github.com/emscripten-core/emsdk/archive/refs/tags/3.0.0.tar.gz", -+ sha256 = "a41dccfd15be9e85f923efaa0ac21943cbab77ec8d39e52f25eca1ec61a9ac9e" -+) -+ -+load("@emsdk//:deps.bzl", emsdk_deps = "deps") -+emsdk_deps() -+ -+load("@emsdk//:emscripten_deps.bzl", emsdk_emscripten_deps = "emscripten_deps") -+emsdk_emscripten_deps() -+ - # Android NDK location and version is auto-detected from $ANDROID_NDK_HOME environment variable --android_ndk_repository(name = "androidndk") -+#android_ndk_repository(name = "androidndk") - - # Android SDK location and API is auto-detected from $ANDROID_HOME environment variable --android_sdk_repository(name = "androidsdk") -+#android_sdk_repository(name = "androidsdk") -diff --git a/build_defs.bzl b/build_defs.bzl -index b8217a18d..6f2d1675e 100644 ---- a/build_defs.bzl -+++ b/build_defs.bzl -@@ -380,7 +380,7 @@ def xnnpack_benchmark(name, srcs, copts = [], deps = [], tags = []): - explicitly specified. - """ - native.cc_binary( -- name = name, -+ name = name + ".wasm", - srcs = srcs, - copts = xnnpack_std_cxxopts() + [ - "-Iinclude", -@@ -405,5 +405,5 @@ def xnnpack_benchmark(name, srcs, copts = [], deps = [], tags = []): - ":emscripten": xnnpack_emscripten_deps(), - "//conditions:default": [], - }), -- tags = tags, -+ tags = tags, - ) -diff --git a/emscripten.bzl b/emscripten.bzl -index f1557a7b1..7f964a094 100644 ---- a/emscripten.bzl -+++ b/emscripten.bzl -@@ -25,12 +25,19 @@ def xnnpack_emscripten_benchmark_linkopts(): - """Emscripten-specific linkopts for benchmarks.""" - return [ - "-s ASSERTIONS=1", -- "-s ENVIRONMENT=node,shell,web", -- "-s ERROR_ON_UNDEFINED_SYMBOLS=1", -- "-s EXIT_RUNTIME=1", -+ "-s ERROR_ON_UNDEFINED_SYMBOLS=0", - "-s ALLOW_MEMORY_GROWTH=1", - "-s TOTAL_MEMORY=536870912", # 512M -- "--pre-js $(location :preamble.js.lds)", -+ "-s USE_PTHREADS=0", -+ "-s STANDALONE_WASM=1", -+ "-Wno-unused", -+ "-Wno-unused-variable", -+ "-Wno-unused-command-line-argument", -+ "-Wl,--export=__heap_base", -+ "-Wl,--export=__data_end", -+ "-Wl,--export=malloc", -+ "-Wl,--export=free", -+ "--oformat=wasm", - ] - - def xnnpack_emscripten_deps(): -diff --git a/src/log.c b/src/log.c -index 5715f2f85..4b3e4261b 100644 ---- a/src/log.c -+++ b/src/log.c -@@ -55,7 +55,7 @@ - #endif - - #if XNN_LOG_TO_STDIO --static void xnn_vlog(int output_handle, const char* prefix, size_t prefix_length, const char* format, va_list args) { -+void xnn_vlog(int output_handle, const char* prefix, size_t prefix_length, const char* format, va_list args) { - char stack_buffer[XNN_LOG_STACK_BUFFER_SIZE]; - char* heap_buffer = NULL; - char* out_buffer = &stack_buffer[0]; -diff --git a/third_party/cpuinfo.BUILD b/third_party/cpuinfo.BUILD -index 1997f4e3a..5e03c43af 100644 ---- a/third_party/cpuinfo.BUILD -+++ b/third_party/cpuinfo.BUILD -@@ -150,7 +150,7 @@ cc_library( - "src/arm/midr.h", - ], - deps = [ -- "@clog", -+ "//deps/clog" - ], - ) - -@@ -352,5 +352,5 @@ config_setting( - - config_setting( - name = "emscripten", -- values = {"crosstool_top": "//toolchain:emscripten"}, -+ values = {"crosstool_top": "@emsdk//emscripten_toolchain:everything"}, - ) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.gitignore b/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.gitignore deleted file mode 100644 index 417c854d242..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -out -dist -node_modules -.vscode-test/ -*.vsix -package-lock.json -src/test \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/extensions.json b/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/extensions.json deleted file mode 100644 index b1a2d99f09e..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/extensions.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": ["dbaeumer.vscode-eslint"] -} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/launch.json b/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/launch.json deleted file mode 100644 index 4e9ccc24b5d..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/launch.json +++ /dev/null @@ -1,15 +0,0 @@ -// A launch configuration that compiles the extension and then opens it inside a new window - -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Launch Extension", - "type": "extensionHost", - "request": "launch", - "args": ["--extensionDevelopmentPath=${workspaceFolder}"], - "outFiles": ["${workspaceFolder}/out/**/*.js"], - "preLaunchTask": "${defaultBuildTask}" - } - ] -} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/tasks.json b/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/tasks.json deleted file mode 100644 index 5deb2bccd09..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscode/tasks.json +++ /dev/null @@ -1,20 +0,0 @@ -// See https://go.microsoft.com/fwlink/?LinkId=733558 -// for the documentation about the tasks.json format -{ - "version": "2.0.0", - "tasks": [ - { - "type": "npm", - "script": "watch", - "problemMatcher": "$tsc-watch", - "isBackground": true, - "presentation": { - "reveal": "never" - }, - "group": { - "kind": "build", - "isDefault": true - } - } - ] -} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscodeignore b/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscodeignore deleted file mode 100644 index b2d2b478746..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.vscodeignore +++ /dev/null @@ -1,11 +0,0 @@ -.gitignore -.yarnrc - -.vscode/** -.vscode-test/** -out/test/** - -**/tsconfig.json -**/.eslintrc.json -**/*.map -**/*.ts diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/README.md b/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/README.md deleted file mode 100644 index 403e35ae9cf..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/README.md +++ /dev/null @@ -1,15 +0,0 @@ -### If you want to enable `source debugging` for this extension and use your own patched `lldb`, please build `lldb` firstly following this [instruction](../../../../../doc/source_debugging.md#debugging-with-interpreter) - -### After building(`linux` for example), create `bin` folder and `lib` folder respectively in `linux` directory, add following necessary target files into the folders - -```shell -/llvm/build-lldb/bin/lldb # move this file to {VS Code directory}/resource/debug/linux/bin/ -/llvm/build-lldb/bin/lldb-vscode # move this file to {VS Code directory}/resource/debug/linux/bin/ -/llvm/build-lldb/lib/liblldb.so.13 # move this file to {VS Code directory}/resource/debug/linux/lib/ -``` - -> If you are debugging this extension following this [tutorial](../../README.md), {VS Code directory} will be `{WAMR root directory}/test-tools/wamr-ide/VSCode-Extension`. If you want to replace the current lldb with your own patched version so that you can use your patched lldb in VS Code, {VS Code directory} will be `~/.vscode/extensions/wamr.wamride-1.1.2` or `~/.vscode-server/extensions/wamr.wamride-1.1.2`. - -Note: For macOS, the library is named like `liblldb.13.0.1.dylib`. - -### Then you can start the extension and run the execute source debugging by clicking the `debug` button in the extension panel. diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/darwin/.placeholder b/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/darwin/.placeholder deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/linux/.placeholder b/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/linux/.placeholder deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/windows/.placeholder b/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/debug/windows/.placeholder deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/coremark/run.sh b/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/coremark/run.sh deleted file mode 100755 index a1ea7f6b75d..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/coremark/run.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -IWASM="../../../product-mini/platforms/linux/build/iwasm" -WAMRC="../../../wamr-compiler/build/wamrc" - -echo "Run coremark with native .." -./coremark.exe - -echo "Run coremark with iwasm mode .." -${IWASM} coremark.aot - -echo "Run coremakr with iwasm interpreter .." -${IWASM} coremark.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/jetstream/build.sh b/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/jetstream/build.sh deleted file mode 100755 index 030b8d3a0d0..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/jetstream/build.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash - -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -OUT_DIR=$PWD/out -WAMRC_CMD=$PWD/../../../wamr-compiler/build/wamrc - -mkdir -p jetstream -mkdir -p ${OUT_DIR} - -cd jetstream - -echo "Download source files .." -wget https://browserbench.org/JetStream/wasm/gcc-loops.cpp -wget https://browserbench.org/JetStream/wasm/quicksort.c -wget https://browserbench.org/JetStream/wasm/HashSet.cpp -wget https://browserbench.org/JetStream/simple/float-mm.c - -patch -p1 < ../jetstream.patch - -echo "Build gcc-loops with g++ .." -g++ -O3 -msse2 -msse3 -msse4 -o ${OUT_DIR}/gcc-loops_native gcc-loops.cpp - -echo "Build gcc-loops with em++ .." -em++ -O3 -s STANDALONE_WASM=1 -msimd128 \ - -s INITIAL_MEMORY=1048576 \ - -s TOTAL_STACK=32768 \ - -s "EXPORTED_FUNCTIONS=['_main']" \ - -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ - -o ${OUT_DIR}/gcc-loops.wasm gcc-loops.cpp - -echo "Compile gcc-loops.wasm to gcc-loops.aot" -${WAMRC_CMD} -o ${OUT_DIR}/gcc-loops.aot ${OUT_DIR}/gcc-loops.wasm - -echo "Build quicksort with gcc .." -gcc -O3 -msse2 -msse3 -msse4 -o ${OUT_DIR}/quicksort_native quicksort.c - -echo "Build quicksort with emcc .." -emcc -O3 -s STANDALONE_WASM=1 -msimd128 \ - -s INITIAL_MEMORY=1048576 \ - -s TOTAL_STACK=32768 \ - -s "EXPORTED_FUNCTIONS=['_main']" \ - -o ${OUT_DIR}/quicksort.wasm quicksort.c - -echo "Compile quicksort.wasm to quicksort.aot" -${WAMRC_CMD} -o ${OUT_DIR}/quicksort.aot ${OUT_DIR}/quicksort.wasm - -echo "Build HashSet with g++ .." -g++ -O3 -msse2 -msse3 -msse4 -o ${OUT_DIR}/HashSet_native HashSet.cpp \ - -lstdc++ - -echo "Build HashSet with em++ .." -em++ -O3 -s STANDALONE_WASM=1 -msimd128 \ - -s INITIAL_MEMORY=1048576 \ - -s TOTAL_STACK=32768 \ - -s "EXPORTED_FUNCTIONS=['_main']" \ - -o ${OUT_DIR}/HashSet.wasm HashSet.cpp - -echo "Compile HashSet.wasm to HashSet.aot" -${WAMRC_CMD} -o ${OUT_DIR}/HashSet.aot ${OUT_DIR}/HashSet.wasm - -echo "Build float-mm with gcc .." -gcc -O3 -msse2 -msse3 -msse4 -o ${OUT_DIR}/float-mm_native float-mm.c - -echo "Build float-mm with emcc .." -emcc -O3 -s STANDALONE_WASM=1 -msimd128 \ - -s INITIAL_MEMORY=1048576 \ - -s TOTAL_STACK=32768 \ - -s "EXPORTED_FUNCTIONS=['_main']" \ - -o ${OUT_DIR}/float-mm.wasm float-mm.c - -echo "Compile float-mm.wasm to float-mm.aot" -${WAMRC_CMD} -o ${OUT_DIR}/float-mm.aot ${OUT_DIR}/float-mm.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/libsodium/test_aot.sh b/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/libsodium/test_aot.sh deleted file mode 100755 index 2e4e3e357c4..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/libsodium/test_aot.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -libsodium_CASES="aead_aes256gcm2 aead_aes256gcm aead_chacha20poly13052 aead_chacha20poly1305 \ - aead_xchacha20poly1305 auth2 auth3 auth5 auth6 auth7 auth box2 box7 box8 \ - box_easy2 box_easy box_seal box_seed box chacha20 codecs core1 core2 core3 \ - core4 core5 core6 core_ed25519 core_ristretto255 ed25519_convert generichash2 \ - generichash3 generichash hash3 hash kdf keygen kx metamorphic misuse \ - onetimeauth2 onetimeauth7 onetimeauth pwhash_argon2id pwhash_argon2i \ - pwhash_scrypt_ll pwhash_scrypt randombytes scalarmult2 scalarmult5 \ - scalarmult6 scalarmult7 scalarmult8 scalarmult_ed25519 scalarmult_ristretto255 \ - scalarmult secretbox2 secretbox7 secretbox8 secretbox_easy2 secretbox_easy \ - secretbox secretstream shorthash sign siphashx24 sodium_core sodium_utils2 \ - sodium_utils3 sodium_utils sodium_version stream2 stream3 stream4 stream verify1 \ - xchacha20" - -readonly OUT_DIR=$PWD/libsodium/zig-out/bin -readonly REPORT=$PWD/report.txt -readonly IWASM_CMD=$PWD/../../../product-mini/platforms/linux/build/iwasm - -BENCH_NAME_MAX_LEN=20 - -rm -f $REPORT -touch $REPORT - -function print_bench_name() -{ - name=$1 - echo -en "$name" >> $REPORT - name_len=${#name} - if [ $name_len -lt $BENCH_NAME_MAX_LEN ] - then - spaces=$(( $BENCH_NAME_MAX_LEN - $name_len )) - for i in $(eval echo "{1..$spaces}"); do echo -n " " >> $REPORT; done - fi -} - -# run benchmarks -cd $OUT_DIR - -echo -en "\t\t\t\t\t\tnative\tiwasm-aot\n" >> $REPORT - -for t in $libsodium_CASES -do - print_bench_name $t - - echo "run $t with native..." - echo -en "\t" >> $REPORT - ./${t} | awk -F '-' 'BEGIN{FIELDWIDTHS="10"}{ORS=""; print $1 / 1000000.0}' >> $REPORT - - echo "run $t with iwasm aot..." - echo -en "\t \t" >> $REPORT - $IWASM_CMD ${t}.aot | awk -F '-' 'BEGIN{FIELDWIDTHS="10"}{ORS=""; print $1 / 1000000.0}' >> $REPORT - - echo -en "\n" >> $REPORT -done - diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/wasi-test-script/run_wasi_tests.sh b/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/wasi-test-script/run_wasi_tests.sh deleted file mode 100755 index eb6cf3f91e1..00000000000 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/wasi-test-script/run_wasi_tests.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/bash - -# -# Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# - -readonly MODE=$1 -readonly TARGET=$2 - -readonly WORK_DIR=$PWD -readonly PLATFORM=$(uname -s | tr A-Z a-z) -readonly WAMR_DIR="${WORK_DIR}/../../../.." -readonly IWASM_CMD="${WORK_DIR}/../../../../product-mini/platforms/${PLATFORM}/build/iwasm" -readonly WAMRC_CMD="${WORK_DIR}/../../../../wamr-compiler/build/wamrc" -readonly C_TESTS="tests/c/testsuite/" -readonly ASSEMBLYSCRIPT_TESTS="tests/assemblyscript/testsuite/" -readonly THREAD_PROPOSAL_TESTS="tests/proposals/wasi-threads/" -readonly THREAD_INTERNAL_TESTS="${WAMR_DIR}/core/iwasm/libraries/lib-wasi-threads/test/" -readonly LIB_SOCKET_TESTS="${WAMR_DIR}/core/iwasm/libraries/lib-socket/test/" - -run_aot_tests () { - local tests=("$@") - for test_wasm in ${tests[@]}; do - test_aot="${test_wasm%.wasm}.aot" - test_json="${test_wasm%.wasm}.json" - - if [ -f ${test_wasm} ]; then - expected=$(jq .exit_code ${test_json}) - fi - - echo "Compiling $test_wasm to $test_aot" - ${WAMRC_CMD} --enable-multi-thread ${target_option} \ - -o ${test_aot} ${test_wasm} - - echo "Running $test_aot" - expected=0 - if [ -f ${test_json} ]; then - expected=$(jq .exit_code ${test_json}) - fi - - ${IWASM_CMD} $test_aot - - ret=${PIPESTATUS[0]} - - echo "expected=$expected, actual=$ret" - if [[ $expected != "" ]] && [[ $expected != $ret ]];then - exit_code=1 - fi - done -} - -if [[ $MODE != "aot" ]];then - python3 -m venv wasi-env && source wasi-env/bin/activate - python3 -m pip install -r test-runner/requirements.txt - TEST_RUNTIME_EXE="${IWASM_CMD}" python3 test-runner/wasi_test_runner.py \ - -r adapters/wasm-micro-runtime.py \ - -t \ - ${C_TESTS} \ - ${ASSEMBLYSCRIPT_TESTS} \ - ${THREAD_PROPOSAL_TESTS} \ - ${THREAD_INTERNAL_TESTS} \ - ${LIB_SOCKET_TESTS} \ - exit_code=${PIPESTATUS[0]} - deactivate -else - target_option="" - if [[ $TARGET == "X86_32" ]];then - target_option="--target=i386" - fi - - exit_code=0 - for testsuite in ${THREAD_PROPOSAL_TESTS} ${THREAD_INTERNAL_TESTS}; do - tests=$(ls ${testsuite}*.wasm) - tests_array=($tests) - run_aot_tests "${tests_array[@]}" - done -fi - -exit ${exit_code} \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.clang-tidy b/lib/wasm-micro-runtime-WAMR-1.3.0/.clang-tidy similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.clang-tidy rename to lib/wasm-micro-runtime-WAMR-1.3.0/.clang-tidy diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/.devcontainer/Dockerfile b/lib/wasm-micro-runtime-WAMR-1.3.0/.devcontainer/Dockerfile new file mode 100644 index 00000000000..1587a7ddc75 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.devcontainer/Dockerfile @@ -0,0 +1,150 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/cpp/.devcontainer/base.Dockerfile +# [Choice] Debian / Ubuntu version (use Debian 12/11/9, Ubuntu 18.04/21.04 on local arm64/Apple Silicon): debian-12, debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04 +ARG VARIANT=debian-12 +FROM mcr.microsoft.com/vscode/devcontainers/cpp:${VARIANT} + +ARG DEBIAN_FRONTEND=noninteractive +ENV TZ=Asian/Shanghai + +# hadolint ignore=DL3008 +RUN apt-get update \ + && apt-get upgrade -y \ + && apt-get install -y apt-transport-https apt-utils build-essential \ + ca-certificates ccache cmake curl g++-multilib git gnupg \ + libgcc-12-dev lib32gcc-12-dev lsb-release \ + ninja-build ocaml ocamlbuild \ + software-properties-common tree tzdata \ + unzip valgrind vim wget zip --no-install-recommends \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* + +# +# binaryen +ARG BINARYEN_VER=114 +WORKDIR /opt +RUN wget -c --progress=dot:giga https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VER}/binaryen-version_${BINARYEN_VER}-x86_64-linux.tar.gz \ + && tar xf binaryen-version_${BINARYEN_VER}-x86_64-linux.tar.gz \ + && ln -sf /opt/binaryen-version_${BINARYEN_VER} /opt/binaryen \ + && rm binaryen-version_${BINARYEN_VER}-x86_64-linux.tar.gz + +# +# CMAKE (https://apt.kitware.com/) +SHELL ["/bin/bash", "-o", "pipefail", "-c"] +# hadolint ignore=DL3008 +ARG CMAKE_VER=3.27.0 +RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}-Linux-x86_64.sh \ + -q -O /tmp/cmake-install.sh \ + && chmod u+x /tmp/cmake-install.sh \ + && mkdir /opt/cmake-${CMAKE_VER} \ + && /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-${CMAKE_VER} \ + && rm /tmp/cmake-install.sh \ + && ln -s /opt/cmake-${CMAKE_VER}/bin/* /usr/local/bin + +# +# install emsdk +WORKDIR /opt +RUN git clone https://github.com/emscripten-core/emsdk.git + +ARG EMSDK_VER=3.1.43 +WORKDIR /opt/emsdk +RUN git pull \ + && ./emsdk install ${EMSDK_VER} \ + && ./emsdk activate ${EMSDK_VER} \ + && echo "source /opt/emsdk/emsdk_env.sh" >> /root/.bashrc + +# +# install wasi-sdk +ARG WASI_SDK_VER=20 +RUN wget -c --progress=dot:giga https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VER}/wasi-sdk-${WASI_SDK_VER}.0-linux.tar.gz -P /opt \ + && tar xf /opt/wasi-sdk-${WASI_SDK_VER}.0-linux.tar.gz -C /opt \ + && ln -sf /opt/wasi-sdk-${WASI_SDK_VER}.0 /opt/wasi-sdk \ + && rm /opt/wasi-sdk-${WASI_SDK_VER}.0-linux.tar.gz + +# +#install wabt +ARG WABT_VER=1.0.33 +RUN wget -c --progress=dot:giga https://github.com/WebAssembly/wabt/releases/download/${WABT_VER}/wabt-${WABT_VER}-ubuntu.tar.gz -P /opt \ + && tar xf /opt/wabt-${WABT_VER}-ubuntu.tar.gz -C /opt \ + && ln -sf /opt/wabt-${WABT_VER} /opt/wabt \ + && rm /opt/wabt-${WABT_VER}-ubuntu.tar.gz + +# +# install bazelisk +ARG BAZELISK_VER=1.17.0 +RUN mkdir /opt/bazelisk \ + && wget -c --progress=dot:giga https://github.com/bazelbuild/bazelisk/releases/download/v${BAZELISK_VER}/bazelisk-linux-amd64 -P /opt/bazelisk \ + && chmod a+x /opt/bazelisk/bazelisk-linux-amd64 \ + && ln -fs /opt/bazelisk/bazelisk-linux-amd64 /opt/bazelisk/bazel + +# +# install clang+llvm +ARG LLVM_VER=16 +RUN apt-get purge -y clang-14 llvm-14 && apt-get autoremove -y +WORKDIR /etc/apt/apt.conf.d +RUN touch 99verfiy-peer.conf \ + && echo "Acquire { https::Verify-Peer false }" > 99verfiy-peer.conf + +WORKDIR /tmp +#RUN wget --progress=dot:giga https://apt.llvm.org/llvm.sh \ +# && chmod a+x ./llvm.sh \ +# && ./llvm.sh ${LLVM_VER} all + +# Workaround due to https://github.com/llvm/llvm-project/issues/62475 +# hadolint ignore=DL3008 +RUN set -ex \ + && echo "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-${LLVM_VER} main" > /etc/apt/sources.list.d/apt.llvm.org.list \ + && wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc \ + && apt-get update \ + && apt-get install -y \ + clang-${LLVM_VER} lldb-${LLVM_VER} lld-${LLVM_VER} clangd-${LLVM_VER} clang-tidy-${LLVM_VER} clang-format-${LLVM_VER} clang-tools-${LLVM_VER} \ + llvm-${LLVM_VER}-dev lld-${LLVM_VER} lldb-${LLVM_VER} llvm-${LLVM_VER}-tools libomp-${LLVM_VER}-dev libc++-${LLVM_VER}-dev libc++abi-${LLVM_VER}-dev \ + libclang-common-${LLVM_VER}-dev libclang-${LLVM_VER}-dev libclang-cpp${LLVM_VER}-dev libunwind-${LLVM_VER}-dev \ + libclang-rt-${LLVM_VER}-dev libpolly-${LLVM_VER}-dev --no-install-recommends \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* + +# +# [Optional] + +# +# Install pip +# hadolint ignore=DL3008 +RUN apt-get update \ + && apt-get install -y --reinstall python3-venv python3-pip --no-install-recommends \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* + +# +# Install required python packages +# hadolint ignore=DL3013 +RUN python3 -m pip install --no-cache-dir --break-system-packages --upgrade pip \ + && pip3 install --no-cache-dir --break-system-packages black nose pycparser pylint + +# +# Install github-cli. It doens't work as a feature of devcontainer.json +ARG GH_CLI_VER=2.32.0 +WORKDIR /tmp +RUN wget -q https://github.com/cli/cli/releases/download/v${GH_CLI_VER}/gh_${GH_CLI_VER}_linux_amd64.deb \ + && dpkg -i gh_${GH_CLI_VER}_linux_amd64.deb + +# +# Install NodeJS +RUN wget -qO- https://deb.nodesource.com/setup_20.x | bash - +# hadolint ignore=DL3008 +RUN apt-get install -y nodejs --no-install-recommends + +# set path +ENV PATH="/opt/bazelisk:/usr/lib/llvm-${LLVM_VER}/bin:${PATH}" +ENV CC=/usr/lib/llvm-${LLVM_VER}/bin/clang CXX=/usr/lib/llvm-${LLVM_VER}/bin/clang++ +RUN printf "%s\n" "PS1='\n[ \u@wamr-dev-docker \W ]\n$ '" >> /root/.bashrc \ + && apt-get autoremove -y \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* \ + && rm -rf /tmp/* + +# set workdir when container run +VOLUME /workspaces +WORKDIR /workspaces diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.devcontainer/devcontainer.json b/lib/wasm-micro-runtime-WAMR-1.3.0/.devcontainer/devcontainer.json similarity index 70% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.devcontainer/devcontainer.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/.devcontainer/devcontainer.json index 24e1bdfd61f..5feb175640b 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/.devcontainer/devcontainer.json +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.devcontainer/devcontainer.json @@ -1,20 +1,23 @@ // Copyright (C) 2019 Intel Corporation. All rights reserved. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at: -// https://github.com/microsoft/vscode-dev-containers/tree/v0.195.0/containers/cpp +// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/cpp { "name": "WAMR-Dev", "build": { "dockerfile": "Dockerfile", - // Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04 - // Use Debian 11, Debian 9, Ubuntu 18.04 or Ubuntu 21.04 on local arm64/Apple Silicon + // Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-12, debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04 + // Use Debian 12, Debian 11, Debian 9, Ubuntu 18.04 or Ubuntu 21.04 on local arm64/Apple Silicon "args": { - "BINARYEN_VER": "111", - "EMSDK_VER": "3.0.0", - "LLVM_VER": "15", - "VARIANT": "ubuntu-20.04", - "WASI_SDK_VER": "19", - "WABT_VER": "1.0.31" + "BINARYEN_VER": "114", + "BAZELISK_VER": "1.17.0", + "CMAKE_VER": "3.27.0", + "EMSDK_VER": "3.1.43", + "GH_CLI_VER": "2.32.0", + "LLVM_VER": "16", + "VARIANT": "debian-12", + "WASI_SDK_VER": "20", + "WABT_VER": "1.0.33" } }, "runArgs": [ @@ -34,7 +37,7 @@ "llvm-vs-code-extensions.vscode-clangd", "ms-python.python", "ms-python.vscode-pylance", - "ms-vscode.cmake-tools", + "ms-vscode.cmake-tools" ] } }, diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/extract_from_release_notes.py b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/scripts/extract_from_release_notes.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/extract_from_release_notes.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/scripts/extract_from_release_notes.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/fetch_and_compare_version.py b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/scripts/fetch_and_compare_version.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/fetch_and_compare_version.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/scripts/fetch_and_compare_version.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/reuse_latest_release_binaries.py b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/scripts/reuse_latest_release_binaries.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/scripts/reuse_latest_release_binaries.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/scripts/reuse_latest_release_binaries.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_docker_images.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_docker_images.yml similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_docker_images.yml rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_docker_images.yml diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_iwasm_release.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_iwasm_release.yml similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_iwasm_release.yml rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_iwasm_release.yml diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_llvm_libraries.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_llvm_libraries.yml similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_llvm_libraries.yml rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_llvm_libraries.yml diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamr_lldb.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamr_lldb.yml similarity index 63% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamr_lldb.yml rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamr_lldb.yml index ba491ad3ad1..1a73750a642 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamr_lldb.yml +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamr_lldb.yml @@ -22,6 +22,11 @@ on: description: a semantic version number type: string required: true + wasi_sdk_url: + description: download WASI_SDK from this URL + type: string + required: false + default: "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz" jobs: try_reuse: @@ -29,16 +34,30 @@ jobs: with: binary_name_stem: "wamr-lldb-${{ inputs.ver_num }}-${{ inputs.arch }}-${{ inputs.runner }}" last_commit: "ea63ba4bd010c2285623ad4acc0262a4d63bcfea" - the_path: "./build-scripts/lldb-wasm.patch" + the_path: "./build-scripts/lldb_wasm.patch" upload_url: ${{ inputs.upload_url }} build: needs: try_reuse if: needs.try_reuse.outputs.result != 'hit' runs-on: ${{ inputs.runner }} + + env: + PYTHON_VERSION: '3.10' + PYTHON_UBUNTU_STANDALONE_BUILD: https://github.com/indygreg/python-build-standalone/releases/download/20230507/cpython-3.10.11+20230507-x86_64-unknown-linux-gnu-install_only.tar.gz + PYTHON_MACOS_STANDALONE_BUILD: https://github.com/indygreg/python-build-standalone/releases/download/20230507/cpython-3.10.11+20230507-x86_64-apple-darwin-install_only.tar.gz steps: - uses: actions/checkout@v3 + - name: download and install wasi-sdk + run: | + cd /opt + basename=$(basename ${{ inputs.wasi_sdk_url }}) + sudo wget --progress=dot:giga ${{ inputs.wasi_sdk_url }} + sudo tar -xzf ${basename} + sudo rm ${basename} + sudo mv wasi-sdk-* wasi-sdk + - name: Cache build id: lldb_build_cache uses: actions/cache@v3 @@ -63,10 +82,12 @@ jobs: - name: install utils macos if: steps.lldb_build_cache.outputs.cache-hit != 'true' && contains(inputs.runner, 'macos') run: | - brew install swig cmake ninja libedit + brew remove swig + brew install swig@4.1 cmake ninja libedit + brew link --overwrite swig@4.1 sudo rm -rf /Library/Developer/CommandLineTools - - name: intsall utils ubuntu + - name: install utils ubuntu if: steps.lldb_build_cache.outputs.cache-hit != 'true' && contains(inputs.runner, 'ubuntu') run: sudo apt update && sudo apt-get install -y lld ninja-build @@ -85,9 +106,23 @@ jobs: git init git config user.email "action@github.com" git config user.name "github action" - git apply ../../../build-scripts/lldb-wasm.patch + git apply ../../../build-scripts/lldb_wasm.patch working-directory: core/deps/llvm-project + - name: get stand-alone python ubuntu + if: steps.lldb_build_cache.outputs.cache-hit != 'true' && contains(inputs.runner, 'ubuntu') + run: | + wget ${{ env.PYTHON_UBUNTU_STANDALONE_BUILD }} -O python.tar.gz + tar -xvf python.tar.gz + working-directory: core/deps + + - name: get stand-alone python macos + if: steps.lldb_build_cache.outputs.cache-hit != 'true' && contains(inputs.runner, 'macos') + run: | + wget ${{ env.PYTHON_MACOS_STANDALONE_BUILD }} -O python.tar.gz + tar -xvf python.tar.gz + working-directory: core/deps + - name: build lldb ubuntu if: steps.lldb_build_cache.outputs.cache-hit != 'true' && contains(inputs.runner, 'ubuntu') run: | @@ -102,20 +137,35 @@ jobs: -DLLVM_TARGETS_TO_BUILD:STRING="X86;WebAssembly" \ -DLLVM_BUILD_BENCHMARKS:BOOL=OFF \ -DLLVM_BUILD_DOCS:BOOL=OFF \ - -DLLVM_BUILD_EXAMPLES:BOOL=OFF \ + -DLLVM_BUILD_EXAMPLES:BOOL=OFF \ -DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF \ - -DLLVM_BUILD_TESTS:BOOL=OFF \ - -DLLVM_INCLUDE_BENCHMARKS:BOOL=OFF \ + -DLLVM_BUILD_TESTS:BOOL=OFF \ + -DLLVM_INCLUDE_BENCHMARKS:BOOL=OFF \ -DLLVM_INCLUDE_DOCS:BOOL=OFF \ -DLLVM_INCLUDE_EXAMPLES:BOOL=OFF \ -DLLVM_INCLUDE_TESTS:BOOL=OFF \ -DLLVM_ENABLE_BINDINGS:BOOL=OFF \ -DLLVM_ENABLE_LIBXML2:BOOL=ON \ - -DLLDB_ENABLE_PYTHON:BOOL=OFF \ - -DLLVM_ENABLE_LLD:BOOL=ON + -DLLVM_ENABLE_LLD:BOOL=ON \ + -DLLDB_ENABLE_PYTHON:BOOL=ON \ + -DLLDB_EMBED_PYTHON_HOME=ON \ + -DLLDB_PYTHON_HOME=.. \ + -DLLDB_PYTHON_RELATIVE_PATH=lib/lldb-python \ + -DPython3_EXECUTABLE="$(pwd)/../python/bin/python${{ env.PYTHON_VERSION }}" cmake --build build --target lldb install --parallel $(nproc) working-directory: core/deps/llvm-project + - name: validate lldb ubuntu + if: steps.lldb_build_cache.outputs.cache-hit != 'true' && contains(inputs.runner, 'ubuntu') + run: | + echo "start to validate lldb..." + mkdir -p wamr-debug + cmake -S product-mini/platforms/linux -B wamr-debug -DWAMR_BUILD_DEBUG_INTERP=1 + cmake --build wamr-debug --parallel $(nproc) + export LD_LIBRARY_PATH=$(pwd)/core/deps/python/lib:${LD_LIBRARY_PATH} + python3 ci/validate_lldb.py --port 1239 --lldb core/deps/wamr-lldb/bin/lldb --wamr wamr-debug/iwasm --verbose + working-directory: . + - name: build lldb macos if: steps.lldb_build_cache.outputs.cache-hit != 'true' && contains(inputs.runner, 'macos') run: | @@ -130,20 +180,21 @@ jobs: -DLLVM_TARGETS_TO_BUILD:STRING="X86;WebAssembly" \ -DLLVM_BUILD_BENCHMARKS:BOOL=OFF \ -DLLVM_BUILD_DOCS:BOOL=OFF \ - -DLLVM_BUILD_EXAMPLES:BOOL=OFF \ + -DLLVM_BUILD_EXAMPLES:BOOL=OFF \ -DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF \ - -DLLVM_BUILD_TESTS:BOOL=OFF \ - -DLLVM_INCLUDE_BENCHMARKS:BOOL=OFF \ + -DLLVM_BUILD_TESTS:BOOL=OFF \ + -DLLVM_INCLUDE_BENCHMARKS:BOOL=OFF \ -DLLVM_INCLUDE_DOCS:BOOL=OFF \ -DLLVM_INCLUDE_EXAMPLES:BOOL=OFF \ -DLLVM_INCLUDE_TESTS:BOOL=OFF \ - -DLLVM_BUILD_BENCHMARKS:BOOL=OFF \ - -DLLVM_BUILD_DOCS:BOOL=OFF \ - -DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF \ -DLLVM_ENABLE_BINDINGS:BOOL=OFF \ -DLLVM_ENABLE_LIBXML2:BOOL=ON \ - -DLLDB_ENABLE_PYTHON:BOOL=OFF \ - -DLLDB_BUILD_FRAMEWORK:BOOL=OFF + -DLLDB_BUILD_FRAMEWORK:BOOL=OFF \ + -DLLDB_ENABLE_PYTHON:BOOL=ON \ + -DLLDB_EMBED_PYTHON_HOME=ON \ + -DLLDB_PYTHON_HOME=.. \ + -DLLDB_PYTHON_RELATIVE_PATH=lib/lldb-python \ + -DPython3_EXECUTABLE="$(pwd)/../python/bin/python${{ env.PYTHON_VERSION }}" cmake --build build --target lldb install --parallel $(nproc) working-directory: core/deps/llvm-project @@ -154,7 +205,7 @@ jobs: mkdir -p wamr-lldb/lib cp build/bin/lldb* wamr-lldb/bin cp lldb/tools/lldb-vscode/package.json wamr-lldb - cp -r lldb/tools/lldb-vscode/syntaxes/ wamr-lldb + cp -r lldb/tools/lldb-vscode/syntaxes/ wamr-lldb working-directory: core/deps/llvm-project - name: pack ubuntu specific libraries @@ -162,12 +213,20 @@ jobs: run: | cp build/lib/liblldb*.so wamr-lldb/lib cp build/lib/liblldb*.so.* wamr-lldb/lib + cp -R build/lib/lldb-python wamr-lldb/lib + cp -R ../python/lib/python* wamr-lldb/lib + cp ../python/lib/libpython${{ env.PYTHON_VERSION }}.so.1.0 wamr-lldb/lib working-directory: core/deps/llvm-project - name: pack macos specific libraries if: steps.lldb_build_cache.outputs.cache-hit != 'true' && contains(inputs.runner, 'macos') run: | cp build/lib/liblldb*.dylib wamr-lldb/lib + cp -R build/lib/lldb-python wamr-lldb/lib + cp -R ../python/lib/python* wamr-lldb/lib + cp ../python/lib/libpython*.dylib wamr-lldb/lib + install_name_tool -change /install/lib/libpython${{ env.PYTHON_VERSION }}.dylib @rpath/libpython${{ env.PYTHON_VERSION }}.dylib wamr-lldb/lib/liblldb.*.dylib + # Patch path of python library -> https://github.com/indygreg/python-build-standalone/blob/85923ca3911784e6978b85d56e06e9ae75cb2dc4/docs/quirks.rst?plain=1#L412-L446 working-directory: core/deps/llvm-project - name: compress the binary diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamr_sdk.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamr_sdk.yml similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamr_sdk.yml rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamr_sdk.yml diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamr_vscode_ext.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamr_vscode_ext.yml similarity index 97% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamr_vscode_ext.yml rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamr_vscode_ext.yml index 297dc9b9e72..3dfb290cf77 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamr_vscode_ext.yml +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamr_vscode_ext.yml @@ -20,10 +20,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Use Node.js 14.x + - name: Use Node.js 16.x uses: actions/setup-node@v3 with: - node-version: 14.x + node-version: 16.x - name: set vscode extension to correct version run: | diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamrc.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamrc.yml similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/build_wamrc.yml rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/build_wamrc.yml diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/coding_guidelines.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/coding_guidelines.yml similarity index 96% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/coding_guidelines.yml rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/coding_guidelines.yml index 259e84fe51b..17d60ac43d7 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/coding_guidelines.yml +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/coding_guidelines.yml @@ -16,7 +16,7 @@ concurrency: jobs: compliance_job: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - name: checkout uses: actions/checkout@v3 diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_android_ubuntu.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_android_ubuntu.yml new file mode 100644 index 00000000000..98d346f9ebb --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_android_ubuntu.yml @@ -0,0 +1,713 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +name: compilation on android, ubuntu-22.04 + +on: + # will be triggered on PR events + pull_request: + types: + - opened + - synchronize + paths: + - ".github/workflows/build_llvm_libraries.yml" + - ".github/workflows/compilation_on_android_ubuntu.yml" + - "build-scripts/**" + - "core/**" + - "!core/deps/**" + - "product-mini/**" + - "samples/**" + - "!samples/workload/**" + - "tests/wamr-test-suites/**" + - "wamr-compiler/**" + - "wamr-sdk/**" + - "test-tools/wamr-ide/**" + # will be triggered on push events + push: + branches: + - main + - "dev/**" + paths: + - ".github/workflows/build_llvm_libraries.yml" + - ".github/workflows/compilation_on_android_ubuntu.yml" + - "build-scripts/**" + - "core/**" + - "!core/deps/**" + - "product-mini/**" + - "samples/**" + - "!samples/workload/**" + - "tests/wamr-test-suites/**" + - "wamr-compiler/**" + - "wamr-sdk/**" + - "test-tools/wamr-ide/**" + # allow to be triggered manually + workflow_dispatch: + +# Cancel any in-flight jobs for the same PR/branch so there's only one active +# at a time +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + # For BUILD + 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" + MULTI_TIER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1" + # For Spec Test + DEFAULT_TEST_OPTIONS: "-s spec -b -P" + MULTI_MODULES_TEST_OPTIONS: "-s spec -b -M -P" + SIMD_TEST_OPTIONS: "-s spec -b -S -P" + THREADS_TEST_OPTIONS: "-s spec -b -p -P" + X86_32_TARGET_TEST_OPTIONS: "-m x86_32 -P" + WASI_TEST_OPTIONS: "-s wasi_certification -w" + WAMR_COMPILER_TEST_OPTIONS: "-s wamr_compiler -b -P" + +jobs: + build_llvm_libraries_on_ubuntu_2204: + uses: ./.github/workflows/build_llvm_libraries.yml + with: + os: "ubuntu-22.04" + arch: "X86" + + build_wamrc: + needs: + [build_llvm_libraries_on_ubuntu_2204] + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: ubuntu-22.04 + llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }} + steps: + - name: checkout + uses: actions/checkout@v3 + + # since jobs.id can't contain the dot character + # it is hard to use `format` to assemble the cache key + - name: Get LLVM libraries + id: retrieve_llvm_libs + uses: actions/cache@v3 + with: + path: | + ./core/deps/llvm/build/bin + ./core/deps/llvm/build/include + ./core/deps/llvm/build/lib + ./core/deps/llvm/build/libexec + ./core/deps/llvm/build/share + key: ${{ matrix.llvm_cache_key }} + + - name: Quit if cache miss + if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' + run: echo "::error::can not get prebuilt llvm libraries" && exit 1 + + - name: Build wamrc + run: | + mkdir build && cd build + cmake .. + cmake --build . --config Release --parallel 4 + working-directory: wamr-compiler + + build_iwasm: + needs: + [build_llvm_libraries_on_ubuntu_2204] + runs-on: ${{ matrix.os }} + strategy: + matrix: + make_options_run_mode: [ + # 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, + $MULTI_TIER_JIT_BUILD_OPTIONS, + ] + make_options_feature: [ + # Features + "-DWAMR_BUILD_CUSTOM_NAME_SECTION=1", + "-DWAMR_BUILD_DEBUG_AOT=1", + "-DWAMR_BUILD_DEBUG_INTERP=1", + "-DWAMR_BUILD_DUMP_CALL_STACK=1", + "-DWAMR_BUILD_LIB_PTHREAD=1", + "-DWAMR_BUILD_LIB_WASI_THREADS=1", + "-DWAMR_BUILD_LOAD_CUSTOM_SECTION=1", + "-DWAMR_BUILD_MINI_LOADER=1", + "-DWAMR_BUILD_MEMORY_PROFILING=1", + "-DWAMR_BUILD_MULTI_MODULE=1", + "-DWAMR_BUILD_PERF_PROFILING=1", + "-DWAMR_BUILD_REF_TYPES=1", + "-DWAMR_BUILD_SIMD=1", + "-DWAMR_BUILD_TAIL_CALL=1", + "-DWAMR_DISABLE_HW_BOUND_CHECK=1", + ] + os: [ubuntu-22.04] + platform: [android, linux] + exclude: + # uncompatiable feature and platform + # uncompatiable mode and feature + # MULTI_MODULE only on INTERP mode and AOT mode + - 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: $MULTI_TIER_JIT_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" + - make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS + make_options_feature: "-DWAMR_BUILD_SIMD=1" + # 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: $MULTI_TIER_JIT_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" + - make_options_run_mode: $MULTI_TIER_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 + make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1" + - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS + make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1" + # Fast-JIT and Multi-Tier-JIT mode don't support android(X86-32) + - make_options_run_mode: $FAST_JIT_BUILD_OPTIONS + platform: android + - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS + platform: android + include: + - os: ubuntu-22.04 + llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }} + steps: + - name: checkout + uses: actions/checkout@v3 + + # only download llvm cache when needed + - name: Get LLVM libraries + id: retrieve_llvm_libs + if: endsWith(matrix.make_options_run_mode, '_JIT_BUILD_OPTIONS') + uses: actions/cache@v3 + with: + path: | + ./core/deps/llvm/build/bin + ./core/deps/llvm/build/include + ./core/deps/llvm/build/lib + ./core/deps/llvm/build/libexec + ./core/deps/llvm/build/share + key: ${{ matrix.llvm_cache_key }} + + - name: Quit if cache miss + if: endsWith(matrix.make_options_run_mode, '_JIT_BUILD_OPTIONS') && (steps.retrieve_llvm_libs.outputs.cache-hit != 'true') + run: echo "::error::can not get prebuilt llvm libraries" && exit 1 + + - name: Build iwasm + run: | + mkdir build && cd build + cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} + cmake --build . --config Release --parallel 4 + working-directory: product-mini/platforms/${{ matrix.platform }} + + - name: Build and run unit tests + run: | + mkdir build-unittests && cd build-unittests + cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} + cmake --build . --config Release --parallel 4 + ctest + working-directory: tests/unit + + build_samples_wasm_c_api: + needs: + [ + build_iwasm, + build_llvm_libraries_on_ubuntu_2204, + build_wamrc, + ] + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + 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, + $MULTI_TIER_JIT_BUILD_OPTIONS, + ] + os: [ubuntu-22.04] + wasi_sdk_release: + [ + "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz", + ] + wabt_release: + [ + "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz", + ] + include: + - os: ubuntu-22.04 + llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }} + + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: Get LLVM libraries + id: retrieve_llvm_libs + if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS')) + uses: actions/cache@v3 + with: + path: | + ./core/deps/llvm/build/bin + ./core/deps/llvm/build/include + ./core/deps/llvm/build/lib + ./core/deps/llvm/build/libexec + ./core/deps/llvm/build/share + key: ${{ matrix.llvm_cache_key }} + + - name: Quit if cache miss + if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS')) && (steps.retrieve_llvm_libs.outputs.cache-hit != 'true') + run: echo "::error::can not get prebuilt llvm libraries" && exit 1 + + - name: download and install wabt + run: | + cd /opt + sudo wget ${{ matrix.wabt_release }} + sudo tar -xzf wabt-1.0.31-*.tar.gz + sudo mv wabt-1.0.31 wabt + + - name: Build wamrc + if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS')) + run: | + mkdir build && cd build + cmake .. + cmake --build . --config Release --parallel 4 + working-directory: wamr-compiler + + - name: Build Sample [wasm-c-api] + run: | + VERBOSE=1 + cmake -S . -B build ${{ matrix.make_options }} + cmake --build build --config Release --parallel 4 + ctest --test-dir build --output-on-failure + working-directory: samples/wasm-c-api + + build_samples_others: + needs: + [ + build_iwasm, + build_llvm_libraries_on_ubuntu_2204, + build_wamrc, + ] + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-22.04] + wasi_sdk_release: + [ + "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz", + ] + wabt_release: + [ + "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz", + ] + include: + - os: ubuntu-22.04 + llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }} + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: download and install wasi-sdk + run: | + cd /opt + sudo wget ${{ matrix.wasi_sdk_release }} + sudo tar -xzf wasi-sdk-*.tar.gz + sudo mv wasi-sdk-20.0 wasi-sdk + + - name: download and install wabt + run: | + cd /opt + sudo wget ${{ matrix.wabt_release }} + sudo tar -xzf wabt-1.0.31-*.tar.gz + sudo mv wabt-1.0.31 wabt + - name: Get LLVM libraries + id: retrieve_llvm_libs + uses: actions/cache@v3 + with: + path: | + ./core/deps/llvm/build/bin + ./core/deps/llvm/build/include + ./core/deps/llvm/build/lib + ./core/deps/llvm/build/libexec + ./core/deps/llvm/build/share + key: ${{ matrix.llvm_cache_key }} + - name: Build wamrc + run: | + mkdir build && cd build + cmake .. + cmake --build . --config Release --parallel 4 + working-directory: wamr-compiler + - name: Build Sample [basic] + run: | + cd samples/basic + ./build.sh + ./run.sh + + - name: Build Sample [file] + run: | + cd samples/file + mkdir build && cd build + cmake .. + cmake --build . --config Release --parallel 4 + ./src/iwasm -f wasm-app/file.wasm -d . + + - name: Build Sample [multi-thread] + run: | + cd samples/multi-thread + mkdir build && cd build + cmake .. + cmake --build . --config Release --parallel 4 + ./iwasm wasm-apps/test.wasm + + - name: Build Sample [multi-module] + run: | + cd samples/multi-module + mkdir build && cd build + cmake .. -DWAMR_BUILD_AOT=1 + cmake --build . --config Release --parallel 4 + ./multi_module mC.wasm + ./multi_module mC.aot + + - name: Build Sample [spawn-thread] + run: | + cd samples/spawn-thread + mkdir build && cd build + cmake .. + cmake --build . --config Release --parallel 4 + ./spawn_thread + + - name: Build Sample [ref-types] + run: | + cd samples/ref-types + mkdir build && cd build + cmake .. + cmake --build . --config Release --parallel 4 + ./hello + + - name: Build Sample [simple] + run: | + ./build.sh -p host-interp + python3 ./sample_test_run.py $(pwd)/out + exit $? + working-directory: ./samples/simple + + - name: Build Sample [wasi-threads] + run: | + cd samples/wasi-threads + mkdir build && cd build + cmake .. + cmake --build . --config Release --parallel 4 + ./iwasm wasm-apps/no_pthread.wasm + + - name: Build Sample [shared-module] + run: | + cd samples/shared-module + ./build.sh + ./run.sh + + test: + needs: + [ + build_iwasm, + build_llvm_libraries_on_ubuntu_2204, + build_wamrc, + ] + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-22.04] + running_mode: + [ + "classic-interp", + "fast-interp", + "jit", + "aot", + "fast-jit", + "multi-tier-jit", + ] + test_option: + [ + $DEFAULT_TEST_OPTIONS, + $MULTI_MODULES_TEST_OPTIONS, + $SIMD_TEST_OPTIONS, + $THREADS_TEST_OPTIONS, + $WASI_TEST_OPTIONS, + ] + wasi_sdk_release: + [ + "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz", + ] + include: + - os: ubuntu-22.04 + llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }} + ubuntu_version: "22.04" + - os: ubuntu-22.04 + llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }} + running_mode: aot + test_option: $WAMR_COMPILER_TEST_OPTIONS + exclude: + # uncompatiable modes and features + # classic-interp and fast-interp don't support simd + - running_mode: "classic-interp" + test_option: $SIMD_TEST_OPTIONS + - running_mode: "fast-interp" + test_option: $SIMD_TEST_OPTIONS + # llvm jit doesn't support multi module + - running_mode: "jit" + test_option: $MULTI_MODULES_TEST_OPTIONS + # fast-jit doesn't support multi module, simd + - running_mode: "fast-jit" + test_option: $MULTI_MODULES_TEST_OPTIONS + - running_mode: "fast-jit" + test_option: $SIMD_TEST_OPTIONS + # multi-tier-jit doesn't support multi module, simd + - running_mode: "multi-tier-jit" + test_option: $MULTI_MODULES_TEST_OPTIONS + - running_mode: "multi-tier-jit" + test_option: $SIMD_TEST_OPTIONS + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: download and install wasi-sdk + if: matrix.test_option == '$WASI_TEST_OPTIONS' + run: | + cd /opt + sudo wget ${{ matrix.wasi_sdk_release }} + sudo tar -xzf wasi-sdk-*.tar.gz + sudo mv wasi-sdk-20.0 wasi-sdk + + # It is a temporary solution until new wasi-sdk that includes bug fixes is released + - name: build wasi-libc from source + if: matrix.test_option == '$WASI_TEST_OPTIONS' + run: | + git clone https://github.com/WebAssembly/wasi-libc + cd wasi-libc + make -j AR=/opt/wasi-sdk/bin/llvm-ar NM=/opt/wasi-sdk/bin/llvm-nm CC=/opt/wasi-sdk/bin/clang THREAD_MODEL=posix + echo "SYSROOT_PATH=$PWD/sysroot" >> $GITHUB_ENV + + + - name: set env variable(if llvm are used) + if: matrix.running_mode == 'aot' || matrix.running_mode == 'jit' || matrix.running_mode == 'multi-tier-jit' + run: echo "USE_LLVM=true" >> $GITHUB_ENV + + - name: set env variable(if x86_32 test needed) + if: > + (matrix.test_option == '$DEFAULT_TEST_OPTIONS' || matrix.test_option == '$THREADS_TEST_OPTIONS' + || matrix.test_option == '$WASI_TEST_OPTIONS') + && matrix.running_mode != 'fast-jit' && matrix.running_mode != 'jit' && matrix.running_mode != 'multi-tier-jit' + run: echo "TEST_ON_X86_32=true" >> $GITHUB_ENV + + #only download llvm libraries in jit and aot mode + - name: Get LLVM libraries + if: env.USE_LLVM == 'true' + id: retrieve_llvm_libs + uses: actions/cache@v3 + with: + path: | + ./core/deps/llvm/build/bin + ./core/deps/llvm/build/include + ./core/deps/llvm/build/lib + ./core/deps/llvm/build/libexec + ./core/deps/llvm/build/share + key: ${{ matrix.llvm_cache_key }} + + - name: Quit if cache miss + if: env.USE_LLVM == 'true' && steps.retrieve_llvm_libs.outputs.cache-hit != 'true' + run: echo "::error::can not get prebuilt llvm libraries" && exit 1 + + - name: install jq JSON processor + if: matrix.running_mode == 'aot' && matrix.test_option == '$WASI_TEST_OPTIONS' + run: sudo apt-get update && sudo apt install -y jq + + - name: Build WASI thread tests + if: matrix.test_option == '$WASI_TEST_OPTIONS' + run: bash build.sh --sysroot "$SYSROOT_PATH" + working-directory: ./core/iwasm/libraries/lib-wasi-threads/test/ + + - name: build socket api tests + if: matrix.test_option == '$WASI_TEST_OPTIONS' + run: bash build.sh + working-directory: ./core/iwasm/libraries/lib-socket/test/ + + - name: run tests + timeout-minutes: 30 + run: ./test_wamr.sh ${{ matrix.test_option }} -t ${{ matrix.running_mode }} + working-directory: ./tests/wamr-test-suites + + #only install x32 support libraries when to run x86_32 cases + - name: install x32 support libraries + if: env.TEST_ON_X86_32 == 'true' + run: + # Add another apt repository as some packages cannot + # be downloaded with the github default repository + sudo curl -sSL https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc && + sudo apt-add-repository https://packages.microsoft.com/ubuntu/${{ matrix.ubuntu_version }}/prod && + sudo apt-get update && + sudo apt install -y g++-multilib lib32gcc-9-dev + + - name: run tests x86_32 + timeout-minutes: 30 + if: env.TEST_ON_X86_32 == 'true' + run: ./test_wamr.sh ${{ env.X86_32_TARGET_TEST_OPTIONS }} ${{ matrix.test_option }} -t ${{ matrix.running_mode }} + working-directory: ./tests/wamr-test-suites + + test-wamr-ide: + needs: + [ + build_iwasm + ] + runs-on: ubuntu-22.04 + env: + PYTHON_VERSION: '3.10' + PYTHON_UBUNTU_STANDALONE_BUILD: https://github.com/indygreg/python-build-standalone/releases/download/20230507/cpython-3.10.11+20230507-x86_64-unknown-linux-gnu-install_only.tar.gz + + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: install dependencies + run: | + rustup target add wasm32-wasi + sudo apt update && sudo apt-get install -y lld ninja-build + npm install + working-directory: test-tools/wamr-ide/VSCode-Extension + + - name: build iwasm with source debugging feature + run: | + mkdir build + cd build + cmake .. -DWAMR_BUILD_DEBUG_INTERP=1 + make + working-directory: product-mini/platforms/linux + + - name: Cache LLDB + id: cache-lldb + uses: actions/cache@v3 + env: + cache-name: cache-lldb-vscode + with: + path: test-tools/wamr-ide/VSCode-Extension/resource/debug/linux + key: ${{ env.cache-name }}-${{ hashFiles('build-scripts/lldb_wasm.patch') }}-${{ env.PYTHON_UBUNTU_STANDALONE_BUILD }} + + - if: ${{ steps.cache-lldb.outputs.cache-hit != 'true' }} + name: get stand-alone python ubuntu + run: | + wget ${{ env.PYTHON_UBUNTU_STANDALONE_BUILD }} -O python.tar.gz + tar -xvf python.tar.gz + working-directory: core/deps + + - if: ${{ steps.cache-lldb.outputs.cache-hit != 'true' }} + name: download llvm + run: | + wget https://github.com/llvm/llvm-project/archive/1f27fe6128769f00197925c3b8f6abb9d0e5cd2e.zip + unzip -q 1f27fe6128769f00197925c3b8f6abb9d0e5cd2e.zip + mv llvm-project-1f27fe6128769f00197925c3b8f6abb9d0e5cd2e llvm-project + working-directory: core/deps + + - if: ${{ steps.cache-lldb.outputs.cache-hit != 'true' }} + name: apply wamr patch + run: | + git init + git config user.email "action@github.com" + git config user.name "github action" + git apply ../../../build-scripts/lldb_wasm.patch + working-directory: core/deps/llvm-project + + - if: ${{ steps.cache-lldb.outputs.cache-hit != 'true' }} + name: build lldb ubuntu + run: | + echo "start to build lldb..." + mkdir -p wamr-lldb + cmake -S ./llvm -B build \ + -G Ninja \ + -DCMAKE_INSTALL_PREFIX=../wamr-lldb \ + -DCMAKE_BUILD_TYPE:STRING="Release" \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DLLVM_ENABLE_PROJECTS="clang;lldb" \ + -DLLVM_TARGETS_TO_BUILD:STRING="X86;WebAssembly" \ + -DLLVM_BUILD_BENCHMARKS:BOOL=OFF \ + -DLLVM_BUILD_DOCS:BOOL=OFF \ + -DLLVM_BUILD_EXAMPLES:BOOL=OFF \ + -DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF \ + -DLLVM_BUILD_TESTS:BOOL=OFF \ + -DLLVM_INCLUDE_BENCHMARKS:BOOL=OFF \ + -DLLVM_INCLUDE_DOCS:BOOL=OFF \ + -DLLVM_INCLUDE_EXAMPLES:BOOL=OFF \ + -DLLVM_INCLUDE_TESTS:BOOL=OFF \ + -DLLVM_ENABLE_BINDINGS:BOOL=OFF \ + -DLLVM_ENABLE_LIBXML2:BOOL=ON \ + -DLLVM_ENABLE_LLD:BOOL=ON \ + -DLLDB_ENABLE_PYTHON:BOOL=ON \ + -DLLDB_EMBED_PYTHON_HOME=ON \ + -DLLDB_PYTHON_HOME=.. \ + -DLLDB_PYTHON_RELATIVE_PATH=lib/lldb-python \ + -DPython3_EXECUTABLE="$(pwd)/../python/bin/python${{ env.PYTHON_VERSION }}" + cmake --build build --target lldb install --parallel $(nproc) + working-directory: core/deps/llvm-project + + - if: ${{ steps.cache-lldb.outputs.cache-hit != 'true' }} + name: copy lldb to extension folder + run: | + mkdir -p bin + mkdir -p lib + cp ../../../../../../core/deps/llvm-project/lldb/tools/lldb-vscode/package.json ./ + cp -r ../../../../../../core/deps/llvm-project/lldb/tools/lldb-vscode/syntaxes/ ./ + cp ../../../../../../core/deps/llvm-project/build/bin/lldb* bin + cp ../../../../../../core/deps/llvm-project/build/lib/liblldb*.so lib + cp ../../../../../../core/deps/llvm-project/build/lib/liblldb*.so.* lib + cp -R ../../../../../../core/deps/llvm-project/build/lib/lldb-python lib + cp -R ../../../../../../core/deps/python/lib/python* lib + cp ../../../../../../core/deps/python/lib/libpython${{ env.PYTHON_VERSION }}.so.1.0 lib + working-directory: test-tools/wamr-ide/VSCode-Extension/resource/debug/linux + + - name: run tests + timeout-minutes: 5 + run: xvfb-run npm run test + working-directory: test-tools/wamr-ide/VSCode-Extension diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_macos.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_macos.yml similarity index 97% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_macos.yml rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_macos.yml index aaa97d038cd..12f1d73cb91 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_macos.yml +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_macos.yml @@ -133,13 +133,11 @@ jobs: exclude: # uncompatiable feature and platform # uncompatiable mode and feature - # MULTI_MODULE only on INTERP mode + # MULTI_MODULE only on INTERP mode and AOT mode - 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" @@ -245,7 +243,7 @@ jobs: working-directory: samples/wasm-c-api build_samples_others: - needs: [build_iwasm] + needs: [build_iwasm, build_wamrc] runs-on: ${{ matrix.os }} strategy: matrix: @@ -304,7 +302,7 @@ jobs: mkdir build && cd build cmake .. cmake --build . --config Release --parallel 4 - ./multi_module + ./multi_module mC.wasm - name: Build Sample [spawn-thread] run: | @@ -329,3 +327,9 @@ jobs: cmake .. cmake --build . --config Release --parallel 4 ./iwasm wasm-apps/no_pthread.wasm + + - name: Build Sample [shared-module] + run: | + cd samples/shared-module + ./build.sh + ./run.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_nuttx.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_nuttx.yml similarity index 93% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_nuttx.yml rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_nuttx.yml index f338c8dea7b..77b3da75a10 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_nuttx.yml +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_nuttx.yml @@ -94,9 +94,9 @@ jobs: - name: Install RISC-V Compilers if: contains(matrix.nuttx_board_config, 'risc-v') run: | - curl -L https://static.dev.sifive.com/dev-tools/freedom-tools/v2020.12/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz > riscv.tar.gz + curl -L https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v12.3.0-1/xpack-riscv-none-elf-gcc-12.3.0-1-linux-x64.tar.gz > riscv.tar.gz tar xvf riscv.tar.gz - echo "$PWD/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin" >> $GITHUB_PATH + echo "$PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin" >> $GITHUB_PATH - name: Install WASI-SDK run: | @@ -108,12 +108,14 @@ jobs: uses: actions/checkout@v3 with: repository: apache/incubator-nuttx + ref: releases/12.3 path: nuttx - name: Checkout NuttX Apps uses: actions/checkout@v3 with: repository: apache/incubator-nuttx-apps + ref: releases/12.3 path: apps - name: Checkout WAMR diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_sgx.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_sgx.yml similarity index 69% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_sgx.yml rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_sgx.yml index f17261118fe..0d19d83ad94 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_sgx.yml +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_sgx.yml @@ -51,6 +51,7 @@ env: 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" + FAST_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_LAZY_JIT=1" 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" @@ -70,6 +71,7 @@ jobs: $AOT_BUILD_OPTIONS, $CLASSIC_INTERP_BUILD_OPTIONS, $FAST_INTERP_BUILD_OPTIONS, + $FAST_JIT_BUILD_OPTIONS, # Running modes unsupported #$LLVM_LAZY_JIT_BUILD_OPTIONS, #$LLVM_EAGER_JIT_BUILD_OPTIONS, @@ -99,9 +101,6 @@ jobs: platform: [linux-sgx] exclude: # 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" # MINI_LOADER only on INTERP mode - make_options_run_mode: $AOT_BUILD_OPTIONS make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1" @@ -127,69 +126,24 @@ jobs: mkdir build && cd build cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} cmake --build . --config Release --parallel 4 + cd ../enclave-sample + make working-directory: product-mini/platforms/${{ matrix.platform }} - build_wamrc: - needs: [build_llvm_libraries] + run_samples_file: + needs: [build_iwasm, build_llvm_libraries] runs-on: ${{ matrix.os }} strategy: matrix: - include: - - os: ubuntu-20.04 - llvm_cache_key: ${{ needs.build_llvm_libraries.outputs.cache_key }} - steps: - - name: install SGX SDK and necessary libraries - run: | - mkdir -p /opt/intel - cd /opt/intel - wget https://download.01.org/intel-sgx/sgx-linux/2.15/distro/ubuntu20.04-server/sgx_linux_x64_sdk_2.15.100.3.bin - chmod +x sgx_linux_x64_sdk_2.15.100.3.bin - echo 'yes' | ./sgx_linux_x64_sdk_2.15.100.3.bin - echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu focal main' | sudo tee /etc/apt/sources.list.d/intel-sgx.list - wget -qO - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | sudo apt-key add - - sudo apt update - sudo apt install -y libsgx-launch libsgx-urts - source /opt/intel/sgxsdk/environment - - - name: checkout - uses: actions/checkout@v3 - - - name: Get LLVM libraries - id: retrieve_llvm_libs - uses: actions/cache@v3 - with: - path: | - ./core/deps/llvm/build/bin - ./core/deps/llvm/build/include - ./core/deps/llvm/build/lib - ./core/deps/llvm/build/libexec - ./core/deps/llvm/build/share - key: ${{ matrix.llvm_cache_key }} - - - name: Quit if cache miss - if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' - run: echo "::error::can not get prebuilt llvm libraries" && exit 1 - - - name: Build wamrc - run: | - mkdir build && cd build - cmake .. - cmake --build . --config Release --parallel 4 - working-directory: wamr-compiler - - build_samples_wasm_c_api: - needs: [build_iwasm] - runs-on: ${{ matrix.os }} - strategy: - matrix: - make_options: [ + iwasm_make_options_run_mode: [ # Running modes supported + $AOT_BUILD_OPTIONS, $CLASSIC_INTERP_BUILD_OPTIONS, $FAST_INTERP_BUILD_OPTIONS, + $FAST_JIT_BUILD_OPTIONS, # Running modes unsupported - #$LLVM_EAGER_JIT_BUILD_OPTIONS, #$LLVM_LAZY_JIT_BUILD_OPTIONS, - #$AOT_BUILD_OPTIONS, + #$LLVM_EAGER_JIT_BUILD_OPTIONS, ] os: [ubuntu-20.04] wasi_sdk_release: @@ -200,51 +154,15 @@ jobs: [ "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz", ] - steps: - - name: checkout - uses: actions/checkout@v3 - - - name: download and install wabt - run: | - cd /opt - sudo wget ${{ matrix.wabt_release }} - sudo tar -xzf wabt-1.0.31-*.tar.gz - sudo mv wabt-1.0.31 wabt - - - name: install SGX SDK and necessary libraries - run: | - mkdir -p /opt/intel - cd /opt/intel - wget https://download.01.org/intel-sgx/sgx-linux/2.15/distro/ubuntu20.04-server/sgx_linux_x64_sdk_2.15.100.3.bin - chmod +x sgx_linux_x64_sdk_2.15.100.3.bin - echo 'yes' | ./sgx_linux_x64_sdk_2.15.100.3.bin - echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu focal main' | sudo tee /etc/apt/sources.list.d/intel-sgx.list - wget -qO - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | sudo apt-key add - - sudo apt update - sudo apt install -y libsgx-launch libsgx-urts - source /opt/intel/sgxsdk/environment - - - name: Build Sample [wasm-c-api] - run: | - cmake -S . -B build ${{ matrix.make_options }} - cmake --build build --config Release --parallel 4 - ctest --test-dir build - working-directory: samples/wasm-c-api - - build_samples_others: - needs: [build_iwasm] - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-20.04] - wasi_sdk_release: - [ - "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz", - ] - wabt_release: - [ - "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz", + iwasm_make_options_feature: [ + # Features to be tested: IPFS + "-DWAMR_BUILD_SGX_IPFS=1", ] + platform: [linux-sgx] + include: + - os: ubuntu-20.04 + llvm_cache_key: ${{ needs.build_llvm_libraries.outputs.cache_key }} + steps: - name: checkout uses: actions/checkout@v3 @@ -290,76 +208,85 @@ jobs: wget -qO - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | sudo apt-key add - sudo apt update sudo apt install -y libsgx-launch libsgx-urts - source /opt/intel/sgxsdk/environment - - - name: Build Sample [basic] - run: | - cd samples/basic - ./build.sh - ./run.sh - - name: Build Sample [file] + - name: Build iwasm for testing samples run: | - cd samples/file mkdir build && cd build - cmake .. + cmake .. ${{ matrix.iwasm_make_options_run_mode }} ${{ matrix.iwasm_make_options_feature }} cmake --build . --config Release --parallel 4 - ./src/iwasm -f wasm-app/file.wasm -d . + cd ../enclave-sample + make + working-directory: product-mini/platforms/${{ matrix.platform }} - - name: Build Sample [multi-thread] - run: | - cd samples/multi-thread - mkdir build && cd build - cmake .. - cmake --build . --config Release --parallel 4 - ./iwasm wasm-apps/test.wasm + - name: Get LLVM libraries + if: matrix.iwasm_make_options_run_mode == '$AOT_BUILD_OPTIONS' + id: retrieve_llvm_libs + uses: actions/cache@v3 + with: + path: | + ./core/deps/llvm/build/bin + ./core/deps/llvm/build/include + ./core/deps/llvm/build/lib + ./core/deps/llvm/build/libexec + ./core/deps/llvm/build/share + key: ${{ matrix.llvm_cache_key }} + fail-on-cache-miss: true - - name: Build Sample [multi-module] + - name: Build wamrc only for testing samples in aot mode + if: matrix.iwasm_make_options_run_mode == '$AOT_BUILD_OPTIONS' run: | - cd samples/multi-module mkdir build && cd build cmake .. cmake --build . --config Release --parallel 4 - ./multi_module + cp wamrc `pwd`/../../product-mini/platforms/${{ matrix.platform }}/enclave-sample + working-directory: wamr-compiler - - name: Build Sample [spawn-thread] + - name: Build Sample [file] run: | - cd samples/spawn-thread + cd samples/file mkdir build && cd build cmake .. cmake --build . --config Release --parallel 4 - ./spawn_thread + cp wasm-app/file.wasm `pwd`/../../../product-mini/platforms/${{ matrix.platform }}/enclave-sample - - name: Build Sample [ref-types] + - name: Test Sample [file] in non-aot mode + if: matrix.iwasm_make_options_run_mode != '$AOT_BUILD_OPTIONS' run: | - cd samples/ref-types - mkdir build && cd build - cmake .. - cmake --build . --config Release --parallel 4 - ./hello + source /opt/intel/sgxsdk/environment + ./iwasm --dir=. file.wasm + working-directory: product-mini/platforms/${{ matrix.platform }}/enclave-sample - - name: Build Sample [wasi-threads] + - name: Test Sample [file] in aot mode + if: matrix.iwasm_make_options_run_mode == '$AOT_BUILD_OPTIONS' run: | - cd samples/wasi-threads - mkdir build && cd build - cmake -DWASI_SYSROOT=`pwd`/../../../core/deps/wasi-libc/sysroot .. - cmake --build . --config Release --parallel 4 - ./iwasm wasm-apps/no_pthread.wasm + source /opt/intel/sgxsdk/environment + ./wamrc -sgx -o file.aot file.wasm + ./iwasm --dir=. file.aot + working-directory: product-mini/platforms/${{ matrix.platform }}/enclave-sample spec_test_default: - needs: [build_iwasm, build_llvm_libraries, build_wamrc] + needs: [build_iwasm, build_llvm_libraries] runs-on: ubuntu-20.04 strategy: matrix: - running_mode: ["classic-interp", "fast-interp", "aot"] - test_option: ["-x -p -s spec -b -P", "-x -p -s spec -S -b -P"] + running_mode: ["classic-interp", "fast-interp", "aot", "fast-jit"] + test_option: ["-x -p -s spec -b -P", "-x -p -s spec -S -b -P", "-x -p -s spec -X -b -P"] llvm_cache_key: ["${{ needs.build_llvm_libraries.outputs.cache_key }}"] - # classic-interp and fast-interp don't support simd exclude: + # classic-interp, fast-interp and fast-jit don't support simd - running_mode: "classic-interp" test_option: "-x -p -s spec -S -b -P" - running_mode: "fast-interp" test_option: "-x -p -s spec -S -b -P" + - running_mode: "fast-jit" + test_option: "-x -p -s spec -S -b -P" + # classic-interp, fast-interp and fast jit don't support XIP + - running_mode: "classic-interp" + test_option: "-x -p -s spec -X -b -P" + - running_mode: "fast-interp" + test_option: "-x -p -s spec -X -b -P" + - running_mode: "fast-jit" + test_option: "-x -p -s spec -X -b -P" steps: - name: checkout diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_windows.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_windows.yml similarity index 50% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_windows.yml rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_windows.yml index 0d38e8ae554..97a4aaae20e 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_windows.yml +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/compilation_on_windows.yml @@ -39,6 +39,16 @@ on: # allow to be triggered manually workflow_dispatch: +env: + # For Spec Test + DEFAULT_TEST_OPTIONS: "-s spec -b" + MULTI_MODULES_TEST_OPTIONS: "-s spec -b -M" + THREADS_TEST_OPTIONS: "-s spec -b -p" + WASI_TEST_OPTIONS: "-s wasi_certification -w" + WASI_TEST_FILTER: ${{ github.workspace }}/product-mini/platforms/windows/wasi_filtered_tests.json + # Used when building the WASI socket and thread tests + CC: ${{ github.workspace }}/wasi-sdk/bin/clang + # Cancel any in-flight jobs for the same PR/branch so there's only one active # at a time concurrency: @@ -60,12 +70,14 @@ jobs: "-DWAMR_BUILD_SIMD=1", "-DWAMR_BUILD_DEBUG_INTERP=1", "-DWAMR_BUILD_LIB_PTHREAD=1", - "-DWAMR_BUILD_LIB_WASI_THREADS=1" + "-DWAMR_BUILD_LIB_WASI_THREADS=1", + "-DWAMR_BUILD_LIBC_UVWASI=0 -DWAMR_BUILD_LIBC_WASI=1" ] steps: - uses: actions/checkout@v3 - name: clone uvwasi library + if: ${{ !contains(matrix.build_options, '-DWAMR_BUILD_LIBC_UVWASI=0') }} run: | cd core/deps git clone https://github.com/nodejs/uvwasi.git @@ -75,3 +87,50 @@ jobs: mkdir build && cd build cmake .. ${{ matrix.build_options }} cmake --build . --config Release --parallel 4 + + test: + runs-on: windows-latest + needs: [build] + strategy: + fail-fast: false + matrix: + running_mode: + [ + "classic-interp", + "fast-interp", + ] + test_option: + [ + $DEFAULT_TEST_OPTIONS, + $MULTI_MODULES_TEST_OPTIONS, + $THREADS_TEST_OPTIONS, + $WASI_TEST_OPTIONS, + ] + steps: + - name: checkout + uses: actions/checkout@v3 + + - name: download and install wasi-sdk + if: matrix.test_option == '$WASI_TEST_OPTIONS' + run: | + curl "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0.m-mingw.tar.gz" -o wasi-sdk.tar.gz -L + mkdir wasi-sdk + tar -xzf wasi-sdk.tar.gz -C wasi-sdk --strip-components 1 + + - name: build socket api tests + shell: bash + if: matrix.test_option == '$WASI_TEST_OPTIONS' + run: ./build.sh + working-directory: ./core/iwasm/libraries/lib-socket/test/ + + - name: Build WASI thread tests + shell: bash + if: matrix.test_option == '$WASI_TEST_OPTIONS' + run: ./build.sh + working-directory: ./core/iwasm/libraries/lib-wasi-threads/test/ + + - name: run tests + shell: bash + timeout-minutes: 20 + run: ./test_wamr.sh ${{ matrix.test_option }} -t ${{ matrix.running_mode }} + working-directory: ./tests/wamr-test-suites diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/create_tag.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/create_tag.yml similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/create_tag.yml rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/create_tag.yml diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/hadolint_dockerfiles.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/hadolint_dockerfiles.yml new file mode 100644 index 00000000000..bdabeb6e5d4 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/hadolint_dockerfiles.yml @@ -0,0 +1,47 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +name: hadolint dockerfiles + +on: + # will be triggered on PR events + pull_request: + types: + - opened + - synchronize + paths: + - "**/Dockerfile*" + - ".github/workflows/hadolint_dockerfiles.yml" + push: + branches: + - main + - "dev/**" + paths: + - "**/Dockerfile*" + - ".github/workflows/hadolint_dockerfiles.yml" + # allow to be triggered manually + workflow_dispatch: + +# Cancel any in-flight jobs for the same PR/branch so there's only one active +# at a time +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + run-hadolint-on-dockerfiles: + runs-on: ubuntu-22.04 + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # on default, hadolint will fail on warnings and errors + - name: Run hadolint on dockerfiles + run: | + docker pull hadolint/hadolint:latest-debian + find . -name "*Dockerfile*" | while read dockerfile; do + echo "run hadolint on $dockerfile:" + docker run --rm -i hadolint/hadolint:latest-debian hadolint - <"$dockerfile" + echo "successful" + done \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_android_ubuntu.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/nightly_run.yml similarity index 84% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_android_ubuntu.yml rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/nightly_run.yml index 2a57f621955..8153cea99f4 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/compilation_on_android_ubuntu.yml +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/nightly_run.yml @@ -1,43 +1,22 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. +# Copyright (C) 2023 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -name: compilation on android, ubuntu-20.04, ubuntu-22.04 +name: nightly_run on: - # will be triggered on PR events pull_request: types: - opened - synchronize + # running nightly pipeline if you're changing it + # stress tests are run only in nightly at the moment, so running them in they are changed paths: - - ".github/workflows/build_llvm_libraries.yml" - - ".github/workflows/compilation_on_android_ubuntu.yml" - - "build-scripts/**" - - "core/**" - - "!core/deps/**" - - "product-mini/**" - - "samples/**" - - "!samples/workload/**" - - "tests/wamr-test-suites/**" - - "wamr-compiler/**" - - "wamr-sdk/**" - # will be triggered on push events - push: - branches: - - main - - "dev/**" - paths: - - ".github/workflows/build_llvm_libraries.yml" - - ".github/workflows/compilation_on_android_ubuntu.yml" - - "build-scripts/**" - - "core/**" - - "!core/deps/**" - - "product-mini/**" - - "samples/**" - - "!samples/workload/**" - - "tests/wamr-test-suites/**" - - "wamr-compiler/**" - - "wamr-sdk/**" + - ".github/workflows/nightly_run.yml" + - "core/iwasm/libraries/lib-wasi-threads/stress-test/**" + + # midnight UTC + schedule: + - cron: "0 0 * * *" # allow to be triggered manually workflow_dispatch: @@ -70,24 +49,23 @@ jobs: with: os: "ubuntu-20.04" arch: "X86" - build_llvm_libraries_on_ubuntu_2204: uses: ./.github/workflows/build_llvm_libraries.yml with: os: "ubuntu-22.04" arch: "X86" - + build_wamrc: needs: - [build_llvm_libraries_on_ubuntu_2004, build_llvm_libraries_on_ubuntu_2204] + [ + build_llvm_libraries_on_ubuntu_2004, + ] runs-on: ${{ matrix.os }} strategy: matrix: include: - os: ubuntu-20.04 - llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }} - - os: ubuntu-22.04 - llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }} + llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }} steps: - name: checkout uses: actions/checkout@v3 @@ -117,17 +95,23 @@ jobs: cmake --build . --config Release --parallel 4 working-directory: wamr-compiler - build_iwasm_linux_gcc4_8: - runs-on: ubuntu-latest - container: - image: ubuntu:14.04 + build_iwasm: + needs: + [ + build_llvm_libraries_on_ubuntu_2004, + ] + runs-on: ${{ matrix.os }} strategy: matrix: make_options_run_mode: [ # 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, + $MULTI_TIER_JIT_BUILD_OPTIONS, ] make_options_feature: [ # Features @@ -147,22 +131,38 @@ jobs: "-DWAMR_BUILD_TAIL_CALL=1", "-DWAMR_DISABLE_HW_BOUND_CHECK=1", ] + os: [ubuntu-20.04] + platform: [android, linux] exclude: # uncompatiable feature and platform # uncompatiable mode and feature - # MULTI_MODULE only on INTERP mode + # MULTI_MODULE only on INTERP mode and AOT mode - 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: $MULTI_TIER_JIT_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" - make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS make_options_feature: "-DWAMR_BUILD_SIMD=1" # 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: $MULTI_TIER_JIT_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" @@ -171,45 +171,72 @@ jobs: # 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" + - make_options_run_mode: $MULTI_TIER_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 + make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1" + - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS + make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1" + # Fast-JIT and Multi-Tier-JIT mode don't support android(X86-32) + - make_options_run_mode: $FAST_JIT_BUILD_OPTIONS + platform: android + - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS + platform: android + include: + - os: ubuntu-20.04 + llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }} + steps: - name: checkout uses: actions/checkout@v3 - - name: Install dependencies - run: apt update && apt install -y make g++-4.8 gcc-4.8 wget git + # only download llvm cache when needed + - name: Get LLVM libraries + id: retrieve_llvm_libs + if: endsWith(matrix.make_options_run_mode, '_JIT_BUILD_OPTIONS') + uses: actions/cache@v3 + with: + path: | + ./core/deps/llvm/build/bin + ./core/deps/llvm/build/include + ./core/deps/llvm/build/lib + ./core/deps/llvm/build/libexec + ./core/deps/llvm/build/share + key: ${{ matrix.llvm_cache_key }} - - name: Install cmake - run: | - wget https://github.com/Kitware/CMake/releases/download/v3.26.1/cmake-3.26.1-linux-x86_64.tar.gz -O cmake.tar.gz - tar xzf cmake.tar.gz - cp cmake-3.26.1-linux-x86_64/bin/cmake /usr/local/bin - cp -r cmake-3.26.1-linux-x86_64/share/cmake-3.26/ /usr/local/share/ + - name: Quit if cache miss + if: endsWith(matrix.make_options_run_mode, '_JIT_BUILD_OPTIONS') && (steps.retrieve_llvm_libs.outputs.cache-hit != 'true') + run: echo "::error::can not get prebuilt llvm libraries" && exit 1 - name: Build iwasm run: | mkdir build && cd build - cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} -DCMAKE_C_COMPILER=gcc-4.8 -DCMAKE_CXX_COMPILER=g++-4.8 + cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} cmake --build . --config Release --parallel 4 - working-directory: product-mini/platforms/linux + working-directory: product-mini/platforms/${{ matrix.platform }} - build_iwasm: - needs: - [build_llvm_libraries_on_ubuntu_2004, build_llvm_libraries_on_ubuntu_2204] - runs-on: ${{ matrix.os }} + build_iwasm_linux_gcc4_8: + runs-on: ubuntu-latest + container: + image: ubuntu:14.04 strategy: matrix: make_options_run_mode: [ # 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, - $MULTI_TIER_JIT_BUILD_OPTIONS, ] make_options_feature: [ # Features @@ -229,40 +256,22 @@ jobs: "-DWAMR_BUILD_TAIL_CALL=1", "-DWAMR_DISABLE_HW_BOUND_CHECK=1", ] - os: [ubuntu-20.04, ubuntu-22.04] - platform: [android, linux] exclude: # 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" + # MULTI_MODULE only on INTERP mode and AOT mode - 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: $MULTI_TIER_JIT_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" - make_options_run_mode: $FAST_INTERP_BUILD_OPTIONS make_options_feature: "-DWAMR_BUILD_SIMD=1" # 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: $MULTI_TIER_JIT_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" @@ -271,78 +280,46 @@ jobs: # 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" - - make_options_run_mode: $MULTI_TIER_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 - make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1" - - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS - make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1" - # Fast-JIT and Multi-Tier-JIT mode don't support android(X86-32) - - make_options_run_mode: $FAST_JIT_BUILD_OPTIONS - platform: android - - make_options_run_mode: $MULTI_TIER_JIT_BUILD_OPTIONS - platform: android - # only test andorid on ubuntu latest - - os: ubuntu-20.04 - platform: android - include: - - os: ubuntu-20.04 - llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }} - - os: ubuntu-22.04 - llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }} steps: - name: checkout uses: actions/checkout@v3 - # only download llvm cache when needed - - name: Get LLVM libraries - id: retrieve_llvm_libs - if: endsWith(matrix.make_options_run_mode, '_JIT_BUILD_OPTIONS') - uses: actions/cache@v3 + - name: Install dependencies + uses: nick-fields/retry@v2 with: - path: | - ./core/deps/llvm/build/bin - ./core/deps/llvm/build/include - ./core/deps/llvm/build/lib - ./core/deps/llvm/build/libexec - ./core/deps/llvm/build/share - key: ${{ matrix.llvm_cache_key }} - - - name: Quit if cache miss - if: endsWith(matrix.make_options_run_mode, '_JIT_BUILD_OPTIONS') && (steps.retrieve_llvm_libs.outputs.cache-hit != 'true') - run: echo "::error::can not get prebuilt llvm libraries" && exit 1 + timeout_minutes: 10 + max_attempts: 3 + command: apt update && apt install -y make g++-4.8 gcc-4.8 wget git + on_retry_command: sudo rm -r /var/lib/apt/lists/* + - name: Install cmake + run: | + wget https://github.com/Kitware/CMake/releases/download/v3.26.1/cmake-3.26.1-linux-x86_64.tar.gz -O cmake.tar.gz + tar xzf cmake.tar.gz + cp cmake-3.26.1-linux-x86_64/bin/cmake /usr/local/bin + cp -r cmake-3.26.1-linux-x86_64/share/cmake-3.26/ /usr/local/share/ - name: Build iwasm run: | mkdir build && cd build - cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} + cmake .. ${{ matrix.make_options_run_mode }} ${{ matrix.make_options_feature }} -DCMAKE_C_COMPILER=gcc-4.8 -DCMAKE_CXX_COMPILER=g++-4.8 cmake --build . --config Release --parallel 4 - working-directory: product-mini/platforms/${{ matrix.platform }} + working-directory: product-mini/platforms/linux build_samples_wasm_c_api: needs: [ build_iwasm, build_llvm_libraries_on_ubuntu_2004, - build_llvm_libraries_on_ubuntu_2204, build_wamrc, ] runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - sanitizer: ["", "ubsan"] + sanitizer: ["", "ubsan", "asan"] make_options: [ # Running mode $AOT_BUILD_OPTIONS, @@ -353,7 +330,7 @@ jobs: $LLVM_EAGER_JIT_BUILD_OPTIONS, $MULTI_TIER_JIT_BUILD_OPTIONS, ] - os: [ubuntu-20.04, ubuntu-22.04] + os: [ubuntu-20.04] wasi_sdk_release: [ "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz", @@ -365,9 +342,9 @@ jobs: include: - os: ubuntu-20.04 llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }} - - os: ubuntu-22.04 - llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }} - + exclude: + - make_options: $MULTI_TIER_JIT_BUILD_OPTIONS + sanitizer: asan steps: - name: checkout uses: actions/checkout@v3 @@ -395,29 +372,33 @@ jobs: sudo wget ${{ matrix.wabt_release }} sudo tar -xzf wabt-1.0.31-*.tar.gz sudo mv wabt-1.0.31 wabt - - name: Build wamrc if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS')) run: | mkdir build && cd build - cmake -DSANITIZER="${{matrix.sanitizer}}" .. + cmake -D WAMR_BUILD_SANITIZER="${{matrix.sanitizer}}" .. cmake --build . --config Release --parallel 4 working-directory: wamr-compiler - name: Build Sample [wasm-c-api] run: | VERBOSE=1 - cmake -S . -B build ${{ matrix.make_options }} -DSANITIZER="${{matrix.sanitizer}}" + cmake -S . -B build ${{ matrix.make_options }} -D WAMR_BUILD_SANITIZER="${{matrix.sanitizer}}" cmake --build build --config Release --parallel 4 ctest --test-dir build --output-on-failure working-directory: samples/wasm-c-api build_samples_others: - needs: [build_iwasm] + needs: + [ + build_iwasm, + build_llvm_libraries_on_ubuntu_2004, + build_wamrc, + ] runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04, ubuntu-22.04] + os: [ubuntu-20.04] wasi_sdk_release: [ "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz", @@ -426,6 +407,9 @@ jobs: [ "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz", ] + include: + - os: ubuntu-20.04 + llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2004.outputs.cache_key }} steps: - name: checkout uses: actions/checkout@v3 @@ -436,7 +420,6 @@ jobs: sudo wget ${{ matrix.wasi_sdk_release }} sudo tar -xzf wasi-sdk-*.tar.gz sudo mv wasi-sdk-20.0 wasi-sdk - - name: download and install wabt run: | cd /opt @@ -444,12 +427,30 @@ jobs: sudo tar -xzf wabt-1.0.31-*.tar.gz sudo mv wabt-1.0.31 wabt + - name: Get LLVM libraries + id: retrieve_llvm_libs + uses: actions/cache@v3 + with: + path: | + ./core/deps/llvm/build/bin + ./core/deps/llvm/build/include + ./core/deps/llvm/build/lib + ./core/deps/llvm/build/libexec + ./core/deps/llvm/build/share + key: ${{ matrix.llvm_cache_key }} + + - name: Build wamrc + run: | + mkdir build && cd build + cmake -D WAMR_BUILD_SANITIZER="${{matrix.sanitizer}}" .. + cmake --build . --config Release --parallel 4 + working-directory: wamr-compiler + - name: Build Sample [basic] run: | cd samples/basic ./build.sh ./run.sh - - name: Build Sample [file] run: | cd samples/file @@ -457,7 +458,6 @@ jobs: cmake .. cmake --build . --config Release --parallel 4 ./src/iwasm -f wasm-app/file.wasm -d . - - name: Build Sample [multi-thread] run: | cd samples/multi-thread @@ -465,15 +465,14 @@ jobs: cmake .. cmake --build . --config Release --parallel 4 ./iwasm wasm-apps/test.wasm - - name: Build Sample [multi-module] run: | cd samples/multi-module mkdir build && cd build - cmake .. + cmake .. -DWAMR_BUILD_AOT=1 cmake --build . --config Release --parallel 4 - ./multi_module - + ./multi_module mC.wasm + ./multi_module mC.aot - name: Build Sample [spawn-thread] run: | cd samples/spawn-thread @@ -481,7 +480,6 @@ jobs: cmake .. cmake --build . --config Release --parallel 4 ./spawn_thread - - name: Build Sample [ref-types] run: | cd samples/ref-types @@ -489,7 +487,6 @@ jobs: cmake .. cmake --build . --config Release --parallel 4 ./hello - - name: Build Sample [simple] run: | ./build.sh -p host-interp @@ -505,6 +502,11 @@ jobs: cmake --build . --config Release --parallel 4 ./iwasm wasm-apps/no_pthread.wasm + - name: Build Sample [shared-module] + run: | + cd samples/shared-module + ./build.sh + ./run.sh test: needs: [ @@ -515,8 +517,10 @@ jobs: ] runs-on: ${{ matrix.os }} strategy: + fail-fast: false matrix: os: [ubuntu-20.04, ubuntu-22.04] + sanitizer: ["", "ubsan", "asan", "tsan"] running_mode: [ "classic-interp", @@ -545,16 +549,36 @@ jobs: - os: ubuntu-22.04 llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }} ubuntu_version: "22.04" + exclude: # uncompatiable modes and features + - os: ubuntu-20.04 + sanitizer: tsan + # asan works only for aot now + - running_mode: "classic-interp" + sanitizer: asan + - running_mode: "fast-interp" + sanitizer: asan + - running_mode: "jit" + sanitizer: asan + - running_mode: "fast-jit" + sanitizer: asan + - running_mode: "multi-tier-jit" + sanitizer: asan + - running_mode: "classic-interp" + sanitizer: tsan + - running_mode: "jit" + sanitizer: tsan + - running_mode: "fast-jit" + sanitizer: tsan + - running_mode: "multi-tier-jit" + sanitizer: tsan # classic-interp and fast-interp don't support simd - running_mode: "classic-interp" test_option: $SIMD_TEST_OPTIONS - running_mode: "fast-interp" test_option: $SIMD_TEST_OPTIONS - # aot and jit don't support multi module - - running_mode: "aot" - test_option: $MULTI_MODULES_TEST_OPTIONS + # llvm jit doesn't support multi module - running_mode: "jit" test_option: $MULTI_MODULES_TEST_OPTIONS # fast-jit doesn't support multi module, simd @@ -579,6 +603,15 @@ jobs: sudo tar -xzf wasi-sdk-*.tar.gz sudo mv wasi-sdk-20.0 wasi-sdk + # It is a temporary solution until new wasi-sdk that includes bug fixes is released + - name: build wasi-libc from source + if: matrix.test_option == '$WASI_TEST_OPTIONS' + run: | + git clone https://github.com/WebAssembly/wasi-libc + cd wasi-libc + make -j AR=/opt/wasi-sdk/bin/llvm-ar NM=/opt/wasi-sdk/bin/llvm-nm CC=/opt/wasi-sdk/bin/clang THREAD_MODEL=posix + echo "SYSROOT_PATH=$PWD/sysroot" >> $GITHUB_ENV + - name: set env variable(if llvm are used) if: matrix.running_mode == 'aot' || matrix.running_mode == 'jit' || matrix.running_mode == 'multi-tier-jit' run: echo "USE_LLVM=true" >> $GITHUB_ENV @@ -590,6 +623,10 @@ jobs: && matrix.running_mode != 'fast-jit' && matrix.running_mode != 'jit' && matrix.running_mode != 'multi-tier-jit' run: echo "TEST_ON_X86_32=true" >> $GITHUB_ENV + - name: set additional tsan options + run: echo "TSAN_OPTIONS=suppressions=$PWD/tsan_suppressions.txt" >> $GITHUB_ENV + working-directory: tests/wamr-test-suites + #only download llvm libraries in jit and aot mode - name: Get LLVM libraries if: env.USE_LLVM == 'true' @@ -614,17 +651,22 @@ jobs: - name: Build WASI thread tests if: matrix.test_option == '$WASI_TEST_OPTIONS' - run: bash build.sh + run: bash build.sh --sysroot "$SYSROOT_PATH" working-directory: ./core/iwasm/libraries/lib-wasi-threads/test/ + - name: Build WASI thread stress tests + if: matrix.test_option == '$WASI_TEST_OPTIONS' + run: bash build.sh --sysroot "$SYSROOT_PATH" + working-directory: ./core/iwasm/libraries/lib-wasi-threads/stress-test/ + - name: build socket api tests if: matrix.test_option == '$WASI_TEST_OPTIONS' run: bash build.sh working-directory: ./core/iwasm/libraries/lib-socket/test/ - name: run tests - timeout-minutes: 10 - run: ./test_wamr.sh ${{ matrix.test_option }} -t ${{ matrix.running_mode }} + timeout-minutes: 40 + run: ./test_wamr.sh ${{ matrix.test_option }} -t ${{ matrix.running_mode }} -T %{{matrix.sanitizer}} working-directory: ./tests/wamr-test-suites #only install x32 support libraries when to run x86_32 cases @@ -639,7 +681,7 @@ jobs: sudo apt install -y g++-multilib lib32gcc-9-dev - name: run tests x86_32 - timeout-minutes: 10 + timeout-minutes: 40 if: env.TEST_ON_X86_32 == 'true' run: ./test_wamr.sh ${{ env.X86_32_TARGET_TEST_OPTIONS }} ${{ matrix.test_option }} -t ${{ matrix.running_mode }} working-directory: ./tests/wamr-test-suites diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/release_process.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/release_process.yml similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/release_process.yml rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/release_process.yml index 4188b4d40ad..ef722acdb1f 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/release_process.yml +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/release_process.yml @@ -56,21 +56,21 @@ jobs: uses: ./.github/workflows/build_llvm_libraries.yml with: os: "ubuntu-20.04" - arch: "X86" + arch: "AArch64 ARM Mips RISCV X86" build_llvm_libraries_on_ubuntu_2204: needs: [create_tag, create_release] uses: ./.github/workflows/build_llvm_libraries.yml with: os: "ubuntu-22.04" - arch: "X86" + arch: "AArch64 ARM Mips RISCV X86" build_llvm_libraries_on_macos: needs: [create_tag, create_release] uses: ./.github/workflows/build_llvm_libraries.yml with: os: "macos-latest" - arch: "X86" + arch: "AArch64 ARM Mips RISCV X86" # # WAMRC diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/reuse_latest_release_binaries.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/reuse_latest_release_binaries.yml similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.github/workflows/reuse_latest_release_binaries.yml rename to lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/reuse_latest_release_binaries.yml diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/spec_test_on_nuttx.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/spec_test_on_nuttx.yml new file mode 100644 index 00000000000..48fff2d23c0 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.github/workflows/spec_test_on_nuttx.yml @@ -0,0 +1,211 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +name: spec test on nuttx + +on: + pull_request: + types: + - closed + branches: + - main + + schedule: + - cron: '0 0 * * *' + + workflow_dispatch: + +env: + LLVM_CACHE_SUFFIX: "build-llvm_libraries_ex" + WASI_SDK_PATH: "/opt/wasi-sdk" + WAMR_COMMON_OPTION: + "CONFIG_INTERPRETERS_WAMR=y\\nCONFIG_INTERPRETERS_WAMR_STACKSIZE=32768\\nCONFIG_INTERPRETERS_WAMR_LOG=y\\nCONFIG_INTERPRETERS_WAMR_LIBC_BUILTIN=y\\nCONFIG_INTERPRETERS_WAMR_REF_TYPES=y\\nCONFIG_INTERPRETERS_WAMR_ENABLE_SPEC_TEST=y\\nCONFIG_INTERPRETERS_WAMR_SHARED_MEMORY=y\\nCONFIG_INTERPRETERS_WAMR_BULK_MEMORY=y\\nCONFIG_EOL_IS_LF=y\\nCONFIG_ARM_SEMIHOSTING_HOSTFS=y\\nCONFIG_ARM_SEMIHOSTING_HOSTFS_CACHE_COHERENCE=y\\nCONFIG_RISCV_SEMIHOSTING_HOSTFS=y\\nCONFIG_FS_HOSTFS=y\\nCONFIG_LIBC_FLOATINGPOINT=y\\n" + +jobs: + build_llvm_libraries: + uses: ./.github/workflows/build_llvm_libraries.yml + with: + os: "ubuntu-22.04" + arch: "ARM RISCV AArch64" + + spec_test_on_qemu: + runs-on: ubuntu-22.04 + needs: [build_llvm_libraries] + strategy: + matrix: + target_config: [ + # { + # config: "boards/arm64/qemu/qemu-armv8a/configs/nsh", + # target: "aarch64_vfp", + # fpu_type: "fp" + # }, + # { + # config: "boards/arm/imx6/sabre-6quad/configs/nsh", + # target: "thumbv7", + # fpu_type: "none" + # }, + { + config: "boards/arm/imx6/sabre-6quad/configs/nsh", + target: "thumbv7_vfp", + fpu_type: "dp" + }, + { + config: "boards/risc-v/qemu-rv/rv-virt/configs/nsh", + target: "riscv32", + fpu_type: "none" + }, + # { + # config: "boards/risc-v/qemu-rv/rv-virt/configs/nsh", + # target: "riscv32_ilp32d", + # fpu_type: "dp" + # }, + { + config: "boards/risc-v/qemu-rv/rv-virt/configs/nsh64", + target: "riscv64", + fpu_type: "none" + }, + ] + + wamr_test_option: [ + { + mode: "-t aot", + option: "CONFIG_INTERPRETERS_WAMR_AOT=y\\n" + }, + { + mode: "-t aot -X", + option: "CONFIG_INTERPRETERS_WAMR_AOT=y\\n" + }, + { + mode: "-t classic-interp", + option: "CONFIG_INTERPRETERS_WAMR_CLASSIC=y\\n" + }, + { + mode: "-t fast-interp", + option: "CONFIG_INTERPRETERS_WAMR_FAST=y\\n" + }, + ] + + exclude: + # XIP is not fully supported yet on RISCV64, some relocations can not be resolved + - target_config: { config: "boards/risc-v/qemu-rv/rv-virt/configs/nsh64" } + wamr_test_option: { mode: "-t aot -X" } + + steps: + - name: Install Utilities + run: | + sudo apt install -y kconfig-frontends-nox genromfs + + - name: Install ARM Compilers + if: startsWith(matrix.target_config.config, 'boards/arm') + run: | + sudo apt install -y gcc-arm-none-eabi + wget --quiet https://developer.arm.com/-/media/Files/downloads/gnu/11.2-2022.02/binrel/gcc-arm-11.2-2022.02-x86_64-aarch64-none-elf.tar.xz + xz -d gcc-arm-11.2-2022.02-x86_64-aarch64-none-elf.tar.xz + tar xf gcc-arm-11.2-2022.02-x86_64-aarch64-none-elf.tar + echo "$PWD/gcc-arm-11.2-2022.02-x86_64-aarch64-none-elf/bin" >> $GITHUB_PATH + + - name: Install RISC-V Compilers + if: startsWith(matrix.target_config.config, 'boards/risc-v') + run: | + curl -L https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v12.3.0-1/xpack-riscv-none-elf-gcc-12.3.0-1-linux-x64.tar.gz > riscv.tar.gz + tar xvf riscv.tar.gz + echo "$PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin" >> $GITHUB_PATH + + - name: Install WASI-SDK + run: | + curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz > wasi-sdk.tar.gz + tar xvf wasi-sdk.tar.gz + sudo mv wasi-sdk-* /opt/wasi-sdk + + - name: Checkout NuttX + uses: actions/checkout@v3 + with: + repository: apache/incubator-nuttx + ref: releases/12.3 + path: nuttx + + - name: Checkout NuttX Apps + uses: actions/checkout@v3 + with: + repository: apache/incubator-nuttx-apps + ref: releases/12.3 + path: apps + + - name: Checkout WAMR + uses: actions/checkout@v3 + with: + repository: ${{ github.repository }} + path: apps/interpreters/wamr/wamr + + - name: Get LLVM libraries + if: contains(matrix.wamr_test_option.mode, 'aot') + id: retrieve_llvm_libs + uses: actions/cache@v3 + with: + path: | + ./core/deps/llvm/build/bin + ./core/deps/llvm/build/include + ./core/deps/llvm/build/lib + ./core/deps/llvm/build/libexec + ./core/deps/llvm/build/share + key: ${{ needs.build_llvm_libraries.outputs.cache_key }} + + - name: Quit if cache miss + if: contains(matrix.wamr_test_option.mode, 'aot') && steps.retrieve_llvm_libs.outputs.cache-hit != 'true' + run: echo "::error::can not get prebuilt llvm libraries" && exit 1 + + - name: Copy LLVM + if: contains(matrix.wamr_test_option.mode, 'aot') + run: cp -r core/deps/llvm apps/interpreters/wamr/wamr/core/deps/llvm + + - name: Enable WAMR for NuttX + run: | + find nuttx/boards -name defconfig | xargs sed -i '$a\${{ env.WAMR_COMMON_OPTION }}' + + - name: Enable WAMR Interpreter for NuttX + run: | + find nuttx/boards -name defconfig | xargs sed -i '$a\${{ matrix.wamr_test_option.option }}' + + - name: Disable FPU for NuttX + if: matrix.target_config.fpu_type == 'none' + run: | + find nuttx/boards -name defconfig | xargs sed -i '$a\# CONFIG_ARCH_FPU is not set\n' + + - name: Disable DPFPU for NuttX + if: matrix.target_config.fpu_type == 'fp' + run: | + find nuttx/boards -name defconfig | xargs sed -i '$a\# CONFIG_ARCH_DPFPU is not set\n' + + - name: Build wamrc + if: contains(matrix.wamr_test_option.mode, 'aot') + working-directory: apps/interpreters/wamr/wamr/wamr-compiler + run: | + cmake -Bbuild . + cmake --build build + + - name: Build + id: build_firmware + run: | + cd nuttx + tools/configure.sh ${{ matrix.target_config.config }} + make -j$(nproc) + echo "firmware=$PWD/nuttx" >> $GITHUB_OUTPUT + + - name: Install QEMU for ARM + if: startsWith(matrix.target_config.config, 'boards/arm') + run: | + curl -L https://github.com/xpack-dev-tools/qemu-arm-xpack/releases/download/v7.1.0-1/xpack-qemu-arm-7.1.0-1-linux-x64.tar.gz > xpack-qemu-arm.tar.gz + tar xvf xpack-qemu-arm.tar.gz + echo $PWD/xpack-qemu-arm-7.1.0-1/bin >> $GITHUB_PATH + + - name: Install QEMU for RISC-V + if: startsWith(matrix.target_config.config, 'boards/risc-v') + run: | + curl -L https://github.com/xpack-dev-tools/qemu-riscv-xpack/releases/download/v7.1.0-1/xpack-qemu-riscv-7.1.0-1-linux-x64.tar.gz > xpack-qemu-riscv.tar.gz + tar xvf xpack-qemu-riscv.tar.gz + echo PATH=$PATH:$PWD/xpack-qemu-riscv-7.1.0-1/bin >> $GITHUB_PATH + + - name: Test + run: | + cd apps/interpreters/wamr/wamr/tests/wamr-test-suites + ./test_wamr.sh -s spec ${{ matrix.wamr_test_option.mode }} -m ${{ matrix.target_config.target }} -b -Q -P -F ${{ steps.build_firmware.outputs.firmware }} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/.gitignore similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/.gitignore rename to lib/wasm-micro-runtime-WAMR-1.3.0/.gitignore index a4889fb7f5f..99f1a502e45 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/.gitignore +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/.gitignore @@ -1,4 +1,5 @@ .cache +.clangd .vs .vscode .venv diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/ATTRIBUTIONS.md b/lib/wasm-micro-runtime-WAMR-1.3.0/ATTRIBUTIONS.md similarity index 92% rename from lib/wasm-micro-runtime-WAMR-1.2.2/ATTRIBUTIONS.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/ATTRIBUTIONS.md index 0cf62f499e1..c772b96911d 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/ATTRIBUTIONS.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/ATTRIBUTIONS.md @@ -16,12 +16,13 @@ WAMR project reused some components from other open source project: - **asmjit**: for the Fast JIT x86-64 codegen implementation - **zydis**: for the Fast JIT x86-64 codegen implementation - **NuttX ELF headers**: used in core/iwasm/aot/debug/elf_parser.c +- **Dhrystone**: for the test benchmakr dhrystone The WAMR fast interpreter is a clean room development. We would acknowledge the inspirations by [WASM3](https://github.com/wasm3/wasm3) open source project for the approach of pre-calculated oprand stack location. | third party components | version number | latest release | vendor pages | CVE details | | --- | --- | --- | --- | --- | -| cjson | 1.7.10 | 1.7.14 | https://github.com/DaveGamble/cJSON | https://www.cvedetails.com/vendor/19164/Cjson-Project.html | +| cjson | 1.7.16 | 1.7.16 | https://github.com/DaveGamble/cJSON | https://www.cvedetails.com/vendor/19164/Cjson-Project.html | | contiki-ng (er-coap) | unspecified | 3.0 | https://github.com/contiki-os/contiki | https://www.cvedetails.com/vendor/16528/Contiki-os.html | | freebsd libm | unspecified | 13.0 | https://www.freebsd.org/ | https://www.cvedetails.com/vendor/6/Freebsd.html | | LVGL | 6.0.1 | 7.11.0 | https://lvgl.io/ | | @@ -30,11 +31,12 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the | wasmtime | unspecified | v0.26.0 | https://github.com/bytecodealliance/wasmtime | | | zephyr | unspecified | v2.5.0 | https://www.zephyrproject.org/ | https://www.cvedetails.com/vendor/19255/Zephyrproject.html | | WebAssembly debugging patch for LLDB | unspecified | unspecified | https://reviews.llvm.org/D78801 | | -| libuv | v1.42.0 | v1.44.1 | https://github.com/libuv/libuv | https://www.cvedetails.com/vendor/15402/Libuv-Project.html | +| libuv | v1.46.0 | v1.46.0 | https://github.com/libuv/libuv | https://www.cvedetails.com/vendor/15402/Libuv-Project.html | | uvwasi | unspecified | v0.0.12 | https://github.com/nodejs/uvwasi | | | asmjit | unspecified | unspecified | https://github.com/asmjit/asmjit | | | zydis | unspecified | e14a07895136182a5b53e181eec3b1c6e0b434de | https://github.com/zyantific/zydis | | | NuttX ELF headers | 72313301e23f9c2de969fb64b9a0f67bb4c284df | 10.3.0 | https://github.com/apache/incubator-nuttx | | +| Dhrystone | 2.1 | 2.1 | https://fossies.org/linux/privat/old/ | | ## Licenses @@ -81,15 +83,19 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the [LICENSE](./tests/wamr-test-suites/spec-test-script/LICENSE) ### libuv + [LICENSE](./core/iwasm/libraries/libc-uvwasi/LICENSE_LIBUV) ### uvwasi + [LICENSE](./core/iwasm/libraries/libc-uvwasi/LICENSE_UVWASI) ### asmjit + [LICENSE](./core/iwasm/fast-jit/cg/LICENSE_ASMJIT) ### zydis + [LICENSE](./core/iwasm/fast-jit/cg/LICENSE_ZYDIS) ### NuttX ELF headers @@ -97,3 +103,7 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the [LICENSE](./core/iwasm/aot/debug/LICENSE_NUTTX) [NOTICE](./core/iwasm/aot/debug/NOTICE_NUTTX) + +### Dhrystone + +[LICENSE](./tests/benchmarks/dhrystone/LICENSE) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/CODE_OF_CONDUCT.md b/lib/wasm-micro-runtime-WAMR-1.3.0/CODE_OF_CONDUCT.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/CODE_OF_CONDUCT.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/CODE_OF_CONDUCT.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/CONTRIBUTING.md b/lib/wasm-micro-runtime-WAMR-1.3.0/CONTRIBUTING.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/CONTRIBUTING.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/CONTRIBUTING.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/LICENSE b/lib/wasm-micro-runtime-WAMR-1.3.0/LICENSE similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/LICENSE rename to lib/wasm-micro-runtime-WAMR-1.3.0/LICENSE diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/ORG_CODE_OF_CONDUCT.md b/lib/wasm-micro-runtime-WAMR-1.3.0/ORG_CODE_OF_CONDUCT.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/ORG_CODE_OF_CONDUCT.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/ORG_CODE_OF_CONDUCT.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/README.md similarity index 97% rename from lib/wasm-micro-runtime-WAMR-1.2.2/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/README.md index 8cbdcf49592..dfdae2da894 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/README.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/README.md @@ -77,6 +77,7 @@ The following platforms are supported, click each link below for how to build iw - [Blog: Introduction to WAMR running modes](https://bytecodealliance.github.io/wamr.dev/blog/introduction-to-wamr-running-modes/) - [Memory usage tunning](./doc/memory_tune.md): the memory model and how to tune the memory usage - [Memory usage profiling](./doc/build_wamr.md#enable-memory-profiling-experiment): how to profile the memory usage +- [Performance tunning](./doc/perf_tune.md): how to tune the performance - [Benchmarks](./tests/benchmarks): checkout these links for how to run the benchmarks: [PolyBench](./tests/benchmarks/polybench), [CoreMark](./tests/benchmarks/coremark), [Sightglass](./tests/benchmarks/sightglass), [JetStream2](./tests/benchmarks/jetstream) - [Performance and footprint data](https://github.com/bytecodealliance/wasm-micro-runtime/wiki/Performance): the performance and footprint data @@ -91,8 +92,10 @@ The current TSC members: - [lum1n0us](https://github.com/lum1n0us) - **Liang He**, - [no1wudi](https://github.com/no1wudi) **Qi Huang**, - [qinxk-inter](https://github.com/qinxk-inter) - **Xiaokang Qin**, +- [ttrenner ](https://github.com/ttrenner) - **Trenner, Thomas**, - [wei-tang](https://github.com/wei-tang) - **Wei Tang**, - [wenyongh](https://github.com/wenyongh) - **Wenyong Huang**, +- [woodsmc](https://github.com/woodsmc) - **Woods, Chris**, - [xujuntwt95329](https://github.com/xujuntwt95329) - **Jun Xu**, - [xwang98](https://github.com/xwang98) - **Xin Wang**, (chair) - [yamt](https://github.com/yamt) - **Takashi Yamamoto**, diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/RELEASE_NOTES.md b/lib/wasm-micro-runtime-WAMR-1.3.0/RELEASE_NOTES.md similarity index 52% rename from lib/wasm-micro-runtime-WAMR-1.2.2/RELEASE_NOTES.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/RELEASE_NOTES.md index d6308ce671e..fbb97f5d756 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/RELEASE_NOTES.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/RELEASE_NOTES.md @@ -1,3 +1,308 @@ +## WAMR-1.3.0 + +### Breaking Changes +- Abstract POSIX filesystem functions (#2585) + - Change API wasm_runtime_set_wasi_args_ex's arguments + `int stdinfd/stdoutfd/stderrfd` to `int64_t stdinfd/stdoutfd/stderrfd` +- core/iwasm: Support mapped file system access on non-libuv WASI (#2628) + - Enable mapping host directories to guest directories by parsing + the `map_dir_list` argument in API `wasm_runtime_init_wasi` for libc-wasi +- Support muti-module for AOT mode (#2482) + - Add argument `package_type_t module_type` for module_reader callback +- Generate jitdump to support linux perf for LLVM JIT (#2788) + - Add a field `bool linux_perf_support` in RuntimeInitArgs +- Remove provision of unnecessary fd rights (#2579) +- libc-wasi: Conditionally support SYNC flags (#2581) + +### New Features +- Support muti-module for AOT mode (#2482) +- Implement libc-wasi for Windows platform (#2740) +- Implement module instance context APIs (#2436) +- Implement async termination of blocking thread (#2516) +- Generate jitdump to support linux perf for LLVM JIT (#2788) +- Add Cosmopolitan Libc Platform (#2598) + +### Bug Fixes +- sgx-ra: Disable the building of samples (#2507) +- Handle a return from wasi _start function correctly (#2529) +- fd_object_release: Preserve errno (#2535) +- Fix build error with ancient GCC (4.8) (#2553) +- Fix compiling error for RT-Thread (#2569) +- Fix potential unaligned store issue when extra return value is v128 (#2583) +- Fix loader push_pop_frame_ref_offset (#2590) +- Fix compilation error on Android platform (#2594) +- Ignore handling SIG_DFL/SIG_IGN for previous sig action (#2589) +- Fix nightly run sanitizer error in Fast JIT (#2601) +- Check ValueKind before extracting a constant int value (#2595) +- Patch implementations of vfbinop(min,max,pmin,pax) (#2584) +- Improve stack trace dump and fix coding guideline CI (#2599) +- aot_resolve_stack_sizes: Disable the size check for now (#2608) +- Remove module instance from hashmap in wasi_nn_destroy (#2613) +- Fix label index out-of-range references in op_br_table_cache (#2615) +- Fix compilation of shift opcodes on x86_64 and i386 architectures (#2619) +- Fix potential issue in aot compiler when translating block opcodes (#2622) +- Use another default pipeline when opt-level is 0 (#2624) +- Fix AOT shift operations for indirect constants (#2627) +- Fix fast-interp "pre-compiled label offset out of range" issue (#2659) +- Revert "Strip static and shared libraries of iwasm to reduce the binary size (#2431)" (#2669) +- Fix windows compilation on C++20 (#2670) +- Fix fast-jit f32/f64 truncate to i32/i64 (#2671) +- Fix use getrandom on cosmopolitan libc (#2674) +- Fix repeatedly initialize shared memory data and protect the memory's fields (#2673) +- Minor fixes for Go bindings (#2676) +- Fix issues reported by Coverity (#2681) +- Add more buffer boundary checks in wasm loader (#2734) +- Grab cluster->lock when modifying exec_env->module_inst (#2685) +- Fix CMSIS import with Zephyr 3.4+ (#2744) +- Fix log messages in Zephyr example (#2761) +- Fix fast-jit callnative translation (#2765) +- aot compiler: Disable musttail for thumb (#2771) +- Fix data/elem drop (#2747) +- Fix formatting in aot_dump_perf_profiling (#2796) +- Fix formatting in wasm_dump_perf_profiling (#2799) +- Fix memory.init opcode issue in fast-interp (#2798) +- aot compiler: Fix handle next reachable if block (#2793) +- Fix configurable bounds checks typo (#2809) +- Attestation: Free JSON from the Wasm module heap (#2803) +- Update Zephyr support to v3.5.0 and make instructions generic to boards (#2805) +- Return error when shutdown() fails (#2801) +- iwasm: Print help when meeting unknown cmd options (#2824) +- Fix fast-jit accessing shared memory's fields issue (#2841) +- Fix wasm loader handle op_br_table and op_drop (#2864) +- Fix block with type issue in fast interp (#2866) +- Fix float argument handling for riscv32 ilp32d (#2871) +- Portably handle fd_advise on directory fd (#2875) +- Fix sample basic intToStr was called with wrong length (#2876) + +### Enhancements +- Implement strict validation of thread IDs according to the specification (#2521) +- Stop abusing shared memory lock to protect exception (#2509) +- Implement os_usleep for posix (#2517) +- set_exception_visitor: Remove the special case for wasi proc exit (#2525) +- Revert "Return error when exception was raised after main thread finishes" (#2524) +- libc-wasi: Remove unused code (#2528) +- Add callback to handle memory.grow failures (#2522) +- Add context to enlarge memory error callback (#2546) +- Add ARM aeabi symbol for clearing memory content in a specific range (#2531) +- Unifdef -U WASMTIME_SSP_STATIC_CURFDS (#2533) +- Fix typo for IP address buffer (#2532) +- Add an API to terminate instance (#2538) +- Add user to enlarge memory error callback (#2546) +- runtest.py: Show accurate case amount in summary (#2549) +- Allow using custom signal handler from non-main thread (#2551) +- Return __WASI_EINVAL from fd_prestat_dir_name (#2580) +- Support AOT compiler with LLVM 17 (#2567) +- Add support for closing/renumbering preopen fds (#2578) +- Enable AOT usage on M1 mac (#2618) +- core/iwasm: Support mapped file system access on non-libuv WASI (#2628) +- Enable MASM automatically in runtime_lib.cmake (#2634) +- Abstract POSIX filesystem functions (#2585) +- Implement wasi clock_time/clock_res get (#2637) +- Fix several typo/warning/unused-code issues (#2655) +- Partial windows filesystem implementation (#2657) +- Apply no_sanitize_address for clang compiler in several places (#2663) +- Refactor clock functions to use WASI types (#2666) +- Refine lock/unlock shared memory (#2682) +- Fix several AOT compiler issues (#2697) +- Fix AOT compiler simd shift opcodes (#2715) +- Fix invalid use of jit_reg_is_const_val in fast-jit (#2718) +- Use user defined malloc/free functions for user defined memory allocator (#2717) +- Move WASI types into separate header (#2724) +- Provide default vprintf on UWP (#2725) +- Fix typo in Zephyr simple example (#2738) +- Fix switch-case fallthrough compilation warning (#2753) +- Add eabihf ABI support and set vendor-sys of bare-metal targets (#2745) +- Return uint32 from WASI functions (#2749) +- Add compilation flag to enable/disable heap corruption check (#2766) +- Extend os_mmap to support map file from fd (#2763) +- Fix printing ref.extern addresses in wasm_application.c (#2774) +- Remove unused JitBitmap (#2775) +- Use next generation crypto API on Windows (#2769) +- More precise help info of enabled targets for wamrc (#2783) +- Refine atomic operation flags in bh_atomic.h (#2780) +- Fix comment in WAMR_MEM_DUAL_BUS_MIRROR (#2791) +- Fix return type in wasm_loader_get_custom_section (#2794) +- Add support for custom sections in nuttx (#2795) +- Change is_shared_memory type from bool to uint8 (#2800) +- Fix typos in zephyr platform struct descriptions (#2818) +- Access linear memory size atomically (#2834) +- Output warning and quit if import/export name contains '\00' (#2806) +- Use wasm_config_t to pass private configuration to wasm_engine_new (#2837) +- core/iwasm/interpreter/wasm_loader.c: remove an extra validation (#2845) +- Don't add "+d" to riscv cpu features if already given (#2855) +- Fix compilation warnings on Windows (#2868) + +### Others +- Add mutex stress test (#2472) +- Add unit tests for the tid allocator (#2519) +- Add support for running tests on apple M1 macs (#2554) +- export_native_api.md: Add a note about thread termination (#2572) +- test_wamr.sh: Print a bit more meaningful message (#2574) +- run_wasi_tests.sh: Provide stdin by ourselves (#2576) +- Fix a few issues in "run_wasi_tests.sh: provide stdin by ourselves" (#2582) +- Fix compile error of tsf benchmark (#2588) +- test_wamr.sh: Bump wasi-testsuite version (#2568) +- samples/inst-context-threads: Add a brief explanation (#2592) +- doc/memory_tune.md: "remove malloc" hack is not relevant to wasi-threads (#2603) +- Refactor stress tests to make them runnable in reactor mode (#2614) +- Run rust tests from wasi-testsuite (#2484) +- spec-test-script: Fix NaN comparision between v128 values (#2605) +- CI: Enable testing AOT multi-module feature (#2621) +- Vote for nomination of Woods, Chris and Trenner, Thomas as TSC members (#2638) +- Add tsan for fast interp and aot (#2679) +- Enable WASI tests on Windows CI (#2699) +- docs: Fix typo in export native APIs doc (#2750) +- Update RISC-V compilers in Nuttx compilation CI and spec test CI (#2756) +- Enable more LLVM backends for the release wamrc binary (#2778) +- Disable FPU in NuttX spec test (#2781) +- Fix broken links in app-mgr README.md (#2786) +- Fix build error of libsodium benchmark (#2792) +- Fix wamr-test-suites script for macos (#2819) +- Run spec test for classic/fast-interp in NuttX CI (#2817) +- test_wamr.sh: Don't bother to build shared library (#2844) +- doc/build_wamr.md: Fix links to RISC-V named ABIs (#2852) +- Fix typos of CIDR in docs and help text (#2851) +- Enable spectest on riscv64 (#2843) +- Update FPU configuration in spec_test_on_nuttx.yml (#2856) + +--- + +## WAMR-1.2.3 + +### Breaking Changes +- Increase default native stack size (#2332) + +### New Features +- Implement the segue optimization for LLVM AOT/JIT (#2230) +- Implement AOT static PGO (#2243) +- Enable static PGO for Linux SGX (#2270) +- Add Rust Formatters to Debugger (Vector, Map etc.) (#2219) + +### Bug Fixes +- The Python language-binding needs python>=3.9 (#2228) +- aot_compile_op_call: Remove a wrong optimization (#2233) +- Fix typo in samples/ref-types (#2236) +- Update thread proposal ignore cases (#2246) +- Disable writting GS register on linux-sgx platform (#2255) +- Fix compile error of wamrc with llvm-13/llvm-14 (#2261) +- aot/jit: Set module layout (#2260) +- Fix build error with LLVM 16 (#2259) +- spec-test-script: Disable conversions.wast on i386 (#2269) +- Fix a heap corruption bug in ems realloc (#2279) +- Fix fast-interp issue of LAST_OP_OUTPUT_I32/64 check (#2295) +- Fix wamrc build issues with LLVM 13 and LLVM 16 (#2313) +- aot: Move stack_sizes table to a dedicated section (#2317) +- product-mini/platforms/linux: Mark vmlib POSITION_INDEPENDENT_CODE (#2323) +- aot: Avoid possible relocations around "stack_sizes" for XIP mode (#2322) +- Avoid switch lowering to lookup tables for XIP (#2339) +- Fix typo in zephyr's Dockerfile.old (#2354) +- Fix typo (dwarf) in the codebase (#2367) +- Implement suspend flags as atomic variable (#2361) +- Fix llvm jit failed to lookup aot_stack_sizes symbol issue (#2384) +- Fix some check issues on table operations (#2392) +- Fix ExpandMemoryOpPass doesn't work properly (#2399) +- Fix non-builtin BH_ATOMIC_32_FETCH_OR and BH_ATOMIC_32_FETCH_AND (#2400) +- Fix wasi-sockets tests (#2389) +- Fix result arity check on select_t opcode (#2406) +- Re-organize intrinsics in aot_reloc_riscv.c to fix some FPU issues (#2414) +- Fix lib-pthread issues (#2410) +- Fix typo in test_wamr.sh (#2421) +- Fix memory sharing (#2415) +- wasm_export.h: Fix struct wasm_val_t (#2435) +- Fix typos in wamrc print_help() (#2442) +- iwasm: Fix native lib cleanup after error occurs (#2443) +- Correct --heap-size option in messages (#2458) +- wasm_instantiate: Fix a potential integer overflow issue (#2459) +- Fix windows link error and clear windows warnings (#2463) +- aot: Disable musttail for mips (#2457) +- Fix opcode overwrite issue in fast interp (#2476) +- wamrc: Fix windows relocation to `aot_func_internal#n` (#2474) +- Fix windows AOT hw bound check (#2475) +- Fix typo in aot_emit_aot_file.c (#2478) + +### Enhancements +- A few changes related to WAMRC_LLC_COMPILER (#2218) +- Enhance linux-sgx CI (#2102) +- Add asan and ubsan to WAMR CI (#2161) +- Update doc on WAMR_DISABLE_HW_BOUND_CHECK 32-bit (#2262) +- wamrc: Add an incompatibility note in the help message (#2276) +- Add cmake variable to disable writing gs register (#2284) +- Make hmu_tree_node 4 byte aligned to reduce compiler warning (#2268) +- Appease unused warning on min_uint64 (#2277) +- Fix format warning by PRIu32 in [wasm|aot] dump call stack (#2251) +- Fix a compile warning due to missing include (#2293) +- Fix dockerfile linter warnings (#2291) +- Enable windows x86-32 AOT relocations (#2285) +- wamr-ide: Add vscode extension tests (#2292) +- AOT/JIT native stack bound check improvement (#2244) +- Add retries to flaky step in nightly run CI (#2306) +- Use system libuv if available (#1861) +- wasi-nn: Simplify cmake and headers' location (#2308) +- wasi-nn: Improve tests paths for local dev (#2309) +- aot: Implement a few more relocation types for riscv (#2318) +- wasi-nn: Add support of wasi-nn as shared lib (#2310) +- Add a few more assertions on structures to which aot abi is sensitive (#2326) +- Fix sanitizer errors in posix socket (#2331) +- Add "--xip" option for wamrc (#2336) +- Add "--enable-llvm-passes=" option to wamrc (#2335) +- Make memory access boundary check behavior configurable (#2289) +- Migrate ExpandMemoryOpPass to llvm new pass manager (#2334) +- Allow defining hints without exact socket type or address family (#2337) +- wamrc: Warn on text relocations for XIP (#2340) +- Add scripts to validate lldb source debugger (#2150) +- Add docker file to fix Zephy ESP32 linking issue (#2314) +- Add "--native-lib=" option to wamrc (#2342) +- Fix unused warnings on disable_bounds_checks (#2347) +- Add "--enable-builtin-intrinsics=" option to wamrc (#2341) +- nuttx: Add a kconfig for wasi-threads (#2343) +- iwasm: Disable app heap by default if wasi is enabled (#2346) +- Fix some static scan issues (#2362) +- Bring up WAMR on esp32-s3 device (#2348) +- ESP-IDF platform supports to load AOT to PSRAM and run it (#2385) +- Add hadolint CI for Dockerfile linting (#2387) +- Move generic parts of wasm_suspend_flags.h to bh_atomic.h (#2393) +- bh_atomic.h: Add comments (#2398) +- bh_atomic.h: Add BH_ATOMIC_32_FETCH_ADD/BH_ATOMIC_32_FETCH_SUB (#2408) +- Update libuv version to v1.46.0 (#2405) +- Remove a few unused functions (#2409) +- Add initial stress test (#2364) +- Move wasm_runtime_destroy_wasi and wasi_nn_destroy calls together (#2418) +- embed_wamr.md: Improvements about threads (#2420) +- Add runtime inited checks in Enclave command handlings to improve security (#2416) +- Add some relocation symbols for xtensa target (#2422) +- Remove unnecessary and extra zero length check in mem functions' macro (#2428) +- Introduce WASMModuleInstanceExtraCommon (#2429) +- Strip static and shared libraries of iwasm to reduce the binary size (#2431) +- Auto-check wrgsbase in cmake script (#2437) +- iwasm: call native lib init/deinit if exists (#2439) +- wasi-nn: Support uint8 quantized networks (#2433) +- Implement `wasm_externref_objdel` and `wasm_externref_set_cleanup` (#2455) +- wasi-nn: Improve TPU support (#2447) +- wamr-python: Enable debugging WASM and grant dir access (#2449) +- Build wasi-libc from source in WAMR CI (#2465) +- wamrc: More friendly to print help info (#2451) +- Add another wamr test (#2411) +- Fix issues reported by Coverity and clear windows warnings (#2467) +- Clone the input binary during wasm_module_validate (#2483) + +### Others +- Nuttx CI: Ignore the expired certificate for riscv gcc toolchain (#2222) +- core/iwasm/compilation: constify a bit (#2223) +- Bump requests from 2.28.2 to 2.31.0 in /build-scripts (#2229) +- dwarf_extractor: Constify a bit (#2278) +- AOTFuncContext: Remove a stale comment (#2283) +- Add performance tunning document (#2286) +- Reduce CI jobs number (#2296) +- CI: Update used node version to 16 (#2303) +- Update Docker image for latest version of external libraries & tools (#2374) +- Upgrade cJSON version to v1.7.16 (#2404) +- Upgrade XNNPACK workload (#2394) +- Build more benchmarks in workload XNNPACK (#2417) +- Upgrade SGX-RA integration for 0.1.2 and Ubuntu 20.04 (#2454) +- Add sample pre-commit hook (#2470) + +--- + ## WAMR-1.2.2 ### Breaking Changes diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/SConscript similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/SConscript rename to lib/wasm-micro-runtime-WAMR-1.3.0/SConscript diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/SECURITY.md b/lib/wasm-micro-runtime-WAMR-1.3.0/SECURITY.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/SECURITY.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/SECURITY.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/TSC_Charter.md b/lib/wasm-micro-runtime-WAMR-1.3.0/TSC_Charter.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/TSC_Charter.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/TSC_Charter.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/.gitignore similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/.gitignore rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/.gitignore diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/package-lock.json b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/package-lock.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/package-lock.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/package-lock.json diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/package.json b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/package.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/package.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/package.json diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/event_publisher.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/event_publisher.ts similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/event_publisher.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/event_publisher.ts diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/event_subscriber.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/event_subscriber.ts similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/event_subscriber.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/event_subscriber.ts diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/request_handler.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/request_handler.ts similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/request_handler.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/request_handler.ts diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/request_sender.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/request_sender.ts similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/request_sender.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/request_sender.ts diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/timer.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/timer.ts similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/timer.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/timer.ts diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/tsconfig.json b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/tsconfig.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/samples/tsconfig.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/samples/tsconfig.json diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/wamr_app_lib/console.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/wamr_app_lib/console.ts similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/wamr_app_lib/console.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/wamr_app_lib/console.ts diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/wamr_app_lib/request.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/wamr_app_lib/request.ts similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/wamr_app_lib/request.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/wamr_app_lib/request.ts diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/wamr_app_lib/timer.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/wamr_app_lib/timer.ts similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/wamr_app_lib/timer.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/wamr_app_lib/timer.ts diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/wamr_app_lib/tsconfig.json b/lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/wamr_app_lib/tsconfig.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/assembly-script/wamr_app_lib/tsconfig.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/assembly-script/wamr_app_lib/tsconfig.json diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/SConscript similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/SConscript rename to lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/SConscript diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/SConscript_config b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/SConscript_config similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/SConscript_config rename to lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/SConscript_config diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/build_llvm.py b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/build_llvm.py similarity index 96% rename from lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/build_llvm.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/build_llvm.py index 3957f4b8950..e5036e5cae8 100755 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/build_llvm.py +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/build_llvm.py @@ -55,22 +55,26 @@ def build_llvm(llvm_dir, platform, backends, projects, use_clang=False, extra_fl "-DLLVM_APPEND_VC_REV:BOOL=ON", "-DLLVM_BUILD_EXAMPLES:BOOL=OFF", "-DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF", - "-DLLVM_BUILD_TESTS:BOOL=OFF", - "-DLLVM_CCACHE_BUILD:BOOL=ON", "-DLLVM_ENABLE_BINDINGS:BOOL=OFF", "-DLLVM_ENABLE_IDE:BOOL=OFF", "-DLLVM_ENABLE_LIBEDIT=OFF", "-DLLVM_ENABLE_TERMINFO:BOOL=OFF", - "-DLLVM_ENABLE_ZLIB:BOOL=OFF", + "-DLLVM_ENABLE_ZLIB:BOOL=ON", "-DLLVM_INCLUDE_BENCHMARKS:BOOL=OFF", "-DLLVM_INCLUDE_DOCS:BOOL=OFF", "-DLLVM_INCLUDE_EXAMPLES:BOOL=OFF", "-DLLVM_INCLUDE_UTILS:BOOL=OFF", "-DLLVM_INCLUDE_TESTS:BOOL=OFF", - "-DLLVM_BUILD_TESTS:BOOL=OFF", "-DLLVM_OPTIMIZED_TABLEGEN:BOOL=ON", ] + # ccache is not available on Windows + if not "windows" == platform: + LLVM_COMPILE_OPTIONS.append("-DLLVM_CCACHE_BUILD:BOOL=ON") + # perf support is available on Linux only + if "linux" == platform: + LLVM_COMPILE_OPTIONS.append("-DLLVM_USE_PERF:BOOL=ON") + # use clang/clang++/lld. but macos doesn't support lld if not sys.platform.startswith("darwin") and use_clang: if shutil.which("clang") and shutil.which("clang++") and shutil.which("lld"): @@ -255,7 +259,7 @@ def main(): "branch": "release/15.x", }, "xtensa": { - "repo": "https://github.com/espressif/llvm-project.git", + "repo": "https://github.com/espressif/llvm-project.git", "repo_ssh": "git@github.com:espressif/llvm-project.git", "branch": "xtensa_release_15.x", }, @@ -281,13 +285,13 @@ def main(): commit_hash = query_llvm_version(llvm_info) print(commit_hash) return commit_hash is not None - + repo_addr = llvm_info["repo"] if os.environ.get('USE_GIT_SSH') == "true": repo_addr = llvm_info["repo_ssh"] else: print("To use ssh for git clone, run: export USE_GIT_SSH=true") - + llvm_dir = clone_llvm(deps_dir, repo_addr, llvm_info["branch"]) if ( build_llvm( diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/config_common.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/config_common.cmake similarity index 78% rename from lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/config_common.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/config_common.cmake index ea8ad1f3204..e73ebc85f1f 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/config_common.cmake +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/config_common.cmake @@ -122,11 +122,38 @@ if (WAMR_BUILD_JIT EQUAL 1) if (CXX_SUPPORTS_REDUNDANT_MOVE_FLAG) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-redundant-move") endif () + # Enable exporting symbols after llvm-17, or LLVM JIT may run failed + # with `llvm_orc_registerEHFrameSectionWrapper` symbol not found error + if (${LLVM_PACKAGE_VERSION} VERSION_GREATER_EQUAL "17.0.0") + set (CMAKE_ENABLE_EXPORTS 1) + endif () endif () else () unset (LLVM_AVAILABLE_LIBS) endif () +# Sanitizers + +set(WAMR_BUILD_SANITIZER $ENV{WAMR_BUILD_SANITIZER}) + +if (NOT DEFINED WAMR_BUILD_SANITIZER) + set(WAMR_BUILD_SANITIZER "") +elseif (WAMR_BUILD_SANITIZER STREQUAL "ubsan") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all -fno-sanitize=alignment" ) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined") +elseif (WAMR_BUILD_SANITIZER STREQUAL "asan") + if (NOT WAMR_BUILD_JIT EQUAL 1) + set (ASAN_OPTIONS "verbosity=2 debug=true ") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fno-omit-frame-pointer -fsanitize=address -fno-sanitize-recover=all" ) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") + endif() +elseif (WAMR_BUILD_SANITIZER STREQUAL "tsan") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fno-omit-frame-pointer -fsanitize=thread -fno-sanitize-recover=all" ) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread") +elseif (NOT (WAMR_BUILD_SANITIZER STREQUAL "") ) + message(SEND_ERROR "Unsupported sanitizer: ${WAMR_BUILD_SANITIZER}") +endif() + ######################################## message ("-- Build Configurations:") @@ -251,6 +278,13 @@ else () add_definitions (-DWASM_DISABLE_STACK_HW_BOUND_CHECK=0) endif () endif () +if (WAMR_DISABLE_WAKEUP_BLOCKING_OP EQUAL 1) + add_definitions (-DWASM_DISABLE_WAKEUP_BLOCKING_OP=1) + message (" Wakeup of blocking operations disabled") +else () + add_definitions (-DWASM_DISABLE_WAKEUP_BLOCKING_OP=0) + message (" Wakeup of blocking operations enabled") +endif () if (WAMR_BUILD_SIMD EQUAL 1) if (NOT WAMR_BUILD_TARGET MATCHES "RISCV64.*") add_definitions (-DWASM_ENABLE_SIMD=1) @@ -337,16 +371,16 @@ endif () if (WAMR_BUILD_WASI_NN EQUAL 1) message (" WASI-NN enabled") add_definitions (-DWASM_ENABLE_WASI_NN=1) - if (WASI_NN_ENABLE_GPU EQUAL 1) + if (WAMR_BUILD_WASI_NN_ENABLE_GPU EQUAL 1) message (" WASI-NN: GPU enabled") - add_definitions (-DWASI_NN_ENABLE_GPU=1) + add_definitions (-DWASM_ENABLE_WASI_NN_GPU=1) endif () - if (WAMR_BUILD_WASI_NN_ENABLE_EXT EQUAL 1) + if (WAMR_BUILD_WASI_NN_ENABLE_EXTERNAL_DELEGATE EQUAL 1) message (" WASI-NN: External Delegation enabled") - add_definitions (-DWASI_NN_ENABLE_EXTERNAL_DELEGATE=1) + add_definitions (-DWASM_ENABLE_WASI_NN_EXTERNAL_DELEGATE=1) endif () - if (DEFINED WASI_NN_EXT_DELEGATE_PATH) - add_definitions (-DWASI_NN_EXT_DELEGATE_PATH="${WASI_NN_EXT_DELEGATE_PATH}") + if (DEFINED WAMR_BUILD_WASI_NN_EXTERNAL_DELEGATE_PATH) + add_definitions (-DWASM_WASI_NN_EXTERNAL_DELEGATE_PATH="${WAMR_BUILD_WASI_NN_EXTERNAL_DELEGATE_PATH}") endif () endif () if (WAMR_BUILD_ALLOC_WITH_USER_DATA EQUAL 1) @@ -356,6 +390,10 @@ if (WAMR_BUILD_WASM_CACHE EQUAL 1) add_definitions (-DWASM_ENABLE_WASM_CACHE=1) message (" Wasm files cache enabled") endif () +if (WAMR_BUILD_MODULE_INST_CONTEXT EQUAL 1) + add_definitions (-DWASM_ENABLE_MODULE_INST_CONTEXT=1) + message (" Module instance context enabled") +endif () if (WAMR_BUILD_GC_HEAP_VERIFY EQUAL 1) add_definitions (-DWASM_ENABLE_GC_VERIFY=1) message (" GC heap verification enabled") @@ -366,3 +404,39 @@ if ("$ENV{COLLECT_CODE_COVERAGE}" STREQUAL "1" OR COLLECT_CODE_COVERAGE EQUAL 1) add_definitions (-DCOLLECT_CODE_COVERAGE) message (" Collect code coverage enabled") endif () +if (WAMR_BUILD_STATIC_PGO EQUAL 1) + add_definitions (-DWASM_ENABLE_STATIC_PGO=1) + message (" AOT static PGO enabled") +endif () +if (WAMR_DISABLE_WRITE_GS_BASE EQUAL 1) + add_definitions (-DWASM_DISABLE_WRITE_GS_BASE=1) + message (" Write linear memory base addr to x86 GS register disabled") +elseif (WAMR_BUILD_TARGET STREQUAL "X86_64" + AND WAMR_BUILD_PLATFORM STREQUAL "linux") + set (TEST_WRGSBASE_SOURCE "${CMAKE_BINARY_DIR}/test_wrgsbase.c") + file (WRITE "${TEST_WRGSBASE_SOURCE}" " + #include + #include + int main() { + uint64_t value; + asm volatile (\"wrgsbase %0\" : : \"r\"(value)); + printf(\"WRGSBASE instruction is available.\\n\"); + return 0; + }") + # Try to compile and run the test program + try_run (TEST_WRGSBASE_RESULT + TEST_WRGSBASE_COMPILED + ${CMAKE_BINARY_DIR}/test_wrgsbase + SOURCES ${TEST_WRGSBASE_SOURCE} + CMAKE_FLAGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + ) + #message("${TEST_WRGSBASE_COMPILED}, ${TEST_WRGSBASE_RESULT}") + if (NOT TEST_WRGSBASE_RESULT EQUAL 0) + add_definitions (-DWASM_DISABLE_WRITE_GS_BASE=1) + message (" Write linear memory base addr to x86 GS register disabled") + endif () +endif () +if (WAMR_CONFIGUABLE_BOUNDS_CHECKS EQUAL 1) + add_definitions (-DWASM_CONFIGURABLE_BOUNDS_CHECKS=1) + message (" Configurable bounds checks enabled") +endif () diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/esp-idf/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/esp-idf/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/esp-idf/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/esp-idf/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/esp-idf/wamr/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/esp-idf/wamr/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/esp-idf/wamr/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/esp-idf/wamr/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/involve_boringssl.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/involve_boringssl.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/involve_boringssl.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/involve_boringssl.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/lldb-wasm.patch b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/lldb_wasm.patch similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/lldb-wasm.patch rename to lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/lldb_wasm.patch index d6044e3a3ee..83221ef6ac6 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/lldb-wasm.patch +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/lldb_wasm.patch @@ -1,5 +1,44 @@ +diff --git a/lldb/bindings/CMakeLists.txt b/lldb/bindings/CMakeLists.txt +index 9759b069fdc4..25b427f8bcf2 100644 +--- a/lldb/bindings/CMakeLists.txt ++++ b/lldb/bindings/CMakeLists.txt +@@ -26,8 +26,6 @@ set(SWIG_COMMON_FLAGS + -features autodoc + -I${LLDB_SOURCE_DIR}/include + -I${CMAKE_CURRENT_SOURCE_DIR} +- -D__STDC_LIMIT_MACROS +- -D__STDC_CONSTANT_MACROS + ${DARWIN_EXTRAS} + ) + +diff --git a/lldb/bindings/interfaces.swig b/lldb/bindings/interfaces.swig +index c9a6d0f06056..021c7683d170 100644 +--- a/lldb/bindings/interfaces.swig ++++ b/lldb/bindings/interfaces.swig +@@ -1,8 +1,5 @@ + /* Various liblldb typedefs that SWIG needs to know about. */ + #define __extension__ /* Undefine GCC keyword to make Swig happy when processing glibc's stdint.h. */ +-/* The ISO C99 standard specifies that in C++ implementations limit macros such +- as INT32_MAX should only be defined if __STDC_LIMIT_MACROS is. */ +-#define __STDC_LIMIT_MACROS + %include "stdint.i" + + %include "lldb/lldb-defines.h" +diff --git a/lldb/bindings/python/python-typemaps.swig b/lldb/bindings/python/python-typemaps.swig +index b1ace4ff3b1e..5f8f4aa678c4 100644 +--- a/lldb/bindings/python/python-typemaps.swig ++++ b/lldb/bindings/python/python-typemaps.swig +@@ -439,7 +439,7 @@ bool SetNumberFromPyObject(double &number, PyObject *obj) { + + %typemap(out) lldb::FileSP { + $result = nullptr; +- lldb::FileSP &sp = $1; ++ const lldb::FileSP &sp = $1; + if (sp) { + PythonFile pyfile = unwrapOrSetPythonException(PythonFile::FromFile(*sp)); + if (!pyfile.IsValid()) diff --git a/lldb/include/lldb/Breakpoint/Breakpoint.h b/lldb/include/lldb/Breakpoint/Breakpoint.h -index f2e2a0d22..426d1129b 100644 +index f2e2a0d22784..426d1129bd10 100644 --- a/lldb/include/lldb/Breakpoint/Breakpoint.h +++ b/lldb/include/lldb/Breakpoint/Breakpoint.h @@ -9,6 +9,7 @@ @@ -11,7 +50,7 @@ index f2e2a0d22..426d1129b 100644 #include #include diff --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h -index dd7100c46..97d70daad 100644 +index dd7100c4616c..97d70daadbdc 100644 --- a/lldb/include/lldb/Core/Module.h +++ b/lldb/include/lldb/Core/Module.h @@ -41,6 +41,7 @@ @@ -41,7 +80,7 @@ index dd7100c46..97d70daad 100644 /// /// Tries to resolve \a vm_addr as a file address (if \a diff --git a/lldb/include/lldb/Core/PluginManager.h b/lldb/include/lldb/Core/PluginManager.h -index be91929c6..8d876fc1f 100644 +index be91929c62e1..8d876fc1fa2f 100644 --- a/lldb/include/lldb/Core/PluginManager.h +++ b/lldb/include/lldb/Core/PluginManager.h @@ -508,6 +508,17 @@ public: @@ -64,7 +103,7 @@ index be91929c6..8d876fc1f 100644 } // namespace lldb_private diff --git a/lldb/include/lldb/Expression/DWARFEvaluator.h b/lldb/include/lldb/Expression/DWARFEvaluator.h new file mode 100644 -index 000000000..6811cbeae +index 000000000000..6811cbeae3d3 --- /dev/null +++ b/lldb/include/lldb/Expression/DWARFEvaluator.h @@ -0,0 +1,110 @@ @@ -180,7 +219,7 @@ index 000000000..6811cbeae +#endif // LLDB_EXPRESSION_DWARFEVALUATOR_H diff --git a/lldb/include/lldb/Expression/DWARFEvaluatorFactory.h b/lldb/include/lldb/Expression/DWARFEvaluatorFactory.h new file mode 100644 -index 000000000..f3b496c58 +index 000000000000..f3b496c580e4 --- /dev/null +++ b/lldb/include/lldb/Expression/DWARFEvaluatorFactory.h @@ -0,0 +1,56 @@ @@ -241,7 +280,7 @@ index 000000000..f3b496c58 + +#endif // LLDB_EXPRESSION_DWARFEVALUATORFACTORY_H diff --git a/lldb/include/lldb/Expression/DWARFExpression.h b/lldb/include/lldb/Expression/DWARFExpression.h -index 1490ac2d6..35c741d4e 100644 +index 1490ac2d614a..35c741d4e6ba 100644 --- a/lldb/include/lldb/Expression/DWARFExpression.h +++ b/lldb/include/lldb/Expression/DWARFExpression.h @@ -120,6 +120,10 @@ public: @@ -275,7 +314,7 @@ index 1490ac2d6..35c741d4e 100644 GetLocationExpression(lldb::addr_t load_function_start, lldb::addr_t addr) const; diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h -index aaa2470d2..c15f2db52 100644 +index aaa2470d2931..c15f2db52fbc 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -1434,7 +1434,7 @@ public: @@ -288,7 +327,7 @@ index aaa2470d2..c15f2db52 100644 /// Read of memory from a process. /// diff --git a/lldb/include/lldb/Target/ProcessTrace.h b/lldb/include/lldb/Target/ProcessTrace.h -index 7b9d6b13d..9525fc975 100644 +index 7b9d6b13dd6f..9525fc9750fd 100644 --- a/lldb/include/lldb/Target/ProcessTrace.h +++ b/lldb/include/lldb/Target/ProcessTrace.h @@ -59,7 +59,7 @@ public: @@ -301,7 +340,7 @@ index 7b9d6b13d..9525fc975 100644 size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, Status &error) override; diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h -index ad5298151..5a3c0b27a 100644 +index ad5298151e4a..5a3c0b27a738 100644 --- a/lldb/include/lldb/lldb-forward.h +++ b/lldb/include/lldb/lldb-forward.h @@ -74,6 +74,7 @@ class Disassembler; @@ -313,7 +352,7 @@ index ad5298151..5a3c0b27a 100644 class EmulateInstruction; class Environment; diff --git a/lldb/include/lldb/lldb-private-interfaces.h b/lldb/include/lldb/lldb-private-interfaces.h -index 2ed083ec8..f4d500d19 100644 +index 2ed083ec8ae9..f4d500d198e8 100644 --- a/lldb/include/lldb/lldb-private-interfaces.h +++ b/lldb/include/lldb/lldb-private-interfaces.h @@ -113,6 +113,8 @@ typedef lldb::REPLSP (*REPLCreateInstance)(Status &error, @@ -326,7 +365,7 @@ index 2ed083ec8..f4d500d19 100644 /// \{ typedef llvm::Expected (*TraceCreateInstanceForSessionFile)( diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp -index 19c97be15..1647f93ec 100644 +index 19c97be15066..1647f93ec4f3 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -16,6 +16,7 @@ @@ -348,7 +387,7 @@ index 19c97be15..1647f93ec 100644 + return m_dwarf_evaluator_factory.get(); +} diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp -index fcaa868b0..59a404d4a 100644 +index fcaa868b083e..59a404d4a7e1 100644 --- a/lldb/source/Core/PluginManager.cpp +++ b/lldb/source/Core/PluginManager.cpp @@ -1597,3 +1597,32 @@ bool PluginManager::CreateSettingForStructuredDataPlugin( @@ -385,7 +424,7 @@ index fcaa868b0..59a404d4a 100644 + return GetDWARFEvaluatorFactoryInstances().GetCallbackAtIndex(idx); +} diff --git a/lldb/source/Core/Value.cpp b/lldb/source/Core/Value.cpp -index fb57c0fed..f92d6a54d 100644 +index fb57c0fedf04..f92d6a54de94 100644 --- a/lldb/source/Core/Value.cpp +++ b/lldb/source/Core/Value.cpp @@ -538,7 +538,7 @@ Status Value::GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data, @@ -398,7 +437,7 @@ index fb57c0fed..f92d6a54d 100644 error.SetErrorStringWithFormat( "read memory from 0x%" PRIx64 " failed (%u of %u bytes read)", diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp -index 9c1ba99da..b15b214b2 100644 +index 9c1ba99da1d0..b15b214b2a2f 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -735,7 +735,7 @@ size_t ValueObject::GetPointeeData(DataExtractor &data, uint32_t item_idx, @@ -411,7 +450,7 @@ index 9c1ba99da..b15b214b2 100644 data.SetData(data_sp); return bytes_read; diff --git a/lldb/source/Expression/CMakeLists.txt b/lldb/source/Expression/CMakeLists.txt -index bf94361dd..4e76d547a 100644 +index bf94361dd6c1..4e76d547aeaf 100644 --- a/lldb/source/Expression/CMakeLists.txt +++ b/lldb/source/Expression/CMakeLists.txt @@ -1,5 +1,7 @@ @@ -424,7 +463,7 @@ index bf94361dd..4e76d547a 100644 ExpressionVariable.cpp diff --git a/lldb/source/Expression/DWARFEvaluator.cpp b/lldb/source/Expression/DWARFEvaluator.cpp new file mode 100644 -index 000000000..06107e136 +index 000000000000..06107e136197 --- /dev/null +++ b/lldb/source/Expression/DWARFEvaluator.cpp @@ -0,0 +1,1952 @@ @@ -2382,7 +2421,7 @@ index 000000000..06107e136 +} diff --git a/lldb/source/Expression/DWARFEvaluatorFactory.cpp b/lldb/source/Expression/DWARFEvaluatorFactory.cpp new file mode 100644 -index 000000000..c06126412 +index 000000000000..c0612641204a --- /dev/null +++ b/lldb/source/Expression/DWARFEvaluatorFactory.cpp @@ -0,0 +1,57 @@ @@ -2444,7 +2483,7 @@ index 000000000..c06126412 + object_address_ptr); +} diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp -index a10546c1d..4d13e4642 100644 +index a10546c1deae..4d13e4642af3 100644 --- a/lldb/source/Expression/DWARFExpression.cpp +++ b/lldb/source/Expression/DWARFExpression.cpp @@ -15,6 +15,8 @@ @@ -4261,7 +4300,7 @@ index a10546c1d..4d13e4642 100644 static DataExtractor ToDataExtractor(const llvm::DWARFLocationExpression &loc, diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp -index 00e9ccb76..2137a1ac8 100644 +index 00e9ccb762c3..2137a1ac8324 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -759,6 +759,24 @@ void CommandInterpreter::LoadCommandDictionary() { @@ -4290,7 +4329,7 @@ index 00e9ccb76..2137a1ac8 100644 new CommandObjectRegexCommand( *this, "kdp-remote", diff --git a/lldb/source/Plugins/CMakeLists.txt b/lldb/source/Plugins/CMakeLists.txt -index 9181a4e47..2be6ec365 100644 +index 9181a4e47675..2be6ec3657c0 100644 --- a/lldb/source/Plugins/CMakeLists.txt +++ b/lldb/source/Plugins/CMakeLists.txt @@ -2,6 +2,7 @@ add_subdirectory(ABI) @@ -4320,14 +4359,14 @@ index 9181a4e47..2be6ec365 100644 endif() diff --git a/lldb/source/Plugins/DWARFEvaluator/CMakeLists.txt b/lldb/source/Plugins/DWARFEvaluator/CMakeLists.txt new file mode 100644 -index 000000000..73fad41e1 +index 000000000000..73fad41e1a72 --- /dev/null +++ b/lldb/source/Plugins/DWARFEvaluator/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(wasm) diff --git a/lldb/source/Plugins/DWARFEvaluator/wasm/CMakeLists.txt b/lldb/source/Plugins/DWARFEvaluator/wasm/CMakeLists.txt new file mode 100644 -index 000000000..e50b1bef7 +index 000000000000..e50b1bef7e69 --- /dev/null +++ b/lldb/source/Plugins/DWARFEvaluator/wasm/CMakeLists.txt @@ -0,0 +1,10 @@ @@ -4343,7 +4382,7 @@ index 000000000..e50b1bef7 + ) diff --git a/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluator.cpp b/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluator.cpp new file mode 100644 -index 000000000..fdda1991d +index 000000000000..fdda1991d19f --- /dev/null +++ b/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluator.cpp @@ -0,0 +1,126 @@ @@ -4475,7 +4514,7 @@ index 000000000..fdda1991d +} diff --git a/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluator.h b/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluator.h new file mode 100644 -index 000000000..a01159064 +index 000000000000..a01159064a39 --- /dev/null +++ b/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluator.h @@ -0,0 +1,47 @@ @@ -4528,7 +4567,7 @@ index 000000000..a01159064 +#endif // LLDB_SOURCE_PLUGINS_DWARFEVALUATOR_WASM_WASMDWARFEVALUATOR_H diff --git a/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluatorFactory.cpp b/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluatorFactory.cpp new file mode 100644 -index 000000000..d43e96a34 +index 000000000000..d43e96a34d37 --- /dev/null +++ b/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluatorFactory.cpp @@ -0,0 +1,64 @@ @@ -4598,7 +4637,7 @@ index 000000000..d43e96a34 +} diff --git a/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluatorFactory.h b/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluatorFactory.h new file mode 100644 -index 000000000..8a946592a +index 000000000000..8a946592a09a --- /dev/null +++ b/lldb/source/Plugins/DWARFEvaluator/wasm/WasmDWARFEvaluatorFactory.h @@ -0,0 +1,55 @@ @@ -4658,7 +4697,7 @@ index 000000000..8a946592a + +#endif // LLDB_SOURCE_PLUGINS_DWARFEVALUATOR_WASM_WASMDWARFEVALUATORFACTORY_H diff --git a/lldb/source/Plugins/DynamicLoader/wasm-DYLD/DynamicLoaderWasmDYLD.cpp b/lldb/source/Plugins/DynamicLoader/wasm-DYLD/DynamicLoaderWasmDYLD.cpp -index ae7e011ea..24ea75d19 100644 +index ae7e011eaa52..24ea75d1971c 100644 --- a/lldb/source/Plugins/DynamicLoader/wasm-DYLD/DynamicLoaderWasmDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/wasm-DYLD/DynamicLoaderWasmDYLD.cpp @@ -62,6 +62,15 @@ void DynamicLoaderWasmDYLD::DidAttach() { @@ -4678,7 +4717,7 @@ index ae7e011ea..24ea75d19 100644 ThreadPlanSP DynamicLoaderWasmDYLD::GetStepThroughTrampolinePlan(Thread &thread, diff --git a/lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp b/lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp -index 5272da9ab..abc5523bf 100644 +index 5272da9ab33a..abc5523bfd70 100644 --- a/lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp +++ b/lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp @@ -23,6 +23,7 @@ @@ -4718,7 +4757,7 @@ index 5272da9ab..abc5523bf 100644 } } diff --git a/lldb/source/Plugins/Platform/CMakeLists.txt b/lldb/source/Plugins/Platform/CMakeLists.txt -index 5f284e517..6084cbc93 100644 +index 5f284e517dca..6084cbc9378d 100644 --- a/lldb/source/Plugins/Platform/CMakeLists.txt +++ b/lldb/source/Plugins/Platform/CMakeLists.txt @@ -15,3 +15,4 @@ @@ -4728,7 +4767,7 @@ index 5f284e517..6084cbc93 100644 +add_subdirectory(wasm-remote) diff --git a/lldb/source/Plugins/Platform/wasm-remote/CMakeLists.txt b/lldb/source/Plugins/Platform/wasm-remote/CMakeLists.txt new file mode 100644 -index 000000000..4a65765a5 +index 000000000000..4a65765a5659 --- /dev/null +++ b/lldb/source/Plugins/Platform/wasm-remote/CMakeLists.txt @@ -0,0 +1,10 @@ @@ -4744,7 +4783,7 @@ index 000000000..4a65765a5 + ) diff --git a/lldb/source/Plugins/Platform/wasm-remote/PlatformRemoteWasmServer.cpp b/lldb/source/Plugins/Platform/wasm-remote/PlatformRemoteWasmServer.cpp new file mode 100644 -index 000000000..f26d11f00 +index 000000000000..f26d11f00e5c --- /dev/null +++ b/lldb/source/Plugins/Platform/wasm-remote/PlatformRemoteWasmServer.cpp @@ -0,0 +1,139 @@ @@ -4890,7 +4929,7 @@ index 000000000..f26d11f00 \ No newline at end of file diff --git a/lldb/source/Plugins/Platform/wasm-remote/PlatformRemoteWasmServer.h b/lldb/source/Plugins/Platform/wasm-remote/PlatformRemoteWasmServer.h new file mode 100644 -index 000000000..f306a79d3 +index 000000000000..f306a79d3f4f --- /dev/null +++ b/lldb/source/Plugins/Platform/wasm-remote/PlatformRemoteWasmServer.h @@ -0,0 +1,37 @@ @@ -4933,7 +4972,7 @@ index 000000000..f306a79d3 +#endif \ No newline at end of file diff --git a/lldb/source/Plugins/Plugins.def.in b/lldb/source/Plugins/Plugins.def.in -index bf54598fb..b0bd7b996 100644 +index bf54598fb2f3..b0bd7b9965fe 100644 --- a/lldb/source/Plugins/Plugins.def.in +++ b/lldb/source/Plugins/Plugins.def.in @@ -31,6 +31,7 @@ @@ -4945,7 +4984,7 @@ index bf54598fb..b0bd7b996 100644 #undef LLDB_PLUGIN diff --git a/lldb/source/Plugins/Process/CMakeLists.txt b/lldb/source/Plugins/Process/CMakeLists.txt -index bea5bac9e..7a0855e02 100644 +index bea5bac9eb21..7a0855e02ca2 100644 --- a/lldb/source/Plugins/Process/CMakeLists.txt +++ b/lldb/source/Plugins/Process/CMakeLists.txt @@ -18,3 +18,4 @@ add_subdirectory(Utility) @@ -4954,7 +4993,7 @@ index bea5bac9e..7a0855e02 100644 add_subdirectory(minidump) +add_subdirectory(wasm) diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp -index 12bc7390c..707ab85e5 100644 +index 12bc7390c729..707ab85e5615 100644 --- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp +++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp @@ -285,7 +285,7 @@ bool ProcessElfCore::IsAlive() { return true; } @@ -4967,7 +5006,7 @@ index 12bc7390c..707ab85e5 100644 // in core files we have it all cached our our core file anyway. return DoReadMemory(addr, buf, size, error); diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h -index d8e3cc9ae..f0bf9c4d3 100644 +index d8e3cc9ae3e1..f0bf9c4d3b00 100644 --- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h +++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h @@ -84,7 +84,8 @@ public: @@ -4981,7 +5020,7 @@ index d8e3cc9ae..f0bf9c4d3 100644 size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Status &error) override; diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp -index 6914b3734..bb8a05604 100644 +index 6914b37348ea..bb8a056049f3 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -334,6 +334,11 @@ ConstString ProcessGDBRemote::GetPluginName() { return GetPluginNameStatic(); } @@ -5015,7 +5054,7 @@ index 6914b3734..bb8a05604 100644 } } diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h -index fe04cdddd..e4a14c645 100644 +index fe04cdddd0f5..e4a14c64579a 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h @@ -237,6 +237,8 @@ protected: @@ -5028,7 +5067,7 @@ index fe04cdddd..e4a14c645 100644 enum { eBroadcastBitAsyncContinue = (1 << 0), diff --git a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp -index 84548edb5..0ae6f7e4a 100644 +index 84548edb5caa..0ae6f7e4a177 100644 --- a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp +++ b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp @@ -596,7 +596,7 @@ bool ProcessMachCore::WarnBeforeDetach() const { return false; } @@ -5041,7 +5080,7 @@ index 84548edb5..0ae6f7e4a 100644 // in core files we have it all cached our our core file anyway. return DoReadMemory(addr, buf, size, error); diff --git a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.h b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.h -index db77e96f1..1c930896c 100644 +index db77e96f1072..1c930896c743 100644 --- a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.h +++ b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.h @@ -65,7 +65,8 @@ public: @@ -5055,7 +5094,7 @@ index db77e96f1..1c930896c 100644 size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Status &error) override; diff --git a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp -index 385557422..d8bb21581 100644 +index 385557422758..d8bb21581086 100644 --- a/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp +++ b/lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp @@ -374,7 +374,7 @@ bool ProcessMinidump::IsAlive() { return true; } @@ -5068,7 +5107,7 @@ index 385557422..d8bb21581 100644 // we have it all cached in our dump file anyway. return DoReadMemory(addr, buf, size, error); diff --git a/lldb/source/Plugins/Process/minidump/ProcessMinidump.h b/lldb/source/Plugins/Process/minidump/ProcessMinidump.h -index 27b0da004..e94ecab43 100644 +index 27b0da0047a5..e94ecab430c1 100644 --- a/lldb/source/Plugins/Process/minidump/ProcessMinidump.h +++ b/lldb/source/Plugins/Process/minidump/ProcessMinidump.h @@ -69,8 +69,8 @@ public: @@ -5084,7 +5123,7 @@ index 27b0da004..e94ecab43 100644 Status &error) override; diff --git a/lldb/source/Plugins/Process/wasm/CMakeLists.txt b/lldb/source/Plugins/Process/wasm/CMakeLists.txt new file mode 100644 -index 000000000..61efb933f +index 000000000000..61efb933fa62 --- /dev/null +++ b/lldb/source/Plugins/Process/wasm/CMakeLists.txt @@ -0,0 +1,12 @@ @@ -5102,7 +5141,7 @@ index 000000000..61efb933f + ) diff --git a/lldb/source/Plugins/Process/wasm/ProcessWasm.cpp b/lldb/source/Plugins/Process/wasm/ProcessWasm.cpp new file mode 100644 -index 000000000..9c0fc7b7f +index 000000000000..9c0fc7b7f270 --- /dev/null +++ b/lldb/source/Plugins/Process/wasm/ProcessWasm.cpp @@ -0,0 +1,261 @@ @@ -5369,7 +5408,7 @@ index 000000000..9c0fc7b7f +} diff --git a/lldb/source/Plugins/Process/wasm/ProcessWasm.h b/lldb/source/Plugins/Process/wasm/ProcessWasm.h new file mode 100644 -index 000000000..d3aece7a6 +index 000000000000..d3aece7a6554 --- /dev/null +++ b/lldb/source/Plugins/Process/wasm/ProcessWasm.h @@ -0,0 +1,128 @@ @@ -5503,7 +5542,7 @@ index 000000000..d3aece7a6 +#endif // LLDB_SOURCE_PLUGINS_PROCESS_WASM_PROCESSWASM_H diff --git a/lldb/source/Plugins/Process/wasm/ThreadWasm.cpp b/lldb/source/Plugins/Process/wasm/ThreadWasm.cpp new file mode 100644 -index 000000000..fa02073e7 +index 000000000000..fa02073e7a52 --- /dev/null +++ b/lldb/source/Plugins/Process/wasm/ThreadWasm.cpp @@ -0,0 +1,35 @@ @@ -5544,7 +5583,7 @@ index 000000000..fa02073e7 +} diff --git a/lldb/source/Plugins/Process/wasm/ThreadWasm.h b/lldb/source/Plugins/Process/wasm/ThreadWasm.h new file mode 100644 -index 000000000..0a33c07de +index 000000000000..0a33c07de994 --- /dev/null +++ b/lldb/source/Plugins/Process/wasm/ThreadWasm.h @@ -0,0 +1,41 @@ @@ -5591,7 +5630,7 @@ index 000000000..0a33c07de +#endif // LLDB_SOURCE_PLUGINS_PROCESS_WASM_THREADWASM_H diff --git a/lldb/source/Plugins/Process/wasm/UnwindWasm.cpp b/lldb/source/Plugins/Process/wasm/UnwindWasm.cpp new file mode 100644 -index 000000000..1a195cb93 +index 000000000000..1a195cb9361a --- /dev/null +++ b/lldb/source/Plugins/Process/wasm/UnwindWasm.cpp @@ -0,0 +1,74 @@ @@ -5672,7 +5711,7 @@ index 000000000..1a195cb93 \ No newline at end of file diff --git a/lldb/source/Plugins/Process/wasm/UnwindWasm.h b/lldb/source/Plugins/Process/wasm/UnwindWasm.h new file mode 100644 -index 000000000..9bd1dac9a +index 000000000000..9bd1dac9a98a --- /dev/null +++ b/lldb/source/Plugins/Process/wasm/UnwindWasm.h @@ -0,0 +1,55 @@ @@ -5732,7 +5771,7 @@ index 000000000..9bd1dac9a + +#endif // lldb_UnwindWasm_h_ diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp -index ccaf31317..c3ef5aebd 100644 +index ccaf31317d75..c3ef5aebd46d 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -3212,8 +3212,13 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc, @@ -5751,7 +5790,7 @@ index ccaf31317..c3ef5aebd 100644 // DWARF doesn't specify if a DW_TAG_variable is a local, global // or static variable, so we have to do a little digging: diff --git a/lldb/source/Target/PathMappingList.cpp b/lldb/source/Target/PathMappingList.cpp -index b660c310e..cd76421ce 100644 +index b660c310ef31..cd76421cec18 100644 --- a/lldb/source/Target/PathMappingList.cpp +++ b/lldb/source/Target/PathMappingList.cpp @@ -218,7 +218,12 @@ bool PathMappingList::ReverseRemapPath(const FileSpec &file, FileSpec &fixed) co @@ -5769,7 +5808,7 @@ index b660c310e..cd76421ce 100644 return {}; diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp -index a77ecddfb..e257f9350 100644 +index a77ecddfbab6..e257f93508f6 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -1970,6 +1970,12 @@ size_t Platform::GetSoftwareBreakpointTrapOpcode(Target &target, @@ -5786,7 +5825,7 @@ index a77ecddfb..e257f9350 100644 return 0; } diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp -index 8ecc66b59..f14898791 100644 +index 8ecc66b592ea..f148987915de 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -1892,7 +1892,8 @@ Status Process::DisableSoftwareBreakpoint(BreakpointSite *bp_site) { @@ -5800,7 +5839,7 @@ index 8ecc66b59..f14898791 100644 if (!GetDisableMemoryCache()) { #if defined(VERIFY_MEMORY_READS) diff --git a/lldb/source/Target/ProcessTrace.cpp b/lldb/source/Target/ProcessTrace.cpp -index c878a2ac4..ad5945b0a 100644 +index c878a2ac4eb9..ad5945b0ad1f 100644 --- a/lldb/source/Target/ProcessTrace.cpp +++ b/lldb/source/Target/ProcessTrace.cpp @@ -88,7 +88,7 @@ void ProcessTrace::RefreshStateAfterStop() {} @@ -5813,7 +5852,7 @@ index c878a2ac4..ad5945b0a 100644 // we have it all cached in the trace files. return DoReadMemory(addr, buf, size, error); diff --git a/lldb/source/Target/ThreadPlanStepRange.cpp b/lldb/source/Target/ThreadPlanStepRange.cpp -index 896e647bb..f76307016 100644 +index 896e647bbb52..f76307016102 100644 --- a/lldb/source/Target/ThreadPlanStepRange.cpp +++ b/lldb/source/Target/ThreadPlanStepRange.cpp @@ -334,7 +334,10 @@ bool ThreadPlanStepRange::SetNextBranchBreakpoint() { @@ -5829,7 +5868,7 @@ index 896e647bb..f76307016 100644 instructions->GetInstructionAtIndex(last_index); size_t last_inst_size = last_inst->GetOpcode().GetByteSize(); diff --git a/lldb/source/Target/UnixSignals.cpp b/lldb/source/Target/UnixSignals.cpp -index 4ec2e25c7..24c88fe9a 100644 +index 4ec2e25c7e3b..24c88fe9ae4f 100644 --- a/lldb/source/Target/UnixSignals.cpp +++ b/lldb/source/Target/UnixSignals.cpp @@ -46,6 +46,8 @@ lldb::UnixSignalsSP UnixSignals::Create(const ArchSpec &arch) { @@ -5842,7 +5881,7 @@ index 4ec2e25c7..24c88fe9a 100644 return std::make_shared(); } diff --git a/llvm/include/llvm/ExecutionEngine/Orc/OrcRPCExecutorProcessControl.h b/llvm/include/llvm/ExecutionEngine/Orc/OrcRPCExecutorProcessControl.h -index 4310ba9ce..297b33879 100644 +index 4310ba9ce9e0..297b3387999d 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/OrcRPCExecutorProcessControl.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/OrcRPCExecutorProcessControl.h @@ -13,6 +13,7 @@ @@ -5854,7 +5893,7 @@ index 4310ba9ce..297b33879 100644 #include "llvm/ExecutionEngine/Orc/Shared/RPCUtils.h" #include "llvm/ExecutionEngine/Orc/Shared/RawByteChannel.h" diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h -index 753b1998c..27370c62d 100644 +index 753b1998c40c..27370c62dd6e 100644 --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/include/llvm/Support/MathExtras.h @@ -16,6 +16,7 @@ diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/requirements.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/requirements.txt new file mode 100644 index 00000000000..077c95d8a43 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/requirements.txt @@ -0,0 +1 @@ +requests==2.31.0 \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/runtime_lib.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/runtime_lib.cmake similarity index 95% rename from lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/runtime_lib.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/runtime_lib.cmake index 6931ece74b9..811009df6ec 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/build-scripts/runtime_lib.cmake +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/build-scripts/runtime_lib.cmake @@ -91,8 +91,10 @@ endif () if (WAMR_BUILD_LIBC_UVWASI EQUAL 1) include (${IWASM_DIR}/libraries/libc-uvwasi/libc_uvwasi.cmake) + set (WAMR_BUILD_MODULE_INST_CONTEXT 1) elseif (WAMR_BUILD_LIBC_WASI EQUAL 1) include (${IWASM_DIR}/libraries/libc-wasi/libc_wasi.cmake) + set (WAMR_BUILD_MODULE_INST_CONTEXT 1) endif () if (WAMR_BUILD_LIB_PTHREAD_SEMAPHORE EQUAL 1) @@ -101,7 +103,7 @@ if (WAMR_BUILD_LIB_PTHREAD_SEMAPHORE EQUAL 1) endif () if (WAMR_BUILD_WASI_NN EQUAL 1) - include (${IWASM_DIR}/libraries/wasi-nn/wasi_nn.cmake) + include (${IWASM_DIR}/libraries/wasi-nn/cmake/wasi_nn.cmake) endif () if (WAMR_BUILD_LIB_PTHREAD EQUAL 1) @@ -163,7 +165,11 @@ file (GLOB header ) LIST (APPEND RUNTIME_LIB_HEADER_LIST ${header}) -enable_language (ASM) +if (WAMR_BUILD_PLATFORM STREQUAL "windows") + enable_language (ASM_MASM) +else() + enable_language (ASM) +endif() include (${SHARED_PLATFORM_CONFIG}) include (${SHARED_DIR}/mem-alloc/mem_alloc.cmake) @@ -177,7 +183,7 @@ set (source_all ${UTILS_SHARED_SOURCE} ${LIBC_BUILTIN_SOURCE} ${LIBC_WASI_SOURCE} - ${LIBC_WASI_NN_SOURCE} + ${WASI_NN_SOURCES} ${IWASM_COMMON_SOURCE} ${IWASM_INTERP_SOURCE} ${IWASM_AOT_SOURCE} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/ci/build_wamr.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/ci/build_wamr.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/ci/build_wamr.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/ci/build_wamr.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/ci/coding_guidelines_check.py b/lib/wasm-micro-runtime-WAMR-1.3.0/ci/coding_guidelines_check.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/ci/coding_guidelines_check.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/ci/coding_guidelines_check.py diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/ci/pre_commit_hook_sample b/lib/wasm-micro-runtime-WAMR-1.3.0/ci/pre_commit_hook_sample new file mode 100755 index 00000000000..682e7894644 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/ci/pre_commit_hook_sample @@ -0,0 +1,32 @@ +#!/bin/bash + +# Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# This is a sample of pre-commit hook that can be used to make your code fit the WAMR CI code style requirements. +# You need to have clang-format-12 installed to use this hook. +# To add this pre-commit hook, copy it to /.git/hooks/pre-commit +# (you don't need any extensions here) + +# Function to check if a file has a C or C++ extension + +is_c_or_cpp_file() { + file="$1" + if [[ "$filename" =~ \.(h|c|cpp)$ ]]; then + return 0 + else + return 1 + fi +} + +# Loop through staged files and apply command "abc" to C and C++ files +for staged_file in $(git diff --cached --name-only); do + if is_c_or_cpp_file "$staged_file"; then + clang-format-12 -Werror --style file --dry-run "$staged_file" 2>/dev/null + if [ $? -ne 0 ]; then + echo "Issues are found in $staged_file. Applying the fix" + clang-format-12 --style file -i "$staged_file" + fi + git add "$staged_file" # Add the modified file back to staging + fi +done diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/ci/setup.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/ci/setup.sh new file mode 100755 index 00000000000..ebdf73af553 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/ci/setup.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# This script executes some commands to make your onboarding with WAMR easier. +# For example, setting pre-commit hook that will make your code complaint with the +# code style requirements checked in WAMR CI + +echo "Copy the pre-commit hook to your hooks folder" +cp pre_commit_hook_sample ../.git/hooks/pre-commit + +# Feel free to propose your commands to this script to make developing WAMR easier + +echo "Setup is done" diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/ci/validate_lldb.py b/lib/wasm-micro-runtime-WAMR-1.3.0/ci/validate_lldb.py new file mode 100755 index 00000000000..1b431ada853 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/ci/validate_lldb.py @@ -0,0 +1,128 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2023 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# + +import argparse +import time +from pathlib import Path +import subprocess, shlex + +SCRIPT_DIR = Path(__file__).parent.resolve() +REPO_ROOT_DIR = SCRIPT_DIR.parent +SAMPLE_CODE_FILE = REPO_ROOT_DIR / 'product-mini/app-samples/hello-world/main.c' +WASM_OUT_FILE = SCRIPT_DIR / 'out.wasm' + +parser = argparse.ArgumentParser( + description="Validate the customized lldb with sample code" +) +parser.add_argument( + "-l", "--lldb", dest='lldb', default='lldb', help="path to lldb executable" +) +parser.add_argument( + "-w", "--wamr", dest='wamr', default='iwasm', help="path to iwasm executable" +) +parser.add_argument( + "-p", "--port", dest='port', default='1234', help="debug server listen port" +) +parser.add_argument( + "-v", "--verbose", dest='verbose', action='store_true', default=False, help="display lldb stdout" +) + +options = parser.parse_args() + +lldb_command_epilogue = '-o q' + +test_cases = { + 'run_to_exit': '-o c', + 'func_breakpoint': '-o "b main" -o c -o c', + 'line_breakpoint': '-o "b main.c:12" -o c -o c', + 'break_on_unknown_func': '-o "b not_a_func" -o c', + 'watch_point': '-o "b main" -o c -o "watchpoint set variable buf" -o c -o "fr v buf" -o c', +} + +# Step1: Build wasm module with debug information +build_cmd = f'/opt/wasi-sdk/bin/clang -g -O0 -o {WASM_OUT_FILE} {SAMPLE_CODE_FILE}' +try: + print(f'building wasm module ...', end='', flush=True) + subprocess.check_call(shlex.split(build_cmd)) + print(f'\t OK') +except subprocess.CalledProcessError: + print("Failed to build wasm module with debug information") + exit(1) + +def print_process_output(p): + try: + outs, errs = p.communicate(timeout=2) + print("stdout:") + print(outs) + print("stderr:") + print(errs) + except subprocess.TimeoutExpired: + print("Failed to get process output") + +# Step2: Launch WAMR in debug mode and validate lldb commands + +iteration = 0 +for case, cmd in test_cases.items(): + lldb_command_prologue = f'{options.lldb} -o "process connect -p wasm connect://127.0.0.1:{int(options.port) + iteration}"' + wamr_cmd = f'{options.wamr} -g=127.0.0.1:{int(options.port) + iteration} {WASM_OUT_FILE}' + iteration += 1 + + has_error = False + print(f'validating case [{case}] ...', end='', flush=True) + lldb_cmd = f'{lldb_command_prologue} {cmd} {lldb_command_epilogue}' + + wamr_process = subprocess.Popen(shlex.split( + wamr_cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + + time.sleep(0.1) + if (wamr_process.poll() != None): + print("\nWAMR doesn't wait for lldb connection") + print_process_output(wamr_process) + exit(1) + + lldb_process = subprocess.Popen(shlex.split( + lldb_cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + + if (options.verbose): + while (lldb_process.poll() is None): + print(lldb_process.stdout.read(), end='', flush=True) + + try: + if (lldb_process.wait(5) != 0): + print(f"\nFailed to validate case [{case}]") + print_process_output(lldb_process) + has_error = True + + if wamr_process.wait(2) != 0: + print("\nWAMR process doesn't exit normally") + print_process_output(wamr_process) + has_error = True + + except subprocess.TimeoutExpired: + print(f"\nFailed to validate case [{case}]") + print("wamr output:") + print_process_output(wamr_process) + print("lldb output:") + print_process_output(lldb_process) + has_error = True + finally: + if (lldb_process.poll() == None): + print(f'\nterminating lldb process [{lldb_process.pid}]') + lldb_process.kill() + if (wamr_process.poll() == None): + print(f'terminating wamr process [{wamr_process.pid}]') + wamr_process.kill() + + if (has_error): + exit(1) + + print(f'\t OK') + + # wait 100ms to ensure the socket is closed + time.sleep(0.1) + +print('Validate lldb success') +exit(0) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/attr_container.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/attr_container.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/attr_container.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/attr_container.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/bi-inc/attr_container.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/bi-inc/attr_container.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/bi-inc/attr_container.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/bi-inc/attr_container.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/bi-inc/shared_utils.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/bi-inc/shared_utils.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/bi-inc/shared_utils.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/bi-inc/shared_utils.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/bi-inc/wgl_shared_utils.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/bi-inc/wgl_shared_utils.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/bi-inc/wgl_shared_utils.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/bi-inc/wgl_shared_utils.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/native_interface.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/native_interface.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/native_interface.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/native_interface.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/native_interface.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/native_interface.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/native_interface.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/native_interface.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/restful_utils.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/restful_utils.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app-native-shared/restful_utils.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app-native-shared/restful_utils.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app_ext_lib_export.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app_ext_lib_export.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app_ext_lib_export.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app_ext_lib_export.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app_framework.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app_framework.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/app_framework.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/app_framework.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/bh_platform.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/bh_platform.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/bh_platform.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/bh_platform.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/bh_platform.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/bh_platform.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/bh_platform.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/bh_platform.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/req_resp_api.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/req_resp_api.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/req_resp_api.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/req_resp_api.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/request.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/request.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/request.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/request.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/timer.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/timer.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/timer.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/timer.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/timer_api.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/timer_api.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/timer_api.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/timer_api.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/wa-inc/request.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/wa-inc/request.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/wa-inc/request.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/wa-inc/request.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/wa-inc/timer_wasm_app.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/wa-inc/timer_wasm_app.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/wa-inc/timer_wasm_app.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/wa-inc/timer_wasm_app.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/wasm_app.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/wasm_app.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/wasm_app.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/wasm_app.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/wasm_app.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/wasm_app.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/app/wasm_app.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/app/wasm_app.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/base_lib.inl b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/base_lib.inl similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/base_lib.inl rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/base_lib.inl diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/base_lib_export.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/base_lib_export.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/base_lib_export.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/base_lib_export.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/req_resp_native_api.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/req_resp_native_api.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/req_resp_native_api.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/req_resp_native_api.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/request_response.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/request_response.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/request_response.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/request_response.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/runtime_lib.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/runtime_lib.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/runtime_lib.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/runtime_lib.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/timer_native_api.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/timer_native_api.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/timer_native_api.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/timer_native_api.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/timer_wrapper.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/timer_wrapper.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/timer_wrapper.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/timer_wrapper.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/wasm_lib.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/wasm_lib.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/base/native/wasm_lib.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/base/native/wasm_lib.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/app/connection.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/app/connection.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/app/connection.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/app/connection.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/app/connection_api.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/app/connection_api.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/app/connection_api.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/app/connection_api.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/app/wa-inc/connection.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/app/wa-inc/connection.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/app/wa-inc/connection.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/app/wa-inc/connection.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/app/wasm_app.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/app/wasm_app.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/app/wasm_app.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/app/wasm_app.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/connection.inl b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/connection.inl similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/connection.inl rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/connection.inl diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/connection_lib.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/connection_lib.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/connection_lib.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/connection_lib.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/connection_native_api.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/connection_native_api.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/connection_native_api.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/connection_native_api.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/connection_wrapper.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/connection_wrapper.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/connection_wrapper.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/connection_wrapper.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_tcp.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_tcp.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_tcp.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_tcp.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_tcp.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_tcp.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_tcp.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_tcp.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_uart.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_uart.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_uart.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_uart.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_uart.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_uart.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_uart.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_uart.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_udp.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_udp.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_udp.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_udp.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_udp.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_udp.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/conn_udp.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/conn_udp.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/connection_mgr.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/connection_mgr.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/connection_mgr.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/connection_mgr.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/connection_mgr.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/connection_mgr.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/linux/connection_mgr.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/linux/connection_mgr.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/wasm_lib.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/wasm_lib.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/wasm_lib.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/wasm_lib.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/zephyr/connection_lib_impl.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/zephyr/connection_lib_impl.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/zephyr/connection_lib_impl.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/zephyr/connection_lib_impl.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/zephyr/connection_mgr.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/zephyr/connection_mgr.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/connection/native/zephyr/connection_mgr.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/connection/native/zephyr/connection_mgr.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/app/sensor.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/app/sensor.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/app/sensor.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/app/sensor.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/app/sensor_api.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/app/sensor_api.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/app/sensor_api.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/app/sensor_api.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/app/wa-inc/sensor.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/app/wa-inc/sensor.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/app/wa-inc/sensor.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/app/wa-inc/sensor.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/app/wasm_app.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/app/wasm_app.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/app/wasm_app.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/app/wasm_app.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/runtime_sensor.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/runtime_sensor.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/runtime_sensor.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/runtime_sensor.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/runtime_sensor.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/runtime_sensor.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/runtime_sensor.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/runtime_sensor.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/runtime_sensor.inl b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/runtime_sensor.inl similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/runtime_sensor.inl rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/runtime_sensor.inl diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/sensor_mgr_ref.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/sensor_mgr_ref.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/sensor_mgr_ref.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/sensor_mgr_ref.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/sensor_native_api.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/sensor_native_api.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/sensor_native_api.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/sensor_native_api.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/wasm_lib.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/wasm_lib.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/sensor/native/wasm_lib.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/sensor/native/wasm_lib.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/template/app/wa-inc/app_xxx.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/template/app/wa-inc/app_xxx.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/template/app/wa-inc/app_xxx.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/template/app/wa-inc/app_xxx.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/template/app/wasm_app.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/template/app/wasm_app.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/template/app/wasm_app.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/template/app/wasm_app.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/template/native/app_xxx.inl b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/template/native/app_xxx.inl similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/template/native/app_xxx.inl rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/template/native/app_xxx.inl diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/template/native/wasm_lib.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/template/native/wasm_lib.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-framework/template/native/wasm_lib.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-framework/template/native/wasm_lib.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/README.md new file mode 100644 index 00000000000..7a561897e17 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/README.md @@ -0,0 +1,8 @@ +# Remote application management + +The WAMR application manager supports [remote application management](../../core/app-mgr) from the host environment or the cloud through any physical communications such as TCP, UPD, UART, BLE, etc. Its modular design makes it able to support application management for different managed runtimes. + +The tool [host_tool](../../test-tools/host-tool) communicates to the WAMR app manager for installing/uninstalling the WASM applications on companion chip from the host system. And the [IoT App Store Demo](../../test-tools/IoT-APP-Store-Demo/) shows the conception of remotely managing the device applications from the cloud. + + + diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_manager.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_manager.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_manager.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_manager.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_manager.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_manager.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_manager.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_manager.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_manager_host.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_manager_host.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_manager_host.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_manager_host.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_manager_host.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_manager_host.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_manager_host.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_manager_host.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_mgr.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_mgr.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/app_mgr.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/app_mgr.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/ble_msg.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/ble_msg.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/ble_msg.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/ble_msg.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/coding_rule.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/coding_rule.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/coding_rule.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/coding_rule.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/event.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/event.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/event.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/event.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/event.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/event.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/event.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/event.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/message.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/message.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/message.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/message.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_config.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_config.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_config.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_config.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_jeff.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_jeff.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_jeff.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_jeff.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_jeff.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_jeff.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_jeff.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_jeff.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_utils.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_utils.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_utils.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_utils.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_wasm_app.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_wasm_app.c similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_wasm_app.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_wasm_app.c index 2005ad8e846..6fd929b10f1 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_wasm_app.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_wasm_app.c @@ -1467,7 +1467,7 @@ wasm_app_module_on_install_request_byte_arrive(uint8 ch, int request_total_size, if (total_size >= UINT32_MAX || !(section->section_body = os_mmap(NULL, (uint32)total_size, map_prot, - map_flags))) { + map_flags, os_get_invalid_handle()))) { app_manager_printf( "Allocate executable memory failed!\n"); SEND_ERR_RESPONSE(recv_ctx.message.request_mid, diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_wasm_app.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_wasm_app.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_wasm_app.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_wasm_app.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_wasm_lib.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_wasm_lib.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_wasm_lib.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_wasm_lib.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_wasm_lib.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_wasm_lib.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/module_wasm_lib.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/module_wasm_lib.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/platform/darwin/app_mgr_darwin.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/platform/darwin/app_mgr_darwin.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/platform/darwin/app_mgr_darwin.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/platform/darwin/app_mgr_darwin.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/platform/linux/app_mgr_linux.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/platform/linux/app_mgr_linux.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/platform/linux/app_mgr_linux.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/platform/linux/app_mgr_linux.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/platform/zephyr/app_mgr_zephyr.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/platform/zephyr/app_mgr_zephyr.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/platform/zephyr/app_mgr_zephyr.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/platform/zephyr/app_mgr_zephyr.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/resource_reg.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/resource_reg.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/resource_reg.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/resource_reg.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/watchdog.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/watchdog.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/watchdog.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/watchdog.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/watchdog.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/watchdog.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-manager/watchdog.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-manager/watchdog.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-mgr-shared/app_manager_export.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-mgr-shared/app_manager_export.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-mgr-shared/app_manager_export.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-mgr-shared/app_manager_export.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-mgr-shared/app_mgr_shared.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-mgr-shared/app_mgr_shared.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-mgr-shared/app_mgr_shared.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-mgr-shared/app_mgr_shared.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-mgr-shared/host_link.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-mgr-shared/host_link.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/app-mgr-shared/host_link.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/app-mgr-shared/host_link.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/module.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/module.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/app-mgr/module.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/app-mgr/module.json diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/config.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/config.h similarity index 88% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/config.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/config.h index feedb13fa62..acf70ff081b 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/config.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/config.h @@ -144,6 +144,14 @@ #define WASM_ENABLE_WASI_NN 0 #endif +#ifndef WASM_ENABLE_WASI_NN_GPU +#define WASM_ENABLE_WASI_NN_GPU 0 +#endif + +#ifndef WASM_ENABLE_WASI_NN_EXTERNAL_DELEGATE +#define WASM_ENABLE_WASI_NN_EXTERNAL_DELEGATE 0 +#endif + /* Default disable libc emcc */ #ifndef WASM_ENABLE_LIBC_EMCC #define WASM_ENABLE_LIBC_EMCC 0 @@ -307,6 +315,11 @@ #define BH_ENABLE_GC_VERIFY 0 #endif +/* Heap corruption check, enabled by default */ +#ifndef BH_ENABLE_GC_CORRUPTION_CHECK +#define BH_ENABLE_GC_CORRUPTION_CHECK 1 +#endif + /* Enable global heap pool if heap verification is enabled */ #if BH_ENABLE_GC_VERIFY != 0 #define WASM_ENABLE_GLOBAL_HEAP_POOL 1 @@ -384,7 +397,7 @@ #define APP_THREAD_STACK_SIZE_DEFAULT (64 * 1024) #define APP_THREAD_STACK_SIZE_MIN (48 * 1024) #else -#define APP_THREAD_STACK_SIZE_DEFAULT (32 * 1024) +#define APP_THREAD_STACK_SIZE_DEFAULT (64 * 1024) #define APP_THREAD_STACK_SIZE_MIN (24 * 1024) #endif #endif /* end of !(defined(APP_THREAD_STACK_SIZE_DEFAULT) \ @@ -445,4 +458,36 @@ #define WASM_ENABLE_WASM_CACHE 0 #endif +#ifndef WASM_ENABLE_STATIC_PGO +#define WASM_ENABLE_STATIC_PGO 0 +#endif + +/* Disable writing linear memory base address to GS segment register, + by default only in linux x86-64, linear memory base addr is written + to GS segment register before calling wasm/aot function. */ +#ifndef WASM_DISABLE_WRITE_GS_BASE +#define WASM_DISABLE_WRITE_GS_BASE 0 +#endif + +/* Configurable bounds checks */ +#ifndef WASM_CONFIGURABLE_BOUNDS_CHECKS +#define WASM_CONFIGURABLE_BOUNDS_CHECKS 0 +#endif + +/* Some chip cannot support external ram with rwx attr at the same time, + it has to map it into 2 spaces of idbus and dbus, code in dbus can be + read/written and read/executed in ibus. so there are 2 steps to execute + the code, first, copy & do relocation in dbus space, and second execute + it in ibus space, since in the 2 spaces the contents are the same, + so we call it bus mirror. + */ +#ifndef WASM_MEM_DUAL_BUS_MIRROR +#define WASM_MEM_DUAL_BUS_MIRROR 0 +#endif + +/* The max number of module instance contexts. */ +#ifndef WASM_MAX_INSTANCE_CONTEXTS +#define WASM_MAX_INSTANCE_CONTEXTS 8 +#endif + #endif /* end of _CONFIG_H_ */ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/SConscript similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/SConscript rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/SConscript diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_intrinsic.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_intrinsic.c similarity index 82% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_intrinsic.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_intrinsic.c index 319eeda5cbc..189b43b09b0 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_intrinsic.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_intrinsic.c @@ -648,6 +648,42 @@ add_f64_common_intrinsics(AOTCompContext *comp_ctx) add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_CMP); } +static void +add_f32xi32_intrinsics(AOTCompContext *comp_ctx) +{ + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_TO_I32); + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_TO_U32); + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I32_TO_F32); + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_U32_TO_F32); +} + +static void +add_f64xi32_intrinsics(AOTCompContext *comp_ctx) +{ + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_TO_I32); + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_TO_U32); + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I32_TO_F64); + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_U32_TO_F64); +} + +static void +add_f32xi64_intrinsics(AOTCompContext *comp_ctx) +{ + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_TO_I64); + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_TO_U64); + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I64_TO_F32); + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_U64_TO_F32); +} + +static void +add_f64xi64_intrinsics(AOTCompContext *comp_ctx) +{ + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_TO_I64); + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_TO_U64); + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I64_TO_F64); + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_U64_TO_F64); +} + static void add_common_float_integer_convertion(AOTCompContext *comp_ctx) { @@ -705,8 +741,101 @@ aot_intrinsic_check_capability(const AOTCompContext *comp_ctx, void aot_intrinsic_fill_capability_flags(AOTCompContext *comp_ctx) { + uint32 i; + memset(comp_ctx->flags, 0, sizeof(comp_ctx->flags)); + /* Intrinsics from command line have highest priority */ + + if (comp_ctx->builtin_intrinsics) { + + /* Handle 'all' group */ + if (strstr(comp_ctx->builtin_intrinsics, "all")) { + for (i = 0; i < g_intrinsic_count; i++) { + add_intrinsic_capability(comp_ctx, g_intrinsic_mapping[i].flag); + } + return; + } + + /* Handle 'i32.common' group */ + if (strstr(comp_ctx->builtin_intrinsics, "i32.common")) { + add_i32_common_intrinsics(comp_ctx); + } + + /* Handle 'i64.common' group */ + if (strstr(comp_ctx->builtin_intrinsics, "i64.common")) { + add_i64_common_intrinsics(comp_ctx); + } + + /* Handle 'fp.common' group */ + if (strstr(comp_ctx->builtin_intrinsics, "fp.common")) { + add_f32_common_intrinsics(comp_ctx); + add_f64_common_intrinsics(comp_ctx); + } + + /* Handle 'f32.common' group */ + if (strstr(comp_ctx->builtin_intrinsics, "f32.common")) { + add_f32_common_intrinsics(comp_ctx); + } + + /* Handle 'f64.common' group */ + if (strstr(comp_ctx->builtin_intrinsics, "f64.common")) { + add_f64_common_intrinsics(comp_ctx); + } + + /* Handle 'f32xi32' group */ + if (strstr(comp_ctx->builtin_intrinsics, "f32xi32")) { + add_f32xi32_intrinsics(comp_ctx); + } + + /* Handle 'f64xi32' group */ + if (strstr(comp_ctx->builtin_intrinsics, "f64xi32")) { + add_f64xi32_intrinsics(comp_ctx); + } + + /* Handle 'f32xi64' group */ + if (strstr(comp_ctx->builtin_intrinsics, "f32xi64")) { + add_f32xi64_intrinsics(comp_ctx); + } + + /* Handle 'f64xi64' group */ + if (strstr(comp_ctx->builtin_intrinsics, "f64xi64")) { + add_f64xi64_intrinsics(comp_ctx); + } + + /* Handle 'fpxint' group */ + if (strstr(comp_ctx->builtin_intrinsics, "fpxint")) { + add_f32xi32_intrinsics(comp_ctx); + add_f64xi32_intrinsics(comp_ctx); + add_f32xi64_intrinsics(comp_ctx); + add_f64xi64_intrinsics(comp_ctx); + } + + /* Handle 'constop' group */ + if (strstr(comp_ctx->builtin_intrinsics, "constop")) { + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I32_CONST); + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_I64_CONST); + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F32_CONST); + add_intrinsic_capability(comp_ctx, AOT_INTRINSIC_FLAG_F64_CONST); + } + + /* Handle 'fp.common' group */ + if (strstr(comp_ctx->builtin_intrinsics, "fp.common")) { + add_f32_common_intrinsics(comp_ctx); + add_f64_common_intrinsics(comp_ctx); + } + + /* Handle other single items */ + for (i = 0; i < g_intrinsic_count; i++) { + if (strstr(comp_ctx->builtin_intrinsics, + g_intrinsic_mapping[i].llvm_intrinsic)) { + add_intrinsic_capability(comp_ctx, g_intrinsic_mapping[i].flag); + } + } + + return; + } + if (!comp_ctx->target_cpu) return; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_intrinsic.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_intrinsic.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_intrinsic.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_intrinsic.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_loader.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_loader.c similarity index 86% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_loader.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_loader.c index 5345fb2d72e..abffd6438a7 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_loader.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_loader.c @@ -558,6 +558,56 @@ str2uint32(const char *buf, uint32 *p_res); static bool str2uint64(const char *buf, uint64 *p_res); +#if WASM_ENABLE_MULTI_MODULE != 0 +static void * +aot_loader_resolve_function(const char *module_name, const char *function_name, + const AOTFuncType *expected_function_type, + char *error_buf, uint32 error_buf_size) +{ + WASMModuleCommon *module_reg; + void *function = NULL; + AOTExport *export = NULL; + AOTModule *module = NULL; + AOTFuncType *target_function_type = NULL; + + module_reg = wasm_runtime_find_module_registered(module_name); + if (!module_reg || module_reg->module_type != Wasm_Module_AoT) { + LOG_DEBUG("can not find a module named %s for function %s", module_name, + function_name); + set_error_buf(error_buf, error_buf_size, "unknown import"); + return NULL; + } + + module = (AOTModule *)module_reg; + export = loader_find_export(module_reg, module_name, function_name, + EXPORT_KIND_FUNC, error_buf, error_buf_size); + if (!export) { + return NULL; + } + + /* resolve function type and function */ + if (export->index < module->import_func_count) { + target_function_type = module->import_funcs[export->index].func_type; + function = module->import_funcs[export->index].func_ptr_linked; + } + else { + target_function_type = + module->func_types[module->func_type_indexes + [export->index - module->import_func_count]]; + function = + (module->func_ptrs[export->index - module->import_func_count]); + } + /* check function type */ + if (!wasm_type_equal(expected_function_type, target_function_type)) { + LOG_DEBUG("%s.%s failed the type check", module_name, function_name); + set_error_buf(error_buf, error_buf_size, "incompatible import type"); + return NULL; + } + return function; +} + +#endif /* end of WASM_ENABLE_MULTI_MODULE */ + static bool load_native_symbol_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module, bool is_load_from_file_buf, @@ -1045,7 +1095,6 @@ load_table_init_data_list(const uint8 **p_buf, const uint8 *buf_end, data_list[i]->mode = mode; data_list[i]->elem_type = elem_type; - data_list[i]->is_dropped = false; data_list[i]->table_index = table_index; data_list[i]->offset.init_expr_type = (uint8)init_expr_type; data_list[i]->offset.u.i64 = (int64)init_expr_value; @@ -1357,11 +1406,16 @@ load_import_funcs(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module, bool is_load_from_file_buf, char *error_buf, uint32 error_buf_size) { - const char *module_name, *field_name; + char *module_name, *field_name; const uint8 *buf = *p_buf; AOTImportFunc *import_funcs; uint64 size; uint32 i; +#if WASM_ENABLE_MULTI_MODULE != 0 + AOTModule *sub_module = NULL; + AOTFunc *linked_func = NULL; + WASMType *declare_func_type = NULL; +#endif /* Allocate memory */ size = sizeof(AOTImportFunc) * (uint64)module->import_func_count; @@ -1377,17 +1431,46 @@ load_import_funcs(const uint8 **p_buf, const uint8 *buf_end, AOTModule *module, set_error_buf(error_buf, error_buf_size, "unknown type"); return false; } + +#if WASM_ENABLE_MULTI_MODULE != 0 + declare_func_type = module->func_types[import_funcs[i].func_type_index]; + read_string(buf, buf_end, module_name); + read_string(buf, buf_end, field_name); + + import_funcs[i].module_name = module_name; + import_funcs[i].func_name = field_name; + linked_func = wasm_native_resolve_symbol( + module_name, field_name, declare_func_type, + &import_funcs[i].signature, &import_funcs[i].attachment, + &import_funcs[i].call_conv_raw); + if (!linked_func) { + if (!wasm_runtime_is_built_in_module(module_name)) { + sub_module = (AOTModule *)wasm_runtime_load_depended_module( + (WASMModuleCommon *)module, module_name, error_buf, + error_buf_size); + if (!sub_module) { + return false; + } + } + linked_func = aot_loader_resolve_function( + module_name, field_name, declare_func_type, error_buf, + error_buf_size); + } + import_funcs[i].func_ptr_linked = linked_func; + import_funcs[i].func_type = declare_func_type; + +#else import_funcs[i].func_type = module->func_types[import_funcs[i].func_type_index]; read_string(buf, buf_end, import_funcs[i].module_name); read_string(buf, buf_end, import_funcs[i].func_name); - module_name = import_funcs[i].module_name; field_name = import_funcs[i].func_name; import_funcs[i].func_ptr_linked = wasm_native_resolve_symbol( module_name, field_name, import_funcs[i].func_type, &import_funcs[i].signature, &import_funcs[i].attachment, &import_funcs[i].call_conv_raw); +#endif #if WASM_ENABLE_LIBC_WASI != 0 if (!strcmp(import_funcs[i].module_name, "wasi_unstable") @@ -1430,8 +1513,28 @@ destroy_object_data_sections(AOTObjectDataSection *data_sections, uint32 i; AOTObjectDataSection *data_section = data_sections; for (i = 0; i < data_section_count; i++, data_section++) - if (data_section->data) + if (data_section->data) { +#if WASM_ENABLE_STATIC_PGO != 0 + if (!strncmp(data_section->name, "__llvm_prf_data", 15)) { + LLVMProfileData *data = (LLVMProfileData *)data_section->data; + if (data->values) { + uint32 num_value_sites = + data->num_value_sites[0] + data->num_value_sites[1]; + uint32 j; + for (j = 0; j < num_value_sites; j++) { + ValueProfNode *node = data->values[j], *node_next; + while (node) { + node_next = node->next; + wasm_runtime_free(node); + node = node_next; + } + } + wasm_runtime_free(data->values); + } + } +#endif os_munmap(data_section->data, data_section->size); + } wasm_runtime_free(data_sections); } @@ -1470,8 +1573,9 @@ load_object_data_sections(const uint8 **p_buf, const uint8 *buf_end, /* Allocate memory for data */ if (data_sections[i].size > 0 - && !(data_sections[i].data = os_mmap(NULL, data_sections[i].size, - map_prot, map_flags))) { + && !(data_sections[i].data = + os_mmap(NULL, data_sections[i].size, map_prot, map_flags, + os_get_invalid_handle()))) { set_error_buf(error_buf, error_buf_size, "allocate memory failed"); return false; } @@ -1624,27 +1728,6 @@ load_function_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module, const uint8 *p = buf, *p_end = buf_end; uint32 i; uint64 size, text_offset; -#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS) - RUNTIME_FUNCTION *rtl_func_table; - AOTUnwindInfo *unwind_info; - uint32 unwind_info_offset = module->code_size - sizeof(AOTUnwindInfo); - uint32 unwind_code_offset = unwind_info_offset - PLT_ITEM_SIZE; -#endif - -#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS) - unwind_info = (AOTUnwindInfo *)((uint8 *)module->code + module->code_size - - sizeof(AOTUnwindInfo)); - unwind_info->Version = 1; - unwind_info->Flags = UNW_FLAG_NHANDLER; - *(uint32 *)&unwind_info->UnwindCode[0] = unwind_code_offset; - - size = sizeof(RUNTIME_FUNCTION) * (uint64)module->func_count; - if (size > 0 - && !(rtl_func_table = module->rtl_func_table = - loader_malloc(size, error_buf, error_buf_size))) { - return false; - } -#endif size = sizeof(void *) * (uint64)module->func_count; if (size > 0 @@ -1671,33 +1754,9 @@ load_function_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module, #if defined(BUILD_TARGET_THUMB) || defined(BUILD_TARGET_THUMB_VFP) /* bits[0] of thumb function address must be 1 */ module->func_ptrs[i] = (void *)((uintptr_t)module->func_ptrs[i] | 1); -#endif -#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS) - rtl_func_table[i].BeginAddress = (DWORD)text_offset; - if (i > 0) { - rtl_func_table[i - 1].EndAddress = rtl_func_table[i].BeginAddress; - } - rtl_func_table[i].UnwindInfoAddress = (DWORD)unwind_info_offset; #endif } -#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS) - if (module->func_count > 0) { - uint32 plt_table_size = - module->is_indirect_mode ? 0 : get_plt_table_size(); - rtl_func_table[module->func_count - 1].EndAddress = - (DWORD)(module->code_size - plt_table_size); - - if (!RtlAddFunctionTable(rtl_func_table, module->func_count, - (DWORD64)(uintptr_t)module->code)) { - set_error_buf(error_buf, error_buf_size, - "add dynamic function table failed"); - return false; - } - module->rtl_func_table_registered = true; - } -#endif - /* Set start function when function pointers are resolved */ if (module->start_func_index != (uint32)-1) { if (module->start_func_index >= module->import_func_count) @@ -1823,6 +1882,13 @@ get_data_section_addr(AOTModule *module, const char *section_name, return NULL; } +const void * +aot_get_data_section_addr(AOTModule *module, const char *section_name, + uint32 *p_data_size) +{ + return get_data_section_addr(module, section_name, p_data_size); +} + static void * resolve_target_sym(const char *symbol, int32 *p_index) { @@ -1900,6 +1966,8 @@ str2uint64(const char *buf, uint64 *p_res) return true; } +#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative offset to GOT */ + static bool do_text_relocation(AOTModule *module, AOTRelocationGroup *group, char *error_buf, uint32 error_buf_size) @@ -1937,6 +2005,14 @@ do_text_relocation(AOTModule *module, AOTRelocationGroup *group, bh_memcpy_s(symbol, symbol_len, relocation->symbol_name, symbol_len); symbol[symbol_len] = '\0'; +#if WASM_ENABLE_STATIC_PGO != 0 + if (!strcmp(symbol, "__llvm_profile_runtime") + || !strcmp(symbol, "__llvm_profile_register_function") + || !strcmp(symbol, "__llvm_profile_register_names_function")) { + continue; + } +#endif + if (!strncmp(symbol, AOT_FUNC_PREFIX, strlen(AOT_FUNC_PREFIX))) { p = symbol + strlen(AOT_FUNC_PREFIX); if (*p == '\0' @@ -1945,8 +2021,41 @@ do_text_relocation(AOTModule *module, AOTRelocationGroup *group, "invalid import symbol %s", symbol); goto check_symbol_fail; } +#if (defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)) \ + && !defined(BH_PLATFORM_WINDOWS) + if (relocation->relocation_type == R_X86_64_GOTPCREL) { + GOTItem *got_item = module->got_item_list; + uint32 got_item_idx = 0; + + while (got_item) { + if (got_item->func_idx == func_index) + break; + got_item_idx++; + got_item = got_item->next; + } + /* Calculate `GOT + G` */ + symbol_addr = module->got_func_ptrs + got_item_idx; + } + else + symbol_addr = module->func_ptrs[func_index]; +#else symbol_addr = module->func_ptrs[func_index]; +#endif } +#if defined(BH_PLATFORM_WINDOWS) && defined(BUILD_TARGET_X86_32) + /* AOT function name starts with '_' in windows x86-32 */ + else if (!strncmp(symbol, "_" AOT_FUNC_PREFIX, + strlen("_" AOT_FUNC_PREFIX))) { + p = symbol + strlen("_" AOT_FUNC_PREFIX); + if (*p == '\0' + || (func_index = (uint32)atoi(p)) > module->func_count) { + set_error_buf_v(error_buf, error_buf_size, "invalid symbol %s", + symbol); + goto check_symbol_fail; + } + symbol_addr = module->func_ptrs[func_index]; + } +#endif else if (!strcmp(symbol, ".text")) { symbol_addr = module->code; } @@ -1956,7 +2065,14 @@ do_text_relocation(AOTModule *module, AOTRelocationGroup *group, /* ".rodata.cst4/8/16/.." */ || !strncmp(symbol, ".rodata.cst", strlen(".rodata.cst")) /* ".rodata.strn.m" */ - || !strncmp(symbol, ".rodata.str", strlen(".rodata.str"))) { + || !strncmp(symbol, ".rodata.str", strlen(".rodata.str")) + || !strcmp(symbol, AOT_STACK_SIZES_SECTION_NAME) +#if WASM_ENABLE_STATIC_PGO != 0 + || !strncmp(symbol, "__llvm_prf_cnts", 15) + || !strncmp(symbol, "__llvm_prf_data", 15) + || !strncmp(symbol, "__llvm_prf_names", 16) +#endif + ) { symbol_addr = get_data_section_addr(module, symbol, NULL); if (!symbol_addr) { set_error_buf_v(error_buf, error_buf_size, @@ -2088,6 +2204,14 @@ do_data_relocation(AOTModule *module, AOTRelocationGroup *group, else if (!strcmp(group->section_name, ".rdata")) { data_section_name = group->section_name; } +#if WASM_ENABLE_STATIC_PGO != 0 + else if (!strncmp(group->section_name, ".rel__llvm_prf_data", 19)) { + data_section_name = group->section_name + strlen(".rel"); + } + else if (!strncmp(group->section_name, ".rela__llvm_prf_data", 20)) { + data_section_name = group->section_name + strlen(".rela"); + } +#endif else { set_error_buf(error_buf, error_buf_size, "invalid data relocation section name"); @@ -2107,6 +2231,49 @@ do_data_relocation(AOTModule *module, AOTRelocationGroup *group, if (!strcmp(symbol, ".text")) { symbol_addr = module->code; } +#if WASM_ENABLE_STATIC_PGO != 0 + else if (!strncmp(symbol, AOT_FUNC_PREFIX, strlen(AOT_FUNC_PREFIX))) { + char *p = symbol + strlen(AOT_FUNC_PREFIX); + uint32 func_index; + if (*p == '\0' + || (func_index = (uint32)atoi(p)) > module->func_count) { + set_error_buf_v(error_buf, error_buf_size, + "invalid relocation symbol %s", symbol); + return false; + } + symbol_addr = module->func_ptrs[func_index]; + } + else if (!strcmp(symbol, "__llvm_prf_cnts")) { + uint32 j; + for (j = 0; j < module->data_section_count; j++) { + if (!strncmp(module->data_sections[j].name, symbol, 15)) { + bh_assert(relocation->relocation_addend + sizeof(uint64) + <= module->data_sections[j].size); + symbol_addr = module->data_sections[j].data; + break; + } + } + if (j == module->data_section_count) { + set_error_buf_v(error_buf, error_buf_size, + "invalid relocation symbol %s", symbol); + return false; + } + } + else if (!strncmp(symbol, "__llvm_prf_cnts", 15)) { + uint32 j; + for (j = 0; j < module->data_section_count; j++) { + if (!strcmp(module->data_sections[j].name, symbol)) { + symbol_addr = module->data_sections[j].data; + break; + } + } + if (j == module->data_section_count) { + set_error_buf_v(error_buf, error_buf_size, + "invalid relocation symbol %s", symbol); + return false; + } + } +#endif /* end of WASM_ENABLE_STATIC_PGO != 0 */ else { set_error_buf_v(error_buf, error_buf_size, "invalid relocation symbol %s", symbol); @@ -2154,7 +2321,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end, { AOTRelocationGroup *groups = NULL, *group; uint32 symbol_count = 0; - uint32 group_count = 0, i, j; + uint32 group_count = 0, i, j, got_item_count = 0; uint64 size; uint32 *symbol_offsets, total_string_len; uint8 *symbol_buf, *symbol_buf_end; @@ -2216,6 +2383,8 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end, for (j = 0; j < relocation_count; j++) { AOTRelocation relocation = { 0 }; + char group_name_buf[128] = { 0 }; + char symbol_name_buf[128] = { 0 }; uint32 symbol_index, offset32; int32 addend32; uint16 symbol_name_len; @@ -2244,10 +2413,10 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end, symbol_name_len = *(uint16 *)symbol_name; symbol_name += sizeof(uint16); - char group_name_buf[128] = { 0 }; - char symbol_name_buf[128] = { 0 }; - memcpy(group_name_buf, group_name, group_name_len); - memcpy(symbol_name_buf, symbol_name, symbol_name_len); + bh_memcpy_s(group_name_buf, (uint32)sizeof(group_name_buf), + group_name, group_name_len); + bh_memcpy_s(symbol_name_buf, (uint32)sizeof(symbol_name_buf), + symbol_name, symbol_name_len); if ((group_name_len == strlen(".text") || (module->is_indirect_mode @@ -2301,7 +2470,8 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end, if (size > UINT32_MAX || !(module->extra_plt_data = - os_mmap(NULL, (uint32)size, map_prot, map_flags))) { + os_mmap(NULL, (uint32)size, map_prot, map_flags, + os_get_invalid_handle()))) { set_error_buf(error_buf, error_buf_size, "mmap memory failed"); goto fail; } @@ -2309,6 +2479,140 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end, } #endif /* end of defined(BH_PLATFORM_WINDOWS) */ +#if (defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)) \ + && !defined(BH_PLATFORM_WINDOWS) + buf = symbol_buf_end; + read_uint32(buf, buf_end, group_count); + + /* Resolve the relocations of type R_X86_64_GOTPCREL */ + for (i = 0; i < group_count; i++) { + uint32 name_index, relocation_count; + uint16 group_name_len; + uint8 *group_name; + + /* section name address is 4 bytes aligned. */ + buf = (uint8 *)align_ptr(buf, sizeof(uint32)); + read_uint32(buf, buf_end, name_index); + + if (name_index >= symbol_count) { + set_error_buf(error_buf, error_buf_size, + "symbol index out of range"); + goto fail; + } + + group_name = symbol_buf + symbol_offsets[name_index]; + group_name_len = *(uint16 *)group_name; + group_name += sizeof(uint16); + + read_uint32(buf, buf_end, relocation_count); + + for (j = 0; j < relocation_count; j++) { + AOTRelocation relocation = { 0 }; + char group_name_buf[128] = { 0 }; + char symbol_name_buf[128] = { 0 }; + uint32 symbol_index; + uint16 symbol_name_len; + uint8 *symbol_name; + + /* relocation offset and addend */ + buf += sizeof(void *) * 2; + + read_uint32(buf, buf_end, relocation.relocation_type); + read_uint32(buf, buf_end, symbol_index); + + if (symbol_index >= symbol_count) { + set_error_buf(error_buf, error_buf_size, + "symbol index out of range"); + goto fail; + } + + symbol_name = symbol_buf + symbol_offsets[symbol_index]; + symbol_name_len = *(uint16 *)symbol_name; + symbol_name += sizeof(uint16); + + bh_memcpy_s(group_name_buf, (uint32)sizeof(group_name_buf), + group_name, group_name_len); + bh_memcpy_s(symbol_name_buf, (uint32)sizeof(symbol_name_buf), + symbol_name, symbol_name_len); + + if (relocation.relocation_type == R_X86_64_GOTPCREL + && !strncmp(symbol_name_buf, AOT_FUNC_PREFIX, + strlen(AOT_FUNC_PREFIX))) { + uint32 func_idx = + atoi(symbol_name_buf + strlen(AOT_FUNC_PREFIX)); + GOTItem *got_item = module->got_item_list; + + if (func_idx >= module->func_count) { + set_error_buf(error_buf, error_buf_size, + "func index out of range"); + goto fail; + } + + while (got_item) { + if (got_item->func_idx == func_idx) + break; + got_item = got_item->next; + } + + if (!got_item) { + /* Create the got item and append to the list */ + got_item = wasm_runtime_malloc(sizeof(GOTItem)); + if (!got_item) { + set_error_buf(error_buf, error_buf_size, + "allocate memory failed"); + goto fail; + } + + got_item->func_idx = func_idx; + got_item->next = NULL; + if (!module->got_item_list) { + module->got_item_list = module->got_item_list_end = + got_item; + } + else { + module->got_item_list_end->next = got_item; + module->got_item_list_end = got_item; + } + + got_item_count++; + } + } + } + } + + if (got_item_count) { + GOTItem *got_item = module->got_item_list; + uint32 got_item_idx = 0; + + map_prot = MMAP_PROT_READ | MMAP_PROT_WRITE; + /* aot code and data in x86_64 must be in range 0 to 2G due to + relocation for R_X86_64_32/32S/PC32 */ + map_flags = MMAP_MAP_32BIT; + + /* Create the GOT for func_ptrs, note that it is different from + the .got section of a dynamic object file */ + size = (uint64)sizeof(void *) * got_item_count; + if (size > UINT32_MAX + || !(module->got_func_ptrs = + os_mmap(NULL, (uint32)size, map_prot, map_flags, + os_get_invalid_handle()))) { + set_error_buf(error_buf, error_buf_size, "mmap memory failed"); + goto fail; + } + + while (got_item) { + module->got_func_ptrs[got_item_idx++] = + module->func_ptrs[got_item->func_idx]; + got_item = got_item->next; + } + + module->got_item_count = got_item_count; + } +#else + (void)got_item_count; +#endif /* (defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)) && \ + !defined(BH_PLATFORM_WINDOWS) */ + buf = symbol_buf_end; read_uint32(buf, buf_end, group_count); @@ -2653,6 +2957,7 @@ create_module(char *error_buf, uint32 error_buf_size) { AOTModule *module = loader_malloc(sizeof(AOTModule), error_buf, error_buf_size); + bh_list_status ret; if (!module) { return NULL; @@ -2660,6 +2965,13 @@ create_module(char *error_buf, uint32 error_buf_size) module->module_type = Wasm_Module_AoT; +#if WASM_ENABLE_MULTI_MODULE != 0 + module->import_module_list = &module->import_module_list_head; + ret = bh_list_init(module->import_module_list); + bh_assert(ret == BH_LIST_SUCCESS); +#endif + (void)ret; + return module; } @@ -2750,6 +3062,9 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size, uint32 section_size; uint64 total_size; uint8 *aot_text; +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) + uint8 *mirrored_text; +#endif if (!resolve_execute_mode(buf, size, &is_indirect_mode, error_buf, error_buf_size)) { @@ -2793,8 +3108,9 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size, (uint64)section_size + aot_get_plt_table_size(); total_size = (total_size + 3) & ~((uint64)3); if (total_size >= UINT32_MAX - || !(aot_text = os_mmap(NULL, (uint32)total_size, - map_prot, map_flags))) { + || !(aot_text = + os_mmap(NULL, (uint32)total_size, map_prot, + map_flags, os_get_invalid_handle()))) { wasm_runtime_free(section); set_error_buf(error_buf, error_buf_size, "mmap memory failed"); @@ -2808,8 +3124,17 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size, bh_assert((uintptr_t)aot_text < INT32_MAX); #endif #endif + +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) + mirrored_text = os_get_dbus_mirror(aot_text); + bh_assert(mirrored_text != NULL); + bh_memcpy_s(mirrored_text, (uint32)total_size, + section->section_body, (uint32)section_size); + os_dcache_flush(); +#else bh_memcpy_s(aot_text, (uint32)total_size, section->section_body, (uint32)section_size); +#endif section->section_body = aot_text; destroy_aot_text = true; @@ -2889,6 +3214,16 @@ load(const uint8 *buf, uint32 size, AOTModule *module, char *error_buf, module->code and will be destroyed in aot_unload() */ destroy_sections(section_list, false); } + +#if 0 + { + uint32 i; + for (i = 0; i < module->func_count; i++) { + os_printf("AOT func %u, addr: %p\n", i, module->func_ptrs[i]); + } + } +#endif + return ret; fail: return false; @@ -2903,10 +3238,13 @@ aot_load_from_aot_file(const uint8 *buf, uint32 size, char *error_buf, if (!module) return NULL; + os_thread_jit_write_protect_np(false); /* Make memory writable */ if (!load(buf, size, module, error_buf, error_buf_size)) { aot_unload(module); return NULL; } + os_thread_jit_write_protect_np(true); /* Make memory executable */ + os_icache_flush(module->code, module->code_size); LOG_VERBOSE("Load module success.\n"); return module; @@ -2961,6 +3299,19 @@ aot_unload(AOTModule *module) if (module->const_str_set) bh_hash_map_destroy(module->const_str_set); +#if WASM_ENABLE_MULTI_MODULE != 0 + /* just release the sub module list */ + if (module->import_module_list) { + WASMRegisteredModule *node = + bh_list_first_elem(module->import_module_list); + while (node) { + WASMRegisteredModule *next = bh_list_elem_next(node); + bh_list_remove(module->import_module_list, node); + wasm_runtime_free(node); + node = next; + } + } +#endif if (module->code && !module->is_indirect_mode) { /* The layout is: literal size + literal + code (with plt table) */ @@ -2976,17 +3327,27 @@ aot_unload(AOTModule *module) } #endif -#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS) - if (module->rtl_func_table) { - if (module->rtl_func_table_registered) - RtlDeleteFunctionTable(module->rtl_func_table); - wasm_runtime_free(module->rtl_func_table); +#if (defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)) \ + && !defined(BH_PLATFORM_WINDOWS) + { + GOTItem *got_item = module->got_item_list, *got_item_next; + + if (module->got_func_ptrs) { + os_munmap(module->got_func_ptrs, + sizeof(void *) * module->got_item_count); + } + while (got_item) { + got_item_next = got_item->next; + wasm_runtime_free(got_item); + got_item = got_item_next; + } } #endif if (module->data_sections) destroy_object_data_sections(module->data_sections, module->data_section_count); + #if WASM_ENABLE_DEBUG_AOT != 0 jit_code_entry_destroy(module->elf_hdr); #endif @@ -3033,3 +3394,23 @@ aot_get_custom_section(const AOTModule *module, const char *name, uint32 *len) return NULL; } #endif /* end of WASM_ENABLE_LOAD_CUSTOM_SECTION */ + +#if WASM_ENABLE_STATIC_PGO != 0 +void +aot_exchange_uint16(uint8 *p_data) +{ + return exchange_uint16(p_data); +} + +void +aot_exchange_uint32(uint8 *p_data) +{ + return exchange_uint32(p_data); +} + +void +aot_exchange_uint64(uint8 *p_data) +{ + return exchange_uint64(p_data); +} +#endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_reloc.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_reloc.h similarity index 95% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_reloc.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_reloc.h index 9f5c2d57fd8..98df09cb4f2 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_reloc.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_reloc.h @@ -121,6 +121,14 @@ typedef struct { REG_SYM(aot_intrinsic_i32_rem_s), \ REG_SYM(aot_intrinsic_i32_rem_u), \ +#if WASM_ENABLE_STATIC_PGO != 0 +#define REG_LLVM_PGO_SYM() \ + { "__llvm_profile_instrument_target", llvm_profile_instrument_target }, \ + { "__llvm_profile_instrument_memop", llvm_profile_instrument_memop }, +#else +#define REG_LLVM_PGO_SYM() +#endif + #define REG_COMMON_SYMBOLS \ REG_SYM(aot_set_exception_with_id), \ REG_SYM(aot_invoke_native), \ @@ -150,6 +158,7 @@ typedef struct { REG_REF_TYPES_SYM() \ REG_AOT_TRACE_SYM() \ REG_INTRINSIC_SYM() \ + REG_LLVM_PGO_SYM() \ #define CHECK_RELOC_OFFSET(data_size) do { \ if (!check_reloc_offset(target_section_size, \ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_runtime.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_runtime.c similarity index 73% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_runtime.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_runtime.c index b5c406b960d..076574cb737 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_runtime.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_runtime.c @@ -7,6 +7,7 @@ #include "bh_log.h" #include "mem_alloc.h" #include "../common/wasm_runtime_common.h" +#include "../common/wasm_memory.h" #include "../interpreter/wasm_runtime.h" #if WASM_ENABLE_SHARED_MEMORY != 0 #include "../common/wasm_shared_memory.h" @@ -42,6 +43,11 @@ bh_static_assert(offsetof(AOTModuleInstance, cur_exception) bh_static_assert(offsetof(AOTModuleInstance, global_table_data) == 13 * sizeof(uint64) + 128 + 11 * sizeof(uint64)); +bh_static_assert(sizeof(AOTMemoryInstance) == 104); +bh_static_assert(offsetof(AOTTableInstance, elems) == 8); + +bh_static_assert(offsetof(AOTModuleInstanceExtra, stack_sizes) == 0); + static void set_error_buf(char *error_buf, uint32 error_buf_size, const char *string) { @@ -334,11 +340,8 @@ memories_deinstantiate(AOTModuleInstance *module_inst) memory_inst = module_inst->memories[i]; if (memory_inst) { #if WASM_ENABLE_SHARED_MEMORY != 0 - if (memory_inst->is_shared) { - int32 ref_count = shared_memory_dec_reference( - (WASMModuleCommon *)module_inst->module); - bh_assert(ref_count >= 0); - + if (shared_memory_is_shared(memory_inst)) { + uint32 ref_count = shared_memory_dec_reference(memory_inst); /* if the reference count is not zero, don't free the memory */ if (ref_count > 0) @@ -368,9 +371,10 @@ memories_deinstantiate(AOTModuleInstance *module_inst) } static AOTMemoryInstance * -memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module, - AOTMemoryInstance *memory_inst, AOTMemory *memory, - uint32 heap_size, char *error_buf, uint32 error_buf_size) +memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent, + AOTModule *module, AOTMemoryInstance *memory_inst, + AOTMemory *memory, uint32 memory_idx, uint32 heap_size, + char *error_buf, uint32 error_buf_size) { void *heap_handle; uint32 num_bytes_per_page = memory->num_bytes_per_page; @@ -379,7 +383,7 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module, uint32 inc_page_count, aux_heap_base, global_idx; uint32 bytes_of_last_page, bytes_to_page_end; uint32 heap_offset = num_bytes_per_page * init_page_count; - uint64 total_size; + uint64 memory_data_size, max_memory_data_size; uint8 *p = NULL, *global_addr; #ifdef OS_ENABLE_HW_BOUND_CHECK uint8 *mapped_mem; @@ -391,23 +395,13 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module, bool is_shared_memory = memory->memory_flags & 0x02 ? true : false; /* Shared memory */ - if (is_shared_memory) { + if (is_shared_memory && parent != NULL) { AOTMemoryInstance *shared_memory_instance; - WASMSharedMemNode *node = - wasm_module_get_shared_memory((WASMModuleCommon *)module); - /* If the memory of this module has been instantiated, - return the memory instance directly */ - if (node) { - uint32 ref_count; - ref_count = shared_memory_inc_reference((WASMModuleCommon *)module); - bh_assert(ref_count > 0); - shared_memory_instance = - (AOTMemoryInstance *)shared_memory_get_memory_inst(node); - bh_assert(shared_memory_instance); - - (void)ref_count; - return shared_memory_instance; - } + bh_assert(memory_idx == 0); + bh_assert(parent->memory_count > memory_idx); + shared_memory_instance = parent->memories[memory_idx]; + shared_memory_inc_reference(shared_memory_instance); + return shared_memory_instance; } #endif @@ -427,7 +421,7 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module, if (num_bytes_per_page < heap_size) { set_error_buf(error_buf, error_buf_size, "failed to insert app heap into linear memory, " - "try using `--heap_size=0` option"); + "try using `--heap-size=0` option"); return NULL; } } @@ -485,7 +479,7 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module, if (init_page_count > DEFAULT_MAX_PAGES) { set_error_buf(error_buf, error_buf_size, "failed to insert app heap into linear memory, " - "try using `--heap_size=0` option"); + "try using `--heap-size=0` option"); return NULL; } else if (init_page_count == DEFAULT_MAX_PAGES) { @@ -495,6 +489,12 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module, if (max_page_count > DEFAULT_MAX_PAGES) max_page_count = DEFAULT_MAX_PAGES; } + else { /* heap_size == 0 */ + if (init_page_count == DEFAULT_MAX_PAGES) { + num_bytes_per_page = UINT32_MAX; + init_page_count = max_page_count = 1; + } + } LOG_VERBOSE("Memory instantiate:"); LOG_VERBOSE(" page bytes: %u, init pages: %u, max pages: %u", @@ -503,67 +503,80 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module, module->aux_stack_size); LOG_VERBOSE(" heap offset: %u, heap size: %d\n", heap_offset, heap_size); - total_size = (uint64)num_bytes_per_page * init_page_count; + memory_data_size = (uint64)num_bytes_per_page * init_page_count; + max_memory_data_size = (uint64)num_bytes_per_page * max_page_count; + bh_assert(memory_data_size <= UINT32_MAX); + bh_assert(max_memory_data_size <= 4 * (uint64)BH_GB); + (void)max_memory_data_size; + +#ifndef OS_ENABLE_HW_BOUND_CHECK #if WASM_ENABLE_SHARED_MEMORY != 0 if (is_shared_memory) { - /* Allocate max page for shared memory */ - total_size = (uint64)num_bytes_per_page * max_page_count; + /* Allocate maximum memory size when memory is shared */ + if (max_memory_data_size > 0 + && !(p = runtime_malloc(max_memory_data_size, error_buf, + error_buf_size))) { + return NULL; + } } + else #endif - bh_assert(total_size <= UINT32_MAX); - -#ifndef OS_ENABLE_HW_BOUND_CHECK - /* Allocate memory */ - if (total_size > 0 - && !(p = runtime_malloc(total_size, error_buf, error_buf_size))) { - return NULL; + { + /* Allocate initial memory size when memory is not shared */ + if (memory_data_size > 0 + && !(p = runtime_malloc(memory_data_size, error_buf, + error_buf_size))) { + return NULL; + } } -#else - total_size = (total_size + page_size - 1) & ~(page_size - 1); +#else /* else of OS_ENABLE_HW_BOUND_CHECK */ + memory_data_size = (memory_data_size + page_size - 1) & ~(page_size - 1); /* Totally 8G is mapped, the opcode load/store address range is 0 to 8G: * ea = i + memarg.offset * both i and memarg.offset are u32 in range 0 to 4G * so the range of ea is 0 to 8G */ - if (!(p = mapped_mem = - os_mmap(NULL, map_size, MMAP_PROT_NONE, MMAP_MAP_NONE))) { + if (!(p = mapped_mem = os_mmap(NULL, map_size, MMAP_PROT_NONE, + MMAP_MAP_NONE, os_get_invalid_handle()))) { set_error_buf(error_buf, error_buf_size, "mmap memory failed"); return NULL; } #ifdef BH_PLATFORM_WINDOWS - if (!os_mem_commit(p, total_size, MMAP_PROT_READ | MMAP_PROT_WRITE)) { + if (!os_mem_commit(p, memory_data_size, MMAP_PROT_READ | MMAP_PROT_WRITE)) { set_error_buf(error_buf, error_buf_size, "commit memory failed"); os_munmap(mapped_mem, map_size); return NULL; } #endif - if (os_mprotect(p, total_size, MMAP_PROT_READ | MMAP_PROT_WRITE) != 0) { + if (os_mprotect(p, memory_data_size, MMAP_PROT_READ | MMAP_PROT_WRITE) + != 0) { set_error_buf(error_buf, error_buf_size, "mprotect memory failed"); #ifdef BH_PLATFORM_WINDOWS - os_mem_decommit(p, total_size); + os_mem_decommit(p, memory_data_size); #endif os_munmap(mapped_mem, map_size); return NULL; } + /* Newly allocated pages are filled with zero by the OS, we don't fill it * again here */ -#endif /* end of OS_ENABLE_HW_BOUND_CHECK */ - if (total_size > UINT32_MAX) - total_size = UINT32_MAX; + if (memory_data_size > UINT32_MAX) + memory_data_size = UINT32_MAX; +#endif /* end of OS_ENABLE_HW_BOUND_CHECK */ memory_inst->module_type = Wasm_Module_AoT; memory_inst->num_bytes_per_page = num_bytes_per_page; memory_inst->cur_page_count = init_page_count; memory_inst->max_page_count = max_page_count; - memory_inst->memory_data_size = (uint32)total_size; + memory_inst->memory_data_size = (uint32)memory_data_size; /* Init memory info */ memory_inst->memory_data = p; - memory_inst->memory_data_end = p + (uint32)total_size; + memory_inst->memory_data_end = p + (uint32)memory_data_size; /* Initialize heap info */ memory_inst->heap_data = p + heap_offset; @@ -586,41 +599,19 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module, } } - if (total_size > 0) { -#if UINTPTR_MAX == UINT64_MAX - memory_inst->mem_bound_check_1byte.u64 = total_size - 1; - memory_inst->mem_bound_check_2bytes.u64 = total_size - 2; - memory_inst->mem_bound_check_4bytes.u64 = total_size - 4; - memory_inst->mem_bound_check_8bytes.u64 = total_size - 8; - memory_inst->mem_bound_check_16bytes.u64 = total_size - 16; -#else - memory_inst->mem_bound_check_1byte.u32[0] = (uint32)total_size - 1; - memory_inst->mem_bound_check_2bytes.u32[0] = (uint32)total_size - 2; - memory_inst->mem_bound_check_4bytes.u32[0] = (uint32)total_size - 4; - memory_inst->mem_bound_check_8bytes.u32[0] = (uint32)total_size - 8; - memory_inst->mem_bound_check_16bytes.u32[0] = (uint32)total_size - 16; -#endif + if (memory_data_size > 0) { + wasm_runtime_set_mem_bound_check_bytes(memory_inst, memory_data_size); } #if WASM_ENABLE_SHARED_MEMORY != 0 if (is_shared_memory) { - memory_inst->is_shared = true; - if (!shared_memory_set_memory_inst( - (WASMModuleCommon *)module, - (WASMMemoryInstanceCommon *)memory_inst)) { - set_error_buf(error_buf, error_buf_size, "allocate memory failed"); - goto fail3; - } + memory_inst->is_shared_memory = 1; + memory_inst->ref_count = 1; } #endif return memory_inst; -#if WASM_ENABLE_SHARED_MEMORY != 0 -fail3: - if (heap_size > 0) - mem_allocator_destroy(memory_inst->heap_handle); -#endif fail2: if (heap_size > 0) wasm_runtime_free(memory_inst->heap_handle); @@ -631,7 +622,7 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModule *module, #else #ifdef BH_PLATFORM_WINDOWS if (memory_inst->memory_data) - os_mem_decommit(p, total_size); + os_mem_decommit(p, memory_data_size); #endif os_munmap(mapped_mem, map_size); #endif @@ -649,8 +640,9 @@ aot_get_default_memory(AOTModuleInstance *module_inst) } static bool -memories_instantiate(AOTModuleInstance *module_inst, AOTModule *module, - uint32 heap_size, char *error_buf, uint32 error_buf_size) +memories_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent, + AOTModule *module, uint32 heap_size, char *error_buf, + uint32 error_buf_size) { uint32 global_index, global_data_offset, base_offset, length; uint32 i, memory_count = module->memory_count; @@ -667,8 +659,8 @@ memories_instantiate(AOTModuleInstance *module_inst, AOTModule *module, memories = module_inst->global_table_data.memory_instances; for (i = 0; i < memory_count; i++, memories++) { - memory_inst = memory_instantiate(module_inst, module, memories, - &module->memories[i], heap_size, + memory_inst = memory_instantiate(module_inst, parent, module, memories, + &module->memories[i], i, heap_size, error_buf, error_buf_size); if (!memory_inst) { return false; @@ -690,6 +682,10 @@ memories_instantiate(AOTModuleInstance *module_inst, AOTModule *module, if (data_seg->is_passive) continue; #endif + if (parent != NULL) + /* Ignore setting memory init data if the memory has been + initialized */ + continue; bh_assert(data_seg->offset.init_expr_type == INIT_EXPR_TYPE_I32_CONST || data_seg->offset.init_expr_type @@ -986,7 +982,8 @@ execute_post_instantiate_functions(AOTModuleInstance *module_inst, wasm functions, and ensure that the exec_env's module inst is the correct one. */ module_inst_main = exec_env_main->module_inst; - exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst; + wasm_exec_env_set_module_inst(exec_env, + (WASMModuleInstanceCommon *)module_inst); } else { /* Try using the existing exec_env */ @@ -1011,10 +1008,20 @@ execute_post_instantiate_functions(AOTModuleInstance *module_inst, module inst to ensure that the exec_env's module inst is the correct one. */ module_inst_main = exec_env->module_inst; - exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst; + wasm_exec_env_set_module_inst( + exec_env, (WASMModuleInstanceCommon *)module_inst); } } +#if defined(os_writegsbase) + { + AOTMemoryInstance *memory_inst = aot_get_default_memory(module_inst); + if (memory_inst) + /* write base addr of linear memory to GS segment register */ + os_writegsbase(memory_inst->memory_data); + } +#endif + /* Execute start function for both main insance and sub instance */ if (module->start_function) { AOTFunctionInstance start_func = { 0 }; @@ -1052,12 +1059,12 @@ execute_post_instantiate_functions(AOTModuleInstance *module_inst, fail: if (is_sub_inst) { /* Restore the parent exec_env's module inst */ - exec_env_main->module_inst = module_inst_main; + wasm_exec_env_restore_module_inst(exec_env_main, module_inst_main); } else { if (module_inst_main) /* Restore the existing exec_env's module inst */ - exec_env->module_inst = module_inst_main; + wasm_exec_env_restore_module_inst(exec_env, module_inst_main); if (exec_env_created) wasm_exec_env_destroy(exec_env_created); } @@ -1086,11 +1093,14 @@ check_linked_symbol(AOTModule *module, char *error_buf, uint32 error_buf_size) } AOTModuleInstance * -aot_instantiate(AOTModule *module, bool is_sub_inst, WASMExecEnv *exec_env_main, - uint32 stack_size, uint32 heap_size, char *error_buf, - uint32 error_buf_size) +aot_instantiate(AOTModule *module, AOTModuleInstance *parent, + WASMExecEnv *exec_env_main, uint32 stack_size, uint32 heap_size, + char *error_buf, uint32 error_buf_size) { AOTModuleInstance *module_inst; +#if WASM_ENABLE_BULK_MEMORY != 0 || WASM_ENABLE_REF_TYPES != 0 + WASMModuleInstanceExtraCommon *common; +#endif const uint32 module_inst_struct_size = offsetof(AOTModuleInstance, global_table_data.bytes); const uint64 module_inst_mem_inst_size = @@ -1098,6 +1108,10 @@ aot_instantiate(AOTModule *module, bool is_sub_inst, WASMExecEnv *exec_env_main, uint64 total_size, table_size = 0; uint8 *p; uint32 i, extra_info_offset; + const bool is_sub_inst = parent != NULL; +#if WASM_ENABLE_MULTI_MODULE != 0 + bool ret = false; +#endif /* Check heap size */ heap_size = align_uint(heap_size, 8); @@ -1141,6 +1155,44 @@ aot_instantiate(AOTModule *module, bool is_sub_inst, WASMExecEnv *exec_env_main, module_inst->e = (WASMModuleInstanceExtra *)((uint8 *)module_inst + extra_info_offset); +#if WASM_ENABLE_MULTI_MODULE != 0 + ((AOTModuleInstanceExtra *)module_inst->e)->sub_module_inst_list = + &((AOTModuleInstanceExtra *)module_inst->e)->sub_module_inst_list_head; + ret = wasm_runtime_sub_module_instantiate( + (WASMModuleCommon *)module, (WASMModuleInstanceCommon *)module_inst, + stack_size, heap_size, error_buf, error_buf_size); + if (!ret) { + LOG_DEBUG("build a sub module list failed"); + goto fail; + } +#endif + +#if WASM_ENABLE_BULK_MEMORY != 0 || WASM_ENABLE_REF_TYPES != 0 + common = &((AOTModuleInstanceExtra *)module_inst->e)->common; +#endif +#if WASM_ENABLE_BULK_MEMORY != 0 + if (module->mem_init_data_count > 0) { + common->data_dropped = bh_bitmap_new(0, module->mem_init_data_count); + if (common->data_dropped == NULL) { + LOG_DEBUG("failed to allocate bitmaps"); + set_error_buf(error_buf, error_buf_size, + "failed to allocate bitmaps"); + goto fail; + } + } +#endif +#if WASM_ENABLE_REF_TYPES != 0 + if (module->table_init_data_count > 0) { + common->elem_dropped = bh_bitmap_new(0, module->table_init_data_count); + if (common->elem_dropped == NULL) { + LOG_DEBUG("failed to allocate bitmaps"); + set_error_buf(error_buf, error_buf_size, + "failed to allocate bitmaps"); + goto fail; + } + } +#endif + /* Initialize global info */ p = (uint8 *)module_inst + module_inst_struct_size + module_inst_mem_inst_size; @@ -1157,7 +1209,7 @@ aot_instantiate(AOTModule *module, bool is_sub_inst, WASMExecEnv *exec_env_main, goto fail; /* Initialize memory space */ - if (!memories_instantiate(module_inst, module, heap_size, error_buf, + if (!memories_instantiate(module_inst, parent, module, heap_size, error_buf, error_buf_size)) goto fail; @@ -1192,17 +1244,6 @@ aot_instantiate(AOTModule *module, bool is_sub_inst, WASMExecEnv *exec_env_main, } #endif -#if WASM_ENABLE_WASI_NN != 0 - if (!is_sub_inst) { - if (!(((AOTModuleInstanceExtra *)module_inst->e)->wasi_nn_ctx = - wasi_nn_initialize())) { - set_error_buf(error_buf, error_buf_size, - "wasi nn initialization failed"); - goto fail; - } - } -#endif - /* Initialize the thread related data */ if (stack_size == 0) stack_size = DEFAULT_WASM_STACK_SIZE; @@ -1212,6 +1253,9 @@ aot_instantiate(AOTModule *module, bool is_sub_inst, WASMExecEnv *exec_env_main, #endif module_inst->default_wasm_stack_size = stack_size; + ((AOTModuleInstanceExtra *)module_inst->e)->stack_sizes = + aot_get_data_section_addr(module, AOT_STACK_SIZES_SECTION_NAME, NULL); + #if WASM_ENABLE_PERF_PROFILING != 0 total_size = (uint64)sizeof(AOTFuncPerfProfInfo) * (module->import_func_count + module->func_count); @@ -1249,6 +1293,8 @@ aot_instantiate(AOTModule *module, bool is_sub_inst, WASMExecEnv *exec_env_main, void aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst) { + WASMModuleInstanceExtraCommon *common = + &((AOTModuleInstanceExtra *)module_inst->e)->common; if (module_inst->exec_env_singleton) { /* wasm_exec_env_destroy will call wasm_cluster_wait_for_all_except_self to wait for other @@ -1258,16 +1304,6 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst) wasm_exec_env_destroy((WASMExecEnv *)module_inst->exec_env_singleton); } -#if WASM_ENABLE_LIBC_WASI != 0 - /* Destroy wasi resource before freeing app heap, since some fields of - wasi contex are allocated from app heap, and if app heap is freed, - these fields will be set to NULL, we cannot free their internal data - which may allocated from global heap. */ - /* Only destroy wasi ctx in the main module instance */ - if (!is_sub_inst) - wasm_runtime_destroy_wasi((WASMModuleInstanceCommon *)module_inst); -#endif - #if WASM_ENABLE_PERF_PROFILING != 0 if (module_inst->func_perf_profilings) wasm_runtime_free(module_inst->func_perf_profilings); @@ -1281,6 +1317,11 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst) } #endif +#if WASM_ENABLE_MULTI_MODULE != 0 + wasm_runtime_sub_module_deinstantiate( + (WASMModuleInstanceCommon *)module_inst); +#endif + if (module_inst->tables) wasm_runtime_free(module_inst->tables); @@ -1296,17 +1337,22 @@ aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst) if (module_inst->func_type_indexes) wasm_runtime_free(module_inst->func_type_indexes); - if (((AOTModuleInstanceExtra *)module_inst->e)->c_api_func_imports) - wasm_runtime_free( - ((AOTModuleInstanceExtra *)module_inst->e)->c_api_func_imports); + if (common->c_api_func_imports) + wasm_runtime_free(((AOTModuleInstanceExtra *)module_inst->e) + ->common.c_api_func_imports); -#if WASM_ENABLE_WASI_NN != 0 if (!is_sub_inst) { - WASINNContext *wasi_nn_ctx = - ((AOTModuleInstanceExtra *)module_inst->e)->wasi_nn_ctx; - if (wasi_nn_ctx) - wasi_nn_destroy(wasi_nn_ctx); +#if WASM_ENABLE_WASI_NN != 0 + wasi_nn_destroy(module_inst); +#endif + wasm_native_call_context_dtors((WASMModuleInstanceCommon *)module_inst); } + +#if WASM_ENABLE_BULK_MEMORY != 0 + bh_bitmap_delete(common->data_dropped); +#endif +#if WASM_ENABLE_REF_TYPES != 0 + bh_bitmap_delete(common->elem_dropped); #endif wasm_runtime_free(module_inst); @@ -1438,10 +1484,43 @@ aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function, unsigned argc, uint32 argv[]) { AOTModuleInstance *module_inst = (AOTModuleInstance *)exec_env->module_inst; - AOTFuncType *func_type = function->u.func.func_type; + AOTFuncType *func_type = function->is_import_func + ? function->u.func_import->func_type + : function->u.func.func_type; uint32 result_count = func_type->result_count; uint32 ext_ret_count = result_count > 1 ? result_count - 1 : 0; bool ret; + void *func_ptr = function->is_import_func + ? function->u.func_import->func_ptr_linked + : function->u.func.func_ptr; +#if WASM_ENABLE_MULTI_MODULE != 0 + bh_list *sub_module_list_node = NULL; + const char *sub_inst_name = NULL; + const char *func_name = function->u.func_import->module_name; + if (function->is_import_func) { + sub_module_list_node = + ((AOTModuleInstanceExtra *)module_inst->e)->sub_module_inst_list; + sub_module_list_node = bh_list_first_elem(sub_module_list_node); + while (sub_module_list_node) { + sub_inst_name = + ((AOTSubModInstNode *)sub_module_list_node)->module_name; + if (strcmp(sub_inst_name, func_name) == 0) { + exec_env = wasm_runtime_get_exec_env_singleton( + (WASMModuleInstanceCommon *)((AOTSubModInstNode *) + sub_module_list_node) + ->module_inst); + module_inst = (AOTModuleInstance *)exec_env->module_inst; + break; + } + sub_module_list_node = bh_list_elem_next(sub_module_list_node); + } + if (exec_env == NULL) { + wasm_runtime_set_exception((WASMModuleInstanceCommon *)module_inst, + "create singleton exec_env failed"); + return false; + } + } +#endif if (argc < func_type->param_cell_num) { char buf[108]; @@ -1453,12 +1532,23 @@ aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function, } argc = func_type->param_cell_num; - /* func pointer was looked up previously */ - bh_assert(function->u.func.func_ptr != NULL); +#if defined(os_writegsbase) + { + AOTMemoryInstance *memory_inst = aot_get_default_memory(module_inst); + if (memory_inst) + /* write base addr of linear memory to GS segment register */ + os_writegsbase(memory_inst->memory_data); + } +#endif + /* func pointer was looked up previously */ + bh_assert(func_ptr != NULL); /* set thread handle and stack boundary */ wasm_exec_env_set_thread_info(exec_env); + /* set exec env so it can be later retrieved from instance */ + ((AOTModuleInstanceExtra *)module_inst->e)->common.cur_exec_env = exec_env; + if (ext_ret_count > 0) { uint32 cell_num = 0, i; uint8 *ext_ret_types = func_type->types + func_type->param_count + 1; @@ -1561,8 +1651,8 @@ aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function, } #endif - ret = invoke_native_internal(exec_env, function->u.func.func_ptr, - func_type, NULL, NULL, argv, argc, argv); + ret = invoke_native_internal(exec_env, func_ptr, func_type, NULL, NULL, + argv, argc, argv); #if WASM_ENABLE_DUMP_CALL_STACK != 0 if (aot_copy_exception(module_inst, NULL)) { @@ -1663,7 +1753,8 @@ execute_malloc_function(AOTModuleInstance *module_inst, WASMExecEnv *exec_env, module inst to ensure that the exec_env's module inst is the correct one. */ module_inst_old = exec_env->module_inst; - exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst; + wasm_exec_env_set_module_inst( + exec_env, (WASMModuleInstanceCommon *)module_inst); } } @@ -1674,7 +1765,7 @@ execute_malloc_function(AOTModuleInstance *module_inst, WASMExecEnv *exec_env, if (module_inst_old) /* Restore the existing exec_env's module inst */ - exec_env->module_inst = module_inst_old; + wasm_exec_env_restore_module_inst(exec_env, module_inst_old); if (exec_env_created) wasm_exec_env_destroy(exec_env_created); @@ -1730,7 +1821,8 @@ execute_free_function(AOTModuleInstance *module_inst, WASMExecEnv *exec_env, module inst to ensure that the exec_env's module inst is the correct one. */ module_inst_old = exec_env->module_inst; - exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst; + wasm_exec_env_set_module_inst( + exec_env, (WASMModuleInstanceCommon *)module_inst); } } @@ -1738,7 +1830,7 @@ execute_free_function(AOTModuleInstance *module_inst, WASMExecEnv *exec_env, if (module_inst_old) /* Restore the existing exec_env's module inst */ - exec_env->module_inst = module_inst_old; + wasm_exec_env_restore_module_inst(exec_env, module_inst_old); if (exec_env_created) wasm_exec_env_destroy(exec_env_created); @@ -1860,6 +1952,13 @@ aot_module_free_internal(AOTModuleInstance *module_inst, WASMExecEnv *exec_env, if (ptr) { uint8 *addr = memory_inst->memory_data + ptr; + uint8 *memory_data_end; + + /* memory->memory_data_end may be changed in memory grow */ + SHARED_MEMORY_LOCK(memory_inst); + memory_data_end = memory_inst->memory_data_end; + SHARED_MEMORY_UNLOCK(memory_inst); + if (memory_inst->heap_handle && memory_inst->heap_data < addr && addr < memory_inst->heap_data_end) { mem_allocator_free(memory_inst->heap_handle, addr); @@ -1867,7 +1966,7 @@ aot_module_free_internal(AOTModuleInstance *module_inst, WASMExecEnv *exec_env, else if (module->malloc_func_index != (uint32)-1 && module->free_func_index != (uint32)-1 && memory_inst->memory_data <= addr - && addr < memory_inst->memory_data_end) { + && addr < memory_data_end) { AOTFunctionInstance *free_func; char *free_func_name; @@ -1941,8 +2040,8 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc, AOTModuleInstanceExtra *module_inst_extra = (AOTModuleInstanceExtra *)module_inst->e; CApiFuncImport *c_api_func_import = - module_inst_extra->c_api_func_imports - ? module_inst_extra->c_api_func_imports + func_idx + module_inst_extra->common.c_api_func_imports + ? module_inst_extra->common.c_api_func_imports + func_idx : NULL; uint32 *func_type_indexes = module_inst->func_type_indexes; uint32 func_type_idx = func_type_indexes[func_idx]; @@ -1954,7 +2053,10 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc, void *attachment; char buf[96]; bool ret = false; - +#if WASM_ENABLE_MULTI_MODULE != 0 + bh_list *sub_module_list_node = NULL; + const char *sub_inst_name = NULL; +#endif bh_assert(func_idx < aot_module->import_func_count); import_func = aot_module->import_funcs + func_idx; @@ -1978,6 +2080,28 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc, } else if (!import_func->call_conv_raw) { signature = import_func->signature; +#if WASM_ENABLE_MULTI_MODULE != 0 + sub_module_list_node = + ((AOTModuleInstanceExtra *)module_inst->e)->sub_module_inst_list; + sub_module_list_node = bh_list_first_elem(sub_module_list_node); + while (sub_module_list_node) { + sub_inst_name = + ((AOTSubModInstNode *)sub_module_list_node)->module_name; + if (strcmp(sub_inst_name, import_func->module_name) == 0) { + exec_env = wasm_runtime_get_exec_env_singleton( + (WASMModuleInstanceCommon *)((AOTSubModInstNode *) + sub_module_list_node) + ->module_inst); + break; + } + sub_module_list_node = bh_list_elem_next(sub_module_list_node); + } + if (exec_env == NULL) { + wasm_runtime_set_exception((WASMModuleInstanceCommon *)module_inst, + "create singleton exec_env failed"); + goto fail; + } +#endif ret = wasm_runtime_invoke_native(exec_env, func_ptr, func_type, signature, attachment, argv, argc, argv); @@ -2216,13 +2340,21 @@ aot_memory_init(AOTModuleInstance *module_inst, uint32 seg_index, uint32 offset, { AOTMemoryInstance *memory_inst = aot_get_default_memory(module_inst); AOTModule *aot_module; - uint8 *data = NULL; + uint8 *data; uint8 *maddr; - uint64 seg_len = 0; + uint64 seg_len; - aot_module = (AOTModule *)module_inst->module; - seg_len = aot_module->mem_init_data_list[seg_index]->byte_count; - data = aot_module->mem_init_data_list[seg_index]->bytes; + if (bh_bitmap_get_bit( + ((AOTModuleInstanceExtra *)module_inst->e)->common.data_dropped, + seg_index)) { + seg_len = 0; + data = NULL; + } + else { + aot_module = (AOTModule *)module_inst->module; + seg_len = aot_module->mem_init_data_list[seg_index]->byte_count; + data = aot_module->mem_init_data_list[seg_index]->bytes; + } if (!wasm_runtime_validate_app_addr((WASMModuleInstanceCommon *)module_inst, dst, len)) @@ -2236,16 +2368,18 @@ aot_memory_init(AOTModuleInstance *module_inst, uint32 seg_index, uint32 offset, maddr = wasm_runtime_addr_app_to_native( (WASMModuleInstanceCommon *)module_inst, dst); + SHARED_MEMORY_LOCK(memory_inst); bh_memcpy_s(maddr, memory_inst->memory_data_size - dst, data + offset, len); + SHARED_MEMORY_UNLOCK(memory_inst); return true; } bool aot_data_drop(AOTModuleInstance *module_inst, uint32 seg_index) { - AOTModule *aot_module = (AOTModule *)module_inst->module; - - aot_module->mem_init_data_list[seg_index]->byte_count = 0; + bh_bitmap_set_bit( + ((AOTModuleInstanceExtra *)module_inst->e)->common.data_dropped, + seg_index); /* Currently we can't free the dropped data segment as the mem_init_data_count is a continuous array */ return true; @@ -2458,9 +2592,9 @@ aot_get_module_inst_mem_consumption(const AOTModuleInstance *module_inst, void aot_drop_table_seg(AOTModuleInstance *module_inst, uint32 tbl_seg_idx) { - AOTModule *module = (AOTModule *)module_inst->module; - AOTTableInitData *tbl_seg = module->table_init_data_list[tbl_seg_idx]; - tbl_seg->is_dropped = true; + bh_bitmap_set_bit( + ((AOTModuleInstanceExtra *)module_inst->e)->common.elem_dropped, + tbl_seg_idx); } void @@ -2478,17 +2612,19 @@ aot_table_init(AOTModuleInstance *module_inst, uint32 tbl_idx, tbl_seg = module->table_init_data_list[tbl_seg_idx]; bh_assert(tbl_seg); - if (!length) { + if (offset_len_out_of_bounds(src_offset, length, tbl_seg->func_index_count) + || offset_len_out_of_bounds(dst_offset, length, tbl_inst->cur_size)) { + aot_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS); return; } - if (length + src_offset > tbl_seg->func_index_count - || dst_offset + length > tbl_inst->cur_size) { - aot_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS); + if (!length) { return; } - if (tbl_seg->is_dropped) { + if (bh_bitmap_get_bit( + ((AOTModuleInstanceExtra *)module_inst->e)->common.elem_dropped, + tbl_seg_idx)) { aot_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS); return; } @@ -2517,8 +2653,9 @@ aot_table_copy(AOTModuleInstance *module_inst, uint32 src_tbl_idx, dst_tbl_inst = module_inst->tables[dst_tbl_idx]; bh_assert(dst_tbl_inst); - if ((uint64)dst_offset + length > dst_tbl_inst->cur_size - || (uint64)src_offset + length > src_tbl_inst->cur_size) { + if (offset_len_out_of_bounds(dst_offset, length, dst_tbl_inst->cur_size) + || offset_len_out_of_bounds(src_offset, length, + src_tbl_inst->cur_size)) { aot_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS); return; } @@ -2543,7 +2680,7 @@ aot_table_fill(AOTModuleInstance *module_inst, uint32 tbl_idx, uint32 length, tbl_inst = module_inst->tables[tbl_idx]; bh_assert(tbl_inst); - if (data_offset + length > tbl_inst->cur_size) { + if (offset_len_out_of_bounds(data_offset, length, tbl_inst->cur_size)) { aot_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS); return; } @@ -2744,6 +2881,7 @@ aot_create_call_stack(struct WASMExecEnv *exec_env) total_len += \ wasm_runtime_dump_line_buf_impl(line_buf, print, &buf, &len); \ if ((!print) && buf && (len == 0)) { \ + exception_unlock(module_inst); \ return total_len; \ } \ } while (0) @@ -2766,6 +2904,7 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len) return 0; } + exception_lock(module_inst); snprintf(line_buf, sizeof(line_buf), "\n"); PRINT_OR_DUMP(); @@ -2774,17 +2913,20 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len) uint32 line_length, i; if (!bh_vector_get(module_inst->frames, n, &frame)) { + exception_unlock(module_inst); return 0; } /* function name not exported, print number instead */ if (frame.func_name_wp == NULL) { - line_length = snprintf(line_buf, sizeof(line_buf), "#%02d $f%d\n", - n, frame.func_index); + line_length = + snprintf(line_buf, sizeof(line_buf), + "#%02" PRIu32 " $f%" PRIu32 "\n", n, frame.func_index); } else { - line_length = snprintf(line_buf, sizeof(line_buf), "#%02d %s\n", n, - frame.func_name_wp); + line_length = + snprintf(line_buf, sizeof(line_buf), "#%02" PRIu32 " %s\n", n, + frame.func_name_wp); } if (line_length >= sizeof(line_buf)) { @@ -2802,6 +2944,7 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len) } snprintf(line_buf, sizeof(line_buf), "\n"); PRINT_OR_DUMP(); + exception_unlock(module_inst); return total_len + 1; } @@ -2822,15 +2965,534 @@ aot_dump_perf_profiling(const AOTModuleInstance *module_inst) func_name = get_func_name_from_index(module_inst, i); if (func_name) - os_printf(" func %s, execution time: %.3f ms, execution count: %d " - "times\n", - func_name, perf_prof->total_exec_time / 1000.0f, - perf_prof->total_exec_cnt); + os_printf( + " func %s, execution time: %.3f ms, execution count: %" PRIu32 + " times\n", + func_name, perf_prof->total_exec_time / 1000.0f, + perf_prof->total_exec_cnt); else - os_printf(" func %d, execution time: %.3f ms, execution count: %d " - "times\n", + os_printf(" func %" PRIu32 + ", execution time: %.3f ms, execution count: %" PRIu32 + " times\n", i, perf_prof->total_exec_time / 1000.0f, perf_prof->total_exec_cnt); } } #endif /* end of WASM_ENABLE_PERF_PROFILING */ + +#if WASM_ENABLE_STATIC_PGO != 0 + +/* indirect call target */ +#define IPVK_IndirectCallTarget 0 +/* memory intrinsic functions size */ +#define IPVK_MemOPSize 1 +#define IPVK_First IPVK_IndirectCallTarget +#define IPVK_Last IPVK_MemOPSize + +#define INSTR_PROF_DEFAULT_NUM_VAL_PER_SITE 24 +#define INSTR_PROF_MAX_NUM_VAL_PER_SITE 255 + +static int hasNonDefaultValsPerSite = 0; +static uint32 VPMaxNumValsPerSite = INSTR_PROF_DEFAULT_NUM_VAL_PER_SITE; + +static bool +cmpxchg_ptr(void **ptr, void *old_val, void *new_val) +{ +#if defined(os_atomic_cmpxchg) + return os_atomic_cmpxchg(ptr, &old_val, new_val); +#else + /* TODO: add lock when thread-manager is enabled */ + void *read = *ptr; + if (read == old_val) { + *ptr = new_val; + return true; + } + return false; +#endif +} + +static int +allocateValueProfileCounters(LLVMProfileData *Data) +{ + ValueProfNode **Mem; + uint64 NumVSites = 0, total_size; + uint32 VKI; + + /* When dynamic allocation is enabled, allow tracking the max number of + values allowed. */ + if (!hasNonDefaultValsPerSite) + VPMaxNumValsPerSite = INSTR_PROF_MAX_NUM_VAL_PER_SITE; + + for (VKI = IPVK_First; VKI <= IPVK_Last; ++VKI) + NumVSites += Data->num_value_sites[VKI]; + + /* If NumVSites = 0, calloc is allowed to return a non-null pointer. */ + bh_assert(NumVSites > 0 && "NumVSites can't be zero"); + + total_size = (uint64)sizeof(ValueProfNode *) * NumVSites; + if (total_size > UINT32_MAX + || !(Mem = (ValueProfNode **)wasm_runtime_malloc((uint32)total_size))) { + return 0; + } + memset(Mem, 0, (uint32)total_size); + + if (!cmpxchg_ptr((void **)&Data->values, NULL, Mem)) { + wasm_runtime_free(Mem); + return 0; + } + return 1; +} + +static ValueProfNode * +allocateOneNode(void) +{ + ValueProfNode *Node; + + Node = wasm_runtime_malloc((uint32)sizeof(ValueProfNode)); + if (Node) + memset(Node, 0, sizeof(ValueProfNode)); + return Node; +} + +static void +instrumentTargetValueImpl(uint64 TargetValue, void *Data, uint32 CounterIndex, + uint64 CountValue) +{ + ValueProfNode **ValueCounters; + ValueProfNode *PrevVNode = NULL, *MinCountVNode = NULL, *CurVNode; + LLVMProfileData *PData = (LLVMProfileData *)Data; + uint64 MinCount = UINT64_MAX; + uint8 VDataCount = 0; + bool success = false; + + if (!PData) + return; + if (!CountValue) + return; + if (!PData->values) { + if (!allocateValueProfileCounters(PData)) + return; + } + + ValueCounters = (ValueProfNode **)PData->values; + CurVNode = ValueCounters[CounterIndex]; + + while (CurVNode) { + if (TargetValue == CurVNode->value) { + CurVNode->count += CountValue; + return; + } + if (CurVNode->count < MinCount) { + MinCount = CurVNode->count; + MinCountVNode = CurVNode; + } + PrevVNode = CurVNode; + CurVNode = CurVNode->next; + ++VDataCount; + } + + if (VDataCount >= VPMaxNumValsPerSite) { + if (MinCountVNode->count <= CountValue) { + CurVNode = MinCountVNode; + CurVNode->value = TargetValue; + CurVNode->count = CountValue; + } + else + MinCountVNode->count -= CountValue; + + return; + } + + CurVNode = allocateOneNode(); + if (!CurVNode) + return; + CurVNode->value = TargetValue; + CurVNode->count += CountValue; + + if (!ValueCounters[CounterIndex]) { + success = + cmpxchg_ptr((void **)&ValueCounters[CounterIndex], NULL, CurVNode); + } + else if (PrevVNode && !PrevVNode->next) { + success = cmpxchg_ptr((void **)&PrevVNode->next, 0, CurVNode); + } + + if (!success) { + wasm_runtime_free(CurVNode); + } +} + +void +llvm_profile_instrument_target(uint64 target_value, void *data, + uint32 counter_idx) +{ + instrumentTargetValueImpl(target_value, data, counter_idx, 1); +} + +static inline uint32 +popcount64(uint64 u) +{ + uint32 ret = 0; + while (u) { + u = (u & (u - 1)); + ret++; + } + return ret; +} + +static inline uint32 +clz64(uint64 type) +{ + uint32 num = 0; + if (type == 0) + return 64; + while (!(type & 0x8000000000000000LL)) { + num++; + type <<= 1; + } + return num; +} + +/* Map an (observed) memop size value to the representative value of its range. + For example, 5 -> 5, 22 -> 17, 99 -> 65, 256 -> 256, 1001 -> 513. */ +static uint64 +InstrProfGetRangeRepValue(uint64 Value) +{ + if (Value <= 8) + /* The first ranges are individually tracked. Use the value as is. */ + return Value; + else if (Value >= 513) + /* The last range is mapped to its lowest value. */ + return 513; + else if (popcount64(Value) == 1) + /* If it's a power of two, use it as is. */ + return Value; + else + /* Otherwise, take to the previous power of two + 1. */ + return (((uint64)1) << (64 - clz64(Value) - 1)) + 1; +} + +void +llvm_profile_instrument_memop(uint64 target_value, void *data, + uint32 counter_idx) +{ + uint64 rep_value = InstrProfGetRangeRepValue(target_value); + instrumentTargetValueImpl(rep_value, data, counter_idx, 1); +} + +static uint32 +get_pgo_prof_data_size(AOTModuleInstance *module_inst, uint32 *p_num_prof_data, + uint32 *p_num_prof_counters, uint32 *p_padding_size, + uint32 *p_prof_counters_size, uint32 *p_prof_names_size, + uint32 *p_value_counters_size, uint8 **p_prof_names) +{ + AOTModule *module = (AOTModule *)module_inst->module; + LLVMProfileData *prof_data; + uint8 *prof_names = NULL; + uint32 num_prof_data = 0, num_prof_counters = 0, padding_size, i; + uint32 prof_counters_size = 0, prof_names_size = 0; + uint32 total_size, total_size_wo_value_counters; + + for (i = 0; i < module->data_section_count; i++) { + if (!strncmp(module->data_sections[i].name, "__llvm_prf_data", 15)) { + bh_assert(module->data_sections[i].size == sizeof(LLVMProfileData)); + num_prof_data++; + prof_data = (LLVMProfileData *)module->data_sections[i].data; + num_prof_counters += prof_data->num_counters; + } + else if (!strncmp(module->data_sections[i].name, "__llvm_prf_cnts", + 15)) { + prof_counters_size += module->data_sections[i].size; + } + else if (!strncmp(module->data_sections[i].name, "__llvm_prf_names", + 16)) { + prof_names_size = module->data_sections[i].size; + prof_names = module->data_sections[i].data; + } + } + + if (prof_counters_size != num_prof_counters * sizeof(uint64)) + return 0; + + total_size = sizeof(LLVMProfileRawHeader) + + num_prof_data * sizeof(LLVMProfileData_64) + + prof_counters_size + prof_names_size; + padding_size = sizeof(uint64) - (prof_names_size % sizeof(uint64)); + if (padding_size != sizeof(uint64)) + total_size += padding_size; + + /* Total size excluding value counters */ + total_size_wo_value_counters = total_size; + + for (i = 0; i < module->data_section_count; i++) { + if (!strncmp(module->data_sections[i].name, "__llvm_prf_data", 15)) { + uint32 j, k, num_value_sites, num_value_nodes; + ValueProfNode **values, *value_node; + + prof_data = (LLVMProfileData *)module->data_sections[i].data; + values = prof_data->values; + + if (prof_data->num_value_sites[0] > 0 + || prof_data->num_value_sites[1] > 0) { + /* TotalSize (uint32) and NumValueKinds (uint32) */ + total_size += 8; + for (j = 0; j < 2; j++) { + if ((num_value_sites = prof_data->num_value_sites[j]) > 0) { + /* ValueKind (uint32) and NumValueSites (uint32) */ + total_size += 8; + /* (Value + Counter) group counts of each value site, + each count is one byte */ + total_size += align_uint(num_value_sites, 8); + + if (values) { + for (k = 0; k < num_value_sites; k++) { + num_value_nodes = 0; + value_node = *values; + while (value_node) { + num_value_nodes++; + value_node = value_node->next; + } + if (num_value_nodes) { + /* (Value + Counter) groups */ + total_size += num_value_nodes * 8 * 2; + } + values++; + } + } + } + } + } + } + } + + if (p_num_prof_data) + *p_num_prof_data = num_prof_data; + if (p_num_prof_counters) + *p_num_prof_counters = num_prof_counters; + if (p_padding_size) + *p_padding_size = padding_size; + if (p_prof_counters_size) + *p_prof_counters_size = prof_counters_size; + if (p_prof_names_size) + *p_prof_names_size = prof_names_size; + if (p_value_counters_size) + *p_value_counters_size = total_size - total_size_wo_value_counters; + if (p_prof_names) + *p_prof_names = prof_names; + + return total_size; +} + +uint32 +aot_get_pgo_prof_data_size(AOTModuleInstance *module_inst) +{ + return get_pgo_prof_data_size(module_inst, NULL, NULL, NULL, NULL, NULL, + NULL, NULL); +} + +static union { + int a; + char b; +} __ue = { .a = 1 }; + +#define is_little_endian() (__ue.b == 1) + +uint32 +aot_dump_pgo_prof_data_to_buf(AOTModuleInstance *module_inst, char *buf, + uint32 len) +{ + AOTModule *module = (AOTModule *)module_inst->module; + LLVMProfileRawHeader prof_header = { 0 }; + LLVMProfileData *prof_data; + uint8 *prof_names = NULL; + uint32 num_prof_data = 0, num_prof_counters = 0, padding_size, i; + uint32 prof_counters_size = 0, prof_names_size = 0; + uint32 value_counters_size = 0, value_counters_size_backup = 0; + uint32 total_size, size; + int64 counters_delta, offset_counters; + + total_size = get_pgo_prof_data_size(module_inst, &num_prof_data, + &num_prof_counters, &padding_size, + &prof_counters_size, &prof_names_size, + &value_counters_size, &prof_names); + if (len < total_size) + return 0; + + value_counters_size_backup = value_counters_size; + value_counters_size = 0; + + prof_header.counters_delta = counters_delta = + sizeof(LLVMProfileData_64) * num_prof_data; + offset_counters = 0; + for (i = 0; i < module->data_section_count; i++) { + if (!strncmp(module->data_sections[i].name, "__llvm_prf_data", 15)) { + prof_data = (LLVMProfileData *)module->data_sections[i].data; + prof_data->offset_counters = counters_delta + offset_counters; + offset_counters += prof_data->num_counters * sizeof(uint64); + counters_delta -= sizeof(LLVMProfileData_64); + } + } + + prof_header.magic = 0xFF6C70726F667281LL; + /* Version 8 */ + prof_header.version = 0x0000000000000008LL; + /* with VARIANT_MASK_IR_PROF (IR Instrumentation) */ + prof_header.version |= 0x1ULL << 56; + /* with VARIANT_MASK_MEMPROF (Memory Profile) */ + prof_header.version |= 0x1ULL << 62; + prof_header.num_prof_data = num_prof_data; + prof_header.num_prof_counters = num_prof_counters; + prof_header.names_size = prof_names_size; + prof_header.value_kind_last = 1; + + if (!is_little_endian()) { + aot_exchange_uint64((uint8 *)&prof_header.magic); + aot_exchange_uint64((uint8 *)&prof_header.version); + aot_exchange_uint64((uint8 *)&prof_header.num_prof_data); + aot_exchange_uint64((uint8 *)&prof_header.num_prof_counters); + aot_exchange_uint64((uint8 *)&prof_header.names_size); + aot_exchange_uint64((uint8 *)&prof_header.counters_delta); + aot_exchange_uint64((uint8 *)&prof_header.value_kind_last); + } + + size = sizeof(LLVMProfileRawHeader); + bh_memcpy_s(buf, size, &prof_header, size); + buf += size; + + for (i = 0; i < module->data_section_count; i++) { + if (!strncmp(module->data_sections[i].name, "__llvm_prf_data", 15)) { + LLVMProfileData_64 *prof_data_64 = (LLVMProfileData_64 *)buf; + + /* Convert LLVMProfileData to LLVMProfileData_64, the pointer width + in the output file is alawys 8 bytes */ + prof_data = (LLVMProfileData *)module->data_sections[i].data; + prof_data_64->func_md5 = prof_data->func_md5; + prof_data_64->func_hash = prof_data->func_hash; + prof_data_64->offset_counters = prof_data->offset_counters; + prof_data_64->func_ptr = prof_data->func_ptr; + prof_data_64->values = (uint64)(uintptr_t)prof_data->values; + prof_data_64->num_counters = prof_data->num_counters; + prof_data_64->num_value_sites[0] = prof_data->num_value_sites[0]; + prof_data_64->num_value_sites[1] = prof_data->num_value_sites[1]; + + if (!is_little_endian()) { + aot_exchange_uint64((uint8 *)&prof_data_64->func_hash); + aot_exchange_uint64((uint8 *)&prof_data_64->offset_counters); + aot_exchange_uint64((uint8 *)&prof_data_64->offset_counters); + aot_exchange_uint64((uint8 *)&prof_data_64->func_ptr); + aot_exchange_uint64((uint8 *)&prof_data_64->values); + aot_exchange_uint32((uint8 *)&prof_data_64->num_counters); + aot_exchange_uint16((uint8 *)&prof_data_64->num_value_sites[0]); + aot_exchange_uint16((uint8 *)&prof_data_64->num_value_sites[1]); + } + buf += sizeof(LLVMProfileData_64); + } + } + + for (i = 0; i < module->data_section_count; i++) { + if (!strncmp(module->data_sections[i].name, "__llvm_prf_cnts", 15)) { + size = module->data_sections[i].size; + bh_memcpy_s(buf, size, module->data_sections[i].data, size); + buf += size; + } + } + + if (prof_names && prof_names_size > 0) { + size = prof_names_size; + bh_memcpy_s(buf, size, prof_names, size); + buf += size; + padding_size = sizeof(uint64) - (prof_names_size % sizeof(uint64)); + if (padding_size != sizeof(uint64)) { + char padding_buf[8] = { 0 }; + bh_memcpy_s(buf, padding_size, padding_buf, padding_size); + buf += padding_size; + } + } + + for (i = 0; i < module->data_section_count; i++) { + if (!strncmp(module->data_sections[i].name, "__llvm_prf_data", 15)) { + uint32 j, k, num_value_sites, num_value_nodes; + ValueProfNode **values, **values_tmp, *value_node; + + prof_data = (LLVMProfileData *)module->data_sections[i].data; + values = values_tmp = prof_data->values; + + if (prof_data->num_value_sites[0] > 0 + || prof_data->num_value_sites[1] > 0) { + uint32 *buf_total_size = (uint32 *)buf; + + buf += 4; /* emit TotalSize later */ + *(uint32 *)buf = (prof_data->num_value_sites[0] > 0 + && prof_data->num_value_sites[1] > 0) + ? 2 + : 1; + if (!is_little_endian()) + aot_exchange_uint32((uint8 *)buf); + buf += 4; + + for (j = 0; j < 2; j++) { + if ((num_value_sites = prof_data->num_value_sites[j]) > 0) { + /* ValueKind */ + *(uint32 *)buf = j; + if (!is_little_endian()) + aot_exchange_uint32((uint8 *)buf); + buf += 4; + /* NumValueSites */ + *(uint32 *)buf = num_value_sites; + if (!is_little_endian()) + aot_exchange_uint32((uint8 *)buf); + buf += 4; + + for (k = 0; k < num_value_sites; k++) { + num_value_nodes = 0; + if (values_tmp) { + value_node = *values_tmp; + while (value_node) { + num_value_nodes++; + value_node = value_node->next; + } + values_tmp++; + } + bh_assert(num_value_nodes < 255); + *(uint8 *)buf++ = (uint8)num_value_nodes; + } + if (num_value_sites % 8) { + buf += 8 - (num_value_sites % 8); + } + + for (k = 0; k < num_value_sites; k++) { + if (values) { + value_node = *values; + while (value_node) { + *(uint64 *)buf = value_node->value; + if (!is_little_endian()) + aot_exchange_uint64((uint8 *)buf); + buf += 8; + *(uint64 *)buf = value_node->count; + if (!is_little_endian()) + aot_exchange_uint64((uint8 *)buf); + buf += 8; + value_node = value_node->next; + } + values++; + } + } + } + } + + /* TotalSize */ + *(uint32 *)buf_total_size = + (uint8 *)buf - (uint8 *)buf_total_size; + if (!is_little_endian()) + aot_exchange_uint64((uint8 *)buf_total_size); + value_counters_size += (uint8 *)buf - (uint8 *)buf_total_size; + } + } + } + + bh_assert(value_counters_size == value_counters_size_backup); + (void)value_counters_size_backup; + + return total_size; +} +#endif /* end of WASM_ENABLE_STATIC_PGO != 0 */ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_runtime.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_runtime.h similarity index 80% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_runtime.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_runtime.h index bcd06534e6e..35c78bfa082 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/aot_runtime.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/aot_runtime.h @@ -41,6 +41,10 @@ typedef struct AOTObjectDataSection { char *name; uint8 *data; uint32 size; +#if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0 + bool is_name_allocated; + bool is_data_allocated; +#endif } AOTObjectDataSection; /* Relocation info */ @@ -51,6 +55,9 @@ typedef struct AOTRelocation { char *symbol_name; /* index in the symbol offset field */ uint32 symbol_index; +#if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0 + bool is_symbol_name_allocated; +#endif } AOTRelocation; /* Relocation Group */ @@ -60,6 +67,9 @@ typedef struct AOTRelocationGroup { uint32 name_index; uint32 relocation_count; AOTRelocation *relocations; +#if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0 + bool is_section_name_allocated; +#endif } AOTRelocationGroup; /* AOT function instance */ @@ -78,34 +88,19 @@ typedef struct AOTFunctionInstance { } AOTFunctionInstance; typedef struct AOTModuleInstanceExtra { - CApiFuncImport *c_api_func_imports; -#if WASM_ENABLE_WASI_NN != 0 - WASINNContext *wasi_nn_ctx; + DefPointer(const uint32 *, stack_sizes); + WASMModuleInstanceExtraCommon common; +#if WASM_ENABLE_MULTI_MODULE != 0 + bh_list sub_module_inst_list_head; + bh_list *sub_module_inst_list; #endif } AOTModuleInstanceExtra; -#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS) -/* clang-format off */ -typedef struct AOTUnwindInfo { - uint8 Version : 3; - uint8 Flags : 5; - uint8 SizeOfProlog; - uint8 CountOfCodes; - uint8 FrameRegister : 4; - uint8 FrameOffset : 4; - struct { - struct { - uint8 CodeOffset; - uint8 UnwindOp : 4; - uint8 OpInfo : 4; - }; - uint16 FrameOffset; - } UnwindCode[1]; -} AOTUnwindInfo; -/* clang-format on */ - -/* size of mov instruction and jmp instruction */ -#define PLT_ITEM_SIZE 12 +#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) +typedef struct GOTItem { + uint32 func_idx; + struct GOTItem *next; +} GOTItem, *GOTItemList; #endif typedef struct AOTModule { @@ -196,12 +191,11 @@ typedef struct AOTModule { uint32 float_plt_count; #endif -#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS) - /* dynamic function table to be added by RtlAddFunctionTable(), - used to unwind the call stack and register exception handler - for AOT functions */ - RUNTIME_FUNCTION *rtl_func_table; - bool rtl_func_table_registered; +#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) + uint32 got_item_count; + GOTItemList got_item_list; + GOTItemList got_item_list_end; + void **got_func_ptrs; #endif /* data sections in AOT object file, including .data, .rodata @@ -239,6 +233,12 @@ typedef struct AOTModule { WASIArguments wasi_args; bool import_wasi_api; #endif + +#if WASM_ENABLE_MULTI_MODULE != 0 + /* TODO: add mutex for mutli-thread? */ + bh_list import_module_list_head; + bh_list *import_module_list; +#endif #if WASM_ENABLE_DEBUG_AOT != 0 void *elf_hdr; uint32 elf_size; @@ -257,6 +257,10 @@ typedef struct AOTModule { #define AOTTableInstance WASMTableInstance #define AOTModuleInstance WASMModuleInstance +#if WASM_ENABLE_MULTI_MODULE != 0 +#define AOTSubModInstNode WASMSubModInstNode +#endif + /* Target info, read from ELF header of object file */ typedef struct AOTTargetInfo { /* Binary type, elf32l/elf32b/elf64l/elf64b */ @@ -294,6 +298,54 @@ typedef struct AOTFrame { #endif } AOTFrame; +#if WASM_ENABLE_STATIC_PGO != 0 +typedef struct LLVMProfileRawHeader { + uint64 magic; + uint64 version; + uint64 binary_ids_size; + uint64 num_prof_data; + uint64 padding_bytes_before_counters; + uint64 num_prof_counters; + uint64 padding_bytes_after_counters; + uint64 names_size; + uint64 counters_delta; + uint64 names_delta; + uint64 value_kind_last; +} LLVMProfileRawHeader; + +typedef struct ValueProfNode { + uint64 value; + uint64 count; + struct ValueProfNode *next; +} ValueProfNode; + +/* The profiling data of data sections created by aot compiler and + used when profiling, the width of pointer can be 8 bytes (64-bit) + or 4 bytes (32-bit) */ +typedef struct LLVMProfileData { + uint64 func_md5; + uint64 func_hash; + uint64 offset_counters; + uintptr_t func_ptr; + ValueProfNode **values; + uint32 num_counters; + uint16 num_value_sites[2]; +} LLVMProfileData; + +/* The profiling data for writting to the output file, the width of + pointer is 8 bytes suppose we always use wamrc and llvm-profdata + with 64-bit mode */ +typedef struct LLVMProfileData_64 { + uint64 func_md5; + uint64 func_hash; + uint64 offset_counters; + uint64 func_ptr; + uint64 values; + uint32 num_counters; + uint16 num_value_sites[2]; +} LLVMProfileData_64; +#endif /* end of WASM_ENABLE_STATIC_PGO != 0 */ + /** * Load a AOT module from aot file buffer * @param buf the byte buffer which contains the AOT file data @@ -332,7 +384,7 @@ aot_unload(AOTModule *module); * Instantiate a AOT module. * * @param module the AOT module to instantiate - * @param is_sub_inst the flag of sub instance + * @param parent the parent module instance * @param heap_size the default heap size of the module instance, a heap will * be created besides the app memory space. Both wasm app and native * function can allocate memory from the heap. If heap_size is 0, the @@ -343,9 +395,9 @@ aot_unload(AOTModule *module); * @return return the instantiated AOT module instance, NULL if failed */ AOTModuleInstance * -aot_instantiate(AOTModule *module, bool is_sub_inst, WASMExecEnv *exec_env_main, - uint32 stack_size, uint32 heap_size, char *error_buf, - uint32 error_buf_size); +aot_instantiate(AOTModule *module, AOTModuleInstance *parent, + WASMExecEnv *exec_env_main, uint32 stack_size, uint32 heap_size, + char *error_buf, uint32 error_buf_size); /** * Deinstantiate a AOT module instance, destroy the resources. @@ -564,6 +616,36 @@ aot_dump_perf_profiling(const AOTModuleInstance *module_inst); const uint8 * aot_get_custom_section(const AOTModule *module, const char *name, uint32 *len); +const void * +aot_get_data_section_addr(AOTModule *module, const char *section_name, + uint32 *p_data_size); + +#if WASM_ENABLE_STATIC_PGO != 0 +void +llvm_profile_instrument_target(uint64 target_value, void *data, + uint32 counter_idx); + +void +llvm_profile_instrument_memop(uint64 target_value, void *data, + uint32 counter_idx); + +uint32 +aot_get_pgo_prof_data_size(AOTModuleInstance *module_inst); + +uint32 +aot_dump_pgo_prof_data_to_buf(AOTModuleInstance *module_inst, char *buf, + uint32 len); + +void +aot_exchange_uint16(uint8 *p_data); + +void +aot_exchange_uint32(uint8 *p_data); + +void +aot_exchange_uint64(uint8 *p_data); +#endif /* end of WASM_ENABLE_STATIC_PGO != 0 */ + #ifdef __cplusplus } /* end of extern "C" */ #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_aarch64.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_aarch64.c similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_aarch64.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_aarch64.c index 4c46eaa003c..b4bb6024a47 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_aarch64.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_aarch64.c @@ -53,7 +53,12 @@ get_target_symbol_map(uint32 *sym_num) return target_sym_map; } +#if (defined(__APPLE__) || defined(__MACH__)) && defined(__arm64__) +#define BUILD_TARGET_AARCH64_DEFAULT "arm64" +#else #define BUILD_TARGET_AARCH64_DEFAULT "aarch64v8" +#endif + void get_current_target(char *target_buf, uint32 target_buf_size) { diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_arc.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_arc.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_arc.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_arc.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_arm.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_arm.c similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_arm.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_arm.c index fbf9be13c86..5d79e8a68ac 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_arm.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_arm.c @@ -40,6 +40,7 @@ void __aeabi_ldivmod(); void __aeabi_memcpy(); void __aeabi_memmove(); void __aeabi_memset(); +void __aeabi_memclr(); void __aeabi_uidiv(); void __aeabi_uidivmod(); void __aeabi_ul2d(); @@ -126,6 +127,7 @@ static SymbolMap target_sym_map[] = { REG_SYM(__aeabi_memcpy), REG_SYM(__aeabi_memmove), REG_SYM(__aeabi_memset), + REG_SYM(__aeabi_memclr), REG_SYM(__aeabi_uidiv), REG_SYM(__aeabi_uidivmod), REG_SYM(__aeabi_ul2d), diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_mips.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_mips.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_mips.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_mips.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_riscv.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_riscv.c similarity index 80% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_riscv.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_riscv.c index 75fee56fda1..045cab6412c 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_riscv.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_riscv.c @@ -9,6 +9,9 @@ #define R_RISCV_64 2 #define R_RISCV_CALL 18 #define R_RISCV_CALL_PLT 19 +#define R_RISCV_PCREL_HI20 23 +#define R_RISCV_PCREL_LO12_I 24 +#define R_RISCV_PCREL_LO12_S 25 #define R_RISCV_HI20 26 #define R_RISCV_LO12_I 27 #define R_RISCV_LO12_S 28 @@ -76,6 +79,13 @@ static SymbolMap target_sym_map[] = { REG_SYM(__addsf3), REG_SYM(__divdf3), REG_SYM(__divsf3), + REG_SYM(__eqdf2), + REG_SYM(__eqsf2), + REG_SYM(__extendsfdf2), + REG_SYM(__fixunsdfdi), + REG_SYM(__fixunsdfsi), + REG_SYM(__fixunssfdi), + REG_SYM(__fixunssfsi), REG_SYM(__gedf2), REG_SYM(__gesf2), REG_SYM(__gtdf2), @@ -87,44 +97,33 @@ static SymbolMap target_sym_map[] = { REG_SYM(__muldf3), REG_SYM(__nedf2), REG_SYM(__nesf2), - REG_SYM(__eqsf2), - REG_SYM(__eqdf2), - REG_SYM(__extendsfdf2), - REG_SYM(__fixunsdfdi), - REG_SYM(__fixunsdfsi), - REG_SYM(__fixunssfsi), REG_SYM(__subdf3), REG_SYM(__subsf3), REG_SYM(__truncdfsf2), REG_SYM(__unorddf2), REG_SYM(__unordsf2), -#endif - REG_SYM(__divdi3), - REG_SYM(__divsi3), -#if __riscv_xlen == 32 + REG_SYM(__mulsf3), + REG_SYM(__floatundidf), REG_SYM(__fixdfdi), + REG_SYM(__floatsidf), + REG_SYM(__floatunsidf), +#if __riscv_xlen == 32 REG_SYM(__fixdfsi), REG_SYM(__fixsfdi), REG_SYM(__fixsfsi), -#endif - REG_SYM(__fixunssfdi), -#if __riscv_xlen == 32 REG_SYM(__floatdidf), REG_SYM(__floatdisf), REG_SYM(__floatsisf), - REG_SYM(__floatsidf), - REG_SYM(__floatundidf), REG_SYM(__floatundisf), REG_SYM(__floatunsisf), - REG_SYM(__floatunsidf), + REG_SYM(__mulsi3), #endif +#endif + REG_SYM(__divdi3), + REG_SYM(__divsi3), REG_SYM(__moddi3), REG_SYM(__modsi3), REG_SYM(__muldi3), -#if __riscv_xlen == 32 - REG_SYM(__mulsf3), - REG_SYM(__mulsi3), -#endif REG_SYM(__udivdi3), REG_SYM(__udivsi3), REG_SYM(__umoddi3), @@ -179,7 +178,11 @@ rv_set_val(uint16 *addr, uint32 val) *addr = (val & 0xffff); *(addr + 1) = (val >> 16); +#ifdef __riscv_zifencei __asm__ volatile("fence.i"); +#else + __asm__ volatile("fence"); +#endif } /* Add a val to given address */ @@ -267,9 +270,11 @@ typedef struct RelocTypeStrMap { } static RelocTypeStrMap reloc_type_str_maps[] = { - RELOC_TYPE_MAP(R_RISCV_32), RELOC_TYPE_MAP(R_RISCV_CALL), - RELOC_TYPE_MAP(R_RISCV_CALL_PLT), RELOC_TYPE_MAP(R_RISCV_HI20), - RELOC_TYPE_MAP(R_RISCV_LO12_I), RELOC_TYPE_MAP(R_RISCV_LO12_S), + RELOC_TYPE_MAP(R_RISCV_32), RELOC_TYPE_MAP(R_RISCV_64), + RELOC_TYPE_MAP(R_RISCV_CALL), RELOC_TYPE_MAP(R_RISCV_CALL_PLT), + RELOC_TYPE_MAP(R_RISCV_PCREL_HI20), RELOC_TYPE_MAP(R_RISCV_PCREL_LO12_I), + RELOC_TYPE_MAP(R_RISCV_PCREL_LO12_S), RELOC_TYPE_MAP(R_RISCV_HI20), + RELOC_TYPE_MAP(R_RISCV_LO12_I), RELOC_TYPE_MAP(R_RISCV_LO12_S), }; static const char * @@ -324,21 +329,37 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, rv_set_val((uint16 *)addr, val_32); break; } + +#if __riscv_xlen == 64 case R_RISCV_64: { uint64 val_64 = - (uint64)((uintptr_t)symbol_addr + (intptr_t)reloc_addend); + (uint64)((intptr_t)symbol_addr + (intptr_t)reloc_addend); + CHECK_RELOC_OFFSET(sizeof(uint64)); + if (val_64 + != (uint64)((intptr_t)symbol_addr + (intptr_t)reloc_addend)) { + goto fail_addr_out_of_range; + } + bh_memcpy_s(addr, 8, &val_64, 8); +#ifdef __riscv_zifencei + __asm__ volatile("fence.i"); +#else + __asm__ volatile("fence"); +#endif break; } +#endif + case R_RISCV_CALL: case R_RISCV_CALL_PLT: + case R_RISCV_PCREL_HI20: /* S + A - P */ { - val = (int32)(intptr_t)((uint8 *)symbol_addr - addr); + val = (int32)(intptr_t)((uint8 *)symbol_addr + reloc_addend - addr); CHECK_RELOC_OFFSET(sizeof(uint32)); - if (val != (intptr_t)((uint8 *)symbol_addr - addr)) { + if (val != (intptr_t)((uint8 *)symbol_addr + reloc_addend - addr)) { if (symbol_index >= 0) { /* Call runtime function by plt code */ symbol_addr = (uint8 *)module->code + module->code_size @@ -348,7 +369,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, } } - if (val != (intptr_t)((uint8 *)symbol_addr - addr)) { + if (val != (intptr_t)((uint8 *)symbol_addr + reloc_addend - addr)) { goto fail_addr_out_of_range; } @@ -369,7 +390,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, break; } - case R_RISCV_HI20: + case R_RISCV_HI20: /* S + A */ { val = (int32)((intptr_t)symbol_addr + (intptr_t)reloc_addend); @@ -378,7 +399,6 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, goto fail_addr_out_of_range; } - addr = target_section_addr + reloc_offset; insn = rv_get_val((uint16 *)addr); rv_calc_imm(val, &imm_hi, &imm_lo); insn = (insn & 0x00000fff) | (imm_hi << 12); @@ -386,11 +406,42 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, break; } - case R_RISCV_LO12_I: + case R_RISCV_PCREL_LO12_I: /* S - P */ + case R_RISCV_PCREL_LO12_S: /* S - P */ + { + /* Already handled in R_RISCV_PCREL_HI20, it should be skipped for + * most cases. But it is still needed for some special cases, e.g. + * ``` + * label: + * auipc t0, %pcrel_hi(symbol) # R_RISCV_PCREL_HI20 (symbol) + * lui t1, 1 + * lw t2, t0, %pcrel_lo(label) # R_RISCV_PCREL_LO12_I (label) + * add t2, t2, t1 + * sw t2, t0, %pcrel_lo(label) # R_RISCV_PCREL_LO12_S (label) + * ``` + * In this case, the R_RISCV_PCREL_LO12_I/S relocation should be + * handled after R_RISCV_PCREL_HI20 relocation. + * + * So, if the R_RISCV_PCREL_LO12_I/S relocation is not followed by + * R_RISCV_PCREL_HI20 relocation, it should be handled here but + * not implemented yet. + */ + + if ((uintptr_t)addr - (uintptr_t)symbol_addr + - (uintptr_t)reloc_addend + != 4) { + goto fail_addr_out_of_range; + } + break; + } + + case R_RISCV_LO12_I: /* S + A */ { + val = (int32)((intptr_t)symbol_addr + (intptr_t)reloc_addend); CHECK_RELOC_OFFSET(sizeof(uint32)); + if (val != (intptr_t)symbol_addr + (intptr_t)reloc_addend) { goto fail_addr_out_of_range; } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_thumb.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_thumb.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_thumb.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_thumb.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_x86_32.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_x86_32.c similarity index 82% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_x86_32.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_x86_32.c index af3e0bb8ef0..0a423c398c3 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_x86_32.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_x86_32.c @@ -5,9 +5,19 @@ #include "aot_reloc.h" +/* clang-format off */ +#if !defined(BH_PLATFORM_WINDOWS) #define R_386_32 1 /* Direct 32 bit */ #define R_386_PC32 2 /* PC relative 32 bit */ #define R_386_PLT32 4 /* 32-bit address ProcedureLinkageTable */ +#define R_386_TLS_GD_32 24 /* Direct 32 bit for general dynamic + thread local data */ +#else +#define IMAGE_REL_I386_DIR32 6 /* The target's 32-bit VA */ +#define IMAGE_REL_I386_REL32 20 /* The 32-bit relative displacement + to the target */ +#endif +/* clang-format on */ #if !defined(_WIN32) && !defined(_WIN32_) /* clang-format off */ @@ -45,6 +55,12 @@ __umoddi3(uint64 a, uint64 b) } #endif +static uint64 +__aulldiv(uint64 a, uint64 b) +{ + return a / b; +} + /* clang-format off */ static SymbolMap target_sym_map[] = { REG_COMMON_SYMBOLS @@ -52,7 +68,8 @@ static SymbolMap target_sym_map[] = { REG_SYM(__divdi3), REG_SYM(__udivdi3), REG_SYM(__moddi3), - REG_SYM(__umoddi3) + REG_SYM(__umoddi3), + REG_SYM(__aulldiv) }; /* clang-format on */ @@ -109,7 +126,14 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, int32 symbol_index, char *error_buf, uint32 error_buf_size) { switch (reloc_type) { +#if !defined(BH_PLATFORM_WINDOWS) case R_386_32: +#if WASM_ENABLE_STATIC_PGO != 0 + case R_386_TLS_GD_32: +#endif +#else + case IMAGE_REL_I386_DIR32: +#endif { intptr_t value; @@ -121,12 +145,16 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, break; } +#if !defined(BH_PLATFORM_WINDOWS) /* * Handle R_386_PLT32 like R_386_PC32 since it should be able to reach * any 32 bit address */ case R_386_PLT32: case R_386_PC32: +#else + case IMAGE_REL_I386_REL32: +#endif { int32 value; @@ -136,6 +164,9 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, (uint32)((uintptr_t)symbol_addr + (intptr_t)reloc_addend - (uintptr_t)(target_section_addr + (uint32)reloc_offset) +#if defined(BH_PLATFORM_WINDOWS) + - sizeof(int32) +#endif + value); /* S + A - P */ break; } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_x86_64.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_x86_64.c similarity index 89% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_x86_64.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_x86_64.c index f4d8eeabd29..b5be2459322 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_x86_64.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_x86_64.c @@ -6,11 +6,13 @@ #include "aot_reloc.h" #if !defined(BH_PLATFORM_WINDOWS) -#define R_X86_64_64 1 /* Direct 64 bit */ -#define R_X86_64_PC32 2 /* PC relative 32 bit signed */ -#define R_X86_64_PLT32 4 /* 32 bit PLT address */ -#define R_X86_64_32 10 /* Direct 32 bit zero extended */ -#define R_X86_64_32S 11 /* Direct 32 bit sign extended */ +#define R_X86_64_64 1 /* Direct 64 bit */ +#define R_X86_64_PC32 2 /* PC relative 32 bit signed */ +#define R_X86_64_PLT32 4 /* 32 bit PLT address */ +#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative offset to GOT */ +#define R_X86_64_32 10 /* Direct 32 bit zero extended */ +#define R_X86_64_32S 11 /* Direct 32 bit sign extended */ +#define R_X86_64_PC64 24 /* PC relative 64 bit */ #else #ifndef IMAGE_REL_AMD64_ADDR64 #define IMAGE_REL_AMD64_ADDR64 1 /* The 64-bit VA of the relocation target */ @@ -67,9 +69,6 @@ get_plt_table_size() { uint32 size = get_plt_item_size() * (sizeof(target_sym_map) / sizeof(SymbolMap)); -#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS) - size += get_plt_item_size() + sizeof(AOTUnwindInfo); -#endif return size; } @@ -91,18 +90,6 @@ init_plt_table(uint8 *plt) *p++ = 0xE0; plt += get_plt_item_size(); } - -#if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS) - p = plt; - /* mov exception_handler, rax */ - *p++ = 0x48; - *p++ = 0xB8; - *(uint64 *)p = 0; /*(uint64)(uintptr_t)aot_exception_handler;*/ - p += sizeof(uint64); - /* jmp rax */ - *p++ = 0xFF; - *p++ = 0xE0; -#endif } static bool @@ -164,6 +151,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, #endif #if !defined(BH_PLATFORM_WINDOWS) case R_X86_64_PC32: + case R_X86_64_GOTPCREL: /* GOT + G has been calculated as symbol_addr */ { intptr_t target_addr = (intptr_t) /* S + A - P */ ((uintptr_t)symbol_addr + reloc_addend @@ -182,6 +170,16 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, *(int32 *)(target_section_addr + reloc_offset) = (int32)target_addr; break; } + case R_X86_64_PC64: + { + intptr_t target_addr = (intptr_t) /* S + A - P */ + ((uintptr_t)symbol_addr + reloc_addend + - (uintptr_t)(target_section_addr + reloc_offset)); + + CHECK_RELOC_OFFSET(sizeof(int64)); + *(int64 *)(target_section_addr + reloc_offset) = (int64)target_addr; + break; + } case R_X86_64_32: case R_X86_64_32S: { @@ -229,7 +227,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, - (uintptr_t)(target_section_addr + reloc_offset)); } else { - target_addr = (intptr_t) /* L + A - P */ + target_addr = (intptr_t) /* S + A - P */ ((uintptr_t)symbol_addr + reloc_addend - (uintptr_t)(target_section_addr + reloc_offset)); } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_xtensa.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_xtensa.c similarity index 93% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_xtensa.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_xtensa.c index 3327c396fb5..a29c9f2b9e8 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/arch/aot_reloc_xtensa.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/arch/aot_reloc_xtensa.c @@ -43,6 +43,11 @@ void __floatdidf(); void __divsf3(); void __fixdfdi(); void __floatundidf(); +void __fixsfdi(); +void __fixunssfdi(); +void __fixunsdfdi(); +void __floatdisf(); +void __floatundisf(); static SymbolMap target_sym_map[] = { @@ -85,6 +90,11 @@ static SymbolMap target_sym_map[] = { REG_SYM(__divsf3), REG_SYM(__fixdfdi), REG_SYM(__floatundidf), + REG_SYM(__fixsfdi), + REG_SYM(__fixunssfdi), + REG_SYM(__fixunsdfdi), + REG_SYM(__floatdisf), + REG_SYM(__floatundisf), }; /* clang-format on */ @@ -207,6 +217,10 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, case R_XTENSA_32: { uint8 *insn_addr = target_section_addr + reloc_offset; +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) + insn_addr = os_get_dbus_mirror((void *)insn_addr); + bh_assert(insn_addr != NULL); +#endif int32 initial_addend; /* (S + A) */ if ((intptr_t)insn_addr & 3) { @@ -265,6 +279,11 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, return false; } +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) + insn_addr = os_get_dbus_mirror((void *)insn_addr); + bh_assert(insn_addr != NULL); + l32r_insn = (l32r_insn_t *)insn_addr; +#endif imm16 = (int16)(relative_offset >> 2); /* write back the imm16 to the l32r instruction */ @@ -285,7 +304,6 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr, #if __GNUC__ >= 9 #pragma GCC diagnostic pop #endif - break; } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/LICENSE_NUTTX b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/LICENSE_NUTTX similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/LICENSE_NUTTX rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/LICENSE_NUTTX diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/NOTICE_NUTTX b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/NOTICE_NUTTX similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/NOTICE_NUTTX rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/NOTICE_NUTTX diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf32.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf32.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf32.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf32.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf64.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf64.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf64.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf64.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf_parser.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf_parser.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf_parser.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf_parser.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf_parser.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf_parser.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/elf_parser.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/elf_parser.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/jit_debug.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/jit_debug.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/jit_debug.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/jit_debug.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/jit_debug.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/jit_debug.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/aot/debug/jit_debug.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/debug/jit_debug.h diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/iwasm_aot.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/iwasm_aot.cmake new file mode 100644 index 00000000000..efff88dd079 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/aot/iwasm_aot.cmake @@ -0,0 +1,84 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +set (IWASM_AOT_DIR ${CMAKE_CURRENT_LIST_DIR}) + +add_definitions (-DWASM_ENABLE_AOT=1) + +include_directories (${IWASM_AOT_DIR}) + +file (GLOB c_source_all ${IWASM_AOT_DIR}/*.c) + +if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64") + set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_x86_64.c) +elseif (WAMR_BUILD_TARGET STREQUAL "X86_32") + set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_x86_32.c) +elseif (WAMR_BUILD_TARGET MATCHES "AARCH64.*") + set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_aarch64.c) +elseif (WAMR_BUILD_TARGET MATCHES "ARM.*") + set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_arm.c) +elseif (WAMR_BUILD_TARGET MATCHES "THUMB.*") + set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_thumb.c) +elseif (WAMR_BUILD_TARGET STREQUAL "MIPS") + set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_mips.c) +elseif (WAMR_BUILD_TARGET STREQUAL "XTENSA") + set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_xtensa.c) +elseif (WAMR_BUILD_TARGET MATCHES "RISCV*") + set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_riscv.c) +elseif (WAMR_BUILD_TARGET STREQUAL "ARC") + set (arch_source ${IWASM_AOT_DIR}/arch/aot_reloc_arc.c) +else () + message (FATAL_ERROR "Build target isn't set") +endif () + +if (WAMR_BUILD_DEBUG_AOT EQUAL 1) + add_definitions(-DWASM_ENABLE_DEBUG_AOT=1) + file(GLOB debug_source ${IWASM_AOT_DIR}/debug/*.c) +endif() + +if ((WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64") + AND (WAMR_BUILD_PLATFORM STREQUAL "windows") + AND (NOT WAMR_DISABLE_HW_BOUND_CHECK EQUAL 1)) + include(FetchContent) + + FetchContent_Declare( + zycore + GIT_REPOSITORY https://github.com/zyantific/zycore-c.git + ) + FetchContent_GetProperties(zycore) + if (NOT zycore_POPULATED) + message ("-- Fetching zycore ..") + FetchContent_Populate(zycore) + include_directories("${zycore_SOURCE_DIR}/include") + include_directories("${zycore_BINARY_DIR}") + add_definitions(-DZYCORE_STATIC_BUILD=1) + add_subdirectory(${zycore_SOURCE_DIR} ${zycore_BINARY_DIR} EXCLUDE_FROM_ALL) + file (GLOB_RECURSE c_source_zycore ${zycore_SOURCE_DIR}/src/*.c) + endif () + + FetchContent_Declare( + zydis + GIT_REPOSITORY https://github.com/zyantific/zydis.git + GIT_TAG e14a07895136182a5b53e181eec3b1c6e0b434de + ) + FetchContent_GetProperties(zydis) + if (NOT zydis_POPULATED) + message ("-- Fetching zydis ..") + FetchContent_Populate(zydis) + option(ZYDIS_FEATURE_ENCODER "" OFF) + option(ZYDIS_BUILD_TOOLS "" OFF) + option(ZYDIS_BUILD_EXAMPLES "" OFF) + option(ZYDIS_BUILD_MAN "" OFF) + option(ZYDIS_BUILD_DOXYGEN "" OFF) + include_directories("${zydis_BINARY_DIR}") + include_directories("${zydis_SOURCE_DIR}/include") + include_directories("${zydis_SOURCE_DIR}/src") + add_definitions(-DZYDIS_STATIC_BUILD=1) + add_subdirectory(${zydis_SOURCE_DIR} ${zydis_BINARY_DIR} EXCLUDE_FROM_ALL) + file (GLOB_RECURSE c_source_zydis ${zydis_SOURCE_DIR}/src/*.c) + endif () +endif () + + +set (IWASM_AOT_SOURCE ${c_source_all} ${arch_source} ${debug_source} + ${c_source_zycore} ${c_source_zydis}) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/SConscript similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/SConscript rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/SConscript diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_aarch64.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_aarch64.s similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_aarch64.s rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_aarch64.s diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_aarch64_simd.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_aarch64_simd.s similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_aarch64_simd.s rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_aarch64_simd.s diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_arc.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_arc.s similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_arc.s rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_arc.s diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_arm.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_arm.s similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_arm.s rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_arm.s diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_arm_vfp.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_arm_vfp.s similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_arm_vfp.s rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_arm_vfp.s diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_em64.asm b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_em64.asm similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_em64.asm rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_em64.asm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_em64.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_em64.s similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_em64.s rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_em64.s diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_em64_simd.asm b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_em64_simd.asm similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_em64_simd.asm rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_em64_simd.asm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_em64_simd.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_em64_simd.s similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_em64_simd.s rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_em64_simd.s diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_general.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_general.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_general.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_general.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_ia32.asm b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_ia32.asm similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_ia32.asm rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_ia32.asm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_ia32.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_ia32.s similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_ia32.s rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_ia32.s diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_mingw_x64.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_mingw_x64.s similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_mingw_x64.s rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_mingw_x64.s diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_mingw_x64_simd.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_mingw_x64_simd.s similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_mingw_x64_simd.s rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_mingw_x64_simd.s diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_mips.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_mips.s similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_mips.s rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_mips.s diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_osx_universal.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_osx_universal.s similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_osx_universal.s rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_osx_universal.s diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_riscv.S b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_riscv.S similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_riscv.S rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_riscv.S diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_thumb.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_thumb.s similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_thumb.s rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_thumb.s diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_thumb_vfp.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_thumb_vfp.s similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_thumb_vfp.s rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_thumb_vfp.s diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_xtensa.s b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_xtensa.s similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_xtensa.s rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/arch/invokeNative_xtensa.s diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/iwasm_common.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/iwasm_common.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/iwasm_common.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/iwasm_common.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_application.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_application.c similarity index 90% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_application.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_application.c index 2ed217e7a96..93c9342dace 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_application.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_application.c @@ -107,7 +107,34 @@ execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, char *argv[]) the actual main function. Directly calling main function may cause exception thrown. */ if ((func = wasm_runtime_lookup_wasi_start_function(module_inst))) { - return wasm_runtime_call_wasm(exec_env, func, 0, NULL); + const char *wasi_proc_exit_exception = "wasi proc exit"; + + ret = wasm_runtime_call_wasm(exec_env, func, 0, NULL); +#if WASM_ENABLE_THREAD_MGR != 0 + if (ret) { + /* On a successful return from the `_start` function, + we terminate other threads by mimicing wasi:proc_exit(0). + + Note: + - A return from the `main` function is an equivalent of + exit(). (C standard) + - When exit code is 0, wasi-libc's `_start` function just + returns w/o calling `proc_exit`. + - A process termination should terminate threads in + the process. */ + + wasm_runtime_set_exception(module_inst, wasi_proc_exit_exception); + /* exit_code is zero-initialized */ + ret = false; + } +#endif + /* report wasm proc exit as a success */ + WASMModuleInstance *inst = (WASMModuleInstance *)module_inst; + if (!ret && strstr(inst->cur_exception, wasi_proc_exit_exception)) { + inst->cur_exception[0] = 0; + ret = true; + } + return ret; } #endif /* end of WASM_ENABLE_LIBC_WASI */ @@ -204,7 +231,7 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, char *argv[]) { bool ret; -#if (WASM_ENABLE_MEMORY_PROFILING != 0) || (WASM_ENABLE_DUMP_CALL_STACK != 0) +#if (WASM_ENABLE_MEMORY_PROFILING != 0) WASMExecEnv *exec_env; #endif @@ -224,14 +251,6 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, if (ret) ret = wasm_runtime_get_exception(module_inst) == NULL; -#if WASM_ENABLE_DUMP_CALL_STACK != 0 - if (!ret) { - exec_env = wasm_runtime_get_exec_env_singleton(module_inst); - if (exec_env) - wasm_runtime_dump_call_stack(exec_env); - } -#endif - return ret; } @@ -293,7 +312,6 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name, #endif int32 i, p, module_type; uint64 total_size; - const char *exception; char buf[128]; bh_assert(argc >= 0); @@ -370,6 +388,18 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name, { float32 f32 = strtof(argv[i], &endptr); if (isnan(f32)) { +#ifdef _MSC_VER + /* + * Spec tests require the binary representation of NaN to be + * 0x7fc00000 for float and 0x7ff8000000000000 for float; + * however, in MSVC compiler, strtof doesn't return this + * exact value, causing some of the spec test failures. We + * use the value returned by nan/nanf as it is the one + * expected by spec tests. + * + */ + f32 = nanf(""); +#endif if (argv[i][0] == '-') { union ieee754_float u; u.f = f32; @@ -404,6 +434,9 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name, } u; u.val = strtod(argv[i], &endptr); if (isnan(u.val)) { +#ifdef _MSC_VER + u.val = nan(""); +#endif if (argv[i][0] == '-') { union ieee754_double ud; ud.d = u.val; @@ -567,7 +600,7 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name, { #if UINTPTR_MAX == UINT32_MAX if (argv1[k] != 0 && argv1[k] != (uint32)-1) - os_printf("%p:ref.extern", (void *)argv1[k]); + os_printf("0x%" PRIxPTR ":ref.extern", (uintptr_t)argv1[k]); else os_printf("extern:ref.null"); k++; @@ -580,7 +613,7 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name, u.parts[1] = argv1[k + 1]; k += 2; if (u.val && u.val != (uintptr_t)-1LL) - os_printf("%p:ref.extern", (void *)u.val); + os_printf("0x%" PRIxPTR ":ref.extern", u.val); else os_printf("extern:ref.null"); #endif @@ -613,9 +646,7 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name, if (argv1) wasm_runtime_free(argv1); - exception = wasm_runtime_get_exception(module_inst); - bh_assert(exception); - os_printf("%s\n", exception); + bh_assert(wasm_runtime_get_exception(module_inst)); return false; } diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_blocking_op.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_blocking_op.c new file mode 100644 index 00000000000..25777c8d746 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_blocking_op.c @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2023 Midokura Japan KK. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "wasm_runtime_common.h" + +#include "bh_platform.h" +#include "bh_common.h" +#include "bh_assert.h" + +#if WASM_ENABLE_THREAD_MGR != 0 && defined(OS_ENABLE_WAKEUP_BLOCKING_OP) + +#define LOCK(env) WASM_SUSPEND_FLAGS_LOCK((env)->wait_lock) +#define UNLOCK(env) WASM_SUSPEND_FLAGS_UNLOCK((env)->wait_lock) + +#define ISSET(env, bit) \ + ((WASM_SUSPEND_FLAGS_GET((env)->suspend_flags) & WASM_SUSPEND_FLAG_##bit) \ + != 0) +#define SET(env, bit) \ + WASM_SUSPEND_FLAGS_FETCH_OR((env)->suspend_flags, WASM_SUSPEND_FLAG_##bit) +#define CLR(env, bit) \ + WASM_SUSPEND_FLAGS_FETCH_AND((env)->suspend_flags, ~WASM_SUSPEND_FLAG_##bit) + +bool +wasm_runtime_begin_blocking_op(wasm_exec_env_t env) +{ + LOCK(env); + bh_assert(!ISSET(env, BLOCKING)); + SET(env, BLOCKING); + if (ISSET(env, TERMINATE)) { + CLR(env, BLOCKING); + UNLOCK(env); + return false; + } + UNLOCK(env); + os_begin_blocking_op(); + return true; +} + +void +wasm_runtime_end_blocking_op(wasm_exec_env_t env) +{ + int saved_errno = errno; + LOCK(env); + bh_assert(ISSET(env, BLOCKING)); + CLR(env, BLOCKING); + UNLOCK(env); + os_end_blocking_op(); + errno = saved_errno; +} + +void +wasm_runtime_interrupt_blocking_op(wasm_exec_env_t env) +{ + /* + * ISSET(BLOCKING) here means that the target thread + * is in somewhere between wasm_begin_blocking_op and + * wasm_end_blocking_op. + * keep waking it up until it reaches wasm_end_blocking_op, + * which clears the BLOCKING bit. + * + * this dumb loop is necessary because posix doesn't provide + * a way to unmask signal and block atomically. + */ + + LOCK(env); + SET(env, TERMINATE); + while (ISSET(env, BLOCKING)) { + UNLOCK(env); + os_wakeup_blocking_op(env->handle); + + /* relax a bit */ + os_usleep(50 * 1000); + LOCK(env); + } + UNLOCK(env); +} + +#else /* WASM_ENABLE_THREAD_MGR && OS_ENABLE_WAKEUP_BLOCKING_OP */ + +bool +wasm_runtime_begin_blocking_op(wasm_exec_env_t env) +{ + return true; +} + +void +wasm_runtime_end_blocking_op(wasm_exec_env_t env) +{} + +#endif /* WASM_ENABLE_THREAD_MGR && OS_ENABLE_WAKEUP_BLOCKING_OP */ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_c_api.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_c_api.c similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_c_api.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_c_api.c index 7b8cf477974..57c3ebd0d0c 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_c_api.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_c_api.c @@ -292,13 +292,46 @@ WASM_DEFINE_VEC_OWN(valtype, wasm_valtype_delete) own wasm_config_t * wasm_config_new(void) { - return NULL; + /* since wasm_runtime_malloc is not ready */ + wasm_config_t *config = os_malloc(sizeof(wasm_config_t)); + if (!config) + return NULL; + + memset(config, 0, sizeof(wasm_config_t)); + config->mem_alloc_type = Alloc_With_System_Allocator; + return config; } void wasm_config_delete(own wasm_config_t *config) { - (void)config; + if (config) + os_free(config); +} + +wasm_config_t * +wasm_config_set_mem_alloc_opt(wasm_config_t *config, + mem_alloc_type_t mem_alloc_type, + MemAllocOption *mem_alloc_option) +{ + if (!config) + return NULL; + + config->mem_alloc_type = mem_alloc_type; + if (mem_alloc_option) + memcpy(&config->mem_alloc_option, mem_alloc_option, + sizeof(MemAllocOption)); + return config; +} + +wasm_config_t * +wasm_config_set_linux_perf_opt(wasm_config_t *config, bool enable) +{ + if (!config) + return NULL; + + config->linux_perf_support = enable; + return config; } static void @@ -329,12 +362,11 @@ wasm_engine_delete_internal(wasm_engine_t *engine) } static wasm_engine_t * -wasm_engine_new_internal(mem_alloc_type_t type, const MemAllocOption *opts) +wasm_engine_new_internal(wasm_config_t *config) { wasm_engine_t *engine = NULL; /* init runtime */ RuntimeInitArgs init_args = { 0 }; - init_args.mem_alloc_type = type; #ifndef NDEBUG bh_log_set_verbose_level(BH_LOG_LEVEL_VERBOSE); @@ -344,34 +376,11 @@ wasm_engine_new_internal(mem_alloc_type_t type, const MemAllocOption *opts) WASM_C_DUMP_PROC_MEM(); - if (type == Alloc_With_Pool) { - if (!opts) { - return NULL; - } - - init_args.mem_alloc_option.pool.heap_buf = opts->pool.heap_buf; - init_args.mem_alloc_option.pool.heap_size = opts->pool.heap_size; - } - else if (type == Alloc_With_Allocator) { - if (!opts) { - return NULL; - } - - init_args.mem_alloc_option.allocator.malloc_func = - opts->allocator.malloc_func; - init_args.mem_alloc_option.allocator.free_func = - opts->allocator.free_func; - init_args.mem_alloc_option.allocator.realloc_func = - opts->allocator.realloc_func; -#if WASM_MEM_ALLOC_WITH_USER_DATA != 0 - init_args.mem_alloc_option.allocator.user_data = - opts->allocator.user_data; -#endif - } - else { - init_args.mem_alloc_option.pool.heap_buf = NULL; - init_args.mem_alloc_option.pool.heap_size = 0; - } + /* wasm_config_t->MemAllocOption -> RuntimeInitArgs->MemAllocOption */ + init_args.mem_alloc_type = config->mem_alloc_type; + memcpy(&init_args.mem_alloc_option, &config->mem_alloc_option, + sizeof(MemAllocOption)); + init_args.linux_perf_support = config->linux_perf_support; if (!wasm_runtime_full_init(&init_args)) { LOG_DEBUG("wasm_runtime_full_init failed"); @@ -418,14 +427,23 @@ static korp_mutex engine_lock = OS_THREAD_MUTEX_INITIALIZER; #endif own wasm_engine_t * -wasm_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts) +wasm_engine_new() +{ + wasm_config_t config = { 0 }; + wasm_config_set_mem_alloc_opt(&config, Alloc_With_System_Allocator, NULL); + wasm_engine_t *engine = wasm_engine_new_with_config(&config); + return engine; +} + +own wasm_engine_t * +wasm_engine_new_with_config(wasm_config_t *config) { #if defined(OS_THREAD_MUTEX_INITIALIZER) os_mutex_lock(&engine_lock); #endif if (!singleton_engine) - singleton_engine = wasm_engine_new_internal(type, opts); + singleton_engine = wasm_engine_new_internal(config); else singleton_engine->ref_count++; @@ -437,16 +455,12 @@ wasm_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts) } own wasm_engine_t * -wasm_engine_new() -{ - return wasm_engine_new_with_args(Alloc_With_System_Allocator, NULL); -} - -own wasm_engine_t * -wasm_engine_new_with_config(own wasm_config_t *config) +wasm_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts) { - (void)config; - return wasm_engine_new_with_args(Alloc_With_System_Allocator, NULL); + wasm_config_t config = { 0 }; + config.mem_alloc_type = type; + memcpy(&config.mem_alloc_option, opts, sizeof(MemAllocOption)); + return wasm_engine_new_with_config(&config); } void @@ -2290,8 +2304,10 @@ wasm_module_new(wasm_store_t *store, const wasm_byte_vec_t *binary) bool wasm_module_validate(wasm_store_t *store, const wasm_byte_vec_t *binary) { + wasm_byte_vec_t local_binary = { 0 }; struct WASMModuleCommon *module_rt; char error_buf[128] = { 0 }; + bool ret; bh_assert(singleton_engine); @@ -2300,15 +2316,25 @@ wasm_module_validate(wasm_store_t *store, const wasm_byte_vec_t *binary) return false; } - if ((module_rt = wasm_runtime_load((uint8 *)binary->data, - (uint32)binary->size, error_buf, 128))) { + /* make a copy of binary */ + wasm_byte_vec_copy(&local_binary, binary); + + if (binary->size && !local_binary.data) + return false; + + module_rt = wasm_runtime_load((uint8 *)local_binary.data, + (uint32)local_binary.size, error_buf, 128); + wasm_byte_vec_delete(&local_binary); + if (module_rt) { wasm_runtime_unload(module_rt); - return true; + ret = true; } else { + ret = false; LOG_VERBOSE(error_buf); - return false; } + + return ret; } static void @@ -4858,7 +4884,7 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module, if (instance->inst_comm_rt->module_type == Wasm_Module_Bytecode) { WASMModuleInstanceExtra *e = ((WASMModuleInstance *)instance->inst_comm_rt)->e; - p_func_imports = &(e->c_api_func_imports); + p_func_imports = &(e->common.c_api_func_imports); import_func_count = MODULE_INTERP(module)->import_function_count; } #endif @@ -4868,7 +4894,7 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module, (AOTModuleInstanceExtra *)((AOTModuleInstance *) instance->inst_comm_rt) ->e; - p_func_imports = &(e->c_api_func_imports); + p_func_imports = &(e->common.c_api_func_imports); import_func_count = MODULE_AOT(module)->import_func_count; } #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_c_api_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_c_api_internal.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_c_api_internal.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_c_api_internal.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_exec_env.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_exec_env.c similarity index 81% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_exec_env.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_exec_env.c index 622bcd71ee7..d524c7de093 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_exec_env.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_exec_env.c @@ -58,7 +58,8 @@ wasm_exec_env_create_internal(struct WASMModuleInstanceCommon *module_inst, #ifdef OS_ENABLE_HW_BOUND_CHECK if (!(exec_env->exce_check_guard_page = - os_mmap(NULL, os_getpagesize(), MMAP_PROT_NONE, MMAP_MAP_NONE))) + os_mmap(NULL, os_getpagesize(), MMAP_PROT_NONE, MMAP_MAP_NONE, + os_get_invalid_handle()))) goto fail5; #endif @@ -201,7 +202,52 @@ void wasm_exec_env_set_module_inst(WASMExecEnv *exec_env, WASMModuleInstanceCommon *const module_inst) { +#if WASM_ENABLE_THREAD_MGR != 0 + wasm_cluster_traverse_lock(exec_env); +#endif exec_env->module_inst = module_inst; +#if WASM_ENABLE_THREAD_MGR != 0 + wasm_cluster_traverse_unlock(exec_env); +#endif +} + +void +wasm_exec_env_restore_module_inst( + WASMExecEnv *exec_env, WASMModuleInstanceCommon *const module_inst_common) +{ + WASMModuleInstanceCommon *old_module_inst_common = exec_env->module_inst; + WASMModuleInstance *old_module_inst = + (WASMModuleInstance *)old_module_inst_common; + WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_common; + char cur_exception[EXCEPTION_BUF_LEN]; + +#if WASM_ENABLE_THREAD_MGR != 0 + wasm_cluster_traverse_lock(exec_env); +#endif + exec_env->module_inst = module_inst_common; + /* + * propagate an exception if any. + */ + exception_lock(old_module_inst); + if (old_module_inst->cur_exception[0] != '\0') { + bh_memcpy_s(cur_exception, sizeof(cur_exception), + old_module_inst->cur_exception, + sizeof(old_module_inst->cur_exception)); + } + else { + cur_exception[0] = '\0'; + } + exception_unlock(old_module_inst); +#if WASM_ENABLE_THREAD_MGR != 0 + wasm_cluster_traverse_unlock(exec_env); +#endif + if (cur_exception[0] != '\0') { + exception_lock(module_inst); + bh_memcpy_s(module_inst->cur_exception, + sizeof(module_inst->cur_exception), cur_exception, + sizeof(cur_exception)); + exception_unlock(module_inst); + } } void diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_exec_env.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_exec_env.h similarity index 96% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_exec_env.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_exec_env.h index 29b28a15922..132642ea8eb 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_exec_env.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_exec_env.h @@ -7,6 +7,7 @@ #define _WASM_EXEC_ENV_H #include "bh_assert.h" +#include "wasm_suspend_flags.h" #if WASM_ENABLE_INTERP != 0 #include "../interpreter/wasm.h" #endif @@ -57,15 +58,8 @@ typedef struct WASMExecEnv { exception. */ uint8 *native_stack_boundary; - /* Used to terminate or suspend current thread - bit 0: need to terminate - bit 1: need to suspend - bit 2: need to go into breakpoint - bit 3: return from pthread_exit */ - union { - uint32 flags; - uintptr_t __padding__; - } suspend_flags; + /* Used to terminate or suspend current thread */ + WASMSuspendFlags suspend_flags; /* Auxiliary stack boundary */ union { @@ -297,6 +291,10 @@ void wasm_exec_env_set_module_inst( WASMExecEnv *exec_env, struct WASMModuleInstanceCommon *const module_inst); +void +wasm_exec_env_restore_module_inst( + WASMExecEnv *exec_env, struct WASMModuleInstanceCommon *const module_inst); + void wasm_exec_env_set_thread_info(WASMExecEnv *exec_env); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_memory.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_memory.c similarity index 73% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_memory.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_memory.c index 82676ae271d..3941c224aa2 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_memory.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_memory.c @@ -5,8 +5,10 @@ #include "wasm_runtime_common.h" #include "../interpreter/wasm_runtime.h" +#include "../aot/aot_runtime.h" #include "bh_platform.h" #include "mem_alloc.h" +#include "wasm_memory.h" #if WASM_ENABLE_SHARED_MEMORY != 0 #include "../common/wasm_shared_memory.h" @@ -23,6 +25,9 @@ static Memory_Mode memory_mode = MEMORY_MODE_UNKNOWN; static mem_allocator_t pool_allocator = NULL; +static enlarge_memory_error_callback_t enlarge_memory_error_cb; +static void *enlarge_memory_error_user_data; + #if WASM_MEM_ALLOC_WITH_USER_DATA != 0 static void *allocator_user_data = NULL; static void *(*malloc_func)(void *user_data, unsigned int size) = NULL; @@ -87,6 +92,16 @@ wasm_memory_init_with_allocator(void *_malloc_func, void *_realloc_func, } #endif +static inline bool +is_bounds_checks_enabled(WASMModuleInstanceCommon *module_inst) +{ +#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0 + return wasm_runtime_is_bounds_checks_enabled(module_inst); +#else + return true; +#endif +} + bool wasm_runtime_memory_init(mem_alloc_type_t mem_alloc_type, const MemAllocOption *alloc_option) @@ -269,6 +284,10 @@ wasm_runtime_validate_app_addr(WASMModuleInstanceCommon *module_inst_comm, bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode || module_inst_comm->module_type == Wasm_Module_AoT); + if (!is_bounds_checks_enabled(module_inst_comm)) { + return true; + } + memory_inst = wasm_get_default_memory(module_inst); if (!memory_inst) { goto fail; @@ -279,10 +298,15 @@ wasm_runtime_validate_app_addr(WASMModuleInstanceCommon *module_inst_comm, goto fail; } + SHARED_MEMORY_LOCK(memory_inst); + if (app_offset + size <= memory_inst->memory_data_size) { + SHARED_MEMORY_UNLOCK(memory_inst); return true; } + SHARED_MEMORY_UNLOCK(memory_inst); + fail: wasm_set_exception(module_inst, "out of bounds memory access"); return false; @@ -299,6 +323,10 @@ wasm_runtime_validate_app_str_addr(WASMModuleInstanceCommon *module_inst_comm, bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode || module_inst_comm->module_type == Wasm_Module_AoT); + if (!is_bounds_checks_enabled(module_inst_comm)) { + return true; + } + if (!wasm_runtime_get_app_addr_range(module_inst_comm, app_str_offset, NULL, &app_end_offset)) goto fail; @@ -327,6 +355,10 @@ wasm_runtime_validate_native_addr(WASMModuleInstanceCommon *module_inst_comm, bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode || module_inst_comm->module_type == Wasm_Module_AoT); + if (!is_bounds_checks_enabled(module_inst_comm)) { + return true; + } + memory_inst = wasm_get_default_memory(module_inst); if (!memory_inst) { goto fail; @@ -337,11 +369,16 @@ wasm_runtime_validate_native_addr(WASMModuleInstanceCommon *module_inst_comm, goto fail; } + SHARED_MEMORY_LOCK(memory_inst); + if (memory_inst->memory_data <= addr && addr + size <= memory_inst->memory_data_end) { + SHARED_MEMORY_UNLOCK(memory_inst); return true; } + SHARED_MEMORY_UNLOCK(memory_inst); + fail: wasm_set_exception(module_inst, "out of bounds memory access"); return false; @@ -354,20 +391,36 @@ wasm_runtime_addr_app_to_native(WASMModuleInstanceCommon *module_inst_comm, WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_comm; WASMMemoryInstance *memory_inst; uint8 *addr; + bool bounds_checks; bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode || module_inst_comm->module_type == Wasm_Module_AoT); + bounds_checks = is_bounds_checks_enabled(module_inst_comm); + memory_inst = wasm_get_default_memory(module_inst); if (!memory_inst) { return NULL; } + SHARED_MEMORY_LOCK(memory_inst); + addr = memory_inst->memory_data + app_offset; - if (memory_inst->memory_data <= addr && addr < memory_inst->memory_data_end) + if (bounds_checks) { + if (memory_inst->memory_data <= addr + && addr < memory_inst->memory_data_end) { + SHARED_MEMORY_UNLOCK(memory_inst); + return addr; + } + } + /* If bounds checks is disabled, return the address directly */ + else if (app_offset != 0) { + SHARED_MEMORY_UNLOCK(memory_inst); return addr; + } + SHARED_MEMORY_UNLOCK(memory_inst); return NULL; } @@ -378,18 +431,37 @@ wasm_runtime_addr_native_to_app(WASMModuleInstanceCommon *module_inst_comm, WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_comm; WASMMemoryInstance *memory_inst; uint8 *addr = (uint8 *)native_ptr; + bool bounds_checks; + uint32 ret; bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode || module_inst_comm->module_type == Wasm_Module_AoT); + bounds_checks = is_bounds_checks_enabled(module_inst_comm); + memory_inst = wasm_get_default_memory(module_inst); if (!memory_inst) { return 0; } - if (memory_inst->memory_data <= addr && addr < memory_inst->memory_data_end) - return (uint32)(addr - memory_inst->memory_data); + SHARED_MEMORY_LOCK(memory_inst); + + if (bounds_checks) { + if (memory_inst->memory_data <= addr + && addr < memory_inst->memory_data_end) { + ret = (uint32)(addr - memory_inst->memory_data); + SHARED_MEMORY_UNLOCK(memory_inst); + return ret; + } + } + /* If bounds checks is disabled, return the offset directly */ + else if (addr != NULL) { + ret = (uint32)(addr - memory_inst->memory_data); + SHARED_MEMORY_UNLOCK(memory_inst); + return ret; + } + SHARED_MEMORY_UNLOCK(memory_inst); return 0; } @@ -410,6 +482,8 @@ wasm_runtime_get_app_addr_range(WASMModuleInstanceCommon *module_inst_comm, return false; } + SHARED_MEMORY_LOCK(memory_inst); + memory_data_size = memory_inst->memory_data_size; if (app_offset < memory_data_size) { @@ -417,9 +491,11 @@ wasm_runtime_get_app_addr_range(WASMModuleInstanceCommon *module_inst_comm, *p_app_start_offset = 0; if (p_app_end_offset) *p_app_end_offset = memory_data_size; + SHARED_MEMORY_UNLOCK(memory_inst); return true; } + SHARED_MEMORY_UNLOCK(memory_inst); return false; } @@ -441,15 +517,19 @@ wasm_runtime_get_native_addr_range(WASMModuleInstanceCommon *module_inst_comm, return false; } + SHARED_MEMORY_LOCK(memory_inst); + if (memory_inst->memory_data <= addr && addr < memory_inst->memory_data_end) { if (p_native_start_addr) *p_native_start_addr = memory_inst->memory_data; if (p_native_end_addr) *p_native_end_addr = memory_inst->memory_data_end; + SHARED_MEMORY_UNLOCK(memory_inst); return true; } + SHARED_MEMORY_UNLOCK(memory_inst); return false; } @@ -460,16 +540,29 @@ wasm_check_app_addr_and_convert(WASMModuleInstance *module_inst, bool is_str, { WASMMemoryInstance *memory_inst = wasm_get_default_memory(module_inst); uint8 *native_addr; + bool bounds_checks; if (!memory_inst) { - goto fail; + wasm_set_exception(module_inst, "out of bounds memory access"); + return false; } native_addr = memory_inst->memory_data + app_buf_addr; + bounds_checks = is_bounds_checks_enabled((wasm_module_inst_t)module_inst); + + if (!bounds_checks) { + if (app_buf_addr == 0) { + native_addr = NULL; + } + goto success; + } + /* No need to check the app_offset and buf_size if memory access boundary check with hardware trap is enabled */ #ifndef OS_ENABLE_HW_BOUND_CHECK + SHARED_MEMORY_LOCK(memory_inst); + if (app_buf_addr >= memory_inst->memory_data_size) { goto fail; } @@ -490,13 +583,20 @@ wasm_check_app_addr_and_convert(WASMModuleInstance *module_inst, bool is_str, if (str == str_end) goto fail; } + + SHARED_MEMORY_UNLOCK(memory_inst); #endif +success: *p_native_addr = (void *)native_addr; return true; + +#ifndef OS_ENABLE_HW_BOUND_CHECK fail: + SHARED_MEMORY_UNLOCK(memory_inst); wasm_set_exception(module_inst, "out of bounds memory access"); return false; +#endif } WASMMemoryInstance * @@ -508,19 +608,43 @@ wasm_get_default_memory(WASMModuleInstance *module_inst) return NULL; } +void +wasm_runtime_set_mem_bound_check_bytes(WASMMemoryInstance *memory, + uint64 memory_data_size) +{ +#if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0 || WASM_ENABLE_AOT != 0 +#if UINTPTR_MAX == UINT64_MAX + memory->mem_bound_check_1byte.u64 = memory_data_size - 1; + memory->mem_bound_check_2bytes.u64 = memory_data_size - 2; + memory->mem_bound_check_4bytes.u64 = memory_data_size - 4; + memory->mem_bound_check_8bytes.u64 = memory_data_size - 8; + memory->mem_bound_check_16bytes.u64 = memory_data_size - 16; +#else + memory->mem_bound_check_1byte.u32[0] = (uint32)memory_data_size - 1; + memory->mem_bound_check_2bytes.u32[0] = (uint32)memory_data_size - 2; + memory->mem_bound_check_4bytes.u32[0] = (uint32)memory_data_size - 4; + memory->mem_bound_check_8bytes.u32[0] = (uint32)memory_data_size - 8; + memory->mem_bound_check_16bytes.u32[0] = (uint32)memory_data_size - 16; +#endif +#endif +} + #ifndef OS_ENABLE_HW_BOUND_CHECK bool wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count) { WASMMemoryInstance *memory = wasm_get_default_memory(module); uint8 *memory_data_old, *memory_data_new, *heap_data_old; - uint32 num_bytes_per_page, heap_size, total_size_old; + uint32 num_bytes_per_page, heap_size, total_size_old = 0; uint32 cur_page_count, max_page_count, total_page_count; uint64 total_size_new; bool ret = true; + enlarge_memory_error_reason_t failure_reason = INTERNAL_ERROR; - if (!memory) - return false; + if (!memory) { + ret = false; + goto return_func; + } heap_data_old = memory->heap_data; heap_size = (uint32)(memory->heap_data_end - memory->heap_data); @@ -538,9 +662,15 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count) /* No need to enlarge memory */ return true; - if (total_page_count < cur_page_count /* integer overflow */ - || total_page_count > max_page_count) { - return false; + if (total_page_count < cur_page_count) { /* integer overflow */ + ret = false; + goto return_func; + } + + if (total_page_count > max_page_count) { + failure_reason = MAX_SIZE_REACHED; + ret = false; + goto return_func; } bh_assert(total_size_new <= 4 * (uint64)BH_GB); @@ -552,13 +682,14 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count) } #if WASM_ENABLE_SHARED_MEMORY != 0 - if (memory->is_shared) { + if (shared_memory_is_shared(memory)) { memory->num_bytes_per_page = num_bytes_per_page; memory->cur_page_count = total_page_count; memory->max_page_count = max_page_count; - /* No need to update memory->memory_data_size as it is - initialized with the maximum memory data size for - shared memory */ + SET_LINEAR_MEMORY_SIZE(memory, (uint32)total_size_new); + memory->memory_data_end = memory->memory_data + (uint32)total_size_new; + + wasm_runtime_set_mem_bound_check_bytes(memory, total_size_new); return true; } #endif @@ -566,14 +697,16 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count) if (heap_size > 0) { if (mem_allocator_is_heap_corrupted(memory->heap_handle)) { wasm_runtime_show_app_heap_corrupted_prompt(); - return false; + ret = false; + goto return_func; } } if (!(memory_data_new = wasm_runtime_realloc(memory_data_old, (uint32)total_size_new))) { if (!(memory_data_new = wasm_runtime_malloc((uint32)total_size_new))) { - return false; + ret = false; + goto return_func; } if (memory_data_old) { bh_memcpy_s(memory_data_new, (uint32)total_size_new, @@ -608,22 +741,34 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count) memory->memory_data = memory_data_new; memory->memory_data_end = memory_data_new + (uint32)total_size_new; -#if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0 || WASM_ENABLE_AOT != 0 -#if UINTPTR_MAX == UINT64_MAX - memory->mem_bound_check_1byte.u64 = total_size_new - 1; - memory->mem_bound_check_2bytes.u64 = total_size_new - 2; - memory->mem_bound_check_4bytes.u64 = total_size_new - 4; - memory->mem_bound_check_8bytes.u64 = total_size_new - 8; - memory->mem_bound_check_16bytes.u64 = total_size_new - 16; -#else - memory->mem_bound_check_1byte.u32[0] = (uint32)total_size_new - 1; - memory->mem_bound_check_2bytes.u32[0] = (uint32)total_size_new - 2; - memory->mem_bound_check_4bytes.u32[0] = (uint32)total_size_new - 4; - memory->mem_bound_check_8bytes.u32[0] = (uint32)total_size_new - 8; - memory->mem_bound_check_16bytes.u32[0] = (uint32)total_size_new - 16; + wasm_runtime_set_mem_bound_check_bytes(memory, total_size_new); + +#if defined(os_writegsbase) + /* write base addr of linear memory to GS segment register */ + os_writegsbase(memory_data_new); #endif + +return_func: + if (!ret && enlarge_memory_error_cb) { + WASMExecEnv *exec_env = NULL; + +#if WASM_ENABLE_INTERP != 0 + if (module->module_type == Wasm_Module_Bytecode) + exec_env = + ((WASMModuleInstanceExtra *)module->e)->common.cur_exec_env; +#endif +#if WASM_ENABLE_AOT != 0 + if (module->module_type == Wasm_Module_AoT) + exec_env = + ((AOTModuleInstanceExtra *)module->e)->common.cur_exec_env; #endif + enlarge_memory_error_cb(inc_page_count, total_size_old, 0, + failure_reason, + (WASMModuleInstanceCommon *)module, exec_env, + enlarge_memory_error_user_data); + } + return ret; } #else @@ -631,12 +776,16 @@ bool wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count) { WASMMemoryInstance *memory = wasm_get_default_memory(module); - uint32 num_bytes_per_page, total_size_old; + uint32 num_bytes_per_page, total_size_old = 0; uint32 cur_page_count, max_page_count, total_page_count; uint64 total_size_new; + bool ret = true; + enlarge_memory_error_reason_t failure_reason = INTERNAL_ERROR; - if (!memory) - return false; + if (!memory) { + ret = false; + goto return_func; + } num_bytes_per_page = memory->num_bytes_per_page; cur_page_count = memory->cur_page_count; @@ -649,9 +798,15 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count) /* No need to enlarge memory */ return true; - if (total_page_count < cur_page_count /* integer overflow */ - || total_page_count > max_page_count) { - return false; + if (total_page_count < cur_page_count) { /* integer overflow */ + ret = false; + goto return_func; + } + + if (total_page_count > max_page_count) { + failure_reason = MAX_SIZE_REACHED; + ret = false; + goto return_func; } bh_assert(total_size_new <= 4 * (uint64)BH_GB); @@ -666,7 +821,8 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count) if (!os_mem_commit(memory->memory_data_end, (uint32)total_size_new - total_size_old, MMAP_PROT_READ | MMAP_PROT_WRITE)) { - return false; + ret = false; + goto return_func; } #endif @@ -678,7 +834,8 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count) os_mem_decommit(memory->memory_data_end, (uint32)total_size_new - total_size_old); #endif - return false; + ret = false; + goto return_func; } /* The increased pages are filled with zero by the OS when os_mmap, @@ -687,73 +844,58 @@ wasm_enlarge_memory_internal(WASMModuleInstance *module, uint32 inc_page_count) memory->num_bytes_per_page = num_bytes_per_page; memory->cur_page_count = total_page_count; memory->max_page_count = max_page_count; - memory->memory_data_size = (uint32)total_size_new; + SET_LINEAR_MEMORY_SIZE(memory, (uint32)total_size_new); memory->memory_data_end = memory->memory_data + (uint32)total_size_new; -#if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0 || WASM_ENABLE_AOT != 0 - memory->mem_bound_check_1byte.u64 = total_size_new - 1; - memory->mem_bound_check_2bytes.u64 = total_size_new - 2; - memory->mem_bound_check_4bytes.u64 = total_size_new - 4; - memory->mem_bound_check_8bytes.u64 = total_size_new - 8; - memory->mem_bound_check_16bytes.u64 = total_size_new - 16; + wasm_runtime_set_mem_bound_check_bytes(memory, total_size_new); + +return_func: + if (!ret && enlarge_memory_error_cb) { + WASMExecEnv *exec_env = NULL; + +#if WASM_ENABLE_INTERP != 0 + if (module->module_type == Wasm_Module_Bytecode) + exec_env = + ((WASMModuleInstanceExtra *)module->e)->common.cur_exec_env; +#endif +#if WASM_ENABLE_AOT != 0 + if (module->module_type == Wasm_Module_AoT) + exec_env = + ((AOTModuleInstanceExtra *)module->e)->common.cur_exec_env; #endif - return true; + enlarge_memory_error_cb(inc_page_count, total_size_old, 0, + failure_reason, + (WASMModuleInstanceCommon *)module, exec_env, + enlarge_memory_error_user_data); + } + + return ret; } #endif /* end of OS_ENABLE_HW_BOUND_CHECK */ +void +wasm_runtime_set_enlarge_mem_error_callback( + const enlarge_memory_error_callback_t callback, void *user_data) +{ + enlarge_memory_error_cb = callback; + enlarge_memory_error_user_data = user_data; +} + bool wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count) { bool ret = false; #if WASM_ENABLE_SHARED_MEMORY != 0 - WASMSharedMemNode *node = - wasm_module_get_shared_memory((WASMModuleCommon *)module->module); - if (node) - os_mutex_lock(&node->shared_mem_lock); + if (module->memory_count > 0) + shared_memory_lock(module->memories[0]); #endif ret = wasm_enlarge_memory_internal(module, inc_page_count); #if WASM_ENABLE_SHARED_MEMORY != 0 - if (node) - os_mutex_unlock(&node->shared_mem_lock); + if (module->memory_count > 0) + shared_memory_unlock(module->memories[0]); #endif return ret; } - -#if !defined(OS_ENABLE_HW_BOUND_CHECK) \ - || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \ - || WASM_ENABLE_BULK_MEMORY != 0 -uint32 -wasm_get_num_bytes_per_page(WASMMemoryInstance *memory, void *node) -{ - uint32 num_bytes_per_page; -#if WASM_ENABLE_SHARED_MEMORY != 0 - if (node) - os_mutex_lock(&((WASMSharedMemNode *)node)->shared_mem_lock); -#endif - num_bytes_per_page = memory->num_bytes_per_page; -#if WASM_ENABLE_SHARED_MEMORY != 0 - if (node) - os_mutex_unlock(&((WASMSharedMemNode *)node)->shared_mem_lock); -#endif - return num_bytes_per_page; -} - -uint32 -wasm_get_linear_memory_size(WASMMemoryInstance *memory, void *node) -{ - uint32 linear_mem_size; -#if WASM_ENABLE_SHARED_MEMORY != 0 - if (node) - os_mutex_lock(&((WASMSharedMemNode *)node)->shared_mem_lock); -#endif - linear_mem_size = memory->num_bytes_per_page * memory->cur_page_count; -#if WASM_ENABLE_SHARED_MEMORY != 0 - if (node) - os_mutex_unlock(&((WASMSharedMemNode *)node)->shared_mem_lock); -#endif - return linear_mem_size; -} -#endif \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_memory.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_memory.h new file mode 100644 index 00000000000..9b74db5262a --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_memory.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#ifndef _WASM_MEMORY_H +#define _WASM_MEMORY_H + +#include "bh_common.h" +#include "../include/wasm_export.h" +#include "../interpreter/wasm_runtime.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if WASM_ENABLE_SHARED_MEMORY != 0 +#define GET_LINEAR_MEMORY_SIZE(memory) \ + BH_ATOMIC_32_LOAD(memory->memory_data_size) +#define SET_LINEAR_MEMORY_SIZE(memory, size) \ + BH_ATOMIC_32_STORE(memory->memory_data_size, size) +#else +#define GET_LINEAR_MEMORY_SIZE(memory) memory->memory_data_size +#define SET_LINEAR_MEMORY_SIZE(memory, size) memory->memory_data_size = size +#endif + +bool +wasm_runtime_memory_init(mem_alloc_type_t mem_alloc_type, + const MemAllocOption *alloc_option); + +void +wasm_runtime_memory_destroy(); + +unsigned +wasm_runtime_memory_pool_size(); + +void +wasm_runtime_set_mem_bound_check_bytes(WASMMemoryInstance *memory, + uint64 memory_data_size); + +void +wasm_runtime_set_enlarge_mem_error_callback( + const enlarge_memory_error_callback_t callback, void *user_data); + +#ifdef __cplusplus +} +#endif + +#endif /* end of _WASM_MEMORY_H */ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_native.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_native.c similarity index 75% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_native.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_native.c index 1acaed6eee5..c42bf7b318a 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_native.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_native.c @@ -6,6 +6,15 @@ #include "wasm_native.h" #include "wasm_runtime_common.h" #include "bh_log.h" +#if WASM_ENABLE_INTERP != 0 +#include "../interpreter/wasm_runtime.h" +#endif +#if WASM_ENABLE_AOT != 0 +#include "../aot/aot_runtime.h" +#endif +#if WASM_ENABLE_THREAD_MGR != 0 +#include "../libraries/thread-mgr/thread_manager.h" +#endif #if !defined(BH_PLATFORM_ZEPHYR) && !defined(BH_PLATFORM_ALIOS_THINGS) \ && !defined(BH_PLATFORM_OPENRTOS) && !defined(BH_PLATFORM_ESP_IDF) @@ -22,6 +31,10 @@ static NativeSymbolsList g_native_symbols_list = NULL; +#if WASM_ENABLE_LIBC_WASI != 0 +static void *g_wasi_context_key; +#endif /* WASM_ENABLE_LIBC_WASI */ + uint32 get_libc_builtin_export_apis(NativeSymbol **p_libc_builtin_apis); @@ -394,6 +407,154 @@ wasm_native_unregister_natives(const char *module_name, return false; } +#if WASM_ENABLE_MODULE_INST_CONTEXT != 0 +static uint32 +context_key_to_idx(void *key) +{ + bh_assert(key != NULL); + uint32 idx = (uint32)(uintptr_t)key; + bh_assert(idx > 0); + bh_assert(idx <= WASM_MAX_INSTANCE_CONTEXTS); + return idx - 1; +} + +static void * +context_idx_to_key(uint32 idx) +{ + bh_assert(idx < WASM_MAX_INSTANCE_CONTEXTS); + return (void *)(uintptr_t)(idx + 1); +} + +typedef void (*dtor_t)(WASMModuleInstanceCommon *, void *); +static dtor_t g_context_dtors[WASM_MAX_INSTANCE_CONTEXTS]; + +static void +dtor_noop(WASMModuleInstanceCommon *inst, void *ctx) +{} + +void * +wasm_native_create_context_key(void (*dtor)(WASMModuleInstanceCommon *inst, + void *ctx)) +{ + uint32 i; + for (i = 0; i < WASM_MAX_INSTANCE_CONTEXTS; i++) { + if (g_context_dtors[i] == NULL) { + if (dtor == NULL) { + dtor = dtor_noop; + } + g_context_dtors[i] = dtor; + return context_idx_to_key(i); + } + } + LOG_ERROR("failed to allocate instance context key"); + return NULL; +} + +void +wasm_native_destroy_context_key(void *key) +{ + uint32 idx = context_key_to_idx(key); + bh_assert(g_context_dtors[idx] != NULL); + g_context_dtors[idx] = NULL; +} + +static WASMModuleInstanceExtraCommon * +wasm_module_inst_extra_common(WASMModuleInstanceCommon *inst) +{ +#if WASM_ENABLE_INTERP != 0 + if (inst->module_type == Wasm_Module_Bytecode) { + return &((WASMModuleInstance *)inst)->e->common; + } +#endif +#if WASM_ENABLE_AOT != 0 + if (inst->module_type == Wasm_Module_AoT) { + return &((AOTModuleInstanceExtra *)((AOTModuleInstance *)inst)->e) + ->common; + } +#endif + bh_assert(false); + return NULL; +} + +void +wasm_native_set_context(WASMModuleInstanceCommon *inst, void *key, void *ctx) +{ + uint32 idx = context_key_to_idx(key); + WASMModuleInstanceExtraCommon *common = wasm_module_inst_extra_common(inst); + common->contexts[idx] = ctx; +} + +void +wasm_native_set_context_spread(WASMModuleInstanceCommon *inst, void *key, + void *ctx) +{ +#if WASM_ENABLE_THREAD_MGR != 0 + wasm_cluster_set_context(inst, key, ctx); +#else + wasm_native_set_context(inst, key, ctx); +#endif +} + +void * +wasm_native_get_context(WASMModuleInstanceCommon *inst, void *key) +{ + uint32 idx = context_key_to_idx(key); + WASMModuleInstanceExtraCommon *common = wasm_module_inst_extra_common(inst); + return common->contexts[idx]; +} + +void +wasm_native_call_context_dtors(WASMModuleInstanceCommon *inst) +{ + WASMModuleInstanceExtraCommon *common = wasm_module_inst_extra_common(inst); + uint32 i; + for (i = 0; i < WASM_MAX_INSTANCE_CONTEXTS; i++) { + dtor_t dtor = g_context_dtors[i]; + if (dtor != NULL) { + dtor(inst, common->contexts[i]); + } + } +} + +void +wasm_native_inherit_contexts(WASMModuleInstanceCommon *child, + WASMModuleInstanceCommon *parent) +{ + WASMModuleInstanceExtraCommon *parent_common = + wasm_module_inst_extra_common(parent); + WASMModuleInstanceExtraCommon *child_common = + wasm_module_inst_extra_common(child); + bh_memcpy_s(child_common->contexts, + sizeof(*child_common->contexts) * WASM_MAX_INSTANCE_CONTEXTS, + parent_common->contexts, + sizeof(*parent_common->contexts) * WASM_MAX_INSTANCE_CONTEXTS); +} +#endif /* WASM_ENABLE_MODULE_INST_CONTEXT != 0 */ + +#if WASM_ENABLE_LIBC_WASI != 0 +WASIContext * +wasm_runtime_get_wasi_ctx(WASMModuleInstanceCommon *module_inst_comm) +{ + return wasm_native_get_context(module_inst_comm, g_wasi_context_key); +} + +void +wasm_runtime_set_wasi_ctx(WASMModuleInstanceCommon *module_inst_comm, + WASIContext *wasi_ctx) +{ + wasm_native_set_context(module_inst_comm, g_wasi_context_key, wasi_ctx); +} + +static void +wasi_context_dtor(WASMModuleInstanceCommon *inst, void *ctx) +{ + if (ctx == NULL) { + return; + } + wasm_runtime_destroy_wasi(inst); +} +#endif /* end of WASM_ENABLE_LIBC_WASI */ + bool wasm_native_init() { @@ -420,6 +581,10 @@ wasm_native_init() #endif /* WASM_ENABLE_SPEC_TEST */ #if WASM_ENABLE_LIBC_WASI != 0 + g_wasi_context_key = wasm_native_create_context_key(wasi_context_dtor); + if (g_wasi_context_key == NULL) { + goto fail; + } n_native_symbols = get_libc_wasi_export_apis(&native_symbols); if (!wasm_native_register_natives("wasi_unstable", native_symbols, n_native_symbols)) @@ -507,6 +672,12 @@ wasm_native_destroy() { NativeSymbolsNode *node, *node_next; +#if WASM_ENABLE_LIBC_WASI != 0 + if (g_wasi_context_key != NULL) { + wasm_native_destroy_context_key(g_wasi_context_key); + g_wasi_context_key = NULL; + } +#endif #if WASM_ENABLE_LIB_PTHREAD != 0 lib_pthread_destroy(); #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_native.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_native.h similarity index 70% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_native.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_native.h index 4f6645d25d8..9ca5265c3ba 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_native.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_native.h @@ -68,6 +68,36 @@ bool wasm_native_unregister_natives(const char *module_name, NativeSymbol *native_symbols); +#if WASM_ENABLE_MODULE_INST_CONTEXT != 0 +struct WASMModuleInstanceCommon; + +void * +wasm_native_create_context_key( + void (*dtor)(struct WASMModuleInstanceCommon *inst, void *ctx)); + +void +wasm_native_destroy_context_key(void *key); + +void +wasm_native_set_context(struct WASMModuleInstanceCommon *inst, void *key, + void *ctx); +void +wasm_native_set_context_spread(struct WASMModuleInstanceCommon *inst, void *key, + void *ctx); +void * +wasm_native_get_context(struct WASMModuleInstanceCommon *inst, void *key); + +void +wasm_native_call_context_dtors(struct WASMModuleInstanceCommon *inst); + +void +wasm_native_inherit_contexts(struct WASMModuleInstanceCommon *child, + struct WASMModuleInstanceCommon *parent); +#else /* WASM_ENABLE_MODULE_INST_CONTEXT */ +#define wasm_native_call_context_dtors(inst) (void)(inst) +#define wasm_native_inherit_contexts(child, parent) (void)(parent) +#endif /* WASM_ENABLE_MODULE_INST_CONTEXT */ + bool wasm_native_init(); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_runtime_common.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_runtime_common.c similarity index 85% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_runtime_common.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_runtime_common.c index 452a2661b93..567e77bec40 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_runtime_common.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_runtime_common.c @@ -125,12 +125,40 @@ runtime_malloc(uint64 size, WASMModuleInstanceCommon *module_inst, return mem; } +#if WASM_ENABLE_MULTI_MODULE != 0 +/* TODO: Let loader_malloc be a general API both for AOT and WASM. */ + +#define loader_malloc(size, error_buf, error_buf_size) \ + runtime_malloc(size, NULL, error_buf, error_buf_size) + +static void +set_error_buf_v(const WASMModuleCommon *module, char *error_buf, + uint32 error_buf_size, const char *format, ...) +{ + va_list args; + char buf[128]; + if (error_buf != NULL) { + va_start(args, format); + vsnprintf(buf, sizeof(buf), format, args); + va_end(args); + if (module->module_type == Wasm_Module_AoT) { + snprintf(error_buf, error_buf_size, "AOT module load failed: %s", + buf); + } + else if (module->module_type == Wasm_Module_Bytecode) { + snprintf(error_buf, error_buf_size, "WASM module load failed: %s", + buf); + } + } +} +#endif + #if WASM_ENABLE_FAST_JIT != 0 static JitCompOptions jit_options = { 0 }; #endif #if WASM_ENABLE_JIT != 0 -static LLVMJITOptions llvm_jit_options = { 3, 3 }; +static LLVMJITOptions llvm_jit_options = { 3, 3, 0, false }; #endif static RunningMode runtime_running_mode = Mode_Default; @@ -199,7 +227,90 @@ runtime_signal_handler(void *sig_addr) } } } -#else +#else /* else of BH_PLATFORM_WINDOWS */ + +#if WASM_ENABLE_AOT != 0 +#include + +static uint32 +decode_insn(uint8 *insn) +{ + uint8 *data = (uint8 *)insn; + uint32 length = 32; /* reserve enough size */ + + /* Initialize decoder context */ + ZydisDecoder decoder; + ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_64, + ZYDIS_STACK_WIDTH_64); + + /* Initialize formatter */ + ZydisFormatter formatter; + ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL); + + /* Loop over the instructions in our buffer */ + ZyanU64 runtime_address = (ZyanU64)(uintptr_t)data; + ZyanUSize offset = 0; + ZydisDecodedInstruction instruction; + ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT_VISIBLE]; + char buffer[256]; + + if (ZYAN_SUCCESS(ZydisDecoderDecodeFull( + &decoder, data + offset, length - offset, &instruction, operands, + ZYDIS_MAX_OPERAND_COUNT_VISIBLE, + ZYDIS_DFLAG_VISIBLE_OPERANDS_ONLY))) { + + /* Format & print the binary instruction structure to + human readable format */ + ZydisFormatterFormatInstruction(&formatter, &instruction, operands, + instruction.operand_count_visible, + buffer, sizeof(buffer), + runtime_address); + + /* Print current instruction */ + /* + os_printf("%012" PRIX64 " ", runtime_address); + puts(buffer); + */ + + return instruction.length; + } + + /* Decode failed */ + return 0; +} +#endif /* end of WASM_ENABLE_AOT != 0 */ + +static LONG +next_action(WASMModuleInstance *module_inst, EXCEPTION_POINTERS *exce_info) +{ +#if WASM_ENABLE_AOT != 0 + uint32 insn_size; +#endif + + if (module_inst->module_type == Wasm_Module_Bytecode + && module_inst->e->running_mode == Mode_Interp) { + /* Continue to search next exception handler for + interpreter mode as it can be caught by + `__try { .. } __except { .. }` sentences in + wasm_runtime.c */ + return EXCEPTION_CONTINUE_SEARCH; + } + +#if WASM_ENABLE_AOT != 0 + /* Skip current instruction and continue to run for AOT/JIT mode. + TODO: implement unwind support for AOT/JIT code in Windows platform */ + insn_size = decode_insn((uint8 *)exce_info->ContextRecord->Rip); + if (insn_size > 0) { + exce_info->ContextRecord->Rip += insn_size; + return EXCEPTION_CONTINUE_EXECUTION; + } +#endif + + /* return different value from EXCEPTION_CONTINUE_SEARCH (= 0) + and EXCEPTION_CONTINUE_EXECUTION (= -1) */ + return -2; +} + static LONG runtime_exception_handler(EXCEPTION_POINTERS *exce_info) { @@ -211,6 +322,7 @@ runtime_exception_handler(EXCEPTION_POINTERS *exce_info) uint8 *mapped_mem_start_addr = NULL; uint8 *mapped_mem_end_addr = NULL; uint32 page_size = os_getpagesize(); + LONG ret; if (exec_env_tls && exec_env_tls->handle == os_self_thread() && (jmpbuf_node = exec_env_tls->jmpbuf_stack_top)) { @@ -232,32 +344,19 @@ runtime_exception_handler(EXCEPTION_POINTERS *exce_info) the wasm func returns, the caller will check whether the exception is thrown and return to runtime. */ wasm_set_exception(module_inst, "out of bounds memory access"); - if (module_inst->module_type == Wasm_Module_Bytecode) { - /* Continue to search next exception handler for - interpreter mode as it can be caught by - `__try { .. } __except { .. }` sentences in - wasm_runtime.c */ - return EXCEPTION_CONTINUE_SEARCH; - } - else { - /* Skip current instruction and continue to run for - AOT mode. TODO: implement unwind support for AOT - code in Windows platform */ - exce_info->ContextRecord->Rip++; - return EXCEPTION_CONTINUE_EXECUTION; - } + ret = next_action(module_inst, exce_info); + if (ret == EXCEPTION_CONTINUE_SEARCH + || ret == EXCEPTION_CONTINUE_EXECUTION) + return ret; } else if (exec_env_tls->exce_check_guard_page <= (uint8 *)sig_addr && (uint8 *)sig_addr < exec_env_tls->exce_check_guard_page + page_size) { bh_assert(wasm_copy_exception(module_inst, NULL)); - if (module_inst->module_type == Wasm_Module_Bytecode) { - return EXCEPTION_CONTINUE_SEARCH; - } - else { - exce_info->ContextRecord->Rip++; - return EXCEPTION_CONTINUE_EXECUTION; - } + ret = next_action(module_inst, exce_info); + if (ret == EXCEPTION_CONTINUE_SEARCH + || ret == EXCEPTION_CONTINUE_EXECUTION) + return ret; } } #if WASM_DISABLE_STACK_HW_BOUND_CHECK == 0 @@ -267,12 +366,10 @@ runtime_exception_handler(EXCEPTION_POINTERS *exce_info) whether the exception is thrown and return to runtime, and the damaged stack will be recovered by _resetstkoflw(). */ wasm_set_exception(module_inst, "native stack overflow"); - if (module_inst->module_type == Wasm_Module_Bytecode) { - return EXCEPTION_CONTINUE_SEARCH; - } - else { - return EXCEPTION_CONTINUE_EXECUTION; - } + ret = next_action(module_inst, exce_info); + if (ret == EXCEPTION_CONTINUE_SEARCH + || ret == EXCEPTION_CONTINUE_EXECUTION) + return ret; } #endif } @@ -388,8 +485,21 @@ wasm_runtime_env_init() } #endif +#if WASM_ENABLE_THREAD_MGR != 0 && defined(OS_ENABLE_WAKEUP_BLOCKING_OP) + if (os_blocking_op_init() != BHT_OK) { + goto fail11; + } + os_end_blocking_op(); +#endif + return true; +#if WASM_ENABLE_THREAD_MGR != 0 && defined(OS_ENABLE_WAKEUP_BLOCKING_OP) +fail11: +#if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0 + aot_compiler_destroy(); +#endif +#endif #if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0 fail10: #if WASM_ENABLE_FAST_JIT != 0 @@ -552,8 +662,14 @@ wasm_runtime_full_init(RuntimeInitArgs *init_args) #endif #if WASM_ENABLE_JIT != 0 + LOG_DEBUG("Start LLVM_JIT, opt_sz=%u, opt_lvl=%u, segue=%s, linux_perf=%s", + init_args->llvm_jit_size_level, init_args->llvm_jit_opt_level, + init_args->segue_flags ? "Yes" : "No", + init_args->linux_perf_support ? "Yes" : "No"); llvm_jit_options.size_level = init_args->llvm_jit_size_level; llvm_jit_options.opt_level = init_args->llvm_jit_opt_level; + llvm_jit_options.segue_flags = init_args->segue_flags; + llvm_jit_options.linux_perf_support = init_args->linux_perf_support; #endif if (!wasm_runtime_env_init()) { @@ -1115,27 +1231,34 @@ wasm_runtime_load(uint8 *buf, uint32 size, char *error_buf, if (get_package_type(buf, size) == Wasm_Module_Bytecode) { #if WASM_ENABLE_INTERP != 0 module_common = - (WASMModuleCommon *)wasm_load(buf, size, error_buf, error_buf_size); - return register_module_with_null_name(module_common, error_buf, - error_buf_size); + (WASMModuleCommon *)wasm_load(buf, size, +#if WASM_ENABLE_MULTI_MODULE != 0 + true, +#endif + error_buf, error_buf_size); #endif } else if (get_package_type(buf, size) == Wasm_Module_AoT) { #if WASM_ENABLE_AOT != 0 module_common = (WASMModuleCommon *)aot_load_from_aot_file( buf, size, error_buf, error_buf_size); - return register_module_with_null_name(module_common, error_buf, - error_buf_size); #endif } - - if (size < 4) - set_error_buf(error_buf, error_buf_size, - "WASM module load failed: unexpected end"); - else - set_error_buf(error_buf, error_buf_size, - "WASM module load failed: magic header not detected"); - return NULL; + else { + if (size < 4) + set_error_buf(error_buf, error_buf_size, + "WASM module load failed: unexpected end"); + else + set_error_buf(error_buf, error_buf_size, + "WASM module load failed: magic header not detected"); + return NULL; + } + if (!module_common) { + LOG_DEBUG("WASM module load failed"); + return NULL; + } + return register_module_with_null_name(module_common, error_buf, + error_buf_size); } WASMModuleCommon * @@ -1148,6 +1271,10 @@ wasm_runtime_load_from_sections(WASMSection *section_list, bool is_aot, #if WASM_ENABLE_INTERP != 0 module_common = (WASMModuleCommon *)wasm_load_from_sections( section_list, error_buf, error_buf_size); + if (!module_common) { + LOG_DEBUG("WASM module load failed from sections"); + return NULL; + } return register_module_with_null_name(module_common, error_buf, error_buf_size); #endif @@ -1156,6 +1283,10 @@ wasm_runtime_load_from_sections(WASMSection *section_list, bool is_aot, #if WASM_ENABLE_AOT != 0 module_common = (WASMModuleCommon *)aot_load_from_sections( section_list, error_buf, error_buf_size); + if (!module_common) { + LOG_DEBUG("WASM module load failed from sections"); + return NULL; + } return register_module_with_null_name(module_common, error_buf, error_buf_size); #endif @@ -1195,7 +1326,8 @@ wasm_runtime_unload(WASMModuleCommon *module) } WASMModuleInstanceCommon * -wasm_runtime_instantiate_internal(WASMModuleCommon *module, bool is_sub_inst, +wasm_runtime_instantiate_internal(WASMModuleCommon *module, + WASMModuleInstanceCommon *parent, WASMExecEnv *exec_env_main, uint32 stack_size, uint32 heap_size, char *error_buf, uint32 error_buf_size) @@ -1203,14 +1335,14 @@ wasm_runtime_instantiate_internal(WASMModuleCommon *module, bool is_sub_inst, #if WASM_ENABLE_INTERP != 0 if (module->module_type == Wasm_Module_Bytecode) return (WASMModuleInstanceCommon *)wasm_instantiate( - (WASMModule *)module, is_sub_inst, exec_env_main, stack_size, - heap_size, error_buf, error_buf_size); + (WASMModule *)module, (WASMModuleInstance *)parent, exec_env_main, + stack_size, heap_size, error_buf, error_buf_size); #endif #if WASM_ENABLE_AOT != 0 if (module->module_type == Wasm_Module_AoT) return (WASMModuleInstanceCommon *)aot_instantiate( - (AOTModule *)module, is_sub_inst, exec_env_main, stack_size, - heap_size, error_buf, error_buf_size); + (AOTModule *)module, (AOTModuleInstance *)parent, exec_env_main, + stack_size, heap_size, error_buf, error_buf_size); #endif set_error_buf(error_buf, error_buf_size, "Instantiate module failed, invalid module type"); @@ -1223,7 +1355,7 @@ wasm_runtime_instantiate(WASMModuleCommon *module, uint32 stack_size, uint32 error_buf_size) { return wasm_runtime_instantiate_internal( - module, false, NULL, stack_size, heap_size, error_buf, error_buf_size); + module, NULL, NULL, stack_size, heap_size, error_buf, error_buf_size); } void @@ -1321,6 +1453,10 @@ wasm_runtime_init_thread_env(void) } #endif +#if WASM_ENABLE_THREAD_MGR != 0 && defined(OS_ENABLE_WAKEUP_BLOCKING_OP) + os_end_blocking_op(); +#endif + return true; } @@ -1867,33 +2003,6 @@ wasm_runtime_finalize_call_function(WASMExecEnv *exec_env, } #endif -static bool -clear_wasi_proc_exit_exception(WASMModuleInstanceCommon *module_inst_comm) -{ -#if WASM_ENABLE_LIBC_WASI != 0 - bool has_exception; - char exception[EXCEPTION_BUF_LEN]; - WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_comm; - - bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode - || module_inst_comm->module_type == Wasm_Module_AoT); - - has_exception = wasm_copy_exception(module_inst, exception); - if (has_exception && !strcmp(exception, "Exception: wasi proc exit")) { - /* The "wasi proc exit" exception is thrown by native lib to - let wasm app exit, which is a normal behavior, we clear - the exception here. And just clear the exception of current - thread, don't call `wasm_set_exception(module_inst, NULL)` - which will clear the exception of all threads. */ - module_inst->cur_exception[0] = '\0'; - return true; - } - return false; -#else - return false; -#endif -} - bool wasm_runtime_call_wasm(WASMExecEnv *exec_env, WASMFunctionInstanceCommon *function, uint32 argc, @@ -1934,15 +2043,10 @@ wasm_runtime_call_wasm(WASMExecEnv *exec_env, param_argc, new_argv); #endif if (!ret) { - if (clear_wasi_proc_exit_exception(exec_env->module_inst)) { - ret = true; - } - else { - if (new_argv != argv) { - wasm_runtime_free(new_argv); - } - return false; + if (new_argv != argv) { + wasm_runtime_free(new_argv); } + return false; } #if WASM_ENABLE_REF_TYPES != 0 @@ -2303,17 +2407,10 @@ wasm_runtime_get_exec_env_singleton(WASMModuleInstanceCommon *module_inst_comm) return module_inst->exec_env_singleton; } -void -wasm_set_exception(WASMModuleInstance *module_inst, const char *exception) +static void +wasm_set_exception_local(WASMModuleInstance *module_inst, const char *exception) { - WASMExecEnv *exec_env = NULL; - -#if WASM_ENABLE_SHARED_MEMORY != 0 - WASMSharedMemNode *node = - wasm_module_get_shared_memory((WASMModuleCommon *)module_inst->module); - if (node) - os_mutex_lock(&node->shared_mem_lock); -#endif + exception_lock(module_inst); if (exception) { snprintf(module_inst->cur_exception, sizeof(module_inst->cur_exception), "Exception: %s", exception); @@ -2321,19 +2418,23 @@ wasm_set_exception(WASMModuleInstance *module_inst, const char *exception) else { module_inst->cur_exception[0] = '\0'; } -#if WASM_ENABLE_SHARED_MEMORY != 0 - if (node) - os_mutex_unlock(&node->shared_mem_lock); -#endif + exception_unlock(module_inst); +} +void +wasm_set_exception(WASMModuleInstance *module_inst, const char *exception) +{ #if WASM_ENABLE_THREAD_MGR != 0 - exec_env = + WASMExecEnv *exec_env = wasm_clusters_search_exec_env((WASMModuleInstanceCommon *)module_inst); if (exec_env) { - wasm_cluster_spread_exception(exec_env, exception ? false : true); + wasm_cluster_set_exception(exec_env, exception); + } + else { + wasm_set_exception_local(module_inst, exception); } #else - (void)exec_env; + wasm_set_exception_local(module_inst, exception); #endif } @@ -2384,12 +2485,7 @@ wasm_copy_exception(WASMModuleInstance *module_inst, char *exception_buf) { bool has_exception = false; -#if WASM_ENABLE_SHARED_MEMORY != 0 - WASMSharedMemNode *node = - wasm_module_get_shared_memory((WASMModuleCommon *)module_inst->module); - if (node) - os_mutex_lock(&node->shared_mem_lock); -#endif + exception_lock(module_inst); if (module_inst->cur_exception[0] != '\0') { /* NULL is passed if the caller is not interested in getting the * exception content, but only in knowing if an exception has been @@ -2401,10 +2497,7 @@ wasm_copy_exception(WASMModuleInstance *module_inst, char *exception_buf) sizeof(module_inst->cur_exception)); has_exception = true; } -#if WASM_ENABLE_SHARED_MEMORY != 0 - if (node) - os_mutex_unlock(&node->shared_mem_lock); -#endif + exception_unlock(module_inst); return has_exception; } @@ -2449,6 +2542,18 @@ wasm_runtime_clear_exception(WASMModuleInstanceCommon *module_inst_comm) wasm_runtime_set_exception(module_inst_comm, NULL); } +#if WASM_ENABLE_THREAD_MGR != 0 +void +wasm_runtime_terminate(WASMModuleInstanceCommon *module_inst_comm) +{ + WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_comm; + + bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode + || module_inst_comm->module_type == Wasm_Module_AoT); + wasm_set_exception(module_inst, "terminated by user"); +} +#endif + void wasm_runtime_set_custom_data_internal( WASMModuleInstanceCommon *module_inst_comm, void *custom_data) @@ -2481,6 +2586,54 @@ wasm_runtime_get_custom_data(WASMModuleInstanceCommon *module_inst_comm) return module_inst->custom_data; } +#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0 +void +wasm_runtime_set_bounds_checks(WASMModuleInstanceCommon *module_inst, + bool enable) +{ + /* Alwary disable bounds checks if hw bounds checks enabled */ +#ifdef OS_ENABLE_HW_BOUND_CHECK + enable = false; +#endif +#if WASM_ENABLE_INTERP != 0 + if (module_inst->module_type == Wasm_Module_Bytecode) { + ((WASMModuleInstanceExtra *)((WASMModuleInstance *)module_inst)->e) + ->common.disable_bounds_checks = enable ? false : true; + } +#endif + +#if WASM_ENABLE_AOT != 0 + if (module_inst->module_type == Wasm_Module_AoT) { + ((AOTModuleInstanceExtra *)((AOTModuleInstance *)module_inst)->e) + ->common.disable_bounds_checks = enable ? false : true; + } +#endif +} + +bool +wasm_runtime_is_bounds_checks_enabled(WASMModuleInstanceCommon *module_inst) +{ + +#if WASM_ENABLE_INTERP != 0 + if (module_inst->module_type == Wasm_Module_Bytecode) { + return !((WASMModuleInstanceExtra *)((WASMModuleInstance *)module_inst) + ->e) + ->common.disable_bounds_checks; + } +#endif + +#if WASM_ENABLE_AOT != 0 + if (module_inst->module_type == Wasm_Module_AoT) { + return !((AOTModuleInstanceExtra *)((WASMModuleInstance *)module_inst) + ->e) + ->common.disable_bounds_checks; + } +#endif + + return true; +} +#endif + uint32 wasm_runtime_module_malloc_internal(WASMModuleInstanceCommon *module_inst, WASMExecEnv *exec_env, uint32 size, @@ -2630,7 +2783,7 @@ wasm_runtime_set_wasi_args_ex(WASMModuleCommon *module, const char *dir_list[], uint32 dir_count, const char *map_dir_list[], uint32 map_dir_count, const char *env_list[], uint32 env_count, char *argv[], int argc, - int stdinfd, int stdoutfd, int stderrfd) + int64 stdinfd, int64 stdoutfd, int64 stderrfd) { WASIArguments *wasi_args = get_wasi_args_from_module(module); @@ -2644,9 +2797,9 @@ wasm_runtime_set_wasi_args_ex(WASMModuleCommon *module, const char *dir_list[], wasi_args->env_count = env_count; wasi_args->argv = argv; wasi_args->argc = (uint32)argc; - wasi_args->stdio[0] = stdinfd; - wasi_args->stdio[1] = stdoutfd; - wasi_args->stdio[2] = stderrfd; + wasi_args->stdio[0] = (os_raw_file_handle)stdinfd; + wasi_args->stdio[1] = (os_raw_file_handle)stdoutfd; + wasi_args->stdio[2] = (os_raw_file_handle)stderrfd; #if WASM_ENABLE_MULTI_MODULE != 0 #if WASM_ENABLE_INTERP != 0 @@ -2741,8 +2894,9 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst, const char *env[], uint32 env_count, const char *addr_pool[], uint32 addr_pool_size, const char *ns_lookup_pool[], uint32 ns_lookup_pool_size, - char *argv[], uint32 argc, int stdinfd, int stdoutfd, - int stderrfd, char *error_buf, uint32 error_buf_size) + char *argv[], uint32 argc, os_raw_file_handle stdinfd, + os_raw_file_handle stdoutfd, os_raw_file_handle stderrfd, + char *error_buf, uint32 error_buf_size) { WASIContext *wasi_ctx; char *argv_buf = NULL; @@ -2760,7 +2914,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst, bool argv_environ_inited = false; bool addr_pool_inited = false; __wasi_fd_t wasm_fd = 3; - int32 raw_fd; + os_file_handle file_handle; char *path, resolved_path[PATH_MAX]; uint32 i; @@ -2830,15 +2984,19 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst, } addr_pool_inited = true; - /* Prepopulate curfds with stdin, stdout, and stderr file descriptors. - * - * If -1 is given, use STDIN_FILENO (0), STDOUT_FILENO (1), - * STDERR_FILENO (2) respectively. - */ - if (!fd_table_insert_existing(curfds, 0, (stdinfd != -1) ? stdinfd : 0) - || !fd_table_insert_existing(curfds, 1, (stdoutfd != -1) ? stdoutfd : 1) - || !fd_table_insert_existing(curfds, 2, - (stderrfd != -1) ? stderrfd : 2)) { + os_file_handle stdin_file_handle = os_convert_stdin_handle(stdinfd); + os_file_handle stdout_file_handle = os_convert_stdout_handle(stdoutfd); + os_file_handle stderr_file_handle = os_convert_stderr_handle(stderrfd); + + if (!os_is_handle_valid(&stdin_file_handle) + || !os_is_handle_valid(&stdout_file_handle) + || !os_is_handle_valid(&stderr_file_handle)) + goto fail; + + /* Prepopulate curfds with stdin, stdout, and stderr file descriptors. */ + if (!fd_table_insert_existing(curfds, 0, stdin_file_handle, true) + || !fd_table_insert_existing(curfds, 1, stdout_file_handle, true) + || !fd_table_insert_existing(curfds, 2, stderr_file_handle, true)) { set_error_buf(error_buf, error_buf_size, "Init wasi environment failed: init fd table failed"); goto fail; @@ -2846,7 +3004,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst, wasm_fd = 3; for (i = 0; i < dir_count; i++, wasm_fd++) { - path = realpath(dir_list[i], resolved_path); + path = os_realpath(dir_list[i], resolved_path); if (!path) { if (error_buf) snprintf(error_buf, error_buf_size, @@ -2855,17 +3013,101 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst, goto fail; } - raw_fd = open(path, O_RDONLY | O_DIRECTORY, 0); - if (raw_fd == -1) { + __wasi_errno_t error = os_open_preopendir(path, &file_handle); + + if (error != __WASI_ESUCCESS) { if (error_buf) snprintf(error_buf, error_buf_size, "error while pre-opening directory %s: %d\n", - dir_list[i], errno); + dir_list[i], error); goto fail; } - fd_table_insert_existing(curfds, wasm_fd, raw_fd); - fd_prestats_insert(prestats, dir_list[i], wasm_fd); + if (!fd_table_insert_existing(curfds, wasm_fd, file_handle, false)) { + if (error_buf) + snprintf(error_buf, error_buf_size, + "error inserting preopen fd %u (directory %s) into fd " + "table", + (unsigned int)wasm_fd, dir_list[i]); + goto fail; + } + + if (!fd_prestats_insert(prestats, dir_list[i], wasm_fd)) { + if (error_buf) + snprintf(error_buf, error_buf_size, + "error inserting preopen fd %u (directory %s) into " + "prestats table", + (unsigned int)wasm_fd, dir_list[i]); + goto fail; + } + } + + for (i = 0; i < map_dir_count; i++, wasm_fd++) { + char mapping_copy_buf[256]; + char *mapping_copy = mapping_copy_buf; + char *map_mapped = NULL, *map_host = NULL; + const unsigned long max_len = strlen(map_dir_list[i]) * 2 + 3; + + /* Allocation limit for runtime environments with reduced stack size */ + if (max_len > 256) { + if (!(mapping_copy = wasm_runtime_malloc(max_len))) { + snprintf(error_buf, error_buf_size, + "error while allocating for directory mapping\n"); + goto fail; + } + } + + bh_memcpy_s(mapping_copy, max_len, map_dir_list[i], + (uint32)(strlen(map_dir_list[i]) + 1)); + map_mapped = strtok(mapping_copy, "::"); + map_host = strtok(NULL, "::"); + + if (!map_mapped || !map_host) { + if (error_buf) + snprintf(error_buf, error_buf_size, + "error while pre-opening mapped directory: " + "invalid map\n"); + if (mapping_copy != mapping_copy_buf) + wasm_runtime_free(mapping_copy); + goto fail; + } + + path = os_realpath(map_host, resolved_path); + if (!path) { + if (error_buf) + snprintf(error_buf, error_buf_size, + "error while pre-opening mapped directory %s: %d\n", + map_host, errno); + if (mapping_copy != mapping_copy_buf) + wasm_runtime_free(mapping_copy); + goto fail; + } + + __wasi_errno_t error = os_open_preopendir(path, &file_handle); + if (error != __WASI_ESUCCESS) { + if (error_buf) + snprintf(error_buf, error_buf_size, + "error while pre-opening mapped directory %s: %d\n", + map_host, errno); + if (mapping_copy != mapping_copy_buf) + wasm_runtime_free(mapping_copy); + goto fail; + } + + if (!fd_table_insert_existing(curfds, wasm_fd, file_handle, false) + || !fd_prestats_insert(prestats, map_mapped, wasm_fd)) { + if (error_buf) + snprintf(error_buf, error_buf_size, + "error while pre-opening mapped directory %s: " + "insertion failed\n", + dir_list[i]); + if (mapping_copy != mapping_copy_buf) + wasm_runtime_free(mapping_copy); + goto fail; + } + + if (mapping_copy != mapping_copy_buf) + wasm_runtime_free(mapping_copy); } /* addr_pool(textual) -> apool */ @@ -2993,8 +3235,9 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst, const char *env[], uint32 env_count, const char *addr_pool[], uint32 addr_pool_size, const char *ns_lookup_pool[], uint32 ns_lookup_pool_size, - char *argv[], uint32 argc, int stdinfd, int stdoutfd, - int stderrfd, char *error_buf, uint32 error_buf_size) + char *argv[], uint32 argc, os_raw_file_handle stdinfd, + os_raw_file_handle stdoutfd, os_raw_file_handle stderrfd, + char *error_buf, uint32 error_buf_size) { WASIContext *ctx; uvwasi_t *uvwasi; @@ -3212,27 +3455,6 @@ wasm_runtime_get_wasi_exit_code(WASMModuleInstanceCommon *module_inst) #endif return wasi_ctx->exit_code; } - -WASIContext * -wasm_runtime_get_wasi_ctx(WASMModuleInstanceCommon *module_inst_comm) -{ - WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_comm; - - bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode - || module_inst_comm->module_type == Wasm_Module_AoT); - return module_inst->wasi_ctx; -} - -void -wasm_runtime_set_wasi_ctx(WASMModuleInstanceCommon *module_inst_comm, - WASIContext *wasi_ctx) -{ - WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_comm; - - bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode - || module_inst_comm->module_type == Wasm_Module_AoT); - module_inst->wasi_ctx = wasi_ctx; -} #endif /* end of WASM_ENABLE_LIBC_WASI */ WASMModuleCommon * @@ -3801,16 +4023,14 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr, if (n_stacks & 1) n_stacks++; if (func_type->types[i] == VALUE_TYPE_F32) { - *(float32 *)&stacks[n_stacks] = *(float32 *)argv_src++; - /* NaN boxing, the upper bits of a valid NaN-boxed - value must be all 1s. */ - stacks[n_stacks + 1] = 0xFFFFFFFF; + *(float32 *)&stacks[n_stacks++] = + *(float32 *)argv_src++; } else { *(float64 *)&stacks[n_stacks] = *(float64 *)argv_src; argv_src += 2; + n_stacks += 2; } - n_stacks += 2; } break; } @@ -4212,6 +4432,14 @@ static V128FuncPtr invokeNative_V128 = (V128FuncPtr)(uintptr_t)invokeNative; || defined(BUILD_TARGET_RISCV64_LP64) */ #endif /* end of defined(_WIN32) || defined(_WIN32_) */ +/* + * ASAN is not designed to work with custom stack unwind or other low-level + * things. Ignore a function that does some low-level magic. (e.g. walking + * through the thread's stack bypassing the frame boundaries) + */ +#if defined(__GNUC__) || defined(__clang__) +__attribute__((no_sanitize_address)) +#endif bool wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr, const WASMType *func_type, const char *signature, @@ -4489,10 +4717,6 @@ wasm_runtime_call_indirect(WASMExecEnv *exec_env, uint32 element_index, ret = aot_call_indirect(exec_env, 0, element_index, argc, argv); #endif - if (!ret && clear_wasi_proc_exit_exception(exec_env->module_inst)) { - ret = true; - } - return ret; } @@ -4629,6 +4853,8 @@ typedef struct ExternRefMapNode { bool retained; /* Whether it is marked by runtime */ bool marked; + /* cleanup function called when the externref is freed */ + void (*cleanup)(void *); } ExternRefMapNode; static uint32 @@ -4691,6 +4917,81 @@ lookup_extobj_callback(void *key, void *value, void *user_data) } } +static void +delete_externref(void *key, ExternRefMapNode *node) +{ + bh_hash_map_remove(externref_map, key, NULL, NULL); + if (node->cleanup) { + (*node->cleanup)(node->extern_obj); + } + wasm_runtime_free(node); +} + +static void +delete_extobj_callback(void *key, void *value, void *user_data) +{ + ExternRefMapNode *node = (ExternRefMapNode *)value; + LookupExtObj_UserData *lookup_user_data = + (LookupExtObj_UserData *)user_data; + + if (node->extern_obj == lookup_user_data->node.extern_obj + && node->module_inst == lookup_user_data->node.module_inst) { + lookup_user_data->found = true; + delete_externref(key, node); + } +} + +bool +wasm_externref_objdel(WASMModuleInstanceCommon *module_inst, void *extern_obj) +{ + LookupExtObj_UserData lookup_user_data = { 0 }; + bool ok = false; + + /* in a wrapper, extern_obj could be any value */ + lookup_user_data.node.extern_obj = extern_obj; + lookup_user_data.node.module_inst = module_inst; + lookup_user_data.found = false; + + os_mutex_lock(&externref_lock); + /* Lookup hashmap firstly */ + bh_hash_map_traverse(externref_map, delete_extobj_callback, + (void *)&lookup_user_data); + if (lookup_user_data.found) { + ok = true; + } + os_mutex_unlock(&externref_lock); + + return ok; +} + +bool +wasm_externref_set_cleanup(WASMModuleInstanceCommon *module_inst, + void *extern_obj, void (*extern_obj_cleanup)(void *)) +{ + + LookupExtObj_UserData lookup_user_data = { 0 }; + bool ok = false; + + /* in a wrapper, extern_obj could be any value */ + lookup_user_data.node.extern_obj = extern_obj; + lookup_user_data.node.module_inst = module_inst; + lookup_user_data.found = false; + + os_mutex_lock(&externref_lock); + /* Lookup hashmap firstly */ + bh_hash_map_traverse(externref_map, lookup_extobj_callback, + (void *)&lookup_user_data); + if (lookup_user_data.found) { + void *key = (void *)(uintptr_t)lookup_user_data.externref_idx; + ExternRefMapNode *node = bh_hash_map_find(externref_map, key); + node->cleanup = extern_obj_cleanup; + ok = true; + } + os_mutex_unlock(&externref_lock); + + return ok; +} + bool wasm_externref_obj2ref(WASMModuleInstanceCommon *module_inst, void *extern_obj, uint32 *p_externref_idx) @@ -4740,6 +5041,7 @@ wasm_externref_obj2ref(WASMModuleInstanceCommon *module_inst, void *extern_obj, memset(node, 0, sizeof(ExternRefMapNode)); node->extern_obj = extern_obj; node->module_inst = module_inst; + node->cleanup = NULL; externref_idx = externref_global_id; @@ -4790,8 +5092,7 @@ reclaim_extobj_callback(void *key, void *value, void *user_data) if (node->module_inst == module_inst) { if (!node->marked && !node->retained) { - bh_hash_map_remove(externref_map, key, NULL, NULL); - wasm_runtime_free(value); + delete_externref(key, node); } else { node->marked = false; @@ -4906,8 +5207,7 @@ cleanup_extobj_callback(void *key, void *value, void *user_data) (WASMModuleInstanceCommon *)user_data; if (node->module_inst == module_inst) { - bh_hash_map_remove(externref_map, key, NULL, NULL); - wasm_runtime_free(value); + delete_externref(key, node); } } @@ -5026,6 +5326,33 @@ wasm_runtime_dump_call_stack_to_buf(wasm_exec_env_t exec_env, char *buf, } #endif /* end of WASM_ENABLE_DUMP_CALL_STACK */ +#if WASM_ENABLE_STATIC_PGO != 0 +uint32 +wasm_runtime_get_pgo_prof_data_size(WASMModuleInstanceCommon *module_inst) +{ +#if WASM_ENABLE_AOT != 0 + if (module_inst->module_type == Wasm_Module_AoT) { + AOTModuleInstance *aot_inst = (AOTModuleInstance *)module_inst; + return aot_get_pgo_prof_data_size(aot_inst); + } +#endif + return 0; +} + +uint32 +wasm_runtime_dump_pgo_prof_data_to_buf(WASMModuleInstanceCommon *module_inst, + char *buf, uint32 len) +{ +#if WASM_ENABLE_AOT != 0 + if (module_inst->module_type == Wasm_Module_AoT) { + AOTModuleInstance *aot_inst = (AOTModuleInstance *)module_inst; + return aot_dump_pgo_prof_data_to_buf(aot_inst, buf, len); + } +#endif + return 0; +} +#endif /* end of WASM_ENABLE_STATIC_PGO != 0 */ + bool wasm_runtime_get_table_elem_type(const WASMModuleCommon *module_comm, uint32 table_idx, uint8 *out_elem_type, @@ -5473,3 +5800,345 @@ wasm_runtime_is_import_global_linked(const char *module_name, return false; #endif } + +#if WASM_ENABLE_LIBC_WASI != 0 || WASM_ENABLE_MULTI_MODULE != 0 +WASMExport * +loader_find_export(const WASMModuleCommon *module, const char *module_name, + const char *field_name, uint8 export_kind, char *error_buf, + uint32 error_buf_size) +{ + WASMExport *exports = NULL, *result = NULL, *export; + uint32 export_count = 0, i; +#if WASM_ENABLE_AOT != 0 + if (module->module_type == Wasm_Module_AoT) { + AOTModule *aot_module = (AOTModule *)module; + exports = (WASMExport *)aot_module->exports; + export_count = aot_module->export_count; + } +#endif +#if WASM_ENABLE_INTERP != 0 + if (module->module_type == Wasm_Module_Bytecode) { + WASMModule *wasm_module = (WASMModule *)module; + exports = wasm_module->exports; + export_count = wasm_module->export_count; + } +#endif + for (i = 0, export = exports; i < export_count; ++i, ++export) { + if (export->kind == export_kind && !strcmp(field_name, export->name)) { + result = export; + goto exit; + } + } + if (i == export_count) { + LOG_DEBUG("can not find an export %d named %s in the module %s", + export_kind, field_name, module_name); + set_error_buf(error_buf, error_buf_size, + "unknown import or incompatible import type"); + } +exit: + return result; +} +#endif + +#if WASM_ENABLE_MULTI_MODULE != 0 +WASMModuleCommon * +wasm_runtime_search_sub_module(const WASMModuleCommon *parent_module, + const char *sub_module_name) +{ + WASMRegisteredModule *node = NULL; +#if WASM_ENABLE_AOT != 0 + if (parent_module->module_type == Wasm_Module_AoT) { + node = bh_list_first_elem( + ((AOTModule *)parent_module)->import_module_list); + } +#endif +#if WASM_ENABLE_INTERP != 0 + if (parent_module->module_type == Wasm_Module_Bytecode) { + node = bh_list_first_elem( + ((WASMModule *)parent_module)->import_module_list); + } +#endif + while (node && strcmp(sub_module_name, node->module_name)) { + node = bh_list_elem_next(node); + } + return node ? node->module : NULL; +} + +bool +wasm_runtime_register_sub_module(const WASMModuleCommon *parent_module, + const char *sub_module_name, + WASMModuleCommon *sub_module) +{ + /* register sub_module into its parent sub module list */ + WASMRegisteredModule *node = NULL; + bh_list_status ret = BH_LIST_ERROR; + + if (wasm_runtime_search_sub_module(parent_module, sub_module_name)) { + LOG_DEBUG("%s has been registered in its parent", sub_module_name); + return true; + } + + node = loader_malloc(sizeof(WASMRegisteredModule), NULL, 0); + if (!node) { + return false; + } + + node->module_name = sub_module_name; + node->module = sub_module; +#if WASM_ENABLE_AOT != 0 + if (parent_module->module_type == Wasm_Module_AoT) { + ret = bh_list_insert(((AOTModule *)parent_module)->import_module_list, + node); + } +#endif +#if WASM_ENABLE_INTERP != 0 + if (parent_module->module_type == Wasm_Module_Bytecode) { + ret = bh_list_insert(((WASMModule *)parent_module)->import_module_list, + node); + } +#endif + bh_assert(BH_LIST_SUCCESS == ret); + (void)ret; + return true; +} + +WASMModuleCommon * +wasm_runtime_load_depended_module(const WASMModuleCommon *parent_module, + const char *sub_module_name, char *error_buf, + uint32 error_buf_size) +{ + WASMModuleCommon *sub_module = NULL; + bool ret = false; + uint8 *buffer = NULL; + uint32 buffer_size = 0; + + /* check the registered module list of the parent */ + sub_module = wasm_runtime_search_sub_module(parent_module, sub_module_name); + if (sub_module) { + LOG_DEBUG("%s has been loaded before", sub_module_name); + return sub_module; + } + + /* check the global registered module list */ + sub_module = wasm_runtime_find_module_registered(sub_module_name); + if (sub_module) { + LOG_DEBUG("%s has been loaded", sub_module_name); + goto wasm_runtime_register_sub_module; + } + LOG_VERBOSE("loading %s", sub_module_name); + if (!reader) { + set_error_buf_v(parent_module, error_buf, error_buf_size, + "no sub module reader to load %s", sub_module_name); + return NULL; + } + /* start to maintain a loading module list */ + ret = wasm_runtime_is_loading_module(sub_module_name); + if (ret) { + set_error_buf_v(parent_module, error_buf, error_buf_size, + "found circular dependency on %s", sub_module_name); + return NULL; + } + ret = wasm_runtime_add_loading_module(sub_module_name, error_buf, + error_buf_size); + if (!ret) { + LOG_DEBUG("can not add %s into loading module list\n", sub_module_name); + return NULL; + } + + ret = reader(parent_module->module_type, sub_module_name, &buffer, + &buffer_size); + if (!ret) { + LOG_DEBUG("read the file of %s failed", sub_module_name); + set_error_buf_v(parent_module, error_buf, error_buf_size, + "unknown import", sub_module_name); + goto delete_loading_module; + } + if (get_package_type(buffer, buffer_size) != parent_module->module_type) { + LOG_DEBUG("moudle %s type error", sub_module_name); + goto delete_loading_module; + } + if (get_package_type(buffer, buffer_size) == Wasm_Module_Bytecode) { +#if WASM_ENABLE_INTERP != 0 + sub_module = (WASMModuleCommon *)wasm_load(buffer, buffer_size, false, + error_buf, error_buf_size); +#endif + } + else if (get_package_type(buffer, buffer_size) == Wasm_Module_AoT) { +#if WASM_ENABLE_AOT != 0 + sub_module = (WASMModuleCommon *)aot_load_from_aot_file( + buffer, buffer_size, error_buf, error_buf_size); +#endif + } + if (!sub_module) { + LOG_DEBUG("error: can not load the sub_module %s", sub_module_name); + /* others will be destroyed in runtime_destroy() */ + goto destroy_file_buffer; + } + wasm_runtime_delete_loading_module(sub_module_name); + /* register on a global list */ + ret = wasm_runtime_register_module_internal( + sub_module_name, (WASMModuleCommon *)sub_module, buffer, buffer_size, + error_buf, error_buf_size); + if (!ret) { + LOG_DEBUG("error: can not register module %s globally\n", + sub_module_name); + /* others will be unloaded in runtime_destroy() */ + goto unload_module; + } + + /* register into its parent list */ +wasm_runtime_register_sub_module: + ret = wasm_runtime_register_sub_module(parent_module, sub_module_name, + sub_module); + if (!ret) { + set_error_buf_v(parent_module, error_buf, error_buf_size, + "failed to register sub module %s", sub_module_name); + /* since it is in the global module list, no need to + * unload the module. the runtime_destroy() will do it + */ + return NULL; + } + + return sub_module; + +unload_module: + wasm_runtime_unload(sub_module); + +destroy_file_buffer: + if (destroyer) { + destroyer(buffer, buffer_size); + } + else { + LOG_WARNING("need to release the reading buffer of %s manually", + sub_module_name); + } + +delete_loading_module: + wasm_runtime_delete_loading_module(sub_module_name); + return NULL; +} + +bool +wasm_runtime_sub_module_instantiate(WASMModuleCommon *module, + WASMModuleInstanceCommon *module_inst, + uint32 stack_size, uint32 heap_size, + char *error_buf, uint32 error_buf_size) +{ + bh_list *sub_module_inst_list = NULL; + WASMRegisteredModule *sub_module_list_node = NULL; + +#if WASM_ENABLE_AOT != 0 + if (module->module_type == Wasm_Module_AoT) { + sub_module_inst_list = + ((AOTModuleInstanceExtra *)((AOTModuleInstance *)module_inst)->e) + ->sub_module_inst_list; + sub_module_list_node = + bh_list_first_elem(((AOTModule *)module)->import_module_list); + } +#endif +#if WASM_ENABLE_INTERP != 0 + if (module->module_type == Wasm_Module_Bytecode) { + sub_module_inst_list = + ((WASMModuleInstanceExtra *)((WASMModuleInstance *)module_inst)->e) + ->sub_module_inst_list; + sub_module_list_node = + bh_list_first_elem(((WASMModule *)module)->import_module_list); + } +#endif + while (sub_module_list_node) { + WASMSubModInstNode *sub_module_inst_list_node = NULL; + WASMModuleCommon *sub_module = sub_module_list_node->module; + WASMModuleInstanceCommon *sub_module_inst = NULL; + sub_module_inst = wasm_runtime_instantiate_internal( + sub_module, NULL, NULL, stack_size, heap_size, error_buf, + error_buf_size); + if (!sub_module_inst) { + LOG_DEBUG("instantiate %s failed", + sub_module_list_node->module_name); + return false; + } + sub_module_inst_list_node = loader_malloc(sizeof(WASMSubModInstNode), + error_buf, error_buf_size); + if (!sub_module_inst_list_node) { + LOG_DEBUG("Malloc WASMSubModInstNode failed, SZ:%d", + sizeof(WASMSubModInstNode)); + if (sub_module_inst) + wasm_runtime_deinstantiate_internal(sub_module_inst, false); + return false; + } + sub_module_inst_list_node->module_inst = + (WASMModuleInstance *)sub_module_inst; + sub_module_inst_list_node->module_name = + sub_module_list_node->module_name; + bh_list_status ret = + bh_list_insert(sub_module_inst_list, sub_module_inst_list_node); + bh_assert(BH_LIST_SUCCESS == ret); + (void)ret; + sub_module_list_node = bh_list_elem_next(sub_module_list_node); + } + + return true; +} + +void +wasm_runtime_sub_module_deinstantiate(WASMModuleInstanceCommon *module_inst) +{ + bh_list *list = NULL; +#if WASM_ENABLE_AOT != 0 + if (module_inst->module_type == Wasm_Module_AoT) { + list = ((AOTModuleInstanceExtra *)((AOTModuleInstance *)module_inst)->e) + ->sub_module_inst_list; + } +#endif +#if WASM_ENABLE_INTERP != 0 + if (module_inst->module_type == Wasm_Module_Bytecode) { + list = + ((WASMModuleInstanceExtra *)((WASMModuleInstance *)module_inst)->e) + ->sub_module_inst_list; + } +#endif + + WASMSubModInstNode *node = bh_list_first_elem(list); + while (node) { + WASMSubModInstNode *next_node = bh_list_elem_next(node); + bh_list_remove(list, node); + wasm_runtime_deinstantiate_internal( + (WASMModuleInstanceCommon *)node->module_inst, false); + wasm_runtime_free(node); + node = next_node; + } +} +#endif /* end of WASM_ENABLE_MULTI_MODULE */ +#if WASM_ENABLE_MODULE_INST_CONTEXT != 0 +void * +wasm_runtime_create_context_key(void (*dtor)(WASMModuleInstanceCommon *inst, + void *ctx)) +{ + return wasm_native_create_context_key(dtor); +} + +void +wasm_runtime_destroy_context_key(void *key) +{ + wasm_native_destroy_context_key(key); +} + +void +wasm_runtime_set_context(WASMModuleInstanceCommon *inst, void *key, void *ctx) +{ + wasm_native_set_context(inst, key, ctx); +} + +void +wasm_runtime_set_context_spread(WASMModuleInstanceCommon *inst, void *key, + void *ctx) +{ + wasm_native_set_context_spread(inst, key, ctx); +} + +void * +wasm_runtime_get_context(WASMModuleInstanceCommon *inst, void *key) +{ + return wasm_native_get_context(inst, key); +} +#endif /* WASM_ENABLE_MODULE_INST_CONTEXT != 0 */ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_runtime_common.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_runtime_common.h similarity index 87% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_runtime_common.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_runtime_common.h index 00d5ba23714..2908cafb5f8 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_runtime_common.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_runtime_common.h @@ -12,9 +12,9 @@ #include "wasm_native.h" #include "../include/wasm_export.h" #include "../interpreter/wasm.h" + #if WASM_ENABLE_LIBC_WASI != 0 #if WASM_ENABLE_UVWASI == 0 -#include "wasmtime_ssp.h" #include "posix.h" #else #include "uvwasi.h" @@ -44,15 +44,16 @@ extern "C" { /* For STORE opcodes */ #define STORE_I64 PUT_I64_TO_ADDR -#define STORE_U32(addr, value) \ - do { \ - *(uint32 *)(addr) = (uint32)(value); \ - } while (0) -#define STORE_U16(addr, value) \ - do { \ - *(uint16 *)(addr) = (uint16)(value); \ - } while (0) - +static inline void +STORE_U32(void *addr, uint32_t value) +{ + *(uint32_t *)(addr) = (uint32_t)(value); +} +static inline void +STORE_U16(void *addr, uint16_t value) +{ + *(uint16_t *)(addr) = (uint16_t)(value); +} /* For LOAD opcodes */ #define LOAD_I64(addr) (*(int64 *)(addr)) #define LOAD_F64(addr) (*(float64 *)(addr)) @@ -147,42 +148,42 @@ GET_F64_FROM_ADDR(uint32 *addr) } \ } while (0) -#define STORE_U32(addr, value) \ - do { \ - uintptr_t addr_ = (uintptr_t)(addr); \ - union { \ - uint32 val; \ - uint16 u16[2]; \ - uint8 u8[4]; \ - } u; \ - if ((addr_ & (uintptr_t)3) == 0) \ - *(uint32 *)(addr) = (uint32)(value); \ - else { \ - u.val = (uint32)(value); \ - if ((addr_ & (uintptr_t)1) == 0) { \ - ((uint16 *)(addr))[0] = u.u16[0]; \ - ((uint16 *)(addr))[1] = u.u16[1]; \ - } \ - else { \ - ((uint8 *)(addr))[0] = u.u8[0]; \ - ((uint8 *)(addr))[1] = u.u8[1]; \ - ((uint8 *)(addr))[2] = u.u8[2]; \ - ((uint8 *)(addr))[3] = u.u8[3]; \ - } \ - } \ - } while (0) - -#define STORE_U16(addr, value) \ - do { \ - union { \ - uint16 val; \ - uint8 u8[2]; \ - } u; \ - u.val = (uint16)(value); \ - ((uint8 *)(addr))[0] = u.u8[0]; \ - ((uint8 *)(addr))[1] = u.u8[1]; \ - } while (0) - +static inline void +STORE_U32(void *addr, uint32_t value) +{ + uintptr_t addr_ = (uintptr_t)(addr); + union { + uint32_t val; + uint16_t u16[2]; + uint8_t u8[4]; + } u; + if ((addr_ & (uintptr_t)3) == 0) + *(uint32_t *)(addr) = (uint32_t)(value); + else { + u.val = (uint32_t)(value); + if ((addr_ & (uintptr_t)1) == 0) { + ((uint16_t *)(addr))[0] = u.u16[0]; + ((uint16_t *)(addr))[1] = u.u16[1]; + } + else { + ((uint8_t *)(addr))[0] = u.u8[0]; + ((uint8_t *)(addr))[1] = u.u8[1]; + ((uint8_t *)(addr))[2] = u.u8[2]; + ((uint8_t *)(addr))[3] = u.u8[3]; + } + } +} +static inline void +STORE_U16(void *addr, uint16_t value) +{ + union { + uint16_t val; + uint8_t u8[2]; + } u; + u.val = (uint16_t)(value); + ((uint8_t *)(addr))[0] = u.u8[0]; + ((uint8_t *)(addr))[1] = u.u8[1]; +} /* For LOAD opcodes */ static inline int64 LOAD_I64(void *addr) @@ -298,6 +299,14 @@ LOAD_I16(void *addr) #endif /* WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 */ +#if WASM_ENABLE_SHARED_MEMORY != 0 +#define SHARED_MEMORY_LOCK(memory) shared_memory_lock(memory) +#define SHARED_MEMORY_UNLOCK(memory) shared_memory_unlock(memory) +#else +#define SHARED_MEMORY_LOCK(memory) (void)0 +#define SHARED_MEMORY_UNLOCK(memory) (void)0 +#endif + typedef struct WASMModuleCommon { /* Module type, for module loaded from WASM bytecode binary, this field is Wasm_Module_Bytecode, and this structure should @@ -420,6 +429,8 @@ typedef struct wasm_frame_t { typedef struct LLVMJITOptions { uint32 opt_level; uint32 size_level; + uint32 segue_flags; + bool linux_perf_support; } LLVMJITOptions; #endif @@ -497,7 +508,8 @@ wasm_runtime_unload(WASMModuleCommon *module); /* Internal API */ WASMModuleInstanceCommon * -wasm_runtime_instantiate_internal(WASMModuleCommon *module, bool is_sub_inst, +wasm_runtime_instantiate_internal(WASMModuleCommon *module, + WASMModuleInstanceCommon *parent, WASMExecEnv *exec_env_main, uint32 stack_size, uint32 heap_size, char *error_buf, uint32 error_buf_size); @@ -592,6 +604,17 @@ wasm_runtime_set_user_data(WASMExecEnv *exec_env, void *user_data); WASM_RUNTIME_API_EXTERN void * wasm_runtime_get_user_data(WASMExecEnv *exec_env); +#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0 +/* See wasm_export.h for description */ +WASM_RUNTIME_API_EXTERN void +wasm_runtime_set_bounds_checks(WASMModuleInstanceCommon *module_inst, + bool enable); + +/* See wasm_export.h for description */ +WASM_RUNTIME_API_EXTERN bool +wasm_runtime_is_bounds_checks_enabled(WASMModuleInstanceCommon *module_inst); +#endif + #ifdef OS_ENABLE_HW_BOUND_CHECK /* Access exception check guard page to trigger the signal handler */ void @@ -662,6 +685,10 @@ wasm_runtime_get_exception(WASMModuleInstanceCommon *module); WASM_RUNTIME_API_EXTERN void wasm_runtime_clear_exception(WASMModuleInstanceCommon *module_inst); +/* See wasm_export.h for description */ +WASM_RUNTIME_API_EXTERN void +wasm_runtime_terminate(WASMModuleInstanceCommon *module); + /* Internal API */ void wasm_runtime_set_custom_data_internal(WASMModuleInstanceCommon *module_inst, @@ -771,6 +798,9 @@ wasm_runtime_register_module_internal(const char *module_name, void wasm_runtime_unregister_module(const WASMModuleCommon *module); +WASMModuleCommon * +wasm_runtime_find_module_registered(const char *module_name); + bool wasm_runtime_add_loading_module(const char *module_name, char *error_buf, uint32 error_buf_size); @@ -783,6 +813,35 @@ wasm_runtime_is_loading_module(const char *module_name); void wasm_runtime_destroy_loading_module_list(); + +WASMModuleCommon * +wasm_runtime_search_sub_module(const WASMModuleCommon *parent_module, + const char *sub_module_name); + +bool +wasm_runtime_register_sub_module(const WASMModuleCommon *parent_module, + const char *sub_module_name, + WASMModuleCommon *sub_module); + +WASMModuleCommon * +wasm_runtime_load_depended_module(const WASMModuleCommon *parent_module, + const char *sub_module_name, char *error_buf, + uint32 error_buf_size); + +bool +wasm_runtime_sub_module_instantiate(WASMModuleCommon *module, + WASMModuleInstanceCommon *module_inst, + uint32 stack_size, uint32 heap_size, + char *error_buf, uint32 error_buf_size); +void +wasm_runtime_sub_module_deinstantiate(WASMModuleInstanceCommon *module_inst); +#endif + +#if WASM_ENABLE_LIBC_WASI != 0 || WASM_ENABLE_MULTI_MODULE != 0 +WASMExport * +loader_find_export(const WASMModuleCommon *module, const char *module_name, + const char *field_name, uint8 export_kind, char *error_buf, + uint32 error_buf_size); #endif /* WASM_ENALBE_MULTI_MODULE */ bool @@ -804,7 +863,7 @@ wasm_runtime_set_wasi_args_ex(WASMModuleCommon *module, const char *dir_list[], uint32 dir_count, const char *map_dir_list[], uint32 map_dir_count, const char *env_list[], uint32 env_count, char *argv[], int argc, - int stdinfd, int stdoutfd, int stderrfd); + int64 stdinfd, int64 stdoutfd, int64 stderrfd); /* See wasm_export.h for description */ WASM_RUNTIME_API_EXTERN void @@ -832,8 +891,9 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst, const char *env[], uint32 env_count, const char *addr_pool[], uint32 addr_pool_size, const char *ns_lookup_pool[], uint32 ns_lookup_pool_size, - char *argv[], uint32 argc, int stdinfd, int stdoutfd, - int stderrfd, char *error_buf, uint32 error_buf_size); + char *argv[], uint32 argc, os_raw_file_handle stdinfd, + os_raw_file_handle stdoutfd, os_raw_file_handle stderrfd, + char *error_buf, uint32 error_buf_size); void wasm_runtime_destroy_wasi(WASMModuleInstanceCommon *module_inst); @@ -926,6 +986,26 @@ WASM_RUNTIME_API_EXTERN bool wasm_runtime_unregister_natives(const char *module_name, NativeSymbol *native_symbols); +/* See wasm_export.h for description */ +WASM_RUNTIME_API_EXTERN void * +wasm_runtime_create_context_key(void (*dtor)(WASMModuleInstanceCommon *inst, + void *ctx)); + +/* See wasm_export.h for description */ +WASM_RUNTIME_API_EXTERN void +wasm_runtime_destroy_context_key(void *key); + +/* See wasm_export.h for description */ +WASM_RUNTIME_API_EXTERN void +wasm_runtime_set_context(WASMModuleInstanceCommon *inst, void *key, void *ctx); +/* See wasm_export.h for description */ +WASM_RUNTIME_API_EXTERN void +wasm_runtime_set_context_spread(WASMModuleInstanceCommon *inst, void *key, + void *ctx); +/* See wasm_export.h for description */ +WASM_RUNTIME_API_EXTERN void * +wasm_runtime_get_context(WASMModuleInstanceCommon *inst, void *key); + bool wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr, const WASMType *func_type, const char *signature, @@ -1003,6 +1083,15 @@ WASM_RUNTIME_API_EXTERN bool wasm_runtime_is_import_global_linked(const char *module_name, const char *global_name); +WASM_RUNTIME_API_EXTERN bool +wasm_runtime_begin_blocking_op(WASMExecEnv *exec_env); + +WASM_RUNTIME_API_EXTERN void +wasm_runtime_end_blocking_op(WASMExecEnv *exec_env); + +void +wasm_runtime_interrupt_blocking_op(WASMExecEnv *exec_env); + #ifdef __cplusplus } #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_shared_memory.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_shared_memory.c similarity index 71% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_shared_memory.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_shared_memory.c index 54fc8200f0b..70e84a37504 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/wasm_shared_memory.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_shared_memory.c @@ -9,9 +9,16 @@ #include "../libraries/thread-mgr/thread_manager.h" #endif -static bh_list shared_memory_list_head; -static bh_list *const shared_memory_list = &shared_memory_list_head; -static korp_mutex shared_memory_list_lock; +/* + * Note: this lock can be per memory. + * + * For now, just use a global because: + * - it's a bit cumbersome to extend WASMMemoryInstance w/o breaking + * the AOT ABI. + * - If you care performance, it's better to make the interpreters + * use atomic ops. + */ +korp_mutex g_shared_memory_lock; /* clang-format off */ enum { @@ -37,7 +44,7 @@ typedef struct AtomicWaitNode { static HashMap *wait_map; static uint32 -wait_address_hash(void *address); +wait_address_hash(const void *address); static bool wait_address_equal(void *h1, void *h2); @@ -48,17 +55,15 @@ destroy_wait_info(void *wait_info); bool wasm_shared_memory_init() { - if (os_mutex_init(&shared_memory_list_lock) != 0) + if (os_mutex_init(&g_shared_memory_lock) != 0) return false; - /* wait map not exists, create new map */ if (!(wait_map = bh_hash_map_create(32, true, (HashFunc)wait_address_hash, (KeyEqualFunc)wait_address_equal, NULL, destroy_wait_info))) { - os_mutex_destroy(&shared_memory_list_lock); + os_mutex_destroy(&g_shared_memory_lock); return false; } - return true; } @@ -66,115 +71,52 @@ void wasm_shared_memory_destroy() { bh_hash_map_destroy(wait_map); - os_mutex_destroy(&shared_memory_list_lock); -} - -static WASMSharedMemNode * -search_module(WASMModuleCommon *module) -{ - WASMSharedMemNode *node; - - os_mutex_lock(&shared_memory_list_lock); - node = bh_list_first_elem(shared_memory_list); - - while (node) { - if (module == node->module) { - os_mutex_unlock(&shared_memory_list_lock); - return node; - } - node = bh_list_elem_next(node); - } - - os_mutex_unlock(&shared_memory_list_lock); - return NULL; -} - -WASMSharedMemNode * -wasm_module_get_shared_memory(WASMModuleCommon *module) -{ - return search_module(module); -} - -int32 -shared_memory_inc_reference(WASMModuleCommon *module) -{ - WASMSharedMemNode *node = search_module(module); - uint32 ref_count = -1; - if (node) { - os_mutex_lock(&node->lock); - ref_count = ++node->ref_count; - os_mutex_unlock(&node->lock); - } - return ref_count; + os_mutex_destroy(&g_shared_memory_lock); } -int32 -shared_memory_dec_reference(WASMModuleCommon *module) +uint16 +shared_memory_inc_reference(WASMMemoryInstance *memory) { - WASMSharedMemNode *node = search_module(module); - uint32 ref_count = 0; - if (node) { - os_mutex_lock(&node->lock); - ref_count = --node->ref_count; - os_mutex_unlock(&node->lock); - if (ref_count == 0) { - os_mutex_lock(&shared_memory_list_lock); - bh_list_remove(shared_memory_list, node); - os_mutex_unlock(&shared_memory_list_lock); - - os_mutex_destroy(&node->shared_mem_lock); - os_mutex_destroy(&node->lock); - wasm_runtime_free(node); - } - return ref_count; - } - - return -1; + bh_assert(shared_memory_is_shared(memory)); + uint16 old; +#if BH_ATOMIC_16_IS_ATOMIC == 0 + os_mutex_lock(&g_shared_memory_lock); +#endif + old = BH_ATOMIC_16_FETCH_ADD(memory->ref_count, 1); +#if BH_ATOMIC_16_IS_ATOMIC == 0 + os_mutex_unlock(&g_shared_memory_lock); +#endif + bh_assert(old >= 1); + bh_assert(old < UINT16_MAX); + return old + 1; } -WASMMemoryInstanceCommon * -shared_memory_get_memory_inst(WASMSharedMemNode *node) +uint16 +shared_memory_dec_reference(WASMMemoryInstance *memory) { - return node->memory_inst; + bh_assert(shared_memory_is_shared(memory)); + uint16 old; +#if BH_ATOMIC_16_IS_ATOMIC == 0 + os_mutex_lock(&g_shared_memory_lock); +#endif + old = BH_ATOMIC_16_FETCH_SUB(memory->ref_count, 1); +#if BH_ATOMIC_16_IS_ATOMIC == 0 + os_mutex_unlock(&g_shared_memory_lock); +#endif + bh_assert(old > 0); + return old - 1; } -WASMSharedMemNode * -shared_memory_set_memory_inst(WASMModuleCommon *module, - WASMMemoryInstanceCommon *memory) +static korp_mutex * +shared_memory_get_lock_pointer(WASMMemoryInstance *memory) { - WASMSharedMemNode *node; - bh_list_status ret; - - if (!(node = wasm_runtime_malloc(sizeof(WASMSharedMemNode)))) - return NULL; - - node->module = module; - node->memory_inst = memory; - node->ref_count = 1; - - if (os_mutex_init(&node->shared_mem_lock) != 0) { - wasm_runtime_free(node); - return NULL; - } - - if (os_mutex_init(&node->lock) != 0) { - os_mutex_destroy(&node->shared_mem_lock); - wasm_runtime_free(node); - return NULL; - } - - os_mutex_lock(&shared_memory_list_lock); - ret = bh_list_insert(shared_memory_list, node); - bh_assert(ret == BH_LIST_SUCCESS); - os_mutex_unlock(&shared_memory_list_lock); - - (void)ret; - return node; + bh_assert(memory != NULL); + return &g_shared_memory_lock; } /* Atomics wait && notify APIs */ static uint32 -wait_address_hash(void *address) +wait_address_hash(const void *address) { return (uint32)(uintptr_t)address; } @@ -307,7 +249,7 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address, WASMModuleInstance *module_inst = (WASMModuleInstance *)module; AtomicWaitInfo *wait_info; AtomicWaitNode *wait_node; - WASMSharedMemNode *node; + korp_mutex *lock; #if WASM_ENABLE_THREAD_MGR != 0 WASMExecEnv *exec_env; #endif @@ -322,17 +264,20 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address, } /* Currently we have only one memory instance */ - if (!module_inst->memories[0]->is_shared) { + if (!shared_memory_is_shared(module_inst->memories[0])) { wasm_runtime_set_exception(module, "expected shared memory"); return -1; } + shared_memory_lock(module_inst->memories[0]); if ((uint8 *)address < module_inst->memories[0]->memory_data || (uint8 *)address + (wait64 ? 8 : 4) > module_inst->memories[0]->memory_data_end) { + shared_memory_unlock(module_inst->memories[0]); wasm_runtime_set_exception(module, "out of bounds memory access"); return -1; } + shared_memory_unlock(module_inst->memories[0]); #if WASM_ENABLE_THREAD_MGR != 0 exec_env = @@ -340,30 +285,29 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address, bh_assert(exec_env); #endif - node = search_module((WASMModuleCommon *)module_inst->module); - bh_assert(node); + lock = shared_memory_get_lock_pointer(module_inst->memories[0]); /* Lock the shared_mem_lock for the whole atomic wait process, and use it to os_cond_reltimedwait */ - os_mutex_lock(&node->shared_mem_lock); + os_mutex_lock(lock); no_wait = (!wait64 && *(uint32 *)address != (uint32)expect) || (wait64 && *(uint64 *)address != expect); if (no_wait) { - os_mutex_unlock(&node->shared_mem_lock); + os_mutex_unlock(lock); return 1; } if (!(wait_node = wasm_runtime_malloc(sizeof(AtomicWaitNode)))) { - os_mutex_unlock(&node->shared_mem_lock); + os_mutex_unlock(lock); wasm_runtime_set_exception(module, "failed to create wait node"); return -1; } memset(wait_node, 0, sizeof(AtomicWaitNode)); if (0 != os_cond_init(&wait_node->wait_cond)) { - os_mutex_unlock(&node->shared_mem_lock); + os_mutex_unlock(lock); wasm_runtime_free(wait_node); wasm_runtime_set_exception(module, "failed to init wait cond"); return -1; @@ -375,7 +319,7 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address, wait_info = acquire_wait_info(address, wait_node); if (!wait_info) { - os_mutex_unlock(&node->shared_mem_lock); + os_mutex_unlock(lock); os_cond_destroy(&wait_node->wait_cond); wasm_runtime_free(wait_node); wasm_runtime_set_exception(module, "failed to acquire wait_info"); @@ -390,7 +334,7 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address, if (timeout < 0) { /* wait forever until it is notified or terminatied here we keep waiting and checking every second */ - os_cond_reltimedwait(&wait_node->wait_cond, &node->shared_mem_lock, + os_cond_reltimedwait(&wait_node->wait_cond, lock, (uint64)timeout_1sec); if (wait_node->status == S_NOTIFIED /* notified by atomic.notify */ #if WASM_ENABLE_THREAD_MGR != 0 @@ -404,8 +348,7 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address, else { timeout_wait = timeout_left < timeout_1sec ? timeout_left : timeout_1sec; - os_cond_reltimedwait(&wait_node->wait_cond, &node->shared_mem_lock, - timeout_wait); + os_cond_reltimedwait(&wait_node->wait_cond, lock, timeout_wait); if (wait_node->status == S_NOTIFIED /* notified by atomic.notify */ || timeout_left <= timeout_wait /* time out */ #if WASM_ENABLE_THREAD_MGR != 0 @@ -433,7 +376,7 @@ wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address, /* Release wait info if no wait nodes are attached */ map_try_release_wait_info(wait_map, wait_info, address); - os_mutex_unlock(&node->shared_mem_lock); + os_mutex_unlock(lock); return is_timeout ? 2 : 0; } @@ -445,15 +388,17 @@ wasm_runtime_atomic_notify(WASMModuleInstanceCommon *module, void *address, WASMModuleInstance *module_inst = (WASMModuleInstance *)module; uint32 notify_result; AtomicWaitInfo *wait_info; - WASMSharedMemNode *node; + korp_mutex *lock; bool out_of_bounds; bh_assert(module->module_type == Wasm_Module_Bytecode || module->module_type == Wasm_Module_AoT); + shared_memory_lock(module_inst->memories[0]); out_of_bounds = ((uint8 *)address < module_inst->memories[0]->memory_data || (uint8 *)address + 4 > module_inst->memories[0]->memory_data_end); + shared_memory_unlock(module_inst->memories[0]); if (out_of_bounds) { wasm_runtime_set_exception(module, "out of bounds memory access"); @@ -461,31 +406,30 @@ wasm_runtime_atomic_notify(WASMModuleInstanceCommon *module, void *address, } /* Currently we have only one memory instance */ - if (!module_inst->memories[0]->is_shared) { + if (!shared_memory_is_shared(module_inst->memories[0])) { /* Always return 0 for ushared linear memory since there is no way to create a waiter on it */ return 0; } - node = search_module((WASMModuleCommon *)module_inst->module); - bh_assert(node); + lock = shared_memory_get_lock_pointer(module_inst->memories[0]); /* Lock the shared_mem_lock for the whole atomic notify process, and use it to os_cond_signal */ - os_mutex_lock(&node->shared_mem_lock); + os_mutex_lock(lock); wait_info = acquire_wait_info(address, NULL); /* Nobody wait on this address */ if (!wait_info) { - os_mutex_unlock(&node->shared_mem_lock); + os_mutex_unlock(lock); return 0; } /* Notify each wait node in the wait list */ notify_result = notify_wait_list(wait_info->wait_list, count); - os_mutex_unlock(&node->shared_mem_lock); + os_mutex_unlock(lock); return notify_result; } diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_shared_memory.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_shared_memory.h new file mode 100644 index 00000000000..8bbc4a80045 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_shared_memory.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#ifndef _WASM_SHARED_MEMORY_H +#define _WASM_SHARED_MEMORY_H + +#include "bh_common.h" +#include "../interpreter/wasm_runtime.h" +#include "wasm_runtime_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern korp_mutex g_shared_memory_lock; + +bool +wasm_shared_memory_init(); + +void +wasm_shared_memory_destroy(); + +uint16 +shared_memory_inc_reference(WASMMemoryInstance *memory); + +uint16 +shared_memory_dec_reference(WASMMemoryInstance *memory); + +#define shared_memory_is_shared(memory) memory->is_shared_memory + +#define shared_memory_lock(memory) \ + do { \ + /* \ + * Note: exception logic is currently abusing this lock. \ + * cf. \ + * https://github.com/bytecodealliance/wasm-micro-runtime/issues/2407 \ + */ \ + bh_assert(memory != NULL); \ + if (memory->is_shared_memory) \ + os_mutex_lock(&g_shared_memory_lock); \ + } while (0) + +#define shared_memory_unlock(memory) \ + do { \ + if (memory->is_shared_memory) \ + os_mutex_unlock(&g_shared_memory_lock); \ + } while (0) + +uint32 +wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address, + uint64 expect, int64 timeout, bool wait64); + +uint32 +wasm_runtime_atomic_notify(WASMModuleInstanceCommon *module, void *address, + uint32 count); + +#ifdef __cplusplus +} +#endif + +#endif /* end of _WASM_SHARED_MEMORY_H */ diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_suspend_flags.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_suspend_flags.h new file mode 100644 index 00000000000..b182b2b5f00 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/common/wasm_suspend_flags.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2023 Amazon Inc. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#ifndef _WASM_SUSPEND_FLAGS_H +#define _WASM_SUSPEND_FLAGS_H + +#include "bh_atomic.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Need to terminate */ +#define WASM_SUSPEND_FLAG_TERMINATE 0x1 +/* Need to suspend */ +#define WASM_SUSPEND_FLAG_SUSPEND 0x2 +/* Need to go into breakpoint */ +#define WASM_SUSPEND_FLAG_BREAKPOINT 0x4 +/* Return from pthread_exit */ +#define WASM_SUSPEND_FLAG_EXIT 0x8 +/* The thread might be blocking */ +#define WASM_SUSPEND_FLAG_BLOCKING 0x10 + +typedef union WASMSuspendFlags { + bh_atomic_32_t flags; + uintptr_t __padding__; +} WASMSuspendFlags; + +#define WASM_SUSPEND_FLAGS_IS_ATOMIC BH_ATOMIC_32_IS_ATOMIC +#define WASM_SUSPEND_FLAGS_GET(s_flags) BH_ATOMIC_32_LOAD(s_flags.flags) +#define WASM_SUSPEND_FLAGS_FETCH_OR(s_flags, val) \ + BH_ATOMIC_32_FETCH_OR(s_flags.flags, val) +#define WASM_SUSPEND_FLAGS_FETCH_AND(s_flags, val) \ + BH_ATOMIC_32_FETCH_AND(s_flags.flags, val) + +#if WASM_SUSPEND_FLAGS_IS_ATOMIC != 0 +#define WASM_SUSPEND_FLAGS_LOCK(lock) (void)0 +#define WASM_SUSPEND_FLAGS_UNLOCK(lock) (void)0 +#else /* else of WASM_SUSPEND_FLAGS_IS_ATOMIC */ +#define WASM_SUSPEND_FLAGS_LOCK(lock) os_mutex_lock(&lock) +#define WASM_SUSPEND_FLAGS_UNLOCK(lock) os_mutex_unlock(&lock); +#endif /* WASM_SUSPEND_FLAGS_IS_ATOMIC */ + +#ifdef __cplusplus +} +#endif + +#endif /* end of _WASM_SUSPEND_FLAGS_H */ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot.c similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot.c index e836df28fb9..8162d006e10 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot.c @@ -129,7 +129,6 @@ aot_create_table_init_data_list(const WASMModule *module) data_list[i]->mode = module->table_segments[i].mode; data_list[i]->elem_type = module->table_segments[i].elem_type; /* runtime control it */ - data_list[i]->is_dropped = false; data_list[i]->table_index = module->table_segments[i].table_index; bh_memcpy_s(&data_list[i]->offset, sizeof(AOTInitExpr), &module->table_segments[i].base_offset, diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot.h similarity index 92% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot.h index c67251a6ff6..4bee70f9cea 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot.h @@ -19,12 +19,31 @@ extern "C" { #define AOT_FUNC_PREFIX "aot_func#" #endif +#ifndef AOT_FUNC_INTERNAL_PREFIX +#define AOT_FUNC_INTERNAL_PREFIX "aot_func_internal#" +#endif + +#ifndef AOT_STACK_SIZES_NAME +#define AOT_STACK_SIZES_NAME "aot_stack_sizes" +#endif +extern const char *aot_stack_sizes_name; + +#ifndef AOT_STACK_SIZES_ALIAS_NAME +#define AOT_STACK_SIZES_ALIAS_NAME "aot_stack_sizes_alias" +#endif +extern const char *aot_stack_sizes_alias_name; + +#ifndef AOT_STACK_SIZES_SECTION_NAME +#define AOT_STACK_SIZES_SECTION_NAME ".aot_stack_sizes" +#endif +extern const char *aot_stack_sizes_section_name; + typedef InitializerExpression AOTInitExpr; typedef WASMType AOTFuncType; typedef WASMExport AOTExport; #if WASM_ENABLE_DEBUG_AOT != 0 -typedef void *dwar_extractor_handle_t; +typedef void *dwarf_extractor_handle_t; #endif typedef enum AOTIntCond { @@ -124,7 +143,6 @@ typedef struct AOTTableInitData { uint32 mode; /* funcref or externref, elemkind will be considered as funcref */ uint32 elem_type; - bool is_dropped; /* optional, only for active */ uint32 table_index; /* Start address of init data */ @@ -266,7 +284,7 @@ typedef struct AOTCompData { WASMModule *wasm_module; #if WASM_ENABLE_DEBUG_AOT != 0 - dwar_extractor_handle_t extractor; + dwarf_extractor_handle_t extractor; #endif } AOTCompData; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_compiler.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_compiler.c similarity index 96% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_compiler.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_compiler.c index 06235fe3173..464ca61f321 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_compiler.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_compiler.c @@ -2617,64 +2617,6 @@ verify_module(AOTCompContext *comp_ctx) return true; } -/* Check whether the target supports hardware atomic instructions */ -static bool -aot_require_lower_atomic_pass(AOTCompContext *comp_ctx) -{ - bool ret = false; - if (!strncmp(comp_ctx->target_arch, "riscv", 5)) { - char *feature = - LLVMGetTargetMachineFeatureString(comp_ctx->target_machine); - - if (feature) { - if (!strstr(feature, "+a")) { - ret = true; - } - LLVMDisposeMessage(feature); - } - } - return ret; -} - -/* Check whether the target needs to expand switch to if/else */ -static bool -aot_require_lower_switch_pass(AOTCompContext *comp_ctx) -{ - bool ret = false; - - /* IR switch/case will cause .rodata relocation on riscv/xtensa */ - if (!strncmp(comp_ctx->target_arch, "riscv", 5) - || !strncmp(comp_ctx->target_arch, "xtensa", 6)) { - ret = true; - } - - return ret; -} - -static bool -apply_passes_for_indirect_mode(AOTCompContext *comp_ctx) -{ - LLVMPassManagerRef common_pass_mgr; - - if (!(common_pass_mgr = LLVMCreatePassManager())) { - aot_set_last_error("create pass manager failed"); - return false; - } - - aot_add_expand_memory_op_pass(common_pass_mgr); - - if (aot_require_lower_atomic_pass(comp_ctx)) - LLVMAddLowerAtomicPass(common_pass_mgr); - - if (aot_require_lower_switch_pass(comp_ctx)) - LLVMAddLowerSwitchPass(common_pass_mgr); - - LLVMRunPassManager(common_pass_mgr, comp_ctx->module); - - LLVMDisposePassManager(common_pass_mgr); - return true; -} - bool aot_compile_wasm(AOTCompContext *comp_ctx) { @@ -2714,17 +2656,6 @@ aot_compile_wasm(AOTCompContext *comp_ctx) possible core dump. */ bh_print_time("Begin to run llvm optimization passes"); aot_apply_llvm_new_pass_manager(comp_ctx, comp_ctx->module); - - /* Run specific passes for AOT indirect mode in last since general - optimization may create some intrinsic function calls like - llvm.memset, so let's remove these function calls here. */ - if (!comp_ctx->is_jit_mode && comp_ctx->is_indirect_mode) { - bh_print_time("Begin to run optimization passes " - "for indirect mode"); - if (!apply_passes_for_indirect_mode(comp_ctx)) { - return false; - } - } bh_print_time("Finish llvm optimization passes"); } @@ -2761,6 +2692,16 @@ aot_compile_wasm(AOTCompContext *comp_ctx) aot_handle_llvm_errmsg("failed to addIRModule", err); return false; } + + if (comp_ctx->stack_sizes != NULL) { + LLVMOrcJITTargetAddress addr; + if ((err = LLVMOrcLLLazyJITLookup(comp_ctx->orc_jit, &addr, + aot_stack_sizes_alias_name))) { + aot_handle_llvm_errmsg("failed to look up stack_sizes", err); + return false; + } + comp_ctx->jit_stack_sizes = (uint32 *)addr; + } } return true; @@ -2794,6 +2735,33 @@ aot_generate_tempfile_name(const char *prefix, const char *extension, snprintf(buffer + name_len, len - name_len, ".%s", extension); return buffer; } +#else + +errno_t +_mktemp_s(char *nameTemplate, size_t sizeInChars); + +char * +aot_generate_tempfile_name(const char *prefix, const char *extension, + char *buffer, uint32 len) +{ + int name_len; + + name_len = snprintf(buffer, len, "%s-XXXXXX", prefix); + + if (_mktemp_s(buffer, name_len + 1) != 0) { + return NULL; + } + + /* Check if buffer length is enough */ + /* name_len + '.' + extension + '\0' */ + if (name_len + 1 + strlen(extension) + 1 > len) { + aot_set_last_error("temp file name too long."); + return NULL; + } + + snprintf(buffer + name_len, len - name_len, ".%s", extension); + return buffer; +} #endif /* end of !(defined(_WIN32) || defined(_WIN32_)) */ bool @@ -2815,6 +2783,55 @@ aot_emit_llvm_file(AOTCompContext *comp_ctx, const char *file_name) return true; } +static bool +aot_move_file(const char *dest, const char *src) +{ + FILE *dfp = fopen(dest, "w"); + FILE *sfp = fopen(src, "r"); + size_t rsz; + char buf[128]; + bool success = false; + + if (dfp == NULL || sfp == NULL) { + LOG_DEBUG("open error %s %s", dest, src); + goto fail; + } + do { + rsz = fread(buf, 1, sizeof(buf), sfp); + if (rsz > 0) { + size_t wsz = fwrite(buf, 1, rsz, dfp); + if (wsz < rsz) { + LOG_DEBUG("write error"); + goto fail; + } + } + if (rsz < sizeof(buf)) { + if (ferror(sfp)) { + LOG_DEBUG("read error"); + goto fail; + } + } + } while (rsz > 0); + success = true; +fail: + if (dfp != NULL) { + if (fclose(dfp)) { + LOG_DEBUG("close error"); + success = false; + } + if (!success) { + (void)unlink(dest); + } + } + if (sfp != NULL) { + (void)fclose(sfp); + } + if (success) { + (void)unlink(src); + } + return success; +} + bool aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name) { @@ -2830,7 +2847,25 @@ aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name) int ret; if (comp_ctx->external_llc_compiler) { + const char *stack_usage_flag = ""; char bc_file_name[64]; + char su_file_name[65]; /* See the comment below */ + + if (comp_ctx->stack_usage_file != NULL) { + /* + * Note: we know the caller uses 64 byte buffer for + * file_name. It will get 1 byte longer because we + * replace ".o" with ".su". + */ + size_t len = strlen(file_name); + bh_assert(len + 1 <= sizeof(su_file_name)); + bh_assert(len > 3); + bh_assert(file_name[len - 2] == '.'); + bh_assert(file_name[len - 1] == 'o'); + snprintf(su_file_name, sizeof(su_file_name), "%.*s.su", + (int)(len - 2), file_name); + stack_usage_flag = " -fstack-usage"; + } if (!aot_generate_tempfile_name("wamrc-bc", "bc", bc_file_name, sizeof(bc_file_name))) { @@ -2842,8 +2877,8 @@ aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name) return false; } - snprintf(cmd, sizeof(cmd), "%s %s -o %s %s", - comp_ctx->external_llc_compiler, + snprintf(cmd, sizeof(cmd), "%s%s %s -o %s %s", + comp_ctx->external_llc_compiler, stack_usage_flag, comp_ctx->llc_compiler_flags ? comp_ctx->llc_compiler_flags : "-O3 -c", file_name, bc_file_name); @@ -2858,6 +2893,22 @@ aot_emit_object_file(AOTCompContext *comp_ctx, char *file_name) "with external LLC compiler."); return false; } + if (comp_ctx->stack_usage_file != NULL) { + /* + * move the temporary .su file to the specified location. + * + * Note: the former is automatimally inferred from the output + * filename (file_name here) by clang. + * + * Note: the latter might be user-specified. + * (wamrc --stack-usage=) + */ + if (!aot_move_file(comp_ctx->stack_usage_file, su_file_name)) { + aot_set_last_error("failed to move su file."); + (void)unlink(su_file_name); + return false; + } + } } else if (comp_ctx->external_asm_compiler) { char asm_file_name[64]; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_compiler.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_compiler.h similarity index 95% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_compiler.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_compiler.h index e6031ab892f..b6347c89d78 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_compiler.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_compiler.h @@ -239,6 +239,13 @@ check_type_compatible(uint8 src_type, uint8 dst_type) #define FUNC_REF_TYPE comp_ctx->basic_types.funcref_type #define EXTERN_REF_TYPE comp_ctx->basic_types.externref_type +#define INT8_PTR_TYPE_GS comp_ctx->basic_types.int8_ptr_type_gs +#define INT16_PTR_TYPE_GS comp_ctx->basic_types.int16_ptr_type_gs +#define INT32_PTR_TYPE_GS comp_ctx->basic_types.int32_ptr_type_gs +#define INT64_PTR_TYPE_GS comp_ctx->basic_types.int64_ptr_type_gs +#define F32_PTR_TYPE_GS comp_ctx->basic_types.float32_ptr_type_gs +#define F64_PTR_TYPE_GS comp_ctx->basic_types.float64_ptr_type_gs + #define I32_CONST(v) LLVMConstInt(I32_TYPE, v, true) #define I64_CONST(v) LLVMConstInt(I64_TYPE, v, true) #define F32_CONST(v) LLVMConstReal(F32_TYPE, v) @@ -272,6 +279,7 @@ check_type_compatible(uint8 src_type, uint8 dst_type) #define V128_TYPE comp_ctx->basic_types.v128_type #define V128_PTR_TYPE comp_ctx->basic_types.v128_ptr_type +#define V128_PTR_TYPE_GS comp_ctx->basic_types.v128_ptr_type_gs #define V128_i8x16_TYPE comp_ctx->basic_types.i8x16_vec_type #define V128_i16x8_TYPE comp_ctx->basic_types.i16x8_vec_type #define V128_i32x4_TYPE comp_ctx->basic_types.i32x4_vec_type @@ -355,6 +363,19 @@ check_type_compatible(uint8 src_type, uint8 dst_type) } \ } while (0) +/* if val is a constant integer and its value is not undef or poison */ +static inline bool +LLVMIsEfficientConstInt(LLVMValueRef val) +{ + return LLVMIsConstant(val) + && LLVMGetValueKind(val) == LLVMConstantIntValueKind + && !LLVMIsUndef(val) +#if LLVM_VERSION_NUMBER >= 12 + && !LLVMIsPoison(addr) +#endif + ; +} + bool aot_compile_wasm(AOTCompContext *comp_ctx); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_aot_file.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_aot_file.c similarity index 72% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_aot_file.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_aot_file.c index 62bb809daa1..80bcdc7db48 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_aot_file.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_aot_file.c @@ -93,7 +93,10 @@ check_utf8_str(const uint8 *str, uint32 len) /* Internal function in object file */ typedef struct AOTObjectFunc { char *func_name; + /* text offset of aot_func#n */ uint64 text_offset; + /* text offset of aot_func_internal#n */ + uint64 text_offset_of_aot_func_internal; } AOTObjectFunc; /* Symbol table list node */ @@ -111,6 +114,8 @@ typedef struct AOTSymbolList { /* AOT object data */ typedef struct AOTObjectData { + AOTCompContext *comp_ctx; + LLVMMemoryBufferRef mem_buf; LLVMBinaryRef binary; @@ -119,6 +124,12 @@ typedef struct AOTObjectData { void *text; uint32 text_size; + void *text_unlikely; + uint32 text_unlikely_size; + + void *text_hot; + uint32 text_hot_size; + /* literal data and size */ void *literal; uint32 literal_size; @@ -132,6 +143,10 @@ typedef struct AOTObjectData { AOTSymbolList symbol_list; AOTRelocationGroup *relocation_groups; uint32 relocation_group_count; + + const char *stack_sizes_section_name; + uint32 stack_sizes_offset; + uint32 *stack_sizes; } AOTObjectData; #if 0 @@ -254,7 +269,7 @@ static uint32 get_table_init_data_size(AOTTableInitData *table_init_data) { /* - * mode (4 bytes), elem_type (4 bytes), do not need is_dropped field + * mode (4 bytes), elem_type (4 bytes) * * table_index(4 bytes) + init expr type (4 bytes) + init expr value (8 * bytes) @@ -558,8 +573,10 @@ get_init_data_section_size(AOTCompContext *comp_ctx, AOTCompData *comp_data, static uint32 get_text_section_size(AOTObjectData *obj_data) { - return (sizeof(uint32) + obj_data->literal_size + obj_data->text_size + 3) - & ~3; + return sizeof(uint32) + align_uint(obj_data->literal_size, 4) + + align_uint(obj_data->text_size, 4) + + align_uint(obj_data->text_unlikely_size, 4) + + align_uint(obj_data->text_hot_size, 4); } static uint32 @@ -623,13 +640,33 @@ get_relocation_size(AOTRelocation *relocation, bool is_32bin) } static uint32 -get_relocations_size(AOTRelocation *relocations, uint32 relocation_count, +get_relocations_size(AOTObjectData *obj_data, + AOTRelocationGroup *relocation_group, + AOTRelocation *relocations, uint32 relocation_count, bool is_32bin) { AOTRelocation *relocation = relocations; uint32 size = 0, i; for (i = 0; i < relocation_count; i++, relocation++) { + /* ignore the relocations to aot_func_internal#n in text section + for windows platform since they will be applied in + aot_emit_text_section */ + if (!strcmp(relocation_group->section_name, ".text") + && !strncmp(relocation->symbol_name, AOT_FUNC_INTERNAL_PREFIX, + strlen(AOT_FUNC_INTERNAL_PREFIX)) + && ((!strncmp(obj_data->comp_ctx->target_arch, "x86_64", 6) + /* Windows AOT_COFF64_BIN_TYPE */ + && obj_data->target_info.bin_type == 6 + /* IMAGE_REL_AMD64_REL32 in windows x86_64 */ + && relocation->relocation_type == 4) + || (!strncmp(obj_data->comp_ctx->target_arch, "i386", 4) + /* Windows AOT_COFF32_BIN_TYPE */ + && obj_data->target_info.bin_type == 4 + /* IMAGE_REL_I386_REL32 in windows x86_32 */ + && relocation->relocation_type == 20))) { + continue; + } size = align_uint(size, 4); size += get_relocation_size(relocation, is_32bin); } @@ -637,19 +674,22 @@ get_relocations_size(AOTRelocation *relocations, uint32 relocation_count, } static uint32 -get_relocation_group_size(AOTRelocationGroup *relocation_group, bool is_32bin) +get_relocation_group_size(AOTObjectData *obj_data, + AOTRelocationGroup *relocation_group, bool is_32bin) { uint32 size = 0; /* section name index + relocation count + relocations */ size += (uint32)sizeof(uint32); size += (uint32)sizeof(uint32); - size += get_relocations_size(relocation_group->relocations, + size += get_relocations_size(obj_data, relocation_group, + relocation_group->relocations, relocation_group->relocation_count, is_32bin); return size; } static uint32 -get_relocation_groups_size(AOTRelocationGroup *relocation_groups, +get_relocation_groups_size(AOTObjectData *obj_data, + AOTRelocationGroup *relocation_groups, uint32 relocation_group_count, bool is_32bin) { AOTRelocationGroup *relocation_group = relocation_groups; @@ -657,7 +697,7 @@ get_relocation_groups_size(AOTRelocationGroup *relocation_groups, for (i = 0; i < relocation_group_count; i++, relocation_group++) { size = align_uint(size, 4); - size += get_relocation_group_size(relocation_group, is_32bin); + size += get_relocation_group_size(obj_data, relocation_group, is_32bin); } return size; } @@ -850,7 +890,7 @@ get_relocation_section_size(AOTCompContext *comp_ctx, AOTObjectData *obj_data) /* relocation group count + symbol_table + relocation groups */ return (uint32)sizeof(uint32) + symbol_table_size - + get_relocation_groups_size(relocation_groups, + + get_relocation_groups_size(obj_data, relocation_groups, relocation_group_count, is_32bit_binary(obj_data)); } @@ -1624,7 +1664,31 @@ aot_emit_object_data_section_info(uint8 *buf, uint8 *buf_end, uint32 *p_offset, EMIT_STR(data_section->name); offset = align_uint(offset, 4); EMIT_U32(data_section->size); - EMIT_BUF(data_section->data, data_section->size); + if (obj_data->stack_sizes_section_name != NULL + && !strcmp(obj_data->stack_sizes_section_name, + data_section->name)) { + uint32 ss_offset = obj_data->stack_sizes_offset; + uint32 ss_size = + obj_data->func_count * sizeof(*obj_data->stack_sizes); + LOG_VERBOSE("Replacing stack_sizes in %s section, offset %" PRIu32 + ", size %" PRIu32, + obj_data->stack_sizes_section_name, ss_offset, ss_size); + bh_assert(ss_offset + ss_size <= data_section->size); + /* 0 .. ss_offset */ + if (ss_offset > 0) { + EMIT_BUF(data_section->data, ss_offset); + } + /* ss_offset .. ss_offset+ss_size */ + EMIT_BUF(obj_data->stack_sizes, ss_size); + /* ss_offset+ss_size .. data_section->size */ + if (data_section->size > ss_offset + ss_size) { + EMIT_BUF(data_section->data + ss_offset + ss_size, + data_section->size - (ss_offset + ss_size)); + } + } + else { + EMIT_BUF(data_section->data, data_section->size); + } } if (offset - *p_offset @@ -1696,24 +1760,107 @@ aot_emit_text_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset, uint32 section_size = get_text_section_size(obj_data); uint32 offset = *p_offset; uint8 placeholder = 0; + AOTRelocationGroup *relocation_group; + AOTRelocation *relocation; + uint32 i, j, relocation_count; + uint8 *text; *p_offset = offset = align_uint(offset, 4); EMIT_U32(AOT_SECTION_TYPE_TEXT); EMIT_U32(section_size); EMIT_U32(obj_data->literal_size); - if (obj_data->literal_size > 0) + + if (obj_data->literal_size > 0) { EMIT_BUF(obj_data->literal, obj_data->literal_size); - EMIT_BUF(obj_data->text, obj_data->text_size); + while (offset & 3) + EMIT_BUF(&placeholder, 1); + } - while (offset & 3) - EMIT_BUF(&placeholder, 1); + text = buf + offset; + + if (obj_data->text_size > 0) { + EMIT_BUF(obj_data->text, obj_data->text_size); + while (offset & 3) + EMIT_BUF(&placeholder, 1); + } + if (obj_data->text_unlikely_size > 0) { + EMIT_BUF(obj_data->text_unlikely, obj_data->text_unlikely_size); + while (offset & 3) + EMIT_BUF(&placeholder, 1); + } + if (obj_data->text_hot_size > 0) { + EMIT_BUF(obj_data->text_hot, obj_data->text_hot_size); + while (offset & 3) + EMIT_BUF(&placeholder, 1); + } if (offset - *p_offset != section_size + sizeof(uint32) * 2) { aot_set_last_error("emit text section failed."); return false; } + /* apply relocations to aot_func_internal#n in text section for + windows platform */ + if ((!strncmp(obj_data->comp_ctx->target_arch, "x86_64", 6) + /* Windows AOT_COFF64_BIN_TYPE */ + && obj_data->target_info.bin_type == 6) + || (!strncmp(obj_data->comp_ctx->target_arch, "i386", 4) + /* Windows AOT_COFF32_BIN_TYPE */ + && obj_data->target_info.bin_type == 4)) { + relocation_group = obj_data->relocation_groups; + for (i = 0; i < obj_data->relocation_group_count; + i++, relocation_group++) { + /* relocation in text section */ + if (!strcmp(relocation_group->section_name, ".text")) { + relocation = relocation_group->relocations; + relocation_count = relocation_group->relocation_count; + for (j = 0; j < relocation_count; j++) { + /* relocation to aot_func_internal#n */ + if (str_starts_with(relocation->symbol_name, + AOT_FUNC_INTERNAL_PREFIX) + && ((obj_data->target_info.bin_type + == 6 /* AOT_COFF64_BIN_TYPE */ + && relocation->relocation_type + == 4 /* IMAGE_REL_AMD64_REL32 */) + || (obj_data->target_info.bin_type + == 4 /* AOT_COFF32_BIN_TYPE */ + && relocation->relocation_type + == 20 /* IMAGE_REL_I386_REL32 */))) { + uint32 func_idx = + atoi(relocation->symbol_name + + strlen(AOT_FUNC_INTERNAL_PREFIX)); + uint64 text_offset, reloc_offset, reloc_addend; + + bh_assert(func_idx < obj_data->func_count); + + text_offset = obj_data->funcs[func_idx] + .text_offset_of_aot_func_internal; + reloc_offset = relocation->relocation_offset; + reloc_addend = relocation->relocation_addend; + /* S + A - P */ + *(uint32 *)(text + reloc_offset) = + (uint32)(text_offset + reloc_addend - reloc_offset + - 4); + + /* remove current relocation as it has been applied */ + if (j < relocation_count - 1) { + uint32 move_size = + (uint32)(sizeof(AOTRelocation) + * (relocation_count - 1 - j)); + bh_memmove_s(relocation, move_size, relocation + 1, + move_size); + } + relocation_group->relocation_count--; + } + else { + relocation++; + } + } + } + } + } + *p_offset = offset; return true; @@ -2211,11 +2358,23 @@ aot_resolve_text(AOTObjectData *obj_data) } while ( !LLVMObjectFileIsSectionIteratorAtEnd(obj_data->binary, sec_itr)) { - if ((name = (char *)LLVMGetSectionName(sec_itr)) - && !strcmp(name, ".text")) { - obj_data->text = (char *)LLVMGetSectionContents(sec_itr); - obj_data->text_size = (uint32)LLVMGetSectionSize(sec_itr); - break; + if ((name = (char *)LLVMGetSectionName(sec_itr))) { + if (!strcmp(name, ".text")) { + obj_data->text = (char *)LLVMGetSectionContents(sec_itr); + obj_data->text_size = (uint32)LLVMGetSectionSize(sec_itr); + } + else if (!strcmp(name, ".text.unlikely.")) { + obj_data->text_unlikely = + (char *)LLVMGetSectionContents(sec_itr); + obj_data->text_unlikely_size = + (uint32)LLVMGetSectionSize(sec_itr); + } + else if (!strcmp(name, ".text.hot.")) { + obj_data->text_hot = + (char *)LLVMGetSectionContents(sec_itr); + obj_data->text_hot_size = + (uint32)LLVMGetSectionSize(sec_itr); + } } LLVMMoveToNextSection(sec_itr); } @@ -2253,7 +2412,8 @@ static bool get_relocations_count(LLVMSectionIteratorRef sec_itr, uint32 *p_count); static bool -is_data_section(LLVMSectionIteratorRef sec_itr, char *section_name) +is_data_section(AOTObjectData *obj_data, LLVMSectionIteratorRef sec_itr, + char *section_name) { uint32 relocation_count = 0; @@ -2265,7 +2425,12 @@ is_data_section(LLVMSectionIteratorRef sec_itr, char *section_name) || !strncmp(section_name, ".rodata.str", strlen(".rodata.str")) || (!strcmp(section_name, ".rdata") && get_relocations_count(sec_itr, &relocation_count) - && relocation_count > 0)); + && relocation_count > 0) + || !strcmp(section_name, aot_stack_sizes_section_name) + || (obj_data->comp_ctx->enable_llvm_pgo + && (!strncmp(section_name, "__llvm_prf_cnts", 15) + || !strncmp(section_name, "__llvm_prf_data", 15) + || !strncmp(section_name, "__llvm_prf_names", 16)))); } static bool @@ -2281,7 +2446,7 @@ get_object_data_sections_count(AOTObjectData *obj_data, uint32 *p_count) } while (!LLVMObjectFileIsSectionIteratorAtEnd(obj_data->binary, sec_itr)) { if ((name = (char *)LLVMGetSectionName(sec_itr)) - && (is_data_section(sec_itr, name))) { + && (is_data_section(obj_data, sec_itr, name))) { count++; } LLVMMoveToNextSection(sec_itr); @@ -2306,6 +2471,9 @@ aot_resolve_object_data_sections(AOTObjectData *obj_data) } if (sections_count > 0) { + uint32 llvm_prf_cnts_idx = 0, llvm_prf_data_idx = 0; + char buf[32]; + size = (uint32)sizeof(AOTObjectDataSection) * sections_count; if (!(data_section = obj_data->data_sections = wasm_runtime_malloc(size))) { @@ -2322,10 +2490,46 @@ aot_resolve_object_data_sections(AOTObjectData *obj_data) while ( !LLVMObjectFileIsSectionIteratorAtEnd(obj_data->binary, sec_itr)) { if ((name = (char *)LLVMGetSectionName(sec_itr)) - && (is_data_section(sec_itr, name))) { + && (is_data_section(obj_data, sec_itr, name))) { data_section->name = name; - data_section->data = (uint8 *)LLVMGetSectionContents(sec_itr); - data_section->size = (uint32)LLVMGetSectionSize(sec_itr); + if (obj_data->comp_ctx->enable_llvm_pgo + && !strcmp(name, "__llvm_prf_cnts")) { + snprintf(buf, sizeof(buf), "%s%u", name, + llvm_prf_cnts_idx++); + size = (uint32)(strlen(buf) + 1); + if (!(data_section->name = wasm_runtime_malloc(size))) { + aot_set_last_error( + "allocate memory for data section name failed."); + return false; + } + bh_memcpy_s(data_section->name, size, buf, size); + data_section->is_name_allocated = true; + } + else if (obj_data->comp_ctx->enable_llvm_pgo + && !strcmp(name, "__llvm_prf_data")) { + snprintf(buf, sizeof(buf), "%s%u", name, + llvm_prf_data_idx++); + size = (uint32)(strlen(buf) + 1); + if (!(data_section->name = wasm_runtime_malloc(size))) { + aot_set_last_error( + "allocate memory for data section name failed."); + return false; + } + bh_memcpy_s(data_section->name, size, buf, size); + data_section->is_name_allocated = true; + } + + if (obj_data->comp_ctx->enable_llvm_pgo + && !strcmp(name, "__llvm_prf_names")) { + data_section->data = (uint8 *)aot_compress_aot_func_names( + obj_data->comp_ctx, &data_section->size); + data_section->is_data_allocated = true; + } + else { + data_section->data = + (uint8 *)LLVMGetSectionContents(sec_itr); + data_section->size = (uint32)LLVMGetSectionSize(sec_itr); + } data_section++; } LLVMMoveToNextSection(sec_itr); @@ -2336,6 +2540,303 @@ aot_resolve_object_data_sections(AOTObjectData *obj_data) return true; } +static bool +read_stack_usage_file(const AOTCompContext *comp_ctx, const char *filename, + uint32 *sizes, uint32 count) +{ + FILE *fp = NULL; + if (filename == NULL) { + aot_set_last_error("no stack usage file is specified."); + return false; + } + fp = fopen(filename, "r"); + if (fp == NULL) { + LOG_ERROR("failed to open stack usage file: %s", filename); + goto fail; + } + /* + * the file consists of lines like: + * + * WASM Module:aot_func#9 72 static + */ + const char *aot_func_prefix = AOT_FUNC_PREFIX; + const char *aot_func_internal_prefix = AOT_FUNC_INTERNAL_PREFIX; + uint32 precheck_found = 0; + uint32 precheck_stack_size_max = 0; + uint32 precheck_stack_size_min = UINT32_MAX; + uint32 found = 0; + while (true) { + const char *prefix; + char line[100]; + char *cp = fgets(line, sizeof(line), fp); + char *fn; + char *colon; + uintmax_t func_idx; + uintmax_t sz; + int ret; + + if (cp == NULL) { + break; + } + /* + * Note: strrchr (not strchr) because a module name can contain + * colons. + */ + colon = strrchr(cp, ':'); + if (colon == NULL) { + goto fail; + } + fn = strstr(colon, aot_func_prefix); + if (fn != NULL) { + prefix = aot_func_prefix; + } + else { + fn = strstr(colon, aot_func_internal_prefix); + if (fn == NULL) { + LOG_ERROR("failed to parse stack usage line: %s", cp); + goto fail; + } + prefix = aot_func_internal_prefix; + } + ret = sscanf(fn + strlen(prefix), "%ju %ju static", &func_idx, &sz); + if (ret != 2) { + goto fail; + } + if (sz > UINT32_MAX) { + goto fail; + } + if (func_idx > UINT32_MAX) { + goto fail; + } + if (func_idx >= count) { + goto fail; + } + if (prefix == aot_func_prefix) { + if (sz < precheck_stack_size_min) { + precheck_stack_size_min = (uint32)sz; + } + if (sz > precheck_stack_size_max) { + precheck_stack_size_max = (uint32)sz; + } + precheck_found++; + continue; + } + sizes[func_idx] = (uint32)sz; + found++; + } + fclose(fp); + if (precheck_found != count) { + LOG_ERROR("%" PRIu32 " precheck entries found while %" PRIu32 + " entries are expected", + precheck_found, count); + return false; + } + if (found != count) { + /* + * LLVM seems to eliminate calls to an empty function + * (and eliminate the function) even if it's marked noinline. + */ + LOG_VERBOSE("%" PRIu32 " entries found while %" PRIu32 + " entries are expected. Maybe LLVM optimization eliminated " + "some functions.", + found, count); + } + if (precheck_stack_size_min != precheck_stack_size_max) { + /* + * Note: this is too strict. + * + * actually, the stack consumption of the precheck functions + * can depend on the type of them. + * that is, depending on various factors including + * calling conventions and compilers, a function with many + * parameters can consume more stack, even if it merely does + * a tail-call to another function. + */ + bool musttail = aot_target_precheck_can_use_musttail(comp_ctx); + if (musttail) { + LOG_WARNING( + "precheck functions use variable amount of stack. (%" PRIu32 + " - %" PRIu32 ")", + precheck_stack_size_min, precheck_stack_size_max); + } + else { + LOG_VERBOSE("precheck functions use %" PRIu32 " - %" PRIu32 + " bytes of stack.", + precheck_stack_size_min, precheck_stack_size_max); + } + } + else { + LOG_VERBOSE("precheck functions use %" PRIu32 " bytes of stack.", + precheck_stack_size_max); + } + if (precheck_stack_size_max >= 1024) { + LOG_WARNING("precheck functions themselves consume relatively large " + "amount of stack (%" PRIu32 + "). Please ensure the runtime has large enough " + "WASM_STACK_GUARD_SIZE.", + precheck_stack_size_max); + } + return true; +fail: + if (fp != NULL) + fclose(fp); + aot_set_last_error("failed to read stack usage file."); + return false; +} + +static bool +aot_resolve_stack_sizes(AOTCompContext *comp_ctx, AOTObjectData *obj_data) +{ + LLVMSectionIteratorRef sec_itr = NULL; + LLVMSymbolIteratorRef sym_itr; + const char *name; + + if (!(sym_itr = LLVMObjectFileCopySymbolIterator(obj_data->binary))) { + aot_set_last_error("llvm get symbol iterator failed."); + return false; + } + + while (!LLVMObjectFileIsSymbolIteratorAtEnd(obj_data->binary, sym_itr)) { + if ((name = LLVMGetSymbolName(sym_itr)) + && (!strcmp(name, aot_stack_sizes_alias_name) + /* symbol of COFF32 starts with "_" */ + || (obj_data->target_info.bin_type == AOT_COFF32_BIN_TYPE + && !strncmp(name, "_", 1) + && !strcmp(name + 1, aot_stack_sizes_alias_name)))) { +#if 0 /* cf. https://github.com/llvm/llvm-project/issues/67765 */ + uint64 sz = LLVMGetSymbolSize(sym_itr); + if (sz != sizeof(uint32) * obj_data->func_count + /* sz of COFF64/COFF32 is 0, ignore the check */ + && obj_data->target_info.bin_type != AOT_COFF64_BIN_TYPE + && obj_data->target_info.bin_type != AOT_COFF32_BIN_TYPE) { + aot_set_last_error("stack_sizes had unexpected size."); + goto fail; + } +#endif + uint64 addr = LLVMGetSymbolAddress(sym_itr); + if (!(sec_itr = + LLVMObjectFileCopySectionIterator(obj_data->binary))) { + aot_set_last_error("llvm get section iterator failed."); + goto fail; + } + LLVMMoveToContainingSection(sec_itr, sym_itr); + const char *sec_name = LLVMGetSectionName(sec_itr); + LOG_VERBOSE("stack_sizes found in section %s offset %" PRIu64 ".", + sec_name, addr); + if (strcmp(sec_name, aot_stack_sizes_section_name) || addr != 0) { + aot_set_last_error( + "stack_sizes found at an unexpected location."); + goto fail; + } + /* + * Note: We can't always modify stack_sizes in-place. + * Eg. When WAMRC_LLC_COMPILER is used, LLVM sometimes uses + * read-only mmap of the temporary file to back + * LLVMGetSectionContents. + */ + const uint32 *ro_stack_sizes = + (const uint32 *)(LLVMGetSectionContents(sec_itr) + addr); + uint32 i; + for (i = 0; i < obj_data->func_count; i++) { + /* Note: -1 == AOT_NEG_ONE from aot_create_stack_sizes */ + if (ro_stack_sizes[i] != (uint32)-1) { + aot_set_last_error("unexpected data in stack_sizes."); + goto fail; + } + } + /* + * Record section/offset and construct a copy of stack_sizes. + * aot_emit_object_data_section_info will emit this copy. + */ + obj_data->stack_sizes_section_name = sec_name; + obj_data->stack_sizes_offset = (uint32)addr; + obj_data->stack_sizes = wasm_runtime_malloc( + obj_data->func_count * sizeof(*obj_data->stack_sizes)); + if (obj_data->stack_sizes == NULL) { + aot_set_last_error("failed to allocate memory."); + goto fail; + } + uint32 *stack_sizes = obj_data->stack_sizes; + for (i = 0; i < obj_data->func_count; i++) { + stack_sizes[i] = (uint32)-1; + } + if (!read_stack_usage_file(comp_ctx, comp_ctx->stack_usage_file, + stack_sizes, obj_data->func_count)) { + goto fail; + } + for (i = 0; i < obj_data->func_count; i++) { + const AOTFuncContext *func_ctx = comp_ctx->func_ctxes[i]; + bool musttail = aot_target_precheck_can_use_musttail(comp_ctx); + unsigned int stack_consumption_to_call_wrapped_func = + musttail ? 0 + : aot_estimate_stack_usage_for_function_call( + comp_ctx, func_ctx->aot_func->func_type); + + /* + * LLVM seems to eliminate calls to an empty function + * (and eliminate the function) even if it's marked noinline. + * + * Note: -1 == AOT_NEG_ONE from aot_create_stack_sizes + */ + if (stack_sizes[i] == (uint32)-1) { + if (func_ctx->stack_consumption_for_func_call != 0) { + /* + * This happens if a function calling another + * function has been optimized out. + * + * for example, + * + * (func $func + * (local i32) + * local.get 0 + * if + * call $another + * end + * ) + */ + LOG_VERBOSE("AOT func#%" PRIu32 + " had call(s) but eliminated?", + i); + } + else { + LOG_VERBOSE("AOT func#%" PRIu32 " eliminated?", i); + } + stack_sizes[i] = 0; + } + else { + LOG_VERBOSE("AOT func#%" PRIu32 " stack_size %u + %" PRIu32 + " + %u", + i, stack_consumption_to_call_wrapped_func, + stack_sizes[i], + func_ctx->stack_consumption_for_func_call); + if (UINT32_MAX - stack_sizes[i] + < func_ctx->stack_consumption_for_func_call) { + aot_set_last_error("stack size overflow."); + goto fail; + } + stack_sizes[i] += func_ctx->stack_consumption_for_func_call; + if (UINT32_MAX - stack_sizes[i] + < stack_consumption_to_call_wrapped_func) { + aot_set_last_error("stack size overflow."); + goto fail; + } + stack_sizes[i] += stack_consumption_to_call_wrapped_func; + } + } + LLVMDisposeSectionIterator(sec_itr); + LLVMDisposeSymbolIterator(sym_itr); + return true; + } + LLVMMoveToNextSymbol(sym_itr); + } + aot_set_last_error("stack_sizes not found."); +fail: + if (sec_itr) + LLVMDisposeSectionIterator(sec_itr); + LLVMDisposeSymbolIterator(sym_itr); + return false; +} + static bool aot_resolve_functions(AOTCompContext *comp_ctx, AOTObjectData *obj_data) { @@ -2347,6 +2848,10 @@ aot_resolve_functions(AOTCompContext *comp_ctx, AOTObjectData *obj_data) /* allocate memory for aot function */ obj_data->func_count = comp_ctx->comp_data->func_count; if (obj_data->func_count) { + if ((comp_ctx->enable_stack_bound_check + || comp_ctx->enable_stack_estimation) + && !aot_resolve_stack_sizes(comp_ctx, obj_data)) + return false; total_size = (uint32)sizeof(AOTObjectFunc) * obj_data->func_count; if (!(obj_data->funcs = wasm_runtime_malloc(total_size))) { aot_set_last_error("allocate memory for functions failed."); @@ -2363,11 +2868,77 @@ aot_resolve_functions(AOTCompContext *comp_ctx, AOTObjectData *obj_data) while (!LLVMObjectFileIsSymbolIteratorAtEnd(obj_data->binary, sym_itr)) { if ((name = (char *)LLVMGetSymbolName(sym_itr)) && str_starts_with(name, prefix)) { + /* symbol aot_func#n */ func_index = (uint32)atoi(name + strlen(prefix)); if (func_index < obj_data->func_count) { + LLVMSectionIteratorRef contain_section; + char *contain_section_name; + func = obj_data->funcs + func_index; func->func_name = name; - func->text_offset = LLVMGetSymbolAddress(sym_itr); + + if (!(contain_section = LLVMObjectFileCopySectionIterator( + obj_data->binary))) { + aot_set_last_error("llvm get section iterator failed."); + LLVMDisposeSymbolIterator(sym_itr); + return false; + } + LLVMMoveToContainingSection(contain_section, sym_itr); + contain_section_name = + (char *)LLVMGetSectionName(contain_section); + LLVMDisposeSectionIterator(contain_section); + + if (!strcmp(contain_section_name, ".text.unlikely.")) { + func->text_offset = align_uint(obj_data->text_size, 4) + + LLVMGetSymbolAddress(sym_itr); + } + else if (!strcmp(contain_section_name, ".text.hot.")) { + func->text_offset = + align_uint(obj_data->text_size, 4) + + align_uint(obj_data->text_unlikely_size, 4) + + LLVMGetSymbolAddress(sym_itr); + } + else { + func->text_offset = LLVMGetSymbolAddress(sym_itr); + } + } + } + else if ((name = (char *)LLVMGetSymbolName(sym_itr)) + && str_starts_with(name, AOT_FUNC_INTERNAL_PREFIX)) { + /* symbol aot_func_internal#n */ + func_index = (uint32)atoi(name + strlen(AOT_FUNC_INTERNAL_PREFIX)); + if (func_index < obj_data->func_count) { + LLVMSectionIteratorRef contain_section; + char *contain_section_name; + + func = obj_data->funcs + func_index; + + if (!(contain_section = LLVMObjectFileCopySectionIterator( + obj_data->binary))) { + aot_set_last_error("llvm get section iterator failed."); + LLVMDisposeSymbolIterator(sym_itr); + return false; + } + LLVMMoveToContainingSection(contain_section, sym_itr); + contain_section_name = + (char *)LLVMGetSectionName(contain_section); + LLVMDisposeSectionIterator(contain_section); + + if (!strcmp(contain_section_name, ".text.unlikely.")) { + func->text_offset_of_aot_func_internal = + align_uint(obj_data->text_size, 4) + + LLVMGetSymbolAddress(sym_itr); + } + else if (!strcmp(contain_section_name, ".text.hot.")) { + func->text_offset_of_aot_func_internal = + align_uint(obj_data->text_size, 4) + + align_uint(obj_data->text_unlikely_size, 4) + + LLVMGetSymbolAddress(sym_itr); + } + else { + func->text_offset_of_aot_func_internal = + LLVMGetSymbolAddress(sym_itr); + } } } LLVMMoveToNextSymbol(sym_itr); @@ -2478,9 +3049,95 @@ aot_resolve_object_relocation_group(AOTObjectData *obj_data, } /* set relocation fields */ - relocation->relocation_offset = offset; relocation->relocation_type = (uint32)type; relocation->symbol_name = (char *)LLVMGetSymbolName(rel_sym); + relocation->relocation_offset = offset; + if (!strcmp(group->section_name, ".rela.text.unlikely.") + || !strcmp(group->section_name, ".rel.text.unlikely.")) { + relocation->relocation_offset += align_uint(obj_data->text_size, 4); + } + else if (!strcmp(group->section_name, ".rela.text.hot.") + || !strcmp(group->section_name, ".rel.text.hot.")) { + relocation->relocation_offset += + align_uint(obj_data->text_size, 4) + + align_uint(obj_data->text_unlikely_size, 4); + } + if (!strcmp(relocation->symbol_name, ".text.unlikely.")) { + relocation->symbol_name = ".text"; + relocation->relocation_addend += align_uint(obj_data->text_size, 4); + } + if (!strcmp(relocation->symbol_name, ".text.hot.")) { + relocation->symbol_name = ".text"; + relocation->relocation_addend += + align_uint(obj_data->text_size, 4) + + align_uint(obj_data->text_unlikely_size, 4); + } + + /* + * Note: aot_stack_sizes_section_name section only contains + * stack_sizes table. + */ + if (!strcmp(relocation->symbol_name, aot_stack_sizes_name)) { + /* discard const */ + relocation->symbol_name = (char *)aot_stack_sizes_section_name; + } + + if (obj_data->comp_ctx->enable_llvm_pgo + && (!strcmp(relocation->symbol_name, "__llvm_prf_cnts") + || !strcmp(relocation->symbol_name, "__llvm_prf_data"))) { + LLVMSectionIteratorRef sec_itr; + char buf[32], *section_name; + uint32 prof_section_idx = 0; + + if (!(sec_itr = + LLVMObjectFileCopySectionIterator(obj_data->binary))) { + aot_set_last_error("llvm get section iterator failed."); + LLVMDisposeSymbolIterator(rel_sym); + goto fail; + } + while (!LLVMObjectFileIsSectionIteratorAtEnd(obj_data->binary, + sec_itr)) { + section_name = (char *)LLVMGetSectionName(sec_itr); + if (section_name + && !strcmp(section_name, relocation->symbol_name)) { + if (LLVMGetSectionContainsSymbol(sec_itr, rel_sym)) + break; + prof_section_idx++; + } + LLVMMoveToNextSection(sec_itr); + } + LLVMDisposeSectionIterator(sec_itr); + + if (!strcmp(group->section_name, ".rela.text") + || !strcmp(group->section_name, ".rel.text")) { + snprintf(buf, sizeof(buf), "%s%u", relocation->symbol_name, + prof_section_idx); + size = (uint32)(strlen(buf) + 1); + if (!(relocation->symbol_name = wasm_runtime_malloc(size))) { + aot_set_last_error( + "allocate memory for relocation symbol name failed."); + LLVMDisposeSymbolIterator(rel_sym); + goto fail; + } + bh_memcpy_s(relocation->symbol_name, size, buf, size); + relocation->is_symbol_name_allocated = true; + } + else if (!strncmp(group->section_name, ".rela__llvm_prf_data", 20) + || !strncmp(group->section_name, ".rel__llvm_prf_data", + 19)) { + snprintf(buf, sizeof(buf), "%s%u", relocation->symbol_name, + prof_section_idx); + size = (uint32)(strlen(buf) + 1); + if (!(relocation->symbol_name = wasm_runtime_malloc(size))) { + aot_set_last_error( + "allocate memory for relocation symbol name failed."); + LLVMDisposeSymbolIterator(rel_sym); + goto fail; + } + bh_memcpy_s(relocation->symbol_name, size, buf, size); + relocation->is_symbol_name_allocated = true; + } + } /* for ".LCPIxxx", ".LJTIxxx", ".LBBxxx" and switch lookup table * relocation, transform the symbol name to real section name and set @@ -2525,10 +3182,14 @@ aot_resolve_object_relocation_group(AOTObjectData *obj_data, } static bool -is_relocation_section_name(char *section_name) +is_relocation_section_name(AOTObjectData *obj_data, char *section_name) { return (!strcmp(section_name, ".rela.text") || !strcmp(section_name, ".rel.text") + || !strcmp(section_name, ".rela.text.unlikely.") + || !strcmp(section_name, ".rel.text.unlikely.") + || !strcmp(section_name, ".rela.text.hot.") + || !strcmp(section_name, ".rel.text.hot.") || !strcmp(section_name, ".rela.literal") || !strcmp(section_name, ".rela.data") || !strcmp(section_name, ".rel.data") @@ -2536,6 +3197,9 @@ is_relocation_section_name(char *section_name) || !strcmp(section_name, ".rel.sdata") || !strcmp(section_name, ".rela.rodata") || !strcmp(section_name, ".rel.rodata") + || (obj_data->comp_ctx->enable_llvm_pgo + && (!strcmp(section_name, ".rela__llvm_prf_data") + || !strcmp(section_name, ".rel__llvm_prf_data"))) /* ".rela.rodata.cst4/8/16/.." */ || !strncmp(section_name, ".rela.rodata.cst", strlen(".rela.rodata.cst")) @@ -2545,20 +3209,28 @@ is_relocation_section_name(char *section_name) } static bool -is_relocation_section(LLVMSectionIteratorRef sec_itr) +is_relocation_section(AOTObjectData *obj_data, LLVMSectionIteratorRef sec_itr) { uint32 count = 0; char *name = (char *)LLVMGetSectionName(sec_itr); if (name) { - if (is_relocation_section_name(name)) + if (is_relocation_section_name(obj_data, name)) return true; - else if ((!strcmp(name, ".text") || !strcmp(name, ".rdata")) + else if ((!strcmp(name, ".text") || !strcmp(name, ".text.unlikely.") + || !strcmp(name, ".text.hot.") || !strcmp(name, ".rdata")) && get_relocations_count(sec_itr, &count) && count > 0) return true; } return false; } +static bool +is_readonly_section(const char *name) +{ + return !strcmp(name, ".rel.text") || !strcmp(name, ".rela.text") + || !strcmp(name, ".rela.literal") || !strcmp(name, ".text"); +} + static bool get_relocation_groups_count(AOTObjectData *obj_data, uint32 *p_count) { @@ -2570,7 +3242,7 @@ get_relocation_groups_count(AOTObjectData *obj_data, uint32 *p_count) return false; } while (!LLVMObjectFileIsSectionIteratorAtEnd(obj_data->binary, sec_itr)) { - if (is_relocation_section(sec_itr)) { + if (is_relocation_section(obj_data, sec_itr)) { count++; } LLVMMoveToNextSection(sec_itr); @@ -2586,7 +3258,7 @@ aot_resolve_object_relocation_groups(AOTObjectData *obj_data) { LLVMSectionIteratorRef sec_itr; AOTRelocationGroup *relocation_group; - uint32 group_count; + uint32 group_count, llvm_prf_data_idx = 0; char *name; uint32 size; @@ -2612,14 +3284,63 @@ aot_resolve_object_relocation_groups(AOTObjectData *obj_data) return false; } while (!LLVMObjectFileIsSectionIteratorAtEnd(obj_data->binary, sec_itr)) { - if (is_relocation_section(sec_itr)) { + if (is_relocation_section(obj_data, sec_itr)) { name = (char *)LLVMGetSectionName(sec_itr); relocation_group->section_name = name; + + if (obj_data->comp_ctx->enable_llvm_pgo + && (!strcmp(name, ".rela__llvm_prf_data") + || !strcmp(name, ".rel__llvm_prf_data"))) { + char buf[32]; + snprintf(buf, sizeof(buf), "%s%u", name, llvm_prf_data_idx); + size = (uint32)(strlen(buf) + 1); + if (!(relocation_group->section_name = + wasm_runtime_malloc(size))) { + aot_set_last_error( + "allocate memory for section name failed."); + LLVMDisposeSectionIterator(sec_itr); + return false; + } + bh_memcpy_s(relocation_group->section_name, size, buf, size); + relocation_group->is_section_name_allocated = true; + } + if (!aot_resolve_object_relocation_group(obj_data, relocation_group, sec_itr)) { LLVMDisposeSectionIterator(sec_itr); return false; } + + if (obj_data->comp_ctx->enable_llvm_pgo + && (!strcmp(name, ".rela__llvm_prf_data") + || !strcmp(name, ".rel__llvm_prf_data"))) { + llvm_prf_data_idx++; + } + + if (!strcmp(relocation_group->section_name, ".rela.text.unlikely.") + || !strcmp(relocation_group->section_name, ".rela.text.hot.")) { + relocation_group->section_name = ".rela.text"; + } + else if (!strcmp(relocation_group->section_name, + ".rel.text.unlikely.") + || !strcmp(relocation_group->section_name, + ".rel.text.hot.")) { + relocation_group->section_name = ".rel.text"; + } + + /* + * Relocations in read-only sections are problematic, + * especially for XIP on platforms which don't have + * copy-on-write mappings. + */ + if (obj_data->comp_ctx->is_indirect_mode + && is_readonly_section(relocation_group->section_name)) { + LOG_WARNING("%" PRIu32 + " text relocations in %s section for indirect mode", + relocation_group->relocation_count, + relocation_group->section_name); + } + relocation_group++; } LLVMMoveToNextSection(sec_itr); @@ -2633,12 +3354,21 @@ static void destroy_relocation_groups(AOTRelocationGroup *relocation_groups, uint32 relocation_group_count) { - uint32 i; + uint32 i, j; AOTRelocationGroup *relocation_group = relocation_groups; - for (i = 0; i < relocation_group_count; i++, relocation_group++) - if (relocation_group->relocations) + for (i = 0; i < relocation_group_count; i++, relocation_group++) { + if (relocation_group->relocations) { + for (j = 0; j < relocation_group->relocation_count; j++) { + if (relocation_group->relocations[j].is_symbol_name_allocated) + wasm_runtime_free( + relocation_group->relocations[j].symbol_name); + } wasm_runtime_free(relocation_group->relocations); + } + if (relocation_group->is_section_name_allocated) + wasm_runtime_free(relocation_group->section_name); + } wasm_runtime_free(relocation_groups); } @@ -2664,13 +3394,27 @@ aot_obj_data_destroy(AOTObjectData *obj_data) LLVMDisposeMemoryBuffer(obj_data->mem_buf); if (obj_data->funcs) wasm_runtime_free(obj_data->funcs); - if (obj_data->data_sections) + if (obj_data->data_sections) { + uint32 i; + for (i = 0; i < obj_data->data_sections_count; i++) { + if (obj_data->data_sections[i].name + && obj_data->data_sections[i].is_name_allocated) { + wasm_runtime_free(obj_data->data_sections[i].name); + } + if (obj_data->data_sections[i].data + && obj_data->data_sections[i].is_data_allocated) { + wasm_runtime_free(obj_data->data_sections[i].data); + } + } wasm_runtime_free(obj_data->data_sections); + } if (obj_data->relocation_groups) destroy_relocation_groups(obj_data->relocation_groups, obj_data->relocation_group_count); if (obj_data->symbol_list.len) destroy_relocation_symbol_list(&obj_data->symbol_list); + if (obj_data->stack_sizes) + wasm_runtime_free(obj_data->stack_sizes); wasm_runtime_free(obj_data); } @@ -2688,6 +3432,7 @@ aot_obj_data_create(AOTCompContext *comp_ctx) return false; } memset(obj_data, 0, sizeof(AOTObjectData)); + obj_data->comp_ctx = comp_ctx; bh_print_time("Begin to emit object file"); if (comp_ctx->external_llc_compiler || comp_ctx->external_asm_compiler) { @@ -2821,8 +3566,8 @@ aot_obj_data_create(AOTCompContext *comp_ctx) if (!aot_resolve_target_info(comp_ctx, obj_data) || !aot_resolve_text(obj_data) || !aot_resolve_literal(obj_data) || !aot_resolve_object_data_sections(obj_data) - || !aot_resolve_object_relocation_groups(obj_data) - || !aot_resolve_functions(comp_ctx, obj_data)) + || !aot_resolve_functions(comp_ctx, obj_data) + || !aot_resolve_object_relocation_groups(obj_data)) goto fail; return obj_data; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_compare.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_compare.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_compare.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_compare.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_compare.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_compare.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_compare.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_compare.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_const.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_const.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_const.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_const.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_const.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_const.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_const.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_const.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_control.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_control.c similarity index 94% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_control.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_control.c index 2cf51cf6727..a8ee938f253 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_control.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_control.c @@ -4,6 +4,7 @@ */ #include "aot_emit_control.h" +#include "aot_compiler.h" #include "aot_emit_exception.h" #include "../aot/aot_runtime.h" #include "../interpreter/wasm_loader.h" @@ -201,6 +202,9 @@ handle_next_reachable_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, *p_frame_ip = block->wasm_code_else + 1; /* Push back the block */ aot_block_stack_push(&func_ctx->block_stack, block); + /* Recover parameters of else branch */ + for (i = 0; i < block->param_count; i++) + PUSH(block->else_param_phis[i], block->param_types[i]); return true; } else if (block->llvm_end_block) { @@ -220,6 +224,19 @@ handle_next_reachable_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return true; } + if (block->label_type == LABEL_TYPE_IF && block->llvm_else_block + && !block->skip_wasm_code_else + && *p_frame_ip <= block->wasm_code_else) { + /* Clear value stack and start to translate else branch */ + aot_value_stack_destroy(&block->value_stack); + /* Recover parameters of else branch */ + for (i = 0; i < block->param_count; i++) + PUSH(block->else_param_phis[i], block->param_types[i]); + SET_BUILDER_POS(block->llvm_else_block); + *p_frame_ip = block->wasm_code_else + 1; + return true; + } + *p_frame_ip = block->wasm_code_end + 1; SET_BUILDER_POS(block->llvm_end_block); @@ -234,13 +251,15 @@ handle_next_reachable_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, else { /* Store extra return values to function parameters */ if (i != 0) { + LLVMValueRef res; uint32 param_index = func_type->param_count + i; - if (!LLVMBuildStore( - comp_ctx->builder, block->result_phis[i], - LLVMGetParam(func_ctx->func, param_index))) { + if (!(res = LLVMBuildStore( + comp_ctx->builder, block->result_phis[i], + LLVMGetParam(func_ctx->func, param_index)))) { aot_set_last_error("llvm build store failed."); goto fail; } + LLVMSetAlignment(res, 1); } } } @@ -278,7 +297,7 @@ push_aot_block_to_stack_and_pass_params(AOTCompContext *comp_ctx, AOTBlock *block) { uint32 i, param_index; - LLVMValueRef value; + LLVMValueRef value, br_inst; uint64 size; char name[32]; LLVMBasicBlockRef block_curr = CURR_BLOCK(); @@ -326,7 +345,14 @@ push_aot_block_to_stack_and_pass_params(AOTCompContext *comp_ctx, } } } - SET_BUILDER_POS(block_curr); + + /* At this point, the branch instruction was already built to jump to + * the new BB, to avoid generating zext instruction from the popped + * operand that would come after branch instruction, we should position + * the builder before the last branch instruction */ + br_inst = LLVMGetLastInstruction(block_curr); + bh_assert(LLVMGetInstructionOpcode(br_inst) == LLVMBr); + LLVMPositionBuilderBefore(comp_ctx->builder, br_inst); /* Pop param values from current block's * value stack and add to param phis. @@ -334,7 +360,9 @@ push_aot_block_to_stack_and_pass_params(AOTCompContext *comp_ctx, for (i = 0; i < block->param_count; i++) { param_index = block->param_count - 1 - i; POP(value, block->param_types[param_index]); - ADD_TO_PARAM_PHIS(block, value, param_index); + if (block->llvm_entry_block) + /* Only add incoming phis if the entry block was created */ + ADD_TO_PARAM_PHIS(block, value, param_index); if (block->label_type == LABEL_TYPE_IF && !block->skip_wasm_code_else) { if (block->llvm_else_block) { @@ -356,7 +384,17 @@ push_aot_block_to_stack_and_pass_params(AOTCompContext *comp_ctx, /* Push param phis to the new block */ for (i = 0; i < block->param_count; i++) { - PUSH(block->param_phis[i], block->param_types[i]); + if (block->llvm_entry_block) + /* Push param phis if the entry basic block was created */ + PUSH(block->param_phis[i], block->param_types[i]); + else { + bh_assert(block->label_type == LABEL_TYPE_IF + && block->llvm_else_block && block->else_param_phis + && !block->skip_wasm_code_else); + /* Push else param phis if we start to translate the + else branch */ + PUSH(block->else_param_phis[i], block->param_types[i]); + } } return true; @@ -467,7 +505,7 @@ aot_compile_op_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, p_frame_ip); } - if (!LLVMIsConstant(value)) { + if (!LLVMIsEfficientConstInt(value)) { /* Compare value is not constant, create condition br IR */ /* Create entry block */ format_block_name(name, sizeof(name), block->block_index, @@ -833,7 +871,7 @@ aot_compile_op_br_if(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return aot_handle_next_reachable_block(comp_ctx, func_ctx, p_frame_ip); } - if (!LLVMIsConstant(value_cmp)) { + if (!LLVMIsEfficientConstInt(value_cmp)) { /* Compare value is not constant, create condition br IR */ if (!(block_dst = get_target_block(func_ctx, br_depth))) { return false; @@ -970,7 +1008,7 @@ aot_compile_op_br_table(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return aot_handle_next_reachable_block(comp_ctx, func_ctx, p_frame_ip); } - if (!LLVMIsConstant(value_cmp)) { + if (!LLVMIsEfficientConstInt(value_cmp)) { /* Compare value is not constant, create switch IR */ for (i = 0; i <= br_count; i++) { target_block = get_target_block(func_ctx, br_depths[i]); @@ -1102,14 +1140,17 @@ aot_compile_op_return(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, if (block_func->result_count) { /* Store extra result values to function parameters */ for (i = 0; i < block_func->result_count - 1; i++) { + LLVMValueRef res; result_index = block_func->result_count - 1 - i; POP(value, block_func->result_types[result_index]); param_index = func_type->param_count + result_index; - if (!LLVMBuildStore(comp_ctx->builder, value, - LLVMGetParam(func_ctx->func, param_index))) { + if (!(res = LLVMBuildStore( + comp_ctx->builder, value, + LLVMGetParam(func_ctx->func, param_index)))) { aot_set_last_error("llvm build store failed."); goto fail; } + LLVMSetAlignment(res, 1); } /* Return the first result value */ POP(value, block_func->result_types[0]); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_control.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_control.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_control.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_control.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_conversion.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_conversion.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_conversion.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_conversion.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_conversion.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_conversion.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_conversion.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_conversion.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_exception.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_exception.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_exception.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_exception.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_exception.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_exception.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_exception.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_exception.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_function.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_function.c similarity index 90% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_function.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_function.c index 9ba8baa24f9..bc8cb0a55a6 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_function.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_function.c @@ -18,6 +18,20 @@ } \ } while (0) +static bool +is_win_platform(AOTCompContext *comp_ctx) +{ + char *triple = LLVMGetTargetMachineTriple(comp_ctx->target_machine); + bool ret; + + bh_assert(triple); + ret = (strstr(triple, "win32") || strstr(triple, "win")) ? true : false; + + LLVMDisposeMessage(triple); + + return ret; +} + static bool create_func_return_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) { @@ -366,143 +380,6 @@ call_aot_free_frame_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) #endif /* end of (WASM_ENABLE_DUMP_CALL_STACK != 0) \ || (WASM_ENABLE_PERF_PROFILING != 0) */ -static bool -record_stack_usage(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - uint32 callee_cell_num) -{ - LLVMBasicBlockRef block_curr = LLVMGetInsertBlock(comp_ctx->builder); - LLVMBasicBlockRef block_update; - LLVMBasicBlockRef block_after_update; - LLVMValueRef callee_local_size, new_sp, cmp; - LLVMValueRef native_stack_top_min; - LLVMTypeRef ptrdiff_type; - if (comp_ctx->pointer_size == sizeof(uint64_t)) { - ptrdiff_type = I64_TYPE; - } - else { - ptrdiff_type = I32_TYPE; - } - - /* - * new_sp = last_alloca - callee_local_size; - * if (*native_stack_top_min_addr > new_sp) { - * *native_stack_top_min_addr = new_sp; - * } - */ - - if (!(callee_local_size = LLVMConstInt( - ptrdiff_type, -(int64_t)callee_cell_num * 4, true))) { - aot_set_last_error("llvm build const failed."); - return false; - } - if (!(new_sp = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, - func_ctx->last_alloca, - &callee_local_size, 1, "new_sp"))) { - aot_set_last_error("llvm build gep failed"); - return false; - } - if (!(native_stack_top_min = LLVMBuildLoad2( - comp_ctx->builder, OPQ_PTR_TYPE, - func_ctx->native_stack_top_min_addr, "native_stack_top_min"))) { - aot_set_last_error("llvm build load failed"); - return false; - } - if (!(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntULT, new_sp, - native_stack_top_min, "cmp"))) { - aot_set_last_error("llvm build icmp failed."); - return false; - } - - if (!(block_update = LLVMAppendBasicBlockInContext( - comp_ctx->context, func_ctx->func, "block_update"))) { - aot_set_last_error("llvm add basic block failed."); - return false; - } - if (!(block_after_update = LLVMAppendBasicBlockInContext( - comp_ctx->context, func_ctx->func, "block_after_update"))) { - aot_set_last_error("llvm add basic block failed."); - return false; - } - LLVMMoveBasicBlockAfter(block_update, block_curr); - LLVMMoveBasicBlockAfter(block_after_update, block_update); - - if (!LLVMBuildCondBr(comp_ctx->builder, cmp, block_update, - block_after_update)) { - aot_set_last_error("llvm build cond br failed."); - return false; - } - - LLVMPositionBuilderAtEnd(comp_ctx->builder, block_update); - if (!LLVMBuildStore(comp_ctx->builder, new_sp, - func_ctx->native_stack_top_min_addr)) { - aot_set_last_error("llvm build store failed"); - return false; - } - if (!LLVMBuildBr(comp_ctx->builder, block_after_update)) { - aot_set_last_error("llvm build br failed."); - return false; - } - - LLVMPositionBuilderAtEnd(comp_ctx->builder, block_after_update); - return true; -} - -static bool -check_stack_boundary(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - uint32 callee_cell_num) -{ - LLVMBasicBlockRef block_curr = LLVMGetInsertBlock(comp_ctx->builder); - LLVMBasicBlockRef check_stack; - LLVMValueRef callee_local_size, stack_bound, cmp; - - if (!(callee_local_size = I32_CONST(callee_cell_num * 4))) { - aot_set_last_error("llvm build const failed."); - return false; - } - - if (!(stack_bound = LLVMBuildInBoundsGEP2( - comp_ctx->builder, INT8_TYPE, func_ctx->native_stack_bound, - &callee_local_size, 1, "stack_bound"))) { - aot_set_last_error("llvm build inbound gep failed."); - return false; - } - - if (!(check_stack = LLVMAppendBasicBlockInContext( - comp_ctx->context, func_ctx->func, "check_stack"))) { - aot_set_last_error("llvm add basic block failed."); - return false; - } - - LLVMMoveBasicBlockAfter(check_stack, block_curr); - - if (!(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntULT, - func_ctx->last_alloca, stack_bound, "cmp"))) { - aot_set_last_error("llvm build icmp failed."); - return false; - } - - if (!aot_emit_exception(comp_ctx, func_ctx, EXCE_NATIVE_STACK_OVERFLOW, - true, cmp, check_stack)) { - return false; - } - - LLVMPositionBuilderAtEnd(comp_ctx->builder, check_stack); - return true; -} - -static bool -check_stack(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - uint32 callee_cell_num) -{ - if (comp_ctx->enable_stack_estimation - && !record_stack_usage(comp_ctx, func_ctx, callee_cell_num)) - return false; - if (comp_ctx->enable_stack_bound_check - && !check_stack_boundary(comp_ctx, func_ctx, callee_cell_num)) - return false; - return true; -} - /** * Check whether the app address and its buffer are inside the linear memory, * if no, throw exception @@ -595,7 +472,7 @@ check_app_addr_and_convert(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, } /* Check whether exception was thrown when executing the function */ - if (comp_ctx->enable_bound_check + if ((comp_ctx->enable_bound_check || is_win_platform(comp_ctx)) && !check_call_return(comp_ctx, func_ctx, res)) { return false; } @@ -610,6 +487,30 @@ check_app_addr_and_convert(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return true; } +static void +aot_estimate_and_record_stack_usage_for_function_call( + const AOTCompContext *comp_ctx, AOTFuncContext *caller_func_ctx, + const AOTFuncType *callee_func_type) +{ + unsigned int size; + + if (!(comp_ctx->enable_stack_bound_check + || comp_ctx->enable_stack_estimation)) { + return; + } + + size = + aot_estimate_stack_usage_for_function_call(comp_ctx, callee_func_type); + /* + * only record the max value, assuming that LLVM emits machine code + * which rewinds the stack before making the next call in the + * function. + */ + if (caller_func_ctx->stack_consumption_for_func_call < size) { + caller_func_ctx->stack_consumption_for_func_call = size; + } +} + bool aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 func_idx, bool tail_call) @@ -620,7 +521,6 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 ext_ret_cell_num = 0, cell_num = 0; AOTFuncContext **func_ctxes = comp_ctx->func_ctxes; AOTFuncType *func_type; - AOTFunc *aot_func; LLVMTypeRef *param_types = NULL, ret_type; LLVMTypeRef ext_ret_ptr_type; LLVMValueRef *param_values = NULL, value_ret = NULL, func; @@ -628,7 +528,6 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMValueRef ext_ret, ext_ret_ptr, ext_ret_idx; int32 i, j = 0, param_count, result_count, ext_ret_count; uint64 total_size; - uint32 callee_cell_num; uint8 wasm_ret_type; uint8 *ext_ret_types = NULL; const char *signature = NULL; @@ -658,6 +557,8 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, func_type = func_ctxes[func_idx - import_func_count]->aot_func->func_type; } + aot_estimate_and_record_stack_usage_for_function_call(comp_ctx, func_ctx, + func_type); /* Get param cell number */ param_cell_num = func_type->param_cell_num; @@ -809,7 +710,7 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, goto fail; /* Check whether there was exception thrown when executing the function */ - if (comp_ctx->enable_bound_check + if ((comp_ctx->enable_bound_check || is_win_platform(comp_ctx)) && !check_call_return(comp_ctx, func_ctx, res)) goto fail; } @@ -868,10 +769,6 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, #if LLVM_VERSION_MAJOR >= 14 LLVMTypeRef llvm_func_type; #endif - bool recursive_call = - (func_ctx == func_ctxes[func_idx - import_func_count]) ? true - : false; - if (comp_ctx->is_indirect_mode) { LLVMTypeRef func_ptr_type; @@ -889,15 +786,17 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, else { if (func_ctxes[func_idx - import_func_count] == func_ctx) { /* recursive call */ - func = func_ctx->func; + func = func_ctx->precheck_func; } else { if (!comp_ctx->is_jit_mode) { - func = func_ctxes[func_idx - import_func_count]->func; + func = + func_ctxes[func_idx - import_func_count]->precheck_func; } else { #if !(WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_LAZY_JIT != 0) - func = func_ctxes[func_idx - import_func_count]->func; + func = + func_ctxes[func_idx - import_func_count]->precheck_func; #else /* JIT tier-up, load func ptr from func_ptrs[func_idx] */ LLVMValueRef func_ptr, func_idx_const; @@ -942,13 +841,6 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, } } - aot_func = func_ctxes[func_idx - import_func_count]->aot_func; - callee_cell_num = - aot_func->param_cell_num + aot_func->local_cell_num + 1; - - if (!check_stack(comp_ctx, func_ctx, callee_cell_num)) - goto fail; - #if LLVM_VERSION_MAJOR >= 14 llvm_func_type = func_ctxes[func_idx - import_func_count]->func_type; #endif @@ -971,7 +863,8 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, /* Check whether there was exception thrown when executing the function */ - if (!tail_call && !recursive_call && comp_ctx->enable_bound_check + if (!tail_call + && (comp_ctx->enable_bound_check || is_win_platform(comp_ctx)) && !check_exception_thrown(comp_ctx, func_ctx)) goto fail; } @@ -1217,6 +1110,8 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, CHECK_LLVM_CONST(ftype_idx_const); func_type = comp_ctx->comp_data->func_types[type_idx]; + aot_estimate_and_record_stack_usage_for_function_call(comp_ctx, func_ctx, + func_type); func_param_count = func_type->param_count; func_result_count = func_type->result_count; @@ -1551,7 +1446,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, goto fail; /* Check whether exception was thrown when executing the function */ - if (comp_ctx->enable_bound_check + if ((comp_ctx->enable_bound_check || is_win_platform(comp_ctx)) && !check_call_return(comp_ctx, func_ctx, res)) goto fail; @@ -1568,13 +1463,6 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, /* Translate call non-import block */ LLVMPositionBuilderAtEnd(comp_ctx->builder, block_call_non_import); - if (!check_stack(comp_ctx, func_ctx, - param_cell_num + ext_cell_num - + 1 - /* Reserve some local variables */ - + 16)) - goto fail; - /* Load function pointer */ if (!(func_ptr = LLVMBuildInBoundsGEP2(comp_ctx->builder, OPQ_PTR_TYPE, func_ctx->func_ptrs, &func_idx, 1, @@ -1610,7 +1498,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, } /* Check whether exception was thrown when executing the function */ - if (comp_ctx->enable_bound_check + if ((comp_ctx->enable_bound_check || is_win_platform(comp_ctx)) && !check_exception_thrown(comp_ctx, func_ctx)) goto fail; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_function.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_function.h similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_function.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_function.h index 26f09c66030..798243e60ef 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_function.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_function.h @@ -29,6 +29,7 @@ aot_compile_op_ref_is_null(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx); bool aot_compile_op_ref_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 func_idx); + #ifdef __cplusplus } /* end of extern "C" */ #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_memory.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_memory.c similarity index 85% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_memory.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_memory.c index 4da4cc807f5..8c35c3fe650 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_memory.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_memory.c @@ -4,6 +4,7 @@ */ #include "aot_emit_memory.h" +#include "aot_compiler.h" #include "aot_emit_exception.h" #include "../aot/aot_runtime.h" #include "aot_intrinsic.h" @@ -81,7 +82,7 @@ get_memory_curr_page_count(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx); LLVMValueRef aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - uint32 offset, uint32 bytes) + uint32 offset, uint32 bytes, bool enable_segue) { LLVMValueRef offset_const = I32_CONST(offset); LLVMValueRef addr, maddr, offset1, cmp1, cmp2, cmp; @@ -145,11 +146,7 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, * have been thrown when converting float to integer before */ /* return addres directly if constant offset and inside memory space */ - if (LLVMIsConstant(addr) && !LLVMIsUndef(addr) -#if LLVM_VERSION_NUMBER >= 12 - && !LLVMIsPoison(addr) -#endif - ) { + if (LLVMIsEfficientConstInt(addr)) { uint64 mem_offset = (uint64)LLVMConstIntGetZExtValue(addr) + (uint64)offset; uint32 num_bytes_per_page = @@ -160,13 +157,25 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, if (mem_offset + bytes <= mem_data_size) { /* inside memory space */ - offset1 = I32_CONST((uint32)mem_offset); + if (comp_ctx->pointer_size == sizeof(uint64)) + offset1 = I64_CONST((uint32)mem_offset); + else + offset1 = I32_CONST((uint32)mem_offset); CHECK_LLVM_CONST(offset1); - if (!(maddr = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, - mem_base_addr, &offset1, 1, - "maddr"))) { - aot_set_last_error("llvm build add failed."); - goto fail; + if (!enable_segue) { + if (!(maddr = LLVMBuildInBoundsGEP2(comp_ctx->builder, + INT8_TYPE, mem_base_addr, + &offset1, 1, "maddr"))) { + aot_set_last_error("llvm build add failed."); + goto fail; + } + } + else { + if (!(maddr = LLVMBuildIntToPtr(comp_ctx->builder, offset1, + INT8_PTR_TYPE_GS, "maddr"))) { + aot_set_last_error("llvm build IntToPtr failed."); + goto fail; + } } return maddr; } @@ -244,11 +253,29 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, } } - /* maddr = mem_base_addr + offset1 */ - if (!(maddr = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, + if (!enable_segue) { + /* maddr = mem_base_addr + offset1 */ + if (!(maddr = + LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, mem_base_addr, &offset1, 1, "maddr"))) { - aot_set_last_error("llvm build add failed."); - goto fail; + aot_set_last_error("llvm build add failed."); + goto fail; + } + } + else { + LLVMValueRef maddr_base; + + if (!(maddr_base = LLVMBuildIntToPtr(comp_ctx->builder, addr, + INT8_PTR_TYPE_GS, "maddr_base"))) { + aot_set_last_error("llvm build int to ptr failed."); + goto fail; + } + if (!(maddr = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, + maddr_base, &offset_const, 1, + "maddr"))) { + aot_set_last_error("llvm build inboundgep failed."); + goto fail; + } } return maddr; fail: @@ -388,13 +415,18 @@ aot_compile_op_i32_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, { LLVMValueRef maddr, value = NULL; LLVMTypeRef data_type; + bool enable_segue = comp_ctx->enable_segue_i32_load; - if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes))) + if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes, + enable_segue))) return false; switch (bytes) { case 4: - BUILD_PTR_CAST(INT32_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT32_PTR_TYPE); + else + BUILD_PTR_CAST(INT32_PTR_TYPE_GS); #if WASM_ENABLE_SHARED_MEMORY != 0 if (atomic) BUILD_ATOMIC_LOAD(align, I32_TYPE); @@ -405,11 +437,17 @@ aot_compile_op_i32_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, case 2: case 1: if (bytes == 2) { - BUILD_PTR_CAST(INT16_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT16_PTR_TYPE); + else + BUILD_PTR_CAST(INT16_PTR_TYPE_GS); data_type = INT16_TYPE; } else { - BUILD_PTR_CAST(INT8_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT8_PTR_TYPE); + else + BUILD_PTR_CAST(INT8_PTR_TYPE_GS); data_type = INT8_TYPE; } @@ -447,13 +485,18 @@ aot_compile_op_i64_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, { LLVMValueRef maddr, value = NULL; LLVMTypeRef data_type; + bool enable_segue = comp_ctx->enable_segue_i64_load; - if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes))) + if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes, + enable_segue))) return false; switch (bytes) { case 8: - BUILD_PTR_CAST(INT64_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT64_PTR_TYPE); + else + BUILD_PTR_CAST(INT64_PTR_TYPE_GS); #if WASM_ENABLE_SHARED_MEMORY != 0 if (atomic) BUILD_ATOMIC_LOAD(align, I64_TYPE); @@ -465,15 +508,24 @@ aot_compile_op_i64_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, case 2: case 1: if (bytes == 4) { - BUILD_PTR_CAST(INT32_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT32_PTR_TYPE); + else + BUILD_PTR_CAST(INT32_PTR_TYPE_GS); data_type = I32_TYPE; } else if (bytes == 2) { - BUILD_PTR_CAST(INT16_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT16_PTR_TYPE); + else + BUILD_PTR_CAST(INT16_PTR_TYPE_GS); data_type = INT16_TYPE; } else { - BUILD_PTR_CAST(INT8_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT8_PTR_TYPE); + else + BUILD_PTR_CAST(INT8_PTR_TYPE_GS); data_type = INT8_TYPE; } @@ -509,12 +561,18 @@ aot_compile_op_f32_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align, uint32 offset) { LLVMValueRef maddr, value; + bool enable_segue = comp_ctx->enable_segue_f32_load; - if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, 4))) + if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, 4, + enable_segue))) return false; - BUILD_PTR_CAST(F32_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(F32_PTR_TYPE); + else + BUILD_PTR_CAST(F32_PTR_TYPE_GS); BUILD_LOAD(F32_TYPE); + PUSH_F32(value); return true; fail: @@ -526,12 +584,18 @@ aot_compile_op_f64_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align, uint32 offset) { LLVMValueRef maddr, value; + bool enable_segue = comp_ctx->enable_segue_f64_load; - if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, 8))) + if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, 8, + enable_segue))) return false; - BUILD_PTR_CAST(F64_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(F64_PTR_TYPE); + else + BUILD_PTR_CAST(F64_PTR_TYPE_GS); BUILD_LOAD(F64_TYPE); + PUSH_F64(value); return true; fail: @@ -543,22 +607,33 @@ aot_compile_op_i32_store(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align, uint32 offset, uint32 bytes, bool atomic) { LLVMValueRef maddr, value; + bool enable_segue = comp_ctx->enable_segue_i32_store; POP_I32(value); - if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes))) + if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes, + enable_segue))) return false; switch (bytes) { case 4: - BUILD_PTR_CAST(INT32_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT32_PTR_TYPE); + else + BUILD_PTR_CAST(INT32_PTR_TYPE_GS); break; case 2: - BUILD_PTR_CAST(INT16_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT16_PTR_TYPE); + else + BUILD_PTR_CAST(INT16_PTR_TYPE_GS); BUILD_TRUNC(value, INT16_TYPE); break; case 1: - BUILD_PTR_CAST(INT8_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT8_PTR_TYPE); + else + BUILD_PTR_CAST(INT8_PTR_TYPE_GS); BUILD_TRUNC(value, INT8_TYPE); break; default: @@ -582,26 +657,40 @@ aot_compile_op_i64_store(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align, uint32 offset, uint32 bytes, bool atomic) { LLVMValueRef maddr, value; + bool enable_segue = comp_ctx->enable_segue_i64_store; POP_I64(value); - if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes))) + if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes, + enable_segue))) return false; switch (bytes) { case 8: - BUILD_PTR_CAST(INT64_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT64_PTR_TYPE); + else + BUILD_PTR_CAST(INT64_PTR_TYPE_GS); break; case 4: - BUILD_PTR_CAST(INT32_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT32_PTR_TYPE); + else + BUILD_PTR_CAST(INT32_PTR_TYPE_GS); BUILD_TRUNC(value, I32_TYPE); break; case 2: - BUILD_PTR_CAST(INT16_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT16_PTR_TYPE); + else + BUILD_PTR_CAST(INT16_PTR_TYPE_GS); BUILD_TRUNC(value, INT16_TYPE); break; case 1: - BUILD_PTR_CAST(INT8_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT8_PTR_TYPE); + else + BUILD_PTR_CAST(INT8_PTR_TYPE_GS); BUILD_TRUNC(value, INT8_TYPE); break; default: @@ -625,13 +714,18 @@ aot_compile_op_f32_store(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align, uint32 offset) { LLVMValueRef maddr, value; + bool enable_segue = comp_ctx->enable_segue_f32_store; POP_F32(value); - if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, 4))) + if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, 4, + enable_segue))) return false; - BUILD_PTR_CAST(F32_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(F32_PTR_TYPE); + else + BUILD_PTR_CAST(F32_PTR_TYPE_GS); BUILD_STORE(); return true; fail: @@ -643,13 +737,18 @@ aot_compile_op_f64_store(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align, uint32 offset) { LLVMValueRef maddr, value; + bool enable_segue = comp_ctx->enable_segue_f64_store; POP_F64(value); - if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, 8))) + if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, 8, + enable_segue))) return false; - BUILD_PTR_CAST(F64_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(F64_PTR_TYPE); + else + BUILD_PTR_CAST(F64_PTR_TYPE_GS); BUILD_STORE(); return true; fail: @@ -812,11 +911,7 @@ check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, * have been thrown when converting float to integer before */ /* return addres directly if constant offset and inside memory space */ - if (!LLVMIsUndef(offset) && !LLVMIsUndef(bytes) -#if LLVM_VERSION_NUMBER >= 12 - && !LLVMIsPoison(offset) && !LLVMIsPoison(bytes) -#endif - && LLVMIsConstant(offset) && LLVMIsConstant(bytes)) { + if (LLVMIsEfficientConstInt(offset) && LLVMIsEfficientConstInt(bytes)) { uint64 mem_offset = (uint64)LLVMConstIntGetZExtValue(offset); uint64 mem_len = (uint64)LLVMConstIntGetZExtValue(bytes); uint32 num_bytes_per_page = @@ -1140,13 +1235,19 @@ aot_compile_op_atomic_rmw(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 offset, uint32 bytes) { LLVMValueRef maddr, value, result; + bool enable_segue = (op_type == VALUE_TYPE_I32) + ? comp_ctx->enable_segue_i32_load + && comp_ctx->enable_segue_i32_store + : comp_ctx->enable_segue_i64_load + && comp_ctx->enable_segue_i64_store; if (op_type == VALUE_TYPE_I32) POP_I32(value); else POP_I64(value); - if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes))) + if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes, + enable_segue))) return false; if (!check_memory_alignment(comp_ctx, func_ctx, maddr, align)) @@ -1154,19 +1255,31 @@ aot_compile_op_atomic_rmw(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, switch (bytes) { case 8: - BUILD_PTR_CAST(INT64_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT64_PTR_TYPE); + else + BUILD_PTR_CAST(INT64_PTR_TYPE_GS); break; case 4: - BUILD_PTR_CAST(INT32_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT32_PTR_TYPE); + else + BUILD_PTR_CAST(INT32_PTR_TYPE_GS); if (op_type == VALUE_TYPE_I64) BUILD_TRUNC(value, I32_TYPE); break; case 2: - BUILD_PTR_CAST(INT16_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT16_PTR_TYPE); + else + BUILD_PTR_CAST(INT16_PTR_TYPE_GS); BUILD_TRUNC(value, INT16_TYPE); break; case 1: - BUILD_PTR_CAST(INT8_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT8_PTR_TYPE); + else + BUILD_PTR_CAST(INT8_PTR_TYPE_GS); BUILD_TRUNC(value, INT8_TYPE); break; default: @@ -1208,6 +1321,11 @@ aot_compile_op_atomic_cmpxchg(AOTCompContext *comp_ctx, uint32 align, uint32 offset, uint32 bytes) { LLVMValueRef maddr, value, expect, result; + bool enable_segue = (op_type == VALUE_TYPE_I32) + ? comp_ctx->enable_segue_i32_load + && comp_ctx->enable_segue_i32_store + : comp_ctx->enable_segue_i64_load + && comp_ctx->enable_segue_i64_store; if (op_type == VALUE_TYPE_I32) { POP_I32(value); @@ -1218,7 +1336,8 @@ aot_compile_op_atomic_cmpxchg(AOTCompContext *comp_ctx, POP_I64(expect); } - if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes))) + if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes, + enable_segue))) return false; if (!check_memory_alignment(comp_ctx, func_ctx, maddr, align)) @@ -1226,22 +1345,34 @@ aot_compile_op_atomic_cmpxchg(AOTCompContext *comp_ctx, switch (bytes) { case 8: - BUILD_PTR_CAST(INT64_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT64_PTR_TYPE); + else + BUILD_PTR_CAST(INT64_PTR_TYPE_GS); break; case 4: - BUILD_PTR_CAST(INT32_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT32_PTR_TYPE); + else + BUILD_PTR_CAST(INT32_PTR_TYPE_GS); if (op_type == VALUE_TYPE_I64) { BUILD_TRUNC(value, I32_TYPE); BUILD_TRUNC(expect, I32_TYPE); } break; case 2: - BUILD_PTR_CAST(INT16_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT16_PTR_TYPE); + else + BUILD_PTR_CAST(INT16_PTR_TYPE_GS); BUILD_TRUNC(value, INT16_TYPE); BUILD_TRUNC(expect, INT16_TYPE); break; case 1: - BUILD_PTR_CAST(INT8_PTR_TYPE); + if (!enable_segue) + BUILD_PTR_CAST(INT8_PTR_TYPE); + else + BUILD_PTR_CAST(INT8_PTR_TYPE_GS); BUILD_TRUNC(value, INT8_TYPE); BUILD_TRUNC(expect, INT8_TYPE); break; @@ -1318,7 +1449,8 @@ aot_compile_op_atomic_wait(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, CHECK_LLVM_CONST(is_wait64); - if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes))) + if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes, + false))) return false; if (!check_memory_alignment(comp_ctx, func_ctx, maddr, align)) @@ -1393,7 +1525,8 @@ aot_compiler_op_atomic_notify(AOTCompContext *comp_ctx, POP_I32(count); - if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes))) + if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes, + false))) return false; if (!check_memory_alignment(comp_ctx, func_ctx, maddr, align)) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_memory.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_memory.h similarity index 97% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_memory.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_memory.h index e49582e3c0c..1c2db503a85 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_memory.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_memory.h @@ -53,7 +53,7 @@ aot_compile_op_f64_store(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMValueRef aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - uint32 offset, uint32 bytes); + uint32 offset, uint32 bytes, bool enable_segue); bool aot_compile_op_memory_size(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_numberic.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_numberic.c similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_numberic.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_numberic.c index 4c63e8a40be..8b6ec02d64b 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_numberic.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_numberic.c @@ -54,13 +54,13 @@ } while (0) #if LLVM_VERSION_NUMBER >= 12 -#define IS_CONST_ZERO(val) \ - (!LLVMIsUndef(val) && !LLVMIsPoison(val) && LLVMIsConstant(val) \ - && ((is_i32 && (int32)LLVMConstIntGetZExtValue(val) == 0) \ +#define IS_CONST_ZERO(val) \ + (LLVMIsEfficientConstInt(val) \ + && ((is_i32 && (int32)LLVMConstIntGetZExtValue(val) == 0) \ || (!is_i32 && (int64)LLVMConstIntGetSExtValue(val) == 0))) #else #define IS_CONST_ZERO(val) \ - (!LLVMIsUndef(val) && LLVMIsConstant(val) \ + (LLVMIsEfficientConstInt(val) \ && ((is_i32 && (int32)LLVMConstIntGetZExtValue(val) == 0) \ || (!is_i32 && (int64)LLVMConstIntGetSExtValue(val) == 0))) #endif @@ -473,7 +473,7 @@ compile_int_div(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return aot_handle_next_reachable_block(comp_ctx, func_ctx, p_frame_ip); } - if (LLVMIsConstant(right)) { + if (LLVMIsEfficientConstInt(right)) { int64 right_val = (int64)LLVMConstIntGetSExtValue(right); switch (right_val) { case 0: @@ -728,9 +728,7 @@ compile_int_shl(AOTCompContext *comp_ctx, LLVMValueRef left, LLVMValueRef right, { LLVMValueRef res; - if (strcmp(comp_ctx->target_arch, "x86_64") != 0 - && strcmp(comp_ctx->target_arch, "i386") != 0) - SHIFT_COUNT_MASK; + SHIFT_COUNT_MASK; /* Build shl */ LLVM_BUILD_OP(Shl, left, right, res, "shl", NULL); @@ -744,9 +742,7 @@ compile_int_shr_s(AOTCompContext *comp_ctx, LLVMValueRef left, { LLVMValueRef res; - if (strcmp(comp_ctx->target_arch, "x86_64") != 0 - && strcmp(comp_ctx->target_arch, "i386") != 0) - SHIFT_COUNT_MASK; + SHIFT_COUNT_MASK; /* Build shl */ LLVM_BUILD_OP(AShr, left, right, res, "shr_s", NULL); @@ -760,9 +756,7 @@ compile_int_shr_u(AOTCompContext *comp_ctx, LLVMValueRef left, { LLVMValueRef res; - if (strcmp(comp_ctx->target_arch, "x86_64") != 0 - && strcmp(comp_ctx->target_arch, "i386") != 0) - SHIFT_COUNT_MASK; + SHIFT_COUNT_MASK; /* Build shl */ LLVM_BUILD_OP(LShr, left, right, res, "shr_u", NULL); @@ -783,17 +777,25 @@ compile_int_rot(AOTCompContext *comp_ctx, LLVMValueRef left, LLVMValueRef right, if (IS_CONST_ZERO(right)) return left; - /* Calculate (bits - shif_count) */ + /* Calculate (bits - shift_count) */ LLVM_BUILD_OP(Sub, is_i32 ? I32_32 : I64_64, right, bits_minus_shift_count, "bits_minus_shift_count", NULL); + /* Calculate (bits - shift_count) & mask */ + bits_minus_shift_count = + LLVMBuildAnd(comp_ctx->builder, bits_minus_shift_count, + is_i32 ? I32_31 : I64_63, "bits_minus_shift_count_and"); + if (!bits_minus_shift_count) { + aot_set_last_error("llvm build and failed."); + return NULL; + } if (is_rotl) { - /* left<>(BITS-count) */ + /* (left << count) | (left >> ((BITS - count) & mask)) */ LLVM_BUILD_OP(Shl, left, right, tmp_l, "tmp_l", NULL); LLVM_BUILD_OP(LShr, left, bits_minus_shift_count, tmp_r, "tmp_r", NULL); } else { - /* left>>count | left<<(BITS-count) */ + /* (left >> count) | (left << ((BITS - count) & mask)) */ LLVM_BUILD_OP(LShr, left, right, tmp_l, "tmp_l", NULL); LLVM_BUILD_OP(Shl, left, bits_minus_shift_count, tmp_r, "tmp_r", NULL); } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_numberic.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_numberic.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_numberic.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_numberic.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_parametric.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_parametric.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_parametric.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_parametric.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_parametric.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_parametric.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_parametric.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_parametric.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_table.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_table.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_table.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_table.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_table.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_table.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_table.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_table.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_variable.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_variable.c similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_variable.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_variable.c index 70487d4dedb..31d803553a4 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_variable.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_variable.c @@ -112,7 +112,7 @@ static bool compile_global(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 global_idx, bool is_set, bool is_aux_stack) { - AOTCompData *comp_data = comp_ctx->comp_data; + const AOTCompData *comp_data = comp_ctx->comp_data; uint32 import_global_count = comp_data->import_global_count; uint32 global_base_offset; uint32 global_offset; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_variable.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_variable.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_emit_variable.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_emit_variable.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm.c similarity index 74% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm.c index dc3fe7f5959..bbf16f55c49 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm.c @@ -7,6 +7,7 @@ #include "aot_llvm_extra2.h" #include "aot_compiler.h" #include "aot_emit_exception.h" +#include "aot_emit_table.h" #include "../aot/aot_runtime.h" #include "../aot/aot_intrinsic.h" @@ -14,8 +15,17 @@ #include "debug/dwarf_extractor.h" #endif +static bool +create_native_symbol(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx); +static bool +create_native_stack_bound(const AOTCompContext *comp_ctx, + AOTFuncContext *func_ctx); +static bool +create_native_stack_top_min(const AOTCompContext *comp_ctx, + AOTFuncContext *func_ctx); + LLVMTypeRef -wasm_type_to_llvm_type(AOTLLVMTypes *llvm_types, uint8 wasm_type) +wasm_type_to_llvm_type(const AOTLLVMTypes *llvm_types, uint8 wasm_type) { switch (wasm_type) { case VALUE_TYPE_I32: @@ -38,17 +48,533 @@ wasm_type_to_llvm_type(AOTLLVMTypes *llvm_types, uint8 wasm_type) return NULL; } +static LLVMValueRef +aot_add_llvm_func1(const AOTCompContext *comp_ctx, LLVMModuleRef module, + uint32 func_index, uint32 param_count, LLVMTypeRef func_type, + const char *prefix) +{ + char func_name[48]; + LLVMValueRef func; + LLVMValueRef local_value; + uint32 i, j; + + /* Add LLVM function */ + snprintf(func_name, sizeof(func_name), "%s%d", prefix, func_index); + if (!(func = LLVMAddFunction(module, func_name, func_type))) { + aot_set_last_error("add LLVM function failed."); + return NULL; + } + + j = 0; + local_value = LLVMGetParam(func, j++); + LLVMSetValueName(local_value, "exec_env"); + + /* Set parameter names */ + for (i = 0; i < param_count; i++) { + local_value = LLVMGetParam(func, j++); + LLVMSetValueName(local_value, ""); + } + + return func; +} + +/* + * create a basic func_ctx enough to call aot_emit_exception. + * + * that is: + * - exec_env + * - aot_inst + * - native_symbol (if is_indirect_mode) + */ +static bool +create_basic_func_context(const AOTCompContext *comp_ctx, + AOTFuncContext *func_ctx) +{ + LLVMValueRef aot_inst_offset = I32_TWO, aot_inst_addr; + + /* Save the pameters for fast access */ + func_ctx->exec_env = LLVMGetParam(func_ctx->func, 0); + + /* Get aot inst address, the layout of exec_env is: + exec_env->next, exec_env->prev, exec_env->module_inst, and argv_buf */ + if (!(aot_inst_addr = LLVMBuildInBoundsGEP2( + comp_ctx->builder, OPQ_PTR_TYPE, func_ctx->exec_env, + &aot_inst_offset, 1, "aot_inst_addr"))) { + aot_set_last_error("llvm build in bounds gep failed"); + goto fail; + } + + /* Load aot inst */ + if (!(func_ctx->aot_inst = LLVMBuildLoad2(comp_ctx->builder, OPQ_PTR_TYPE, + aot_inst_addr, "aot_inst"))) { + aot_set_last_error("llvm build load failed"); + goto fail; + } + + if (comp_ctx->is_indirect_mode + && !create_native_symbol(comp_ctx, func_ctx)) { + goto fail; + } + + return true; +fail: + return false; +} + +/* + * return if the "precheck" wrapper function can use tail call optimization + */ +bool +aot_target_precheck_can_use_musttail(const AOTCompContext *comp_ctx) +{ + if (!strcmp(comp_ctx->target_arch, "xtensa")) { + /* + * xtensa windowed ABI doesn't have tail call optimization. + * + * Note: as of writing this, the xtensa version of LLVM + * simply ignores the musttail attribute. + * https://github.com/espressif/llvm-project/pull/73 + */ + return false; + } + if (!strcmp(comp_ctx->target_arch, "riscv32") + || !strcmp(comp_ctx->target_arch, "riscv64")) { + /* + * REVISIT: actually, riscv can use tail call optimization + * in some cases. I (yamamoto) don't know the exact conditions + * though. + */ + return false; + } + if (!strcmp(comp_ctx->target_arch, "mips")) { + /* + * cf. + * https://github.com/bytecodealliance/wasm-micro-runtime/issues/2412 + */ + return false; + } + if (strstr(comp_ctx->target_arch, "thumb")) { + /* + * cf. + * https://github.com/bytecodealliance/wasm-micro-runtime/issues/2412 + */ + return false; + } + /* + * x86-64/i386: true + * + * others: assume true for now + */ + return true; +} + +unsigned int +aot_estimate_stack_usage_for_function_call(const AOTCompContext *comp_ctx, + const AOTFuncType *callee_func_type) +{ + /* + * Estimate how much stack is necessary to make a function call. + * This does not include the stack consumption of the callee function. + * + * For precise estimation, ideally this function needs to be + * target-specific. + * However, this implementation aims to be target-independent, + * allowing a small overstimation, which is probably ok for our purpose. + * (overflow detection and memory profiling) + * On the other hand, an underestimation should be avoided as it + * can cause more serious problems like silent data corruptions. + * + * Assumptions: + * + * - the first result is returned via a register. + * + * - all parameters, including exec_env and pointers to non-first + * results, are passed via stack. + * (this is a bit pessimistic than many of real calling conventions, + * where some of parameters are passed via register.) + * + * - N-byte value needs N-byte alignment on stack. + * + * - a value smaller than a pointer is extended. + * (eg. 4 byte values are extended to 8 byte on x86-64.) + */ + + const unsigned int param_count = callee_func_type->param_count; + const unsigned int result_count = callee_func_type->result_count; + unsigned int size = 0; + unsigned int i; + unsigned int nb; + + if (!strcmp(comp_ctx->target_arch, "xtensa")) { + /* + * In the xtensa windowed ABI, outgoing arguments are already + * included in the callee's stack frame size, which equals to + * the operand of the ENTRY instruction and what LLVM + * MFI->getStackSize returns. + */ + return 0; + } + + /* exec_env */ + size = comp_ctx->pointer_size; + + /* parameters */ + for (i = 0; i < param_count; i++) { + nb = wasm_value_type_cell_num(callee_func_type->types[i]) * 4; + if (nb < comp_ctx->pointer_size) { + nb = comp_ctx->pointer_size; + } + size = align_uint(size, nb) + nb; + } + + /* pointers to results */ + nb = comp_ctx->pointer_size; + for (i = 1; i < result_count; i++) { + size = align_uint(size, nb) + nb; + } + + /* return address */ + nb = comp_ctx->pointer_size; + size = align_uint(size, nb) + nb; + + /* + * some extra for possible arch-dependent things like + * 16-byte alignment for x86_64. + */ + size += 16; + return size; +} + +static uint32 +get_inst_extra_offset(AOTCompContext *comp_ctx) +{ + const AOTCompData *comp_data = comp_ctx->comp_data; + uint32 table_count = comp_data->import_table_count + comp_data->table_count; + uint64 offset = get_tbl_inst_offset(comp_ctx, NULL, table_count); + uint32 offset_32 = (uint32)offset; + bh_assert(offset <= UINT32_MAX); + offset_32 = align_uint((uint32)offset_32, 8); + return offset_32; +} + +/* + * a "precheck" function performs a few things before calling wrapped_func. + * + * - update native_stack_top_min if necessary + * - stack overflow check (if it does, trap) + */ +static LLVMValueRef +aot_add_precheck_function(AOTCompContext *comp_ctx, LLVMModuleRef module, + uint32 func_index, uint32 orig_param_count, + LLVMTypeRef func_type, LLVMValueRef wrapped_func) +{ + LLVMValueRef precheck_func; + LLVMBasicBlockRef begin = NULL; + LLVMBasicBlockRef check_top_block = NULL; + LLVMBasicBlockRef update_top_block = NULL; + LLVMBasicBlockRef stack_bound_check_block = NULL; + LLVMBasicBlockRef call_wrapped_func_block = NULL; + LLVMValueRef *params = NULL; + + precheck_func = + aot_add_llvm_func1(comp_ctx, module, func_index, orig_param_count, + func_type, AOT_FUNC_PREFIX); + if (!precheck_func) { + goto fail; + } + begin = LLVMAppendBasicBlockInContext(comp_ctx->context, precheck_func, + "begin"); + check_top_block = LLVMAppendBasicBlockInContext( + comp_ctx->context, precheck_func, "check_top_block"); + if (comp_ctx->enable_stack_estimation) { + update_top_block = LLVMAppendBasicBlockInContext( + comp_ctx->context, precheck_func, "update_top_block"); + if (!update_top_block) { + goto fail; + } + } + stack_bound_check_block = LLVMAppendBasicBlockInContext( + comp_ctx->context, precheck_func, "stack_bound_check_block"); + call_wrapped_func_block = LLVMAppendBasicBlockInContext( + comp_ctx->context, precheck_func, "call_wrapped_func"); + if (!begin || !check_top_block || !stack_bound_check_block + || !call_wrapped_func_block) { + goto fail; + } + LLVMBuilderRef b = comp_ctx->builder; + LLVMPositionBuilderAtEnd(b, begin); + + /* create a temporary minimum func_ctx */ + AOTFuncContext tmp; + AOTFuncContext *func_ctx = &tmp; + memset(func_ctx, 0, sizeof(*func_ctx)); + func_ctx->func = precheck_func; + func_ctx->module = module; + func_ctx->aot_func = comp_ctx->comp_data->funcs[func_index]; +#if WASM_ENABLE_DEBUG_AOT != 0 + func_ctx->debug_func = NULL; +#endif + if (!create_basic_func_context(comp_ctx, func_ctx)) + goto fail; + if (comp_ctx->enable_stack_bound_check + && !create_native_stack_bound(comp_ctx, func_ctx)) + goto fail; + if (comp_ctx->enable_stack_estimation + && !create_native_stack_top_min(comp_ctx, func_ctx)) { + goto fail; + } + + uint32 param_count = LLVMCountParams(precheck_func); + uint32 sz = param_count * (uint32)sizeof(LLVMValueRef); + params = wasm_runtime_malloc(sz); + if (params == NULL) { + goto fail; + } + LLVMGetParams(precheck_func, params); + + const bool is_64bit = comp_ctx->pointer_size == sizeof(uint64); + LLVMTypeRef uintptr_type; + if (is_64bit) + uintptr_type = I64_TYPE; + else + uintptr_type = I32_TYPE; + + /* + * load the stack pointer + */ + LLVMValueRef sp_ptr = LLVMBuildAlloca(b, I32_TYPE, "sp_ptr"); + if (!sp_ptr) { + goto fail; + } + LLVMValueRef sp = LLVMBuildPtrToInt(b, sp_ptr, uintptr_type, "sp"); + if (!sp) { + goto fail; + } + + /* + * load the value for this wrapped function from the stack_sizes array + */ + LLVMValueRef stack_sizes; + if (comp_ctx->is_indirect_mode) { + uint32 offset_u32; + LLVMValueRef offset; + LLVMValueRef stack_sizes_p; + + offset_u32 = get_inst_extra_offset(comp_ctx); + offset_u32 += offsetof(AOTModuleInstanceExtra, stack_sizes); + offset = I32_CONST(offset_u32); + if (!offset) { + goto fail; + } + stack_sizes_p = + LLVMBuildInBoundsGEP2(b, INT8_TYPE, func_ctx->aot_inst, &offset, 1, + "aot_inst_stack_sizes_p"); + if (!stack_sizes_p) { + goto fail; + } + stack_sizes = + LLVMBuildLoad2(b, INT32_PTR_TYPE, stack_sizes_p, "stack_sizes"); + if (!stack_sizes) { + goto fail; + } + } + else { + stack_sizes = comp_ctx->stack_sizes; + } + LLVMValueRef func_index_const = I32_CONST(func_index); + LLVMValueRef sizes = + LLVMBuildBitCast(b, stack_sizes, INT32_PTR_TYPE, "sizes"); + if (!sizes) { + goto fail; + } + LLVMValueRef sizep = LLVMBuildInBoundsGEP2(b, I32_TYPE, sizes, + &func_index_const, 1, "sizep"); + if (!sizep) { + goto fail; + } + LLVMValueRef size32 = LLVMBuildLoad2(b, I32_TYPE, sizep, "size32"); + if (!size32) { + goto fail; + } + LLVMValueRef size; + if (is_64bit) { + size = LLVMBuildZExt(b, size32, uintptr_type, "size"); + if (!size) { + goto fail; + } + } + else { + size = size32; + } + /* + * calculate new sp + */ + LLVMValueRef underflow = + LLVMBuildICmp(b, LLVMIntULT, sp, size, "underflow"); + if (!underflow) { + goto fail; + } + LLVMValueRef new_sp = LLVMBuildSub(b, sp, size, "new_sp"); + if (!new_sp) { + goto fail; + } + if (!LLVMBuildBr(b, check_top_block)) { + goto fail; + } + + LLVMPositionBuilderAtEnd(b, check_top_block); + if (comp_ctx->enable_stack_estimation) { + /* + * load native_stack_top_min from the exec_env + */ + LLVMValueRef top_min = + LLVMBuildLoad2(b, OPQ_PTR_TYPE, func_ctx->native_stack_top_min_addr, + "native_stack_top_min"); + if (!top_min) { + goto fail; + } + LLVMValueRef top_min_int = LLVMBuildPtrToInt( + b, top_min, uintptr_type, "native_stack_top_min_int"); + if (!top_min_int) { + goto fail; + } + + bh_assert(update_top_block); + + /* + * update native_stack_top_min if + * new_sp = sp - size < native_stack_top_min + * + * Note: unless the stack has already overflown in this exec_env, + * native_stack_bound <= native_stack_top_min + */ + LLVMValueRef cmp_top = + LLVMBuildICmp(b, LLVMIntULT, new_sp, top_min_int, "cmp_top"); + if (!cmp_top) { + goto fail; + } + cmp_top = LLVMBuildOr(b, underflow, cmp_top, "cmp_top2"); + if (!cmp_top) { + goto fail; + } + if (!LLVMBuildCondBr(b, cmp_top, update_top_block, + call_wrapped_func_block)) { + aot_set_last_error("llvm build cond br failed."); + goto fail; + } + + /* + * update native_stack_top_min + */ + LLVMPositionBuilderAtEnd(b, update_top_block); + LLVMValueRef new_sp_ptr = + LLVMBuildIntToPtr(b, new_sp, INT8_PTR_TYPE, "new_sp_ptr"); + if (!new_sp_ptr) { + goto fail; + } + if (!LLVMBuildStore(b, new_sp_ptr, + func_ctx->native_stack_top_min_addr)) { + goto fail; + } + if (!LLVMBuildBr(b, stack_bound_check_block)) { + goto fail; + } + } + else { + if (!LLVMBuildBr(b, stack_bound_check_block)) { + goto fail; + } + } + + LLVMPositionBuilderAtEnd(b, stack_bound_check_block); + if (comp_ctx->enable_stack_bound_check) { + /* + * trap if new_sp < native_stack_bound + */ + LLVMValueRef bound_int = LLVMBuildPtrToInt( + b, func_ctx->native_stack_bound, uintptr_type, "bound_base_int"); + if (!bound_int) { + goto fail; + } + LLVMValueRef cmp = + LLVMBuildICmp(b, LLVMIntULT, new_sp, bound_int, "cmp"); + if (!cmp) { + goto fail; + } + cmp = LLVMBuildOr(b, underflow, cmp, "cmp2"); + if (!cmp) { + goto fail; + } + /* todo: @llvm.expect.i1(i1 %cmp, i1 0) */ + if (!aot_emit_exception(comp_ctx, func_ctx, EXCE_NATIVE_STACK_OVERFLOW, + true, cmp, call_wrapped_func_block)) + goto fail; + } + else { + if (!LLVMBuildBr(b, call_wrapped_func_block)) { + goto fail; + } + } + + /* + * call the wrapped function + * use a tail-call if possible + */ + LLVMPositionBuilderAtEnd(b, call_wrapped_func_block); + const char *name = "tail_call"; + LLVMTypeRef ret_type = LLVMGetReturnType(func_type); + if (ret_type == VOID_TYPE) { + name = ""; + } + LLVMValueRef retval = + LLVMBuildCall2(b, func_type, wrapped_func, params, param_count, name); + if (!retval) { + goto fail; + } + wasm_runtime_free(params); + params = NULL; + +#if LLVM_VERSION_MAJOR < 17 + if (aot_target_precheck_can_use_musttail(comp_ctx)) { + LLVMSetTailCallKind(retval, LLVMTailCallKindMustTail); + } + else { + LLVMSetTailCallKind(retval, LLVMTailCallKindTail); + } +#else + LLVMSetTailCall(retval, true); +#endif + + if (ret_type == VOID_TYPE) { + if (!LLVMBuildRetVoid(b)) { + goto fail; + } + } + else { + if (!LLVMBuildRet(b, retval)) { + goto fail; + } + } + + return precheck_func; +fail: + if (params != NULL) { + wasm_runtime_free(params); + } + aot_set_last_error("failed to build precheck wrapper function."); + return NULL; +} + /** * Add LLVM function */ static LLVMValueRef aot_add_llvm_func(AOTCompContext *comp_ctx, LLVMModuleRef module, - AOTFuncType *aot_func_type, uint32 func_index, - LLVMTypeRef *p_func_type) + const AOTFuncType *aot_func_type, uint32 func_index, + LLVMTypeRef *p_func_type, LLVMValueRef *p_precheck_func) { LLVMValueRef func = NULL; LLVMTypeRef *param_types, ret_type, func_type; - LLVMValueRef local_value; LLVMTypeRef func_type_wrapper; LLVMValueRef func_wrapper; LLVMBasicBlockRef func_begin; @@ -101,21 +627,67 @@ aot_add_llvm_func(AOTCompContext *comp_ctx, LLVMModuleRef module, goto fail; } - /* Add LLVM function */ - snprintf(func_name, sizeof(func_name), "%s%d", AOT_FUNC_PREFIX, func_index); - if (!(func = LLVMAddFunction(module, func_name, func_type))) { - aot_set_last_error("add LLVM function failed."); + bh_assert(func_index < comp_ctx->func_ctx_count); + bh_assert(LLVMGetReturnType(func_type) == ret_type); + const char *prefix = AOT_FUNC_PREFIX; + const bool need_precheck = + comp_ctx->enable_stack_bound_check || comp_ctx->enable_stack_estimation; + if (need_precheck) { + /* + * REVISIT: probably this breaks windows hw bound check + * (the RtlAddFunctionTable stuff) + */ + prefix = AOT_FUNC_INTERNAL_PREFIX; + } + if (!(func = aot_add_llvm_func1(comp_ctx, module, func_index, + aot_func_type->param_count, func_type, + prefix))) goto fail; + + if (comp_ctx->is_indirect_mode) { + /* avoid LUT relocations ("switch-table") */ + LLVMAttributeRef attr_no_jump_tables = LLVMCreateStringAttribute( + comp_ctx->context, "no-jump-tables", + (uint32)strlen("no-jump-tables"), "true", (uint32)strlen("true")); + LLVMAddAttributeAtIndex(func, LLVMAttributeFunctionIndex, + attr_no_jump_tables); + } + + /* spread fp.all to every function */ + if (comp_ctx->emit_frame_pointer) { + const char *key = "frame-pointer"; + const char *val = "all"; + LLVMAttributeRef no_omit_fp = LLVMCreateStringAttribute( + comp_ctx->context, key, (unsigned)strlen(key), val, + (unsigned)strlen(val)); + if (!no_omit_fp) { + aot_set_last_error("create LLVM attribute (frame-pointer) failed."); + goto fail; + } + LLVMAddAttributeAtIndex(func, LLVMAttributeFunctionIndex, no_omit_fp); } - j = 0; - local_value = LLVMGetParam(func, j++); - LLVMSetValueName(local_value, "exec_env"); + if (need_precheck) { + if (!comp_ctx->is_jit_mode) + LLVMSetLinkage(func, LLVMInternalLinkage); + unsigned int kind = + LLVMGetEnumAttributeKindForName("noinline", strlen("noinline")); + LLVMAttributeRef attr_noinline = + LLVMCreateEnumAttribute(comp_ctx->context, kind, 0); + LLVMAddAttributeAtIndex(func, LLVMAttributeFunctionIndex, + attr_noinline); - /* Set parameter names */ - for (i = 0; i < aot_func_type->param_count; i++) { - local_value = LLVMGetParam(func, j++); - LLVMSetValueName(local_value, ""); + LLVMValueRef precheck_func = aot_add_precheck_function( + comp_ctx, module, func_index, aot_func_type->param_count, func_type, + func); + if (!precheck_func) + goto fail; + LLVMAddAttributeAtIndex(precheck_func, LLVMAttributeFunctionIndex, + attr_noinline); + *p_precheck_func = precheck_func; + } + else { + *p_precheck_func = func; } if (p_func_type) @@ -177,8 +749,9 @@ free_block_memory(AOTBlock *block) * Create first AOTBlock, or function block for the function */ static AOTBlock * -aot_create_func_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - AOTFunc *func, AOTFuncType *aot_func_type) +aot_create_func_block(const AOTCompContext *comp_ctx, + const AOTFuncContext *func_ctx, const AOTFunc *func, + const AOTFuncType *aot_func_type) { AOTBlock *aot_block; uint32 param_count = aot_func_type->param_count, @@ -266,7 +839,8 @@ create_argv_buf(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) } static bool -create_native_stack_bound(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) +create_native_stack_bound(const AOTCompContext *comp_ctx, + AOTFuncContext *func_ctx) { LLVMValueRef stack_bound_offset = I32_FOUR, stack_bound_addr; @@ -288,7 +862,8 @@ create_native_stack_bound(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) } static bool -create_native_stack_top_min(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) +create_native_stack_top_min(const AOTCompContext *comp_ctx, + AOTFuncContext *func_ctx) { LLVMValueRef offset = I32_NINE; @@ -303,7 +878,7 @@ create_native_stack_top_min(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) } static bool -create_aux_stack_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) +create_aux_stack_info(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) { LLVMValueRef aux_stack_bound_offset = I32_SIX, aux_stack_bound_addr; LLVMValueRef aux_stack_bottom_offset = I32_SEVEN, aux_stack_bottom_addr; @@ -355,7 +930,7 @@ create_aux_stack_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) } static bool -create_native_symbol(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) +create_native_symbol(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) { LLVMValueRef native_symbol_offset = I32_EIGHT, native_symbol_addr; @@ -384,8 +959,9 @@ create_native_symbol(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) } static bool -create_local_variables(AOTCompData *comp_data, AOTCompContext *comp_ctx, - AOTFuncContext *func_ctx, AOTFunc *func) +create_local_variables(const AOTCompData *comp_data, + const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, + const AOTFunc *func) { AOTFuncType *aot_func_type = comp_data->func_types[func->func_type_index]; char local_name[32]; @@ -450,32 +1026,11 @@ create_local_variables(AOTCompData *comp_data, AOTCompContext *comp_ctx, } } - if (comp_ctx->enable_stack_bound_check - || comp_ctx->enable_stack_estimation) { - if (aot_func_type->param_count + func->local_count > 0) { - func_ctx->last_alloca = func_ctx->locals[aot_func_type->param_count - + func->local_count - 1]; - if (!(func_ctx->last_alloca = - LLVMBuildBitCast(comp_ctx->builder, func_ctx->last_alloca, - INT8_PTR_TYPE, "stack_ptr"))) { - aot_set_last_error("llvm build bit cast failed."); - return false; - } - } - else { - if (!(func_ctx->last_alloca = LLVMBuildAlloca( - comp_ctx->builder, INT8_TYPE, "stack_ptr"))) { - aot_set_last_error("llvm build alloca failed."); - return false; - } - } - } - return true; } static bool -create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, +create_memory_info(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMTypeRef int8_ptr_type, uint32 func_index) { LLVMValueRef offset, mem_info_base; @@ -807,7 +1362,7 @@ create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, } static bool -create_cur_exception(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) +create_cur_exception(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) { LLVMValueRef offset; @@ -823,7 +1378,8 @@ create_cur_exception(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) } static bool -create_func_type_indexes(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) +create_func_type_indexes(const AOTCompContext *comp_ctx, + AOTFuncContext *func_ctx) { LLVMValueRef offset, func_type_indexes_ptr; LLVMTypeRef int32_ptr_type; @@ -861,7 +1417,7 @@ create_func_type_indexes(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) } static bool -create_func_ptrs(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) +create_func_ptrs(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) { LLVMValueRef offset; @@ -899,11 +1455,95 @@ create_func_ptrs(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) return true; } +const char *aot_stack_sizes_name = AOT_STACK_SIZES_NAME; +const char *aot_stack_sizes_alias_name = AOT_STACK_SIZES_ALIAS_NAME; +const char *aot_stack_sizes_section_name = AOT_STACK_SIZES_SECTION_NAME; + +static bool +aot_create_stack_sizes(const AOTCompData *comp_data, AOTCompContext *comp_ctx) +{ + LLVMValueRef stack_sizes, *values, array, alias; + LLVMTypeRef stack_sizes_type; +#if LLVM_VERSION_MAJOR <= 13 + LLVMTypeRef alias_type; +#endif + uint64 size; + uint32 i; + + stack_sizes_type = LLVMArrayType(I32_TYPE, comp_data->func_count); + if (!stack_sizes_type) { + aot_set_last_error("failed to create stack_sizes type."); + return false; + } + + stack_sizes = + LLVMAddGlobal(comp_ctx->module, stack_sizes_type, aot_stack_sizes_name); + if (!stack_sizes) { + aot_set_last_error("failed to create stack_sizes global."); + return false; + } + + size = sizeof(LLVMValueRef) * comp_data->func_count; + if (size >= UINT32_MAX || !(values = wasm_runtime_malloc((uint32)size))) { + aot_set_last_error("allocate memory failed."); + return false; + } + + for (i = 0; i < comp_data->func_count; i++) { + /* + * This value is a placeholder, which will be replaced + * after the corresponding functions are compiled. + * + * Don't use zeros becasue LLVM can optimize them to + * zeroinitializer. + */ + values[i] = I32_NEG_ONE; + } + + array = LLVMConstArray(I32_TYPE, values, comp_data->func_count); + wasm_runtime_free(values); + if (!array) { + aot_set_last_error("failed to create stack_sizes initializer."); + return false; + } + LLVMSetInitializer(stack_sizes, array); + + /* + * create an alias so that aot_resolve_stack_sizes can find it. + */ +#if LLVM_VERSION_MAJOR > 13 + alias = LLVMAddAlias2(comp_ctx->module, stack_sizes_type, 0, stack_sizes, + aot_stack_sizes_alias_name); +#else + alias_type = LLVMPointerType(stack_sizes_type, 0); + if (!alias_type) { + aot_set_last_error("failed to create alias type."); + return false; + } + alias = LLVMAddAlias(comp_ctx->module, alias_type, stack_sizes, + aot_stack_sizes_alias_name); +#endif + if (!alias) { + aot_set_last_error("failed to create stack_sizes alias."); + return false; + } + + /* + * make the original symbol internal. we mainly use this version to + * avoid creating extra relocations in the precheck functions. + */ + LLVMSetLinkage(stack_sizes, LLVMInternalLinkage); + LLVMSetSection(stack_sizes, aot_stack_sizes_section_name); + comp_ctx->stack_sizes_type = stack_sizes_type; + comp_ctx->stack_sizes = stack_sizes; + return true; +} + /** * Create function compiler context */ static AOTFuncContext * -aot_create_func_context(AOTCompData *comp_data, AOTCompContext *comp_ctx, +aot_create_func_context(const AOTCompData *comp_data, AOTCompContext *comp_ctx, AOTFunc *func, uint32 func_index) { AOTFuncContext *func_ctx; @@ -912,7 +1552,6 @@ aot_create_func_context(AOTCompData *comp_data, AOTCompContext *comp_ctx, WASMFunction *wasm_func = module->functions[func_index]; AOTBlock *aot_block; LLVMTypeRef int8_ptr_type; - LLVMValueRef aot_inst_offset = I32_TWO, aot_inst_addr; uint64 size; /* Allocate memory for the function context */ @@ -930,9 +1569,9 @@ aot_create_func_context(AOTCompData *comp_data, AOTCompContext *comp_ctx, func_ctx->module = comp_ctx->module; /* Add LLVM function */ - if (!(func_ctx->func = - aot_add_llvm_func(comp_ctx, func_ctx->module, aot_func_type, - func_index, &func_ctx->func_type))) { + if (!(func_ctx->func = aot_add_llvm_func( + comp_ctx, func_ctx->module, aot_func_type, func_index, + &func_ctx->func_type, &func_ctx->precheck_func))) { goto fail; } @@ -951,22 +1590,7 @@ aot_create_func_context(AOTCompData *comp_data, AOTCompContext *comp_ctx, /* Add local variables */ LLVMPositionBuilderAtEnd(comp_ctx->builder, aot_block->llvm_entry_block); - /* Save the pameters for fast access */ - func_ctx->exec_env = LLVMGetParam(func_ctx->func, 0); - - /* Get aot inst address, the layout of exec_env is: - exec_env->next, exec_env->prev, exec_env->module_inst, and argv_buf */ - if (!(aot_inst_addr = LLVMBuildInBoundsGEP2( - comp_ctx->builder, OPQ_PTR_TYPE, func_ctx->exec_env, - &aot_inst_offset, 1, "aot_inst_addr"))) { - aot_set_last_error("llvm build in bounds gep failed"); - goto fail; - } - - /* Load aot inst */ - if (!(func_ctx->aot_inst = LLVMBuildLoad2(comp_ctx->builder, OPQ_PTR_TYPE, - aot_inst_addr, "aot_inst"))) { - aot_set_last_error("llvm build load failed"); + if (!create_basic_func_context(comp_ctx, func_ctx)) { goto fail; } @@ -975,28 +1599,12 @@ aot_create_func_context(AOTCompData *comp_data, AOTCompContext *comp_ctx, goto fail; } - /* Get native stack boundary address */ - if (comp_ctx->enable_stack_bound_check - && !create_native_stack_bound(comp_ctx, func_ctx)) { - goto fail; - } - if (comp_ctx->enable_stack_estimation - && !create_native_stack_top_min(comp_ctx, func_ctx)) { - goto fail; - } - /* Get auxiliary stack info */ if (wasm_func->has_op_set_global_aux_stack && !create_aux_stack_info(comp_ctx, func_ctx)) { goto fail; } - /* Get native symbol list */ - if (comp_ctx->is_indirect_mode - && !create_native_symbol(comp_ctx, func_ctx)) { - goto fail; - } - /* Create local variables */ if (!create_local_variables(comp_data, comp_ctx, func_ctx, func)) { goto fail; @@ -1059,12 +1667,17 @@ aot_destroy_func_contexts(AOTFuncContext **func_ctxes, uint32 count) * Create function compiler contexts */ static AOTFuncContext ** -aot_create_func_contexts(AOTCompData *comp_data, AOTCompContext *comp_ctx) +aot_create_func_contexts(const AOTCompData *comp_data, AOTCompContext *comp_ctx) { AOTFuncContext **func_ctxes; uint64 size; uint32 i; + if ((comp_ctx->enable_stack_bound_check + || comp_ctx->enable_stack_estimation) + && !aot_create_stack_sizes(comp_data, comp_ctx)) + return NULL; + /* Allocate memory */ size = sizeof(AOTFuncContext *) * (uint64)comp_data->func_count; if (size >= UINT32_MAX @@ -1127,6 +1740,28 @@ aot_set_llvm_basic_types(AOTLLVMTypes *basic_types, LLVMContextRef context) basic_types->v128_type = basic_types->i64x2_vec_type; basic_types->v128_ptr_type = LLVMPointerType(basic_types->v128_type, 0); + basic_types->int8_ptr_type_gs = + LLVMPointerType(basic_types->int8_type, 256); + basic_types->int16_ptr_type_gs = + LLVMPointerType(basic_types->int16_type, 256); + basic_types->int32_ptr_type_gs = + LLVMPointerType(basic_types->int32_type, 256); + basic_types->int64_ptr_type_gs = + LLVMPointerType(basic_types->int64_type, 256); + basic_types->float32_ptr_type_gs = + LLVMPointerType(basic_types->float32_type, 256); + basic_types->float64_ptr_type_gs = + LLVMPointerType(basic_types->float64_type, 256); + basic_types->v128_ptr_type_gs = + LLVMPointerType(basic_types->v128_type, 256); + if (!basic_types->int8_ptr_type_gs || !basic_types->int16_ptr_type_gs + || !basic_types->int32_ptr_type_gs || !basic_types->int64_ptr_type_gs + || !basic_types->float32_ptr_type_gs + || !basic_types->float64_ptr_type_gs + || !basic_types->v128_ptr_type_gs) { + return false; + } + basic_types->i1x2_vec_type = LLVMVectorType(basic_types->int1_type, 2); basic_types->funcref_type = LLVMInt32TypeInContext(context); @@ -1301,6 +1936,7 @@ static ArchItem valid_archs[] = { static const char *valid_abis[] = { "gnu", "eabi", + "eabihf", "gnueabihf", "msvc", "ilp32", @@ -1316,13 +1952,33 @@ static void print_supported_targets() { uint32 i; + const char *target_name; + os_printf("Supported targets:\n"); - for (i = 0; i < sizeof(valid_archs) / sizeof(ArchItem); i++) { - os_printf("%s ", valid_archs[i].arch); - if (valid_archs[i].support_eb) - os_printf("%seb ", valid_archs[i].arch); + /* over the list of all available targets */ + for (LLVMTargetRef target = LLVMGetFirstTarget(); target != NULL; + target = LLVMGetNextTarget(target)) { + target_name = LLVMGetTargetName(target); + /* Skip mipsel, aarch64_be since prefix mips, aarch64 will cover them */ + if (strcmp(target_name, "mipsel") == 0) + continue; + else if (strcmp(target_name, "aarch64_be") == 0) + continue; + + if (strcmp(target_name, "x86-64") == 0) + os_printf(" x86_64\n"); + else if (strcmp(target_name, "x86") == 0) + os_printf(" i386\n"); + else { + for (i = 0; i < sizeof(valid_archs) / sizeof(ArchItem); i++) { + /* If target_name is prefix for valid_archs[i].arch */ + if ((strncmp(target_name, valid_archs[i].arch, + strlen(target_name)) + == 0)) + os_printf(" %s\n", valid_archs[i].arch); + } + } } - os_printf("\n"); } static void @@ -1378,6 +2034,18 @@ get_target_arch_from_triple(const char *triple, char *arch_buf, uint32 buf_size) bh_assert(*triple == '-' || *triple == '\0'); } +static bool +is_baremetal_target(const char *target, const char *cpu, const char *abi) +{ + /* TODO: support more baremetal targets */ + if (target) { + /* If target is thumbxxx, then it is baremetal target */ + if (!strncmp(target, "thumb", strlen("thumb"))) + return true; + } + return false; +} + void aot_handle_llvm_errmsg(const char *string, LLVMErrorRef err) { @@ -1456,8 +2124,57 @@ create_target_machine_detect_host(AOTCompContext *comp_ctx) return ret; } +static void +jit_stack_size_callback(void *user_data, const char *name, size_t namelen, + size_t stack_size) +{ + AOTCompContext *comp_ctx = user_data; + /* + * Note: the longest name we care is + * something like "aot_func_internal#4294967295". + */ + char buf[64]; + uint32 func_idx; + const AOTFuncContext *func_ctx; + bool musttail; + unsigned int stack_consumption_to_call_wrapped_func; + unsigned int call_size; + int ret; + + bh_assert(comp_ctx != NULL); + bh_assert(comp_ctx->jit_stack_sizes != NULL); + + if (namelen >= sizeof(buf)) { + LOG_DEBUG("too long name: %.*s", (int)namelen, name); + return; + } + /* ensure NUL termination */ + bh_memcpy_s(buf, (uint32)sizeof(buf), name, (uint32)namelen); + buf[namelen] = 0; + + ret = sscanf(buf, AOT_FUNC_INTERNAL_PREFIX "%" SCNu32, &func_idx); + if (ret != 1) { + return; + } + + bh_assert(func_idx < comp_ctx->func_ctx_count); + func_ctx = comp_ctx->func_ctxes[func_idx]; + call_size = func_ctx->stack_consumption_for_func_call; + musttail = aot_target_precheck_can_use_musttail(comp_ctx); + stack_consumption_to_call_wrapped_func = + musttail ? 0 + : aot_estimate_stack_usage_for_function_call( + comp_ctx, func_ctx->aot_func->func_type); + LOG_VERBOSE("func %.*s stack %u + %zu + %u", (int)namelen, name, + stack_consumption_to_call_wrapped_func, stack_size, call_size); + + /* Note: -1 == AOT_NEG_ONE from aot_create_stack_sizes */ + bh_assert(comp_ctx->jit_stack_sizes[func_idx] == (uint32)-1); + comp_ctx->jit_stack_sizes[func_idx] = (uint32)stack_size + call_size; +} + static bool -orc_jit_create(AOTCompContext *comp_ctx) +orc_jit_create(AOTCompContext *comp_ctx, bool linux_perf_support) { LLVMErrorRef err; LLVMOrcLLLazyJITRef orc_jit = NULL; @@ -1471,6 +2188,10 @@ orc_jit_create(AOTCompContext *comp_ctx) goto fail; } + if (comp_ctx->enable_stack_bound_check || comp_ctx->enable_stack_estimation) + LLVMOrcLLJITBuilderSetCompileFuncitonCreatorWithStackSizesCallback( + builder, jit_stack_size_callback, comp_ctx); + err = LLVMOrcJITTargetMachineBuilderDetectHost(&jtmb); if (err != LLVMErrorSuccess) { aot_handle_llvm_errmsg( @@ -1493,6 +2214,14 @@ orc_jit_create(AOTCompContext *comp_ctx) /* Ownership transfer: LLVMOrcLLJITBuilderRef -> LLVMOrcLLJITRef */ builder = NULL; + if (linux_perf_support) { + LOG_DEBUG("Enable linux perf support"); + LLVMOrcObjectLayerRef obj_linking_layer = + (LLVMOrcObjectLayerRef)LLVMOrcLLLazyJITGetObjLinkingLayer(orc_jit); + LLVMOrcRTDyldObjectLinkingLayerRegisterJITEventListener( + obj_linking_layer, LLVMCreatePerfJITEventListener()); + } + /* Ownership transfer: local -> AOTCompContext */ comp_ctx->orc_jit = orc_jit; orc_jit = NULL; @@ -1511,8 +2240,10 @@ bool aot_compiler_init(void) { /* Initialize LLVM environment */ - +#if LLVM_VERSION_MAJOR < 17 LLVMInitializeCore(LLVMGetGlobalPassRegistry()); +#endif + #if WASM_ENABLE_WAMR_COMPILER != 0 /* Init environment of all targets for AOT compiler */ LLVMInitializeAllTargetInfos(); @@ -1536,7 +2267,7 @@ aot_compiler_destroy(void) } AOTCompContext * -aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) +aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) { AOTCompContext *comp_ctx, *ret = NULL; LLVMTargetRef target; @@ -1545,7 +2276,7 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) char *triple_norm_new = NULL, *cpu_new = NULL; char *err = NULL, *fp_round = "round.tonearest", *fp_exce = "fpexcept.strict"; - char triple_buf[32] = { 0 }, features_buf[128] = { 0 }; + char triple_buf[128] = { 0 }, features_buf[128] = { 0 }; uint32 opt_level, size_level, i; LLVMCodeModel code_model; LLVMTargetDataRef target_data_ref; @@ -1589,6 +2320,17 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) goto fail; } + if (option->linux_perf_support) { + /* FramePointerKind.All */ + LLVMMetadataRef val = + LLVMValueAsMetadata(LLVMConstInt(LLVMInt32Type(), 2, false)); + const char *key = "frame-pointer"; + LLVMAddModuleFlag(comp_ctx->module, LLVMModuleFlagBehaviorWarning, key, + strlen(key), val); + + comp_ctx->emit_frame_pointer = true; + } + if (BH_LIST_ERROR == bh_list_init(&comp_ctx->native_symbols)) { goto fail; } @@ -1643,9 +2385,21 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) if (option->disable_llvm_lto) comp_ctx->disable_llvm_lto = true; + if (option->enable_llvm_pgo) + comp_ctx->enable_llvm_pgo = true; + + if (option->use_prof_file) + comp_ctx->use_prof_file = option->use_prof_file; + if (option->enable_stack_estimation) comp_ctx->enable_stack_estimation = true; + if (option->llvm_passes) + comp_ctx->llvm_passes = option->llvm_passes; + + if (option->builtin_intrinsics) + comp_ctx->builtin_intrinsics = option->builtin_intrinsics; + comp_ctx->opt_level = option->opt_level; comp_ctx->size_level = option->size_level; @@ -1655,14 +2409,6 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) if (option->is_jit_mode) { comp_ctx->is_jit_mode = true; - /* Create TargetMachine */ - if (!create_target_machine_detect_host(comp_ctx)) - goto fail; - - /* Create LLJIT Instance */ - if (!orc_jit_create(comp_ctx)) - goto fail; - #ifndef OS_ENABLE_HW_BOUND_CHECK comp_ctx->enable_bound_check = true; /* Always enable stack boundary check if `bounds-checks` @@ -1682,6 +2428,14 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) comp_ctx->enable_stack_bound_check = false; #endif #endif + + /* Create TargetMachine */ + if (!create_target_machine_detect_host(comp_ctx)) + goto fail; + + /* Create LLJIT Instance */ + if (!orc_jit_create(comp_ctx, option->linux_perf_support)) + goto fail; } else { /* Create LLVM target machine */ @@ -1829,6 +2583,7 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) * for Windows/MacOS under Linux host, or generating AOT file for * Linux/MacOS under Windows host. */ + if (!strcmp(abi, "msvc")) { if (!strcmp(arch1, "i386")) vendor_sys = "-pc-win32-"; @@ -1836,7 +2591,10 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) vendor_sys = "-pc-windows-"; } else { - vendor_sys = "-pc-linux-"; + if (is_baremetal_target(arch, cpu, abi)) + vendor_sys = "-unknown-none-"; + else + vendor_sys = "-pc-linux-"; } bh_assert(strlen(arch1) + strlen(vendor_sys) + strlen(abi) @@ -1872,6 +2630,11 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) if (!abi) abi = "msvc"; } + else if (is_baremetal_target(arch, cpu, abi)) { + vendor_sys = "-unknown-none-"; + if (!abi) + abi = "gnu"; + } else { vendor_sys = "-pc-linux-"; if (!abi) @@ -1946,13 +2709,14 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) meta_target_abi); if (!strcmp(abi, "lp64d") || !strcmp(abi, "ilp32d")) { - if (features) { + if (features && !strstr(features, "+d")) { snprintf(features_buf, sizeof(features_buf), "%s%s", features, ",+d"); features = features_buf; } - else + else if (!features) { features = "+d"; + } } } @@ -2004,9 +2768,23 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) (option->stack_bounds_checks == 1) ? true : false; } + if ((comp_ctx->enable_stack_bound_check + || comp_ctx->enable_stack_estimation) + && option->stack_usage_file == NULL) { + if (!aot_generate_tempfile_name( + "wamrc-su", "su", comp_ctx->stack_usage_temp_file, + sizeof(comp_ctx->stack_usage_temp_file))) + goto fail; + comp_ctx->stack_usage_file = comp_ctx->stack_usage_temp_file; + } + else { + comp_ctx->stack_usage_file = option->stack_usage_file; + } + 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(" target triple: %s\n", triple_norm); os_printf(" cpu features: %s\n", features); os_printf(" opt level: %d\n", opt_level); os_printf(" size level: %d\n", size_level); @@ -2025,6 +2803,8 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) break; } + LLVMSetTarget(comp_ctx->module, triple_norm); + if (!LLVMTargetHasTargetMachine(target)) { snprintf(buf, sizeof(buf), "no target machine for this target (%s).", triple_norm); @@ -2059,11 +2839,52 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) if (!(comp_ctx->target_machine = LLVMCreateTargetMachineWithOpts( target, triple_norm, cpu, features, opt_level, LLVMRelocStatic, code_model, false, - option->stack_usage_file))) { + comp_ctx->stack_usage_file))) { aot_set_last_error("create LLVM target machine failed."); goto fail; } + + /* If only to create target machine for querying information, early stop + */ + if ((arch && !strcmp(arch, "help")) || (abi && !strcmp(abi, "help")) + || (cpu && !strcmp(cpu, "help")) + || (features && !strcmp(features, "+help"))) { + LOG_DEBUG( + "create LLVM target machine only for printing help info."); + goto fail; + } + } + + triple = LLVMGetTargetMachineTriple(comp_ctx->target_machine); + if (!triple) { + aot_set_last_error("get target machine triple failed."); + goto fail; } + if (strstr(triple, "linux") && !strcmp(comp_ctx->target_arch, "x86_64")) { + if (option->segue_flags) { + if (option->segue_flags & (1 << 0)) + comp_ctx->enable_segue_i32_load = true; + if (option->segue_flags & (1 << 1)) + comp_ctx->enable_segue_i64_load = true; + if (option->segue_flags & (1 << 2)) + comp_ctx->enable_segue_f32_load = true; + if (option->segue_flags & (1 << 3)) + comp_ctx->enable_segue_f64_load = true; + if (option->segue_flags & (1 << 4)) + comp_ctx->enable_segue_v128_load = true; + if (option->segue_flags & (1 << 8)) + comp_ctx->enable_segue_i32_store = true; + if (option->segue_flags & (1 << 9)) + comp_ctx->enable_segue_i64_store = true; + if (option->segue_flags & (1 << 10)) + comp_ctx->enable_segue_f32_store = true; + if (option->segue_flags & (1 << 11)) + comp_ctx->enable_segue_f64_store = true; + if (option->segue_flags & (1 << 12)) + comp_ctx->enable_segue_v128_store = true; + } + } + LLVMDisposeMessage(triple); if (option->enable_simd && strcmp(comp_ctx->target_arch, "x86_64") != 0 && strncmp(comp_ctx->target_arch, "aarch64", 7) != 0) { @@ -2098,6 +2919,7 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) aot_set_last_error("create LLVM target data layout failed."); goto fail; } + LLVMSetModuleDataLayout(comp_ctx->module, target_data_ref); comp_ctx->pointer_size = LLVMPointerSize(target_data_ref); LLVMDisposeTargetData(target_data_ref); @@ -2171,6 +2993,10 @@ aot_destroy_comp_context(AOTCompContext *comp_ctx) if (!comp_ctx) return; + if (comp_ctx->stack_usage_file == comp_ctx->stack_usage_temp_file) { + (void)unlink(comp_ctx->stack_usage_temp_file); + } + if (comp_ctx->target_machine) LLVMDisposeTargetMachine(comp_ctx->target_machine); @@ -2466,8 +3292,8 @@ aot_checked_addr_list_destroy(AOTFuncContext *func_ctx) } bool -aot_build_zero_function_ret(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - AOTFuncType *func_type) +aot_build_zero_function_ret(const AOTCompContext *comp_ctx, + AOTFuncContext *func_ctx, AOTFuncType *func_type) { LLVMValueRef ret = NULL; @@ -2506,9 +3332,12 @@ aot_build_zero_function_ret(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return false; } #if WASM_ENABLE_DEBUG_AOT != 0 - LLVMMetadataRef return_location = - dwarf_gen_func_ret_location(comp_ctx, func_ctx); - LLVMInstructionSetDebugLoc(ret, return_location); + /* debug_func is NULL for precheck function */ + if (func_ctx->debug_func != NULL) { + LLVMMetadataRef return_location = + dwarf_gen_func_ret_location(comp_ctx, func_ctx); + LLVMInstructionSetDebugLoc(ret, return_location); + } #endif return true; } @@ -2768,3 +3597,23 @@ aot_load_const_from_table(AOTCompContext *comp_ctx, LLVMValueRef base, (void)const_type; return const_value; } + +bool +aot_set_cond_br_weights(AOTCompContext *comp_ctx, LLVMValueRef cond_br, + int32 weights_true, int32 weights_false) +{ + LLVMMetadataRef md_nodes[3], meta_data; + LLVMValueRef meta_data_as_value; + + md_nodes[0] = LLVMMDStringInContext2(comp_ctx->context, "branch_weights", + strlen("branch_weights")); + md_nodes[1] = LLVMValueAsMetadata(I32_CONST(weights_true)); + md_nodes[2] = LLVMValueAsMetadata(I32_CONST(weights_false)); + + meta_data = LLVMMDNodeInContext2(comp_ctx->context, md_nodes, 3); + meta_data_as_value = LLVMMetadataAsValue(comp_ctx->context, meta_data); + + LLVMSetMetadata(cond_br, 2, meta_data_as_value); + + return true; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm.h similarity index 85% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm.h index 2a1564019d7..32d7bbebacd 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm.h @@ -12,18 +12,22 @@ #include "llvm-c/Target.h" #include "llvm-c/Core.h" #include "llvm-c/Object.h" +#include "llvm-c/OrcEE.h" #include "llvm-c/ExecutionEngine.h" #include "llvm-c/Analysis.h" #include "llvm-c/BitWriter.h" +#if LLVM_VERSION_MAJOR < 17 #include "llvm-c/Transforms/Utils.h" #include "llvm-c/Transforms/Scalar.h" #include "llvm-c/Transforms/Vectorize.h" #include "llvm-c/Transforms/PassManagerBuilder.h" +#include "llvm-c/Initialization.h" +#endif #include "llvm-c/Orc.h" #include "llvm-c/Error.h" #include "llvm-c/Support.h" -#include "llvm-c/Initialization.h" + #include "llvm-c/TargetMachine.h" #include "llvm-c/LLJIT.h" #if WASM_ENABLE_DEBUG_AOT != 0 @@ -153,9 +157,8 @@ typedef struct AOTMemInfo { typedef struct AOTFuncContext { AOTFunc *aot_func; LLVMValueRef func; + LLVMValueRef precheck_func; LLVMTypeRef func_type; - /* LLVM module for this function, note that in LAZY JIT mode, - each aot function belongs to an individual module */ LLVMModuleRef module; AOTBlockStack block_stack; @@ -167,7 +170,6 @@ typedef struct AOTFuncContext { LLVMValueRef aux_stack_bound; LLVMValueRef aux_stack_bottom; LLVMValueRef native_symbol; - LLVMValueRef last_alloca; LLVMValueRef func_ptrs; AOTMemInfo *mem_info; @@ -184,6 +186,9 @@ typedef struct AOTFuncContext { #if WASM_ENABLE_DEBUG_AOT != 0 LLVMMetadataRef debug_func; #endif + + unsigned int stack_consumption_for_func_call; + LLVMValueRef locals[1]; } AOTFuncContext; @@ -214,6 +219,14 @@ typedef struct AOTLLVMTypes { LLVMTypeRef f32x4_vec_type; LLVMTypeRef f64x2_vec_type; + LLVMTypeRef int8_ptr_type_gs; + LLVMTypeRef int16_ptr_type_gs; + LLVMTypeRef int32_ptr_type_gs; + LLVMTypeRef int64_ptr_type_gs; + LLVMTypeRef float32_ptr_type_gs; + LLVMTypeRef float64_ptr_type_gs; + LLVMTypeRef v128_ptr_type_gs; + LLVMTypeRef i1x2_vec_type; LLVMTypeRef meta_data_type; @@ -275,7 +288,7 @@ typedef struct AOTLLVMConsts { * Compiler context */ typedef struct AOTCompContext { - AOTCompData *comp_data; + const AOTCompData *comp_data; /* LLVM variables required to emit LLVM IR */ LLVMContextRef context; @@ -341,6 +354,25 @@ typedef struct AOTCompContext { /* Disable LLVM link time optimization */ bool disable_llvm_lto; + /* Enable LLVM PGO (Profile-Guided Optimization) */ + bool enable_llvm_pgo; + + /* Use profile file collected by LLVM PGO */ + char *use_prof_file; + + /* Enable to use segument register as the base addr + of linear memory for load/store operations */ + bool enable_segue_i32_load; + bool enable_segue_i64_load; + bool enable_segue_f32_load; + bool enable_segue_f64_load; + bool enable_segue_v128_load; + bool enable_segue_i32_store; + bool enable_segue_i64_store; + bool enable_segue_f32_store; + bool enable_segue_f64_store; + bool enable_segue_v128_store; + /* Whether optimize the JITed code */ bool optimize; @@ -353,6 +385,11 @@ typedef struct AOTCompContext { /* LLVM floating-point exception behavior metadata */ LLVMValueRef fp_exception_behavior; + /* a global array to store stack sizes */ + LLVMTypeRef stack_sizes_type; + LLVMValueRef stack_sizes; + uint32 *jit_stack_sizes; /* for JIT */ + /* LLVM data types */ AOTLLVMTypes basic_types; LLVMTypeRef exec_env_type; @@ -381,6 +418,13 @@ typedef struct AOTCompContext { * file for some architecture (such as arc) */ const char *external_asm_compiler; const char *asm_compiler_flags; + + const char *stack_usage_file; + char stack_usage_temp_file[64]; + const char *llvm_passes; + const char *builtin_intrinsics; + + bool emit_frame_pointer; } AOTCompContext; enum { @@ -390,6 +434,7 @@ enum { AOT_LLVMIR_OPT_FILE, }; +/* always sync it with AOTCompOption in aot_export.h */ typedef struct AOTCompOption { bool is_jit_mode; bool is_indirect_mode; @@ -407,15 +452,21 @@ typedef struct AOTCompOption { bool enable_aux_stack_frame; bool disable_llvm_intrinsics; bool disable_llvm_lto; + bool enable_llvm_pgo; bool enable_stack_estimation; + char *use_prof_file; uint32 opt_level; uint32 size_level; uint32 output_format; uint32 bounds_checks; uint32 stack_bounds_checks; + uint32 segue_flags; + bool linux_perf_support; char **custom_sections; uint32 custom_sections_count; const char *stack_usage_file; + const char *llvm_passes; + const char *builtin_intrinsics; } AOTCompOption, *aot_comp_option_t; bool @@ -425,7 +476,7 @@ void aot_compiler_destroy(void); AOTCompContext * -aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option); +aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option); void aot_destroy_comp_context(AOTCompContext *comp_ctx); @@ -464,7 +515,7 @@ void aot_block_destroy(AOTBlock *block); LLVMTypeRef -wasm_type_to_llvm_type(AOTLLVMTypes *llvm_types, uint8 wasm_type); +wasm_type_to_llvm_type(const AOTLLVMTypes *llvm_types, uint8 wasm_type); bool aot_checked_addr_list_add(AOTFuncContext *func_ctx, uint32 local_idx, @@ -481,8 +532,8 @@ void aot_checked_addr_list_destroy(AOTFuncContext *func_ctx); bool -aot_build_zero_function_ret(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - AOTFuncType *func_type); +aot_build_zero_function_ret(const AOTCompContext *comp_ctx, + AOTFuncContext *func_ctx, AOTFuncType *func_type); LLVMValueRef aot_call_llvm_intrinsic(const AOTCompContext *comp_ctx, @@ -519,6 +570,20 @@ aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module); void aot_handle_llvm_errmsg(const char *string, LLVMErrorRef err); +char * +aot_compress_aot_func_names(AOTCompContext *comp_ctx, uint32 *p_size); + +bool +aot_set_cond_br_weights(AOTCompContext *comp_ctx, LLVMValueRef cond_br, + int32 weights_true, int32 weights_false); + +bool +aot_target_precheck_can_use_musttail(const AOTCompContext *comp_ctx); + +unsigned int +aot_estimate_stack_usage_for_function_call(const AOTCompContext *comp_ctx, + const AOTFuncType *callee_func_type); + #ifdef __cplusplus } /* end of extern "C" */ #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm_extra.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm_extra.cpp similarity index 52% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm_extra.cpp rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm_extra.cpp index 9b77f5e6a1e..ed0205c3c93 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm_extra.cpp +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm_extra.cpp @@ -5,9 +5,13 @@ #include #include +#if LLVM_VERSION_MAJOR < 17 +#include +#include +#include +#endif #include #include -#include #include #include #include @@ -16,7 +20,9 @@ #include #include #include +#if LLVM_VERSION_MAJOR < 17 #include +#endif #include #include #include @@ -25,9 +31,13 @@ #include #include #include -#include +#include #include #include +#if LLVM_VERSION_MAJOR >= 17 +#include +#include +#endif #include #include #include @@ -44,6 +54,7 @@ #if LLVM_VERSION_MAJOR >= 12 #include #endif +#include #include #include "../aot/aot_runtime.h" @@ -52,6 +63,13 @@ using namespace llvm; using namespace llvm::orc; +#if LLVM_VERSION_MAJOR >= 17 +namespace llvm { +template +using Optional = std::optional; +} +#endif + LLVM_C_EXTERN_C_BEGIN bool @@ -70,115 +88,63 @@ LLVM_C_EXTERN_C_END ExitOnError ExitOnErr; -class ExpandMemoryOpPass : public llvm::ModulePass +class ExpandMemoryOpPass : public PassInfoMixin { public: - static char ID; - - ExpandMemoryOpPass() - : ModulePass(ID) - {} - - bool runOnModule(Module &M) override; - - bool expandMemIntrinsicUses(Function &F); - StringRef getPassName() const override - { - return "Expand memory operation intrinsics"; - } - - void getAnalysisUsage(AnalysisUsage &AU) const override - { - AU.addRequired(); - } + PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); }; -char ExpandMemoryOpPass::ID = 0; - -bool -ExpandMemoryOpPass::expandMemIntrinsicUses(Function &F) +PreservedAnalyses +ExpandMemoryOpPass::run(Function &F, FunctionAnalysisManager &AM) { - Intrinsic::ID ID = F.getIntrinsicID(); - bool Changed = false; - - for (auto I = F.user_begin(), E = F.user_end(); I != E;) { - Instruction *Inst = cast(*I); - ++I; - - switch (ID) { - case Intrinsic::memcpy: - { - auto *Memcpy = cast(Inst); - Function *ParentFunc = Memcpy->getParent()->getParent(); - const TargetTransformInfo &TTI = - getAnalysis().getTTI( - *ParentFunc); - expandMemCpyAsLoop(Memcpy, TTI); - Changed = true; - Memcpy->eraseFromParent(); - break; + SmallVector MemCalls; + + /* Iterate over all instructions in the function, looking for memcpy, + * memmove, and memset. When we find one, expand it into a loop. */ + + for (auto &BB : F) { + for (auto &Inst : BB) { + if (auto *Memcpy = dyn_cast_or_null(&Inst)) { + MemCalls.push_back(Memcpy); } - case Intrinsic::memmove: - { - auto *Memmove = cast(Inst); - expandMemMoveAsLoop(Memmove); - Changed = true; - Memmove->eraseFromParent(); - break; + else if (auto *Memmove = dyn_cast_or_null(&Inst)) { + MemCalls.push_back(Memmove); } - case Intrinsic::memset: - { - auto *Memset = cast(Inst); - expandMemSetAsLoop(Memset); - Changed = true; - Memset->eraseFromParent(); - break; + else if (auto *Memset = dyn_cast_or_null(&Inst)) { + MemCalls.push_back(Memset); } - default: - break; } } - return Changed; -} - -bool -ExpandMemoryOpPass::runOnModule(Module &M) -{ - bool Changed = false; - - for (Function &F : M) { - if (!F.isDeclaration()) - continue; - - switch (F.getIntrinsicID()) { - case Intrinsic::memcpy: - case Intrinsic::memmove: - case Intrinsic::memset: - if (expandMemIntrinsicUses(F)) - Changed = true; - break; - - default: - break; + for (MemIntrinsic *MemCall : MemCalls) { + if (MemCpyInst *Memcpy = dyn_cast(MemCall)) { + Function *ParentFunc = Memcpy->getParent()->getParent(); + const TargetTransformInfo &TTI = + AM.getResult(*ParentFunc); + expandMemCpyAsLoop(Memcpy, TTI); + Memcpy->eraseFromParent(); + } + else if (MemMoveInst *Memmove = dyn_cast(MemCall)) { +#if LLVM_VERSION_MAJOR >= 17 + Function *ParentFunc = Memmove->getParent()->getParent(); + const TargetTransformInfo &TTI = + AM.getResult(*ParentFunc); + expandMemMoveAsLoop(Memmove, TTI); +#else + expandMemMoveAsLoop(Memmove); +#endif + Memmove->eraseFromParent(); + } + else if (MemSetInst *Memset = dyn_cast(MemCall)) { + expandMemSetAsLoop(Memset); + Memset->eraseFromParent(); } } - return Changed; -} - -void -aot_add_expand_memory_op_pass(LLVMPassManagerRef pass) -{ - reinterpret_cast(pass)->add( - new ExpandMemoryOpPass()); -} + PreservedAnalyses PA; + PA.preserveSet(); -void -aot_add_simple_loop_unswitch_pass(LLVMPassManagerRef pass) -{ - reinterpret_cast(pass)->add( - createSimpleLoopUnswitchLegacyPass()); + return PA; } bool @@ -232,14 +198,42 @@ aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module) PTO.SLPVectorization = true; PTO.LoopUnrolling = true; +#if LLVM_VERSION_MAJOR >= 16 + Optional PGO = std::nullopt; +#else + Optional PGO = llvm::None; +#endif + + if (comp_ctx->enable_llvm_pgo) { + /* Disable static counter allocation for value profiler, + it will be allocated by runtime */ + const char *argv[] = { "", "-vp-static-alloc=false" }; + cl::ParseCommandLineOptions(2, argv); +#if LLVM_VERSION_MAJOR < 17 + PGO = PGOOptions("", "", "", PGOOptions::IRInstr); +#else + auto FS = vfs::getRealFileSystem(); + PGO = PGOOptions("", "", "", "", FS, PGOOptions::IRInstr); +#endif + } + else if (comp_ctx->use_prof_file) { +#if LLVM_VERSION_MAJOR < 17 + PGO = PGOOptions(comp_ctx->use_prof_file, "", "", PGOOptions::IRUse); +#else + auto FS = vfs::getRealFileSystem(); + PGO = PGOOptions(comp_ctx->use_prof_file, "", "", "", FS, + PGOOptions::IRUse); +#endif + } + #ifdef DEBUG_PASS PassInstrumentationCallbacks PIC; - PassBuilder PB(TM, PTO, None, &PIC); + PassBuilder PB(TM, PTO, PGO, &PIC); #else #if LLVM_VERSION_MAJOR == 12 - PassBuilder PB(false, TM, PTO); + PassBuilder PB(false, TM, PTO, PGO); #else - PassBuilder PB(TM, PTO); + PassBuilder PB(TM, PTO, PGO); #endif #endif @@ -334,27 +328,95 @@ aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module) FPM.addPass(SLPVectorizerPass()); FPM.addPass(LoadStoreVectorizerPass()); + if (comp_ctx->enable_llvm_pgo || comp_ctx->use_prof_file) { + /* LICM pass: loop invariant code motion, attempting to remove + as much code from the body of a loop as possible. Experiments + show it is good to enable it when pgo is enabled. */ +#if LLVM_VERSION_MAJOR >= 15 + LICMOptions licm_opt; + FPM.addPass( + createFunctionToLoopPassAdaptor(LICMPass(licm_opt), true)); +#else + FPM.addPass(createFunctionToLoopPassAdaptor(LICMPass(), true)); +#endif + } + /* - FPM.addPass(createFunctionToLoopPassAdaptor(LICMPass())); FPM.addPass(createFunctionToLoopPassAdaptor(LoopRotatePass())); FPM.addPass(createFunctionToLoopPassAdaptor(SimpleLoopUnswitchPass())); */ MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); - if (!disable_llvm_lto) { - /* Apply LTO for AOT mode */ - if (comp_ctx->comp_data->func_count >= 10) - /* Adds the pre-link optimizations if the func count - is large enough */ - MPM.addPass(PB.buildLTOPreLinkDefaultPipeline(OL)); - else - MPM.addPass(PB.buildLTODefaultPipeline(OL, NULL)); + if (comp_ctx->llvm_passes) { + ExitOnErr(PB.parsePassPipeline(MPM, comp_ctx->llvm_passes)); + } + + if ( +#if LLVM_VERSION_MAJOR <= 13 + PassBuilder::OptimizationLevel::O0 == OL +#else + OptimizationLevel::O0 == OL +#endif + ) { + MPM.addPass(PB.buildO0DefaultPipeline(OL)); } else { - MPM.addPass(PB.buildPerModuleDefaultPipeline(OL)); + if (!disable_llvm_lto) { + /* Apply LTO for AOT mode */ + if (comp_ctx->comp_data->func_count >= 10 + || comp_ctx->enable_llvm_pgo || comp_ctx->use_prof_file) + /* Add the pre-link optimizations if the func count + is large enough or PGO is enabled */ + MPM.addPass(PB.buildLTOPreLinkDefaultPipeline(OL)); + else + MPM.addPass(PB.buildLTODefaultPipeline(OL, NULL)); + } + else { + MPM.addPass(PB.buildPerModuleDefaultPipeline(OL)); + } + } + + /* Run specific passes for AOT indirect mode in last since general + optimization may create some intrinsic function calls like + llvm.memset, so let's remove these function calls here. */ + if (comp_ctx->is_indirect_mode) { + FunctionPassManager FPM1; + FPM1.addPass(ExpandMemoryOpPass()); + MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM1))); } } MPM.run(*M, MAM); } + +char * +aot_compress_aot_func_names(AOTCompContext *comp_ctx, uint32 *p_size) +{ + std::vector NameStrs; + std::string Result; + char buf[32], *compressed_str; + uint32 compressed_str_len, i; + + for (i = 0; i < comp_ctx->func_ctx_count; i++) { + snprintf(buf, sizeof(buf), "%s%d", AOT_FUNC_PREFIX, i); + std::string str(buf); + NameStrs.push_back(str); + } + + if (collectPGOFuncNameStrings(NameStrs, true, Result)) { + aot_set_last_error("collect pgo func name strings failed"); + return NULL; + } + + compressed_str_len = Result.size(); + if (!(compressed_str = (char *)wasm_runtime_malloc(compressed_str_len))) { + aot_set_last_error("allocate memory failed"); + return NULL; + } + + bh_memcpy_s(compressed_str, compressed_str_len, Result.c_str(), + compressed_str_len); + *p_size = compressed_str_len; + return compressed_str; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm_extra2.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm_extra2.cpp similarity index 76% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm_extra2.cpp rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm_extra2.cpp index 9bd44bbff77..8364e5ebf42 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm_extra2.cpp +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm_extra2.cpp @@ -4,19 +4,39 @@ */ #include +#if LLVM_VERSION_MAJOR < 17 +#include +#include +#endif +#include +#if LLVM_VERSION_MAJOR >= 14 #include +#else +#include +#endif #include #include "bh_assert.h" #include "aot_llvm_extra2.h" +#if LLVM_VERSION_MAJOR >= 17 +namespace llvm { +template +using Optional = std::optional; +} +#endif + static llvm::Optional convert(LLVMRelocMode reloc_mode) { switch (reloc_mode) { case LLVMRelocDefault: +#if LLVM_VERSION_MAJOR >= 16 + return std::nullopt; +#else return llvm::None; +#endif case LLVMRelocStatic: return llvm::Reloc::Static; case LLVMRelocPIC: @@ -31,7 +51,11 @@ convert(LLVMRelocMode reloc_mode) return llvm::Reloc::ROPI_RWPI; } bh_assert(0); +#if LLVM_VERSION_MAJOR >= 16 + return std::nullopt; +#else return llvm::None; +#endif } static llvm::CodeGenOpt::Level @@ -57,10 +81,18 @@ convert(LLVMCodeModel code_model, bool *jit) *jit = false; switch (code_model) { case LLVMCodeModelDefault: +#if LLVM_VERSION_MAJOR >= 16 + return std::nullopt; +#else return llvm::None; +#endif case LLVMCodeModelJITDefault: *jit = true; +#if LLVM_VERSION_MAJOR >= 16 + return std::nullopt; +#else return llvm::None; +#endif case LLVMCodeModelTiny: return llvm::CodeModel::Tiny; case LLVMCodeModelSmall: @@ -73,7 +105,11 @@ convert(LLVMCodeModel code_model, bool *jit) return llvm::CodeModel::Large; } bh_assert(0); +#if LLVM_VERSION_MAJOR >= 16 + return std::nullopt; +#else return llvm::None; +#endif } LLVMTargetMachineRef @@ -106,3 +142,20 @@ LLVMCreateTargetMachineWithOpts(LLVMTargetRef ctarget, const char *triple, opts, rm, cm, ol, jit); return reinterpret_cast(targetmachine); } + +/* https://reviews.llvm.org/D153107 */ +#if LLVM_VERSION_MAJOR < 17 +using namespace llvm; + +LLVMTailCallKind +LLVMGetTailCallKind(LLVMValueRef Call) +{ + return (LLVMTailCallKind)unwrap(Call)->getTailCallKind(); +} + +void +LLVMSetTailCallKind(LLVMValueRef Call, LLVMTailCallKind kind) +{ + unwrap(Call)->setTailCallKind((CallInst::TailCallKind)kind); +} +#endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm_extra2.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm_extra2.h similarity index 62% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm_extra2.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm_extra2.h index ef99622a431..f3f89799436 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_llvm_extra2.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_llvm_extra2.h @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +#include #include LLVM_C_EXTERN_C_BEGIN @@ -14,4 +15,20 @@ LLVMCreateTargetMachineWithOpts(LLVMTargetRef ctarget, const char *triple, LLVMCodeModel code_model, bool EmitStackSizeSection, const char *StackUsageOutput); + +/* https://reviews.llvm.org/D153107 */ +#if LLVM_VERSION_MAJOR < 17 +typedef enum { + LLVMTailCallKindNone = 0, + LLVMTailCallKindTail = 1, + LLVMTailCallKindMustTail = 2, + LLVMTailCallKindNoTail = 3, +} LLVMTailCallKind; + +LLVMTailCallKind +LLVMGetTailCallKind(LLVMValueRef CallInst); +void +LLVMSetTailCallKind(LLVMValueRef CallInst, LLVMTailCallKind kind); +#endif + LLVM_C_EXTERN_C_END diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_orc_extra.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra.cpp similarity index 81% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_orc_extra.cpp rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra.cpp index 8cf253e9487..ad8c41c3fdd 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_orc_extra.cpp +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra.cpp @@ -8,17 +8,30 @@ #include "llvm-c/OrcEE.h" #include "llvm-c/TargetMachine.h" +#if LLVM_VERSION_MAJOR < 17 +#include "llvm/ADT/None.h" +#include "llvm/ADT/Optional.h" +#endif +#include "llvm/ExecutionEngine/JITEventListener.h" +#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h" #include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h" #include "llvm/ExecutionEngine/Orc/LLJIT.h" +#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" #include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h" #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h" -#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/Support/CBindingWrapping.h" #include "aot_orc_extra.h" #include "aot.h" +#if LLVM_VERSION_MAJOR >= 17 +namespace llvm { +template +using Optional = std::optional; +} +#endif + using namespace llvm; using namespace llvm::orc; using GlobalValueSet = std::set; @@ -97,6 +110,7 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ObjectTransformLayer, LLVMOrcObjectTransformLayerRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(OrcV2CAPIHelper::PoolEntry, LLVMOrcSymbolStringPoolEntryRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ObjectLayer, LLVMOrcObjectLayerRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(SymbolStringPool, LLVMOrcSymbolStringPoolRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ThreadSafeModule, LLVMOrcThreadSafeModuleRef) @@ -155,13 +169,29 @@ PartitionFunction(GlobalValueSet Requested) const char *wrapper; uint32 prefix_len = strlen(AOT_FUNC_PREFIX); + LOG_DEBUG("requested func %s", gvname); /* Convert "aot_func#n_wrapper" to "aot_func#n" */ - if (strstr(gvname, AOT_FUNC_PREFIX) - && (wrapper = strstr(gvname + prefix_len, "_wrapper"))) { + if (strstr(gvname, AOT_FUNC_PREFIX)) { char buf[16] = { 0 }; char func_name[64]; int group_stride, i, j; - + int num; + + /* + * if the jit wrapper (which has "_wrapper" suffix in + * the name) is requested, compile others in the group too. + * otherwise, only compile the requested one. + * (and possibly the correspondig wrapped function, + * which has AOT_FUNC_INTERNAL_PREFIX.) + */ + wrapper = strstr(gvname + prefix_len, "_wrapper"); + if (wrapper != NULL) { + num = WASM_ORC_JIT_COMPILE_THREAD_NUM; + } + else { + num = 1; + wrapper = strchr(gvname + prefix_len, 0); + } bh_assert(wrapper - (gvname + prefix_len) > 0); /* Get AOT function index */ bh_memcpy_s(buf, (uint32)sizeof(buf), gvname + prefix_len, @@ -171,10 +201,18 @@ PartitionFunction(GlobalValueSet Requested) group_stride = WASM_ORC_JIT_BACKEND_THREAD_NUM; /* Compile some functions each time */ - for (j = 0; j < WASM_ORC_JIT_COMPILE_THREAD_NUM; j++) { + for (j = 0; j < num; j++) { + Function *F1; snprintf(func_name, sizeof(func_name), "%s%d", AOT_FUNC_PREFIX, i + j * group_stride); - Function *F1 = M->getFunction(func_name); + F1 = M->getFunction(func_name); + if (F1) { + LOG_DEBUG("compile func %s", func_name); + GVsToAdd.push_back(cast(F1)); + } + snprintf(func_name, sizeof(func_name), "%s%d", + AOT_FUNC_INTERNAL_PREFIX, i + j * group_stride); + F1 = M->getFunction(func_name); if (F1) { LOG_DEBUG("compile func %s", func_name); GVsToAdd.push_back(cast(F1)); @@ -287,3 +325,9 @@ LLVMOrcLLLazyJITGetObjTransformLayer(LLVMOrcLLLazyJITRef J) { return wrap(&unwrap(J)->getObjTransformLayer()); } + +LLVMOrcObjectLayerRef +LLVMOrcLLLazyJITGetObjLinkingLayer(LLVMOrcLLLazyJITRef J) +{ + return wrap(&unwrap(J)->getObjLinkingLayer()); +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_orc_extra.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra.h similarity index 89% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_orc_extra.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra.h index e152b877843..32ece4de4e1 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/aot_orc_extra.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra.h @@ -71,5 +71,13 @@ LLVMOrcLLLazyJITGetIRTransformLayer(LLVMOrcLLLazyJITRef J); LLVMOrcObjectTransformLayerRef LLVMOrcLLLazyJITGetObjTransformLayer(LLVMOrcLLLazyJITRef J); +void +LLVMOrcLLJITBuilderSetCompileFuncitonCreatorWithStackSizesCallback( + LLVMOrcLLLazyJITBuilderRef Builder, + void (*cb)(void *, const char *, size_t, size_t), void *cb_data); + +LLVMOrcObjectLayerRef +LLVMOrcLLLazyJITGetObjLinkingLayer(LLVMOrcLLLazyJITRef J); + LLVM_C_EXTERN_C_END #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra2.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra2.cpp new file mode 100644 index 00000000000..515f7209f96 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/aot_orc_extra2.cpp @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2023 Midokura Japan KK. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include "llvm/ExecutionEngine/Orc/CompileUtils.h" +#include "llvm/ExecutionEngine/Orc/LLJIT.h" +#include "llvm/IR/LegacyPassManager.h" +#include "llvm/Object/ObjectFile.h" +#include "llvm/Support/SmallVectorMemoryBuffer.h" +#include "llvm/CodeGen/Passes.h" +#include "llvm/CodeGen/MachineFrameInfo.h" +#include "llvm/CodeGen/MachineFunctionPass.h" + +#include "aot_orc_extra.h" +#include "bh_log.h" + +typedef void (*cb_t)(void *, const char *, size_t, size_t); + +class MyCompiler : public llvm::orc::IRCompileLayer::IRCompiler +{ + public: + MyCompiler(llvm::orc::JITTargetMachineBuilder JTMB, cb_t cb, void *cb_data); + llvm::Expected operator()( + llvm::Module &M) override; + + private: + llvm::orc::JITTargetMachineBuilder JTMB; + + cb_t cb; + void *cb_data; +}; + +MyCompiler::MyCompiler(llvm::orc::JITTargetMachineBuilder JTMB, cb_t cb, + void *cb_data) + : IRCompiler(llvm::orc::irManglingOptionsFromTargetOptions(JTMB.getOptions())) + , JTMB(std::move(JTMB)) + , cb(cb) + , cb_data(cb_data) +{} + +class PrintStackSizes : public llvm::MachineFunctionPass +{ + public: + PrintStackSizes(cb_t cb, void *cb_data); + bool runOnMachineFunction(llvm::MachineFunction &MF) override; + static char ID; + + private: + cb_t cb; + void *cb_data; +}; + +PrintStackSizes::PrintStackSizes(cb_t cb, void *cb_data) + : MachineFunctionPass(ID) + , cb(cb) + , cb_data(cb_data) +{} + +char PrintStackSizes::ID = 0; + +bool +PrintStackSizes::runOnMachineFunction(llvm::MachineFunction &MF) +{ + auto name = MF.getName(); + auto MFI = &MF.getFrameInfo(); + size_t sz = MFI->getStackSize(); + cb(cb_data, name.data(), name.size(), sz); + return false; +} + +class MyPassManager : public llvm::legacy::PassManager +{ + public: + void add(llvm::Pass *P) override; +}; + +void +MyPassManager::add(llvm::Pass *P) +{ + // a hack to avoid having a copy of the whole addPassesToEmitMC. + // we want to add PrintStackSizes before FreeMachineFunctionPass. + if (P->getPassName() == "Free MachineFunction") { + return; + } + llvm::legacy::PassManager::add(P); +} + +// a modified copy from llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp +llvm::Expected +MyCompiler::operator()(llvm::Module &M) +{ + auto TM = cantFail(JTMB.createTargetMachine()); + llvm::SmallVector ObjBufferSV; + + { + llvm::raw_svector_ostream ObjStream(ObjBufferSV); + + MyPassManager PM; + llvm::MCContext *Ctx; + if (TM->addPassesToEmitMC(PM, Ctx, ObjStream)) + return llvm::make_error( + "Target does not support MC emission", + llvm::inconvertibleErrorCode()); + PM.add(new PrintStackSizes(cb, cb_data)); + dynamic_cast(&PM)->add( + llvm::createFreeMachineFunctionPass()); + PM.run(M); + } + +#if LLVM_VERSION_MAJOR > 13 + auto ObjBuffer = std::make_unique( + std::move(ObjBufferSV), + M.getModuleIdentifier() + "-jitted-objectbuffer", + /*RequiresNullTerminator=*/false); +#else + auto ObjBuffer = std::make_unique( + std::move(ObjBufferSV), + M.getModuleIdentifier() + "-jitted-objectbuffer"); +#endif + + return std::move(ObjBuffer); +} + +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(llvm::orc::LLLazyJITBuilder, + LLVMOrcLLLazyJITBuilderRef) + +void +LLVMOrcLLJITBuilderSetCompileFuncitonCreatorWithStackSizesCallback( + LLVMOrcLLLazyJITBuilderRef Builder, + void (*cb)(void *, const char *, size_t, size_t), void *cb_data) +{ + auto b = unwrap(Builder); + b->setCompileFunctionCreator( + [cb, cb_data](llvm::orc::JITTargetMachineBuilder JTMB) + -> llvm::Expected< + std::unique_ptr> { + return std::make_unique( + MyCompiler(std::move(JTMB), cb, cb_data)); + }); +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/debug/dwarf_extractor.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/debug/dwarf_extractor.cpp similarity index 92% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/debug/dwarf_extractor.cpp rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/debug/dwarf_extractor.cpp index d5a1be85e06..99182f82f99 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/debug/dwarf_extractor.cpp +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/debug/dwarf_extractor.cpp @@ -28,25 +28,25 @@ using namespace lldb; -typedef struct dwar_extractor { +typedef struct dwarf_extractor { SBDebugger debugger; SBTarget target; SBModule module; -} dwar_extractor; +} dwarf_extractor; -#define TO_HANDLE(extractor) (dwar_extractor_handle_t)(extractor) +#define TO_HANDLE(extractor) (dwarf_extractor_handle_t)(extractor) -#define TO_EXTACTOR(handle) (dwar_extractor *)(handle) +#define TO_EXTACTOR(handle) (dwarf_extractor *)(handle) static bool is_debugger_initialized; -dwar_extractor_handle_t +dwarf_extractor_handle_t create_dwarf_extractor(AOTCompData *comp_data, char *file_name) { char *arch = NULL; char *platform = NULL; - dwar_extractor *extractor = NULL; + dwarf_extractor *extractor = NULL; //__attribute__((constructor)) may be better? if (!is_debugger_initialized) { @@ -61,7 +61,7 @@ create_dwarf_extractor(AOTCompData *comp_data, char *file_name) SBError error; SBFileSpec exe_file_spec(file_name, true); - if (!(extractor = new dwar_extractor())) { + if (!(extractor = new dwarf_extractor())) { LOG_ERROR("Create Dwarf Extractor error: failed to allocate memory"); goto fail3; } @@ -101,9 +101,9 @@ create_dwarf_extractor(AOTCompData *comp_data, char *file_name) } void -destroy_dwarf_extractor(dwar_extractor_handle_t handle) +destroy_dwarf_extractor(dwarf_extractor_handle_t handle) { - dwar_extractor *extractor = TO_EXTACTOR(handle); + dwarf_extractor *extractor = TO_EXTACTOR(handle); if (!extractor) return; extractor->debugger.DeleteTarget(extractor->target); @@ -114,9 +114,9 @@ destroy_dwarf_extractor(dwar_extractor_handle_t handle) } LLVMMetadataRef -dwarf_gen_file_info(AOTCompContext *comp_ctx) +dwarf_gen_file_info(const AOTCompContext *comp_ctx) { - dwar_extractor *extractor; + dwarf_extractor *extractor; int units_number; LLVMMetadataRef file_info = NULL; const char *file_name; @@ -191,9 +191,9 @@ dwarf_gen_mock_vm_info(AOTCompContext *comp_ctx) #endif LLVMMetadataRef -dwarf_gen_comp_unit_info(AOTCompContext *comp_ctx) +dwarf_gen_comp_unit_info(const AOTCompContext *comp_ctx) { - dwar_extractor *extractor; + dwarf_extractor *extractor; int units_number; LLVMMetadataRef comp_unit = NULL; @@ -257,7 +257,7 @@ lldb_get_basic_type_encoding(BasicType basic_type) } static LLVMMetadataRef -lldb_type_to_type_dbi(AOTCompContext *comp_ctx, SBType &type) +lldb_type_to_type_dbi(const AOTCompContext *comp_ctx, SBType &type) { LLVMMetadataRef type_info = NULL; BasicType basic_type = type.GetBasicType(); @@ -282,8 +282,9 @@ lldb_type_to_type_dbi(AOTCompContext *comp_ctx, SBType &type) } static LLVMMetadataRef -lldb_function_to_function_dbi(AOTCompContext *comp_ctx, SBSymbolContext &sc, - AOTFuncContext *func_ctx) +lldb_function_to_function_dbi(const AOTCompContext *comp_ctx, + SBSymbolContext &sc, + const AOTFuncContext *func_ctx) { SBFunction function(sc.GetFunction()); const char *function_name = function.GetName(); @@ -291,7 +292,7 @@ lldb_function_to_function_dbi(AOTCompContext *comp_ctx, SBSymbolContext &sc, SBTypeList function_args = function.GetType().GetFunctionArgumentTypes(); SBType return_type = function.GetType().GetFunctionReturnType(); const size_t num_function_args = function_args.GetSize(); - dwar_extractor *extractor; + dwarf_extractor *extractor; if (!(extractor = TO_EXTACTOR(comp_ctx->comp_data->extractor))) return NULL; @@ -388,10 +389,11 @@ lldb_function_to_function_dbi(AOTCompContext *comp_ctx, SBSymbolContext &sc, } LLVMMetadataRef -dwarf_gen_func_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) +dwarf_gen_func_info(const AOTCompContext *comp_ctx, + const AOTFuncContext *func_ctx) { LLVMMetadataRef func_info = NULL; - dwar_extractor *extractor; + dwarf_extractor *extractor; uint64_t vm_offset; AOTFunc *func = func_ctx->aot_func; @@ -417,11 +419,11 @@ dwarf_gen_func_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) } void -dwarf_get_func_name(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - char *name, int len) +dwarf_get_func_name(const AOTCompContext *comp_ctx, + const AOTFuncContext *func_ctx, char *name, int len) { LLVMMetadataRef func_info = NULL; - dwar_extractor *extractor; + dwarf_extractor *extractor; uint64_t vm_offset; AOTFunc *func = func_ctx->aot_func; @@ -448,11 +450,11 @@ dwarf_get_func_name(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, } LLVMMetadataRef -dwarf_gen_location(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - uint64_t vm_offset) +dwarf_gen_location(const AOTCompContext *comp_ctx, + const AOTFuncContext *func_ctx, uint64_t vm_offset) { LLVMMetadataRef location_info = NULL; - dwar_extractor *extractor; + dwarf_extractor *extractor; AOTFunc *func = func_ctx->aot_func; if (!(extractor = TO_EXTACTOR(comp_ctx->comp_data->extractor))) @@ -487,10 +489,11 @@ dwarf_gen_location(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, } LLVMMetadataRef -dwarf_gen_func_ret_location(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) +dwarf_gen_func_ret_location(const AOTCompContext *comp_ctx, + const AOTFuncContext *func_ctx) { LLVMMetadataRef func_info = NULL; - dwar_extractor *extractor; + dwarf_extractor *extractor; uint64_t vm_offset; AOTFunc *func = func_ctx->aot_func; LLVMMetadataRef location_info = NULL; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/debug/dwarf_extractor.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/debug/dwarf_extractor.h similarity index 55% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/debug/dwarf_extractor.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/debug/dwarf_extractor.h index 449d4d57c51..0bacb97fa2e 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/debug/dwarf_extractor.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/debug/dwarf_extractor.h @@ -18,7 +18,7 @@ typedef unsigned int LLDBLangType; struct AOTCompData; typedef struct AOTCompData *aot_comp_data_t; -typedef void *dwar_extractor_handle_t; +typedef void *dwarf_extractor_handle_t; struct AOTCompContext; typedef struct AOTCompContext AOTCompContext; @@ -26,28 +26,30 @@ typedef struct AOTCompContext AOTCompContext; struct AOTFuncContext; typedef struct AOTFuncContext AOTFuncContext; -dwar_extractor_handle_t +dwarf_extractor_handle_t create_dwarf_extractor(aot_comp_data_t comp_data, char *file_name); LLVMMetadataRef -dwarf_gen_file_info(AOTCompContext *comp_ctx); +dwarf_gen_file_info(const AOTCompContext *comp_ctx); LLVMMetadataRef -dwarf_gen_comp_unit_info(AOTCompContext *comp_ctx); +dwarf_gen_comp_unit_info(const AOTCompContext *comp_ctx); LLVMMetadataRef -dwarf_gen_func_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx); +dwarf_gen_func_info(const AOTCompContext *comp_ctx, + const AOTFuncContext *func_ctx); LLVMMetadataRef -dwarf_gen_location(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - uint64_t vm_offset); +dwarf_gen_location(const AOTCompContext *comp_ctx, + const AOTFuncContext *func_ctx, uint64_t vm_offset); LLVMMetadataRef -dwarf_gen_func_ret_location(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx); +dwarf_gen_func_ret_location(const AOTCompContext *comp_ctx, + const AOTFuncContext *func_ctx); void -dwarf_get_func_name(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - char *name, int len); +dwarf_get_func_name(const AOTCompContext *comp_ctx, + const AOTFuncContext *func_ctx, char *name, int len); #ifdef __cplusplus } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/iwasm_compl.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/iwasm_compl.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/iwasm_compl.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/iwasm_compl.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_access_lanes.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_access_lanes.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_access_lanes.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_access_lanes.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_access_lanes.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_access_lanes.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_access_lanes.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_access_lanes.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bit_shifts.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bit_shifts.c similarity index 89% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bit_shifts.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bit_shifts.c index 675ffbcfe06..1d645ed7146 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bit_shifts.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bit_shifts.c @@ -30,11 +30,11 @@ simd_shift(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVM_CONST(i16x8_vec_zero), LLVM_CONST(i32x4_vec_zero), LLVM_CONST(i64x2_vec_zero) }; - LLVMValueRef lane_bits[] = { - LLVM_CONST(i32_eight), - LLVMConstInt(I32_TYPE, 16, true), - LLVMConstInt(I32_TYPE, 32, true), - LLVMConstInt(I32_TYPE, 64, true), + LLVMValueRef lane_shift_masks[] = { + LLVMConstInt(I32_TYPE, 7, true), + LLVMConstInt(I32_TYPE, 15, true), + LLVMConstInt(I32_TYPE, 31, true), + LLVMConstInt(I32_TYPE, 63, true), }; POP_I32(offset); @@ -44,11 +44,11 @@ simd_shift(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return false; } - /* offset mod LaneBits */ - if (!lane_bits[itype] - || !(offset = LLVMBuildSRem(comp_ctx->builder, offset, lane_bits[itype], - "offset_fix"))) { - HANDLE_FAILURE("LLVMBuildSRem"); + /* offset = offset & shift_mask */ + if (!lane_shift_masks[itype] + || !(offset = LLVMBuildAnd(comp_ctx->builder, offset, + lane_shift_masks[itype], "offset_fix"))) { + HANDLE_FAILURE("LLVMBuildAnd"); return false; } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bit_shifts.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bit_shifts.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bit_shifts.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bit_shifts.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bitmask_extracts.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bitmask_extracts.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bitmask_extracts.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bitmask_extracts.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bitmask_extracts.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bitmask_extracts.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bitmask_extracts.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bitmask_extracts.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bitwise_ops.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bitwise_ops.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bitwise_ops.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bitwise_ops.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bitwise_ops.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bitwise_ops.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bitwise_ops.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bitwise_ops.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bool_reductions.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bool_reductions.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bool_reductions.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bool_reductions.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bool_reductions.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bool_reductions.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_bool_reductions.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_bool_reductions.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_common.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_common.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_common.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_common.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_common.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_common.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_common.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_common.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_comparisons.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_comparisons.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_comparisons.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_comparisons.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_comparisons.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_comparisons.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_comparisons.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_comparisons.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_construct_values.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_construct_values.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_construct_values.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_construct_values.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_construct_values.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_construct_values.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_construct_values.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_construct_values.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_conversions.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_conversions.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_conversions.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_conversions.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_conversions.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_conversions.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_conversions.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_conversions.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_floating_point.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_floating_point.c similarity index 62% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_floating_point.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_floating_point.c index d850fe8f75e..7fcc1ab655d 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_floating_point.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_floating_point.c @@ -217,10 +217,9 @@ aot_compile_simd_f64x2_nearest(AOTCompContext *comp_ctx, static bool simd_float_cmp(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - FloatArithmetic arith_op, LLVMTypeRef vector_type) + FloatArithmetic op, LLVMTypeRef vector_type) { - LLVMValueRef lhs, rhs, result; - LLVMRealPredicate op = FLOAT_MIN == arith_op ? LLVMRealULT : LLVMRealUGT; + LLVMValueRef lhs, rhs, cmp, selected; if (!(rhs = simd_pop_v128_and_bitcast(comp_ctx, func_ctx, vector_type, "rhs")) @@ -229,47 +228,122 @@ simd_float_cmp(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return false; } - if (!(result = LLVMBuildFCmp(comp_ctx->builder, op, lhs, rhs, "cmp"))) { + if (!(cmp = LLVMBuildFCmp(comp_ctx->builder, + op == FLOAT_MIN ? LLVMRealOLT : LLVMRealOGT, rhs, + lhs, "cmp"))) { HANDLE_FAILURE("LLVMBuildFCmp"); return false; } - if (!(result = - LLVMBuildSelect(comp_ctx->builder, result, lhs, rhs, "select"))) { + if (!(selected = + LLVMBuildSelect(comp_ctx->builder, cmp, rhs, lhs, "selected"))) { HANDLE_FAILURE("LLVMBuildSelect"); return false; } - return simd_bitcast_and_push_v128(comp_ctx, func_ctx, result, "result"); + return simd_bitcast_and_push_v128(comp_ctx, func_ctx, selected, "result"); } -/*TODO: sugggest non-IA platforms check with "llvm.minimum.*" and - * "llvm.maximum.*" firstly */ -bool -aot_compile_simd_f32x4_min_max(AOTCompContext *comp_ctx, - AOTFuncContext *func_ctx, bool run_min) +static bool +simd_float_min(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, + LLVMTypeRef vector_type) { - return simd_float_cmp(comp_ctx, func_ctx, run_min ? FLOAT_MIN : FLOAT_MAX, - V128_f32x4_TYPE); -} + LLVMValueRef lhs, rhs, lhs_nan, rhs_nan, olt_ret, ogt_ret, or_ret, ret1, + ret2, ret3, ret4; -bool -aot_compile_simd_f64x2_min_max(AOTCompContext *comp_ctx, - AOTFuncContext *func_ctx, bool run_min) -{ - return simd_float_cmp(comp_ctx, func_ctx, run_min ? FLOAT_MIN : FLOAT_MAX, - V128_f64x2_TYPE); + if (!(rhs = + simd_pop_v128_and_bitcast(comp_ctx, func_ctx, vector_type, "rhs")) + || !(lhs = simd_pop_v128_and_bitcast(comp_ctx, func_ctx, vector_type, + "lhs"))) { + return false; + } + + if (!(lhs_nan = LLVMBuildFCmp(comp_ctx->builder, LLVMRealUNO, lhs, lhs, + "lhs_nan"))) { + HANDLE_FAILURE("LLVMBuildFCmp + LLVMRealUNO"); + return false; + } + + if (!(rhs_nan = LLVMBuildFCmp(comp_ctx->builder, LLVMRealUNO, rhs, rhs, + "rhs_nan"))) { + HANDLE_FAILURE("LLVMBuildFCmp + LLVMRealUNO"); + return false; + } + + if (!(olt_ret = LLVMBuildFCmp(comp_ctx->builder, LLVMRealOLT, lhs, rhs, + "olt_ret"))) { + HANDLE_FAILURE("LLVMBuildFCmp + LLVMRealOLT"); + return false; + } + + if (!(ogt_ret = LLVMBuildFCmp(comp_ctx->builder, LLVMRealOGT, lhs, rhs, + "ogt_ret"))) { + HANDLE_FAILURE("LLVMBuildFCmp + LLVMRealOGT"); + return false; + } + + /* lhs or rhs */ + { + LLVMValueRef integer_l, integer_r, integer_or; + + if (!(integer_l = LLVMBuildBitCast(comp_ctx->builder, lhs, + V128_i64x2_TYPE, "lhs_to_int"))) { + HANDLE_FAILURE("LLVMBuildBitCas"); + return false; + } + + if (!(integer_r = LLVMBuildBitCast(comp_ctx->builder, rhs, + V128_i64x2_TYPE, "rhs_to_int"))) { + HANDLE_FAILURE("LLVMBuildBitCas"); + return false; + } + + if (!(integer_or = + LLVMBuildOr(comp_ctx->builder, integer_l, integer_r, "or"))) { + HANDLE_FAILURE("LLVMBuildOr"); + return false; + } + + if (!(or_ret = LLVMBuildBitCast(comp_ctx->builder, integer_or, + vector_type, "holder"))) { + HANDLE_FAILURE("LLVMBuildBitCast"); + return false; + } + } + + if (!(ret1 = LLVMBuildSelect(comp_ctx->builder, olt_ret, lhs, or_ret, + "sel_olt"))) { + HANDLE_FAILURE("LLVMBuildSelect"); + return false; + } + + if (!(ret2 = LLVMBuildSelect(comp_ctx->builder, ogt_ret, rhs, ret1, + "sel_ogt"))) { + HANDLE_FAILURE("LLVMBuildSelect"); + return false; + } + + if (!(ret3 = LLVMBuildSelect(comp_ctx->builder, lhs_nan, lhs, ret2, + "sel_lhs_nan"))) { + HANDLE_FAILURE("LLVMBuildSelect"); + return false; + } + + if (!(ret4 = LLVMBuildSelect(comp_ctx->builder, rhs_nan, rhs, ret3, + "sel_rhs_nan"))) { + HANDLE_FAILURE("LLVMBuildSelect"); + return false; + } + + return simd_bitcast_and_push_v128(comp_ctx, func_ctx, ret4, "result"); } static bool -simd_float_pmin_max(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - LLVMTypeRef vector_type, const char *intrinsic) +simd_float_max(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, + LLVMTypeRef vector_type) { - LLVMValueRef lhs, rhs, result; - LLVMTypeRef param_types[2]; - - param_types[0] = vector_type; - param_types[1] = vector_type; + LLVMValueRef lhs, rhs, lhs_nan, rhs_nan, olt_ret, ogt_ret, and_ret, ret1, + ret2, ret3, ret4; if (!(rhs = simd_pop_v128_and_bitcast(comp_ctx, func_ctx, vector_type, "rhs")) @@ -278,31 +352,116 @@ simd_float_pmin_max(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return false; } - if (!(result = - aot_call_llvm_intrinsic(comp_ctx, func_ctx, intrinsic, - vector_type, param_types, 2, lhs, rhs))) { + if (!(lhs_nan = LLVMBuildFCmp(comp_ctx->builder, LLVMRealUNO, lhs, lhs, + "lhs_nan"))) { + HANDLE_FAILURE("LLVMBuildFCmp + LLVMRealUNO"); return false; } - return simd_bitcast_and_push_v128(comp_ctx, func_ctx, result, "result"); + if (!(rhs_nan = LLVMBuildFCmp(comp_ctx->builder, LLVMRealUNO, rhs, rhs, + "rhs_nan"))) { + HANDLE_FAILURE("LLVMBuildFCmp + LLVMRealUNO"); + return false; + } + + if (!(olt_ret = LLVMBuildFCmp(comp_ctx->builder, LLVMRealOLT, lhs, rhs, + "olt_ret"))) { + HANDLE_FAILURE("LLVMBuildFCmp + LLVMRealOLT"); + return false; + } + + if (!(ogt_ret = LLVMBuildFCmp(comp_ctx->builder, LLVMRealOGT, lhs, rhs, + "ogt_ret"))) { + HANDLE_FAILURE("LLVMBuildFCmp + LLVMRealOGT"); + return false; + } + + /* lhs and rhs */ + { + LLVMValueRef integer_l, integer_r, integer_and; + + if (!(integer_l = LLVMBuildBitCast(comp_ctx->builder, lhs, + V128_i64x2_TYPE, "lhs_to_int"))) { + HANDLE_FAILURE("LLVMBuildBitCas"); + return false; + } + + if (!(integer_r = LLVMBuildBitCast(comp_ctx->builder, rhs, + V128_i64x2_TYPE, "rhs_to_int"))) { + HANDLE_FAILURE("LLVMBuildBitCas"); + return false; + } + + if (!(integer_and = LLVMBuildAnd(comp_ctx->builder, integer_l, + integer_r, "and"))) { + HANDLE_FAILURE("LLVMBuildOr"); + return false; + } + + if (!(and_ret = LLVMBuildBitCast(comp_ctx->builder, integer_and, + vector_type, "holder"))) { + HANDLE_FAILURE("LLVMBuildBitCast"); + return false; + } + } + + if (!(ret1 = LLVMBuildSelect(comp_ctx->builder, ogt_ret, lhs, and_ret, + "sel_ogt"))) { + HANDLE_FAILURE("LLVMBuildSelect"); + return false; + } + + if (!(ret2 = LLVMBuildSelect(comp_ctx->builder, olt_ret, rhs, ret1, + "sel_olt"))) { + HANDLE_FAILURE("LLVMBuildSelect"); + return false; + } + + if (!(ret3 = LLVMBuildSelect(comp_ctx->builder, lhs_nan, lhs, ret2, + "sel_lhs_nan"))) { + HANDLE_FAILURE("LLVMBuildSelect"); + return false; + } + + if (!(ret4 = LLVMBuildSelect(comp_ctx->builder, rhs_nan, rhs, ret3, + "sel_rhs_nan"))) { + HANDLE_FAILURE("LLVMBuildSelect"); + return false; + } + + return simd_bitcast_and_push_v128(comp_ctx, func_ctx, ret4, "result"); +} + +bool +aot_compile_simd_f32x4_min_max(AOTCompContext *comp_ctx, + AOTFuncContext *func_ctx, bool run_min) +{ + return run_min ? simd_float_min(comp_ctx, func_ctx, V128_f32x4_TYPE) + : simd_float_max(comp_ctx, func_ctx, V128_f32x4_TYPE); +} + +bool +aot_compile_simd_f64x2_min_max(AOTCompContext *comp_ctx, + AOTFuncContext *func_ctx, bool run_min) +{ + return run_min ? simd_float_min(comp_ctx, func_ctx, V128_f64x2_TYPE) + : simd_float_max(comp_ctx, func_ctx, V128_f64x2_TYPE); } bool aot_compile_simd_f32x4_pmin_pmax(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, bool run_min) { - return simd_float_pmin_max(comp_ctx, func_ctx, V128_f32x4_TYPE, - run_min ? "llvm.minnum.v4f32" - : "llvm.maxnum.v4f32"); + return simd_float_cmp(comp_ctx, func_ctx, run_min ? FLOAT_MIN : FLOAT_MAX, + V128_f32x4_TYPE); } bool aot_compile_simd_f64x2_pmin_pmax(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, bool run_min) { - return simd_float_pmin_max(comp_ctx, func_ctx, V128_f64x2_TYPE, - run_min ? "llvm.minnum.v2f64" - : "llvm.maxnum.v2f64"); + return simd_float_cmp(comp_ctx, func_ctx, run_min ? FLOAT_MIN : FLOAT_MAX, + V128_f64x2_TYPE); } bool diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_floating_point.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_floating_point.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_floating_point.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_floating_point.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_int_arith.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_int_arith.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_int_arith.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_int_arith.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_int_arith.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_int_arith.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_int_arith.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_int_arith.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_load_store.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_load_store.c similarity index 76% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_load_store.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_load_store.c index d166e954c59..0e869727a0b 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_load_store.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_load_store.c @@ -14,12 +14,12 @@ static LLVMValueRef simd_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align, uint32 offset, uint32 data_length, LLVMTypeRef ptr_type, - LLVMTypeRef data_type) + LLVMTypeRef data_type, bool enable_segue) { LLVMValueRef maddr, data; if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, - data_length))) { + data_length, enable_segue))) { HANDLE_FAILURE("aot_check_memory_overflow"); return NULL; } @@ -44,10 +44,12 @@ bool aot_compile_simd_v128_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align, uint32 offset) { + bool enable_segue = comp_ctx->enable_segue_v128_load; + LLVMTypeRef v128_ptr_type = enable_segue ? V128_PTR_TYPE_GS : V128_PTR_TYPE; LLVMValueRef result; if (!(result = simd_load(comp_ctx, func_ctx, align, offset, 16, - V128_PTR_TYPE, V128_TYPE))) { + v128_ptr_type, V128_TYPE, enable_segue))) { return false; } @@ -75,6 +77,7 @@ aot_compile_simd_load_extend(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMVectorType(I32_TYPE, 2), LLVMVectorType(I32_TYPE, 2), }; LLVMTypeRef sub_vector_type, sub_vector_ptr_type; + bool enable_segue = comp_ctx->enable_segue_v128_load; bh_assert(opcode_index < 6); @@ -82,13 +85,15 @@ aot_compile_simd_load_extend(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, /* to vector ptr type */ if (!sub_vector_type - || !(sub_vector_ptr_type = LLVMPointerType(sub_vector_type, 0))) { + || !(sub_vector_ptr_type = + LLVMPointerType(sub_vector_type, enable_segue ? 256 : 0))) { HANDLE_FAILURE("LLVMPointerType"); return false; } - if (!(sub_vector = simd_load(comp_ctx, func_ctx, align, offset, 8, - sub_vector_ptr_type, sub_vector_type))) { + if (!(sub_vector = + simd_load(comp_ctx, func_ctx, align, offset, 8, + sub_vector_ptr_type, sub_vector_type, enable_segue))) { return false; } @@ -118,6 +123,9 @@ aot_compile_simd_load_splat(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMValueRef element, result; LLVMTypeRef element_ptr_types[] = { INT8_PTR_TYPE, INT16_PTR_TYPE, INT32_PTR_TYPE, INT64_PTR_TYPE }; + LLVMTypeRef element_ptr_types_gs[] = { INT8_PTR_TYPE_GS, INT16_PTR_TYPE_GS, + INT32_PTR_TYPE_GS, + INT64_PTR_TYPE_GS }; LLVMTypeRef element_data_types[] = { INT8_TYPE, INT16_TYPE, I32_TYPE, I64_TYPE }; uint32 data_lengths[] = { 1, 2, 4, 8 }; @@ -133,13 +141,16 @@ aot_compile_simd_load_splat(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVM_CONST(i32x4_zero), LLVM_CONST(i32x2_zero), }; + bool enable_segue = comp_ctx->enable_segue_v128_load; bh_assert(opcode_index < 4); - if (!(element = simd_load(comp_ctx, func_ctx, align, offset, - data_lengths[opcode_index], - element_ptr_types[opcode_index], - element_data_types[opcode_index]))) { + if (!(element = simd_load( + comp_ctx, func_ctx, align, offset, data_lengths[opcode_index], + comp_ctx->enable_segue_v128_load + ? element_ptr_types_gs[opcode_index] + : element_ptr_types[opcode_index], + element_data_types[opcode_index], enable_segue))) { return false; } @@ -170,11 +181,15 @@ aot_compile_simd_load_lane(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 data_lengths[] = { 1, 2, 4, 8 }; LLVMTypeRef element_ptr_types[] = { INT8_PTR_TYPE, INT16_PTR_TYPE, INT32_PTR_TYPE, INT64_PTR_TYPE }; + LLVMTypeRef element_ptr_types_gs[] = { INT8_PTR_TYPE_GS, INT16_PTR_TYPE_GS, + INT32_PTR_TYPE_GS, + INT64_PTR_TYPE_GS }; LLVMTypeRef element_data_types[] = { INT8_TYPE, INT16_TYPE, I32_TYPE, I64_TYPE }; LLVMTypeRef vector_types[] = { V128_i8x16_TYPE, V128_i16x8_TYPE, V128_i32x4_TYPE, V128_i64x2_TYPE }; LLVMValueRef lane = simd_lane_id_to_llvm_value(comp_ctx, lane_id); + bool enable_segue = comp_ctx->enable_segue_v128_load; bh_assert(opcode_index < 4); @@ -183,10 +198,12 @@ aot_compile_simd_load_lane(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return false; } - if (!(element = simd_load(comp_ctx, func_ctx, align, offset, - data_lengths[opcode_index], - element_ptr_types[opcode_index], - element_data_types[opcode_index]))) { + if (!(element = simd_load( + comp_ctx, func_ctx, align, offset, data_lengths[opcode_index], + comp_ctx->enable_segue_v128_load + ? element_ptr_types_gs[opcode_index] + : element_ptr_types[opcode_index], + element_data_types[opcode_index], enable_segue))) { return false; } @@ -207,6 +224,8 @@ aot_compile_simd_load_zero(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 opcode_index = opcode - SIMD_v128_load32_zero; uint32 data_lengths[] = { 4, 8 }; LLVMTypeRef element_ptr_types[] = { INT32_PTR_TYPE, INT64_PTR_TYPE }; + LLVMTypeRef element_ptr_types_gs[] = { INT32_PTR_TYPE_GS, + INT64_PTR_TYPE_GS }; LLVMTypeRef element_data_types[] = { I32_TYPE, I64_TYPE }; LLVMValueRef zero[] = { LLVM_CONST(i32x4_vec_zero), @@ -222,13 +241,16 @@ aot_compile_simd_load_zero(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVM_CONST(i32_six) }, { LLVM_CONST(i32_zero), LLVM_CONST(i32_two) }, }; + bool enable_segue = comp_ctx->enable_segue_v128_load; bh_assert(opcode_index < 2); - if (!(element = simd_load(comp_ctx, func_ctx, align, offset, - data_lengths[opcode_index], - element_ptr_types[opcode_index], - element_data_types[opcode_index]))) { + if (!(element = simd_load( + comp_ctx, func_ctx, align, offset, data_lengths[opcode_index], + comp_ctx->enable_segue_v128_load + ? element_ptr_types_gs[opcode_index] + : element_ptr_types[opcode_index], + element_data_types[opcode_index], enable_segue))) { return false; } @@ -260,12 +282,12 @@ aot_compile_simd_load_zero(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, static bool simd_store(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align, uint32 offset, uint32 data_length, LLVMValueRef value, - LLVMTypeRef value_ptr_type) + LLVMTypeRef value_ptr_type, bool enable_segue) { LLVMValueRef maddr, result; if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, - data_length))) + data_length, enable_segue))) return false; if (!(maddr = LLVMBuildBitCast(comp_ctx->builder, maddr, value_ptr_type, @@ -288,12 +310,14 @@ bool aot_compile_simd_v128_store(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align, uint32 offset) { + bool enable_segue = comp_ctx->enable_segue_v128_store; + LLVMTypeRef v128_ptr_type = enable_segue ? V128_PTR_TYPE_GS : V128_PTR_TYPE; LLVMValueRef value; POP_V128(value); return simd_store(comp_ctx, func_ctx, align, offset, 16, value, - V128_PTR_TYPE); + v128_ptr_type, enable_segue); fail: return false; } @@ -307,10 +331,14 @@ aot_compile_simd_store_lane(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 data_lengths[] = { 1, 2, 4, 8 }; LLVMTypeRef element_ptr_types[] = { INT8_PTR_TYPE, INT16_PTR_TYPE, INT32_PTR_TYPE, INT64_PTR_TYPE }; + LLVMTypeRef element_ptr_types_gs[] = { INT8_PTR_TYPE_GS, INT16_PTR_TYPE_GS, + INT32_PTR_TYPE_GS, + INT64_PTR_TYPE_GS }; uint32 opcode_index = opcode - SIMD_v128_store8_lane; LLVMTypeRef vector_types[] = { V128_i8x16_TYPE, V128_i16x8_TYPE, V128_i32x4_TYPE, V128_i64x2_TYPE }; LLVMValueRef lane = simd_lane_id_to_llvm_value(comp_ctx, lane_id); + bool enable_segue = comp_ctx->enable_segue_v128_store; bh_assert(opcode_index < 4); @@ -327,5 +355,7 @@ aot_compile_simd_store_lane(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return simd_store(comp_ctx, func_ctx, align, offset, data_lengths[opcode_index], element, - element_ptr_types[opcode_index]); + enable_segue ? element_ptr_types_gs[opcode_index] + : element_ptr_types[opcode_index], + enable_segue); } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_load_store.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_load_store.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_load_store.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_load_store.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_sat_int_arith.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_sat_int_arith.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_sat_int_arith.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_sat_int_arith.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_sat_int_arith.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_sat_int_arith.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/compilation/simd/simd_sat_int_arith.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/compilation/simd/simd_sat_int_arith.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/classic_interpreter.MD b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/classic_interpreter.MD similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/classic_interpreter.MD rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/classic_interpreter.MD diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/export_function.excalidraw b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/export_function.excalidraw similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/export_function.excalidraw rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/export_function.excalidraw diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/stack_format_ci.excalidraw b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/stack_format_ci.excalidraw similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/stack_format_ci.excalidraw rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/stack_format_ci.excalidraw diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/stack_format_ci.svg b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/stack_format_ci.svg similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/stack_format_ci.svg rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/stack_format_ci.svg diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_exports.svg b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_exports.svg similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_exports.svg rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_exports.svg diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_function.excalidraw b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_function.excalidraw similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_function.excalidraw rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_function.excalidraw diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_function.svg b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_function.svg similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_function.svg rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_function.svg diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_globals.excalidraw b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_globals.excalidraw similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_globals.excalidraw rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_globals.excalidraw diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_globals.svg b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_globals.svg similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/images/wasm_globals.svg rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/images/wasm_globals.svg diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/wasm_exports.MD b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/wasm_exports.MD similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/wasm_exports.MD rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/wasm_exports.MD diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/wasm_function.MD b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/wasm_function.MD similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/wasm_function.MD rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/wasm_function.MD diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/wasm_globals.MD b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/wasm_globals.MD similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/doc/wasm_globals.MD rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/doc/wasm_globals.MD diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/asmjit_sgx_patch.diff b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/asmjit_sgx_patch.diff similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/asmjit_sgx_patch.diff rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/asmjit_sgx_patch.diff diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/cg/LICENSE_ASMJIT b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/cg/LICENSE_ASMJIT similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/cg/LICENSE_ASMJIT rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/cg/LICENSE_ASMJIT diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/cg/LICENSE_ZYDIS b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/cg/LICENSE_ZYDIS similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/cg/LICENSE_ZYDIS rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/cg/LICENSE_ZYDIS diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_compare.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_compare.c similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_compare.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_compare.c index d41249346bc..8fe48f142b3 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_compare.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_compare.c @@ -227,7 +227,7 @@ jit_compile_op_f32_compare(JitCompContext *cc, FloatCond cond) POP_F32(rhs); POP_F32(lhs); - if (jit_reg_is_const_val(lhs) && jit_reg_is_const_val(rhs)) { + if (jit_reg_is_const(lhs) && jit_reg_is_const(rhs)) { float32 lvalue = jit_cc_get_const_F32(cc, lhs); float32 rvalue = jit_cc_get_const_F32(cc, rhs); @@ -290,7 +290,7 @@ jit_compile_op_f64_compare(JitCompContext *cc, FloatCond cond) POP_F64(rhs); POP_F64(lhs); - if (jit_reg_is_const_val(lhs) && jit_reg_is_const_val(rhs)) { + if (jit_reg_is_const(lhs) && jit_reg_is_const(rhs)) { float64 lvalue = jit_cc_get_const_F64(cc, lhs); float64 rvalue = jit_cc_get_const_F64(cc, rhs); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_compare.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_compare.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_compare.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_compare.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_const.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_const.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_const.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_const.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_const.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_const.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_const.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_const.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_control.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_control.c similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_control.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_control.c index f7536c73ea1..5438bc62cfe 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_control.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_control.c @@ -808,7 +808,7 @@ jit_compile_op_block(JitCompContext *cc, uint8 **p_frame_ip, else if (label_type == LABEL_TYPE_IF) { POP_I32(value); - if (!jit_reg_is_const_val(value)) { + if (!jit_reg_is_const(value)) { /* Compare value is not constant, create condition br IR */ /* Create entry block */ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_control.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_control.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_control.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_control.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_conversion.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_conversion.c similarity index 87% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_conversion.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_conversion.c index 8308a3ca945..89d84f142ee 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_conversion.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_conversion.c @@ -192,6 +192,55 @@ jit_compile_check_value_range(JitCompContext *cc, JitReg value, JitReg min_fp, bh_assert(JIT_REG_KIND_F32 == kind || JIT_REG_KIND_F64 == kind); + if (JIT_REG_KIND_F32 == kind && jit_reg_is_const(value)) { + /* value is an f32 const */ + float value_f32_const = jit_cc_get_const_F32(cc, value); + float min_fp_f32_const = jit_cc_get_const_F32(cc, min_fp); + float max_fp_f32_const = jit_cc_get_const_F32(cc, max_fp); + + if (isnan(value_f32_const)) { + /* throw exception if value is nan */ + if (!jit_emit_exception(cc, EXCE_INVALID_CONVERSION_TO_INTEGER, + JIT_OP_JMP, 0, NULL)) + goto fail; + } + + if (value_f32_const <= min_fp_f32_const + || value_f32_const >= max_fp_f32_const) { + /* throw exception if value is out of range */ + if (!jit_emit_exception(cc, EXCE_INTEGER_OVERFLOW, JIT_OP_JMP, 0, + NULL)) + goto fail; + } + + /* value is in range, do nothing */ + return true; + } + else if (JIT_REG_KIND_F64 == kind && jit_reg_is_const(value)) { + /* value is an f64 const */ + double value_f64_const = jit_cc_get_const_F64(cc, value); + double min_fp_f64_const = jit_cc_get_const_F64(cc, min_fp); + double max_fp_f64_const = jit_cc_get_const_F64(cc, max_fp); + + if (isnan(value_f64_const)) { + /* throw exception if value is nan */ + if (!jit_emit_exception(cc, EXCE_INVALID_CONVERSION_TO_INTEGER, + JIT_OP_JMP, 0, NULL)) + goto fail; + } + + if (value_f64_const <= min_fp_f64_const + || value_f64_const >= max_fp_f64_const) { + /* throw exception if value is out of range */ + if (!jit_emit_exception(cc, EXCE_INTEGER_OVERFLOW, JIT_OP_JMP, 0, + NULL)) + goto fail; + } + + /* value is in range, do nothing */ + return true; + } + /* If value is NaN, throw exception */ if (JIT_REG_KIND_F32 == kind) emit_ret = jit_emit_callnative(cc, local_isnanf, nan_ret, &value, 1); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_conversion.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_conversion.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_conversion.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_conversion.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_exception.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_exception.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_exception.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_exception.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_exception.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_exception.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_exception.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_exception.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_function.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_function.c similarity index 96% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_function.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_function.c index 3ac9e3ed6bb..43a71e26aee 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_function.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_function.c @@ -827,23 +827,45 @@ emit_callnative(JitCompContext *cc, JitReg native_func_reg, JitReg res, JitReg *params, uint32 param_count) { JitInsn *insn; + char *i32_arg_names[] = { "edi", "esi", "edx", "ecx" }; char *i64_arg_names[] = { "rdi", "rsi", "rdx", "rcx", "r8", "r9" }; char *f32_arg_names[] = { "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" }; char *f64_arg_names[] = { "xmm0_f64", "xmm1_f64", "xmm2_f64", "xmm3_f64", "xmm4_f64", "xmm5_f64" }; - JitReg i64_arg_regs[6], f32_arg_regs[6], f64_arg_regs[6], res_reg = 0; + JitReg i32_arg_regs[4], i64_arg_regs[6]; + JitReg f32_arg_regs[6], f64_arg_regs[6], res_reg = 0; JitReg eax_hreg = jit_codegen_get_hreg_by_name("eax"); JitReg xmm0_hreg = jit_codegen_get_hreg_by_name("xmm0"); - uint32 i, i64_reg_idx, float_reg_idx; + uint32 i, i64_reg_idx, float_reg_idx, lock_i32_reg_num; bh_assert(param_count <= 6); + for (i = 0; i < 4; i++) { + i32_arg_regs[i] = jit_codegen_get_hreg_by_name(i32_arg_names[i]); + } + for (i = 0; i < 6; i++) { i64_arg_regs[i] = jit_codegen_get_hreg_by_name(i64_arg_names[i]); f32_arg_regs[i] = jit_codegen_get_hreg_by_name(f32_arg_names[i]); f64_arg_regs[i] = jit_codegen_get_hreg_by_name(f64_arg_names[i]); } + lock_i32_reg_num = param_count < 4 ? param_count : 4; + + /* + * Lock i32 registers so that they won't be allocated for the operand + * of below I32TOI64 insn, which may have been overwritten in the + * previous MOV, for example, in the below insns: + * MOV I5, I15 + * I32TOI64 I6, i5 + * CALLNATIVE VOID, native_func, I5, I6 + * i5 is used in the second insn, but it has been overwritten in I5 + * by the first insn + */ + for (i = 0; i < lock_i32_reg_num; i++) { + GEN_INSN(MOV, i32_arg_regs[i], i32_arg_regs[i]); + } + i64_reg_idx = float_reg_idx = 0; for (i = 0; i < param_count; i++) { switch (jit_reg_kind(params[i])) { @@ -865,6 +887,14 @@ emit_callnative(JitCompContext *cc, JitReg native_func_reg, JitReg res, } } + /* + * Announce the locked i32 registers are being used, and do necessary + * spill ASAP + */ + for (i = 0; i < lock_i32_reg_num; i++) { + GEN_INSN(MOV, i32_arg_regs[i], i32_arg_regs[i]); + } + if (res) { switch (jit_reg_kind(res)) { case JIT_REG_KIND_I32: diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_function.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_function.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_function.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_function.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_memory.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_memory.c similarity index 94% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_memory.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_memory.c index 9635d4e57e2..420b4dd8e52 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_memory.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_memory.c @@ -137,6 +137,7 @@ check_and_seek(JitCompContext *cc, JitReg addr, uint32 offset, uint32 bytes) { JitReg memory_boundary = 0, offset1; #ifndef OS_ENABLE_HW_BOUND_CHECK + JitReg cur_page_count; /* the default memory */ uint32 mem_idx = 0; #endif @@ -146,16 +147,10 @@ check_and_seek(JitCompContext *cc, JitReg addr, uint32 offset, uint32 bytes) /* 1. shortcut if the memory size is 0 */ if (cc->cur_wasm_module->memories != NULL && 0 == cc->cur_wasm_module->memories[mem_idx].init_page_count) { - JitReg module_inst, cur_page_count; - uint32 cur_page_count_offset = - (uint32)offsetof(WASMModuleInstance, global_table_data.bytes) - + (uint32)offsetof(WASMMemoryInstance, cur_page_count); + + cur_page_count = get_cur_page_count_reg(cc->jit_frame, mem_idx); /* if (cur_mem_page_count == 0) goto EXCEPTION */ - module_inst = get_module_inst_reg(cc->jit_frame); - cur_page_count = jit_cc_new_reg_I32(cc); - GEN_INSN(LDI32, cur_page_count, module_inst, - NEW_CONST(I32, cur_page_count_offset)); GEN_INSN(CMP, cc->cmp_reg, cur_page_count, NEW_CONST(I32, 0)); if (!jit_emit_exception(cc, EXCE_OUT_OF_BOUNDS_MEMORY_ACCESS, JIT_OP_BEQ, cc->cmp_reg, NULL)) { @@ -580,15 +575,9 @@ jit_compile_op_f64_store(JitCompContext *cc, uint32 align, uint32 offset) bool jit_compile_op_memory_size(JitCompContext *cc, uint32 mem_idx) { - JitReg module_inst, cur_page_count; - uint32 cur_page_count_offset = - (uint32)offsetof(WASMModuleInstance, global_table_data.bytes) - + (uint32)offsetof(WASMMemoryInstance, cur_page_count); + JitReg cur_page_count; - module_inst = get_module_inst_reg(cc->jit_frame); - cur_page_count = jit_cc_new_reg_I32(cc); - GEN_INSN(LDI32, cur_page_count, module_inst, - NEW_CONST(I32, cur_page_count_offset)); + cur_page_count = get_cur_page_count_reg(cc->jit_frame, mem_idx); PUSH_I32(cur_page_count); @@ -600,18 +589,11 @@ jit_compile_op_memory_size(JitCompContext *cc, uint32 mem_idx) bool jit_compile_op_memory_grow(JitCompContext *cc, uint32 mem_idx) { - JitReg module_inst, grow_res, res; + JitReg grow_res, res; JitReg prev_page_count, inc_page_count, args[2]; - /* Get current page count */ - uint32 cur_page_count_offset = - (uint32)offsetof(WASMModuleInstance, global_table_data.bytes) - + (uint32)offsetof(WASMMemoryInstance, cur_page_count); - - module_inst = get_module_inst_reg(cc->jit_frame); - prev_page_count = jit_cc_new_reg_I32(cc); - GEN_INSN(LDI32, prev_page_count, module_inst, - NEW_CONST(I32, cur_page_count_offset)); + /* Get current page count as prev_page_count */ + prev_page_count = get_cur_page_count_reg(cc->jit_frame, mem_idx); /* Call wasm_enlarge_memory */ POP_I32(inc_page_count); @@ -650,6 +632,7 @@ wasm_init_memory(WASMModuleInstance *inst, uint32 mem_idx, uint32 seg_idx, WASMDataSeg *data_segment; uint32 mem_size; uint8 *mem_addr, *data_addr; + uint32 seg_len; /* if d + n > the length of mem.data */ mem_inst = inst->memories[mem_idx]; @@ -659,13 +642,19 @@ wasm_init_memory(WASMModuleInstance *inst, uint32 mem_idx, uint32 seg_idx, /* if s + n > the length of data.data */ bh_assert(seg_idx < inst->module->data_seg_count); - data_segment = inst->module->data_segments[seg_idx]; - if (data_segment->data_length < data_offset - || data_segment->data_length - data_offset < len) + if (bh_bitmap_get_bit(inst->e->common.data_dropped, seg_idx)) { + seg_len = 0; + data_addr = NULL; + } + else { + data_segment = inst->module->data_segments[seg_idx]; + seg_len = data_segment->data_length; + data_addr = data_segment->data + data_offset; + } + if (seg_len < data_offset || seg_len - data_offset < len) goto out_of_bounds; mem_addr = mem_inst->memory_data + mem_offset; - data_addr = data_segment->data + data_offset; bh_memcpy_s(mem_addr, mem_size - mem_offset, data_addr, len); return 0; @@ -706,21 +695,22 @@ jit_compile_op_memory_init(JitCompContext *cc, uint32 mem_idx, uint32 seg_idx) return false; } +static void +wasm_data_drop(WASMModuleInstance *inst, uint32 seg_idx) +{ + bh_bitmap_set_bit(inst->e->common.data_dropped, seg_idx); +} + bool jit_compile_op_data_drop(JitCompContext *cc, uint32 seg_idx) { - JitReg module = get_module_reg(cc->jit_frame); - JitReg data_segments = jit_cc_new_reg_ptr(cc); - JitReg data_segment = jit_cc_new_reg_ptr(cc); + JitReg args[2] = { 0 }; - GEN_INSN(LDPTR, data_segments, module, - NEW_CONST(I32, offsetof(WASMModule, data_segments))); - GEN_INSN(LDPTR, data_segment, data_segments, - NEW_CONST(I32, seg_idx * sizeof(WASMDataSeg *))); - GEN_INSN(STI32, NEW_CONST(I32, 0), data_segment, - NEW_CONST(I32, offsetof(WASMDataSeg, data_length))); + args[0] = get_module_inst_reg(cc->jit_frame); + args[1] = NEW_CONST(I32, seg_idx); - return true; + return jit_emit_callnative(cc, wasm_data_drop, 0, args, + sizeof(args) / sizeof(args[0])); } static int diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_memory.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_memory.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_memory.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_memory.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_numberic.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_numberic.c similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_numberic.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_numberic.c index 03491e691b8..6a1e93edeee 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_numberic.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_numberic.c @@ -298,7 +298,15 @@ jit_compile_op_i64_popcnt(JitCompContext *cc) /* macros for integer binary operations (ibinop) */ +#if defined(__GNUC__) +#define NO_SANITIZER_INTEGER \ + __attribute__((no_sanitize("signed-integer-overflow"))) +#else +#define NO_SANITIZER_INTEGER +#endif + #define __DEF_BI_INT_CONST_OPS(bits, opname, op) \ + NO_SANITIZER_INTEGER \ static int##bits do_i##bits##_const_##opname(int##bits lhs, int##bits rhs) \ { \ return lhs op rhs; \ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_numberic.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_numberic.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_numberic.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_numberic.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_parametric.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_parametric.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_parametric.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_parametric.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_parametric.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_parametric.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_parametric.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_parametric.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_table.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_table.c similarity index 86% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_table.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_table.c index 9fb61931f2d..b8ed6a1d502 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_table.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_table.c @@ -10,21 +10,22 @@ #include "../jit_frontend.h" #if WASM_ENABLE_REF_TYPES != 0 +static void +wasm_elem_drop(WASMModuleInstance *inst, uint32 tbl_seg_idx) +{ + bh_bitmap_set_bit(inst->e->common.elem_dropped, tbl_seg_idx); +} + bool jit_compile_op_elem_drop(JitCompContext *cc, uint32 tbl_seg_idx) { - JitReg module, tbl_segs; + JitReg args[2] = { 0 }; - module = get_module_reg(cc->jit_frame); - - tbl_segs = jit_cc_new_reg_ptr(cc); - GEN_INSN(LDPTR, tbl_segs, module, - NEW_CONST(I32, offsetof(WASMModule, table_segments))); + args[0] = get_module_inst_reg(cc->jit_frame); + args[1] = NEW_CONST(I32, tbl_seg_idx); - GEN_INSN(STI32, NEW_CONST(I32, true), tbl_segs, - NEW_CONST(I32, tbl_seg_idx * sizeof(WASMTableSeg) - + offsetof(WASMTableSeg, is_dropped))); - return true; + return jit_emit_callnative(cc, wasm_elem_drop, 0, args, + sizeof(args) / sizeof(args[0])); } bool @@ -88,27 +89,34 @@ jit_compile_op_table_set(JitCompContext *cc, uint32 tbl_idx) static int wasm_init_table(WASMModuleInstance *inst, uint32 tbl_idx, uint32 elem_idx, - uint32 dst, uint32 len, uint32 src) + uint32 dst_offset, uint32 len, uint32 src_offset) { WASMTableInstance *tbl; uint32 tbl_sz; WASMTableSeg *elem; uint32 elem_len; + elem = inst->module->table_segments + elem_idx; + elem_len = elem->function_count; + if (offset_len_out_of_bounds(src_offset, len, elem_len)) + goto out_of_bounds; + tbl = inst->tables[tbl_idx]; tbl_sz = tbl->cur_size; - if (dst > tbl_sz || tbl_sz - dst < len) + if (offset_len_out_of_bounds(dst_offset, len, tbl_sz)) goto out_of_bounds; - elem = inst->module->table_segments + elem_idx; - elem_len = elem->function_count; - if (src > elem_len || elem_len - src < len) + if (!len) + return 0; + + if (bh_bitmap_get_bit(inst->e->common.elem_dropped, elem_idx)) goto out_of_bounds; bh_memcpy_s((uint8 *)tbl + offsetof(WASMTableInstance, elems) - + dst * sizeof(uint32), - (uint32)((tbl_sz - dst) * sizeof(uint32)), - elem->func_indexes + src, (uint32)(len * sizeof(uint32))); + + dst_offset * sizeof(uint32), + (uint32)((tbl_sz - dst_offset) * sizeof(uint32)), + elem->func_indexes + src_offset, + (uint32)(len * sizeof(uint32))); return 0; out_of_bounds: @@ -157,14 +165,14 @@ wasm_copy_table(WASMModuleInstance *inst, uint32 src_tbl_idx, WASMTableInstance *src_tbl, *dst_tbl; uint32 src_tbl_sz, dst_tbl_sz; - src_tbl = inst->tables[src_tbl_idx]; - src_tbl_sz = src_tbl->cur_size; - if (src_offset > src_tbl_sz || src_tbl_sz - src_offset < len) - goto out_of_bounds; - dst_tbl = inst->tables[dst_tbl_idx]; dst_tbl_sz = dst_tbl->cur_size; - if (dst_offset > dst_tbl_sz || dst_tbl_sz - dst_offset < len) + if (offset_len_out_of_bounds(dst_offset, len, dst_tbl_sz)) + goto out_of_bounds; + + src_tbl = inst->tables[src_tbl_idx]; + src_tbl_sz = src_tbl->cur_size; + if (offset_len_out_of_bounds(src_offset, len, src_tbl_sz)) goto out_of_bounds; bh_memmove_s((uint8 *)dst_tbl + offsetof(WASMTableInstance, elems) @@ -263,7 +271,7 @@ jit_compile_op_table_grow(JitCompContext *cc, uint32 tbl_idx) } static int -wasm_fill_table(WASMModuleInstance *inst, uint32 tbl_idx, uint32 dst, +wasm_fill_table(WASMModuleInstance *inst, uint32 tbl_idx, uint32 dst_offset, uint32 val, uint32 len) { WASMTableInstance *tbl; @@ -272,11 +280,11 @@ wasm_fill_table(WASMModuleInstance *inst, uint32 tbl_idx, uint32 dst, tbl = inst->tables[tbl_idx]; tbl_sz = tbl->cur_size; - if (dst > tbl_sz || tbl_sz - dst < len) + if (offset_len_out_of_bounds(dst_offset, len, tbl_sz)) goto out_of_bounds; - for (; len != 0; dst++, len--) { - tbl->elems[dst] = val; + for (; len != 0; dst_offset++, len--) { + tbl->elems[dst_offset] = val; } return 0; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_table.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_table.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_table.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_table.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_variable.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_variable.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_variable.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_variable.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_variable.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_variable.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/fe/jit_emit_variable.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/fe/jit_emit_variable.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/iwasm_fast_jit.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/iwasm_fast_jit.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/iwasm_fast_jit.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/iwasm_fast_jit.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_codecache.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_codecache.c similarity index 93% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_codecache.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_codecache.c index 73a034f3497..ef207474780 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_codecache.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_codecache.c @@ -17,8 +17,8 @@ jit_code_cache_init(uint32 code_cache_size) int map_prot = MMAP_PROT_READ | MMAP_PROT_WRITE | MMAP_PROT_EXEC; int map_flags = MMAP_MAP_NONE; - if (!(code_cache_pool = - os_mmap(NULL, code_cache_size, map_prot, map_flags))) { + if (!(code_cache_pool = os_mmap(NULL, code_cache_size, map_prot, map_flags, + os_get_invalid_handle()))) { return false; } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_codecache.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_codecache.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_codecache.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_codecache.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_codegen.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_codegen.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_codegen.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_codegen.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_codegen.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_codegen.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_codegen.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_codegen.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_compiler.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_compiler.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_compiler.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_compiler.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_compiler.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_compiler.h similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_compiler.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_compiler.h index 9a49cffdd1a..dee2631d14a 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_compiler.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_compiler.h @@ -70,6 +70,7 @@ typedef struct JitInterpSwitchInfo { typedef struct JitCompOptions { uint32 code_cache_size; uint32 opt_level; + bool linux_perf_support; } JitCompOptions; bool diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_dump.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_dump.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_dump.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_dump.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_dump.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_dump.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_dump.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_dump.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_frontend.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_frontend.c similarity index 86% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_frontend.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_frontend.c index ec68ad91d8e..c9c22e0adf3 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_frontend.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_frontend.c @@ -218,42 +218,149 @@ get_aux_stack_bottom_reg(JitFrame *frame) return frame->aux_stack_bottom_reg; } +#if WASM_ENABLE_SHARED_MEMORY != 0 +static bool +is_shared_memory(WASMModule *module, uint32 mem_idx) +{ + WASMMemory *memory; + WASMMemoryImport *memory_import; + bool is_shared; + + if (mem_idx < module->import_memory_count) { + memory_import = &(module->import_memories[mem_idx].u.memory); + is_shared = memory_import->flags & 0x02 ? true : false; + } + else { + memory = &module->memories[mem_idx - module->import_memory_count]; + is_shared = memory->flags & 0x02 ? true : false; + } + return is_shared; +} +#endif + JitReg -get_memory_data_reg(JitFrame *frame, uint32 mem_idx) +get_memory_inst_reg(JitFrame *frame, uint32 mem_idx) { JitCompContext *cc = frame->cc; JitReg module_inst_reg = get_module_inst_reg(frame); - uint32 memory_data_offset; + uint32 memory_inst_offset; +#if WASM_ENABLE_SHARED_MEMORY != 0 + JitReg memories_addr; + uint32 memories_offset; + bool is_shared; +#endif + + if (frame->memory_regs[mem_idx].memory_inst) + return frame->memory_regs[mem_idx].memory_inst; + + frame->memory_regs[mem_idx].memory_inst = + cc->memory_regs[mem_idx].memory_inst; bh_assert(mem_idx == 0); #if WASM_ENABLE_SHARED_MEMORY != 0 - uint32 memories_offset = (uint32)offsetof(WASMModuleInstance, memories); - JitReg memories_addr = jit_cc_new_reg_ptr(cc); - JitReg memories_0_addr = jit_cc_new_reg_ptr(cc); - memory_data_offset = (uint32)offsetof(WASMMemoryInstance, memory_data); - if (!frame->memory_regs[mem_idx].memory_data) { - frame->memory_regs[mem_idx].memory_data = - cc->memory_regs[mem_idx].memory_data; + is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx); + if (is_shared) { + memories_addr = jit_cc_new_reg_ptr(cc); + memories_offset = (uint32)offsetof(WASMModuleInstance, memories); /* module_inst->memories */ GEN_INSN(LDPTR, memories_addr, module_inst_reg, NEW_CONST(I32, memories_offset)); - /* module_inst->memories[0] */ - GEN_INSN(LDPTR, memories_0_addr, memories_addr, NEW_CONST(I32, 0)); - /* memories[0]->memory_data */ + /* module_inst->memories[mem_idx], mem_idx can only be 0 now */ + GEN_INSN(LDPTR, frame->memory_regs[mem_idx].memory_inst, memories_addr, + NEW_CONST(I32, mem_idx)); + } + else +#endif + { + memory_inst_offset = + (uint32)offsetof(WASMModuleInstance, global_table_data.bytes); + GEN_INSN(LDPTR, frame->memory_regs[mem_idx].memory_inst, + module_inst_reg, NEW_CONST(I32, memory_inst_offset)); + } + + return frame->memory_regs[mem_idx].memory_inst; +} + +JitReg +get_cur_page_count_reg(JitFrame *frame, uint32 mem_idx) +{ + JitCompContext *cc = frame->cc; + JitReg module_inst_reg; + uint32 cur_page_count_offset; +#if WASM_ENABLE_SHARED_MEMORY != 0 + JitReg memory_inst_reg; + bool is_shared; +#endif + + if (frame->memory_regs[mem_idx].cur_page_count) + return frame->memory_regs[mem_idx].cur_page_count; + + frame->memory_regs[mem_idx].cur_page_count = + cc->memory_regs[mem_idx].cur_page_count; + + /* Get current page count */ + bh_assert(mem_idx == 0); +#if WASM_ENABLE_SHARED_MEMORY != 0 + is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx); + if (is_shared) { + memory_inst_reg = get_memory_inst_reg(frame, mem_idx); + cur_page_count_offset = + (uint32)offsetof(WASMMemoryInstance, cur_page_count); + /* memories[mem_idx]->cur_page_count_offset */ + GEN_INSN(LDI32, frame->memory_regs[mem_idx].cur_page_count, + memory_inst_reg, NEW_CONST(I32, cur_page_count_offset)); + } + else +#endif + { + module_inst_reg = get_module_inst_reg(frame); + cur_page_count_offset = + (uint32)offsetof(WASMModuleInstance, global_table_data.bytes) + + (uint32)offsetof(WASMMemoryInstance, cur_page_count); + GEN_INSN(LDI32, frame->memory_regs[mem_idx].cur_page_count, + module_inst_reg, NEW_CONST(I32, cur_page_count_offset)); + } + + return frame->memory_regs[mem_idx].cur_page_count; +} + +JitReg +get_memory_data_reg(JitFrame *frame, uint32 mem_idx) +{ + JitCompContext *cc = frame->cc; + JitReg module_inst_reg; + uint32 memory_data_offset; +#if WASM_ENABLE_SHARED_MEMORY != 0 + JitReg memory_inst_reg; + bool is_shared; +#endif + + if (frame->memory_regs[mem_idx].memory_data) + return frame->memory_regs[mem_idx].memory_data; + + frame->memory_regs[mem_idx].memory_data = + cc->memory_regs[mem_idx].memory_data; + + bh_assert(mem_idx == 0); +#if WASM_ENABLE_SHARED_MEMORY != 0 + is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx); + if (is_shared) { + memory_inst_reg = get_memory_inst_reg(frame, mem_idx); + memory_data_offset = (uint32)offsetof(WASMMemoryInstance, memory_data); + /* memories[mem_idx]->memory_data */ GEN_INSN(LDPTR, frame->memory_regs[mem_idx].memory_data, - memories_0_addr, NEW_CONST(I32, memory_data_offset)); + memory_inst_reg, NEW_CONST(I32, memory_data_offset)); } -#else - memory_data_offset = - (uint32)offsetof(WASMModuleInstance, global_table_data.bytes) - + (uint32)offsetof(WASMMemoryInstance, memory_data); - if (!frame->memory_regs[mem_idx].memory_data) { - frame->memory_regs[mem_idx].memory_data = - cc->memory_regs[mem_idx].memory_data; + else +#endif + { + module_inst_reg = get_module_inst_reg(frame); + memory_data_offset = + (uint32)offsetof(WASMModuleInstance, global_table_data.bytes) + + (uint32)offsetof(WASMMemoryInstance, memory_data); GEN_INSN(LDPTR, frame->memory_regs[mem_idx].memory_data, module_inst_reg, NEW_CONST(I32, memory_data_offset)); } -#endif return frame->memory_regs[mem_idx].memory_data; } @@ -261,16 +368,37 @@ JitReg get_memory_data_end_reg(JitFrame *frame, uint32 mem_idx) { JitCompContext *cc = frame->cc; - JitReg module_inst_reg = get_module_inst_reg(frame); - uint32 memory_data_end_offset = - (uint32)offsetof(WASMModuleInstance, global_table_data.bytes) - + (uint32)offsetof(WASMMemoryInstance, memory_data_end); + JitReg module_inst_reg; + uint32 memory_data_end_offset; +#if WASM_ENABLE_SHARED_MEMORY != 0 + JitReg memory_inst_reg; + bool is_shared; +#endif - bh_assert(mem_idx == 0); + if (frame->memory_regs[mem_idx].memory_data_end) + return frame->memory_regs[mem_idx].memory_data_end; + + frame->memory_regs[mem_idx].memory_data_end = + cc->memory_regs[mem_idx].memory_data_end; - if (!frame->memory_regs[mem_idx].memory_data_end) { - frame->memory_regs[mem_idx].memory_data_end = - cc->memory_regs[mem_idx].memory_data_end; + bh_assert(mem_idx == 0); +#if WASM_ENABLE_SHARED_MEMORY != 0 + is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx); + if (is_shared) { + memory_inst_reg = get_memory_inst_reg(frame, mem_idx); + memory_data_end_offset = + (uint32)offsetof(WASMMemoryInstance, memory_data_end); + /* memories[mem_idx]->memory_data_end */ + GEN_INSN(LDPTR, frame->memory_regs[mem_idx].memory_data_end, + memory_inst_reg, NEW_CONST(I32, memory_data_end_offset)); + } + else +#endif + { + module_inst_reg = get_module_inst_reg(frame); + memory_data_end_offset = + (uint32)offsetof(WASMModuleInstance, global_table_data.bytes) + + (uint32)offsetof(WASMMemoryInstance, memory_data_end); GEN_INSN(LDPTR, frame->memory_regs[mem_idx].memory_data_end, module_inst_reg, NEW_CONST(I32, memory_data_end_offset)); } @@ -281,16 +409,43 @@ JitReg get_mem_bound_check_1byte_reg(JitFrame *frame, uint32 mem_idx) { JitCompContext *cc = frame->cc; - JitReg module_inst_reg = get_module_inst_reg(frame); - uint32 mem_bound_check_1byte_offset = - (uint32)offsetof(WASMModuleInstance, global_table_data.bytes) - + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_1byte); + JitReg module_inst_reg; + uint32 mem_bound_check_1byte_offset; +#if WASM_ENABLE_SHARED_MEMORY != 0 + JitReg memory_inst_reg; + bool is_shared; +#endif + + if (frame->memory_regs[mem_idx].mem_bound_check_1byte) + return frame->memory_regs[mem_idx].mem_bound_check_1byte; + + frame->memory_regs[mem_idx].mem_bound_check_1byte = + cc->memory_regs[mem_idx].mem_bound_check_1byte; bh_assert(mem_idx == 0); - if (!frame->memory_regs[mem_idx].mem_bound_check_1byte) { - frame->memory_regs[mem_idx].mem_bound_check_1byte = - cc->memory_regs[mem_idx].mem_bound_check_1byte; +#if WASM_ENABLE_SHARED_MEMORY != 0 + is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx); + if (is_shared) { + memory_inst_reg = get_memory_inst_reg(frame, mem_idx); + mem_bound_check_1byte_offset = + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_1byte); + /* memories[mem_idx]->mem_bound_check_1byte */ +#if UINTPTR_MAX == UINT64_MAX + GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_1byte, + memory_inst_reg, NEW_CONST(I32, mem_bound_check_1byte_offset)); +#else + GEN_INSN(LDI32, frame->memory_regs[mem_idx].mem_bound_check_1byte, + memory_inst_reg, NEW_CONST(I32, mem_bound_check_1byte_offset)); +#endif + } + else +#endif + { + module_inst_reg = get_module_inst_reg(frame); + mem_bound_check_1byte_offset = + (uint32)offsetof(WASMModuleInstance, global_table_data.bytes) + + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_1byte); #if UINTPTR_MAX == UINT64_MAX GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_1byte, module_inst_reg, NEW_CONST(I32, mem_bound_check_1byte_offset)); @@ -306,16 +461,45 @@ JitReg get_mem_bound_check_2bytes_reg(JitFrame *frame, uint32 mem_idx) { JitCompContext *cc = frame->cc; - JitReg module_inst_reg = get_module_inst_reg(frame); - uint32 mem_bound_check_2bytes_offset = - (uint32)offsetof(WASMModuleInstance, global_table_data.bytes) - + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_2bytes); + JitReg module_inst_reg; + uint32 mem_bound_check_2bytes_offset; +#if WASM_ENABLE_SHARED_MEMORY != 0 + JitReg memory_inst_reg; + bool is_shared; +#endif + + if (frame->memory_regs[mem_idx].mem_bound_check_2bytes) + return frame->memory_regs[mem_idx].mem_bound_check_2bytes; + + frame->memory_regs[mem_idx].mem_bound_check_2bytes = + cc->memory_regs[mem_idx].mem_bound_check_2bytes; bh_assert(mem_idx == 0); - if (!frame->memory_regs[mem_idx].mem_bound_check_2bytes) { - frame->memory_regs[mem_idx].mem_bound_check_2bytes = - cc->memory_regs[mem_idx].mem_bound_check_2bytes; +#if WASM_ENABLE_SHARED_MEMORY != 0 + is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx); + if (is_shared) { + memory_inst_reg = get_memory_inst_reg(frame, mem_idx); + mem_bound_check_2bytes_offset = + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_2bytes); + /* memories[mem_idx]->mem_bound_check_2bytes */ +#if UINTPTR_MAX == UINT64_MAX + GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_2bytes, + memory_inst_reg, + NEW_CONST(I32, mem_bound_check_2bytes_offset)); +#else + GEN_INSN(LDI32, frame->memory_regs[mem_idx].mem_bound_check_2bytes, + memory_inst_reg, + NEW_CONST(I32, mem_bound_check_2bytes_offset)); +#endif + } + else +#endif + { + module_inst_reg = get_module_inst_reg(frame); + mem_bound_check_2bytes_offset = + (uint32)offsetof(WASMModuleInstance, global_table_data.bytes) + + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_2bytes); #if UINTPTR_MAX == UINT64_MAX GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_2bytes, module_inst_reg, @@ -333,16 +517,45 @@ JitReg get_mem_bound_check_4bytes_reg(JitFrame *frame, uint32 mem_idx) { JitCompContext *cc = frame->cc; - JitReg module_inst_reg = get_module_inst_reg(frame); - uint32 mem_bound_check_4bytes_offset = - (uint32)offsetof(WASMModuleInstance, global_table_data.bytes) - + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_4bytes); + JitReg module_inst_reg; + uint32 mem_bound_check_4bytes_offset; +#if WASM_ENABLE_SHARED_MEMORY != 0 + JitReg memory_inst_reg; + bool is_shared; +#endif + + if (frame->memory_regs[mem_idx].mem_bound_check_4bytes) + return frame->memory_regs[mem_idx].mem_bound_check_4bytes; + + frame->memory_regs[mem_idx].mem_bound_check_4bytes = + cc->memory_regs[mem_idx].mem_bound_check_4bytes; bh_assert(mem_idx == 0); - if (!frame->memory_regs[mem_idx].mem_bound_check_4bytes) { - frame->memory_regs[mem_idx].mem_bound_check_4bytes = - cc->memory_regs[mem_idx].mem_bound_check_4bytes; +#if WASM_ENABLE_SHARED_MEMORY != 0 + is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx); + if (is_shared) { + memory_inst_reg = get_memory_inst_reg(frame, mem_idx); + mem_bound_check_4bytes_offset = + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_4bytes); + /* memories[mem_idx]->mem_bound_check_4bytes */ +#if UINTPTR_MAX == UINT64_MAX + GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_4bytes, + memory_inst_reg, + NEW_CONST(I32, mem_bound_check_4bytes_offset)); +#else + GEN_INSN(LDI32, frame->memory_regs[mem_idx].mem_bound_check_4bytes, + memory_inst_reg, + NEW_CONST(I32, mem_bound_check_4bytes_offset)); +#endif + } + else +#endif + { + module_inst_reg = get_module_inst_reg(frame); + mem_bound_check_4bytes_offset = + (uint32)offsetof(WASMModuleInstance, global_table_data.bytes) + + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_4bytes); #if UINTPTR_MAX == UINT64_MAX GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_4bytes, module_inst_reg, @@ -360,16 +573,45 @@ JitReg get_mem_bound_check_8bytes_reg(JitFrame *frame, uint32 mem_idx) { JitCompContext *cc = frame->cc; - JitReg module_inst_reg = get_module_inst_reg(frame); - uint32 mem_bound_check_8bytes_offset = - (uint32)offsetof(WASMModuleInstance, global_table_data.bytes) - + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_8bytes); + JitReg module_inst_reg; + uint32 mem_bound_check_8bytes_offset; +#if WASM_ENABLE_SHARED_MEMORY != 0 + JitReg memory_inst_reg; + bool is_shared; +#endif + + if (frame->memory_regs[mem_idx].mem_bound_check_8bytes) + return frame->memory_regs[mem_idx].mem_bound_check_8bytes; + + frame->memory_regs[mem_idx].mem_bound_check_8bytes = + cc->memory_regs[mem_idx].mem_bound_check_8bytes; bh_assert(mem_idx == 0); - if (!frame->memory_regs[mem_idx].mem_bound_check_8bytes) { - frame->memory_regs[mem_idx].mem_bound_check_8bytes = - cc->memory_regs[mem_idx].mem_bound_check_8bytes; +#if WASM_ENABLE_SHARED_MEMORY != 0 + is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx); + if (is_shared) { + memory_inst_reg = get_memory_inst_reg(frame, mem_idx); + mem_bound_check_8bytes_offset = + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_8bytes); + /* memories[mem_idx]->mem_bound_check_8bytes */ +#if UINTPTR_MAX == UINT64_MAX + GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_8bytes, + memory_inst_reg, + NEW_CONST(I32, mem_bound_check_8bytes_offset)); +#else + GEN_INSN(LDI32, frame->memory_regs[mem_idx].mem_bound_check_8bytes, + memory_inst_reg, + NEW_CONST(I32, mem_bound_check_8bytes_offset)); +#endif + } + else +#endif + { + module_inst_reg = get_module_inst_reg(frame); + mem_bound_check_8bytes_offset = + (uint32)offsetof(WASMModuleInstance, global_table_data.bytes) + + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_8bytes); #if UINTPTR_MAX == UINT64_MAX GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_8bytes, module_inst_reg, @@ -387,16 +629,45 @@ JitReg get_mem_bound_check_16bytes_reg(JitFrame *frame, uint32 mem_idx) { JitCompContext *cc = frame->cc; - JitReg module_inst_reg = get_module_inst_reg(frame); - uint32 mem_bound_check_16bytes_offset = - (uint32)offsetof(WASMModuleInstance, global_table_data.bytes) - + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_16bytes); + JitReg module_inst_reg; + uint32 mem_bound_check_16bytes_offset; +#if WASM_ENABLE_SHARED_MEMORY != 0 + JitReg memory_inst_reg; + bool is_shared; +#endif + + if (frame->memory_regs[mem_idx].mem_bound_check_16bytes) + return frame->memory_regs[mem_idx].mem_bound_check_16bytes; + + frame->memory_regs[mem_idx].mem_bound_check_16bytes = + cc->memory_regs[mem_idx].mem_bound_check_16bytes; bh_assert(mem_idx == 0); - if (!frame->memory_regs[mem_idx].mem_bound_check_16bytes) { - frame->memory_regs[mem_idx].mem_bound_check_16bytes = - cc->memory_regs[mem_idx].mem_bound_check_16bytes; +#if WASM_ENABLE_SHARED_MEMORY != 0 + is_shared = is_shared_memory(cc->cur_wasm_module, mem_idx); + if (is_shared) { + memory_inst_reg = get_memory_inst_reg(frame, mem_idx); + mem_bound_check_16bytes_offset = + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_16bytes); + /* memories[mem_idx]->mem_bound_check_16bytes */ +#if UINTPTR_MAX == UINT64_MAX + GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_16bytes, + memory_inst_reg, + NEW_CONST(I32, mem_bound_check_16bytes_offset)); +#else + GEN_INSN(LDI32, frame->memory_regs[mem_idx].mem_bound_check_16bytes, + memory_inst_reg, + NEW_CONST(I32, mem_bound_check_16bytes_offset)); +#endif + } + else +#endif + { + module_inst_reg = get_module_inst_reg(frame); + mem_bound_check_16bytes_offset = + (uint32)offsetof(WASMModuleInstance, global_table_data.bytes) + + (uint32)offsetof(WASMMemoryInstance, mem_bound_check_16bytes); #if UINTPTR_MAX == UINT64_MAX GEN_INSN(LDI64, frame->memory_regs[mem_idx].mem_bound_check_16bytes, module_inst_reg, @@ -462,6 +733,8 @@ clear_fixed_virtual_regs(JitFrame *frame) count = module->import_memory_count + module->memory_count; for (i = 0; i < count; i++) { + frame->memory_regs[i].memory_inst = 0; + frame->memory_regs[i].cur_page_count = 0; frame->memory_regs[i].memory_data = 0; frame->memory_regs[i].memory_data_end = 0; frame->memory_regs[i].mem_bound_check_1byte = 0; @@ -486,6 +759,7 @@ clear_memory_regs(JitFrame *frame) count = module->import_memory_count + module->memory_count; for (i = 0; i < count; i++) { + frame->memory_regs[i].cur_page_count = 0; frame->memory_regs[i].memory_data = 0; frame->memory_regs[i].memory_data_end = 0; frame->memory_regs[i].mem_bound_check_1byte = 0; @@ -654,6 +928,8 @@ create_fixed_virtual_regs(JitCompContext *cc) } for (i = 0; i < count; i++) { + cc->memory_regs[i].memory_inst = jit_cc_new_reg_ptr(cc); + cc->memory_regs[i].cur_page_count = jit_cc_new_reg_I32(cc); cc->memory_regs[i].memory_data = jit_cc_new_reg_ptr(cc); cc->memory_regs[i].memory_data_end = jit_cc_new_reg_ptr(cc); cc->memory_regs[i].mem_bound_check_1byte = jit_cc_new_reg_ptr(cc); @@ -2311,77 +2587,3 @@ jit_frontend_get_jitted_return_addr_offset() { return (uint32)offsetof(WASMInterpFrame, jitted_return_addr); } - -#if 0 -#if WASM_ENABLE_THREAD_MGR != 0 -bool -check_suspend_flags(JitCompContext *cc, JITFuncContext *func_ctx) -{ - LLVMValueRef terminate_addr, terminate_flags, flag, offset, res; - JitBasicBlock *terminate_check_block, non_terminate_block; - JITFuncType *jit_func_type = func_ctx->jit_func->func_type; - JitBasicBlock *terminate_block; - - /* Offset of suspend_flags */ - offset = I32_FIVE; - - if (!(terminate_addr = LLVMBuildInBoundsGEP( - cc->builder, func_ctx->exec_env, &offset, 1, "terminate_addr"))) { - jit_set_last_error("llvm build in bounds gep failed"); - return false; - } - if (!(terminate_addr = - LLVMBuildBitCast(cc->builder, terminate_addr, INT32_PTR_TYPE, - "terminate_addr_ptr"))) { - jit_set_last_error("llvm build bit cast failed"); - return false; - } - - if (!(terminate_flags = - LLVMBuildLoad(cc->builder, terminate_addr, "terminate_flags"))) { - jit_set_last_error("llvm build bit cast failed"); - return false; - } - /* Set terminate_flags memory accecc to volatile, so that the value - will always be loaded from memory rather than register */ - LLVMSetVolatile(terminate_flags, true); - - CREATE_BASIC_BLOCK(terminate_check_block, "terminate_check"); - MOVE_BASIC_BLOCK_AFTER_CURR(terminate_check_block); - - CREATE_BASIC_BLOCK(non_terminate_block, "non_terminate"); - MOVE_BASIC_BLOCK_AFTER_CURR(non_terminate_block); - - BUILD_ICMP(LLVMIntSGT, terminate_flags, I32_ZERO, res, "need_terminate"); - BUILD_COND_BR(res, terminate_check_block, non_terminate_block); - - /* Move builder to terminate check block */ - SET_BUILDER_POS(terminate_check_block); - - CREATE_BASIC_BLOCK(terminate_block, "terminate"); - MOVE_BASIC_BLOCK_AFTER_CURR(terminate_block); - - if (!(flag = LLVMBuildAnd(cc->builder, terminate_flags, I32_ONE, - "termination_flag"))) { - jit_set_last_error("llvm build AND failed"); - return false; - } - - BUILD_ICMP(LLVMIntSGT, flag, I32_ZERO, res, "need_terminate"); - BUILD_COND_BR(res, terminate_block, non_terminate_block); - - /* Move builder to terminate block */ - SET_BUILDER_POS(terminate_block); - if (!jit_build_zero_function_ret(cc, func_ctx, jit_func_type)) { - goto fail; - } - - /* Move builder to terminate block */ - SET_BUILDER_POS(non_terminate_block); - return true; - -fail: - return false; -} -#endif /* End of WASM_ENABLE_THREAD_MGR */ -#endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_frontend.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_frontend.h similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_frontend.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_frontend.h index 7aa460fd9b3..9065d23ec89 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_frontend.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_frontend.h @@ -192,6 +192,12 @@ get_aux_stack_bound_reg(JitFrame *frame); JitReg get_aux_stack_bottom_reg(JitFrame *frame); +JitReg +get_memory_inst_reg(JitFrame *frame, uint32 mem_idx); + +JitReg +get_cur_page_count_reg(JitFrame *frame, uint32 mem_idx); + JitReg get_memory_data_reg(JitFrame *frame, uint32 mem_idx); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_ir.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_ir.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_ir.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_ir.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_ir.def b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_ir.def similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_ir.def rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_ir.def diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_ir.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_ir.h similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_ir.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_ir.h index e13a41d1d21..bef3fcc0c4b 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_ir.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_ir.h @@ -866,6 +866,8 @@ typedef struct JitValueSlot { typedef struct JitMemRegs { /* The following registers should be re-loaded after memory.grow, callbc and callnative */ + JitReg memory_inst; + JitReg cur_page_count; JitReg memory_data; JitReg memory_data_end; JitReg mem_bound_check_1byte; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_regalloc.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_regalloc.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_regalloc.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_regalloc.c diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_utils.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_utils.h new file mode 100644 index 00000000000..a533c70bc6f --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/fast-jit/jit_utils.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2021 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#ifndef _JIT_UTILS_H_ +#define _JIT_UTILS_H_ + +#include "bh_platform.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static inline void * +jit_malloc(unsigned int size) +{ + return wasm_runtime_malloc(size); +} + +static inline void * +jit_calloc(unsigned int size) +{ + void *ret = wasm_runtime_malloc(size); + if (ret) { + memset(ret, 0, size); + } + return ret; +} + +static inline void +jit_free(void *ptr) +{ + if (ptr) + wasm_runtime_free(ptr); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/aot_export.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/aot_export.h similarity index 88% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/aot_export.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/aot_export.h index e58873bfd8b..f2184033a54 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/aot_export.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/aot_export.h @@ -26,8 +26,8 @@ void aot_destroy_comp_data(aot_comp_data_t comp_data); #if WASM_ENABLE_DEBUG_AOT != 0 -typedef void *dwar_extractor_handle_t; -dwar_extractor_handle_t +typedef void *dwarf_extractor_handle_t; +dwarf_extractor_handle_t create_dwarf_extractor(aot_comp_data_t comp_data, char *file_name); #endif @@ -38,6 +38,7 @@ enum { AOT_LLVMIR_OPT_FILE, }; +/* always sync it with AOTCompOption in compilation/aot_llvm.h */ typedef struct AOTCompOption { bool is_jit_mode; bool is_indirect_mode; @@ -55,15 +56,21 @@ typedef struct AOTCompOption { bool enable_aux_stack_frame; bool disable_llvm_intrinsics; bool disable_llvm_lto; + bool enable_llvm_pgo; bool enable_stack_estimation; + char *use_prof_file; uint32_t opt_level; uint32_t size_level; uint32_t output_format; uint32_t bounds_checks; uint32_t stack_bounds_checks; + uint32_t segue_flags; + bool linux_perf_support; char **custom_sections; uint32_t custom_sections_count; const char *stack_usage_file; + const char *llvm_passes; + const char *builtin_intrinsics; } AOTCompOption, *aot_comp_option_t; bool diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/lib_export.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/lib_export.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/lib_export.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/lib_export.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/wasm_c_api.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/wasm_c_api.h similarity index 96% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/wasm_c_api.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/wasm_c_api.h index 324a43bd52d..eaad941e45f 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/wasm_c_api.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/wasm_c_api.h @@ -21,6 +21,15 @@ #endif #endif +#if defined(__GNUC__) || defined(__clang__) +#define DEPRECATED __attribute__((deprecated)) +#elif defined(_MSC_VER) +#define DEPRECATED __declspec(deprecated) +#else +#pragma message("WARNING: You need to implement DEPRECATED for this compiler") +#define DEPRECATED +#endif + #ifdef __cplusplus extern "C" { #endif @@ -136,31 +145,6 @@ static inline void wasm_name_new_from_string_nt( WASM_DECLARE_OWN(config) -WASM_API_EXTERN own wasm_config_t* wasm_config_new(void); - -// Embedders may provide custom functions for manipulating configs. - - -// Engine - -WASM_DECLARE_OWN(engine) - -/** - * Create a new engine - * - * Note: for the engine new/delete operations, including this, - * wasm_engine_new_with_config, wasm_engine_new_with_args, and - * wasm_engine_delete, if the platform has mutex initializer, - * then they are thread-safe: we use a global lock to lock the - * operations of the engine. Otherwise they are not thread-safe: - * when there are engine new/delete operations happening - * simultaneously in multiple threads, developer must create - * the lock by himself, and add the lock when calling these - * functions. - */ -WASM_API_EXTERN own wasm_engine_t* wasm_engine_new(void); -WASM_API_EXTERN own wasm_engine_t* wasm_engine_new_with_config(own wasm_config_t*); - #ifndef MEM_ALLOC_OPTION_DEFINED #define MEM_ALLOC_OPTION_DEFINED /* same definition from wasm_export.h */ @@ -191,9 +175,51 @@ typedef union MemAllocOption { void *user_data; } allocator; } MemAllocOption; -#endif +#endif /* MEM_ALLOC_OPTION_DEFINED */ + +/* Runtime configration */ +struct wasm_config_t { + mem_alloc_type_t mem_alloc_type; + MemAllocOption mem_alloc_option; + bool linux_perf_support; + /*TODO: wasi args*/ +}; + +/* + * by default: + * - mem_alloc_type is Alloc_With_System_Allocator + * - mem_alloc_option is all 0 + * - linux_perf_support is false + */ +WASM_API_EXTERN own wasm_config_t* wasm_config_new(void); + +// Embedders may provide custom functions for manipulating configs. +WASM_API_EXTERN own wasm_config_t* +wasm_config_set_mem_alloc_opt(wasm_config_t *, mem_alloc_type_t, MemAllocOption *); -WASM_API_EXTERN own wasm_engine_t * +WASM_API_EXTERN own wasm_config_t* +wasm_config_set_linux_perf_opt(wasm_config_t *, bool); + +// Engine + +WASM_DECLARE_OWN(engine) + +/** + * Create a new engine + * + * Note: for the engine new/delete operations, including this, + * wasm_engine_new_with_config, wasm_engine_new_with_args, and + * wasm_engine_delete, if the platform has mutex initializer, + * then they are thread-safe: we use a global lock to lock the + * operations of the engine. Otherwise they are not thread-safe: + * when there are engine new/delete operations happening + * simultaneously in multiple threads, developer must create + * the lock by himself, and add the lock when calling these + * functions. + */ +WASM_API_EXTERN own wasm_engine_t* wasm_engine_new(void); +WASM_API_EXTERN own wasm_engine_t* wasm_engine_new_with_config(wasm_config_t*); +DEPRECATED WASM_API_EXTERN own wasm_engine_t * wasm_engine_new_with_args(mem_alloc_type_t type, const MemAllocOption *opts); // Store diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/wasm_export.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/wasm_export.h similarity index 82% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/wasm_export.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/wasm_export.h index f6c0107b9ff..d8e761e83e5 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/include/wasm_export.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/include/wasm_export.h @@ -118,7 +118,7 @@ typedef union MemAllocOption { void *realloc_func; void *free_func; /* allocator user data, only used when - WASM_MEM_ALLOC_WITH_USER_DATA is defined */ + WASM_MEM_ALLOC_WITH_USER_DATA is defined */ void *user_data; } allocator; } MemAllocOption; @@ -149,7 +149,7 @@ typedef struct RuntimeInitArgs { uint32_t n_native_symbols; /* maximum thread number, only used when - WASM_ENABLE_THREAD_MGR is defined */ + WASM_ENABLE_THREAD_MGR is defined */ uint32_t max_thread_num; /* Debug settings, only used when @@ -167,6 +167,17 @@ typedef struct RuntimeInitArgs { /* LLVM JIT opt and size level */ uint32_t llvm_jit_opt_level; uint32_t llvm_jit_size_level; + /* Segue optimization flags for LLVM JIT */ + uint32_t segue_flags; + /** + * If enabled + * - llvm-jit will output a jitdump file for `perf inject` + * - aot. TBD + * - fast-jit. TBD + * - multi-tier-jit. TBD + * - interpreter. TBD + */ + bool linux_perf_support; } RuntimeInitArgs; #ifndef WASM_VALKIND_T_DEFINED @@ -184,6 +195,7 @@ enum wasm_valkind_enum { #ifndef WASM_VAL_T_DEFINED #define WASM_VAL_T_DEFINED +struct wasm_ref_t; typedef struct wasm_val_t { wasm_valkind_t kind; @@ -195,6 +207,7 @@ typedef struct wasm_val_t { double f64; /* represent a foreign object, aka externref in .wat */ uintptr_t foreign; + struct wasm_ref_t *ref; } of; } wasm_val_t; #endif @@ -307,7 +320,8 @@ wasm_runtime_is_xip_file(const uint8_t *buf, uint32_t size); /** * Callback to load a module file into a buffer in multi-module feature */ -typedef bool (*module_reader)(const char *module_name, +typedef bool (*module_reader)(package_type_t module_type, + const char *module_name, uint8_t **p_buffer, uint32_t *p_size); /** @@ -419,6 +433,7 @@ wasm_runtime_get_module_hash(wasm_module_t module); * @param dir_list The list of directories to preopen. (real path) * @param dir_count The number of elements in dir_list. * @param map_dir_list The list of directories to preopen. (mapped path) + * Format for each map entry: :: * @param map_dir_count The number of elements in map_dir_list. * If map_dir_count is smaller than dir_count, * mapped path is assumed to be same as the @@ -427,26 +442,31 @@ wasm_runtime_get_module_hash(wasm_module_t module); * @param env_count The number of elements in env. * @param argv The list of command line arguments. * @param argc The number of elements in argv. - * @param stdinfd The host file descriptor to back WASI STDIN_FILENO. - * If -1 is specified, STDIN_FILENO is used. - * @param stdoutfd The host file descriptor to back WASI STDOUT_FILENO. - * If -1 is specified, STDOUT_FILENO is used. - * @param stderrfd The host file descriptor to back WASI STDERR_FILENO. - * If -1 is specified, STDERR_FILENO is used. + * @param stdin_handle The raw host handle to back WASI STDIN_FILENO. + * If an invalid handle is specified (e.g. -1 on POSIX, + * INVALID_HANDLE_VALUE on Windows), the platform default + * for STDIN is used. + * @param stdoutfd The raw host handle to back WASI STDOUT_FILENO. + * If an invalid handle is specified (e.g. -1 on POSIX, + * INVALID_HANDLE_VALUE on Windows), the platform default + * for STDOUT is used. + * @param stderrfd The raw host handle to back WASI STDERR_FILENO. + * If an invalid handle is specified (e.g. -1 on POSIX, + * INVALID_HANDLE_VALUE on Windows), the platform default + * for STDERR is used. */ WASM_RUNTIME_API_EXTERN void wasm_runtime_set_wasi_args_ex(wasm_module_t module, const char *dir_list[], uint32_t dir_count, const char *map_dir_list[], uint32_t map_dir_count, const char *env[], uint32_t env_count, - char *argv[], int argc, - int stdinfd, int stdoutfd, int stderrfd); + char *argv[], int argc, int64_t stdinfd, + int64_t stdoutfd, int64_t stderrfd); /** * Set WASI parameters. * - * Same as wasm_runtime_set_wasi_args_ex with stdinfd = -1, stdoutfd = -1, - * stderrfd = -1. + * Same as wasm_runtime_set_wasi_args_ex but with default stdio handles */ WASM_RUNTIME_API_EXTERN void wasm_runtime_set_wasi_args(wasm_module_t module, @@ -861,6 +881,7 @@ wasm_application_execute_main(wasm_module_inst_t module_inst, WASM_RUNTIME_API_EXTERN bool wasm_application_execute_func(wasm_module_inst_t module_inst, const char *name, int32_t argc, char *argv[]); + /** * Get exception info of the WASM module instance. * @@ -890,6 +911,27 @@ wasm_runtime_set_exception(wasm_module_inst_t module_inst, WASM_RUNTIME_API_EXTERN void wasm_runtime_clear_exception(wasm_module_inst_t module_inst); +/** + * Terminate the WASM module instance. + * + * This function causes the module instance fail as if it raised a trap. + * + * This is intended to be used in situations like: + * + * - A thread is executing the WASM module instance + * (eg. it's in the middle of `wasm_application_execute_main`) + * + * - Another thread has a copy of `wasm_module_inst_t` of + * the module instance and wants to terminate it asynchronously. + * + * This function is provided only when WAMR is built with threading enabled. + * (`WASM_ENABLE_THREAD_MGR=1`) + * + * @param module_inst the WASM module instance + */ +WASM_RUNTIME_API_EXTERN void +wasm_runtime_terminate(wasm_module_inst_t module_inst); + /** * Set custom data to WASM module instance. * Note: @@ -902,6 +944,7 @@ wasm_runtime_clear_exception(wasm_module_inst_t module_inst); WASM_RUNTIME_API_EXTERN void wasm_runtime_set_custom_data(wasm_module_inst_t module_inst, void *custom_data); + /** * Get the custom data within a WASM module instance. * @@ -912,6 +955,26 @@ wasm_runtime_set_custom_data(wasm_module_inst_t module_inst, WASM_RUNTIME_API_EXTERN void * wasm_runtime_get_custom_data(wasm_module_inst_t module_inst); +/** + * Set the memory bounds checks flag of a WASM module instance. + * + * @param module_inst the WASM module instance + * @param enable the flag to enable/disable the memory bounds checks + */ +WASM_RUNTIME_API_EXTERN void +wasm_runtime_set_bounds_checks(wasm_module_inst_t module_inst, + bool enable); + +/** + * Check if the memory bounds checks flag is enabled for a WASM module instance. + * + * @param module_inst the WASM module instance + * @return true if the memory bounds checks flag is enabled, false otherwise + */ +WASM_RUNTIME_API_EXTERN bool +wasm_runtime_is_bounds_checks_enabled( + wasm_module_inst_t module_inst); + /** * Allocate memory from the heap of WASM module instance * @@ -1269,6 +1332,33 @@ WASM_RUNTIME_API_EXTERN bool wasm_externref_obj2ref(wasm_module_inst_t module_inst, void *extern_obj, uint32_t *p_externref_idx); +/** + * Delete external object registered by `wasm_externref_obj2ref`. + * + * @param module_inst the WASM module instance that the extern object + * belongs to + * @param extern_obj the external object to be deleted + * + * @return true if success, false otherwise + */ +WASM_RUNTIME_API_EXTERN bool +wasm_externref_objdel(wasm_module_inst_t module_inst, void *extern_obj); + +/** + * Set cleanup callback to release external object. + * + * @param module_inst the WASM module instance that the extern object + * belongs to + * @param extern_obj the external object to which to set the + * `extern_obj_cleanup` cleanup callback. + * @param extern_obj_cleanup a callback to release `extern_obj` + * + * @return true if success, false otherwise + */ +WASM_RUNTIME_API_EXTERN bool +wasm_externref_set_cleanup(wasm_module_inst_t module_inst, void *extern_obj, + void (*extern_obj_cleanup)(void *)); + /** * Retrieve the external object from an internal externref index * @@ -1329,6 +1419,30 @@ WASM_RUNTIME_API_EXTERN uint32_t wasm_runtime_dump_call_stack_to_buf(wasm_exec_env_t exec_env, char *buf, uint32_t len); +/** + * Get the size required to store the LLVM PGO profile data + * + * @param module_inst the WASM module instance + * + * @return size required to store the contents, 0 means error + */ +WASM_RUNTIME_API_EXTERN uint32_t +wasm_runtime_get_pgo_prof_data_size(wasm_module_inst_t module_inst); + +/** + * Dump the LLVM PGO profile data to buffer + * + * @param module_inst the WASM module instance + * @param buf buffer to store the dumped content + * @param len length of the buffer + * + * @return bytes dumped to the buffer, 0 means error and data in buf + * may be invalid + */ +WASM_RUNTIME_API_EXTERN uint32_t +wasm_runtime_dump_pgo_prof_data_to_buf(wasm_module_inst_t module_inst, + char *buf, uint32_t len); + /** * Get a custom section by name * @@ -1351,20 +1465,151 @@ WASM_RUNTIME_API_EXTERN void wasm_runtime_get_version(uint32_t *major, uint32_t *minor, uint32_t *patch); /** - * Check whether an import func `(import (func ...))` is linked or not - * with runtime registered natvie functions + * Check whether an import func `(import (func ...))` + * is linked or not with runtime registered natvie functions */ WASM_RUNTIME_API_EXTERN bool wasm_runtime_is_import_func_linked(const char *module_name, const char *func_name); /** - * Check whether an import global `(import (global ...))` is linked or not - * with runtime registered natvie globals + * Check whether an import global `(import (global ...))` + * is linked or not with runtime registered natvie globals */ WASM_RUNTIME_API_EXTERN bool wasm_runtime_is_import_global_linked(const char *module_name, const char *global_name); + +typedef enum { + INTERNAL_ERROR, + MAX_SIZE_REACHED, +} enlarge_memory_error_reason_t; + +typedef void (*enlarge_memory_error_callback_t)( + uint32_t inc_page_count, uint64_t current_memory_size, + uint32_t memory_index, enlarge_memory_error_reason_t failure_reason, + wasm_module_inst_t instance, wasm_exec_env_t exec_env, + void* user_data); + +/** + * Setup callback invoked when memory.grow fails + */ +WASM_RUNTIME_API_EXTERN void +wasm_runtime_set_enlarge_mem_error_callback( + const enlarge_memory_error_callback_t callback, void *user_data); + +/* + * module instance context APIs + * wasm_runtime_create_context_key + * wasm_runtime_destroy_context_key + * wasm_runtime_set_context + * wasm_runtime_set_context_spread + * wasm_runtime_get_context + * + * This set of APIs is intended to be used by an embedder which provides + * extra sets of native functions, which need per module instance state + * and are maintained outside of the WAMR tree. + * + * It's modelled after the pthread specific API. + * + * wasm_runtime_set_context_spread is similar to + * wasm_runtime_set_context, except that + * wasm_runtime_set_context_spread applies the change + * to all threads in the cluster. + * It's an undefined behavior if multiple threads in a cluster call + * wasm_runtime_set_context_spread on the same key + * simultaneously. It's a caller's resposibility to perform necessary + * serialization if necessary. For example: + * + * if (wasm_runtime_get_context(inst, key) == NULL) { + * newctx = alloc_and_init(...); + * lock(some_lock); + * if (wasm_runtime_get_context(inst, key) == NULL) { + * // this thread won the race + * wasm_runtime_set_context_spread(inst, key, newctx); + * newctx = NULL; + * } + * unlock(some_lock); + * if (newctx != NULL) { + * // this thread lost the race, free it + * cleanup_and_free(newctx); + * } + * } + * + * Note: dynamic key create/destroy while instances are live is not + * implemented as of writing this. + * it's caller's resposibility to ensure destorying all module instances + * before calling wasm_runtime_create_context_key or + * wasm_runtime_destroy_context_key. + * otherwise, it's an undefined behavior. + * + * Note about threads: + * - When spawning a thread, the contexts (the pointers given to + * wasm_runtime_set_context) are copied from the parent + * instance. + * - The destructor is called only on the main instance. + */ + +WASM_RUNTIME_API_EXTERN void * +wasm_runtime_create_context_key( + void (*dtor)(wasm_module_inst_t inst, void *ctx)); + +WASM_RUNTIME_API_EXTERN void +wasm_runtime_destroy_context_key(void *key); + +WASM_RUNTIME_API_EXTERN void +wasm_runtime_set_context(wasm_module_inst_t inst, void *key, void *ctx); + +WASM_RUNTIME_API_EXTERN void +wasm_runtime_set_context_spread(wasm_module_inst_t inst, void *key, void *ctx); + +WASM_RUNTIME_API_EXTERN void * +wasm_runtime_get_context(wasm_module_inst_t inst, void *key); + +/* + * wasm_runtime_begin_blocking_op/wasm_runtime_end_blocking_op + * + * These APIs are intended to be used by the implementations of + * host functions. It wraps an operation which possibly blocks for long + * to prepare for async termination. + * + * eg. + * + * if (!wasm_runtime_begin_blocking_op(exec_env)) { + * return EINTR; + * } + * ret = possibly_blocking_op(); + * wasm_runtime_end_blocking_op(exec_env); + * return ret; + * + * If threading support (WASM_ENABLE_THREAD_MGR) is not enabled, + * these functions are no-op. + * + * If the underlying platform support (OS_ENABLE_WAKEUP_BLOCKING_OP) is + * not available, these functions are no-op. In that case, the runtime + * might not terminate a blocking thread in a timely manner. + * + * If the underlying platform support is available, it's used to wake up + * the thread for async termination. The expectation here is that a + * `os_wakeup_blocking_op` call makes the blocking operation + * (`possibly_blocking_op` in the above example) return in a timely manner. + * + * The actual wake up mechanism used by `os_wakeup_blocking_op` is + * platform-dependent. It might impose some platform-dependent restrictions + * on the implementation of the blocking opearation. + * + * For example, on POSIX-like platforms, a signal (by default SIGUSR1) is + * used. The signal delivery configurations (eg. signal handler, signal mask, + * etc) for the signal are set up by the runtime. You can change the signal + * to use for this purpose by calling os_set_signal_number_for_blocking_op + * before the runtime initialization. + */ +WASM_RUNTIME_API_EXTERN bool +wasm_runtime_begin_blocking_op(wasm_exec_env_t exec_env); + +WASM_RUNTIME_API_EXTERN void +wasm_runtime_end_blocking_op(wasm_exec_env_t exec_env); + /* clang-format on */ #ifdef __cplusplus diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/SConscript similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/SConscript rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/SConscript diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/iwasm_interp.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/iwasm_interp.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/iwasm_interp.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/iwasm_interp.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm.h similarity index 97% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm.h index 0797a018b88..ee537aa63b2 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm.h @@ -311,7 +311,6 @@ typedef struct WASMTableSeg { uint32 mode; /* funcref or externref, elemkind will be considered as funcref */ uint32 elem_type; - bool is_dropped; /* optional, only for active */ uint32 table_index; InitializerExpression base_offset; @@ -350,7 +349,7 @@ typedef struct WASIArguments { uint32 ns_lookup_count; char **argv; uint32 argc; - int stdio[3]; + os_raw_file_handle stdio[3]; } WASIArguments; #endif @@ -627,7 +626,6 @@ typedef struct WASMBranchBlock { uint32 cell_num; } WASMBranchBlock; -/* Execution environment, e.g. stack info */ /** * Align an unsigned value on a alignment boundary. * @@ -643,6 +641,24 @@ align_uint(unsigned v, unsigned b) return (v + m) & ~m; } +/** + * Check whether a piece of data is out of range + * + * @param offset the offset that the data starts + * @param len the length of the data + * @param max_size the maximum size of the data range + * + * @return true if out of range, false otherwise + */ +inline static bool +offset_len_out_of_bounds(uint32 offset, uint32 len, uint32 max_size) +{ + if (offset + len < offset /* integer overflow */ + || offset + len > max_size) + return true; + return false; +} + /** * Return the hash value of c string. */ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_interp.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_interp.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_interp.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_interp.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_interp_classic.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_interp_classic.c similarity index 94% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_interp_classic.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_interp_classic.c index 4cc47014335..e27b16544f2 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_interp_classic.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_interp_classic.c @@ -36,31 +36,33 @@ typedef float64 CellType_F64; * multi-threading mode since it may be changed by other * threads in memory.grow */ -#define get_linear_mem_size() memory->memory_data_size +#define get_linear_mem_size() GET_LINEAR_MEMORY_SIZE(memory) #endif #if !defined(OS_ENABLE_HW_BOUND_CHECK) \ || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 -#define CHECK_MEMORY_OVERFLOW(bytes) \ - do { \ - uint64 offset1 = (uint64)offset + (uint64)addr; \ - if (offset1 + bytes <= (uint64)get_linear_mem_size()) \ - /* If offset1 is in valid range, maddr must also \ - be in valid range, no need to check it again. */ \ - maddr = memory->memory_data + offset1; \ - else \ - goto out_of_bounds; \ +#define CHECK_MEMORY_OVERFLOW(bytes) \ + do { \ + uint64 offset1 = (uint64)offset + (uint64)addr; \ + if (disable_bounds_checks \ + || offset1 + bytes <= (uint64)get_linear_mem_size()) \ + /* If offset1 is in valid range, maddr must also \ + be in valid range, no need to check it again. */ \ + maddr = memory->memory_data + offset1; \ + else \ + goto out_of_bounds; \ } while (0) -#define CHECK_BULK_MEMORY_OVERFLOW(start, bytes, maddr) \ - do { \ - uint64 offset1 = (uint32)(start); \ - if (offset1 + bytes <= (uint64)get_linear_mem_size()) \ - /* App heap space is not valid space for \ - bulk memory operation */ \ - maddr = memory->memory_data + offset1; \ - else \ - goto out_of_bounds; \ +#define CHECK_BULK_MEMORY_OVERFLOW(start, bytes, maddr) \ + do { \ + uint64 offset1 = (uint32)(start); \ + if (disable_bounds_checks \ + || offset1 + bytes <= (uint64)get_linear_mem_size()) \ + /* App heap space is not valid space for \ + bulk memory operation */ \ + maddr = memory->memory_data + offset1; \ + else \ + goto out_of_bounds; \ } while (0) #else #define CHECK_MEMORY_OVERFLOW(bytes) \ @@ -708,28 +710,28 @@ trunc_f64_to_int(WASMModuleInstance *module, uint32 *frame_sp, float64 src_min, CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); \ CHECK_ATOMIC_MEMORY_ACCESS(); \ \ - os_mutex_lock(&node->shared_mem_lock); \ + shared_memory_lock(memory); \ readv = (uint32)(*(uint8 *)maddr); \ *(uint8 *)maddr = (uint8)(readv op sval); \ - os_mutex_unlock(&node->shared_mem_lock); \ + shared_memory_unlock(memory); \ } \ else if (opcode == WASM_OP_ATOMIC_RMW_I32_##OP_NAME##16_U) { \ CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); \ CHECK_ATOMIC_MEMORY_ACCESS(); \ \ - os_mutex_lock(&node->shared_mem_lock); \ + shared_memory_lock(memory); \ readv = (uint32)LOAD_U16(maddr); \ STORE_U16(maddr, (uint16)(readv op sval)); \ - os_mutex_unlock(&node->shared_mem_lock); \ + shared_memory_unlock(memory); \ } \ else { \ CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); \ CHECK_ATOMIC_MEMORY_ACCESS(); \ \ - os_mutex_lock(&node->shared_mem_lock); \ + shared_memory_lock(memory); \ readv = LOAD_I32(maddr); \ STORE_U32(maddr, readv op sval); \ - os_mutex_unlock(&node->shared_mem_lock); \ + shared_memory_unlock(memory); \ } \ PUSH_I32(readv); \ break; \ @@ -748,39 +750,39 @@ trunc_f64_to_int(WASMModuleInstance *module, uint32 *frame_sp, float64 src_min, CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); \ CHECK_ATOMIC_MEMORY_ACCESS(); \ \ - os_mutex_lock(&node->shared_mem_lock); \ + shared_memory_lock(memory); \ readv = (uint64)(*(uint8 *)maddr); \ *(uint8 *)maddr = (uint8)(readv op sval); \ - os_mutex_unlock(&node->shared_mem_lock); \ + shared_memory_unlock(memory); \ } \ else if (opcode == WASM_OP_ATOMIC_RMW_I64_##OP_NAME##16_U) { \ CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); \ CHECK_ATOMIC_MEMORY_ACCESS(); \ \ - os_mutex_lock(&node->shared_mem_lock); \ + shared_memory_lock(memory); \ readv = (uint64)LOAD_U16(maddr); \ STORE_U16(maddr, (uint16)(readv op sval)); \ - os_mutex_unlock(&node->shared_mem_lock); \ + shared_memory_unlock(memory); \ } \ else if (opcode == WASM_OP_ATOMIC_RMW_I64_##OP_NAME##32_U) { \ CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); \ CHECK_ATOMIC_MEMORY_ACCESS(); \ \ - os_mutex_lock(&node->shared_mem_lock); \ + shared_memory_lock(memory); \ readv = (uint64)LOAD_U32(maddr); \ STORE_U32(maddr, (uint32)(readv op sval)); \ - os_mutex_unlock(&node->shared_mem_lock); \ + shared_memory_unlock(memory); \ } \ else { \ uint64 op_result; \ CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 8, maddr); \ CHECK_ATOMIC_MEMORY_ACCESS(); \ \ - os_mutex_lock(&node->shared_mem_lock); \ + shared_memory_lock(memory); \ readv = (uint64)LOAD_I64(maddr); \ op_result = readv op sval; \ STORE_I64(maddr, op_result); \ - os_mutex_unlock(&node->shared_mem_lock); \ + shared_memory_unlock(memory); \ } \ PUSH_I64(readv); \ break; \ @@ -903,8 +905,9 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst, if (!func_import->call_conv_wasm_c_api) { native_func_pointer = module_inst->import_func_ptrs[cur_func_index]; } - else if (module_inst->e->c_api_func_imports) { - c_api_func_import = module_inst->e->c_api_func_imports + cur_func_index; + else if (module_inst->e->common.c_api_func_imports) { + c_api_func_import = + module_inst->e->common.c_api_func_imports + cur_func_index; native_func_pointer = c_api_func_import->func_ptr_linked; } @@ -1010,7 +1013,8 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst, } /* - module_inst */ - exec_env->module_inst = (WASMModuleInstanceCommon *)sub_module_inst; + wasm_exec_env_set_module_inst(exec_env, + (WASMModuleInstanceCommon *)sub_module_inst); /* - aux_stack_boundary */ aux_stack_origin_boundary = exec_env->aux_stack_boundary.boundary; exec_env->aux_stack_boundary.boundary = @@ -1032,15 +1036,8 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst, prev_frame->ip = ip; exec_env->aux_stack_boundary.boundary = aux_stack_origin_boundary; exec_env->aux_stack_bottom.bottom = aux_stack_origin_bottom; - exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst; - - /* transfer exception if it is thrown */ - if (wasm_copy_exception(sub_module_inst, NULL)) { - bh_memcpy_s(module_inst->cur_exception, - sizeof(module_inst->cur_exception), - sub_module_inst->cur_exception, - sizeof(sub_module_inst->cur_exception)); - } + wasm_exec_env_restore_module_inst(exec_env, + (WASMModuleInstanceCommon *)module_inst); } #endif @@ -1060,21 +1057,33 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst, os_mutex_unlock(&exec_env->wait_lock); \ } while (0) #else -#define CHECK_SUSPEND_FLAGS() \ - do { \ - os_mutex_lock(&exec_env->wait_lock); \ - if (exec_env->suspend_flags.flags != 0) { \ - if (exec_env->suspend_flags.flags & 0x01) { \ - /* terminate current thread */ \ - os_mutex_unlock(&exec_env->wait_lock); \ - return; \ - } \ - while (exec_env->suspend_flags.flags & 0x02) { \ - /* suspend current thread */ \ - os_cond_wait(&exec_env->wait_cond, &exec_env->wait_lock); \ - } \ - } \ - os_mutex_unlock(&exec_env->wait_lock); \ +#if WASM_SUSPEND_FLAGS_IS_ATOMIC != 0 +/* The lock is only needed when the suspend_flags is atomic; otherwise + the lock is already taken at the time when SUSPENSION_LOCK() is called. */ +#define SUSPENSION_LOCK() os_mutex_lock(&exec_env->wait_lock); +#define SUSPENSION_UNLOCK() os_mutex_unlock(&exec_env->wait_lock); +#else +#define SUSPENSION_LOCK() +#define SUSPENSION_UNLOCK() +#endif + +#define CHECK_SUSPEND_FLAGS() \ + do { \ + WASM_SUSPEND_FLAGS_LOCK(exec_env->wait_lock); \ + if (WASM_SUSPEND_FLAGS_GET(exec_env->suspend_flags) \ + & WASM_SUSPEND_FLAG_TERMINATE) { \ + /* terminate current thread */ \ + WASM_SUSPEND_FLAGS_UNLOCK(exec_env->wait_lock); \ + return; \ + } \ + while (WASM_SUSPEND_FLAGS_GET(exec_env->suspend_flags) \ + & WASM_SUSPEND_FLAG_SUSPEND) { \ + /* suspend current thread */ \ + SUSPENSION_LOCK() \ + os_cond_wait(&exec_env->wait_cond, &exec_env->wait_lock); \ + SUSPENSION_UNLOCK() \ + } \ + WASM_SUSPEND_FLAGS_UNLOCK(exec_env->wait_lock); \ } while (0) #endif /* WASM_ENABLE_DEBUG_INTERP */ #endif /* WASM_ENABLE_THREAD_MGR */ @@ -1142,15 +1151,17 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, WASMFunctionInstance *cur_func, WASMInterpFrame *prev_frame) { -#if WASM_ENABLE_SHARED_MEMORY != 0 - WASMSharedMemNode *node = - wasm_module_get_shared_memory((WASMModuleCommon *)module->module); -#endif WASMMemoryInstance *memory = wasm_get_default_memory(module); #if !defined(OS_ENABLE_HW_BOUND_CHECK) \ || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \ || WASM_ENABLE_BULK_MEMORY != 0 - uint32 linear_mem_size = memory ? memory->memory_data_size : 0; + uint32 linear_mem_size = 0; + if (memory) +#if WASM_ENABLE_THREAD_MGR == 0 + linear_mem_size = memory->memory_data_size; +#else + linear_mem_size = GET_LINEAR_MEMORY_SIZE(memory); +#endif #endif WASMType **wasm_types = module->module->types; WASMGlobalInstance *globals = module->e->globals, *global; @@ -1174,6 +1185,15 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, uint8 local_type, *global_addr; uint32 cache_index, type_index, param_cell_num, cell_num; uint8 value_type; +#if !defined(OS_ENABLE_HW_BOUND_CHECK) \ + || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 +#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0 + bool disable_bounds_checks = !wasm_runtime_is_bounds_checks_enabled( + (WASMModuleInstanceCommon *)module); +#else + bool disable_bounds_checks = false; +#endif +#endif #if WASM_ENABLE_DEBUG_INTERP != 0 uint8 *frame_ip_orig = NULL; @@ -1398,6 +1418,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, while (node_cache) { node_next = bh_list_elem_next(node_cache); if (node_cache->br_table_op_addr == frame_ip - 1) { + if (lidx > node_cache->br_count) + lidx = node_cache->br_count; depth = node_cache->br_depths[lidx]; goto label_pop_csp_n; } @@ -2127,7 +2149,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, #if !defined(OS_ENABLE_HW_BOUND_CHECK) \ || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \ || WASM_ENABLE_BULK_MEMORY != 0 - linear_mem_size = memory->memory_data_size; + linear_mem_size = get_linear_mem_size(); #endif } @@ -3132,7 +3154,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, addr = (uint32)POP_I32(); #if WASM_ENABLE_THREAD_MGR != 0 - linear_mem_size = memory->memory_data_size; + linear_mem_size = get_linear_mem_size(); #endif #ifndef OS_ENABLE_HW_BOUND_CHECK @@ -3144,9 +3166,17 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, maddr = memory->memory_data + (uint32)addr; #endif - seg_len = (uint64)module->module->data_segments[segment] - ->data_length; - data = module->module->data_segments[segment]->data; + if (bh_bitmap_get_bit(module->e->common.data_dropped, + segment)) { + seg_len = 0; + data = NULL; + } + else { + seg_len = + (uint64)module->module->data_segments[segment] + ->data_length; + data = module->module->data_segments[segment]->data; + } if (offset + bytes > seg_len) goto out_of_bounds; @@ -3159,7 +3189,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, uint32 segment; read_leb_uint32(frame_ip, frame_ip_end, segment); - module->module->data_segments[segment]->data_length = 0; + bh_bitmap_set_bit(module->e->common.data_dropped, + segment); break; } case WASM_OP_MEMORY_COPY: @@ -3174,7 +3205,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, dst = POP_I32(); #if WASM_ENABLE_THREAD_MGR != 0 - linear_mem_size = memory->memory_data_size; + linear_mem_size = get_linear_mem_size(); #endif #ifndef OS_ENABLE_HW_BOUND_CHECK @@ -3205,7 +3236,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, dst = POP_I32(); #if WASM_ENABLE_THREAD_MGR != 0 - linear_mem_size = memory->memory_data_size; + linear_mem_size = get_linear_mem_size(); #endif #ifndef OS_ENABLE_HW_BOUND_CHECK @@ -3224,7 +3255,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, case WASM_OP_TABLE_INIT: { uint32 tbl_idx, elem_idx; - uint64 n, s, d; + uint32 n, s, d; WASMTableInstance *tbl_inst; read_leb_uint32(frame_ip, frame_ip_end, elem_idx); @@ -3239,22 +3270,23 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, s = (uint32)POP_I32(); d = (uint32)POP_I32(); - /* TODO: what if the element is not passive? */ - - if (!n) { - break; - } - - if (n + s > module->module->table_segments[elem_idx] - .function_count - || d + n > tbl_inst->cur_size) { + if (offset_len_out_of_bounds( + s, n, + module->module->table_segments[elem_idx] + .function_count) + || offset_len_out_of_bounds(d, n, + tbl_inst->cur_size)) { wasm_set_exception(module, "out of bounds table access"); goto got_exception; } - if (module->module->table_segments[elem_idx] - .is_dropped) { + if (!n) { + break; + } + + if (bh_bitmap_get_bit(module->e->common.elem_dropped, + elem_idx)) { wasm_set_exception(module, "out of bounds table access"); goto got_exception; @@ -3286,14 +3318,14 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, read_leb_uint32(frame_ip, frame_ip_end, elem_idx); bh_assert(elem_idx < module->module->table_seg_count); - module->module->table_segments[elem_idx].is_dropped = - true; + bh_bitmap_set_bit(module->e->common.elem_dropped, + elem_idx); break; } case WASM_OP_TABLE_COPY: { uint32 src_tbl_idx, dst_tbl_idx; - uint64 n, s, d; + uint32 n, s, d; WASMTableInstance *src_tbl_inst, *dst_tbl_inst; read_leb_uint32(frame_ip, frame_ip_end, dst_tbl_idx); @@ -3310,8 +3342,10 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, s = (uint32)POP_I32(); d = (uint32)POP_I32(); - if (d + n > dst_tbl_inst->cur_size - || s + n > src_tbl_inst->cur_size) { + if (offset_len_out_of_bounds(d, n, + dst_tbl_inst->cur_size) + || offset_len_out_of_bounds( + s, n, src_tbl_inst->cur_size)) { wasm_set_exception(module, "out of bounds table access"); goto got_exception; @@ -3381,11 +3415,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, fill_val = POP_I32(); i = POP_I32(); - /* TODO: what if the element is not passive? */ - /* TODO: what if the element is dropped? */ - - if (i + n > tbl_inst->cur_size) { - /* TODO: verify warning content */ + if (offset_len_out_of_bounds(i, n, + tbl_inst->cur_size)) { wasm_set_exception(module, "out of bounds table access"); goto got_exception; @@ -3503,23 +3534,23 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, if (opcode == WASM_OP_ATOMIC_I32_LOAD8_U) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint32)(*(uint8 *)maddr); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else if (opcode == WASM_OP_ATOMIC_I32_LOAD16_U) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint32)LOAD_U16(maddr); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = LOAD_I32(maddr); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } PUSH_I32(readv); @@ -3538,30 +3569,30 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, if (opcode == WASM_OP_ATOMIC_I64_LOAD8_U) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint64)(*(uint8 *)maddr); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else if (opcode == WASM_OP_ATOMIC_I64_LOAD16_U) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint64)LOAD_U16(maddr); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else if (opcode == WASM_OP_ATOMIC_I64_LOAD32_U) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint64)LOAD_U32(maddr); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 8, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = LOAD_I64(maddr); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } PUSH_I64(readv); @@ -3580,23 +3611,23 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, if (opcode == WASM_OP_ATOMIC_I32_STORE8) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); *(uint8 *)maddr = (uint8)sval; - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else if (opcode == WASM_OP_ATOMIC_I32_STORE16) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); STORE_U16(maddr, (uint16)sval); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); STORE_U32(maddr, sval); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } break; } @@ -3614,30 +3645,30 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, if (opcode == WASM_OP_ATOMIC_I64_STORE8) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); *(uint8 *)maddr = (uint8)sval; - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else if (opcode == WASM_OP_ATOMIC_I64_STORE16) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); STORE_U16(maddr, (uint16)sval); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else if (opcode == WASM_OP_ATOMIC_I64_STORE32) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); STORE_U32(maddr, (uint32)sval); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 8, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); PUT_I64_TO_ADDR((uint32 *)maddr, sval); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } break; } @@ -3657,32 +3688,32 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, CHECK_ATOMIC_MEMORY_ACCESS(); expect = (uint8)expect; - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint32)(*(uint8 *)maddr); if (readv == expect) *(uint8 *)maddr = (uint8)(sval); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else if (opcode == WASM_OP_ATOMIC_RMW_I32_CMPXCHG16_U) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); expect = (uint16)expect; - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint32)LOAD_U16(maddr); if (readv == expect) STORE_U16(maddr, (uint16)(sval)); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = LOAD_I32(maddr); if (readv == expect) STORE_U32(maddr, sval); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } PUSH_I32(readv); break; @@ -3703,43 +3734,43 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, CHECK_ATOMIC_MEMORY_ACCESS(); expect = (uint8)expect; - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint64)(*(uint8 *)maddr); if (readv == expect) *(uint8 *)maddr = (uint8)(sval); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else if (opcode == WASM_OP_ATOMIC_RMW_I64_CMPXCHG16_U) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); expect = (uint16)expect; - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint64)LOAD_U16(maddr); if (readv == expect) STORE_U16(maddr, (uint16)(sval)); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else if (opcode == WASM_OP_ATOMIC_RMW_I64_CMPXCHG32_U) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); expect = (uint32)expect; - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint64)LOAD_U32(maddr); if (readv == expect) STORE_U32(maddr, (uint32)(sval)); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 8, maddr); CHECK_ATOMIC_MEMORY_ACCESS(); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint64)LOAD_I64(maddr); if (readv == expect) STORE_I64(maddr, sval); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } PUSH_I64(readv); break; @@ -3772,7 +3803,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, HANDLE_OP(DEBUG_OP_BREAK) { wasm_cluster_thread_send_signal(exec_env, WAMR_SIG_TRAP); - exec_env->suspend_flags.flags |= 2; + WASM_SUSPEND_FLAGS_FETCH_OR(exec_env->suspend_flags, + WASM_SUSPEND_FLAG_SUSPEND); frame_ip--; SYNC_ALL_TO_FRAME(); CHECK_SUSPEND_FLAGS(); @@ -3881,7 +3913,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \ || WASM_ENABLE_BULK_MEMORY != 0 if (memory) - linear_mem_size = memory->memory_data_size; + linear_mem_size = get_linear_mem_size(); #endif if (wasm_copy_exception(module, NULL)) goto got_exception; @@ -3986,6 +4018,14 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, } #if WASM_ENABLE_FAST_JIT != 0 +/* + * ASAN is not designed to work with custom stack unwind or other low-level + * things. Ignore a function that does some low-level magic. (e.g. walking + * through the thread's stack bypassing the frame boundaries) + */ +#if defined(__GNUC__) || defined(__clang__) +__attribute__((no_sanitize_address)) +#endif static void fast_jit_call_func_bytecode(WASMModuleInstance *module_inst, WASMExecEnv *exec_env, @@ -4182,7 +4222,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env, unsigned frame_size = wasm_interp_interp_frame_size(all_cell_num); unsigned i; bool copy_argv_from_frame = true; - char exception[EXCEPTION_BUF_LEN]; if (argc < function->param_cell_num) { char buf[128]; @@ -4225,6 +4264,15 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env, wasm_exec_env_set_cur_frame(exec_env, frame); +#if defined(os_writegsbase) + { + WASMMemoryInstance *memory_inst = wasm_get_default_memory(module_inst); + if (memory_inst) + /* write base addr of linear memory to GS segment register */ + os_writegsbase(memory_inst->memory_data); + } +#endif + if (function->is_import_func) { #if WASM_ENABLE_MULTI_MODULE != 0 if (function->import_module_inst) { @@ -4306,8 +4354,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env, wasm_interp_dump_call_stack(exec_env, true, NULL, 0); } #endif - wasm_copy_exception(module_inst, exception); - LOG_DEBUG("meet an exception %s", exception); } wasm_exec_env_set_cur_frame(exec_env, prev_frame); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_interp_fast.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_interp_fast.c similarity index 93% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_interp_fast.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_interp_fast.c index 6ddeaa9c0e4..d3cebc334b3 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_interp_fast.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_interp_fast.c @@ -27,7 +27,7 @@ typedef float64 CellType_F64; * multi-threading mode since it may be changed by other * threads in memory.grow */ -#define get_linear_mem_size() memory->memory_data_size +#define get_linear_mem_size() GET_LINEAR_MEMORY_SIZE(memory) #endif #if !defined(OS_ENABLE_HW_BOUND_CHECK) \ @@ -35,7 +35,8 @@ typedef float64 CellType_F64; #define CHECK_MEMORY_OVERFLOW(bytes) \ do { \ uint64 offset1 = (uint64)offset + (uint64)addr; \ - if (offset1 + bytes <= (uint64)get_linear_mem_size()) \ + if (disable_bounds_checks \ + || offset1 + bytes <= (uint64)get_linear_mem_size()) \ /* If offset1 is in valid range, maddr must also \ be in valid range, no need to check it again. */ \ maddr = memory->memory_data + offset1; \ @@ -43,15 +44,15 @@ typedef float64 CellType_F64; goto out_of_bounds; \ } while (0) -#define CHECK_BULK_MEMORY_OVERFLOW(start, bytes, maddr) \ - do { \ - uint64 offset1 = (uint32)(start); \ - if (offset1 + bytes <= get_linear_mem_size()) \ - /* App heap space is not valid space for \ - bulk memory operation */ \ - maddr = memory->memory_data + offset1; \ - else \ - goto out_of_bounds; \ +#define CHECK_BULK_MEMORY_OVERFLOW(start, bytes, maddr) \ + do { \ + uint64 offset1 = (uint32)(start); \ + if (disable_bounds_checks || offset1 + bytes <= get_linear_mem_size()) \ + /* App heap space is not valid space for \ + bulk memory operation */ \ + maddr = memory->memory_data + offset1; \ + else \ + goto out_of_bounds; \ } while (0) #else #define CHECK_MEMORY_OVERFLOW(bytes) \ @@ -481,28 +482,28 @@ LOAD_PTR(void *addr) CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); \ CHECK_ATOMIC_MEMORY_ACCESS(1); \ \ - os_mutex_lock(&node->shared_mem_lock); \ + shared_memory_lock(memory); \ readv = (uint32)(*(uint8 *)maddr); \ *(uint8 *)maddr = (uint8)(readv op sval); \ - os_mutex_unlock(&node->shared_mem_lock); \ + shared_memory_unlock(memory); \ } \ else if (opcode == WASM_OP_ATOMIC_RMW_I32_##OP_NAME##16_U) { \ CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); \ CHECK_ATOMIC_MEMORY_ACCESS(2); \ \ - os_mutex_lock(&node->shared_mem_lock); \ + shared_memory_lock(memory); \ readv = (uint32)LOAD_U16(maddr); \ STORE_U16(maddr, (uint16)(readv op sval)); \ - os_mutex_unlock(&node->shared_mem_lock); \ + shared_memory_unlock(memory); \ } \ else { \ CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); \ CHECK_ATOMIC_MEMORY_ACCESS(4); \ \ - os_mutex_lock(&node->shared_mem_lock); \ + shared_memory_lock(memory); \ readv = LOAD_I32(maddr); \ STORE_U32(maddr, readv op sval); \ - os_mutex_unlock(&node->shared_mem_lock); \ + shared_memory_unlock(memory); \ } \ PUSH_I32(readv); \ break; \ @@ -521,39 +522,39 @@ LOAD_PTR(void *addr) CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); \ CHECK_ATOMIC_MEMORY_ACCESS(1); \ \ - os_mutex_lock(&node->shared_mem_lock); \ + shared_memory_lock(memory); \ readv = (uint64)(*(uint8 *)maddr); \ *(uint8 *)maddr = (uint8)(readv op sval); \ - os_mutex_unlock(&node->shared_mem_lock); \ + shared_memory_unlock(memory); \ } \ else if (opcode == WASM_OP_ATOMIC_RMW_I64_##OP_NAME##16_U) { \ CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); \ CHECK_ATOMIC_MEMORY_ACCESS(2); \ \ - os_mutex_lock(&node->shared_mem_lock); \ + shared_memory_lock(memory); \ readv = (uint64)LOAD_U16(maddr); \ STORE_U16(maddr, (uint16)(readv op sval)); \ - os_mutex_unlock(&node->shared_mem_lock); \ + shared_memory_unlock(memory); \ } \ else if (opcode == WASM_OP_ATOMIC_RMW_I64_##OP_NAME##32_U) { \ CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); \ CHECK_ATOMIC_MEMORY_ACCESS(4); \ \ - os_mutex_lock(&node->shared_mem_lock); \ + shared_memory_lock(memory); \ readv = (uint64)LOAD_U32(maddr); \ STORE_U32(maddr, (uint32)(readv op sval)); \ - os_mutex_unlock(&node->shared_mem_lock); \ + shared_memory_unlock(memory); \ } \ else { \ uint64 op_result; \ CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 8, maddr); \ CHECK_ATOMIC_MEMORY_ACCESS(8); \ \ - os_mutex_lock(&node->shared_mem_lock); \ + shared_memory_lock(memory); \ readv = (uint64)LOAD_I64(maddr); \ op_result = readv op sval; \ STORE_I64(maddr, op_result); \ - os_mutex_unlock(&node->shared_mem_lock); \ + shared_memory_unlock(memory); \ } \ PUSH_I64(readv); \ break; \ @@ -937,8 +938,9 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst, if (!func_import->call_conv_wasm_c_api) { native_func_pointer = module_inst->import_func_ptrs[cur_func_index]; } - else if (module_inst->e->c_api_func_imports) { - c_api_func_import = module_inst->e->c_api_func_imports + cur_func_index; + else if (module_inst->e->common.c_api_func_imports) { + c_api_func_import = + module_inst->e->common.c_api_func_imports + cur_func_index; native_func_pointer = c_api_func_import->func_ptr_linked; } @@ -1029,7 +1031,8 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst, } /* - module_inst */ - exec_env->module_inst = (WASMModuleInstanceCommon *)sub_module_inst; + wasm_exec_env_set_module_inst(exec_env, + (WASMModuleInstanceCommon *)sub_module_inst); /* - aux_stack_boundary */ aux_stack_origin_boundary = exec_env->aux_stack_boundary.boundary; exec_env->aux_stack_boundary.boundary = @@ -1051,31 +1054,23 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst, prev_frame->ip = ip; exec_env->aux_stack_boundary.boundary = aux_stack_origin_boundary; exec_env->aux_stack_bottom.bottom = aux_stack_origin_bottom; - exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst; - - /* transfer exception if it is thrown */ - if (wasm_copy_exception(sub_module_inst, NULL)) { - bh_memcpy_s(module_inst->cur_exception, - sizeof(module_inst->cur_exception), - sub_module_inst->cur_exception, - sizeof(sub_module_inst->cur_exception)); - } + wasm_exec_env_restore_module_inst(exec_env, + (WASMModuleInstanceCommon *)module_inst); } #endif #if WASM_ENABLE_THREAD_MGR != 0 -#define CHECK_SUSPEND_FLAGS() \ - do { \ - os_mutex_lock(&exec_env->wait_lock); \ - if (exec_env->suspend_flags.flags != 0) { \ - if (exec_env->suspend_flags.flags & 0x01) { \ - /* terminate current thread */ \ - os_mutex_unlock(&exec_env->wait_lock); \ - return; \ - } \ - /* TODO: support suspend and breakpoint */ \ - } \ - os_mutex_unlock(&exec_env->wait_lock); \ +#define CHECK_SUSPEND_FLAGS() \ + do { \ + WASM_SUSPEND_FLAGS_LOCK(exec_env->wait_lock); \ + if (WASM_SUSPEND_FLAGS_GET(exec_env->suspend_flags) \ + & WASM_SUSPEND_FLAG_TERMINATE) { \ + /* terminate current thread */ \ + WASM_SUSPEND_FLAGS_UNLOCK(exec_env->wait_lock); \ + return; \ + } \ + /* TODO: support suspend and breakpoint */ \ + WASM_SUSPEND_FLAGS_UNLOCK(exec_env->wait_lock); \ } while (0) #endif @@ -1127,12 +1122,27 @@ wasm_interp_dump_op_count() goto *p_label_addr; \ } while (0) #else -#define FETCH_OPCODE_AND_DISPATCH() \ - do { \ - const void *p_label_addr = label_base + *(int16 *)frame_ip; \ - frame_ip += sizeof(int16); \ - goto *p_label_addr; \ +#if UINTPTR_MAX == UINT64_MAX +#define FETCH_OPCODE_AND_DISPATCH() \ + do { \ + const void *p_label_addr; \ + bh_assert(((uintptr_t)frame_ip & 1) == 0); \ + /* int32 relative offset was emitted in 64-bit target */ \ + p_label_addr = label_base + (int32)LOAD_U32_WITH_2U16S(frame_ip); \ + frame_ip += sizeof(int32); \ + goto *p_label_addr; \ } while (0) +#else +#define FETCH_OPCODE_AND_DISPATCH() \ + do { \ + const void *p_label_addr; \ + bh_assert(((uintptr_t)frame_ip & 1) == 0); \ + /* uint32 label address was emitted in 32-bit target */ \ + p_label_addr = (void *)(uintptr_t)LOAD_U32_WITH_2U16S(frame_ip); \ + frame_ip += sizeof(int32); \ + goto *p_label_addr; \ + } while (0) +#endif #endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */ #define HANDLE_OP_END() FETCH_OPCODE_AND_DISPATCH() @@ -1166,15 +1176,17 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, WASMFunctionInstance *cur_func, WASMInterpFrame *prev_frame) { -#if WASM_ENABLE_SHARED_MEMORY != 0 - WASMSharedMemNode *node = - wasm_module_get_shared_memory((WASMModuleCommon *)module->module); -#endif WASMMemoryInstance *memory = wasm_get_default_memory(module); #if !defined(OS_ENABLE_HW_BOUND_CHECK) \ || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \ || WASM_ENABLE_BULK_MEMORY != 0 - uint32 linear_mem_size = memory ? memory->memory_data_size : 0; + uint32 linear_mem_size = 0; + if (memory) +#if WASM_ENABLE_THREAD_MGR == 0 + linear_mem_size = memory->memory_data_size; +#else + linear_mem_size = GET_LINEAR_MEMORY_SIZE(memory); +#endif #endif WASMGlobalInstance *globals = module->e ? module->e->globals : NULL; WASMGlobalInstance *global; @@ -1186,7 +1198,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, register uint8 *frame_ip = &opcode_IMPDEP; /* cache of frame->ip */ register uint32 *frame_lp = NULL; /* cache of frame->lp */ #if WASM_ENABLE_LABELS_AS_VALUES != 0 -#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 +#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 && UINTPTR_MAX == UINT64_MAX /* cache of label base addr */ register uint8 *label_base = &&HANDLE_WASM_OP_UNREACHABLE; #endif @@ -1199,6 +1211,15 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, uint8 *maddr = NULL; uint32 local_idx, local_offset, global_idx; uint8 opcode, local_type, *global_addr; +#if !defined(OS_ENABLE_HW_BOUND_CHECK) \ + || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 +#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0 + bool disable_bounds_checks = !wasm_runtime_is_bounds_checks_enabled( + (WASMModuleInstanceCommon *)module); +#else + bool disable_bounds_checks = false; +#endif +#endif #if WASM_ENABLE_LABELS_AS_VALUES != 0 #define HANDLE_OPCODE(op) &&HANDLE_##op @@ -1896,7 +1917,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, #if !defined(OS_ENABLE_HW_BOUND_CHECK) \ || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \ || WASM_ENABLE_BULK_MEMORY != 0 - linear_mem_size = memory->memory_data_size; + linear_mem_size = get_linear_mem_size(); #endif } @@ -2974,12 +2995,12 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, segment = read_uint32(frame_ip); - bytes = (uint64)POP_I32(); - offset = (uint64)POP_I32(); + bytes = (uint64)(uint32)POP_I32(); + offset = (uint64)(uint32)POP_I32(); addr = POP_I32(); #if WASM_ENABLE_THREAD_MGR - linear_mem_size = memory->memory_data_size; + linear_mem_size = get_linear_mem_size(); #endif #ifndef OS_ENABLE_HW_BOUND_CHECK @@ -2990,10 +3011,18 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, goto out_of_bounds; maddr = memory->memory_data + (uint32)addr; #endif + if (bh_bitmap_get_bit(module->e->common.data_dropped, + segment)) { + seg_len = 0; + data = NULL; + } + else { - seg_len = (uint64)module->module->data_segments[segment] - ->data_length; - data = module->module->data_segments[segment]->data; + seg_len = + (uint64)module->module->data_segments[segment] + ->data_length; + data = module->module->data_segments[segment]->data; + } if (offset + bytes > seg_len) goto out_of_bounds; @@ -3006,8 +3035,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, uint32 segment; segment = read_uint32(frame_ip); - - module->module->data_segments[segment]->data_length = 0; + bh_bitmap_set_bit(module->e->common.data_dropped, + segment); break; } case WASM_OP_MEMORY_COPY: @@ -3020,7 +3049,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, dst = POP_I32(); #if WASM_ENABLE_THREAD_MGR - linear_mem_size = memory->memory_data_size; + linear_mem_size = get_linear_mem_size(); #endif #ifndef OS_ENABLE_HW_BOUND_CHECK @@ -3050,7 +3079,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, dst = POP_I32(); #if WASM_ENABLE_THREAD_MGR - linear_mem_size = memory->memory_data_size; + linear_mem_size = get_linear_mem_size(); #endif #ifndef OS_ENABLE_HW_BOUND_CHECK @@ -3069,7 +3098,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, case WASM_OP_TABLE_INIT: { uint32 tbl_idx, elem_idx; - uint64 n, s, d; + uint32 n, s, d; WASMTableInstance *tbl_inst; elem_idx = read_uint32(frame_ip); @@ -3084,20 +3113,23 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, s = (uint32)POP_I32(); d = (uint32)POP_I32(); - if (!n) { - break; - } - - if (n + s > module->module->table_segments[elem_idx] - .function_count - || d + n > tbl_inst->cur_size) { + if (offset_len_out_of_bounds( + s, n, + module->module->table_segments[elem_idx] + .function_count) + || offset_len_out_of_bounds(d, n, + tbl_inst->cur_size)) { wasm_set_exception(module, "out of bounds table access"); goto got_exception; } - if (module->module->table_segments[elem_idx] - .is_dropped) { + if (!n) { + break; + } + + if (bh_bitmap_get_bit(module->e->common.elem_dropped, + elem_idx)) { wasm_set_exception(module, "out of bounds table access"); goto got_exception; @@ -3126,15 +3158,14 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, { uint32 elem_idx = read_uint32(frame_ip); bh_assert(elem_idx < module->module->table_seg_count); - - module->module->table_segments[elem_idx].is_dropped = - true; + bh_bitmap_set_bit(module->e->common.elem_dropped, + elem_idx); break; } case WASM_OP_TABLE_COPY: { uint32 src_tbl_idx, dst_tbl_idx; - uint64 n, s, d; + uint32 n, s, d; WASMTableInstance *src_tbl_inst, *dst_tbl_inst; dst_tbl_idx = read_uint32(frame_ip); @@ -3151,8 +3182,10 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, s = (uint32)POP_I32(); d = (uint32)POP_I32(); - if (d + n > dst_tbl_inst->cur_size - || s + n > src_tbl_inst->cur_size) { + if (offset_len_out_of_bounds(d, n, + dst_tbl_inst->cur_size) + || offset_len_out_of_bounds( + s, n, src_tbl_inst->cur_size)) { wasm_set_exception(module, "out of bounds table access"); goto got_exception; @@ -3223,7 +3256,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, fill_val = POP_I32(); i = POP_I32(); - if (i + n > tbl_inst->cur_size) { + if (offset_len_out_of_bounds(i, n, + tbl_inst->cur_size)) { wasm_set_exception(module, "out of bounds table access"); goto got_exception; @@ -3338,23 +3372,23 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, if (opcode == WASM_OP_ATOMIC_I32_LOAD8_U) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); CHECK_ATOMIC_MEMORY_ACCESS(1); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint32)(*(uint8 *)maddr); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else if (opcode == WASM_OP_ATOMIC_I32_LOAD16_U) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); CHECK_ATOMIC_MEMORY_ACCESS(2); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint32)LOAD_U16(maddr); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); CHECK_ATOMIC_MEMORY_ACCESS(4); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = LOAD_I32(maddr); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } PUSH_I32(readv); @@ -3373,30 +3407,30 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, if (opcode == WASM_OP_ATOMIC_I64_LOAD8_U) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); CHECK_ATOMIC_MEMORY_ACCESS(1); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint64)(*(uint8 *)maddr); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else if (opcode == WASM_OP_ATOMIC_I64_LOAD16_U) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); CHECK_ATOMIC_MEMORY_ACCESS(2); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint64)LOAD_U16(maddr); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else if (opcode == WASM_OP_ATOMIC_I64_LOAD32_U) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); CHECK_ATOMIC_MEMORY_ACCESS(4); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint64)LOAD_U32(maddr); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 8, maddr); CHECK_ATOMIC_MEMORY_ACCESS(8); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = LOAD_I64(maddr); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } PUSH_I64(readv); @@ -3414,23 +3448,23 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, if (opcode == WASM_OP_ATOMIC_I32_STORE8) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); CHECK_ATOMIC_MEMORY_ACCESS(1); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); *(uint8 *)maddr = (uint8)sval; - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else if (opcode == WASM_OP_ATOMIC_I32_STORE16) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); CHECK_ATOMIC_MEMORY_ACCESS(2); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); STORE_U16(maddr, (uint16)sval); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); CHECK_ATOMIC_MEMORY_ACCESS(4); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); STORE_U32(maddr, sval); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } break; } @@ -3448,30 +3482,30 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, if (opcode == WASM_OP_ATOMIC_I64_STORE8) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 1, maddr); CHECK_ATOMIC_MEMORY_ACCESS(1); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); *(uint8 *)maddr = (uint8)sval; - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else if (opcode == WASM_OP_ATOMIC_I64_STORE16) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); CHECK_ATOMIC_MEMORY_ACCESS(2); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); STORE_U16(maddr, (uint16)sval); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else if (opcode == WASM_OP_ATOMIC_I64_STORE32) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); CHECK_ATOMIC_MEMORY_ACCESS(4); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); STORE_U32(maddr, (uint32)sval); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 8, maddr); CHECK_ATOMIC_MEMORY_ACCESS(8); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); STORE_I64(maddr, sval); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } break; } @@ -3491,32 +3525,32 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, CHECK_ATOMIC_MEMORY_ACCESS(1); expect = (uint8)expect; - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint32)(*(uint8 *)maddr); if (readv == expect) *(uint8 *)maddr = (uint8)(sval); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else if (opcode == WASM_OP_ATOMIC_RMW_I32_CMPXCHG16_U) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); CHECK_ATOMIC_MEMORY_ACCESS(2); expect = (uint16)expect; - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint32)LOAD_U16(maddr); if (readv == expect) STORE_U16(maddr, (uint16)(sval)); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); CHECK_ATOMIC_MEMORY_ACCESS(4); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = LOAD_I32(maddr); if (readv == expect) STORE_U32(maddr, sval); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } PUSH_I32(readv); break; @@ -3537,43 +3571,43 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, CHECK_ATOMIC_MEMORY_ACCESS(1); expect = (uint8)expect; - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint64)(*(uint8 *)maddr); if (readv == expect) *(uint8 *)maddr = (uint8)(sval); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else if (opcode == WASM_OP_ATOMIC_RMW_I64_CMPXCHG16_U) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 2, maddr); CHECK_ATOMIC_MEMORY_ACCESS(2); expect = (uint16)expect; - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint64)LOAD_U16(maddr); if (readv == expect) STORE_U16(maddr, (uint16)(sval)); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else if (opcode == WASM_OP_ATOMIC_RMW_I64_CMPXCHG32_U) { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr); CHECK_ATOMIC_MEMORY_ACCESS(4); expect = (uint32)expect; - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint64)LOAD_U32(maddr); if (readv == expect) STORE_U32(maddr, (uint32)(sval)); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } else { CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 8, maddr); CHECK_ATOMIC_MEMORY_ACCESS(8); - os_mutex_lock(&node->shared_mem_lock); + shared_memory_lock(memory); readv = (uint64)LOAD_I64(maddr); if (readv == expect) STORE_I64(maddr, sval); - os_mutex_unlock(&node->shared_mem_lock); + shared_memory_unlock(memory); } PUSH_I64(readv); break; @@ -3820,7 +3854,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \ || WASM_ENABLE_BULK_MEMORY != 0 if (memory) - linear_mem_size = memory->memory_data_size; + linear_mem_size = get_linear_mem_size(); #endif if (wasm_copy_exception(module, NULL)) goto got_exception; @@ -3933,7 +3967,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env, /* This frame won't be used by JITed code, so only allocate interp frame here. */ unsigned frame_size = wasm_interp_interp_frame_size(all_cell_num); - char exception[EXCEPTION_BUF_LEN]; if (argc < function->param_cell_num) { char buf[128]; @@ -3979,6 +4012,15 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env, wasm_exec_env_set_cur_frame(exec_env, frame); +#if defined(os_writegsbase) + { + WASMMemoryInstance *memory_inst = wasm_get_default_memory(module_inst); + if (memory_inst) + /* write base addr of linear memory to GS segment register */ + os_writegsbase(memory_inst->memory_data); + } +#endif + if (function->is_import_func) { #if WASM_ENABLE_MULTI_MODULE != 0 if (function->import_module_inst) { @@ -4009,8 +4051,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env, wasm_interp_dump_call_stack(exec_env, true, NULL, 0); } #endif - wasm_copy_exception(module_inst, exception); - LOG_DEBUG("meet an exception %s", exception); } wasm_exec_env_set_cur_frame(exec_env, prev_frame); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_loader.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_loader.c similarity index 97% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_loader.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_loader.c index a3c4f422490..2a06f42e36e 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_loader.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_loader.c @@ -173,7 +173,6 @@ read_leb(uint8 **p_buf, const uint8 *buf_end, uint32 maxbits, bool sign, #define read_uint8(p) TEMPLATE_READ_VALUE(uint8, p) #define read_uint32(p) TEMPLATE_READ_VALUE(uint32, p) -#define read_bool(p) TEMPLATE_READ_VALUE(bool, p) #define read_leb_int64(p, p_end, res) \ do { \ @@ -302,7 +301,13 @@ check_utf8_str(const uint8 *str, uint32 len) while (p < p_end) { chr = *p; - if (chr < 0x80) { + + if (chr == 0) { + LOG_WARNING( + "LIMITATION: a string which contains '\\00' is unsupported"); + return false; + } + else if (chr < 0x80) { p++; } else if (chr >= 0xC2 && chr <= 0xDF && p + 1 < p_end) { @@ -490,6 +495,7 @@ load_init_expr(const uint8 **p_buf, const uint8 *buf_end, if (type != VALUE_TYPE_V128) goto fail_type_mismatch; + CHECK_BUF(p, p_end, 1); flag = read_uint8(p); (void)flag; @@ -694,34 +700,10 @@ wasm_loader_find_export(const WASMModule *module, const char *module_name, const char *field_name, uint8 export_kind, char *error_buf, uint32 error_buf_size) { - WASMExport *export; - uint32 i; - - for (i = 0, export = module->exports; i < module->export_count; - ++i, ++export) { - /** - * need to consider a scenario that different kinds of exports - * may have the same name, like - * (table (export "m1" "exported") 10 funcref) - * (memory (export "m1" "exported") 10) - **/ - if (export->kind == export_kind && !strcmp(field_name, export->name)) { - break; - } - } - - if (i == module->export_count) { - LOG_DEBUG("can not find an export %d named %s in the module %s", - export_kind, field_name, module_name); - set_error_buf(error_buf, error_buf_size, - "unknown import or incompatible import type"); - return NULL; - } - - (void)module_name; - - /* since there is a validation in load_export_section(), it is for sure - * export->index is valid*/ + WASMExport *export = + loader_find_export((WASMModuleCommon *)module, module_name, field_name, + export_kind, error_buf, error_buf_size); + ; return export; } #endif @@ -912,152 +894,6 @@ wasm_loader_resolve_global(const char *module_name, const char *global_name, return global; } -static WASMModule * -search_sub_module(const WASMModule *parent_module, const char *sub_module_name) -{ - WASMRegisteredModule *node = - bh_list_first_elem(parent_module->import_module_list); - while (node && strcmp(sub_module_name, node->module_name)) { - node = bh_list_elem_next(node); - } - return node ? (WASMModule *)node->module : NULL; -} - -static bool -register_sub_module(const WASMModule *parent_module, - const char *sub_module_name, WASMModule *sub_module) -{ - /* register sub_module into its parent sub module list */ - WASMRegisteredModule *node = NULL; - bh_list_status ret; - - if (search_sub_module(parent_module, sub_module_name)) { - LOG_DEBUG("%s has been registered in its parent", sub_module_name); - return true; - } - - node = loader_malloc(sizeof(WASMRegisteredModule), NULL, 0); - if (!node) { - return false; - } - - node->module_name = sub_module_name; - node->module = (WASMModuleCommon *)sub_module; - ret = bh_list_insert(parent_module->import_module_list, node); - bh_assert(BH_LIST_SUCCESS == ret); - (void)ret; - return true; -} - -static WASMModule * -load_depended_module(const WASMModule *parent_module, - const char *sub_module_name, char *error_buf, - uint32 error_buf_size) -{ - WASMModule *sub_module = NULL; - bool ret = false; - uint8 *buffer = NULL; - uint32 buffer_size = 0; - const module_reader reader = wasm_runtime_get_module_reader(); - const module_destroyer destroyer = wasm_runtime_get_module_destroyer(); - - /* check the registered module list of the parent */ - sub_module = search_sub_module(parent_module, sub_module_name); - if (sub_module) { - LOG_DEBUG("%s has been loaded before", sub_module_name); - return sub_module; - } - - /* check the global registered module list */ - sub_module = - (WASMModule *)wasm_runtime_find_module_registered(sub_module_name); - if (sub_module) { - LOG_DEBUG("%s has been loaded", sub_module_name); - goto register_sub_module; - } - - LOG_VERBOSE("loading %s", sub_module_name); - - if (!reader) { - set_error_buf_v(error_buf, error_buf_size, - "no sub module reader to load %s", sub_module_name); - return NULL; - } - - /* start to maintain a loading module list */ - ret = wasm_runtime_is_loading_module(sub_module_name); - if (ret) { - set_error_buf_v(error_buf, error_buf_size, - "found circular dependency on %s", sub_module_name); - return NULL; - } - - ret = wasm_runtime_add_loading_module(sub_module_name, error_buf, - error_buf_size); - if (!ret) { - LOG_DEBUG("can not add %s into loading module list\n", sub_module_name); - return NULL; - } - - ret = reader(sub_module_name, &buffer, &buffer_size); - if (!ret) { - LOG_DEBUG("read the file of %s failed", sub_module_name); - set_error_buf_v(error_buf, error_buf_size, "unknown import", - sub_module_name); - goto delete_loading_module; - } - - sub_module = - wasm_loader_load(buffer, buffer_size, false, error_buf, error_buf_size); - if (!sub_module) { - LOG_DEBUG("error: can not load the sub_module %s", sub_module_name); - /* others will be destroyed in runtime_destroy() */ - goto destroy_file_buffer; - } - - wasm_runtime_delete_loading_module(sub_module_name); - - /* register on a global list */ - ret = wasm_runtime_register_module_internal( - sub_module_name, (WASMModuleCommon *)sub_module, buffer, buffer_size, - error_buf, error_buf_size); - if (!ret) { - LOG_DEBUG("error: can not register module %s globally\n", - sub_module_name); - /* others will be unloaded in runtime_destroy() */ - goto unload_module; - } - - /* register into its parent list */ -register_sub_module: - ret = register_sub_module(parent_module, sub_module_name, sub_module); - if (!ret) { - set_error_buf_v(error_buf, error_buf_size, - "failed to register sub module %s", sub_module_name); - /* since it is in the global module list, no need to - * unload the module. the runtime_destroy() will do it - */ - return NULL; - } - - return sub_module; - -unload_module: - wasm_loader_unload(sub_module); - -destroy_file_buffer: - if (destroyer) { - destroyer(buffer, buffer_size); - } - else { - LOG_WARNING("need to release the reading buffer of %s manually", - sub_module_name); - } - -delete_loading_module: - wasm_runtime_delete_loading_module(sub_module_name); - return NULL; -} #endif /* end of WASM_ENABLE_MULTI_MODULE */ static bool @@ -1104,8 +940,9 @@ load_function_import(const uint8 **p_buf, const uint8 *buf_end, #if WASM_ENABLE_MULTI_MODULE != 0 else { if (!wasm_runtime_is_built_in_module(sub_module_name)) { - sub_module = load_depended_module(parent_module, sub_module_name, - error_buf, error_buf_size); + sub_module = (WASMModule *)wasm_runtime_load_depended_module( + (WASMModuleCommon *)parent_module, sub_module_name, error_buf, + error_buf_size); if (!sub_module) { return false; } @@ -1193,8 +1030,9 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end, #if WASM_ENABLE_MULTI_MODULE != 0 if (!wasm_runtime_is_built_in_module(sub_module_name)) { - sub_module = load_depended_module(parent_module, sub_module_name, - error_buf, error_buf_size); + sub_module = (WASMModule *)wasm_runtime_load_depended_module( + (WASMModuleCommon *)parent_module, sub_module_name, error_buf, + error_buf_size); if (!sub_module) { return false; } @@ -1327,8 +1165,9 @@ load_memory_import(const uint8 **p_buf, const uint8 *buf_end, #if WASM_ENABLE_MULTI_MODULE != 0 if (!wasm_runtime_is_built_in_module(sub_module_name)) { - sub_module = load_depended_module(parent_module, sub_module_name, - error_buf, error_buf_size); + sub_module = (WASMModule *)wasm_runtime_load_depended_module( + (WASMModuleCommon *)parent_module, sub_module_name, error_buf, + error_buf_size); if (!sub_module) { return false; } @@ -1427,8 +1266,9 @@ load_global_import(const uint8 **p_buf, const uint8 *buf_end, #if WASM_ENABLE_MULTI_MODULE != 0 if (!global->is_linked && !wasm_runtime_is_built_in_module(sub_module_name)) { - sub_module = load_depended_module(parent_module, sub_module_name, - error_buf, error_buf_size); + sub_module = (WASMModule *)wasm_runtime_load_depended_module( + (WASMModuleCommon *)parent_module, sub_module_name, error_buf, + error_buf_size); if (!sub_module) { return false; } @@ -1541,7 +1381,15 @@ load_memory(const uint8 **p_buf, const uint8 *buf_end, WASMMemory *memory, return false; } if (memory->flags > 1) { - set_error_buf(error_buf, error_buf_size, "integer too large"); + if (memory->flags & 2) { + set_error_buf(error_buf, error_buf_size, + "shared memory flag was found, " + "please enable shared memory, lib-pthread " + "or lib-wasi-threads"); + } + else { + set_error_buf(error_buf, error_buf_size, "invalid memory flags"); + } return false; } #else @@ -2860,7 +2708,7 @@ load_user_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module, read_leb_uint32(p, p_end, name_len); - if (name_len == 0 || p + name_len > p_end) { + if (p + name_len > p_end) { set_error_buf(error_buf, error_buf_size, "unexpected end"); return false; } @@ -3000,7 +2848,7 @@ init_llvm_jit_functions_stage1(WASMModule *module, char *error_buf, if (module->function_count == 0) return true; -#if WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_LLVM_JIT != 0 +#if WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_LAZY_JIT != 0 if (os_mutex_init(&module->tierup_wait_lock) != 0) { set_error_buf(error_buf, error_buf_size, "init jit tierup lock failed"); return false; @@ -3035,6 +2883,8 @@ init_llvm_jit_functions_stage1(WASMModule *module, char *error_buf, llvm_jit_options = wasm_runtime_get_llvm_jit_options(); option.opt_level = llvm_jit_options.opt_level; option.size_level = llvm_jit_options.size_level; + option.segue_flags = llvm_jit_options.segue_flags; + option.linux_perf_support = llvm_jit_options.linux_perf_support; #if WASM_ENABLE_BULK_MEMORY != 0 option.enable_bulk_memory = true; @@ -5475,6 +5325,7 @@ wasm_loader_pop_frame_ref(WASMLoaderContext *ctx, uint8 type, char *error_buf, return true; } +#if WASM_ENABLE_FAST_INTERP == 0 static bool wasm_loader_push_pop_frame_ref(WASMLoaderContext *ctx, uint8 pop_cnt, uint8 type_push, uint8 type_pop, char *error_buf, @@ -5489,6 +5340,7 @@ wasm_loader_push_pop_frame_ref(WASMLoaderContext *ctx, uint8 pop_cnt, return false; return true; } +#endif static bool wasm_loader_push_frame_csp(WASMLoaderContext *ctx, uint8 label_type, @@ -5552,21 +5404,27 @@ wasm_loader_pop_frame_csp(WASMLoaderContext *ctx, char *error_buf, LOG_OP("\ndelete last op\n"); \ } while (0) #else /* else of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */ +#if UINTPTR_MAX == UINT64_MAX #define emit_label(opcode) \ do { \ int32 offset = \ (int32)((uint8 *)handle_table[opcode] - (uint8 *)handle_table[0]); \ - if (!(offset >= INT16_MIN && offset < INT16_MAX)) { \ - set_error_buf(error_buf, error_buf_size, \ - "pre-compiled label offset out of range"); \ - goto fail; \ - } \ - wasm_loader_emit_int16(loader_ctx, offset); \ + /* emit int32 relative offset in 64-bit target */ \ + wasm_loader_emit_uint32(loader_ctx, offset); \ LOG_OP("\nemit_op [%02x]\t", opcode); \ } while (0) +#else +#define emit_label(opcode) \ + do { \ + uint32 label_addr = (uint32)(uintptr_t)handle_table[opcode]; \ + /* emit uint32 label address in 32-bit target */ \ + wasm_loader_emit_uint32(loader_ctx, label_addr); \ + LOG_OP("\nemit_op [%02x]\t", opcode); \ + } while (0) +#endif #define skip_label() \ do { \ - wasm_loader_emit_backspace(loader_ctx, sizeof(int16)); \ + wasm_loader_emit_backspace(loader_ctx, sizeof(int32)); \ LOG_OP("\ndelete last op\n"); \ } while (0) #endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */ @@ -5896,12 +5754,6 @@ preserve_referenced_local(WASMLoaderContext *loader_ctx, uint8 opcode, (void)error_buf; (void)error_buf_size; return true; -#if WASM_ENABLE_LABELS_AS_VALUES != 0 -#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 -fail: - return false; -#endif -#endif } static bool @@ -6165,27 +6017,6 @@ wasm_loader_pop_frame_offset(WASMLoaderContext *ctx, uint8 type, return true; } -static bool -wasm_loader_push_pop_frame_offset(WASMLoaderContext *ctx, uint8 pop_cnt, - uint8 type_push, uint8 type_pop, - bool disable_emit, int16 operand_offset, - char *error_buf, uint32 error_buf_size) -{ - uint8 i; - - for (i = 0; i < pop_cnt; i++) { - if (!wasm_loader_pop_frame_offset(ctx, type_pop, error_buf, - error_buf_size)) - return false; - } - if (!wasm_loader_push_frame_offset(ctx, type_push, disable_emit, - operand_offset, error_buf, - error_buf_size)) - return false; - - return true; -} - static bool wasm_loader_push_frame_ref_offset(WASMLoaderContext *ctx, uint8 type, bool disable_emit, int16 operand_offset, @@ -6219,12 +6050,24 @@ wasm_loader_push_pop_frame_ref_offset(WASMLoaderContext *ctx, uint8 pop_cnt, bool disable_emit, int16 operand_offset, char *error_buf, uint32 error_buf_size) { - if (!wasm_loader_push_pop_frame_offset(ctx, pop_cnt, type_push, type_pop, - disable_emit, operand_offset, - error_buf, error_buf_size)) + uint8 i; + + for (i = 0; i < pop_cnt; i++) { + if (!wasm_loader_pop_frame_offset(ctx, type_pop, error_buf, + error_buf_size)) + return false; + + if (!wasm_loader_pop_frame_ref(ctx, type_pop, error_buf, + error_buf_size)) + return false; + } + + if (!wasm_loader_push_frame_offset(ctx, type_push, disable_emit, + operand_offset, error_buf, + error_buf_size)) return false; - if (!wasm_loader_push_pop_frame_ref(ctx, pop_cnt, type_push, type_pop, - error_buf, error_buf_size)) + + if (!wasm_loader_push_frame_ref(ctx, type_push, error_buf, error_buf_size)) return false; return true; @@ -7013,6 +6856,7 @@ static bool copy_params_to_dynamic_space(WASMLoaderContext *loader_ctx, bool is_if_block, char *error_buf, uint32 error_buf_size) { + bool ret = false; int16 *frame_offset = NULL; uint8 *cells = NULL, cell; int16 *src_offsets = NULL; @@ -7083,13 +6927,13 @@ copy_params_to_dynamic_space(WASMLoaderContext *loader_ctx, bool is_if_block, if (is_if_block) PUSH_OFFSET_TYPE(VALUE_TYPE_I32); + ret = true; + +fail: /* Free the emit data */ wasm_runtime_free(emit_data); - return true; - -fail: - return false; + return ret; } #endif @@ -7189,7 +7033,7 @@ wasm_loader_get_custom_section(WASMModule *module, const char *name, section = section->next; } - return false; + return NULL; } #endif @@ -7301,6 +7145,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, BlockType block_type; p_org = p - 1; + CHECK_BUF(p, p_end, 1); value_type = read_uint8(p); if (is_byte_a_type(value_type)) { /* If the first byte is one of these special values: @@ -7354,10 +7199,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, } #if WASM_ENABLE_FAST_INTERP != 0 - if (opcode == WASM_OP_BLOCK) { - skip_label(); - } - else if (opcode == WASM_OP_LOOP) { + if (opcode == WASM_OP_BLOCK || opcode == WASM_OP_LOOP) { skip_label(); if (BLOCK_HAS_PARAM(block_type)) { /* Make sure params are in dynamic space */ @@ -7365,8 +7207,10 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, loader_ctx, false, error_buf, error_buf_size)) goto fail; } - (loader_ctx->frame_csp - 1)->code_compiled = - loader_ctx->p_code_compiled; + if (opcode == WASM_OP_LOOP) { + (loader_ctx->frame_csp - 1)->code_compiled = + loader_ctx->p_code_compiled; + } } else if (opcode == WASM_OP_IF) { /* If block has parameters, we should make sure they are in @@ -7606,6 +7450,9 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, if (frame_csp_tmp->label_type != LABEL_TYPE_LOOP) ret_count = block_type_get_result_types( &frame_csp_tmp->block_type, &ret_types); + else + ret_count = block_type_get_param_types( + &frame_csp_tmp->block_type, &ret_types); } else { uint8 *tmp_ret_types = NULL; @@ -7616,6 +7463,9 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, if (frame_csp_tmp->label_type != LABEL_TYPE_LOOP) tmp_ret_count = block_type_get_result_types( &frame_csp_tmp->block_type, &tmp_ret_types); + else + tmp_ret_count = block_type_get_param_types( + &frame_csp_tmp->block_type, &tmp_ret_types); if (ret_count != tmp_ret_count || (ret_count @@ -7908,7 +7758,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, } if (available_stack_cell > 0) { - if (is_32bit_type(*(loader_ctx->frame_ref - 1))) { + if (is_32bit_type(*(loader_ctx->frame_ref - 1)) + || *(loader_ctx->frame_ref - 1) == VALUE_TYPE_ANY) { loader_ctx->frame_ref--; loader_ctx->stack_cell_num--; #if WASM_ENABLE_FAST_INTERP != 0 @@ -7964,6 +7815,9 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, uint8 ref_type; BranchBlock *cur_block = loader_ctx->frame_csp - 1; int32 available_stack_cell; +#if WASM_ENABLE_FAST_INTERP != 0 + uint8 *p_code_compiled_tmp = loader_ctx->p_code_compiled; +#endif POP_I32(); @@ -7992,26 +7846,26 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, #if WASM_ENABLE_FAST_INTERP != 0 if (loader_ctx->p_code_compiled) { uint8 opcode_tmp = WASM_OP_SELECT_64; - uint8 *p_code_compiled_tmp = - loader_ctx->p_code_compiled - 2; #if WASM_ENABLE_LABELS_AS_VALUES != 0 #if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 *(void **)(p_code_compiled_tmp - sizeof(void *)) = handle_table[opcode_tmp]; #else +#if UINTPTR_MAX == UINT64_MAX + /* emit int32 relative offset in 64-bit target + */ int32 offset = (int32)((uint8 *)handle_table[opcode_tmp] - (uint8 *)handle_table[0]); - if (!(offset >= INT16_MIN - && offset < INT16_MAX)) { - set_error_buf(error_buf, error_buf_size, - "pre-compiled label offset " - "out of range"); - goto fail; - } - *(int16 *)(p_code_compiled_tmp - - sizeof(int16)) = (int16)offset; + *(int32 *)(p_code_compiled_tmp + - sizeof(int32)) = offset; +#else + /* emit uint32 label address in 32-bit target */ + *(uint32 *)(p_code_compiled_tmp + - sizeof(uint32)) = + (uint32)(uintptr_t)handle_table[opcode_tmp]; +#endif #endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */ #else /* else of WASM_ENABLE_LABELS_AS_VALUES */ #if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 @@ -8062,9 +7916,13 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, case WASM_OP_SELECT_T: { uint8 vec_len, ref_type; +#if WASM_ENABLE_FAST_INTERP != 0 + uint8 *p_code_compiled_tmp = loader_ctx->p_code_compiled; +#endif read_leb_uint32(p, p_end, vec_len); - if (!vec_len) { + if (vec_len != 1) { + /* typed select must have exactly one result */ set_error_buf(error_buf, error_buf_size, "invalid result arity"); goto fail; @@ -8083,8 +7941,6 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, #if WASM_ENABLE_FAST_INTERP != 0 if (loader_ctx->p_code_compiled) { uint8 opcode_tmp = WASM_OP_SELECT; - uint8 *p_code_compiled_tmp = - loader_ctx->p_code_compiled - 2; if (ref_type == VALUE_TYPE_V128) { #if (WASM_ENABLE_SIMD == 0) \ @@ -8103,16 +7959,17 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, *(void **)(p_code_compiled_tmp - sizeof(void *)) = handle_table[opcode_tmp]; #else +#if UINTPTR_MAX == UINT64_MAX + /* emit int32 relative offset in 64-bit target */ int32 offset = (int32)((uint8 *)handle_table[opcode_tmp] - (uint8 *)handle_table[0]); - if (!(offset >= INT16_MIN && offset < INT16_MAX)) { - set_error_buf( - error_buf, error_buf_size, - "pre-compiled label offset out of range"); - goto fail; - } - *(int16 *)(p_code_compiled_tmp - sizeof(int16)) = - (int16)offset; + *(int32 *)(p_code_compiled_tmp - sizeof(int32)) = + offset; +#else + /* emit uint32 label address in 32-bit target */ + *(uint32 *)(p_code_compiled_tmp - sizeof(uint32)) = + (uint32)(uintptr_t)handle_table[opcode_tmp]; +#endif #endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */ #else /* else of WASM_ENABLE_LABELS_AS_VALUES */ #if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 @@ -9254,10 +9111,13 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, #if (WASM_ENABLE_WAMR_COMPILER != 0) || (WASM_ENABLE_JIT != 0) case WASM_OP_SIMD_PREFIX: { - opcode = read_uint8(p); + uint32 opcode1; + + CHECK_BUF(p, p_end, 1); + opcode1 = read_uint8(p); /* follow the order of enum WASMSimdEXTOpcode in wasm_opcode.h */ - switch (opcode) { + switch (opcode1) { /* memory instruction */ case SIMD_v128_load: case SIMD_v128_load8x8_s: @@ -9275,7 +9135,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, read_leb_uint32(p, p_end, align); /* align */ if (!check_simd_memory_access_align( - opcode, align, error_buf, error_buf_size)) { + opcode1, align, error_buf, error_buf_size)) { goto fail; } @@ -9294,7 +9154,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, read_leb_uint32(p, p_end, align); /* align */ if (!check_simd_memory_access_align( - opcode, align, error_buf, error_buf_size)) { + opcode1, align, error_buf, error_buf_size)) { goto fail; } @@ -9350,7 +9210,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, uint8 pop_type[] = { VALUE_TYPE_I32, VALUE_TYPE_I32, VALUE_TYPE_I32, VALUE_TYPE_I64, VALUE_TYPE_F32, VALUE_TYPE_F64 }; - POP_AND_PUSH(pop_type[opcode - SIMD_i8x16_splat], + POP_AND_PUSH(pop_type[opcode1 - SIMD_i8x16_splat], VALUE_TYPE_V128); break; } @@ -9395,22 +9255,23 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, CHECK_BUF(p, p_end, 1); lane = read_uint8(p); - if (!check_simd_access_lane(opcode, lane, error_buf, + if (!check_simd_access_lane(opcode1, lane, error_buf, error_buf_size)) { goto fail; } - if (replace[opcode - SIMD_i8x16_extract_lane_s]) { + if (replace[opcode1 - SIMD_i8x16_extract_lane_s]) { if (!(wasm_loader_pop_frame_ref( loader_ctx, - replace[opcode - SIMD_i8x16_extract_lane_s], + replace[opcode1 + - SIMD_i8x16_extract_lane_s], error_buf, error_buf_size))) goto fail; } POP_AND_PUSH( VALUE_TYPE_V128, - push_type[opcode - SIMD_i8x16_extract_lane_s]); + push_type[opcode1 - SIMD_i8x16_extract_lane_s]); break; } @@ -9511,7 +9372,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, read_leb_uint32(p, p_end, align); /* align */ if (!check_simd_memory_access_align( - opcode, align, error_buf, error_buf_size)) { + opcode1, align, error_buf, error_buf_size)) { goto fail; } @@ -9519,14 +9380,14 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, CHECK_BUF(p, p_end, 1); lane = read_uint8(p); - if (!check_simd_access_lane(opcode, lane, error_buf, + if (!check_simd_access_lane(opcode1, lane, error_buf, error_buf_size)) { goto fail; } POP_V128(); POP_I32(); - if (opcode < SIMD_v128_store8_lane) { + if (opcode1 < SIMD_v128_store8_lane) { PUSH_V128(); } #if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0 @@ -9542,7 +9403,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, read_leb_uint32(p, p_end, align); /* align */ if (!check_simd_memory_access_align( - opcode, align, error_buf, error_buf_size)) { + opcode1, align, error_buf, error_buf_size)) { goto fail; } @@ -9899,7 +9760,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, snprintf(error_buf, error_buf_size, "WASM module load failed: " "invalid opcode 0xfd %02x.", - opcode); + opcode1); } goto fail; } @@ -9912,15 +9773,18 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, #if WASM_ENABLE_SHARED_MEMORY != 0 case WASM_OP_ATOMIC_PREFIX: { - opcode = read_uint8(p); + uint32 opcode1; + + CHECK_BUF(p, p_end, 1); + opcode1 = read_uint8(p); #if WASM_ENABLE_FAST_INTERP != 0 - emit_byte(loader_ctx, opcode); + emit_byte(loader_ctx, opcode1); #endif - if (opcode != WASM_OP_ATOMIC_FENCE) { + if (opcode1 != WASM_OP_ATOMIC_FENCE) { CHECK_MEMORY(); read_leb_uint32(p, p_end, align); /* align */ read_leb_uint32(p, p_end, mem_offset); /* offset */ - if (!check_memory_align_equal(opcode, align, error_buf, + if (!check_memory_align_equal(opcode1, align, error_buf, error_buf_size)) { goto fail; } @@ -9931,7 +9795,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, #if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0 func->has_memory_operations = true; #endif - switch (opcode) { + switch (opcode1) { case WASM_OP_ATOMIC_NOTIFY: POP2_AND_PUSH(VALUE_TYPE_I32, VALUE_TYPE_I32); break; @@ -10047,7 +9911,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, default: set_error_buf_v(error_buf, error_buf_size, "%s %02x %02x", "unsupported opcode", - 0xfe, opcode); + 0xfe, opcode1); goto fail; } break; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_loader.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_loader.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_loader.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_loader.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_mini_loader.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_mini_loader.c similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_mini_loader.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_mini_loader.c index aa5e18f6a8f..47ec549eedb 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_mini_loader.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_mini_loader.c @@ -1843,7 +1843,7 @@ init_llvm_jit_functions_stage1(WASMModule *module, char *error_buf, if (module->function_count == 0) return true; -#if WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_LLVM_JIT != 0 +#if WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_LAZY_JIT != 0 if (os_mutex_init(&module->tierup_wait_lock) != 0) { set_error_buf(error_buf, error_buf_size, "init jit tierup lock failed"); return false; @@ -1876,6 +1876,8 @@ init_llvm_jit_functions_stage1(WASMModule *module, char *error_buf, option.is_jit_mode = true; option.opt_level = llvm_jit_options.opt_level; option.size_level = llvm_jit_options.size_level; + option.segue_flags = llvm_jit_options.segue_flags; + option.linux_perf_support = llvm_jit_options.linux_perf_support; #if WASM_ENABLE_BULK_MEMORY != 0 option.enable_bulk_memory = true; @@ -3936,6 +3938,7 @@ wasm_loader_pop_frame_ref(WASMLoaderContext *ctx, uint8 type, char *error_buf, return true; } +#if WASM_ENABLE_FAST_INTERP == 0 static bool wasm_loader_push_pop_frame_ref(WASMLoaderContext *ctx, uint8 pop_cnt, uint8 type_push, uint8 type_pop, char *error_buf, @@ -3950,6 +3953,7 @@ wasm_loader_push_pop_frame_ref(WASMLoaderContext *ctx, uint8 pop_cnt, return false; return true; } +#endif static bool wasm_loader_push_frame_csp(WASMLoaderContext *ctx, uint8 label_type, @@ -4006,21 +4010,27 @@ wasm_loader_pop_frame_csp(WASMLoaderContext *ctx, char *error_buf, LOG_OP("\ndelete last op\n"); \ } while (0) #else /* else of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */ +#if UINTPTR_MAX == UINT64_MAX #define emit_label(opcode) \ do { \ int32 offset = \ (int32)((uint8 *)handle_table[opcode] - (uint8 *)handle_table[0]); \ - if (!(offset >= INT16_MIN && offset < INT16_MAX)) { \ - set_error_buf(error_buf, error_buf_size, \ - "pre-compiled label offset out of range"); \ - goto fail; \ - } \ - wasm_loader_emit_int16(loader_ctx, offset); \ + /* emit int32 relative offset in 64-bit target */ \ + wasm_loader_emit_uint32(loader_ctx, offset); \ LOG_OP("\nemit_op [%02x]\t", opcode); \ } while (0) +#else +#define emit_label(opcode) \ + do { \ + uint32 label_addr = (uint32)(uintptr_t)handle_table[opcode]; \ + /* emit uint32 label address in 32-bit target */ \ + wasm_loader_emit_uint32(loader_ctx, label_addr); \ + LOG_OP("\nemit_op [%02x]\t", opcode); \ + } while (0) +#endif #define skip_label() \ do { \ - wasm_loader_emit_backspace(loader_ctx, sizeof(int16)); \ + wasm_loader_emit_backspace(loader_ctx, sizeof(int32)); \ LOG_OP("\ndelete last op\n"); \ } while (0) #endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */ @@ -4348,13 +4358,6 @@ preserve_referenced_local(WASMLoaderContext *loader_ctx, uint8 opcode, } return true; - -#if WASM_ENABLE_LABELS_AS_VALUES != 0 -#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 -fail: - return false; -#endif -#endif } static bool @@ -4607,25 +4610,6 @@ wasm_loader_pop_frame_offset(WASMLoaderContext *ctx, uint8 type, return true; } -static bool -wasm_loader_push_pop_frame_offset(WASMLoaderContext *ctx, uint8 pop_cnt, - uint8 type_push, uint8 type_pop, - bool disable_emit, int16 operand_offset, - char *error_buf, uint32 error_buf_size) -{ - for (int i = 0; i < pop_cnt; i++) { - if (!wasm_loader_pop_frame_offset(ctx, type_pop, error_buf, - error_buf_size)) - return false; - } - if (!wasm_loader_push_frame_offset(ctx, type_push, disable_emit, - operand_offset, error_buf, - error_buf_size)) - return false; - - return true; -} - static bool wasm_loader_push_frame_ref_offset(WASMLoaderContext *ctx, uint8 type, bool disable_emit, int16 operand_offset, @@ -4659,12 +4643,24 @@ wasm_loader_push_pop_frame_ref_offset(WASMLoaderContext *ctx, uint8 pop_cnt, bool disable_emit, int16 operand_offset, char *error_buf, uint32 error_buf_size) { - if (!wasm_loader_push_pop_frame_offset(ctx, pop_cnt, type_push, type_pop, - disable_emit, operand_offset, - error_buf, error_buf_size)) + uint8 i; + + for (i = 0; i < pop_cnt; i++) { + if (!wasm_loader_pop_frame_offset(ctx, type_pop, error_buf, + error_buf_size)) + return false; + + if (!wasm_loader_pop_frame_ref(ctx, type_pop, error_buf, + error_buf_size)) + return false; + } + + if (!wasm_loader_push_frame_offset(ctx, type_push, disable_emit, + operand_offset, error_buf, + error_buf_size)) return false; - if (!wasm_loader_push_pop_frame_ref(ctx, pop_cnt, type_push, type_pop, - error_buf, error_buf_size)) + + if (!wasm_loader_push_frame_ref(ctx, type_push, error_buf, error_buf_size)) return false; return true; @@ -5631,10 +5627,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, } #if WASM_ENABLE_FAST_INTERP != 0 - if (opcode == WASM_OP_BLOCK) { - skip_label(); - } - else if (opcode == WASM_OP_LOOP) { + if (opcode == WASM_OP_BLOCK || opcode == WASM_OP_LOOP) { skip_label(); if (BLOCK_HAS_PARAM(block_type)) { /* Make sure params are in dynamic space */ @@ -5642,8 +5635,10 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, loader_ctx, false, error_buf, error_buf_size)) goto fail; } - (loader_ctx->frame_csp - 1)->code_compiled = - loader_ctx->p_code_compiled; + if (opcode == WASM_OP_LOOP) { + (loader_ctx->frame_csp - 1)->code_compiled = + loader_ctx->p_code_compiled; + } } else if (opcode == WASM_OP_IF) { /* If block has parameters, we should make sure they are in @@ -6104,7 +6099,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, && !cur_block->is_stack_polymorphic)); if (available_stack_cell > 0) { - if (is_32bit_type(*(loader_ctx->frame_ref - 1))) { + if (is_32bit_type(*(loader_ctx->frame_ref - 1)) + || *(loader_ctx->frame_ref - 1) == VALUE_TYPE_ANY) { loader_ctx->frame_ref--; loader_ctx->stack_cell_num--; #if WASM_ENABLE_FAST_INTERP != 0 @@ -6150,6 +6146,9 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, uint8 ref_type; BranchBlock *cur_block = loader_ctx->frame_csp - 1; int32 available_stack_cell; +#if WASM_ENABLE_FAST_INTERP != 0 + uint8 *p_code_compiled_tmp = loader_ctx->p_code_compiled; +#endif POP_I32(); @@ -6172,26 +6171,26 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, #if WASM_ENABLE_FAST_INTERP != 0 if (loader_ctx->p_code_compiled) { uint8 opcode_tmp = WASM_OP_SELECT_64; - uint8 *p_code_compiled_tmp = - loader_ctx->p_code_compiled - 2; #if WASM_ENABLE_LABELS_AS_VALUES != 0 #if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 *(void **)(p_code_compiled_tmp - sizeof(void *)) = handle_table[opcode_tmp]; #else +#if UINTPTR_MAX == UINT64_MAX + /* emit int32 relative offset in 64-bit target + */ int32 offset = (int32)((uint8 *)handle_table[opcode_tmp] - (uint8 *)handle_table[0]); - if (!(offset >= INT16_MIN - && offset < INT16_MAX)) { - set_error_buf(error_buf, error_buf_size, - "pre-compiled label offset " - "out of range"); - goto fail; - } - *(int16 *)(p_code_compiled_tmp - - sizeof(int16)) = (int16)offset; + *(int32 *)(p_code_compiled_tmp + - sizeof(int32)) = offset; +#else + /* emit uint32 label address in 32-bit target */ + *(uint32 *)(p_code_compiled_tmp + - sizeof(uint32)) = + (uint32)(uintptr_t)handle_table[opcode_tmp]; +#endif #endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */ #else /* else of WASM_ENABLE_LABELS_AS_VALUES */ #if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 @@ -6232,9 +6231,13 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, case WASM_OP_SELECT_T: { uint8 vec_len, ref_type; +#if WASM_ENABLE_FAST_INTERP != 0 + uint8 *p_code_compiled_tmp = loader_ctx->p_code_compiled; +#endif read_leb_uint32(p, p_end, vec_len); - if (!vec_len) { + if (vec_len != 1) { + /* typed select must have exactly one result */ set_error_buf(error_buf, error_buf_size, "invalid result arity"); goto fail; @@ -6253,8 +6256,6 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, #if WASM_ENABLE_FAST_INTERP != 0 if (loader_ctx->p_code_compiled) { uint8 opcode_tmp = WASM_OP_SELECT; - uint8 *p_code_compiled_tmp = - loader_ctx->p_code_compiled - 2; if (ref_type == VALUE_TYPE_F64 || ref_type == VALUE_TYPE_I64) @@ -6265,15 +6266,16 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, *(void **)(p_code_compiled_tmp - sizeof(void *)) = handle_table[opcode_tmp]; #else +#if UINTPTR_MAX == UINT64_MAX + /* emit int32 relative offset in 64-bit target */ int32 offset = (int32)((uint8 *)handle_table[opcode_tmp] - (uint8 *)handle_table[0]); - if (!(offset >= INT16_MIN && offset < INT16_MAX)) { - set_error_buf(error_buf, error_buf_size, - "pre-compiled label offset out of range"); - goto fail; - } - *(int16 *)(p_code_compiled_tmp - sizeof(int16)) = - (int16)offset; + *(int32 *)(p_code_compiled_tmp - sizeof(int32)) = offset; +#else + /* emit uint32 label address in 32-bit target */ + *(uint32 *)(p_code_compiled_tmp - sizeof(uint32)) = + (uint32)(uintptr_t)handle_table[opcode_tmp]; +#endif #endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */ #else /* else of WASM_ENABLE_LABELS_AS_VALUES */ #if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_opcode.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_opcode.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_opcode.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_opcode.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_runtime.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_runtime.c similarity index 90% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_runtime.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_runtime.c index 29365024d9d..205c6d4b6fb 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_runtime.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_runtime.c @@ -10,6 +10,7 @@ #include "bh_log.h" #include "mem_alloc.h" #include "../common/wasm_runtime_common.h" +#include "../common/wasm_memory.h" #if WASM_ENABLE_SHARED_MEMORY != 0 #include "../common/wasm_shared_memory.h" #endif @@ -51,11 +52,15 @@ set_error_buf_v(char *error_buf, uint32 error_buf_size, const char *format, ...) } WASMModule * -wasm_load(uint8 *buf, uint32 size, char *error_buf, uint32 error_buf_size) +wasm_load(uint8 *buf, uint32 size, +#if WASM_ENABLE_MULTI_MODULE != 0 + bool main_module, +#endif + char *error_buf, uint32 error_buf_size) { return wasm_loader_load(buf, size, #if WASM_ENABLE_MULTI_MODULE != 0 - true, + main_module, #endif error_buf, error_buf_size); } @@ -122,11 +127,8 @@ memories_deinstantiate(WASMModuleInstance *module_inst, } #endif #if WASM_ENABLE_SHARED_MEMORY != 0 - if (memories[i]->is_shared) { - int32 ref_count = shared_memory_dec_reference( - (WASMModuleCommon *)module_inst->module); - bh_assert(ref_count >= 0); - + if (shared_memory_is_shared(memories[i])) { + uint32 ref_count = shared_memory_dec_reference(memories[i]); /* if the reference count is not zero, don't free the memory */ if (ref_count > 0) @@ -159,13 +161,14 @@ memories_deinstantiate(WASMModuleInstance *module_inst, } static WASMMemoryInstance * -memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory, +memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent, + WASMMemoryInstance *memory, uint32 memory_idx, uint32 num_bytes_per_page, uint32 init_page_count, uint32 max_page_count, uint32 heap_size, uint32 flags, char *error_buf, uint32 error_buf_size) { WASMModule *module = module_inst->module; - uint64 memory_data_size; + uint64 memory_data_size, max_memory_data_size; uint32 heap_offset = num_bytes_per_page * init_page_count; uint32 inc_page_count, aux_heap_base, global_idx; uint32 bytes_of_last_page, bytes_to_page_end; @@ -180,22 +183,11 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory, bool is_shared_memory = flags & 0x02 ? true : false; /* shared memory */ - if (is_shared_memory) { - WASMSharedMemNode *node = wasm_module_get_shared_memory( - (WASMModuleCommon *)module_inst->module); - /* If the memory of this module has been instantiated, - return the memory instance directly */ - if (node) { - uint32 ref_count; - ref_count = shared_memory_inc_reference( - (WASMModuleCommon *)module_inst->module); - bh_assert(ref_count > 0); - memory = (WASMMemoryInstance *)shared_memory_get_memory_inst(node); - bh_assert(memory); - - (void)ref_count; - return memory; - } + if (is_shared_memory && parent != NULL) { + bh_assert(parent->memory_count > memory_idx); + memory = parent->memories[memory_idx]; + shared_memory_inc_reference(memory); + return memory; } #endif /* end of WASM_ENABLE_SHARED_MEMORY */ @@ -215,7 +207,7 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory, if (num_bytes_per_page < heap_size) { set_error_buf(error_buf, error_buf_size, "failed to insert app heap into linear memory, " - "try using `--heap_size=0` option"); + "try using `--heap-size=0` option"); return NULL; } } @@ -274,7 +266,7 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory, if (init_page_count > DEFAULT_MAX_PAGES) { set_error_buf(error_buf, error_buf_size, "failed to insert app heap into linear memory, " - "try using `--heap_size=0` option"); + "try using `--heap-size=0` option"); return NULL; } else if (init_page_count == DEFAULT_MAX_PAGES) { @@ -284,6 +276,12 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory, if (max_page_count > DEFAULT_MAX_PAGES) max_page_count = DEFAULT_MAX_PAGES; } + else { /* heap_size == 0 */ + if (init_page_count == DEFAULT_MAX_PAGES) { + num_bytes_per_page = UINT32_MAX; + init_page_count = max_page_count = 1; + } + } LOG_VERBOSE("Memory instantiate:"); LOG_VERBOSE(" page bytes: %u, init pages: %u, max pages: %u", @@ -291,22 +289,33 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory, LOG_VERBOSE(" heap offset: %u, heap size: %d\n", heap_offset, heap_size); memory_data_size = (uint64)num_bytes_per_page * init_page_count; + max_memory_data_size = (uint64)num_bytes_per_page * max_page_count; + bh_assert(memory_data_size <= UINT32_MAX); + bh_assert(max_memory_data_size <= 4 * (uint64)BH_GB); + (void)max_memory_data_size; + + bh_assert(memory != NULL); +#ifndef OS_ENABLE_HW_BOUND_CHECK #if WASM_ENABLE_SHARED_MEMORY != 0 if (is_shared_memory) { - /* Allocate max page for shared memory */ - memory_data_size = (uint64)num_bytes_per_page * max_page_count; + /* Allocate maximum memory size when memory is shared */ + if (max_memory_data_size > 0 + && !(memory->memory_data = runtime_malloc( + max_memory_data_size, error_buf, error_buf_size))) { + goto fail1; + } } + else #endif - bh_assert(memory_data_size <= 4 * (uint64)BH_GB); - - bh_assert(memory != NULL); -#ifndef OS_ENABLE_HW_BOUND_CHECK - if (memory_data_size > 0 - && !(memory->memory_data = - runtime_malloc(memory_data_size, error_buf, error_buf_size))) { - goto fail1; + { + /* Allocate initial memory size when memory is not shared */ + if (memory_data_size > 0 + && !(memory->memory_data = runtime_malloc( + memory_data_size, error_buf, error_buf_size))) { + goto fail1; + } } -#else +#else /* else of OS_ENABLE_HW_BOUND_CHECK */ memory_data_size = (memory_data_size + page_size - 1) & ~(page_size - 1); /* Totally 8G is mapped, the opcode load/store address range is 0 to 8G: @@ -315,14 +324,16 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory, * so the range of ea is 0 to 8G */ if (!(memory->memory_data = mapped_mem = - os_mmap(NULL, map_size, MMAP_PROT_NONE, MMAP_MAP_NONE))) { + os_mmap(NULL, map_size, MMAP_PROT_NONE, MMAP_MAP_NONE, + os_get_invalid_handle()))) { set_error_buf(error_buf, error_buf_size, "mmap memory failed"); goto fail1; } #ifdef BH_PLATFORM_WINDOWS - if (!os_mem_commit(mapped_mem, memory_data_size, - MMAP_PROT_READ | MMAP_PROT_WRITE)) { + if (memory_data_size > 0 + && !os_mem_commit(mapped_mem, memory_data_size, + MMAP_PROT_READ | MMAP_PROT_WRITE)) { set_error_buf(error_buf, error_buf_size, "commit memory failed"); os_munmap(mapped_mem, map_size); goto fail1; @@ -335,12 +346,13 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory, set_error_buf(error_buf, error_buf_size, "mprotect memory failed"); goto fail2; } + /* Newly allocated pages are filled with zero by the OS, we don't fill it * again here */ -#endif /* end of OS_ENABLE_HW_BOUND_CHECK */ if (memory_data_size > UINT32_MAX) - memory_data_size = (uint32)memory_data_size; + memory_data_size = UINT32_MAX; +#endif /* end of OS_ENABLE_HW_BOUND_CHECK */ memory->module_type = Wasm_Module_Bytecode; memory->num_bytes_per_page = num_bytes_per_page; @@ -368,44 +380,20 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory, } } -#if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0 if (memory_data_size > 0) { -#if UINTPTR_MAX == UINT64_MAX - memory->mem_bound_check_1byte.u64 = memory_data_size - 1; - memory->mem_bound_check_2bytes.u64 = memory_data_size - 2; - memory->mem_bound_check_4bytes.u64 = memory_data_size - 4; - memory->mem_bound_check_8bytes.u64 = memory_data_size - 8; - memory->mem_bound_check_16bytes.u64 = memory_data_size - 16; -#else - memory->mem_bound_check_1byte.u32[0] = (uint32)memory_data_size - 1; - memory->mem_bound_check_2bytes.u32[0] = (uint32)memory_data_size - 2; - memory->mem_bound_check_4bytes.u32[0] = (uint32)memory_data_size - 4; - memory->mem_bound_check_8bytes.u32[0] = (uint32)memory_data_size - 8; - memory->mem_bound_check_16bytes.u32[0] = (uint32)memory_data_size - 16; -#endif + wasm_runtime_set_mem_bound_check_bytes(memory, memory_data_size); } -#endif #if WASM_ENABLE_SHARED_MEMORY != 0 if (is_shared_memory) { - memory->is_shared = true; - if (!shared_memory_set_memory_inst( - (WASMModuleCommon *)module_inst->module, - (WASMMemoryInstanceCommon *)memory)) { - set_error_buf(error_buf, error_buf_size, "allocate memory failed"); - goto fail4; - } + memory->is_shared_memory = 1; + memory->ref_count = 1; } #endif LOG_VERBOSE("Memory instantiate success."); return memory; -#if WASM_ENABLE_SHARED_MEMORY != 0 -fail4: - if (heap_size > 0) - mem_allocator_destroy(memory->heap_handle); -#endif fail3: if (heap_size > 0) wasm_runtime_free(memory->heap_handle); @@ -428,7 +416,8 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMMemoryInstance *memory, */ static WASMMemoryInstance ** memories_instantiate(const WASMModule *module, WASMModuleInstance *module_inst, - uint32 heap_size, char *error_buf, uint32 error_buf_size) + WASMModuleInstance *parent, uint32 heap_size, + char *error_buf, uint32 error_buf_size) { WASMImport *import; uint32 mem_index = 0, i, @@ -474,26 +463,29 @@ memories_instantiate(const WASMModule *module, WASMModuleInstance *module_inst, else #endif { - if (!(memories[mem_index++] = memory_instantiate( - module_inst, memory, num_bytes_per_page, init_page_count, - max_page_count, actual_heap_size, flags, error_buf, - error_buf_size))) { + if (!(memories[mem_index] = memory_instantiate( + module_inst, parent, memory, mem_index, + num_bytes_per_page, init_page_count, max_page_count, + actual_heap_size, flags, error_buf, error_buf_size))) { memories_deinstantiate(module_inst, memories, memory_count); return NULL; } + mem_index++; } } /* instantiate memories from memory section */ for (i = 0; i < module->memory_count; i++, memory++) { - if (!(memories[mem_index++] = memory_instantiate( - module_inst, memory, module->memories[i].num_bytes_per_page, + if (!(memories[mem_index] = memory_instantiate( + module_inst, parent, memory, mem_index, + module->memories[i].num_bytes_per_page, module->memories[i].init_page_count, module->memories[i].max_page_count, heap_size, module->memories[i].flags, error_buf, error_buf_size))) { memories_deinstantiate(module_inst, memories, memory_count); return NULL; } + mem_index++; } bh_assert(mem_index == memory_count); @@ -1070,7 +1062,8 @@ execute_post_instantiate_functions(WASMModuleInstance *module_inst, wasm functions, and ensure that the exec_env's module inst is the correct one. */ module_inst_main = exec_env_main->module_inst; - exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst; + wasm_exec_env_set_module_inst(exec_env, + (WASMModuleInstanceCommon *)module_inst); } else { /* Try using the existing exec_env */ @@ -1095,7 +1088,8 @@ execute_post_instantiate_functions(WASMModuleInstance *module_inst, module inst to ensure that the exec_env's module inst is the correct one. */ module_inst_main = exec_env->module_inst; - exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst; + wasm_exec_env_set_module_inst( + exec_env, (WASMModuleInstanceCommon *)module_inst); } } @@ -1104,10 +1098,14 @@ execute_post_instantiate_functions(WASMModuleInstance *module_inst, goto fail; } +#if WASM_ENABLE_LIBC_WASI != 0 if (initialize_func && !wasm_call_function(exec_env, initialize_func, 0, NULL)) { goto fail; } +#else + (void)initialize_func; +#endif if (post_inst_func && !wasm_call_function(exec_env, post_inst_func, 0, NULL)) { @@ -1124,12 +1122,12 @@ execute_post_instantiate_functions(WASMModuleInstance *module_inst, fail: if (is_sub_inst) { /* Restore the parent exec_env's module inst */ - exec_env_main->module_inst = module_inst_main; + wasm_exec_env_restore_module_inst(exec_env_main, module_inst_main); } else { if (module_inst_main) /* Restore the existing exec_env's module inst */ - exec_env->module_inst = module_inst_main; + wasm_exec_env_restore_module_inst(exec_env, module_inst_main); if (exec_env_created) wasm_exec_env_destroy(exec_env_created); } @@ -1198,7 +1196,8 @@ execute_malloc_function(WASMModuleInstance *module_inst, WASMExecEnv *exec_env, module inst to ensure that the exec_env's module inst is the correct one. */ module_inst_old = exec_env->module_inst; - exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst; + wasm_exec_env_set_module_inst( + exec_env, (WASMModuleInstanceCommon *)module_inst); } } @@ -1209,7 +1208,7 @@ execute_malloc_function(WASMModuleInstance *module_inst, WASMExecEnv *exec_env, if (module_inst_old) /* Restore the existing exec_env's module inst */ - exec_env->module_inst = module_inst_old; + wasm_exec_env_restore_module_inst(exec_env, module_inst_old); if (exec_env_created) wasm_exec_env_destroy(exec_env_created); @@ -1265,7 +1264,8 @@ execute_free_function(WASMModuleInstance *module_inst, WASMExecEnv *exec_env, module inst to ensure that the exec_env's module inst is the correct one. */ module_inst_old = exec_env->module_inst; - exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst; + wasm_exec_env_set_module_inst( + exec_env, (WASMModuleInstanceCommon *)module_inst); } } @@ -1273,7 +1273,7 @@ execute_free_function(WASMModuleInstance *module_inst, WASMExecEnv *exec_env, if (module_inst_old) /* Restore the existing exec_env's module inst */ - exec_env->module_inst = module_inst_old; + wasm_exec_env_restore_module_inst(exec_env, module_inst_old); if (exec_env_created) wasm_exec_env_destroy(exec_env_created); @@ -1281,78 +1281,6 @@ execute_free_function(WASMModuleInstance *module_inst, WASMExecEnv *exec_env, return ret; } -#if WASM_ENABLE_MULTI_MODULE != 0 -static bool -sub_module_instantiate(WASMModule *module, WASMModuleInstance *module_inst, - uint32 stack_size, uint32 heap_size, char *error_buf, - uint32 error_buf_size) -{ - bh_list *sub_module_inst_list = module_inst->e->sub_module_inst_list; - WASMRegisteredModule *sub_module_list_node = - bh_list_first_elem(module->import_module_list); - - while (sub_module_list_node) { - WASMSubModInstNode *sub_module_inst_list_node = NULL; - WASMModule *sub_module = (WASMModule *)sub_module_list_node->module; - WASMModuleInstance *sub_module_inst = NULL; - - sub_module_inst = - wasm_instantiate(sub_module, false, NULL, stack_size, heap_size, - error_buf, error_buf_size); - if (!sub_module_inst) { - LOG_DEBUG("instantiate %s failed", - sub_module_list_node->module_name); - goto failed; - } - - sub_module_inst_list_node = runtime_malloc(sizeof(WASMSubModInstNode), - error_buf, error_buf_size); - if (!sub_module_inst_list_node) { - LOG_DEBUG("Malloc WASMSubModInstNode failed, SZ:%d", - sizeof(WASMSubModInstNode)); - goto failed; - } - - sub_module_inst_list_node->module_inst = sub_module_inst; - sub_module_inst_list_node->module_name = - sub_module_list_node->module_name; - bh_list_status ret = - bh_list_insert(sub_module_inst_list, sub_module_inst_list_node); - bh_assert(BH_LIST_SUCCESS == ret); - (void)ret; - - sub_module_list_node = bh_list_elem_next(sub_module_list_node); - - continue; - failed: - if (sub_module_inst_list_node) { - bh_list_remove(sub_module_inst_list, sub_module_inst_list_node); - wasm_runtime_free(sub_module_inst_list_node); - } - - if (sub_module_inst) - wasm_deinstantiate(sub_module_inst, false); - return false; - } - - return true; -} - -static void -sub_module_deinstantiate(WASMModuleInstance *module_inst) -{ - bh_list *list = module_inst->e->sub_module_inst_list; - WASMSubModInstNode *node = bh_list_first_elem(list); - while (node) { - WASMSubModInstNode *next_node = bh_list_elem_next(node); - bh_list_remove(list, node); - wasm_deinstantiate(node->module_inst, false); - wasm_runtime_free(node); - node = next_node; - } -} -#endif - static bool check_linked_symbol(WASMModuleInstance *module_inst, char *error_buf, uint32 error_buf_size) @@ -1642,7 +1570,7 @@ wasm_set_running_mode(WASMModuleInstance *module_inst, RunningMode running_mode) * Instantiate module */ WASMModuleInstance * -wasm_instantiate(WASMModule *module, bool is_sub_inst, +wasm_instantiate(WASMModule *module, WASMModuleInstance *parent, WASMExecEnv *exec_env_main, uint32 stack_size, uint32 heap_size, char *error_buf, uint32 error_buf_size) { @@ -1659,6 +1587,7 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst, #if WASM_ENABLE_MULTI_MODULE != 0 bool ret = false; #endif + const bool is_sub_inst = parent != NULL; if (!module) return NULL; @@ -1728,14 +1657,40 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst, #if WASM_ENABLE_MULTI_MODULE != 0 module_inst->e->sub_module_inst_list = &module_inst->e->sub_module_inst_list_head; - ret = sub_module_instantiate(module, module_inst, stack_size, heap_size, - error_buf, error_buf_size); + ret = wasm_runtime_sub_module_instantiate( + (WASMModuleCommon *)module, (WASMModuleInstanceCommon *)module_inst, + stack_size, heap_size, error_buf, error_buf_size); if (!ret) { LOG_DEBUG("build a sub module list failed"); goto fail; } #endif +#if WASM_ENABLE_BULK_MEMORY != 0 + if (module->data_seg_count > 0) { + module_inst->e->common.data_dropped = + bh_bitmap_new(0, module->data_seg_count); + if (module_inst->e->common.data_dropped == NULL) { + LOG_DEBUG("failed to allocate bitmaps"); + set_error_buf(error_buf, error_buf_size, + "failed to allocate bitmaps"); + goto fail; + } + } +#endif +#if WASM_ENABLE_REF_TYPES != 0 + if (module->table_seg_count > 0) { + module_inst->e->common.elem_dropped = + bh_bitmap_new(0, module->table_seg_count); + if (module_inst->e->common.elem_dropped == NULL) { + LOG_DEBUG("failed to allocate bitmaps"); + set_error_buf(error_buf, error_buf_size, + "failed to allocate bitmaps"); + goto fail; + } + } +#endif + #if WASM_ENABLE_DUMP_CALL_STACK != 0 if (!(module_inst->frames = runtime_malloc((uint64)sizeof(Vector), error_buf, error_buf_size))) { @@ -1777,8 +1732,9 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst, /* Instantiate memories/tables/functions */ if ((module_inst->memory_count > 0 - && !(module_inst->memories = memories_instantiate( - module, module_inst, heap_size, error_buf, error_buf_size))) + && !(module_inst->memories = + memories_instantiate(module, module_inst, parent, heap_size, + error_buf, error_buf_size))) || (module_inst->table_count > 0 && !(module_inst->tables = tables_instantiate(module, module_inst, first_table, @@ -1853,20 +1809,25 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst, for (i = 0; i < module->data_seg_count; i++) { WASMMemoryInstance *memory = NULL; uint8 *memory_data = NULL; - uint32 memory_size = 0; + uint64 memory_size = 0; WASMDataSeg *data_seg = module->data_segments[i]; #if WASM_ENABLE_BULK_MEMORY != 0 if (data_seg->is_passive) continue; #endif + if (is_sub_inst) + /* Ignore setting memory init data if the memory has been + initialized */ + continue; /* has check it in loader */ memory = module_inst->memories[data_seg->memory_index]; bh_assert(memory); memory_data = memory->memory_data; - memory_size = memory->num_bytes_per_page * memory->cur_page_count; + memory_size = + (uint64)memory->num_bytes_per_page * memory->cur_page_count; bh_assert(memory_data || memory_size == 0); bh_assert(data_seg->base_offset.init_expr_type @@ -1912,7 +1873,7 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst, /* check offset + length(could be zero) */ length = data_seg->data_length; - if (base_offset + length > memory_size) { + if ((uint64)base_offset + length > memory_size) { LOG_DEBUG("base_offset(%d) + length(%d) > memory_size(%d)", base_offset, length, memory_size); #if WASM_ENABLE_REF_TYPES != 0 @@ -1926,8 +1887,9 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst, } if (memory_data) { - bh_memcpy_s(memory_data + base_offset, memory_size - base_offset, - data_seg->data, length); + bh_memcpy_s(memory_data + base_offset, + (uint32)memory_size - base_offset, data_seg->data, + length); } } @@ -2097,16 +2059,6 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst, } #endif -#if WASM_ENABLE_WASI_NN != 0 - if (!is_sub_inst) { - if (!(module_inst->e->wasi_nn_ctx = wasi_nn_initialize())) { - set_error_buf(error_buf, error_buf_size, - "wasi nn initialization failed"); - goto fail; - } - } -#endif - #if WASM_ENABLE_DEBUG_INTERP != 0 if (!is_sub_inst) { /* Add module instance into module's instance list */ @@ -2219,17 +2171,8 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst) #endif #if WASM_ENABLE_MULTI_MODULE != 0 - sub_module_deinstantiate(module_inst); -#endif - -#if WASM_ENABLE_LIBC_WASI != 0 - /* Destroy wasi resource before freeing app heap, since some fields of - wasi contex are allocated from app heap, and if app heap is freed, - these fields will be set to NULL, we cannot free their internal data - which may allocated from global heap. */ - /* Only destroy wasi ctx in the main module instance */ - if (!is_sub_inst) - wasm_runtime_destroy_wasi((WASMModuleInstanceCommon *)module_inst); + wasm_runtime_sub_module_deinstantiate( + (WASMModuleInstanceCommon *)module_inst); #endif if (module_inst->memory_count > 0) @@ -2261,15 +2204,21 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst) } #endif - if (module_inst->e->c_api_func_imports) - wasm_runtime_free(module_inst->e->c_api_func_imports); + if (module_inst->e->common.c_api_func_imports) + wasm_runtime_free(module_inst->e->common.c_api_func_imports); -#if WASM_ENABLE_WASI_NN != 0 if (!is_sub_inst) { - WASINNContext *wasi_nn_ctx = module_inst->e->wasi_nn_ctx; - if (wasi_nn_ctx) - wasi_nn_destroy(wasi_nn_ctx); +#if WASM_ENABLE_WASI_NN != 0 + wasi_nn_destroy(module_inst); +#endif + wasm_native_call_context_dtors((WASMModuleInstanceCommon *)module_inst); } + +#if WASM_ENABLE_BULK_MEMORY != 0 + bh_bitmap_delete(module_inst->e->common.data_dropped); +#endif +#if WASM_ENABLE_REF_TYPES != 0 + bh_bitmap_delete(module_inst->e->common.elem_dropped); #endif wasm_runtime_free(module_inst); @@ -2431,6 +2380,9 @@ wasm_call_function(WASMExecEnv *exec_env, WASMFunctionInstance *function, /* set thread handle and stack boundary */ wasm_exec_env_set_thread_info(exec_env); + /* set exec env so it can be later retrieved from instance */ + module_inst->e->common.cur_exec_env = exec_env; + interp_call_wasm(module_inst, exec_env, function, argc, argv); return !wasm_copy_exception(module_inst, NULL); } @@ -2467,14 +2419,16 @@ wasm_dump_perf_profiling(const WASMModuleInstance *module_inst) } if (func_name) - os_printf(" func %s, execution time: %.3f ms, execution count: %d " - "times\n", - func_name, - module_inst->e->functions[i].total_exec_time / 1000.0f, - module_inst->e->functions[i].total_exec_cnt); + os_printf( + " func %s, execution time: %.3f ms, execution count: %" PRIu32 + " times\n", + func_name, + module_inst->e->functions[i].total_exec_time / 1000.0f, + module_inst->e->functions[i].total_exec_cnt); else - os_printf(" func %d, execution time: %.3f ms, execution count: %d " - "times\n", + os_printf(" func %" PRIu32 + ", execution time: %.3f ms, execution count: %" PRIu32 + " times\n", i, module_inst->e->functions[i].total_exec_time / 1000.0f, module_inst->e->functions[i].total_exec_cnt); } @@ -2568,15 +2522,20 @@ void wasm_module_free_internal(WASMModuleInstance *module_inst, WASMExecEnv *exec_env, uint32 ptr) { - if (ptr) { - WASMMemoryInstance *memory = wasm_get_default_memory(module_inst); - uint8 *addr; + WASMMemoryInstance *memory = wasm_get_default_memory(module_inst); - if (!memory) { - return; - } + if (!memory) { + return; + } + + if (ptr) { + uint8 *addr = memory->memory_data + ptr; + uint8 *memory_data_end; - addr = memory->memory_data + ptr; + /* memory->memory_data_end may be changed in memory grow */ + SHARED_MEMORY_LOCK(memory); + memory_data_end = memory->memory_data_end; + SHARED_MEMORY_UNLOCK(memory); if (memory->heap_handle && memory->heap_data <= addr && addr < memory->heap_data_end) { @@ -2584,7 +2543,7 @@ wasm_module_free_internal(WASMModuleInstance *module_inst, } else if (module_inst->e->malloc_function && module_inst->e->free_function && memory->memory_data <= addr - && addr < memory->memory_data_end) { + && addr < memory_data_end) { execute_free_function(module_inst, exec_env, module_inst->e->free_function, ptr); } @@ -3011,6 +2970,7 @@ wasm_interp_create_call_stack(struct WASMExecEnv *exec_env) total_len += \ wasm_runtime_dump_line_buf_impl(line_buf, print, &buf, &len); \ if ((!print) && buf && (len == 0)) { \ + exception_unlock(module_inst); \ return total_len; \ } \ } while (0) @@ -3035,6 +2995,7 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf, return 0; } + exception_lock(module_inst); snprintf(line_buf, sizeof(line_buf), "\n"); PRINT_OR_DUMP(); @@ -3043,17 +3004,20 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf, uint32 line_length, i; if (!bh_vector_get(module_inst->frames, n, &frame)) { + exception_unlock(module_inst); return 0; } /* function name not exported, print number instead */ if (frame.func_name_wp == NULL) { - line_length = snprintf(line_buf, sizeof(line_buf), "#%02d $f%d\n", - n, frame.func_index); + line_length = + snprintf(line_buf, sizeof(line_buf), + "#%02" PRIu32 " $f%" PRIu32 "\n", n, frame.func_index); } else { - line_length = snprintf(line_buf, sizeof(line_buf), "#%02d %s\n", n, - frame.func_name_wp); + line_length = + snprintf(line_buf, sizeof(line_buf), "#%02" PRIu32 " %s\n", n, + frame.func_name_wp); } if (line_length >= sizeof(line_buf)) { @@ -3071,6 +3035,7 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf, } snprintf(line_buf, sizeof(line_buf), "\n"); PRINT_OR_DUMP(); + exception_unlock(module_inst); return total_len + 1; } @@ -3124,11 +3089,7 @@ llvm_jit_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 elem_idx, { bool ret; -#if WASM_ENABLE_JIT != 0 - if (Wasm_Module_AoT == exec_env->module_inst->module_type) { - return aot_call_indirect(exec_env, tbl_idx, elem_idx, argc, argv); - } -#endif + bh_assert(exec_env->module_inst->module_type == Wasm_Module_Bytecode); ret = call_indirect(exec_env, tbl_idx, elem_idx, argc, argv, false, 0); #ifdef OS_ENABLE_HW_BOUND_CHECK @@ -3155,11 +3116,7 @@ llvm_jit_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc, char buf[96]; bool ret = false; -#if WASM_ENABLE_JIT != 0 - if (Wasm_Module_AoT == exec_env->module_inst->module_type) { - return aot_invoke_native(exec_env, func_idx, argc, argv); - } -#endif + bh_assert(exec_env->module_inst->module_type == Wasm_Module_Bytecode); module_inst = (WASMModuleInstance *)wasm_runtime_get_module_inst(exec_env); module = module_inst->module; @@ -3172,8 +3129,9 @@ llvm_jit_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc, import_func = &module->import_functions[func_idx].u.function; if (import_func->call_conv_wasm_c_api) { - if (module_inst->e->c_api_func_imports) { - c_api_func_import = module_inst->e->c_api_func_imports + func_idx; + if (module_inst->e->common.c_api_func_imports) { + c_api_func_import = + module_inst->e->common.c_api_func_imports + func_idx; func_ptr = c_api_func_import->func_ptr_linked; } else { @@ -3224,20 +3182,23 @@ llvm_jit_memory_init(WASMModuleInstance *module_inst, uint32 seg_index, { WASMMemoryInstance *memory_inst; WASMModule *module; - uint8 *data = NULL; + uint8 *data; uint8 *maddr; - uint64 seg_len = 0; + uint64 seg_len; -#if WASM_ENABLE_JIT != 0 - if (Wasm_Module_AoT == module_inst->module_type) { - return aot_memory_init(module_inst, seg_index, offset, len, dst); - } -#endif + bh_assert(module_inst->module_type == Wasm_Module_Bytecode); memory_inst = wasm_get_default_memory(module_inst); - module = module_inst->module; - seg_len = module->data_segments[seg_index]->data_length; - data = module->data_segments[seg_index]->data; + + if (bh_bitmap_get_bit(module_inst->e->common.data_dropped, seg_index)) { + seg_len = 0; + data = NULL; + } + else { + module = module_inst->module; + seg_len = module->data_segments[seg_index]->data_length; + data = module->data_segments[seg_index]->data; + } if (!wasm_runtime_validate_app_addr((WASMModuleInstanceCommon *)module_inst, dst, len)) @@ -3251,20 +3212,18 @@ llvm_jit_memory_init(WASMModuleInstance *module_inst, uint32 seg_index, maddr = wasm_runtime_addr_app_to_native( (WASMModuleInstanceCommon *)module_inst, dst); + SHARED_MEMORY_LOCK(memory_inst); bh_memcpy_s(maddr, memory_inst->memory_data_size - dst, data + offset, len); + SHARED_MEMORY_UNLOCK(memory_inst); return true; } bool llvm_jit_data_drop(WASMModuleInstance *module_inst, uint32 seg_index) { -#if WASM_ENABLE_JIT != 0 - if (Wasm_Module_AoT == module_inst->module_type) { - return aot_data_drop(module_inst, seg_index); - } -#endif + bh_assert(module_inst->module_type == Wasm_Module_Bytecode); - module_inst->module->data_segments[seg_index]->data_length = 0; + bh_bitmap_set_bit(module_inst->e->common.data_dropped, seg_index); /* Currently we can't free the dropped data segment as they are stored in wasm bytecode */ return true; @@ -3275,16 +3234,8 @@ llvm_jit_data_drop(WASMModuleInstance *module_inst, uint32 seg_index) void llvm_jit_drop_table_seg(WASMModuleInstance *module_inst, uint32 tbl_seg_idx) { - WASMTableSeg *tbl_segs; - -#if WASM_ENABLE_JIT != 0 - if (Wasm_Module_AoT == module_inst->module_type) { - return aot_drop_table_seg(module_inst, tbl_seg_idx); - } -#endif - - tbl_segs = module_inst->module->table_segments; - tbl_segs[tbl_seg_idx].is_dropped = true; + bh_assert(module_inst->module_type == Wasm_Module_Bytecode); + bh_bitmap_set_bit(module_inst->e->common.elem_dropped, tbl_seg_idx); } void @@ -3295,12 +3246,7 @@ llvm_jit_table_init(WASMModuleInstance *module_inst, uint32 tbl_idx, WASMTableInstance *tbl_inst; WASMTableSeg *tbl_seg; -#if WASM_ENABLE_JIT != 0 - if (Wasm_Module_AoT == module_inst->module_type) { - return aot_table_init(module_inst, tbl_idx, tbl_seg_idx, length, - src_offset, dst_offset); - } -#endif + bh_assert(module_inst->module_type == Wasm_Module_Bytecode); tbl_inst = wasm_get_table_inst(module_inst, tbl_idx); tbl_seg = module_inst->module->table_segments + tbl_seg_idx; @@ -3308,17 +3254,17 @@ llvm_jit_table_init(WASMModuleInstance *module_inst, uint32 tbl_idx, bh_assert(tbl_inst); bh_assert(tbl_seg); - if (!length) { + if (offset_len_out_of_bounds(src_offset, length, tbl_seg->function_count) + || offset_len_out_of_bounds(dst_offset, length, tbl_inst->cur_size)) { + jit_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS); return; } - if (length + src_offset > tbl_seg->function_count - || dst_offset + length > tbl_inst->cur_size) { - jit_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS); + if (!length) { return; } - if (tbl_seg->is_dropped) { + if (bh_bitmap_get_bit(module_inst->e->common.elem_dropped, tbl_seg_idx)) { jit_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS); return; } @@ -3343,21 +3289,16 @@ llvm_jit_table_copy(WASMModuleInstance *module_inst, uint32 src_tbl_idx, WASMTableInstance *src_tbl_inst; WASMTableInstance *dst_tbl_inst; -#if WASM_ENABLE_JIT != 0 - if (Wasm_Module_AoT == module_inst->module_type) { - aot_table_copy(module_inst, src_tbl_idx, dst_tbl_idx, length, - src_offset, dst_offset); - return; - } -#endif + bh_assert(module_inst->module_type == Wasm_Module_Bytecode); src_tbl_inst = wasm_get_table_inst(module_inst, src_tbl_idx); dst_tbl_inst = wasm_get_table_inst(module_inst, dst_tbl_idx); bh_assert(src_tbl_inst); bh_assert(dst_tbl_inst); - if ((uint64)dst_offset + length > dst_tbl_inst->cur_size - || (uint64)src_offset + length > src_tbl_inst->cur_size) { + if (offset_len_out_of_bounds(dst_offset, length, dst_tbl_inst->cur_size) + || offset_len_out_of_bounds(src_offset, length, + src_tbl_inst->cur_size)) { jit_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS); return; } @@ -3379,17 +3320,12 @@ llvm_jit_table_fill(WASMModuleInstance *module_inst, uint32 tbl_idx, { WASMTableInstance *tbl_inst; -#if WASM_ENABLE_JIT != 0 - if (Wasm_Module_AoT == module_inst->module_type) { - aot_table_fill(module_inst, tbl_idx, length, val, data_offset); - return; - } -#endif + bh_assert(module_inst->module_type == Wasm_Module_Bytecode); tbl_inst = wasm_get_table_inst(module_inst, tbl_idx); bh_assert(tbl_inst); - if (data_offset + length > tbl_inst->cur_size) { + if (offset_len_out_of_bounds(data_offset, length, tbl_inst->cur_size)) { jit_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS); return; } @@ -3406,11 +3342,7 @@ llvm_jit_table_grow(WASMModuleInstance *module_inst, uint32 tbl_idx, WASMTableInstance *tbl_inst; uint32 i, orig_size, total_size; -#if WASM_ENABLE_JIT != 0 - if (Wasm_Module_AoT == module_inst->module_type) { - return aot_table_grow(module_inst, tbl_idx, inc_size, init_val); - } -#endif + bh_assert(module_inst->module_type == Wasm_Module_Bytecode); tbl_inst = wasm_get_table_inst(module_inst, tbl_idx); if (!tbl_inst) { @@ -3450,11 +3382,7 @@ llvm_jit_alloc_frame(WASMExecEnv *exec_env, uint32 func_index) WASMInterpFrame *frame; uint32 size; -#if WASM_ENABLE_JIT != 0 - if (Wasm_Module_AoT == exec_env->module_inst->module_type) { - return aot_alloc_frame(exec_env, func_index); - } -#endif + bh_assert(exec_env->module_inst->module_type == Wasm_Module_Bytecode); module_inst = (WASMModuleInstance *)exec_env->module_inst; size = wasm_interp_interp_frame_size(0); @@ -3483,12 +3411,7 @@ llvm_jit_free_frame(WASMExecEnv *exec_env) WASMInterpFrame *frame; WASMInterpFrame *prev_frame; -#if WASM_ENABLE_JIT != 0 - if (Wasm_Module_AoT == exec_env->module_inst->module_type) { - aot_free_frame(exec_env); - return; - } -#endif + bh_assert(exec_env->module_inst->module_type == Wasm_Module_Bytecode); frame = wasm_exec_env_get_cur_frame(exec_env); prev_frame = frame->prev_frame; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_runtime.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_runtime.h similarity index 93% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_runtime.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_runtime.h index 15169433ed8..bb5fdc80bbe 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/interpreter/wasm_runtime.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/interpreter/wasm_runtime.h @@ -7,6 +7,8 @@ #define _WASM_RUNTIME_H #include "wasm.h" +#include "bh_atomic.h" +#include "bh_bitmap.h" #include "bh_hashmap.h" #include "../common/wasm_runtime_common.h" #include "../common/wasm_exec_env.h" @@ -78,8 +80,16 @@ typedef union { struct WASMMemoryInstance { /* Module type */ uint32 module_type; - /* Shared memory flag */ - bool is_shared; + + /* Whether the memory is shared */ + uint8 is_shared_memory; + + /* One byte padding */ + uint8 __padding__; + + /* Reference count of the memory instance: + 0: non-shared memory, > 0: shared memory */ + bh_atomic_16_t ref_count; /* Number bytes per page */ uint32 num_bytes_per_page; @@ -209,8 +219,28 @@ typedef struct CApiFuncImport { void *env_arg; } CApiFuncImport; +/* The common part of WASMModuleInstanceExtra and AOTModuleInstanceExtra */ +typedef struct WASMModuleInstanceExtraCommon { + void *contexts[WASM_MAX_INSTANCE_CONTEXTS]; + CApiFuncImport *c_api_func_imports; + /* pointer to the exec env currently used */ + WASMExecEnv *cur_exec_env; +#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0 + /* Disable bounds checks or not */ + bool disable_bounds_checks; +#endif +#if WASM_ENABLE_BULK_MEMORY != 0 + bh_bitmap *data_dropped; +#endif +#if WASM_ENABLE_REF_TYPES != 0 + bh_bitmap *elem_dropped; +#endif +} WASMModuleInstanceExtraCommon; + /* Extra info of WASM module instance for interpreter/jit mode */ typedef struct WASMModuleInstanceExtra { + WASMModuleInstanceExtraCommon common; + WASMGlobalInstance *globals; WASMFunctionInstance *functions; @@ -222,7 +252,6 @@ typedef struct WASMModuleInstanceExtra { WASMFunctionInstance *free_function; WASMFunctionInstance *retain_function; - CApiFuncImport *c_api_func_imports; RunningMode running_mode; #if WASM_ENABLE_MULTI_MODULE != 0 @@ -241,10 +270,6 @@ typedef struct WASMModuleInstanceExtra { && WASM_ENABLE_LAZY_JIT != 0) WASMModuleInstance *next; #endif - -#if WASM_ENABLE_WASI_NN != 0 - WASINNContext *wasi_nn_ctx; -#endif } WASMModuleInstanceExtra; struct AOTFuncPerfProfInfo; @@ -290,12 +315,8 @@ struct WASMModuleInstance { it denotes `AOTModule *` */ DefPointer(WASMModule *, module); -#if WASM_ENABLE_LIBC_WASI - /* WASI context */ - DefPointer(WASIContext *, wasi_ctx); -#else - DefPointer(void *, wasi_ctx); -#endif + DefPointer(void *, used_to_be_wasi_ctx); /* unused */ + DefPointer(WASMExecEnv *, exec_env_singleton); /* Array of function pointers to import functions, not available in AOTModuleInstance */ @@ -390,7 +411,11 @@ wasm_get_func_code_end(WASMFunctionInstance *func) } WASMModule * -wasm_load(uint8 *buf, uint32 size, char *error_buf, uint32 error_buf_size); +wasm_load(uint8 *buf, uint32 size, +#if WASM_ENABLE_MULTI_MODULE != 0 + bool main_module, +#endif + char *error_buf, uint32 error_buf_size); WASMModule * wasm_load_from_sections(WASMSection *section_list, char *error_buf, @@ -400,7 +425,7 @@ void wasm_unload(WASMModule *module); WASMModuleInstance * -wasm_instantiate(WASMModule *module, bool is_sub_inst, +wasm_instantiate(WASMModule *module, WASMModuleInstance *parent, WASMExecEnv *exec_env_main, uint32 stack_size, uint32 heap_size, char *error_buf, uint32 error_buf_size); @@ -661,6 +686,16 @@ void wasm_propagate_wasi_args(WASMModule *module); #endif +#if WASM_ENABLE_THREAD_MGR != 0 +void +exception_lock(WASMModuleInstance *module_inst); +void +exception_unlock(WASMModuleInstance *module_inst); +#else +#define exception_lock(module_inst) (void)(module_inst) +#define exception_unlock(module_inst) (void)(module_inst) +#endif + #ifdef __cplusplus } #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/debug_engine.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/debug_engine.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/debug_engine.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/debug_engine.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/debug_engine.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/debug_engine.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/debug_engine.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/debug_engine.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/debug_engine.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/debug_engine.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/debug_engine.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/debug_engine.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/gdbserver.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/gdbserver.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/gdbserver.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/gdbserver.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/gdbserver.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/gdbserver.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/gdbserver.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/gdbserver.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/handler.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/handler.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/handler.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/handler.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/handler.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/handler.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/handler.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/handler.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/packets.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/packets.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/packets.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/packets.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/packets.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/packets.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/packets.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/packets.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/utils.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/utils.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/utils.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/utils.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/utils.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/utils.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/debug-engine/utils.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/debug-engine/utils.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-pthread/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-pthread/SConscript similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-pthread/SConscript rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-pthread/SConscript diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-pthread/lib_pthread.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-pthread/lib_pthread.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-pthread/lib_pthread.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-pthread/lib_pthread.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-pthread/lib_pthread_wrapper.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-pthread/lib_pthread_wrapper.c similarity index 97% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-pthread/lib_pthread_wrapper.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-pthread/lib_pthread_wrapper.c index 206479c2a24..56deaff32f1 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-pthread/lib_pthread_wrapper.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-pthread/lib_pthread_wrapper.c @@ -531,7 +531,8 @@ pthread_start_routine(void *arg) else { info_node->u.ret = (void *)(uintptr_t)argv[0]; #ifdef OS_ENABLE_HW_BOUND_CHECK - if (exec_env->suspend_flags.flags & 0x08) + if (WASM_SUSPEND_FLAGS_GET(exec_env->suspend_flags) + & WASM_SUSPEND_FLAG_EXIT) /* argv[0] isn't set after longjmp(1) to invoke_native_with_hw_bound_check */ info_node->u.ret = exec_env->thread_ret_value; @@ -558,9 +559,6 @@ pthread_create_wrapper(wasm_exec_env_t exec_env, uint32 thread_handle; uint32 stack_size = 8192; int32 ret = -1; -#if WASM_ENABLE_LIBC_WASI != 0 - WASIContext *wasi_ctx; -#endif bh_assert(module); bh_assert(module_inst); @@ -580,18 +578,14 @@ pthread_create_wrapper(wasm_exec_env_t exec_env, #endif if (!(new_module_inst = wasm_runtime_instantiate_internal( - module, true, exec_env, stack_size, 0, NULL, 0))) + module, module_inst, exec_env, stack_size, 0, NULL, 0))) return -1; /* Set custom_data to new module instance */ wasm_runtime_set_custom_data_internal( new_module_inst, wasm_runtime_get_custom_data(module_inst)); -#if WASM_ENABLE_LIBC_WASI != 0 - wasi_ctx = get_wasi_ctx(module_inst); - if (wasi_ctx) - wasm_runtime_set_wasi_ctx(new_module_inst, wasi_ctx); -#endif + wasm_native_inherit_contexts(new_module_inst, module_inst); if (!(wasm_cluster_dup_c_api_imports(new_module_inst, module_inst))) goto fail; @@ -690,6 +684,14 @@ pthread_join_wrapper(wasm_exec_env_t exec_env, uint32 thread, bh_assert(node->joinable); join_ret = 0; ret = node->u.ret; + + /* The target thread changes the node's status before calling + wasm_cluster_exit_thread to exit, so here its resources may + haven't been destroyed yet, we wait enough time to ensure that + they are actually destroyed to avoid unexpected behavior. */ + os_mutex_lock(&exec_env->wait_lock); + os_cond_reltimedwait(&exec_env->wait_cond, &exec_env->wait_lock, 1000); + os_mutex_unlock(&exec_env->wait_lock); } if (retval_offset != 0) @@ -757,7 +759,6 @@ __pthread_self_wrapper(wasm_exec_env_t exec_env) static void pthread_exit_wrapper(wasm_exec_env_t exec_env, int32 retval_offset) { - wasm_module_inst_t module_inst = get_module_inst(exec_env); ThreadRoutineArgs *args = get_thread_arg(exec_env); /* Currently exit main thread is not allowed */ if (!args) @@ -775,9 +776,6 @@ pthread_exit_wrapper(wasm_exec_env_t exec_env, int32 retval_offset) /* destroy pthread key values */ call_key_destructor(exec_env); - /* routine exit, destroy instance */ - wasm_runtime_deinstantiate_internal(module_inst, true); - if (!args->info_node->joinable) { delete_thread_info_node(args->info_node); } @@ -789,6 +787,8 @@ pthread_exit_wrapper(wasm_exec_env_t exec_env, int32 retval_offset) wasm_runtime_free(args); + /* Don't destroy exec_env->module_inst in this functuntion since + it will be destroyed in wasm_cluster_exit_thread */ wasm_cluster_exit_thread(exec_env, (void *)(uintptr_t)retval_offset); } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats.cmake similarity index 76% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats.cmake index b773c837e38..e17a6b25afa 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats.cmake +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats.cmake @@ -23,6 +23,7 @@ include(FetchContent) set(RATS_BUILD_MODE "sgx" CACHE INTERNAL "Select build mode for librats(host|occlum|sgx|wasm)") set(RATS_INSTALL_PATH "${CMAKE_BINARY_DIR}/librats" CACHE INTERNAL "") +set(BUILD_SAMPLES OFF CACHE BOOL "Disable de compilation of the librats samples" FORCE) FetchContent_Declare( librats @@ -34,8 +35,17 @@ if (NOT librats_POPULATED) message("-- Fetching librats ..") FetchContent_Populate(librats) include_directories("${librats_SOURCE_DIR}/include") + + # Prevent the propagation of the CMAKE_C_FLAGS of WAMR into librats + set(SAVED_CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) + set(CMAKE_C_FLAGS "") + + # Import the building scripts of librats add_subdirectory(${librats_SOURCE_DIR} ${librats_BINARY_DIR} EXCLUDE_FROM_ALL) + # Restore the CMAKE_C_FLAGS of WAMR + set(CMAKE_C_FLAGS ${SAVED_CMAKE_C_FLAGS}) + endif() file (GLOB source_all ${LIB_RATS_DIR}/*.c) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats_common.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats_common.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats_common.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats_common.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats_wrapper.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats_wrapper.c similarity index 88% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats_wrapper.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats_wrapper.c index 59d61f4c828..bdacc259ce2 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats_wrapper.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats_wrapper.c @@ -17,7 +17,7 @@ #include "lib_rats_common.h" static int -librats_collect_wrapper(wasm_exec_env_t exec_env, char **evidence_json, +librats_collect_wrapper(wasm_exec_env_t exec_env, uint32_t *evidence_json, const char *buffer, uint32_t buffer_size) { wasm_module_inst_t module_inst = get_module_inst(exec_env); @@ -47,7 +47,7 @@ librats_collect_wrapper(wasm_exec_env_t exec_env, char **evidence_json, return (int)RATS_ATTESTER_ERR_NO_MEM; } bh_memcpy_s(str_ret, json_size, json, json_size); - *((int *)evidence_json) = str_ret_offset; + *evidence_json = str_ret_offset; free(json); return 0; @@ -96,6 +96,15 @@ librats_parse_evidence_wrapper(wasm_exec_env_t exec_env, return 0; } +static void +librats_dispose_evidence_json_wrapper(wasm_exec_env_t exec_env, + uint32_t evidence_json) +{ + wasm_module_inst_t module_inst = get_module_inst(exec_env); + + module_free(evidence_json); +} + /* clang-format off */ #define REG_NATIVE_FUNC(func_name, signature) \ { #func_name, func_name##_wrapper, signature, NULL } @@ -104,7 +113,8 @@ librats_parse_evidence_wrapper(wasm_exec_env_t exec_env, static NativeSymbol native_symbols_lib_rats[] = { REG_NATIVE_FUNC(librats_collect, "(**~)i"), REG_NATIVE_FUNC(librats_verify, "(*~*~)i"), - REG_NATIVE_FUNC(librats_parse_evidence, "(*~*~)i") + REG_NATIVE_FUNC(librats_parse_evidence, "(*~*~)i"), + REG_NATIVE_FUNC(librats_dispose_evidence_json, "(i)") }; uint32_t diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats_wrapper.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats_wrapper.h similarity index 96% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats_wrapper.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats_wrapper.h index e334983e9aa..9286451080e 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-rats/lib_rats_wrapper.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-rats/lib_rats_wrapper.h @@ -41,6 +41,9 @@ librats_parse_evidence(const char *evidence_json, uint32_t json_size, evidence_json ? strlen(evidence_json) + 1 : 0, \ evidence, sizeof(rats_sgx_evidence_t)) +void +librats_dispose_evidence_json(char *evidence_json); + #ifdef __cplusplus } #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h index c9a07eb72bd..98429bbb0a4 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h @@ -17,6 +17,8 @@ extern "C" { #endif typedef enum { + /* Used only for sock_addr_resolve hints */ + SOCKET_ANY = -1, SOCKET_DGRAM = 0, SOCKET_STREAM, } __wasi_sock_type_t; @@ -84,7 +86,7 @@ typedef struct __wasi_addr_t { } addr; } __wasi_addr_t; -typedef enum { INET4 = 0, INET6 } __wasi_address_family_t; +typedef enum { INET4 = 0, INET6, INET_UNSPEC } __wasi_address_family_t; typedef struct __wasi_addr_info_t { __wasi_addr_t addr; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/lib_socket_wasi.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/lib_socket_wasi.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/lib_socket_wasi.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/lib_socket_wasi.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c index defbc6efeb6..1172d0a7738 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c @@ -430,6 +430,9 @@ addrinfo_hints_to_wasi_hints(const struct addrinfo *hints, case AF_INET6: wasi_hints->family = INET6; break; + case AF_UNSPEC: + wasi_hints->family = INET_UNSPEC; + break; default: return __WASI_ERRNO_AFNOSUPPORT; } @@ -440,6 +443,8 @@ addrinfo_hints_to_wasi_hints(const struct addrinfo *hints, case SOCK_DGRAM: wasi_hints->type = SOCKET_DGRAM; break; + case 0: + wasi_hints->type = SOCKET_ANY; default: return __WASI_ERRNO_NOTSUP; } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/test/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/build.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/test/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/build.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/manifest.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/manifest.json new file mode 100644 index 00000000000..b0afd1d6b6a --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/manifest.json @@ -0,0 +1,3 @@ +{ + "name": "WAMR lib-socket tests" +} \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/test/nslookup.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/nslookup.c similarity index 64% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/test/nslookup.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/nslookup.c index 37150f1eb7f..8e64d06be30 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-socket/test/nslookup.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/nslookup.c @@ -5,6 +5,8 @@ #include #include +#include +#include #ifdef __wasi__ #include #include @@ -39,11 +41,28 @@ test_nslookup(int af) freeaddrinfo(res); } +void * +test_nslookup_mt(void *params) +{ + int *af = (int *)params; + test_nslookup(*af); + return NULL; +} + int main() { - test_nslookup(AF_INET); /* for ipv4 */ - test_nslookup(AF_INET6); /* for ipv6 */ + int afs[] = { AF_INET, AF_INET6 }; + + for (int i = 0; i < sizeof(afs) / sizeof(afs[0]); i++) { + pthread_t th; + + printf("Testing %d in main thread...\n", afs[i]); + test_nslookup(afs[i]); + printf("Testing %d in a new thread...\n", afs[i]); + pthread_create(&th, NULL, test_nslookup_mt, &afs[i]); + pthread_join(th, NULL); + } return 0; } diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/tcp_udp.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/tcp_udp.c new file mode 100644 index 00000000000..0ed03125074 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-socket/test/tcp_udp.c @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ +#include +#include +#include +#include +#include +#ifdef __wasi__ +#include +#include +#include +#endif +#include +#include +#include + +#define SERVER_MSG "Message from server." +#define PORT 8989 + +pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER; +pthread_cond_t cond = PTHREAD_COND_INITIALIZER; + +int server_init_complete = 0; + +typedef struct { + struct sockaddr_storage addr; + socklen_t addr_len; + int sock; + int protocol; +} socket_info_t; + +void +wait_for_server(int wait_time_seconds) +{ + int res = 0; + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + ts.tv_sec += wait_time_seconds; + + pthread_mutex_lock(&mut); + while (server_init_complete == 0) { + res = pthread_cond_timedwait(&cond, &mut, &ts); + if (res == ETIMEDOUT) + break; + } + pthread_mutex_unlock(&mut); + + assert(res == 0); +} + +void +notify_server_started() +{ + pthread_mutex_lock(&mut); + server_init_complete = 1; + pthread_cond_signal(&cond); + pthread_mutex_unlock(&mut); +} + +socket_info_t +init_socket_addr(int family, int protocol) +{ + socket_info_t info; + + info.sock = socket(family, protocol, 0); + assert(info.sock != -1); + info.protocol = protocol; + + memset(&info.addr, 0, sizeof(info.addr)); + + if (family == AF_INET) { + struct sockaddr_in *addr = (struct sockaddr_in *)&info.addr; + addr->sin_family = AF_INET; + addr->sin_port = htons(PORT); + addr->sin_addr.s_addr = htonl(INADDR_LOOPBACK); + info.addr_len = sizeof(struct sockaddr_in); + } + else if (family == AF_INET6) { + struct sockaddr_in6 *addr = (struct sockaddr_in6 *)&info.addr; + addr->sin6_family = AF_INET6; + addr->sin6_port = htons(PORT); + addr->sin6_addr = in6addr_loopback; + info.addr_len = sizeof(struct sockaddr_in6); + } + + return info; +} + +void * +server(void *arg) +{ + char buffer[sizeof(SERVER_MSG) + 1] = { 0 }; + struct sockaddr_storage client_addr; + socket_info_t *info = (socket_info_t *)arg; + struct sockaddr *server_addr = (struct sockaddr *)&info->addr; + int server_sock = info->sock; + + int optval = 1; + assert(setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, &optval, + sizeof(optval)) + == 0); + + assert(bind(server_sock, server_addr, info->addr_len) == 0); + + if (info->protocol == SOCK_STREAM) + listen(server_sock, 1); + notify_server_started(); + + socklen_t addr_size = info->addr_len; + if (info->protocol == SOCK_STREAM) { + int client_sock = + accept(server_sock, (struct sockaddr *)&client_addr, &addr_size); + assert(client_sock >= 0); + assert(recv(client_sock, buffer, sizeof(buffer), 0) > 0); + strcpy(buffer, SERVER_MSG); + assert(send(client_sock, buffer, sizeof(buffer), 0) > 0); + assert(recv(client_sock, buffer, sizeof(buffer), 0) > 0); + } + else { + assert(recvfrom(server_sock, buffer, sizeof(buffer), 0, + (struct sockaddr *)&client_addr, &addr_size) + > 0); + strcpy(buffer, SERVER_MSG); + assert(sendto(server_sock, buffer, strlen(buffer), 0, + (struct sockaddr *)&client_addr, addr_size) + > 0); + assert(recvfrom(server_sock, buffer, sizeof(buffer), 0, + (struct sockaddr *)&client_addr, &addr_size) + > 0); + } + assert(close(server_sock) == 0); + + return NULL; +} + +void * +client(void *arg) +{ + char buffer[sizeof(SERVER_MSG) + 1]; + socket_info_t *info = (socket_info_t *)arg; + int sock = info->sock; + struct sockaddr *addr = (struct sockaddr *)&info->addr; + + wait_for_server(1); + + if (info->protocol == SOCK_STREAM) { + assert(connect(sock, addr, info->addr_len) != -1); + } + + assert(sendto(sock, "open", strlen("open"), 0, addr, info->addr_len) > 0); + assert(recv(sock, buffer, sizeof(buffer), 0) > 0); + assert(strncmp(buffer, SERVER_MSG, strlen(SERVER_MSG)) == 0); + assert(sendto(sock, "close", sizeof("close"), 0, addr, info->addr_len) > 0); + assert(close(sock) == 0); + + return NULL; +} + +void +test_protocol(int family, int protocol) +{ + pthread_t server_thread, client_thread; + socket_info_t server_info = init_socket_addr(family, protocol); + socket_info_t client_info = init_socket_addr(family, protocol); + + printf("Testing address family: %d protocol: %d\n", family, protocol); + + server_init_complete = 0; + + assert(pthread_create(&server_thread, NULL, server, (void *)&server_info) + == 0); + assert(pthread_create(&client_thread, NULL, client, (void *)&client_info) + == 0); + assert(pthread_join(server_thread, NULL) == 0); + assert(pthread_join(client_thread, NULL) == 0); +} + +int +main(int argc, char **argv) +{ + /* test tcp with ipv4 and ipv6 */ + test_protocol(AF_INET, SOCK_STREAM); + test_protocol(AF_INET6, SOCK_STREAM); + + /* test udp with ipv4 and ipv6 */ + test_protocol(AF_INET, SOCK_DGRAM); + test_protocol(AF_INET6, SOCK_DGRAM); + + return 0; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c similarity index 93% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c index 6b36c9073fb..7e557be9009 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/lib_wasi_threads_wrapper.c @@ -80,9 +80,6 @@ thread_spawn_wrapper(wasm_exec_env_t exec_env, uint32 start_arg) int32 thread_id; uint32 stack_size = 8192; int32 ret = -1; -#if WASM_ENABLE_LIBC_WASI != 0 - WASIContext *wasi_ctx; -#endif bh_assert(module); bh_assert(module_inst); @@ -90,7 +87,7 @@ thread_spawn_wrapper(wasm_exec_env_t exec_env, uint32 start_arg) stack_size = ((WASMModuleInstance *)module_inst)->default_wasm_stack_size; if (!(new_module_inst = wasm_runtime_instantiate_internal( - module, true, exec_env, stack_size, 0, NULL, 0))) + module, module_inst, exec_env, stack_size, 0, NULL, 0))) return -1; wasm_runtime_set_custom_data_internal( @@ -99,11 +96,7 @@ thread_spawn_wrapper(wasm_exec_env_t exec_env, uint32 start_arg) if (!(wasm_cluster_dup_c_api_imports(new_module_inst, module_inst))) goto thread_preparation_fail; -#if WASM_ENABLE_LIBC_WASI != 0 - wasi_ctx = wasm_runtime_get_wasi_ctx(module_inst); - if (wasi_ctx) - wasm_runtime_set_wasi_ctx(new_module_inst, wasi_ctx); -#endif + wasm_native_inherit_contexts(new_module_inst, module_inst); start_func = wasm_runtime_lookup_function(new_module_inst, THREAD_START_FUNCTION, NULL); diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/build.sh new file mode 100755 index 00000000000..1ea95cb97c4 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/build.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# +# Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# + +set -eo pipefail +CC=${CC:=/opt/wasi-sdk/bin/clang} +WAMR_DIR=../../../../.. + +show_usage() { + echo "Usage: $0 [--sysroot PATH_TO_SYSROOT]" + echo "--sysroot PATH_TO_SYSROOT specify to build with custom sysroot for wasi-libc" +} + +while [[ $# -gt 0 ]]; do + key="$1" + case $key in + --sysroot) + sysroot_path="$2" + shift + shift + ;; + --help) + show_usage + exit + ;; + *) + echo "Unknown option: $1" + exit 1 + ;; + esac +done + +rm -rf *.wasm +rm -rf *.aot + +for test_c in *.c; do + test_wasm="$(basename $test_c .c).wasm" + + if [[ -n "$sysroot_path" ]]; then + if [ ! -d "$sysroot_path" ]; then + echo "Directory $sysroot_path doesn't exist. Aborting" + exit 1 + fi + sysroot_command="--sysroot $sysroot_path" + fi + + echo "Compiling $test_c to $test_wasm" + $CC \ + -target wasm32-wasi-threads \ + -O2 \ + -Wall \ + -pthread \ + -z stack-size=32768 \ + -Wl,--export=__heap_base \ + -Wl,--export=__data_end \ + -Wl,--shared-memory,--max-memory=1966080 \ + -Wl,--export=wasi_thread_start \ + -Wl,--export=malloc \ + -Wl,--export=free \ + -Wl,--export=test \ + $sysroot_command \ + $test_c -o $test_wasm +done diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/errorcheck_mutex_stress_test.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/errorcheck_mutex_stress_test.c new file mode 100644 index 00000000000..946e8bd6347 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/errorcheck_mutex_stress_test.c @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include +#include +#include "mutex_common.h" + +void +test() +{ + pthread_mutex_t mutex; + + // Set mutex type to errorcheck. This type provides some additional checks + // (for example returns EDEADLK instead of deadlocking in some cases) + pthread_mutexattr_t mutex_attr; + pthread_mutexattr_init(&mutex_attr); + pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK); + + pthread_mutex_init(&mutex, &mutex_attr); + pthread_mutexattr_destroy(&mutex_attr); + + run_common_tests(&mutex); + fprintf(stderr, "Errorcheck mutex test is completed\n"); + pthread_mutex_destroy(&mutex); +} + +int +main() +{ + test(); + return 0; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/manifest.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/manifest.json new file mode 100644 index 00000000000..bb91ad083e8 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/manifest.json @@ -0,0 +1,3 @@ +{ + "name": "lib-wasi-threads stress tests" +} diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/mutex_common.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/mutex_common.h new file mode 100644 index 00000000000..d57ff7d50eb --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/mutex_common.h @@ -0,0 +1,229 @@ +/* + * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#ifndef MUTEX_COMMON_H +#define MUTEX_COMMON_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum Constants { + NUM_ITER = 250000, + NUM_THREADS = 12, + NUM_RETRY = 8, + RETRY_SLEEP_TIME_US = 1000, +}; + +// We're counting how many times each thread was called using this array +// Main thread is also counted here so we need to make arrays bigger +typedef struct { + int tids[NUM_THREADS + 1]; + int calls[NUM_THREADS + 1]; +} StatCollector; + +typedef struct { + pthread_mutex_t *mutex; + StatCollector stat; + int counter; + bool is_sleeping; +} MutexCounter; + +// This enum defines whether thread should sleep to increase contention +enum SleepState { + NON_SLEEP = 0, + SLEEP = 1, +}; + +void +mutex_counter_init(MutexCounter *mutex_counter, pthread_mutex_t *mutex, + enum SleepState is_sleeping) +{ + memset(mutex_counter, 0, sizeof(*mutex_counter)); + mutex_counter->mutex = mutex; + mutex_counter->is_sleeping = is_sleeping; +} + +// This function spawns the thread using exponential retries if it receives +// EAGAIN +static inline void +spawn_thread(pthread_t *tid, void *func, void *arg) +{ + int status_code = -1; + int timeout_us = RETRY_SLEEP_TIME_US; + for (int tries = 0; status_code != 0 && tries < NUM_RETRY; ++tries) { + status_code = pthread_create(tid, NULL, (void *(*)(void *))func, arg); + assert(status_code == 0 || status_code == EAGAIN); + if (status_code == EAGAIN) { + usleep(timeout_us); + timeout_us *= 2; + } + } + + assert(status_code == 0 && "Thread creation should succeed"); +} + +// This function adds tid to our stat +static inline void +add_to_stat(StatCollector *stat, int tid) +{ + int tid_num = 0; + for (; tid_num < NUM_THREADS + 1 && stat->tids[tid_num] != 0; ++tid_num) { + if (stat->tids[tid_num] == tid) { + stat->calls[tid_num]++; + return; + } + } + + assert(tid_num < NUM_THREADS + 1); + stat->tids[tid_num] = tid; + stat->calls[tid_num] = 1; +} + +// This function prints number of calls by TID +static inline void +print_stat(StatCollector *stat) +{ + fprintf(stderr, "Thread calls count by TID\n"); + for (int i = 0; i < NUM_THREADS + 1; ++i) { + if (stat->tids[i] != 0) { + fprintf(stderr, "TID: %d; Calls: %d\n", stat->tids[i], + stat->calls[i]); + } + } +} + +// This function is run by the threads, it increases counter in a loop and then +// sleeps after unlocking the mutex to provide better contention +static inline void * +inc_shared_variable(void *arg) +{ + MutexCounter *mutex_counter = (MutexCounter *)(arg); + int sleep_us = 0; + while (!pthread_mutex_lock(mutex_counter->mutex) + && mutex_counter->counter < NUM_ITER) { + mutex_counter->counter++; + add_to_stat(&mutex_counter->stat, (int)(pthread_self())); + if (mutex_counter->is_sleeping) { + sleep_us = rand() % 1000; + } + + assert(pthread_mutex_unlock(mutex_counter->mutex) == 0 + && "Should be able to unlock a mutex"); + if (mutex_counter->is_sleeping) { + usleep(sleep_us); + } + } + + assert(mutex_counter->counter == NUM_ITER); + assert(pthread_mutex_unlock(mutex_counter->mutex) == 0 + && "Should be able to unlock the mutex after test execution"); + + return NULL; +} + +// Locking and unlocking a mutex in a single thread. +static inline void * +same_thread_lock_unlock_test(void *mutex) +{ + for (int i = 0; i < NUM_ITER; ++i) { + assert(pthread_mutex_lock(mutex) == 0 + && "Main thread should be able to lock a mutex"); + assert(pthread_mutex_unlock(mutex) == 0 + && "Main thread should be able to unlock a mutex"); + } + + return NULL; +} + +// This function spawns a thread that locks and unlocks a mutex `NUM_ITER` times +// in a row +static inline void +same_non_main_thread_lock_unlock_test(pthread_mutex_t *mutex) +{ + pthread_t tid = 0; + spawn_thread(&tid, same_thread_lock_unlock_test, mutex); + + assert(tid != 0 && "TID can't be 0 after successful thread creation"); + assert(pthread_join(tid, NULL) == 0 + && "Thread should be joined successfully"); +} + +// This function checks basic contention between main and non-main thread +// increasing the shared variable +static inline void +two_threads_inc_test(pthread_mutex_t *mutex) +{ + MutexCounter mutex_counter; + mutex_counter_init(&mutex_counter, mutex, false); + + pthread_t tid = 0; + spawn_thread(&tid, inc_shared_variable, &mutex_counter); + + assert(tid != 0 && "TID can't be 0 after successful thread creation"); + inc_shared_variable(&mutex_counter); + assert(pthread_join(tid, NULL) == 0 + && "Thread should be joined without errors"); + assert(mutex_counter.counter == NUM_ITER); +} + +// This function creates number of threads specified by NUM_THREADS and run +// concurrent increasing of shared variable +static inline void +max_threads_inc_test(pthread_mutex_t *mutex, int threads_num, + enum SleepState is_sleeping) +{ + MutexCounter mutex_counter; + mutex_counter_init(&mutex_counter, mutex, is_sleeping); + + pthread_t tids[threads_num]; + for (int i = 0; i < threads_num; ++i) { + spawn_thread(&tids[i], inc_shared_variable, &mutex_counter); + } + + inc_shared_variable(&mutex_counter); + + for (int i = 0; i < threads_num; ++i) { + assert(pthread_join(tids[i], NULL) == 0 + && "Thread should be joined without errors"); + } + + print_stat(&mutex_counter.stat); +} + +// This function just runs all the tests described above +static inline void +run_common_tests(pthread_mutex_t *mutex) +{ + srand(time(NULL)); + + fprintf(stderr, "Starting same_thread_lock_unlock_test test\n"); + same_thread_lock_unlock_test(mutex); + fprintf(stderr, "Finished same_thread_lock_unlock_test test\n"); + + fprintf(stderr, "Starting same_non_main_thread_lock_unlock_test test\n"); + same_non_main_thread_lock_unlock_test(mutex); + fprintf(stderr, "Finished same_non_main_thread_lock_unlock_test test\n"); + + fprintf(stderr, "Starting two_threads_inc_test test\n"); + two_threads_inc_test(mutex); + fprintf(stderr, "Finished two_threads_inc_test test\n"); + + fprintf(stderr, "Starting max_threads_inc_test_sleep test\n"); + max_threads_inc_test(mutex, NUM_THREADS, SLEEP); + fprintf(stderr, "Finished concurrent_inc sleep test\n"); + + fprintf(stderr, "Starting max_threads_inc_test_non_sleep test\n"); + max_threads_inc_test(mutex, NUM_THREADS, NON_SLEEP); + fprintf(stderr, "Finished max_threads_inc_test test\n"); +} + +#endif // MUTEX_COMMON_H diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/normal_mutex_stress_test.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/normal_mutex_stress_test.c new file mode 100644 index 00000000000..c7ffae279a0 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/normal_mutex_stress_test.c @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include +#include +#include "mutex_common.h" + +void +test() +{ + pthread_mutex_t mutex; + pthread_mutex_init(&mutex, NULL); + + run_common_tests(&mutex); + + fprintf(stderr, "Normal mutex test is completed\n"); + pthread_mutex_destroy(&mutex); +} + +int +main() +{ + test(); + return 0; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/recursive_mutex_stress_test.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/recursive_mutex_stress_test.c new file mode 100644 index 00000000000..5874372cb35 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/recursive_mutex_stress_test.c @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include +#include +#include "mutex_common.h" + +void +multiple_same_thread_lock(void *mutex) +{ + for (int i = 0; i < 100; ++i) { + assert(pthread_mutex_lock(mutex) == 0 + && "Recursive mutex should allow multiple locking"); + } + + for (int i = 0; i < 100; ++i) { + assert(pthread_mutex_unlock(mutex) == 0 + && "Recursive mutex should allow multiple unlocking"); + } +} + +void * +same_thread_multiple_rec_mutex_lock(void *mutex) +{ + for (int i = 0; i < NUM_ITER; ++i) { + multiple_same_thread_lock(mutex); + } + + return NULL; +} + +void +test() +{ + pthread_mutex_t mutex; + + // Set mutex type to recursive. This type allows multiple locking and + // unlocking within the same thread + pthread_mutexattr_t mutex_attr; + pthread_mutexattr_init(&mutex_attr); + pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE); + + pthread_mutex_init(&mutex, &mutex_attr); + pthread_mutexattr_destroy(&mutex_attr); + + run_common_tests(&mutex); + + fprintf(stderr, "Starting same_thread_multiple_rec_mutex_lock test\n"); + same_thread_multiple_rec_mutex_lock(&mutex); + fprintf(stderr, "Finished same_thread_multiple_rec_mutex_lock test\n"); + + fprintf(stderr, "Starting same_thread_multiple_rec_mutex_lock test in " + "non-main thread\n"); + pthread_t tid; + spawn_thread(&tid, same_thread_multiple_rec_mutex_lock, &mutex); + assert(pthread_join(tid, NULL) == 0 + && "Non-main thread should be joined successfully"); + fprintf(stderr, "Finished same_thread_multiple_rec_mutex_lock test in " + "non-main thread\n"); + + fprintf(stderr, "Recursive mutex test is completed\n"); + pthread_mutex_destroy(&mutex); +} + +int +main() +{ + test(); + return 0; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/spawn_stress_test.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/spawn_stress_test.c new file mode 100644 index 00000000000..8cb61a2a694 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/spawn_stress_test.c @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#ifndef __wasi__ +#error This example only compiles to WASM/WASI target +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +unsigned prime_numbers_count = 0; + +bool +is_prime(unsigned int num) +{ + for (unsigned int i = 2; i <= (unsigned int)(sqrt(num)); ++i) { + if (num % i == 0) { + return false; + } + } + + return true; +} + +void * +check_if_prime(void *value) +{ + unsigned int *num = (unsigned int *)(value); + usleep(10000); + if (is_prime(*num)) { + __atomic_fetch_add(&prime_numbers_count, 1, __ATOMIC_SEQ_CST); + } + return NULL; +} + +unsigned int +validate(int iter_num) +{ + unsigned int counter = 0; + for (unsigned int i = 2; i <= iter_num; ++i) { + counter += is_prime(i); + } + + return counter; +} + +void +spawn_thread(pthread_t *thread, int retry_time_us, int retry_num, + unsigned int *arg) +{ + int status_code = -1; + int timeout_us = retry_time_us; + for (int tries = 0; status_code != 0 && tries < retry_num; ++tries) { + status_code = pthread_create(thread, NULL, &check_if_prime, arg); + assert(status_code == 0 || status_code == EAGAIN); + if (status_code == EAGAIN) { + usleep(timeout_us); + timeout_us *= 2; + } + } + + assert(status_code == 0 && "Thread creation should succeed"); +} + +void +test(int iter_num, int retry_num, int max_threads_num, int retry_time_us) +{ + pthread_t threads[max_threads_num]; + unsigned int args[max_threads_num]; + double percentage = 0.1; + + for (unsigned int factorised_number = 2; factorised_number < iter_num; + ++factorised_number) { + if (factorised_number > iter_num * percentage) { + fprintf(stderr, "Stress test is %d%% finished\n", + (unsigned int)(percentage * 100)); + percentage += 0.1; + } + + unsigned int thread_num = factorised_number % max_threads_num; + if (threads[thread_num] != 0) { + assert(pthread_join(threads[thread_num], NULL) == 0); + } + + args[thread_num] = factorised_number; + + usleep(retry_time_us); + spawn_thread(&threads[thread_num], retry_time_us, retry_num, + &args[thread_num]); + assert(threads[thread_num] != 0); + } + + for (int i = 0; i < max_threads_num; ++i) { + assert(threads[i] == 0 || pthread_join(threads[i], NULL) == 0); + } + + // Check the test results + assert( + prime_numbers_count == validate(iter_num) + && "Answer mismatch between tested code and reference implementation"); + + fprintf(stderr, "Stress test finished successfully\n"); +} + +enum DEFAULT_PARAMETERS { + ITER_NUM = 20000, + RETRY_NUM = 8, + MAX_THREADS_NUM = 12, + RETRY_SLEEP_TIME_US = 2000, +}; + +int +main(int argc, char **argv) +{ + test(ITER_NUM, RETRY_NUM, MAX_THREADS_NUM, RETRY_SLEEP_TIME_US); + return 0; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/stress_test_threads_creation.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/stress_test_threads_creation.c new file mode 100644 index 00000000000..c4c2d2857e0 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/stress-test/stress_test_threads_creation.c @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include +#include +#include +#include +#include + +int threads_executed = 0; +unsigned int threads_creation_tried = 0; +unsigned int threads_in_use = 0; + +void * +thread_func(void *arg) +{ + (void)(arg); + __atomic_fetch_add(&threads_executed, 1, __ATOMIC_RELAXED); + __atomic_fetch_sub(&threads_in_use, 1, __ATOMIC_SEQ_CST); + return NULL; +} + +void +spawn_thread(pthread_t *thread, int retry_time, int iter_num) +{ + int status_code = -1; + int timeout_us = retry_time; + for (int tries = 0; status_code != 0 && tries < iter_num; ++tries) { + status_code = pthread_create(thread, NULL, &thread_func, NULL); + __atomic_fetch_add(&threads_creation_tried, 1, __ATOMIC_RELAXED); + + assert(status_code == 0 || status_code == EAGAIN); + if (status_code == EAGAIN) { + usleep(timeout_us); + timeout_us *= 2; + } + } + + assert(status_code == 0 && "Thread creation should succeed"); +} + +void +test(int iter_num, int max_threads_num, int retry_num, int retry_time_us) +{ + double percentage = 0.1; + int second_us = 1000 * 1000 * 1000; // 1 second in us + + for (int iter = 0; iter < iter_num; ++iter) { + if (iter > iter_num * percentage) { + fprintf(stderr, "Spawning stress test is %d%% finished\n", + (unsigned int)(percentage * 100)); + percentage += 0.1; + } + while (__atomic_load_n(&threads_in_use, __ATOMIC_SEQ_CST) + == max_threads_num) { + usleep(100); + } + + __atomic_fetch_add(&threads_in_use, 1, __ATOMIC_SEQ_CST); + pthread_t tmp; + spawn_thread(&tmp, retry_time_us, iter_num); + pthread_detach(tmp); + } + + while ((__atomic_load_n(&threads_in_use, __ATOMIC_SEQ_CST) != 0)) { + // Casting to int* to supress compiler warning + __builtin_wasm_memory_atomic_wait32((int *)(&threads_in_use), 0, + second_us); + } + + assert(__atomic_load_n(&threads_in_use, __ATOMIC_SEQ_CST) == 0); + + // Validation + assert(threads_creation_tried >= threads_executed + && "Test executed more threads than were created"); + assert((1. * threads_creation_tried) / threads_executed < 2.5 + && "Ensuring that we're retrying thread creation less than 2.5 " + "times on average "); + + fprintf(stderr, + "Spawning stress test finished successfully executed %d threads " + "with retry ratio %f\n", + threads_creation_tried, + (1. * threads_creation_tried) / threads_executed); +} + +enum DEFAULT_PARAMETERS { + ITER_NUM = 50000, + RETRY_NUM = 8, + MAX_NUM_THREADS = 12, + RETRY_SLEEP_TIME_US = 4000, +}; + +int +main(int argc, char **argv) +{ + test(ITER_NUM, MAX_NUM_THREADS, RETRY_NUM, RETRY_SLEEP_TIME_US); + return 0; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/build.sh new file mode 100755 index 00000000000..608dd226082 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/build.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +# +# Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# + +set -eo pipefail +CC=${CC:=/opt/wasi-sdk/bin/clang} +WAMR_DIR=../../../../.. + +show_usage() { + echo "Usage: $0 [--sysroot PATH_TO_SYSROOT]" + echo "--sysroot PATH_TO_SYSROOT specify to build with custom sysroot for wasi-libc" +} + +while [[ $# -gt 0 ]]; do + key="$1" + case $key in + --sysroot) + sysroot_path="$2" + shift + shift + ;; + --help) + show_usage + exit + ;; + *) + echo "Unknown option: $1" + exit 1 + ;; + esac +done + +# Stress tests names +thread_start_file_exclusions=("linear_memory_size_update.wasm") + +rm -rf *.wasm +rm -rf *.aot + +for test_c in *.c; do + test_wasm="$(basename $test_c .c).wasm" + + if [[ " ${thread_start_file_exclusions[@]} " =~ " ${test_wasm} " ]] ; then + thread_start_file="" + else + thread_start_file=$WAMR_DIR/samples/wasi-threads/wasm-apps/wasi_thread_start.S + fi + + if [[ -n "$sysroot_path" ]]; then + if [ ! -d "$sysroot_path" ]; then + echo "Directory $sysroot_path doesn't exist. Aborting" + exit 1 + fi + sysroot_command="--sysroot $sysroot_path" + fi + + echo "Compiling $test_c to $test_wasm" + $CC \ + -target wasm32-wasi-threads \ + -O2 \ + -pthread -ftls-model=local-exec \ + -z stack-size=32768 \ + -Wl,--export=__heap_base \ + -Wl,--export=__data_end \ + -Wl,--shared-memory,--max-memory=1966080 \ + -Wl,--export=wasi_thread_start \ + -Wl,--export=malloc \ + -Wl,--export=free \ + -I $WAMR_DIR/samples/wasi-threads/wasm-apps \ + $sysroot_command \ + $thread_start_file \ + $test_c -o $test_wasm +done \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/common.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/common.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/common.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/common.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/create_threads_until_limit.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/create_threads_until_limit.c similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/create_threads_until_limit.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/create_threads_until_limit.c index 23ba5f62777..94ffa0f67e9 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/create_threads_until_limit.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/create_threads_until_limit.c @@ -65,7 +65,7 @@ main(int argc, char **argv) assert(start_args_init(&data[i].base)); thread_ids[i] = __wasi_thread_spawn(&data[i]); printf("Thread created with id=%d\n", thread_ids[i]); - assert(thread_ids[i] > 0 && "Thread creation failed"); + ASSERT_VALID_TID(thread_ids[i]); for (int j = 0; j < i; j++) { assert(thread_ids[i] != thread_ids[j] && "Duplicated TIDs"); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/global_atomic.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/global_atomic.c similarity index 96% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/global_atomic.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/global_atomic.c index a38e753640f..7e1e8e08128 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/global_atomic.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/global_atomic.c @@ -49,7 +49,7 @@ main(int argc, char **argv) for (int i = 0; i < NUM_THREADS; i++) { assert(start_args_init(&data[i].base)); thread_ids[i] = __wasi_thread_spawn(&data[i]); - assert(thread_ids[i] > 0 && "Thread creation failed"); + ASSERT_VALID_TID(thread_ids[i]); } printf("Wait for threads to finish\n"); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/global_lock.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/global_lock.c similarity index 96% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/global_lock.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/global_lock.c index f81fca49b90..fb33802fce9 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/global_lock.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/global_lock.c @@ -61,7 +61,7 @@ main(int argc, char **argv) for (int i = 0; i < NUM_THREADS; i++) { assert(start_args_init(&data[i].base)); thread_ids[i] = __wasi_thread_spawn(&data[i]); - assert(thread_ids[i] > 0 && "Thread creation failed"); + ASSERT_VALID_TID(thread_ids[i]); } printf("Wait for threads to finish\n"); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/linear_memory_size_update.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/linear_memory_size_update.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/linear_memory_size_update.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/linear_memory_size_update.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_busy.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_busy.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_busy.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_busy.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_busy.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_busy.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_busy.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_busy.json diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_sleep.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_sleep.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_sleep.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_sleep.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_sleep.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_sleep.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_sleep.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_sleep.json diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_wait.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_wait.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_wait.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_wait.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_wait.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_wait.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_wait.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_proc_exit_wait.json diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_busy.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_busy.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_busy.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_busy.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_busy.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_busy.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_busy.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_busy.json diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_sleep.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_sleep.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_sleep.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_sleep.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_sleep.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_sleep.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_sleep.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_sleep.json diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_wait.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_wait.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_wait.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_wait.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_wait.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_wait.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/main_trap_wait.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/main_trap_wait.json diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/manifest.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/manifest.json new file mode 100644 index 00000000000..cd2cc7636ca --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/manifest.json @@ -0,0 +1,3 @@ +{ + "name": "lib-wasi-threads tests" +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_busy.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_busy.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_busy.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_busy.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_busy.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_busy.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_busy.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_busy.json diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_sleep.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_sleep.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_sleep.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_sleep.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_sleep.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_sleep.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_sleep.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_sleep.json diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_wait.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_wait.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_wait.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_wait.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_wait.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_wait.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_wait.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_proc_exit_wait.json diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_busy.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_busy.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_busy.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_busy.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_busy.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_busy.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_busy.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_busy.json diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_sleep.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_sleep.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_sleep.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_sleep.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_sleep.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_sleep.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_sleep.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_sleep.json diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_wait.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_wait.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_wait.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_wait.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_wait.json b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_wait.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_wait.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/nonmain_trap_wait.json diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/spawn_multiple_times.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/spawn_multiple_times.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/spawn_multiple_times.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/spawn_multiple_times.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/sync_primitives.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/sync_primitives.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/sync_primitives.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/sync_primitives.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.c similarity index 94% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.c index 69e125d407d..5cf61338f0b 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.c @@ -38,7 +38,7 @@ main(int argc, char **argv) assert(start_args_init(&data.base)); int thread_id = __wasi_thread_spawn(&data); - assert(thread_id > 0 && "Thread creation failed"); + ASSERT_VALID_TID(thread_id); return EXIT_SUCCESS; } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/update_shared_data_and_alloc_heap.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/update_shared_data_and_alloc_heap.c similarity index 97% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/update_shared_data_and_alloc_heap.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/update_shared_data_and_alloc_heap.c index b7fb9afba6b..d6e34539be1 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/test/update_shared_data_and_alloc_heap.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/test/update_shared_data_and_alloc_heap.c @@ -69,7 +69,7 @@ main(int argc, char **argv) data[i].iteration = i; thread_ids[i] = __wasi_thread_spawn(&data[i]); - assert(thread_ids[i] > 0 && "Thread creation failed"); + ASSERT_VALID_TID(thread_ids[i]); } printf("Wait for threads to finish\n"); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/tid_allocator.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/tid_allocator.c similarity index 88% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/tid_allocator.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/tid_allocator.c index 4d53da0c94f..dc2d4f1bca7 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/tid_allocator.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/tid_allocator.c @@ -21,7 +21,8 @@ tid_allocator_init(TidAllocator *tid_allocator) return false; for (int64 i = tid_allocator->pos - 1; i >= 0; i--) - tid_allocator->ids[i] = TID_MIN + (tid_allocator->pos - 1 - i); + tid_allocator->ids[i] = + (uint32)(TID_MIN + (tid_allocator->pos - 1 - i)); return true; } @@ -54,7 +55,8 @@ tid_allocator_get_tid(TidAllocator *tid_allocator) LOG_ERROR("Overflow detected during realloc"); return -1; } - int32 *tmp = wasm_runtime_realloc(tid_allocator->ids, realloc_size); + int32 *tmp = + wasm_runtime_realloc(tid_allocator->ids, (uint32)realloc_size); if (tmp == NULL) { LOG_ERROR("Thread ID allocator realloc failed"); return -1; @@ -64,7 +66,8 @@ tid_allocator_get_tid(TidAllocator *tid_allocator) tid_allocator->pos = new_size - old_size; tid_allocator->ids = tmp; for (int64 i = tid_allocator->pos - 1; i >= 0; i--) - tid_allocator->ids[i] = TID_MIN + (tid_allocator->size - 1 - i); + tid_allocator->ids[i] = + (uint32)(TID_MIN + (tid_allocator->size - 1 - i)); } // Pop available thread identifier from the stack @@ -77,4 +80,4 @@ tid_allocator_release_tid(TidAllocator *tid_allocator, int32 thread_id) // Release thread identifier by pushing it into the stack bh_assert(tid_allocator->pos < tid_allocator->size); tid_allocator->ids[tid_allocator->pos++] = thread_id; -} \ No newline at end of file +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/tid_allocator.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/tid_allocator.h similarity index 83% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/tid_allocator.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/tid_allocator.h index 53af1719ff3..6e25f7749da 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/lib-wasi-threads/tid_allocator.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/tid_allocator.h @@ -8,8 +8,14 @@ #include "platform_common.h" +#ifdef __cplusplus +extern "C" { +#endif + #define TID_ALLOCATOR_INIT_SIZE CLUSTER_MAX_THREAD_NUM enum { + /* Keep it in sync with + https://github.com/WebAssembly/wasi-threads#design-choice-thread-ids */ TID_MIN = 1, TID_MAX = 0x1FFFFFFF }; // Reserved TIDs (WASI specification) @@ -33,4 +39,8 @@ tid_allocator_get_tid(TidAllocator *tid_allocator); void tid_allocator_release_tid(TidAllocator *tid_allocator, int32 thread_id); +#ifdef __cplusplus +} +#endif + #endif /* _TID_ALLOCATOR_H */ \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/unit-test/lib_wasi_threads_unit_tests.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/unit-test/lib_wasi_threads_unit_tests.cmake new file mode 100644 index 00000000000..75d8f4e0e64 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/unit-test/lib_wasi_threads_unit_tests.cmake @@ -0,0 +1,6 @@ +# Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +create_wamr_unit_test(wasi_threads + ${CMAKE_CURRENT_LIST_DIR}/test_tid_allocator.cpp +) diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/unit-test/test_tid_allocator.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/unit-test/test_tid_allocator.cpp new file mode 100644 index 00000000000..6fa7300f6c4 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/lib-wasi-threads/unit-test/test_tid_allocator.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include + +#include "tid_allocator.h" + +#include + +class TidAllocatorTest : public ::testing::Test +{ + protected: + void SetUp() override { ASSERT_TRUE(tid_allocator_init(&_allocator)); } + + void TearDown() override { tid_allocator_deinit(&_allocator); } + + TidAllocator _allocator; +}; + +static bool +is_tid_valid(int32 tid) +{ + /* See: https://github.com/WebAssembly/wasi-threads#design-choice-thread-ids + */ + return tid >= TID_MIN && tid <= TID_MAX; +} + +TEST_F(TidAllocatorTest, BasicTest) +{ + int32 tid = tid_allocator_get_tid(&_allocator); + + ASSERT_TRUE(is_tid_valid(tid)); +} + +TEST_F(TidAllocatorTest, ShouldFailOnAllocatingMoreThanAllowedThreadIDs) +{ + int32 last_tid = 0; + for (int32 i = 0; i < TID_MAX + 1; i++) { + last_tid = tid_allocator_get_tid(&_allocator); + if (last_tid < 0) { + break; + } + ASSERT_TRUE(is_tid_valid(last_tid)); + } + + ASSERT_LT(last_tid, 0); +} + +TEST_F(TidAllocatorTest, ShouldAllocateMoreThanAllowedTIDsIfOldTIDsAreReleased) +{ + int32 last_tid = 0; + for (int32 i = 0; i < TID_MAX + 1; i++) { + if (last_tid != 0) { + tid_allocator_release_tid(&_allocator, last_tid); + } + + last_tid = tid_allocator_get_tid(&_allocator); + ASSERT_TRUE(is_tid_valid(last_tid)); + } +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-builtin/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-builtin/SConscript similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-builtin/SConscript rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-builtin/SConscript diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-builtin/libc_builtin.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-builtin/libc_builtin.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-builtin/libc_builtin.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-builtin/libc_builtin.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-emcc/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-emcc/SConscript similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-emcc/SConscript rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-emcc/SConscript diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-emcc/libc_emcc.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-emcc/libc_emcc.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-emcc/libc_emcc.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-emcc/libc_emcc.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/FindLIBUV.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/FindLIBUV.cmake new file mode 100644 index 00000000000..7949f06f38c --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/FindLIBUV.cmake @@ -0,0 +1,28 @@ +# Copyright (C) 2023 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# Find libuv library +# This module defines +# LIBUV_FOUND, if false, do not try to link to libuv +# LIBUV_LIBRARIES +# LIBUV_INCLUDE_DIR, where to find uv.h + +find_path(LIBUV_INCLUDE_DIR NAMES uv.h) +find_library(LIBUV_LIBRARIES NAMES uv libuv) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args( + LIBUV + FOUND_VAR LIBUV_FOUND + REQUIRED_VARS + LIBUV_LIBRARIES + LIBUV_INCLUDE_DIR +) + +if(WIN32) + list(APPEND LIBUV_LIBRARIES iphlpapi) + list(APPEND LIBUV_LIBRARIES psapi) + list(APPEND LIBUV_LIBRARIES userenv) + list(APPEND LIBUV_LIBRARIES ws2_32) +endif() diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/FindUVWASI.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/FindUVWASI.cmake new file mode 100644 index 00000000000..88499eaa645 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/FindUVWASI.cmake @@ -0,0 +1,25 @@ +# Copyright (C) 2023 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# Find libuvwasi library +# This module defines +# UVWASI_FOUND, if false, do not try to link to libuvwasi +# UVWASI_LIBRARIES +# UVWASI_INCLUDE_DIR, where to find headers + +find_path(UVWASI_INCLUDE_DIR NAMES uvwasi.h wasi_serdes.h wasi_types.h PATH_SUFFIXES uvwasi) +find_library(UVWASI_LIBRARIES NAMES uvwasi_a) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args( + UVWASI + FOUND_VAR UVWASI_FOUND + REQUIRED_VARS + UVWASI_LIBRARIES + UVWASI_INCLUDE_DIR +) + +if(UVWASI_FOUND) + set(UVWASI_INCLUDE_DIR ${UVWASI_INCLUDE_DIR}/uvwasi) +endif() diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/LICENSE_LIBUV b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/LICENSE_LIBUV similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/LICENSE_LIBUV rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/LICENSE_LIBUV diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/LICENSE_UVWASI b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/LICENSE_UVWASI similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/LICENSE_UVWASI rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/LICENSE_UVWASI diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/libc_uvwasi.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/libc_uvwasi.cmake new file mode 100644 index 00000000000..7a3bfbdce7d --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/libc_uvwasi.cmake @@ -0,0 +1,61 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +set (LIBC_WASI_DIR ${CMAKE_CURRENT_LIST_DIR}) + +set (LIBUV_VERSION v1.46.0) + +add_definitions (-DWASM_ENABLE_LIBC_WASI=1 -DWASM_ENABLE_UVWASI=1) + +include(FetchContent) + +# Point CMake at the custom modules to find libuv and uvwasi +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") + +## libuv +find_package(LIBUV QUIET) +if (LIBUV_FOUND) + include_directories(${LIBUV_INCLUDE_DIR}) +else() + FetchContent_Declare( + libuv + GIT_REPOSITORY https://github.com/libuv/libuv.git + GIT_TAG ${LIBUV_VERSION} + ) + FetchContent_GetProperties(libuv) + if (NOT libuv_POPULATED) + message("-- Fetching libuv ..") + FetchContent_Populate(libuv) + include_directories("${libuv_SOURCE_DIR}/include") + add_subdirectory(${libuv_SOURCE_DIR} ${libuv_BINARY_DIR} EXCLUDE_FROM_ALL) + set (LIBUV_LIBRARIES uv_a) + set_target_properties(uv_a PROPERTIES POSITION_INDEPENDENT_CODE 1) + endif() +endif() + +## uvwasi +find_package(UVWASI QUIET) +if (UVWASI_FOUND) + include_directories(${UVWASI_INCLUDE_DIR}) +else() + FetchContent_Declare( + uvwasi + GIT_REPOSITORY https://github.com/nodejs/uvwasi.git + GIT_TAG main + ) + FetchContent_GetProperties(uvwasi) + if (NOT uvwasi_POPULATED) + message("-- Fetching uvwasi ..") + FetchContent_Populate(uvwasi) + include_directories("${uvwasi_SOURCE_DIR}/include") + add_subdirectory(${uvwasi_SOURCE_DIR} ${uvwasi_BINARY_DIR} EXCLUDE_FROM_ALL) + set (UVWASI_LIBRARIES uvwasi_a) + set_target_properties(uvwasi_a PROPERTIES POSITION_INDEPENDENT_CODE 1) + endif() +endif() + +set (UV_A_LIBS ${LIBUV_LIBRARIES} ${UVWASI_LIBRARIES}) + +file (GLOB_RECURSE source_all ${LIBC_WASI_DIR}/*.c) + +set (LIBC_WASI_SOURCE ${source_all}) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/libc_uvwasi_wrapper.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/libc_uvwasi_wrapper.c similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/libc_uvwasi_wrapper.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/libc_uvwasi_wrapper.c index 504ff7f93e4..6ead654066d 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-uvwasi/libc_uvwasi_wrapper.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-uvwasi/libc_uvwasi_wrapper.c @@ -30,7 +30,16 @@ wasm_runtime_module_free(module_inst, offset) /* clang-format on */ -#define wasi_errno_t uvwasi_errno_t +// uvwasi_errno_t is typedef'd to uint16 which is correct according to the ABI +// specification. However, in WASM, the smallest integer type is int32. If we +// return uint16, we would rely on language SDKs to implement the correct +// behaviour of casting to uint16 before checking the value or using it any way. +// Failure to do so can cause tricky bugs as the upper 16 bits of the error +// result are not guaranteed to be zero'ed by us so the result essentially +// contains garbage from the WASM app perspective. To prevent this, we return +// uint32 directly instead so as not to be reliant on the correct behaviour of +// any current/future SDK implementations. +#define wasi_errno_t uint32_t #define wasi_fd_t uvwasi_fd_t #define wasi_clockid_t uvwasi_clockid_t #define wasi_timestamp_t uvwasi_timestamp_t diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/SConscript similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/SConscript rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/SConscript diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/libc_wasi.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/libc_wasi.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/libc_wasi.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/libc_wasi.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c similarity index 88% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c index afb11925ab3..9f35b81a7f8 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c @@ -7,6 +7,7 @@ #include "bh_platform.h" #include "wasm_export.h" #include "wasm_runtime_common.h" +#include "wasmtime_ssp.h" #if WASM_ENABLE_THREAD_MGR != 0 #include "../../../thread-mgr/thread_manager.h" @@ -56,11 +57,13 @@ typedef struct WASIContext *wasi_ctx_t; wasi_ctx_t wasm_runtime_get_wasi_ctx(wasm_module_inst_t module_inst); +#if WASM_ENABLE_THREAD_MGR != 0 static inline uint64_t min_uint64(uint64_t a, uint64_t b) { return a > b ? b : a; } +#endif static inline uint32_t min_uint32(uint32_t a, uint32_t b) @@ -190,7 +193,7 @@ wasi_clock_res_get(wasm_exec_env_t exec_env, if (!validate_native_addr(resolution, sizeof(wasi_timestamp_t))) return (wasi_errno_t)-1; - return wasmtime_ssp_clock_res_get(clock_id, resolution); + return os_clock_res_get(clock_id, resolution); } static wasi_errno_t @@ -204,7 +207,7 @@ wasi_clock_time_get(wasm_exec_env_t exec_env, if (!validate_native_addr(time, sizeof(wasi_timestamp_t))) return (wasi_errno_t)-1; - return wasmtime_ssp_clock_time_get(clock_id, precision, time); + return os_clock_time_get(clock_id, precision, time); } static wasi_errno_t @@ -333,7 +336,7 @@ wasi_fd_close(wasm_exec_env_t exec_env, wasi_fd_t fd) if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_close(curfds, prestats, fd); + return wasmtime_ssp_fd_close(exec_env, curfds, prestats, fd); } static wasi_errno_t @@ -346,7 +349,7 @@ wasi_fd_datasync(wasm_exec_env_t exec_env, wasi_fd_t fd) if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_datasync(curfds, fd); + return wasmtime_ssp_fd_datasync(exec_env, curfds, fd); } static wasi_errno_t @@ -387,8 +390,8 @@ wasi_fd_pread(wasm_exec_env_t exec_env, wasi_fd_t fd, iovec_app_t *iovec_app, iovec->buf_len = iovec_app->buf_len; } - err = wasmtime_ssp_fd_pread(curfds, fd, iovec_begin, iovs_len, offset, - &nread); + err = wasmtime_ssp_fd_pread(exec_env, curfds, fd, iovec_begin, iovs_len, + offset, &nread); if (err) goto fail; @@ -441,8 +444,8 @@ wasi_fd_pwrite(wasm_exec_env_t exec_env, wasi_fd_t fd, ciovec->buf_len = iovec_app->buf_len; } - err = wasmtime_ssp_fd_pwrite(curfds, fd, ciovec_begin, iovs_len, offset, - &nwritten); + err = wasmtime_ssp_fd_pwrite(exec_env, curfds, fd, ciovec_begin, iovs_len, + offset, &nwritten); if (err) goto fail; @@ -494,7 +497,8 @@ wasi_fd_read(wasm_exec_env_t exec_env, wasi_fd_t fd, iovec->buf_len = iovec_app->buf_len; } - err = wasmtime_ssp_fd_read(curfds, fd, iovec_begin, iovs_len, &nread); + err = wasmtime_ssp_fd_read(exec_env, curfds, fd, iovec_begin, iovs_len, + &nread); if (err) goto fail; @@ -519,7 +523,7 @@ wasi_fd_renumber(wasm_exec_env_t exec_env, wasi_fd_t from, wasi_fd_t to) if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_renumber(curfds, prestats, from, to); + return wasmtime_ssp_fd_renumber(exec_env, curfds, prestats, from, to); } static wasi_errno_t @@ -536,7 +540,8 @@ wasi_fd_seek(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filedelta_t offset, if (!validate_native_addr(newoffset, sizeof(wasi_filesize_t))) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_seek(curfds, fd, offset, whence, newoffset); + return wasmtime_ssp_fd_seek(exec_env, curfds, fd, offset, whence, + newoffset); } static wasi_errno_t @@ -552,7 +557,7 @@ wasi_fd_tell(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t *newoffset) if (!validate_native_addr(newoffset, sizeof(wasi_filesize_t))) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_tell(curfds, fd, newoffset); + return wasmtime_ssp_fd_tell(exec_env, curfds, fd, newoffset); } static wasi_errno_t @@ -571,7 +576,7 @@ wasi_fd_fdstat_get(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!validate_native_addr(fdstat_app, sizeof(wasi_fdstat_t))) return (wasi_errno_t)-1; - err = wasmtime_ssp_fd_fdstat_get(curfds, fd, &fdstat); + err = wasmtime_ssp_fd_fdstat_get(exec_env, curfds, fd, &fdstat); if (err) return err; @@ -590,7 +595,7 @@ wasi_fd_fdstat_set_flags(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_fdstat_set_flags(curfds, fd, flags); + return wasmtime_ssp_fd_fdstat_set_flags(exec_env, curfds, fd, flags); } static wasi_errno_t @@ -605,8 +610,8 @@ wasi_fd_fdstat_set_rights(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_fdstat_set_rights(curfds, fd, fs_rights_base, - fs_rights_inheriting); + return wasmtime_ssp_fd_fdstat_set_rights( + exec_env, curfds, fd, fs_rights_base, fs_rights_inheriting); } static wasi_errno_t @@ -619,7 +624,7 @@ wasi_fd_sync(wasm_exec_env_t exec_env, wasi_fd_t fd) if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_sync(curfds, fd); + return wasmtime_ssp_fd_sync(exec_env, curfds, fd); } static wasi_errno_t @@ -661,7 +666,8 @@ wasi_fd_write(wasm_exec_env_t exec_env, wasi_fd_t fd, ciovec->buf_len = iovec_app->buf_len; } - err = wasmtime_ssp_fd_write(curfds, fd, ciovec_begin, iovs_len, &nwritten); + err = wasmtime_ssp_fd_write(exec_env, curfds, fd, ciovec_begin, iovs_len, + &nwritten); if (err) goto fail; @@ -686,7 +692,7 @@ wasi_fd_advise(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t offset, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_advise(curfds, fd, offset, len, advice); + return wasmtime_ssp_fd_advise(exec_env, curfds, fd, offset, len, advice); } static wasi_errno_t @@ -700,7 +706,7 @@ wasi_fd_allocate(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_filesize_t offset, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_allocate(curfds, fd, offset, len); + return wasmtime_ssp_fd_allocate(exec_env, curfds, fd, offset, len); } static wasi_errno_t @@ -714,7 +720,8 @@ wasi_path_create_directory(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_path_create_directory(curfds, fd, path, path_len); + return wasmtime_ssp_path_create_directory(exec_env, curfds, fd, path, + path_len); } static wasi_errno_t @@ -731,8 +738,9 @@ wasi_path_link(wasm_exec_env_t exec_env, wasi_fd_t old_fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_path_link(curfds, prestats, old_fd, old_flags, old_path, - old_path_len, new_fd, new_path, new_path_len); + return wasmtime_ssp_path_link(exec_env, curfds, prestats, old_fd, old_flags, + old_path, old_path_len, new_fd, new_path, + new_path_len); } static wasi_errno_t @@ -754,9 +762,9 @@ wasi_path_open(wasm_exec_env_t exec_env, wasi_fd_t dirfd, if (!validate_native_addr(fd_app, sizeof(wasi_fd_t))) return (wasi_errno_t)-1; - err = wasmtime_ssp_path_open(curfds, dirfd, dirflags, path, path_len, - oflags, fs_rights_base, fs_rights_inheriting, - fs_flags, &fd); + err = wasmtime_ssp_path_open(exec_env, curfds, dirfd, dirflags, path, + path_len, oflags, fs_rights_base, + fs_rights_inheriting, fs_flags, &fd); *fd_app = fd; return err; @@ -778,7 +786,8 @@ wasi_fd_readdir(wasm_exec_env_t exec_env, wasi_fd_t fd, void *buf, if (!validate_native_addr(bufused_app, sizeof(uint32))) return (wasi_errno_t)-1; - err = wasmtime_ssp_fd_readdir(curfds, fd, buf, buf_len, cookie, &bufused); + err = wasmtime_ssp_fd_readdir(exec_env, curfds, fd, buf, buf_len, cookie, + &bufused); if (err) return err; @@ -803,8 +812,8 @@ wasi_path_readlink(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path, if (!validate_native_addr(bufused_app, sizeof(uint32))) return (wasi_errno_t)-1; - err = wasmtime_ssp_path_readlink(curfds, fd, path, path_len, buf, buf_len, - &bufused); + err = wasmtime_ssp_path_readlink(exec_env, curfds, fd, path, path_len, buf, + buf_len, &bufused); if (err) return err; @@ -824,8 +833,9 @@ wasi_path_rename(wasm_exec_env_t exec_env, wasi_fd_t old_fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_path_rename(curfds, old_fd, old_path, old_path_len, - new_fd, new_path, new_path_len); + return wasmtime_ssp_path_rename(exec_env, curfds, old_fd, old_path, + old_path_len, new_fd, new_path, + new_path_len); } static wasi_errno_t @@ -842,7 +852,7 @@ wasi_fd_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!validate_native_addr(filestat, sizeof(wasi_filestat_t))) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_filestat_get(curfds, fd, filestat); + return wasmtime_ssp_fd_filestat_get(exec_env, curfds, fd, filestat); } static wasi_errno_t @@ -857,8 +867,8 @@ wasi_fd_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_filestat_set_times(curfds, fd, st_atim, st_mtim, - fstflags); + return wasmtime_ssp_fd_filestat_set_times(exec_env, curfds, fd, st_atim, + st_mtim, fstflags); } static wasi_errno_t @@ -872,7 +882,7 @@ wasi_fd_filestat_set_size(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_fd_filestat_set_size(curfds, fd, st_size); + return wasmtime_ssp_fd_filestat_set_size(exec_env, curfds, fd, st_size); } static wasi_errno_t @@ -890,8 +900,8 @@ wasi_path_filestat_get(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!validate_native_addr(filestat, sizeof(wasi_filestat_t))) return (wasi_errno_t)-1; - return wasmtime_ssp_path_filestat_get(curfds, fd, flags, path, path_len, - filestat); + return wasmtime_ssp_path_filestat_get(exec_env, curfds, fd, flags, path, + path_len, filestat); } static wasi_errno_t @@ -907,8 +917,9 @@ wasi_path_filestat_set_times(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_path_filestat_set_times( - curfds, fd, flags, path, path_len, st_atim, st_mtim, fstflags); + return wasmtime_ssp_path_filestat_set_times(exec_env, curfds, fd, flags, + path, path_len, st_atim, + st_mtim, fstflags); } static wasi_errno_t @@ -924,8 +935,8 @@ wasi_path_symlink(wasm_exec_env_t exec_env, const char *old_path, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_path_symlink(curfds, prestats, old_path, old_path_len, - fd, new_path, new_path_len); + return wasmtime_ssp_path_symlink(exec_env, curfds, prestats, old_path, + old_path_len, fd, new_path, new_path_len); } static wasi_errno_t @@ -939,7 +950,7 @@ wasi_path_unlink_file(wasm_exec_env_t exec_env, wasi_fd_t fd, const char *path, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_path_unlink_file(curfds, fd, path, path_len); + return wasmtime_ssp_path_unlink_file(exec_env, curfds, fd, path, path_len); } static wasi_errno_t @@ -953,7 +964,8 @@ wasi_path_remove_directory(wasm_exec_env_t exec_env, wasi_fd_t fd, if (!wasi_ctx) return (wasi_errno_t)-1; - return wasmtime_ssp_path_remove_directory(curfds, fd, path, path_len); + return wasmtime_ssp_path_remove_directory(exec_env, curfds, fd, path, + path_len); } #if WASM_ENABLE_THREAD_MGR != 0 @@ -1024,8 +1036,8 @@ execute_interruptible_poll_oneoff( /* update timeout for clock subscription events */ update_clock_subscription_data( in_copy, nsubscriptions, min_uint64(time_quant, timeout - elapsed)); - err = wasmtime_ssp_poll_oneoff(curfds, in_copy, out, nsubscriptions, - nevents); + err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in_copy, out, + nsubscriptions, nevents); elapsed += time_quant; if (err) { @@ -1077,7 +1089,8 @@ wasi_poll_oneoff(wasm_exec_env_t exec_env, const wasi_subscription_t *in, return (wasi_errno_t)-1; #if WASM_ENABLE_THREAD_MGR == 0 - err = wasmtime_ssp_poll_oneoff(curfds, in, out, nsubscriptions, &nevents); + err = wasmtime_ssp_poll_oneoff(exec_env, curfds, in, out, nsubscriptions, + &nevents); #else err = execute_interruptible_poll_oneoff(curfds, in, out, nsubscriptions, &nevents, exec_env); @@ -1131,7 +1144,7 @@ wasi_sock_accept(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_fdflags_t flags, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasi_ssp_sock_accept(curfds, fd, flags, fd_new); + return wasi_ssp_sock_accept(exec_env, curfds, fd, flags, fd_new); } static wasi_errno_t @@ -1150,7 +1163,7 @@ wasi_sock_addr_local(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasi_ssp_sock_addr_local(curfds, fd, addr); + return wasi_ssp_sock_addr_local(exec_env, curfds, fd, addr); } static wasi_errno_t @@ -1169,7 +1182,7 @@ wasi_sock_addr_remote(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasi_ssp_sock_addr_remote(curfds, fd, addr); + return wasi_ssp_sock_addr_remote(exec_env, curfds, fd, addr); } static wasi_errno_t @@ -1190,8 +1203,8 @@ wasi_sock_addr_resolve(wasm_exec_env_t exec_env, const char *host, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); ns_lookup_list = wasi_ctx_get_ns_lookup_list(wasi_ctx); - return wasi_ssp_sock_addr_resolve(curfds, ns_lookup_list, host, service, - hints, addr_info, addr_info_size, + return wasi_ssp_sock_addr_resolve(exec_env, curfds, ns_lookup_list, host, + service, hints, addr_info, addr_info_size, max_info_size); } @@ -1209,7 +1222,7 @@ wasi_sock_bind(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_addr_t *addr) curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); addr_pool = wasi_ctx_get_addr_pool(module_inst, wasi_ctx); - return wasi_ssp_sock_bind(curfds, addr_pool, fd, addr); + return wasi_ssp_sock_bind(exec_env, curfds, addr_pool, fd, addr); } static wasi_errno_t @@ -1232,7 +1245,7 @@ wasi_sock_connect(wasm_exec_env_t exec_env, wasi_fd_t fd, wasi_addr_t *addr) curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); addr_pool = wasi_ctx_get_addr_pool(module_inst, wasi_ctx); - return wasi_ssp_sock_connect(curfds, addr_pool, fd, addr); + return wasi_ssp_sock_connect(exec_env, curfds, addr_pool, fd, addr); } static wasi_errno_t @@ -1251,7 +1264,7 @@ wasi_sock_get_broadcast(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_broadcast(curfds, fd, is_enabled); + return wasmtime_ssp_sock_get_broadcast(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1270,7 +1283,7 @@ wasi_sock_get_keep_alive(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_keep_alive(curfds, fd, is_enabled); + return wasmtime_ssp_sock_get_keep_alive(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1290,7 +1303,8 @@ wasi_sock_get_linger(wasm_exec_env_t exec_env, wasi_fd_t fd, bool *is_enabled, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_linger(curfds, fd, is_enabled, linger_s); + return wasmtime_ssp_sock_get_linger(exec_env, curfds, fd, is_enabled, + linger_s); } static wasi_errno_t @@ -1309,7 +1323,7 @@ wasi_sock_get_recv_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_recv_buf_size(curfds, fd, size); + return wasmtime_ssp_sock_get_recv_buf_size(exec_env, curfds, fd, size); } static wasi_errno_t @@ -1328,7 +1342,7 @@ wasi_sock_get_recv_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_recv_timeout(curfds, fd, timeout_us); + return wasmtime_ssp_sock_get_recv_timeout(exec_env, curfds, fd, timeout_us); } static wasi_errno_t @@ -1347,7 +1361,7 @@ wasi_sock_get_reuse_addr(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_reuse_addr(curfds, fd, is_enabled); + return wasmtime_ssp_sock_get_reuse_addr(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1366,7 +1380,7 @@ wasi_sock_get_reuse_port(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_reuse_port(curfds, fd, is_enabled); + return wasmtime_ssp_sock_get_reuse_port(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1385,7 +1399,7 @@ wasi_sock_get_send_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_send_buf_size(curfds, fd, size); + return wasmtime_ssp_sock_get_send_buf_size(exec_env, curfds, fd, size); } static wasi_errno_t @@ -1404,7 +1418,7 @@ wasi_sock_get_send_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_send_timeout(curfds, fd, timeout_us); + return wasmtime_ssp_sock_get_send_timeout(exec_env, curfds, fd, timeout_us); } static wasi_errno_t @@ -1423,7 +1437,8 @@ wasi_sock_get_tcp_fastopen_connect(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_tcp_fastopen_connect(curfds, fd, is_enabled); + return wasmtime_ssp_sock_get_tcp_fastopen_connect(exec_env, curfds, fd, + is_enabled); } static wasi_errno_t @@ -1442,7 +1457,7 @@ wasi_sock_get_tcp_no_delay(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_tcp_no_delay(curfds, fd, is_enabled); + return wasmtime_ssp_sock_get_tcp_no_delay(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1461,7 +1476,8 @@ wasi_sock_get_tcp_quick_ack(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_tcp_quick_ack(curfds, fd, is_enabled); + return wasmtime_ssp_sock_get_tcp_quick_ack(exec_env, curfds, fd, + is_enabled); } static wasi_errno_t @@ -1480,7 +1496,7 @@ wasi_sock_get_tcp_keep_idle(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_tcp_keep_idle(curfds, fd, time_s); + return wasmtime_ssp_sock_get_tcp_keep_idle(exec_env, curfds, fd, time_s); } static wasi_errno_t @@ -1499,7 +1515,7 @@ wasi_sock_get_tcp_keep_intvl(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_tcp_keep_intvl(curfds, fd, time_s); + return wasmtime_ssp_sock_get_tcp_keep_intvl(exec_env, curfds, fd, time_s); } static wasi_errno_t @@ -1518,7 +1534,7 @@ wasi_sock_get_ip_multicast_loop(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_ip_multicast_loop(curfds, fd, ipv6, + return wasmtime_ssp_sock_get_ip_multicast_loop(exec_env, curfds, fd, ipv6, is_enabled); } @@ -1537,7 +1553,7 @@ wasi_sock_get_ip_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd, uint8_t *ttl_s) curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_ip_ttl(curfds, fd, ttl_s); + return wasmtime_ssp_sock_get_ip_ttl(exec_env, curfds, fd, ttl_s); } static wasi_errno_t @@ -1556,7 +1572,7 @@ wasi_sock_get_ip_multicast_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_ip_multicast_ttl(curfds, fd, ttl_s); + return wasmtime_ssp_sock_get_ip_multicast_ttl(exec_env, curfds, fd, ttl_s); } static wasi_errno_t @@ -1575,7 +1591,7 @@ wasi_sock_get_ipv6_only(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_get_ipv6_only(curfds, fd, is_enabled); + return wasmtime_ssp_sock_get_ipv6_only(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1590,7 +1606,7 @@ wasi_sock_listen(wasm_exec_env_t exec_env, wasi_fd_t fd, uint32 backlog) curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasi_ssp_sock_listen(curfds, fd, backlog); + return wasi_ssp_sock_listen(exec_env, curfds, fd, backlog); } static wasi_errno_t @@ -1607,7 +1623,7 @@ wasi_sock_open(wasm_exec_env_t exec_env, wasi_fd_t poolfd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasi_ssp_sock_open(curfds, poolfd, af, socktype, sockfd); + return wasi_ssp_sock_open(exec_env, curfds, poolfd, af, socktype, sockfd); } static wasi_errno_t @@ -1622,7 +1638,7 @@ wasi_sock_set_broadcast(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled) curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_broadcast(curfds, fd, is_enabled); + return wasmtime_ssp_sock_set_broadcast(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1638,7 +1654,7 @@ wasi_sock_set_keep_alive(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_keep_alive(curfds, fd, is_enabled); + return wasmtime_ssp_sock_set_keep_alive(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1654,7 +1670,8 @@ wasi_sock_set_linger(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_linger(curfds, fd, is_enabled, linger_s); + return wasmtime_ssp_sock_set_linger(exec_env, curfds, fd, is_enabled, + linger_s); } static wasi_errno_t @@ -1669,7 +1686,7 @@ wasi_sock_set_recv_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd, size_t size) curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_recv_buf_size(curfds, fd, size); + return wasmtime_ssp_sock_set_recv_buf_size(exec_env, curfds, fd, size); } static wasi_errno_t @@ -1685,7 +1702,7 @@ wasi_sock_set_recv_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_recv_timeout(curfds, fd, timeout_us); + return wasmtime_ssp_sock_set_recv_timeout(exec_env, curfds, fd, timeout_us); } static wasi_errno_t @@ -1701,7 +1718,7 @@ wasi_sock_set_reuse_addr(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_reuse_addr(curfds, fd, is_enabled); + return wasmtime_ssp_sock_set_reuse_addr(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1717,7 +1734,7 @@ wasi_sock_set_reuse_port(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_reuse_port(curfds, fd, is_enabled); + return wasmtime_ssp_sock_set_reuse_port(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1732,7 +1749,7 @@ wasi_sock_set_send_buf_size(wasm_exec_env_t exec_env, wasi_fd_t fd, size_t size) curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_send_buf_size(curfds, fd, size); + return wasmtime_ssp_sock_set_send_buf_size(exec_env, curfds, fd, size); } static wasi_errno_t @@ -1748,7 +1765,7 @@ wasi_sock_set_send_timeout(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_send_timeout(curfds, fd, timeout_us); + return wasmtime_ssp_sock_set_send_timeout(exec_env, curfds, fd, timeout_us); } static wasi_errno_t @@ -1764,7 +1781,8 @@ wasi_sock_set_tcp_fastopen_connect(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_tcp_fastopen_connect(curfds, fd, is_enabled); + return wasmtime_ssp_sock_set_tcp_fastopen_connect(exec_env, curfds, fd, + is_enabled); } static wasi_errno_t @@ -1780,7 +1798,7 @@ wasi_sock_set_tcp_no_delay(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_tcp_no_delay(curfds, fd, is_enabled); + return wasmtime_ssp_sock_set_tcp_no_delay(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -1796,7 +1814,8 @@ wasi_sock_set_tcp_quick_ack(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_tcp_quick_ack(curfds, fd, is_enabled); + return wasmtime_ssp_sock_set_tcp_quick_ack(exec_env, curfds, fd, + is_enabled); } static wasi_errno_t @@ -1812,7 +1831,7 @@ wasi_sock_set_tcp_keep_idle(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_tcp_keep_idle(curfds, fd, time_s); + return wasmtime_ssp_sock_set_tcp_keep_idle(exec_env, curfds, fd, time_s); } static wasi_errno_t @@ -1828,7 +1847,7 @@ wasi_sock_set_tcp_keep_intvl(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_tcp_keep_intvl(curfds, fd, time_s); + return wasmtime_ssp_sock_set_tcp_keep_intvl(exec_env, curfds, fd, time_s); } static wasi_errno_t @@ -1844,7 +1863,7 @@ wasi_sock_set_ip_multicast_loop(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_ip_multicast_loop(curfds, fd, ipv6, + return wasmtime_ssp_sock_set_ip_multicast_loop(exec_env, curfds, fd, ipv6, is_enabled); } @@ -1865,8 +1884,8 @@ wasi_sock_set_ip_add_membership(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_ip_add_membership(curfds, fd, imr_multiaddr, - imr_interface); + return wasmtime_ssp_sock_set_ip_add_membership( + exec_env, curfds, fd, imr_multiaddr, imr_interface); } static wasi_errno_t @@ -1886,8 +1905,8 @@ wasi_sock_set_ip_drop_membership(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_ip_drop_membership(curfds, fd, imr_multiaddr, - imr_interface); + return wasmtime_ssp_sock_set_ip_drop_membership( + exec_env, curfds, fd, imr_multiaddr, imr_interface); } static wasi_errno_t @@ -1902,7 +1921,7 @@ wasi_sock_set_ip_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd, uint8_t ttl_s) curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_ip_ttl(curfds, fd, ttl_s); + return wasmtime_ssp_sock_set_ip_ttl(exec_env, curfds, fd, ttl_s); } static wasi_errno_t @@ -1918,7 +1937,7 @@ wasi_sock_set_ip_multicast_ttl(wasm_exec_env_t exec_env, wasi_fd_t fd, curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_ip_multicast_ttl(curfds, fd, ttl_s); + return wasmtime_ssp_sock_set_ip_multicast_ttl(exec_env, curfds, fd, ttl_s); } static wasi_errno_t @@ -1933,7 +1952,7 @@ wasi_sock_set_ipv6_only(wasm_exec_env_t exec_env, wasi_fd_t fd, bool is_enabled) curfds = wasi_ctx_get_curfds(module_inst, wasi_ctx); - return wasmtime_ssp_sock_set_ipv6_only(curfds, fd, is_enabled); + return wasmtime_ssp_sock_set_ipv6_only(exec_env, curfds, fd, is_enabled); } static wasi_errno_t @@ -2051,8 +2070,9 @@ wasi_sock_recv_from(wasm_exec_env_t exec_env, wasi_fd_t sock, memset(buf_begin, 0, total_size); *ro_data_len = 0; - err = wasmtime_ssp_sock_recv_from(curfds, sock, buf_begin, total_size, - ri_flags, src_addr, &recv_bytes); + err = wasmtime_ssp_sock_recv_from(exec_env, curfds, sock, buf_begin, + total_size, ri_flags, src_addr, + &recv_bytes); if (err != __WASI_ESUCCESS) { goto fail; } @@ -2151,7 +2171,8 @@ wasi_sock_send(wasm_exec_env_t exec_env, wasi_fd_t sock, return err; *so_data_len = 0; - err = wasmtime_ssp_sock_send(curfds, sock, buf, buf_size, &send_bytes); + err = wasmtime_ssp_sock_send(exec_env, curfds, sock, buf, buf_size, + &send_bytes); *so_data_len = (uint32)send_bytes; wasm_runtime_free(buf); @@ -2191,8 +2212,8 @@ wasi_sock_send_to(wasm_exec_env_t exec_env, wasi_fd_t sock, return err; *so_data_len = 0; - err = wasmtime_ssp_sock_send_to(curfds, addr_pool, sock, buf, buf_size, - si_flags, dest_addr, &send_bytes); + err = wasmtime_ssp_sock_send_to(exec_env, curfds, addr_pool, sock, buf, + buf_size, si_flags, dest_addr, &send_bytes); *so_data_len = (uint32)send_bytes; wasm_runtime_free(buf); @@ -2210,7 +2231,7 @@ wasi_sock_shutdown(wasm_exec_env_t exec_env, wasi_fd_t sock, wasi_sdflags_t how) if (!wasi_ctx) return __WASI_EINVAL; - return wasmtime_ssp_sock_shutdown(curfds, sock); + return wasmtime_ssp_sock_shutdown(exec_env, curfds, sock); } static wasi_errno_t diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.h similarity index 70% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.h index be509576b06..d958fa39cb0 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.h @@ -6,7 +6,6 @@ #ifndef _LIBC_WASI_WRAPPER_H #define _LIBC_WASI_WRAPPER_H -#include "wasmtime_ssp.h" #include "posix.h" #ifdef __cplusplus @@ -19,7 +18,16 @@ typedef __wasi_advice_t wasi_advice_t; typedef __wasi_ciovec_t wasi_ciovec_t; typedef __wasi_clockid_t wasi_clockid_t; typedef __wasi_dircookie_t wasi_dircookie_t; -typedef __wasi_errno_t wasi_errno_t; +// __wasi_errno_t is typedef'd to uint16 which is correct according to the ABI +// specification. However, in WASM, the smallest integer type is int32. If we +// return uint16, we would rely on language SDKs to implement the correct +// behaviour of casting to uint16 before checking the value or using it any way. +// Failure to do so can cause tricky bugs as the upper 16 bits of the error +// result are not guaranteed to be zero'ed by us so the result essentially +// contains garbage from the WASM app perspective. To prevent this, we return +// uint32 directly instead so as not to be reliant on the correct behaviour of +// any current/future WASI SDK implemenations. +typedef uint32_t wasi_errno_t; typedef __wasi_event_t wasi_event_t; typedef __wasi_exitcode_t wasi_exitcode_t; typedef __wasi_fdflags_t wasi_fdflags_t; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/LICENSE b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/LICENSE similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/LICENSE rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/LICENSE diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/LICENSE b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/LICENSE similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/LICENSE rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/LICENSE diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h new file mode 100644 index 00000000000..ed8463866f5 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/include/wasmtime_ssp.h @@ -0,0 +1,606 @@ +/* + * Part of the Wasmtime Project, under the Apache License v2.0 with + * LLVM Exceptions. See + * https://github.com/bytecodealliance/wasmtime/blob/main/LICENSE + * for license information. + */ + +/** + * The defitions of type, macro and structure in this file should be + * consistent with those in wasi-libc: + * https://github.com/WebAssembly/wasi-libc/blob/main/libc-bottom-half/headers/public/wasi/api.h + */ + +#ifndef WASMTIME_SSP_H +#define WASMTIME_SSP_H + +#include +#include +#include + +#include "bh_platform.h" +#include "wasm_export.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(WASMTIME_SSP_WASI_API) +#define WASMTIME_SSP_SYSCALL_NAME(name) asm("__wasi_" #name) +#else +#define WASMTIME_SSP_SYSCALL_NAME(name) +#endif + +__wasi_errno_t +wasmtime_ssp_args_get(struct argv_environ_values *arg_environ, char **argv, + char *argv_buf) + WASMTIME_SSP_SYSCALL_NAME(args_get) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_args_sizes_get(struct argv_environ_values *arg_environ, + size_t *argc, size_t *argv_buf_size) + WASMTIME_SSP_SYSCALL_NAME(args_sizes_get) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_environ_get(struct argv_environ_values *arg_environ, + char **environs, char *environ_buf) + WASMTIME_SSP_SYSCALL_NAME(environ_get) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_environ_sizes_get(struct argv_environ_values *arg_environ, + size_t *environ_count, size_t *environ_buf_size) + WASMTIME_SSP_SYSCALL_NAME(environ_sizes_get) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_prestat_get(struct fd_prestats *prestats, __wasi_fd_t fd, + __wasi_prestat_t *buf) + WASMTIME_SSP_SYSCALL_NAME(fd_prestat_get) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_prestat_dir_name(struct fd_prestats *prestats, __wasi_fd_t fd, + char *path, size_t path_len) + WASMTIME_SSP_SYSCALL_NAME(fd_prestat_dir_name) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_close(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct fd_prestats *prestats, __wasi_fd_t fd) + WASMTIME_SSP_SYSCALL_NAME(fd_close) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_datasync(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd) + WASMTIME_SSP_SYSCALL_NAME(fd_datasync) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_pread(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, const __wasi_iovec_t *iovs, + size_t iovs_len, __wasi_filesize_t offset, size_t *nread) + WASMTIME_SSP_SYSCALL_NAME(fd_pread) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_pwrite(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, const __wasi_ciovec_t *iovs, + size_t iovs_len, __wasi_filesize_t offset, + size_t *nwritten) + WASMTIME_SSP_SYSCALL_NAME(fd_pwrite) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_read(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, const __wasi_iovec_t *iovs, + size_t iovs_len, size_t *nread) + WASMTIME_SSP_SYSCALL_NAME(fd_read) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_renumber(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct fd_prestats *prestats, __wasi_fd_t from, + __wasi_fd_t to) + WASMTIME_SSP_SYSCALL_NAME(fd_renumber) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_seek(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_filedelta_t offset, + __wasi_whence_t whence, __wasi_filesize_t *newoffset) + WASMTIME_SSP_SYSCALL_NAME(fd_seek) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_tell(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_filesize_t *newoffset) + WASMTIME_SSP_SYSCALL_NAME(fd_tell) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_fdstat_get(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_fdstat_t *buf) + WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_get) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_fdstat_set_flags(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_fdflags_t flags) + WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_set_flags) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_fdstat_set_rights(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_rights_t fs_rights_base, + __wasi_rights_t fs_rights_inheriting) + WASMTIME_SSP_SYSCALL_NAME(fd_fdstat_set_rights) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_sync(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd) + WASMTIME_SSP_SYSCALL_NAME(fd_sync) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_write(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, const __wasi_ciovec_t *iovs, + size_t iovs_len, size_t *nwritten) + WASMTIME_SSP_SYSCALL_NAME(fd_write) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_advise(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_filesize_t offset, + __wasi_filesize_t len, __wasi_advice_t advice) + WASMTIME_SSP_SYSCALL_NAME(fd_advise) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_allocate(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_filesize_t offset, + __wasi_filesize_t len) + WASMTIME_SSP_SYSCALL_NAME(fd_allocate) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_path_create_directory(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + const char *path, size_t path_len) + WASMTIME_SSP_SYSCALL_NAME(path_create_directory) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_path_link(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct fd_prestats *prestats, __wasi_fd_t old_fd, + __wasi_lookupflags_t old_flags, const char *old_path, + size_t old_path_len, __wasi_fd_t new_fd, + const char *new_path, size_t new_path_len) + WASMTIME_SSP_SYSCALL_NAME(path_link) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_path_open(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t dirfd, __wasi_lookupflags_t dirflags, + const char *path, size_t path_len, + __wasi_oflags_t oflags, __wasi_rights_t fs_rights_base, + __wasi_rights_t fs_rights_inheriting, + __wasi_fdflags_t fs_flags, __wasi_fd_t *fd) + WASMTIME_SSP_SYSCALL_NAME(path_open) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_readdir(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, void *buf, size_t buf_len, + __wasi_dircookie_t cookie, size_t *bufused) + WASMTIME_SSP_SYSCALL_NAME(fd_readdir) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_path_readlink(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, const char *path, size_t path_len, + char *buf, size_t buf_len, size_t *bufused) + WASMTIME_SSP_SYSCALL_NAME(path_readlink) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_path_rename(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t old_fd, const char *old_path, + size_t old_path_len, __wasi_fd_t new_fd, + const char *new_path, size_t new_path_len) + WASMTIME_SSP_SYSCALL_NAME(path_rename) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_filestat_get(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_filestat_t *buf) + WASMTIME_SSP_SYSCALL_NAME(fd_filestat_get) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_filestat_set_times(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_timestamp_t st_atim, + __wasi_timestamp_t st_mtim, + __wasi_fstflags_t fstflags) + WASMTIME_SSP_SYSCALL_NAME(fd_filestat_set_times) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_fd_filestat_set_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_filesize_t st_size) + WASMTIME_SSP_SYSCALL_NAME(fd_filestat_set_size) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_path_filestat_get(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_lookupflags_t flags, const char *path, + size_t path_len, __wasi_filestat_t *buf) + WASMTIME_SSP_SYSCALL_NAME(path_filestat_get) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_path_filestat_set_times(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_lookupflags_t flags, + const char *path, size_t path_len, + __wasi_timestamp_t st_atim, + __wasi_timestamp_t st_mtim, + __wasi_fstflags_t fstflags) + WASMTIME_SSP_SYSCALL_NAME(path_filestat_set_times) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_path_symlink(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct fd_prestats *prestats, const char *old_path, + size_t old_path_len, __wasi_fd_t fd, + const char *new_path, size_t new_path_len) + WASMTIME_SSP_SYSCALL_NAME(path_symlink) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_path_unlink_file(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, const char *path, size_t path_len) + WASMTIME_SSP_SYSCALL_NAME(path_unlink_file) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_path_remove_directory(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + const char *path, size_t path_len) + WASMTIME_SSP_SYSCALL_NAME(path_remove_directory) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds, + const __wasi_subscription_t *in, __wasi_event_t *out, + size_t nsubscriptions, size_t *nevents) + WASMTIME_SSP_SYSCALL_NAME(poll_oneoff) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_random_get(void *buf, size_t buf_len) + WASMTIME_SSP_SYSCALL_NAME(random_get) WARN_UNUSED; + +__wasi_errno_t +wasi_ssp_sock_accept(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_fdflags_t flags, + __wasi_fd_t *fd_new) WARN_UNUSED; + +__wasi_errno_t +wasi_ssp_sock_addr_local(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_addr_t *addr) WARN_UNUSED; + +__wasi_errno_t +wasi_ssp_sock_addr_remote(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_addr_t *addr) WARN_UNUSED; + +__wasi_errno_t +wasi_ssp_sock_open(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t poolfd, __wasi_address_family_t af, + __wasi_sock_type_t socktype, + __wasi_fd_t *sockfd) WARN_UNUSED; + +__wasi_errno_t +wasi_ssp_sock_bind(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct addr_pool *addr_pool, __wasi_fd_t fd, + __wasi_addr_t *addr) WARN_UNUSED; + +__wasi_errno_t +wasi_ssp_sock_addr_resolve(wasm_exec_env_t exec_env, struct fd_table *curfds, + char **ns_lookup_list, const char *host, + const char *service, __wasi_addr_info_hints_t *hints, + __wasi_addr_info_t *addr_info, + __wasi_size_t addr_info_size, + __wasi_size_t *max_info_size) WARN_UNUSED; + +__wasi_errno_t +wasi_ssp_sock_connect(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct addr_pool *addr_pool, __wasi_fd_t fd, + __wasi_addr_t *addr) WARN_UNUSED; + +__wasi_errno_t +wasi_ssp_sock_get_recv_buf_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_size_t *size) WARN_UNUSED; + +__wasi_errno_t +wasi_ssp_sock_get_reuse_addr(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, uint8_t *reuse) WARN_UNUSED; + +__wasi_errno_t +wasi_ssp_sock_get_reuse_port(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, uint8_t *reuse) WARN_UNUSED; + +__wasi_errno_t +wasi_ssp_sock_get_send_buf_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_size_t *size) WARN_UNUSED; + +__wasi_errno_t +wasi_ssp_sock_set_recv_buf_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_size_t size) WARN_UNUSED; + +__wasi_errno_t +wasi_ssp_sock_set_reuse_addr(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, uint8_t reuse) WARN_UNUSED; + +__wasi_errno_t +wasi_ssp_sock_set_reuse_port(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, uint8_t reuse) WARN_UNUSED; + +__wasi_errno_t +wasi_ssp_sock_set_send_buf_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_size_t size) WARN_UNUSED; + +__wasi_errno_t +wasi_ssp_sock_listen(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_size_t backlog) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_recv(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock, void *buf, size_t buf_len, + size_t *recv_len) + WASMTIME_SSP_SYSCALL_NAME(sock_recv) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_recv_from(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock, void *buf, size_t buf_len, + __wasi_riflags_t ri_flags, __wasi_addr_t *src_addr, + size_t *recv_len) + WASMTIME_SSP_SYSCALL_NAME(sock_recv_from) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_send(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock, const void *buf, size_t buf_len, + size_t *sent_len) + WASMTIME_SSP_SYSCALL_NAME(sock_send) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_send_to(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct addr_pool *addr_pool, __wasi_fd_t sock, + const void *buf, size_t buf_len, + __wasi_siflags_t si_flags, + const __wasi_addr_t *dest_addr, size_t *sent_len) + WASMTIME_SSP_SYSCALL_NAME(sock_send_to) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_shutdown(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock) + WASMTIME_SSP_SYSCALL_NAME(sock_shutdown) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_recv_timeout(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + uint64_t timeout_us) + WASMTIME_SSP_SYSCALL_NAME(sock_set_recv_timeout) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_get_recv_timeout(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + uint64_t *timeout_us) + WASMTIME_SSP_SYSCALL_NAME(sock_get_recv_timeout) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_send_timeout(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + uint64_t timeout_us) + WASMTIME_SSP_SYSCALL_NAME(sock_set_send_timeout) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_get_send_timeout(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + uint64_t *timeout_us) + WASMTIME_SSP_SYSCALL_NAME(sock_get_send_timeout) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_send_buf_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + size_t bufsiz) + WASMTIME_SSP_SYSCALL_NAME(sock_set_send_buf_size) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_get_send_buf_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + size_t *bufsiz) + WASMTIME_SSP_SYSCALL_NAME(sock_get_send_buf_size) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_recv_buf_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + size_t bufsiz) + WASMTIME_SSP_SYSCALL_NAME(sock_set_recv_buf_size) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_get_recv_buf_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + size_t *bufsiz) + WASMTIME_SSP_SYSCALL_NAME(sock_get_recv_buf_size) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_keep_alive(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + bool is_enabled) + WASMTIME_SSP_SYSCALL_NAME(sock_set_keep_alive) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_get_keep_alive(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + bool *is_enabled) + WASMTIME_SSP_SYSCALL_NAME(sock_get_keep_alive) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_reuse_addr(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + bool is_enabled) + WASMTIME_SSP_SYSCALL_NAME(sock_set_reuse_addr) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_get_reuse_addr(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + bool *is_enabled) + WASMTIME_SSP_SYSCALL_NAME(sock_get_reuse_addr) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_reuse_port(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + bool is_enabled) + WASMTIME_SSP_SYSCALL_NAME(sock_set_reuse_port) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_get_reuse_port(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + bool *is_enabled) + WASMTIME_SSP_SYSCALL_NAME(sock_get_reuse_port) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_linger(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock, bool is_enabled, int linger_s) + WASMTIME_SSP_SYSCALL_NAME(sock_set_linger) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_get_linger(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock, bool *is_enabled, int *linger_s) + WASMTIME_SSP_SYSCALL_NAME(sock_get_linger) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_broadcast(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + bool is_enabled) + WASMTIME_SSP_SYSCALL_NAME(sock_set_broadcast) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_get_broadcast(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + bool *is_enabled) + WASMTIME_SSP_SYSCALL_NAME(sock_get_broadcast) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_tcp_no_delay(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + bool is_enabled) + WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_no_delay) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_get_tcp_no_delay(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + bool *is_enabled) + WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_no_delay) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_tcp_quick_ack(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + bool is_enabled) + WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_quick_ack) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_get_tcp_quick_ack(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + bool *is_enabled) + WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_quick_ack) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_tcp_keep_idle(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + uint32_t time_s) + WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_keep_idle) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_get_tcp_keep_idle(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + uint32_t *time_s) + WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_keep_idle) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_tcp_keep_intvl(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + uint32_t time_s) + WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_keep_intvl) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_get_tcp_keep_intvl(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + uint32_t *time_s) + WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_keep_intvl) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_tcp_fastopen_connect(wasm_exec_env_t exec_env, + struct fd_table *curfds, + __wasi_fd_t sock, bool is_enabled) + WASMTIME_SSP_SYSCALL_NAME(sock_set_tcp_fastopen_connect) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_get_tcp_fastopen_connect(wasm_exec_env_t exec_env, + struct fd_table *curfds, + __wasi_fd_t sock, bool *is_enabled) + WASMTIME_SSP_SYSCALL_NAME(sock_get_tcp_fastopen_connect) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_ip_multicast_loop(wasm_exec_env_t exec_env, + struct fd_table *curfds, + __wasi_fd_t sock, bool ipv6, + bool is_enabled) + WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_multicast_loop) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_get_ip_multicast_loop(wasm_exec_env_t exec_env, + struct fd_table *curfds, + __wasi_fd_t sock, bool ipv6, + bool *is_enabled) + WASMTIME_SSP_SYSCALL_NAME(sock_get_ip_multicast_loop) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_ip_add_membership(wasm_exec_env_t exec_env, + struct fd_table *curfds, + __wasi_fd_t sock, + __wasi_addr_ip_t *imr_multiaddr, + uint32_t imr_interface) + WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_add_membership) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_ip_drop_membership(wasm_exec_env_t exec_env, + struct fd_table *curfds, + __wasi_fd_t sock, + __wasi_addr_ip_t *imr_multiaddr, + uint32_t imr_interface) + WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_drop_membership) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_ip_ttl(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock, uint8_t ttl_s) + WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_ttl) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_get_ip_ttl(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock, uint8_t *ttl_s) + WASMTIME_SSP_SYSCALL_NAME(sock_get_ip_ttl) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_ip_multicast_ttl(wasm_exec_env_t exec_env, + struct fd_table *curfds, + __wasi_fd_t sock, uint8_t ttl_s) + WASMTIME_SSP_SYSCALL_NAME(sock_set_ip_multicast_ttl) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_get_ip_multicast_ttl(wasm_exec_env_t exec_env, + struct fd_table *curfds, + __wasi_fd_t sock, uint8_t *ttl_s) + WASMTIME_SSP_SYSCALL_NAME(sock_get_ip_multicast_ttl) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_set_ipv6_only(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + bool is_enabled) + WASMTIME_SSP_SYSCALL_NAME(sock_set_ipv6_only) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sock_get_ipv6_only(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t sock, + bool *is_enabled) + WASMTIME_SSP_SYSCALL_NAME(sock_get_ipv6_only) WARN_UNUSED; + +__wasi_errno_t +wasmtime_ssp_sched_yield(void) + WASMTIME_SSP_SYSCALL_NAME(sched_yield) WARN_UNUSED; + +#ifdef __cplusplus +} +#endif + +#undef WASMTIME_SSP_SYSCALL_NAME + +#endif /* end of WASMTIME_SSP_H */ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/LICENSE b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/LICENSE similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/LICENSE rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/LICENSE diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c new file mode 100644 index 00000000000..ec1481c2ef0 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.c @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2023 Midokura Japan KK. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include + +#include "ssp_config.h" +#include "blocking_op.h" + +__wasi_errno_t +blocking_op_close(wasm_exec_env_t exec_env, os_file_handle handle, + bool is_stdio) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + return __WASI_EINTR; + } + __wasi_errno_t error = os_close(handle, is_stdio); + wasm_runtime_end_blocking_op(exec_env); + return error; +} + +__wasi_errno_t +blocking_op_readv(wasm_exec_env_t exec_env, os_file_handle handle, + const struct __wasi_iovec_t *iov, int iovcnt, size_t *nread) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + return __WASI_EINTR; + } + __wasi_errno_t error = os_readv(handle, iov, iovcnt, nread); + wasm_runtime_end_blocking_op(exec_env); + return error; +} + +__wasi_errno_t +blocking_op_preadv(wasm_exec_env_t exec_env, os_file_handle handle, + const struct __wasi_iovec_t *iov, int iovcnt, + __wasi_filesize_t offset, size_t *nread) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + return __WASI_EINTR; + } + __wasi_errno_t ret = os_preadv(handle, iov, iovcnt, offset, nread); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} + +__wasi_errno_t +blocking_op_writev(wasm_exec_env_t exec_env, os_file_handle handle, + const struct __wasi_ciovec_t *iov, int iovcnt, + size_t *nwritten) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + return __WASI_EINTR; + } + __wasi_errno_t error = os_writev(handle, iov, iovcnt, nwritten); + wasm_runtime_end_blocking_op(exec_env); + return error; +} + +__wasi_errno_t +blocking_op_pwritev(wasm_exec_env_t exec_env, os_file_handle handle, + const struct __wasi_ciovec_t *iov, int iovcnt, + __wasi_filesize_t offset, size_t *nwritten) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + return __WASI_EINTR; + } + __wasi_errno_t error = os_pwritev(handle, iov, iovcnt, offset, nwritten); + wasm_runtime_end_blocking_op(exec_env); + return error; +} + +int +blocking_op_socket_accept(wasm_exec_env_t exec_env, bh_socket_t server_sock, + bh_socket_t *sockp, void *addr, + unsigned int *addrlenp) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + errno = EINTR; + return -1; + } + int ret = os_socket_accept(server_sock, sockp, addr, addrlenp); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} + +int +blocking_op_socket_connect(wasm_exec_env_t exec_env, bh_socket_t sock, + const char *addr, int port) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + errno = EINTR; + return -1; + } + int ret = os_socket_connect(sock, addr, port); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} + +int +blocking_op_socket_recv_from(wasm_exec_env_t exec_env, bh_socket_t sock, + void *buf, unsigned int len, int flags, + bh_sockaddr_t *src_addr) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + errno = EINTR; + return -1; + } + int ret = os_socket_recv_from(sock, buf, len, flags, src_addr); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} + +int +blocking_op_socket_send_to(wasm_exec_env_t exec_env, bh_socket_t sock, + const void *buf, unsigned int len, int flags, + const bh_sockaddr_t *dest_addr) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + errno = EINTR; + return -1; + } + int ret = os_socket_send_to(sock, buf, len, flags, dest_addr); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} + +int +blocking_op_socket_addr_resolve(wasm_exec_env_t exec_env, const char *host, + const char *service, uint8_t *hint_is_tcp, + uint8_t *hint_is_ipv4, + bh_addr_info_t *addr_info, + size_t addr_info_size, size_t *max_info_size) +{ + /* + * Note: Unlike others, os_socket_addr_resolve() is not a simple system + * call. It's likely backed by a complex libc function, getaddrinfo(). + * Depending on the implementation of getaddrinfo() and underlying + * DNS resolver, it might or might not be possible to make it return + * with os_wakeup_blocking_op(). + * + * Unfortunately, many of ISC/bind based resolvers just keep going on + * interrupted system calls. It includes macOS and glibc. + * + * On the other hand, NuttX as of writing this returns EAI_AGAIN + * on EINTR. + */ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + errno = EINTR; + return -1; + } + int ret = os_socket_addr_resolve(host, service, hint_is_tcp, hint_is_ipv4, + addr_info, addr_info_size, max_info_size); + wasm_runtime_end_blocking_op(exec_env); + return ret; +} + +__wasi_errno_t +blocking_op_openat(wasm_exec_env_t exec_env, os_file_handle handle, + const char *path, __wasi_oflags_t oflags, + __wasi_fdflags_t fd_flags, __wasi_lookupflags_t lookup_flags, + wasi_libc_file_access_mode access_mode, os_file_handle *out) +{ + if (!wasm_runtime_begin_blocking_op(exec_env)) { + return __WASI_EINTR; + } + __wasi_errno_t error = os_openat(handle, path, oflags, fd_flags, + lookup_flags, access_mode, out); + wasm_runtime_end_blocking_op(exec_env); + return error; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h new file mode 100644 index 00000000000..afaa4a4f0cb --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/blocking_op.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2023 Midokura Japan KK. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "bh_platform.h" +#include "wasm_export.h" + +__wasi_errno_t +blocking_op_close(wasm_exec_env_t exec_env, os_file_handle handle, + bool is_stdio); +__wasi_errno_t +blocking_op_readv(wasm_exec_env_t exec_env, os_file_handle handle, + const struct __wasi_iovec_t *iov, int iovcnt, size_t *nread); +__wasi_errno_t +blocking_op_preadv(wasm_exec_env_t exec_env, os_file_handle handle, + const struct __wasi_iovec_t *iov, int iovcnt, + __wasi_filesize_t offset, size_t *nread); +__wasi_errno_t +blocking_op_writev(wasm_exec_env_t exec_env, os_file_handle handle, + const struct __wasi_ciovec_t *iov, int iovcnt, + size_t *nwritten); +__wasi_errno_t +blocking_op_pwritev(wasm_exec_env_t exec_env, os_file_handle handle, + const struct __wasi_ciovec_t *iov, int iovcnt, + __wasi_filesize_t offset, size_t *nwritten); +int +blocking_op_socket_accept(wasm_exec_env_t exec_env, bh_socket_t server_sock, + bh_socket_t *sockp, void *addr, + unsigned int *addrlenp); +int +blocking_op_socket_connect(wasm_exec_env_t exec_env, bh_socket_t sock, + const char *addr, int port); +int +blocking_op_socket_recv_from(wasm_exec_env_t exec_env, bh_socket_t sock, + void *buf, unsigned int len, int flags, + bh_sockaddr_t *src_addr); +int +blocking_op_socket_send_to(wasm_exec_env_t exec_env, bh_socket_t sock, + const void *buf, unsigned int len, int flags, + const bh_sockaddr_t *dest_addr); +int +blocking_op_socket_addr_resolve(wasm_exec_env_t exec_env, const char *host, + const char *service, uint8_t *hint_is_tcp, + uint8_t *hint_is_ipv4, + bh_addr_info_t *addr_info, + size_t addr_info_size, size_t *max_info_size); + +__wasi_errno_t +blocking_op_openat(wasm_exec_env_t exec_env, os_file_handle handle, + const char *path, __wasi_oflags_t oflags, + __wasi_fdflags_t fd_flags, __wasi_lookupflags_t lookup_flags, + wasi_libc_file_access_mode access_mode, os_file_handle *out); \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h similarity index 84% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h index 40b064b8136..5e0778c3f22 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/locking.h @@ -49,7 +49,7 @@ /* Mutex that uses the lock annotations. */ struct LOCKABLE mutex { - pthread_mutex_t object; + korp_mutex object; }; /* clang-format off */ @@ -60,69 +60,71 @@ struct LOCKABLE mutex { static inline bool mutex_init(struct mutex *lock) REQUIRES_UNLOCKED(*lock) { - return pthread_mutex_init(&lock->object, NULL) == 0 ? true : false; + return os_mutex_init(&lock->object) == BHT_OK ? true : false; } static inline void mutex_destroy(struct mutex *lock) REQUIRES_UNLOCKED(*lock) { - pthread_mutex_destroy(&lock->object); + os_mutex_destroy(&lock->object); } static inline void mutex_lock(struct mutex *lock) LOCKS_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS { - pthread_mutex_lock(&lock->object); + os_mutex_lock(&lock->object); } static inline void mutex_unlock(struct mutex *lock) UNLOCKS(*lock) NO_LOCK_ANALYSIS { - pthread_mutex_unlock(&lock->object); + os_mutex_unlock(&lock->object); } /* Read-write lock that uses the lock annotations. */ struct LOCKABLE rwlock { - pthread_rwlock_t object; + korp_rwlock object; }; static inline bool rwlock_init(struct rwlock *lock) REQUIRES_UNLOCKED(*lock) { - return pthread_rwlock_init(&lock->object, NULL) == 0 ? true : false; + return os_rwlock_init(&lock->object) == 0 ? true : false; } static inline void rwlock_rdlock(struct rwlock *lock) LOCKS_SHARED(*lock) NO_LOCK_ANALYSIS { - pthread_rwlock_rdlock(&lock->object); + os_rwlock_rdlock(&lock->object); } static inline void rwlock_wrlock(struct rwlock *lock) LOCKS_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS { - pthread_rwlock_wrlock(&lock->object); + os_rwlock_wrlock(&lock->object); } static inline void rwlock_unlock(struct rwlock *lock) UNLOCKS(*lock) NO_LOCK_ANALYSIS { - pthread_rwlock_unlock(&lock->object); + os_rwlock_unlock(&lock->object); } static inline void rwlock_destroy(struct rwlock *lock) UNLOCKS(*lock) NO_LOCK_ANALYSIS { - pthread_rwlock_destroy(&lock->object); + os_rwlock_destroy(&lock->object); } /* Condition variable that uses the lock annotations. */ struct LOCKABLE cond { - pthread_cond_t object; -#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \ - || !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP + korp_cond object; + +#if !CONFIG_HAS_CLOCK_NANOSLEEP \ + && (!CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \ + || !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP) clockid_t clock; #endif }; @@ -147,43 +149,49 @@ cond_init_monotonic(struct cond *cond) fail: pthread_condattr_destroy(&attr); #else - if (pthread_cond_init(&cond->object, NULL) != 0) + if (os_cond_init(&cond->object) != 0) return false; ret = true; #endif -#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \ - || !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP +#if !CONFIG_HAS_CLOCK_NANOSLEEP \ + && (!CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \ + || !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP) cond->clock = CLOCK_MONOTONIC; #endif + return ret; } static inline bool cond_init_realtime(struct cond *cond) { - if (pthread_cond_init(&cond->object, NULL) != 0) + if (os_cond_init(&cond->object) != 0) return false; -#if !CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \ - || !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP + +#if !CONFIG_HAS_CLOCK_NANOSLEEP \ + && (!CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK \ + || !CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP) cond->clock = CLOCK_REALTIME; #endif + return true; } static inline void cond_destroy(struct cond *cond) { - pthread_cond_destroy(&cond->object); + os_cond_destroy(&cond->object); } static inline void cond_signal(struct cond *cond) { - pthread_cond_signal(&cond->object); + os_cond_signal(&cond->object); } #if !CONFIG_HAS_CLOCK_NANOSLEEP + static inline bool cond_timedwait(struct cond *cond, struct mutex *lock, uint64_t timeout, bool abstime) REQUIRES_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS @@ -259,7 +267,7 @@ static inline void cond_wait(struct cond *cond, struct mutex *lock) REQUIRES_EXCLUSIVE(*lock) NO_LOCK_ANALYSIS { - pthread_cond_wait(&cond->object, &lock->object); + os_cond_wait(&cond->object, &lock->object); } #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c similarity index 58% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c index 61e84183695..b59035f349e 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c @@ -13,7 +13,9 @@ #include "ssp_config.h" #include "bh_platform.h" +#include "blocking_op.h" #include "wasmtime_ssp.h" +#include "libc_errno.h" #include "locking.h" #include "posix.h" #include "random.h" @@ -21,6 +23,18 @@ #include "rights.h" #include "str.h" +/* Some platforms (e.g. Windows) already define `min()` macro. + We're undefing it here to make sure the `min` call does exactly + what we want it to do. */ +#ifdef min +#undef min +#endif +static inline size_t +min(size_t a, size_t b) +{ + return a > b ? b : a; +} + #if 0 /* TODO: -std=gnu99 causes compile error, comment them first */ // struct iovec must have the same layout as __wasi_iovec_t. static_assert(offsetof(struct iovec, iov_base) == @@ -55,111 +69,6 @@ static_assert(sizeof(struct iovec) == sizeof(__wasi_ciovec_t), "Size mismatch"); #endif -#if defined(WASMTIME_SSP_STATIC_CURFDS) -static __thread struct fd_table *curfds; -static __thread struct fd_prestats *prestats; -static __thread struct argv_environ_values *argv_environ; -static __thread struct addr_pool *addr_pool; -#endif - -// Converts a POSIX error code to a CloudABI error code. -static __wasi_errno_t -convert_errno(int error) -{ - static const __wasi_errno_t errors[] = { -#define X(v) [v] = __WASI_##v - X(E2BIG), - X(EACCES), - X(EADDRINUSE), - X(EADDRNOTAVAIL), - X(EAFNOSUPPORT), - X(EAGAIN), - X(EALREADY), - X(EBADF), - X(EBADMSG), - X(EBUSY), - X(ECANCELED), - X(ECHILD), - X(ECONNABORTED), - X(ECONNREFUSED), - X(ECONNRESET), - X(EDEADLK), - X(EDESTADDRREQ), - X(EDOM), - X(EDQUOT), - X(EEXIST), - X(EFAULT), - X(EFBIG), - X(EHOSTUNREACH), - X(EIDRM), - X(EILSEQ), - X(EINPROGRESS), - X(EINTR), - X(EINVAL), - X(EIO), - X(EISCONN), - X(EISDIR), - X(ELOOP), - X(EMFILE), - X(EMLINK), - X(EMSGSIZE), - X(EMULTIHOP), - X(ENAMETOOLONG), - X(ENETDOWN), - X(ENETRESET), - X(ENETUNREACH), - X(ENFILE), - X(ENOBUFS), - X(ENODEV), - X(ENOENT), - X(ENOEXEC), - X(ENOLCK), - X(ENOLINK), - X(ENOMEM), - X(ENOMSG), - X(ENOPROTOOPT), - X(ENOSPC), - X(ENOSYS), -#ifdef ENOTCAPABLE - X(ENOTCAPABLE), -#endif - X(ENOTCONN), - X(ENOTDIR), - X(ENOTEMPTY), - X(ENOTRECOVERABLE), - X(ENOTSOCK), - X(ENOTSUP), - X(ENOTTY), - X(ENXIO), - X(EOVERFLOW), - X(EOWNERDEAD), - X(EPERM), - X(EPIPE), - X(EPROTO), - X(EPROTONOSUPPORT), - X(EPROTOTYPE), - X(ERANGE), - X(EROFS), - X(ESPIPE), - X(ESRCH), - X(ESTALE), - X(ETIMEDOUT), - X(ETXTBSY), - X(EXDEV), -#undef X -#if EOPNOTSUPP != ENOTSUP - [EOPNOTSUPP] = __WASI_ENOTSUP, -#endif -#if EWOULDBLOCK != EAGAIN - [EWOULDBLOCK] = __WASI_EAGAIN, -#endif - }; - if (error < 0 || (size_t)error >= sizeof(errors) / sizeof(errors[0]) - || errors[error] == 0) - return __WASI_ENOSYS; - return errors[error]; -} - static bool ns_lookup_list_search(char **list, const char *host) { @@ -185,21 +94,9 @@ ns_lookup_list_search(char **list, const char *host) return false; } -// Converts a POSIX timespec to a CloudABI timestamp. -static __wasi_timestamp_t -convert_timespec(const struct timespec *ts) -{ - if (ts->tv_sec < 0) - return 0; - if ((__wasi_timestamp_t)ts->tv_sec >= UINT64_MAX / 1000000000) - return UINT64_MAX; - return (__wasi_timestamp_t)ts->tv_sec * 1000000000 - + (__wasi_timestamp_t)ts->tv_nsec; -} - -// Converts a CloudABI clock identifier to a POSIX clock identifier. +#if !defined(BH_PLATFORM_WINDOWS) && CONFIG_HAS_CLOCK_NANOSLEEP static bool -convert_clockid(__wasi_clockid_t in, clockid_t *out) +wasi_clockid_to_clockid(__wasi_clockid_t in, clockid_t *out) { switch (in) { case __WASI_CLOCK_MONOTONIC: @@ -222,28 +119,29 @@ convert_clockid(__wasi_clockid_t in, clockid_t *out) return false; } } +#endif static void wasi_addr_to_bh_sockaddr(const __wasi_addr_t *wasi_addr, bh_sockaddr_t *sockaddr) { if (wasi_addr->kind == IPv4) { - sockaddr->addr_bufer.ipv4 = (wasi_addr->addr.ip4.addr.n0 << 24) - | (wasi_addr->addr.ip4.addr.n1 << 16) - | (wasi_addr->addr.ip4.addr.n2 << 8) - | wasi_addr->addr.ip4.addr.n3; + sockaddr->addr_buffer.ipv4 = (wasi_addr->addr.ip4.addr.n0 << 24) + | (wasi_addr->addr.ip4.addr.n1 << 16) + | (wasi_addr->addr.ip4.addr.n2 << 8) + | wasi_addr->addr.ip4.addr.n3; sockaddr->is_ipv4 = true; sockaddr->port = wasi_addr->addr.ip4.port; } else { - sockaddr->addr_bufer.ipv6[0] = wasi_addr->addr.ip6.addr.n0; - sockaddr->addr_bufer.ipv6[1] = wasi_addr->addr.ip6.addr.n1; - sockaddr->addr_bufer.ipv6[2] = wasi_addr->addr.ip6.addr.n2; - sockaddr->addr_bufer.ipv6[3] = wasi_addr->addr.ip6.addr.n3; - sockaddr->addr_bufer.ipv6[4] = wasi_addr->addr.ip6.addr.h0; - sockaddr->addr_bufer.ipv6[5] = wasi_addr->addr.ip6.addr.h1; - sockaddr->addr_bufer.ipv6[6] = wasi_addr->addr.ip6.addr.h2; - sockaddr->addr_bufer.ipv6[7] = wasi_addr->addr.ip6.addr.h3; + sockaddr->addr_buffer.ipv6[0] = wasi_addr->addr.ip6.addr.n0; + sockaddr->addr_buffer.ipv6[1] = wasi_addr->addr.ip6.addr.n1; + sockaddr->addr_buffer.ipv6[2] = wasi_addr->addr.ip6.addr.n2; + sockaddr->addr_buffer.ipv6[3] = wasi_addr->addr.ip6.addr.n3; + sockaddr->addr_buffer.ipv6[4] = wasi_addr->addr.ip6.addr.h0; + sockaddr->addr_buffer.ipv6[5] = wasi_addr->addr.ip6.addr.h1; + sockaddr->addr_buffer.ipv6[6] = wasi_addr->addr.ip6.addr.h2; + sockaddr->addr_buffer.ipv6[7] = wasi_addr->addr.ip6.addr.h3; sockaddr->is_ipv4 = false; sockaddr->port = wasi_addr->addr.ip6.port; } @@ -258,24 +156,24 @@ bh_sockaddr_to_wasi_addr(const bh_sockaddr_t *sockaddr, wasi_addr->kind = IPv4; wasi_addr->addr.ip4.port = sockaddr->port; wasi_addr->addr.ip4.addr.n0 = - (sockaddr->addr_bufer.ipv4 & 0xFF000000) >> 24; + (sockaddr->addr_buffer.ipv4 & 0xFF000000) >> 24; wasi_addr->addr.ip4.addr.n1 = - (sockaddr->addr_bufer.ipv4 & 0x00FF0000) >> 16; + (sockaddr->addr_buffer.ipv4 & 0x00FF0000) >> 16; wasi_addr->addr.ip4.addr.n2 = - (sockaddr->addr_bufer.ipv4 & 0x0000FF00) >> 8; - wasi_addr->addr.ip4.addr.n3 = (sockaddr->addr_bufer.ipv4 & 0x000000FF); + (sockaddr->addr_buffer.ipv4 & 0x0000FF00) >> 8; + wasi_addr->addr.ip4.addr.n3 = (sockaddr->addr_buffer.ipv4 & 0x000000FF); } else { wasi_addr->kind = IPv6; wasi_addr->addr.ip6.port = sockaddr->port; - wasi_addr->addr.ip6.addr.n0 = sockaddr->addr_bufer.ipv6[0]; - wasi_addr->addr.ip6.addr.n1 = sockaddr->addr_bufer.ipv6[1]; - wasi_addr->addr.ip6.addr.n2 = sockaddr->addr_bufer.ipv6[2]; - wasi_addr->addr.ip6.addr.n3 = sockaddr->addr_bufer.ipv6[3]; - wasi_addr->addr.ip6.addr.h0 = sockaddr->addr_bufer.ipv6[4]; - wasi_addr->addr.ip6.addr.h1 = sockaddr->addr_bufer.ipv6[5]; - wasi_addr->addr.ip6.addr.h2 = sockaddr->addr_bufer.ipv6[6]; - wasi_addr->addr.ip6.addr.h3 = sockaddr->addr_bufer.ipv6[7]; + wasi_addr->addr.ip6.addr.n0 = sockaddr->addr_buffer.ipv6[0]; + wasi_addr->addr.ip6.addr.n1 = sockaddr->addr_buffer.ipv6[1]; + wasi_addr->addr.ip6.addr.n2 = sockaddr->addr_buffer.ipv6[2]; + wasi_addr->addr.ip6.addr.n3 = sockaddr->addr_buffer.ipv6[3]; + wasi_addr->addr.ip6.addr.h0 = sockaddr->addr_buffer.ipv6[4]; + wasi_addr->addr.ip6.addr.h1 = sockaddr->addr_buffer.ipv6[5]; + wasi_addr->addr.ip6.addr.h2 = sockaddr->addr_buffer.ipv6[6]; + wasi_addr->addr.ip6.addr.h3 = sockaddr->addr_buffer.ipv6[7]; } } @@ -299,35 +197,6 @@ wasi_addr_ip_to_bh_ip_addr_buffer(__wasi_addr_ip_t *addr, } } -__wasi_errno_t -wasmtime_ssp_clock_res_get(__wasi_clockid_t clock_id, - __wasi_timestamp_t *resolution) -{ - clockid_t nclock_id; - if (!convert_clockid(clock_id, &nclock_id)) - return __WASI_EINVAL; - struct timespec ts; - if (clock_getres(nclock_id, &ts) < 0) - return convert_errno(errno); - *resolution = convert_timespec(&ts); - return 0; -} - -__wasi_errno_t -wasmtime_ssp_clock_time_get(__wasi_clockid_t clock_id, - __wasi_timestamp_t precision, - __wasi_timestamp_t *time) -{ - clockid_t nclock_id; - if (!convert_clockid(clock_id, &nclock_id)) - return __WASI_EINVAL; - struct timespec ts; - if (clock_gettime(nclock_id, &ts) < 0) - return convert_errno(errno); - *time = convert_timespec(&ts); - return 0; -} - struct fd_prestat { const char *dir; }; @@ -340,15 +209,12 @@ fd_prestats_init(struct fd_prestats *pt) pt->prestats = NULL; pt->size = 0; pt->used = 0; -#if defined(WASMTIME_SSP_STATIC_CURFDS) - prestats = pt; -#endif return true; } // Grows the preopened resource table to a required lower bound and a // minimum number of free preopened resource table entries. -static bool +static __wasi_errno_t fd_prestats_grow(struct fd_prestats *pt, size_t min, size_t incr) REQUIRES_EXCLUSIVE(pt->lock) { @@ -362,7 +228,7 @@ fd_prestats_grow(struct fd_prestats *pt, size_t min, size_t incr) struct fd_prestat *prestats = wasm_runtime_malloc((uint32)(sizeof(*prestats) * size)); if (prestats == NULL) - return false; + return __WASI_ENOMEM; if (pt->prestats && pt->size > 0) { bh_memcpy_s(prestats, (uint32)(sizeof(*prestats) * size), @@ -378,27 +244,39 @@ fd_prestats_grow(struct fd_prestats *pt, size_t min, size_t incr) pt->prestats = prestats; pt->size = size; } - return true; + return __WASI_ESUCCESS; } -// Inserts a preopened resource record into the preopened resource table. -bool -fd_prestats_insert(struct fd_prestats *pt, const char *dir, __wasi_fd_t fd) +static __wasi_errno_t +fd_prestats_insert_locked(struct fd_prestats *pt, const char *dir, + __wasi_fd_t fd) { // Grow the preopened resource table if needed. - rwlock_wrlock(&pt->lock); - if (!fd_prestats_grow(pt, fd, 1)) { - rwlock_unlock(&pt->lock); - return false; + __wasi_errno_t error = fd_prestats_grow(pt, fd, 1); + + if (error != __WASI_ESUCCESS) { + return error; } pt->prestats[fd].dir = bh_strdup(dir); - rwlock_unlock(&pt->lock); if (pt->prestats[fd].dir == NULL) - return false; + return __WASI_ENOMEM; - return true; + return __WASI_ESUCCESS; +} + +// Inserts a preopened resource record into the preopened resource table. +bool +fd_prestats_insert(struct fd_prestats *pt, const char *dir, __wasi_fd_t fd) +{ + rwlock_wrlock(&pt->lock); + + __wasi_errno_t error = fd_prestats_insert_locked(pt, dir, fd); + + rwlock_unlock(&pt->lock); + + return error == __WASI_ESUCCESS; } // Looks up a preopened resource table entry by number. @@ -417,16 +295,37 @@ fd_prestats_get_entry(struct fd_prestats *pt, __wasi_fd_t fd, return 0; } +// Remove a preopened resource record from the preopened resource table by +// number +static __wasi_errno_t +fd_prestats_remove_entry(struct fd_prestats *pt, __wasi_fd_t fd) +{ + // Test for file descriptor existence. + if (fd >= pt->size) + return __WASI_EBADF; + struct fd_prestat *prestat = &pt->prestats[fd]; + + if (prestat->dir != NULL) { + wasm_runtime_free((void *)prestat->dir); + prestat->dir = NULL; + } + + return __WASI_ESUCCESS; +} + struct fd_object { struct refcount refcount; __wasi_filetype_t type; - int number; + os_file_handle file_handle; + // Keep track of whether this fd object refers to a stdio stream so we know + // whether to close the underlying file handle when releasing the object. + bool is_stdio; union { // Data associated with directory file descriptors. struct { struct mutex lock; // Lock to protect members below. - DIR *handle; // Directory handle. + os_dir_stream handle; // Directory handle. __wasi_dircookie_t offset; // Offset of the directory. } directory; }; @@ -446,9 +345,6 @@ fd_table_init(struct fd_table *ft) ft->entries = NULL; ft->size = 0; ft->used = 0; -#if defined(WASMTIME_SSP_STATIC_CURFDS) - curfds = ft; -#endif return true; } @@ -511,7 +407,7 @@ fd_table_grow(struct fd_table *ft, size_t min, size_t incr) // Allocates a new file descriptor object. static __wasi_errno_t -fd_object_new(__wasi_filetype_t type, struct fd_object **fo) +fd_object_new(__wasi_filetype_t type, bool is_stdio, struct fd_object **fo) TRYLOCKS_SHARED(0, (*fo)->refcount) { *fo = wasm_runtime_malloc(sizeof(**fo)); @@ -519,7 +415,8 @@ fd_object_new(__wasi_filetype_t type, struct fd_object **fo) return __WASI_ENOMEM; refcount_init(&(*fo)->refcount, 1); (*fo)->type = type; - (*fo)->number = -1; + (*fo)->file_handle = os_get_invalid_handle(); + (*fo)->is_stdio = is_stdio; return 0; } @@ -557,131 +454,122 @@ fd_table_detach(struct fd_table *ft, __wasi_fd_t fd, struct fd_object **fo) // Determines the type of a file descriptor and its maximum set of // rights that should be attached to it. static __wasi_errno_t -fd_determine_type_rights(int fd, __wasi_filetype_t *type, +fd_determine_type_rights(os_file_handle fd, __wasi_filetype_t *type, __wasi_rights_t *rights_base, __wasi_rights_t *rights_inheriting) { - struct stat sb; - if (fstat(fd, &sb) < 0) - return convert_errno(errno); - if (S_ISBLK(sb.st_mode)) { - *type = __WASI_FILETYPE_BLOCK_DEVICE; - *rights_base = RIGHTS_BLOCK_DEVICE_BASE; - *rights_inheriting = RIGHTS_BLOCK_DEVICE_INHERITING; - } - else if (S_ISCHR(sb.st_mode)) { - *type = __WASI_FILETYPE_CHARACTER_DEVICE; -#if CONFIG_HAS_ISATTY - if (isatty(fd)) { - *rights_base = RIGHTS_TTY_BASE; - *rights_inheriting = RIGHTS_TTY_INHERITING; - } - else -#endif - { - *rights_base = RIGHTS_CHARACTER_DEVICE_BASE; - *rights_inheriting = RIGHTS_CHARACTER_DEVICE_INHERITING; - } - } - else if (S_ISDIR(sb.st_mode)) { - *type = __WASI_FILETYPE_DIRECTORY; - *rights_base = RIGHTS_DIRECTORY_BASE; - *rights_inheriting = RIGHTS_DIRECTORY_INHERITING; - } - else if (S_ISREG(sb.st_mode)) { - *type = __WASI_FILETYPE_REGULAR_FILE; - *rights_base = RIGHTS_REGULAR_FILE_BASE; - *rights_inheriting = RIGHTS_REGULAR_FILE_INHERITING; - } - else if (S_ISSOCK(sb.st_mode)) { - int socktype; - socklen_t socktypelen = sizeof(socktype); - if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &socktype, &socktypelen) < 0) - return convert_errno(errno); - switch (socktype) { - case SOCK_DGRAM: - *type = __WASI_FILETYPE_SOCKET_DGRAM; - break; - case SOCK_STREAM: - *type = __WASI_FILETYPE_SOCKET_STREAM; - break; - default: - return __WASI_EINVAL; - } - *rights_base = RIGHTS_SOCKET_BASE; - *rights_inheriting = RIGHTS_SOCKET_INHERITING; - } - else if (S_ISFIFO(sb.st_mode)) { - *type = __WASI_FILETYPE_SOCKET_STREAM; - *rights_base = RIGHTS_SOCKET_BASE; - *rights_inheriting = RIGHTS_SOCKET_INHERITING; - } - else { - return __WASI_EINVAL; + struct __wasi_filestat_t buf; + __wasi_errno_t error = os_fstat(fd, &buf); + + if (error != __WASI_ESUCCESS) + return error; + + *type = buf.st_filetype; + + switch (buf.st_filetype) { + case __WASI_FILETYPE_BLOCK_DEVICE: + *rights_base = RIGHTS_BLOCK_DEVICE_BASE; + *rights_inheriting = RIGHTS_BLOCK_DEVICE_INHERITING; + break; + case __WASI_FILETYPE_CHARACTER_DEVICE: + error = os_isatty(fd); + + if (error == __WASI_ESUCCESS) { + *rights_base = RIGHTS_TTY_BASE; + *rights_inheriting = RIGHTS_TTY_INHERITING; + } + else { + *rights_base = RIGHTS_CHARACTER_DEVICE_BASE; + *rights_inheriting = RIGHTS_CHARACTER_DEVICE_INHERITING; + } + break; + case __WASI_FILETYPE_DIRECTORY: + *rights_base = RIGHTS_DIRECTORY_BASE; + *rights_inheriting = RIGHTS_DIRECTORY_INHERITING; + break; + case __WASI_FILETYPE_REGULAR_FILE: + *rights_base = RIGHTS_REGULAR_FILE_BASE; + *rights_inheriting = RIGHTS_REGULAR_FILE_INHERITING; + break; + case __WASI_FILETYPE_SOCKET_DGRAM: + case __WASI_FILETYPE_SOCKET_STREAM: + *rights_base = RIGHTS_SOCKET_BASE; + *rights_inheriting = RIGHTS_SOCKET_INHERITING; + break; + case __WASI_FILETYPE_SYMBOLIC_LINK: + case __WASI_FILETYPE_UNKNOWN: + // If we don't know the type, allow for the maximum set of + // rights + *rights_base = RIGHTS_ALL; + *rights_inheriting = RIGHTS_ALL; + break; + default: + return __WASI_EINVAL; } + wasi_libc_file_access_mode access_mode; + error = os_file_get_access_mode(fd, &access_mode); + + if (error != __WASI_ESUCCESS) + return error; + // Strip off read/write bits based on the access mode. - switch (fcntl(fd, F_GETFL) & O_ACCMODE) { - case O_RDONLY: + switch (access_mode) { + case WASI_LIBC_ACCESS_MODE_READ_ONLY: *rights_base &= ~(__wasi_rights_t)__WASI_RIGHT_FD_WRITE; break; - case O_WRONLY: + case WASI_LIBC_ACCESS_MODE_WRITE_ONLY: *rights_base &= ~(__wasi_rights_t)__WASI_RIGHT_FD_READ; break; } - return 0; -} -// Returns the underlying file descriptor number of a file descriptor -// object. This function can only be applied to objects that have an -// underlying file descriptor number. -static int -fd_number(const struct fd_object *fo) -{ - int number = fo->number; - assert(number >= 0 && "fd_number() called on virtual file descriptor"); - return number; + return error; } -#define CLOSE_NON_STD_FD(fd) \ - do { \ - if (fd > 2) \ - close(fd); \ - } while (0) - // Lowers the reference count on a file descriptor object. When the // reference count reaches zero, its resources are cleaned up. -static void -fd_object_release(struct fd_object *fo) UNLOCKS(fo->refcount) +static __wasi_errno_t +fd_object_release(wasm_exec_env_t env, struct fd_object *fo) + UNLOCKS(fo->refcount) { + __wasi_errno_t error = __WASI_ESUCCESS; + if (refcount_release(&fo->refcount)) { + int saved_errno = errno; switch (fo->type) { case __WASI_FILETYPE_DIRECTORY: - // For directories we may keep track of a DIR object. Calling - // closedir() on it also closes the underlying file descriptor. + // For directories we may keep track of a DIR object. + // Calling os_closedir() on it also closes the underlying file + // descriptor. mutex_destroy(&fo->directory.lock); - if (fo->directory.handle == NULL) { - CLOSE_NON_STD_FD(fd_number(fo)); - } - else { - closedir(fo->directory.handle); + if (os_is_dir_stream_valid(&fo->directory.handle)) { + error = os_closedir(fo->directory.handle); + break; } - break; + // Fallthrough. default: - CLOSE_NON_STD_FD(fd_number(fo)); + // The env == NULL case is for + // fd_table_destroy, path_get, path_put, + // fd_table_insert_existing + error = (env == NULL) ? os_close(fo->file_handle, fo->is_stdio) + : blocking_op_close(env, fo->file_handle, + fo->is_stdio); break; } wasm_runtime_free(fo); + errno = saved_errno; } + return error; } // Inserts an already existing file descriptor into the file descriptor // table. bool -fd_table_insert_existing(struct fd_table *ft, __wasi_fd_t in, int out) +fd_table_insert_existing(struct fd_table *ft, __wasi_fd_t in, + os_file_handle out, bool is_stdio) { - __wasi_filetype_t type; - __wasi_rights_t rights_base, rights_inheriting; + __wasi_filetype_t type = __WASI_FILETYPE_UNKNOWN; + __wasi_rights_t rights_base = 0, rights_inheriting = 0; struct fd_object *fo; __wasi_errno_t error; @@ -690,8 +578,8 @@ fd_table_insert_existing(struct fd_table *ft, __wasi_fd_t in, int out) if (error != 0) { #ifdef BH_PLATFORM_EGO /** - * since it is an already opened file and we can assume the opened file - * has all necessary rights no matter how to get + * since it is an already opened file and we can assume the opened + * file has all necessary rights no matter how to get */ if (error != __WASI_ENOTSUP) return false; @@ -700,23 +588,23 @@ fd_table_insert_existing(struct fd_table *ft, __wasi_fd_t in, int out) #endif } - error = fd_object_new(type, &fo); + error = fd_object_new(type, is_stdio, &fo); if (error != 0) return false; - fo->number = out; + fo->file_handle = out; if (type == __WASI_FILETYPE_DIRECTORY) { if (!mutex_init(&fo->directory.lock)) { - fd_object_release(fo); + fd_object_release(NULL, fo); return false; } - fo->directory.handle = NULL; + fo->directory.handle = os_get_invalid_dir_stream(); } // Grow the file descriptor table if needed. rwlock_wrlock(&ft->lock); if (!fd_table_grow(ft, in, 1)) { rwlock_unlock(&ft->lock); - fd_object_release(fo); + fd_object_release(NULL, fo); return false; } @@ -726,71 +614,81 @@ fd_table_insert_existing(struct fd_table *ft, __wasi_fd_t in, int out) } // Picks an unused slot from the file descriptor table. -static __wasi_fd_t -fd_table_unused(struct fd_table *ft) REQUIRES_SHARED(ft->lock) +static __wasi_errno_t +fd_table_unused(struct fd_table *ft, __wasi_fd_t *out) REQUIRES_SHARED(ft->lock) { assert(ft->size > ft->used && "File descriptor table has no free slots"); for (;;) { - __wasi_fd_t fd = (__wasi_fd_t)random_uniform(ft->size); - if (ft->entries[fd].object == NULL) - return fd; + uintmax_t random_fd = 0; + __wasi_errno_t error = random_uniform(ft->size, &random_fd); + + if (error != __WASI_ESUCCESS) + return error; + + if (ft->entries[(__wasi_fd_t)random_fd].object == NULL) { + *out = (__wasi_fd_t)random_fd; + return error; + } } } // Inserts a file descriptor object into an unused slot of the file // descriptor table. static __wasi_errno_t -fd_table_insert(struct fd_table *ft, struct fd_object *fo, - __wasi_rights_t rights_base, __wasi_rights_t rights_inheriting, - __wasi_fd_t *out) REQUIRES_UNLOCKED(ft->lock) - UNLOCKS(fo->refcount) +fd_table_insert(wasm_exec_env_t exec_env, struct fd_table *ft, + struct fd_object *fo, __wasi_rights_t rights_base, + __wasi_rights_t rights_inheriting, __wasi_fd_t *out) + REQUIRES_UNLOCKED(ft->lock) UNLOCKS(fo->refcount) { // Grow the file descriptor table if needed. rwlock_wrlock(&ft->lock); if (!fd_table_grow(ft, 0, 1)) { rwlock_unlock(&ft->lock); - fd_object_release(fo); + fd_object_release(exec_env, fo); return convert_errno(errno); } - *out = fd_table_unused(ft); + __wasi_errno_t error = fd_table_unused(ft, out); + + if (error != __WASI_ESUCCESS) + return error; + fd_table_attach(ft, *out, fo, rights_base, rights_inheriting); rwlock_unlock(&ft->lock); - return 0; + return error; } // Inserts a numerical file descriptor into the file descriptor table. static __wasi_errno_t -fd_table_insert_fd(struct fd_table *ft, int in, __wasi_filetype_t type, +fd_table_insert_fd(wasm_exec_env_t exec_env, struct fd_table *ft, + os_file_handle in, __wasi_filetype_t type, __wasi_rights_t rights_base, __wasi_rights_t rights_inheriting, __wasi_fd_t *out) REQUIRES_UNLOCKED(ft->lock) { struct fd_object *fo; - __wasi_errno_t error = fd_object_new(type, &fo); + __wasi_errno_t error = fd_object_new(type, false, &fo); if (error != 0) { - close(in); + os_close(in, false); return error; } - fo->number = in; + fo->file_handle = in; if (type == __WASI_FILETYPE_DIRECTORY) { if (!mutex_init(&fo->directory.lock)) { - fd_object_release(fo); + fd_object_release(exec_env, fo); return (__wasi_errno_t)-1; } - fo->directory.handle = NULL; + fo->directory.handle = os_get_invalid_dir_stream(); } - return fd_table_insert(ft, fo, rights_base, rights_inheriting, out); + return fd_table_insert(exec_env, ft, fo, rights_base, rights_inheriting, + out); } __wasi_errno_t -wasmtime_ssp_fd_prestat_get( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_prestats *prestats, -#endif - __wasi_fd_t fd, __wasi_prestat_t *buf) +wasmtime_ssp_fd_prestat_get(struct fd_prestats *prestats, __wasi_fd_t fd, + __wasi_prestat_t *buf) { rwlock_rdlock(&prestats->lock); struct fd_prestat *prestat; @@ -812,11 +710,8 @@ wasmtime_ssp_fd_prestat_get( } __wasi_errno_t -wasmtime_ssp_fd_prestat_dir_name( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_prestats *prestats, -#endif - __wasi_fd_t fd, char *path, size_t path_len) +wasmtime_ssp_fd_prestat_dir_name(struct fd_prestats *prestats, __wasi_fd_t fd, + char *path, size_t path_len) { rwlock_rdlock(&prestats->lock); struct fd_prestat *prestat; @@ -825,12 +720,14 @@ wasmtime_ssp_fd_prestat_dir_name( rwlock_unlock(&prestats->lock); return error; } - if (path_len != strlen(prestat->dir)) { + + const size_t prestat_dir_len = strlen(prestat->dir); + if (path_len < prestat_dir_len) { rwlock_unlock(&prestats->lock); - return EINVAL; + return __WASI_EINVAL; } - bh_memcpy_s(path, (uint32)path_len, prestat->dir, (uint32)path_len); + bh_memcpy_s(path, (uint32)path_len, prestat->dir, (uint32)prestat_dir_len); rwlock_unlock(&prestats->lock); @@ -838,31 +735,18 @@ wasmtime_ssp_fd_prestat_dir_name( } __wasi_errno_t -wasmtime_ssp_fd_close( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, struct fd_prestats *prestats, -#endif - __wasi_fd_t fd) -{ - // Don't allow closing a pre-opened resource. - // TODO: Eventually, we do want to permit this, once libpreopen in - // userspace is capable of removing entries from its tables as well. - { - rwlock_rdlock(&prestats->lock); - struct fd_prestat *prestat; - __wasi_errno_t error = fd_prestats_get_entry(prestats, fd, &prestat); - rwlock_unlock(&prestats->lock); - if (error == 0) { - return __WASI_ENOTSUP; - } - } - +wasmtime_ssp_fd_close(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct fd_prestats *prestats, __wasi_fd_t fd) +{ // Validate the file descriptor. struct fd_table *ft = curfds; rwlock_wrlock(&ft->lock); + rwlock_wrlock(&prestats->lock); + struct fd_entry *fe; __wasi_errno_t error = fd_table_get_entry(ft, fd, 0, 0, &fe); if (error != 0) { + rwlock_unlock(&prestats->lock); rwlock_unlock(&ft->lock); return error; } @@ -870,9 +754,20 @@ wasmtime_ssp_fd_close( // Remove it from the file descriptor table. struct fd_object *fo; fd_table_detach(ft, fd, &fo); + + // Remove it from the preopened resource table if it exists + error = fd_prestats_remove_entry(prestats, fd); + + rwlock_unlock(&prestats->lock); rwlock_unlock(&ft->lock); - fd_object_release(fo); - return 0; + fd_object_release(exec_env, fo); + + // Ignore the error if there is no preopen associated with this fd + if (error == __WASI_EBADF) { + return __WASI_ESUCCESS; + } + + return error; } // Look up a file descriptor object in a locked file descriptor table @@ -914,11 +809,8 @@ fd_object_get(struct fd_table *curfds, struct fd_object **fo, __wasi_fd_t fd, } __wasi_errno_t -wasmtime_ssp_fd_datasync( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd) +wasmtime_ssp_fd_datasync(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd) { struct fd_object *fo; __wasi_errno_t error = @@ -926,24 +818,17 @@ wasmtime_ssp_fd_datasync( if (error != 0) return error; -#if CONFIG_HAS_FDATASYNC - int ret = fdatasync(fd_number(fo)); -#else - int ret = fsync(fd_number(fo)); -#endif - fd_object_release(fo); - if (ret < 0) - return convert_errno(errno); - return 0; + error = os_fdatasync(fo->file_handle); + + fd_object_release(exec_env, fo); + + return error; } __wasi_errno_t -wasmtime_ssp_fd_pread( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, const __wasi_iovec_t *iov, size_t iovcnt, - __wasi_filesize_t offset, size_t *nread) +wasmtime_ssp_fd_pread(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, const __wasi_iovec_t *iov, size_t iovcnt, + __wasi_filesize_t offset, size_t *nread) { if (iovcnt == 0) return __WASI_EINVAL; @@ -951,175 +836,78 @@ wasmtime_ssp_fd_pread( struct fd_object *fo; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, __WASI_RIGHT_FD_READ, 0); + if (error != 0) return error; -#if CONFIG_HAS_PREADV - ssize_t len = preadv(fd_number(fo), (const struct iovec *)iov, (int)iovcnt, - (off_t)offset); - fd_object_release(fo); - if (len < 0) - return convert_errno(errno); - *nread = (size_t)len; - return 0; -#else - if (iovcnt == 1) { - ssize_t len = pread(fd_number(fo), iov->buf, iov->buf_len, offset); - fd_object_release(fo); - if (len < 0) - return convert_errno(errno); - *nread = len; - return 0; - } - else { - // Allocate a single buffer to fit all data. - size_t totalsize = 0; - for (size_t i = 0; i < iovcnt; ++i) - totalsize += iov[i].buf_len; - char *buf = wasm_runtime_malloc(totalsize); - if (buf == NULL) { - fd_object_release(fo); - return __WASI_ENOMEM; - } + error = blocking_op_preadv(exec_env, fo->file_handle, iov, (int)iovcnt, + offset, nread); - // Perform a single read operation. - ssize_t len = pread(fd_number(fo), buf, totalsize, offset); - fd_object_release(fo); - if (len < 0) { - wasm_runtime_free(buf); - return convert_errno(errno); - } + fd_object_release(exec_env, fo); - // Copy data back to vectors. - size_t bufoff = 0; - for (size_t i = 0; i < iovcnt; ++i) { - if (bufoff + iov[i].buf_len < (size_t)len) { - bh_memcpy_s(iov[i].buf, iov[i].buf_len, buf + bufoff, - iov[i].buf_len); - bufoff += iov[i].buf_len; - } - else { - bh_memcpy_s(iov[i].buf, iov[i].buf_len, buf + bufoff, - len - bufoff); - break; - } - } - wasm_runtime_free(buf); - *nread = len; - return 0; - } -#endif + return error; } __wasi_errno_t -wasmtime_ssp_fd_pwrite( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, const __wasi_ciovec_t *iov, size_t iovcnt, - __wasi_filesize_t offset, size_t *nwritten) +wasmtime_ssp_fd_pwrite(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, const __wasi_ciovec_t *iov, + size_t iovcnt, __wasi_filesize_t offset, + size_t *nwritten) { - if (iovcnt == 0) - return __WASI_EINVAL; - struct fd_object *fo; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, __WASI_RIGHT_FD_WRITE, 0); + if (error != 0) return error; - ssize_t len; -#if CONFIG_HAS_PWRITEV - len = pwritev(fd_number(fo), (const struct iovec *)iov, (int)iovcnt, - (off_t)offset); -#else - if (iovcnt == 1) { - len = pwrite(fd_number(fo), iov->buf, iov->buf_len, offset); - } - else { - // Allocate a single buffer to fit all data. - size_t totalsize = 0; - for (size_t i = 0; i < iovcnt; ++i) - totalsize += iov[i].buf_len; - char *buf = wasm_runtime_malloc(totalsize); - if (buf == NULL) { - fd_object_release(fo); - return __WASI_ENOMEM; - } - size_t bufoff = 0; - for (size_t i = 0; i < iovcnt; ++i) { - bh_memcpy_s(buf + bufoff, totalsize - bufoff, iov[i].buf, - iov[i].buf_len); - bufoff += iov[i].buf_len; - } + error = blocking_op_pwritev(exec_env, fo->file_handle, iov, (int)iovcnt, + offset, nwritten); + fd_object_release(exec_env, fo); - // Perform a single write operation. - len = pwrite(fd_number(fo), buf, totalsize, offset); - wasm_runtime_free(buf); - } -#endif - fd_object_release(fo); - if (len < 0) - return convert_errno(errno); - *nwritten = (size_t)len; - return 0; + return error; } __wasi_errno_t -wasmtime_ssp_fd_read( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, const __wasi_iovec_t *iov, size_t iovcnt, size_t *nread) +wasmtime_ssp_fd_read(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, const __wasi_iovec_t *iov, size_t iovcnt, + size_t *nread) { struct fd_object *fo; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, __WASI_RIGHT_FD_READ, 0); + if (error != 0) return error; - ssize_t len = readv(fd_number(fo), (const struct iovec *)iov, (int)iovcnt); - fd_object_release(fo); - if (len < 0) - return convert_errno(errno); - *nread = (size_t)len; - return 0; + error = + blocking_op_readv(exec_env, fo->file_handle, iov, (int)iovcnt, nread); + + fd_object_release(exec_env, fo); + + return error; } __wasi_errno_t -wasmtime_ssp_fd_renumber( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, struct fd_prestats *prestats, -#endif - __wasi_fd_t from, __wasi_fd_t to) -{ - // Don't allow renumbering over a pre-opened resource. - // TODO: Eventually, we do want to permit this, once libpreopen in - // userspace is capable of removing entries from its tables as well. - { - rwlock_rdlock(&prestats->lock); - struct fd_prestat *prestat; - __wasi_errno_t error = fd_prestats_get_entry(prestats, to, &prestat); - if (error != 0) { - error = fd_prestats_get_entry(prestats, from, &prestat); - } - rwlock_unlock(&prestats->lock); - if (error == 0) { - return __WASI_ENOTSUP; - } - } - +wasmtime_ssp_fd_renumber(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct fd_prestats *prestats, __wasi_fd_t from, + __wasi_fd_t to) +{ struct fd_table *ft = curfds; rwlock_wrlock(&ft->lock); + rwlock_wrlock(&prestats->lock); + struct fd_entry *fe_from; __wasi_errno_t error = fd_table_get_entry(ft, from, 0, 0, &fe_from); if (error != 0) { + rwlock_unlock(&prestats->lock); rwlock_unlock(&ft->lock); return error; } struct fd_entry *fe_to; error = fd_table_get_entry(ft, to, 0, 0, &fe_to); if (error != 0) { + rwlock_unlock(&prestats->lock); rwlock_unlock(&ft->lock); return error; } @@ -1129,40 +917,67 @@ wasmtime_ssp_fd_renumber( refcount_acquire(&fe_from->object->refcount); fd_table_attach(ft, to, fe_from->object, fe_from->rights_base, fe_from->rights_inheriting); - fd_object_release(fo); + fd_object_release(exec_env, fo); // Remove the old fd from the file descriptor table. fd_table_detach(ft, from, &fo); - fd_object_release(fo); + fd_object_release(exec_env, fo); --ft->used; + // Handle renumbering of any preopened resources + struct fd_prestat *prestat_from; + __wasi_errno_t prestat_from_error = + fd_prestats_get_entry(prestats, from, &prestat_from); + + struct fd_prestat *prestat_to; + __wasi_errno_t prestat_to_error = + fd_prestats_get_entry(prestats, to, &prestat_to); + + // Renumbering over two preopened resources. + if (prestat_from_error == __WASI_ESUCCESS + && prestat_to_error == __WASI_ESUCCESS) { + (void)fd_prestats_remove_entry(prestats, to); + + error = fd_prestats_insert_locked(prestats, prestat_from->dir, to); + + if (error == __WASI_ESUCCESS) { + (void)fd_prestats_remove_entry(prestats, from); + } + else { + (void)fd_prestats_remove_entry(prestats, to); + } + } + // Renumbering from a non-preopened fd to a preopened fd. In this case, + // we can't a keep the destination fd entry in the preopened table so + // remove it entirely. + else if (prestat_from_error != __WASI_ESUCCESS + && prestat_to_error == __WASI_ESUCCESS) { + (void)fd_prestats_remove_entry(prestats, to); + } + // Renumbering from a preopened fd to a non-preopened fd + else if (prestat_from_error == __WASI_ESUCCESS + && prestat_to_error != __WASI_ESUCCESS) { + error = fd_prestats_insert_locked(prestats, prestat_from->dir, to); + + if (error == __WASI_ESUCCESS) { + (void)fd_prestats_remove_entry(prestats, from); + } + else { + (void)fd_prestats_remove_entry(prestats, to); + } + } + + rwlock_unlock(&prestats->lock); rwlock_unlock(&ft->lock); - return 0; + + return error; } __wasi_errno_t -wasmtime_ssp_fd_seek( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_filedelta_t offset, __wasi_whence_t whence, - __wasi_filesize_t *newoffset) +wasmtime_ssp_fd_seek(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_filedelta_t offset, + __wasi_whence_t whence, __wasi_filesize_t *newoffset) { - int nwhence; - switch (whence) { - case __WASI_WHENCE_CUR: - nwhence = SEEK_CUR; - break; - case __WASI_WHENCE_END: - nwhence = SEEK_END; - break; - case __WASI_WHENCE_SET: - nwhence = SEEK_SET; - break; - default: - return __WASI_EINVAL; - } - struct fd_object *fo; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, @@ -1173,20 +988,16 @@ wasmtime_ssp_fd_seek( if (error != 0) return error; - off_t ret = lseek(fd_number(fo), offset, nwhence); - fd_object_release(fo); - if (ret < 0) - return convert_errno(errno); - *newoffset = (__wasi_filesize_t)ret; - return 0; + error = os_lseek(fo->file_handle, offset, whence, newoffset); + + fd_object_release(exec_env, fo); + + return error; } __wasi_errno_t -wasmtime_ssp_fd_tell( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_filesize_t *newoffset) +wasmtime_ssp_fd_tell(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_filesize_t *newoffset) { struct fd_object *fo; __wasi_errno_t error = @@ -1194,113 +1005,70 @@ wasmtime_ssp_fd_tell( if (error != 0) return error; - off_t ret = lseek(fd_number(fo), 0, SEEK_CUR); - fd_object_release(fo); - if (ret < 0) - return convert_errno(errno); - *newoffset = (__wasi_filesize_t)ret; - return 0; + error = os_lseek(fo->file_handle, 0, __WASI_WHENCE_CUR, newoffset); + + fd_object_release(exec_env, fo); + + return error; } __wasi_errno_t -wasmtime_ssp_fd_fdstat_get( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_fdstat_t *buf) +wasmtime_ssp_fd_fdstat_get(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_fdstat_t *buf) { struct fd_table *ft = curfds; rwlock_rdlock(&ft->lock); struct fd_entry *fe; __wasi_errno_t error = fd_table_get_entry(ft, fd, 0, 0, &fe); - if (error != 0) { + if (error != __WASI_ESUCCESS) { rwlock_unlock(&ft->lock); return error; } // Extract file descriptor type and rights. struct fd_object *fo = fe->object; - *buf = (__wasi_fdstat_t){ - .fs_filetype = fo->type, - .fs_rights_base = fe->rights_base, - .fs_rights_inheriting = fe->rights_inheriting, - }; - // Fetch file descriptor flags. - int ret; - switch (fo->type) { - default: - ret = fcntl(fd_number(fo), F_GETFL); - break; + __wasi_fdflags_t flags; + error = os_file_get_fdflags(fo->file_handle, &flags); + + if (error != __WASI_ESUCCESS) { + rwlock_unlock(&ft->lock); + return error; } - rwlock_unlock(&ft->lock); - if (ret < 0) - return convert_errno(errno); - if ((ret & O_APPEND) != 0) - buf->fs_flags |= __WASI_FDFLAG_APPEND; -#ifdef O_DSYNC - if ((ret & O_DSYNC) != 0) - buf->fs_flags |= __WASI_FDFLAG_DSYNC; -#endif - if ((ret & O_NONBLOCK) != 0) - buf->fs_flags |= __WASI_FDFLAG_NONBLOCK; -#ifdef O_RSYNC - if ((ret & O_RSYNC) != 0) - buf->fs_flags |= __WASI_FDFLAG_RSYNC; -#endif - if ((ret & O_SYNC) != 0) - buf->fs_flags |= __WASI_FDFLAG_SYNC; - return 0; + *buf = (__wasi_fdstat_t){ .fs_filetype = fo->type, + .fs_rights_base = fe->rights_base, + .fs_rights_inheriting = fe->rights_inheriting, + .fs_flags = flags }; + + rwlock_unlock(&ft->lock); + return error; } __wasi_errno_t -wasmtime_ssp_fd_fdstat_set_flags( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_fdflags_t fs_flags) -{ - int noflags = 0; - if ((fs_flags & __WASI_FDFLAG_APPEND) != 0) - noflags |= O_APPEND; - if ((fs_flags & __WASI_FDFLAG_DSYNC) != 0) -#ifdef O_DSYNC - noflags |= O_DSYNC; -#else - noflags |= O_SYNC; -#endif - if ((fs_flags & __WASI_FDFLAG_NONBLOCK) != 0) - noflags |= O_NONBLOCK; - if ((fs_flags & __WASI_FDFLAG_RSYNC) != 0) -#ifdef O_RSYNC - noflags |= O_RSYNC; -#else - noflags |= O_SYNC; -#endif - if ((fs_flags & __WASI_FDFLAG_SYNC) != 0) - noflags |= O_SYNC; - +wasmtime_ssp_fd_fdstat_set_flags(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_fdflags_t fs_flags) +{ struct fd_object *fo; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, __WASI_RIGHT_FD_FDSTAT_SET_FLAGS, 0); + if (error != 0) return error; - int ret = fcntl(fd_number(fo), F_SETFL, noflags); - fd_object_release(fo); - if (ret < 0) - return convert_errno(errno); - return 0; + error = os_file_set_fdflags(fo->file_handle, fs_flags); + + fd_object_release(exec_env, fo); + + return error; } __wasi_errno_t -wasmtime_ssp_fd_fdstat_set_rights( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_rights_t fs_rights_base, - __wasi_rights_t fs_rights_inheriting) +wasmtime_ssp_fd_fdstat_set_rights(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_rights_t fs_rights_base, + __wasi_rights_t fs_rights_inheriting) { struct fd_table *ft = curfds; rwlock_wrlock(&ft->lock); @@ -1320,31 +1088,27 @@ wasmtime_ssp_fd_fdstat_set_rights( } __wasi_errno_t -wasmtime_ssp_fd_sync( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd) +wasmtime_ssp_fd_sync(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd) { struct fd_object *fo; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, __WASI_RIGHT_FD_SYNC, 0); + if (error != 0) return error; - int ret = fsync(fd_number(fo)); - fd_object_release(fo); - if (ret < 0) - return convert_errno(errno); - return 0; + error = os_fsync(fo->file_handle); + + fd_object_release(exec_env, fo); + + return error; } __wasi_errno_t -wasmtime_ssp_fd_write( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, const __wasi_ciovec_t *iov, size_t iovcnt, size_t *nwritten) +wasmtime_ssp_fd_write(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, const __wasi_ciovec_t *iov, size_t iovcnt, + size_t *nwritten) { struct fd_object *fo; __wasi_errno_t error = @@ -1353,142 +1117,81 @@ wasmtime_ssp_fd_write( return error; #ifndef BH_VPRINTF - ssize_t len = writev(fd_number(fo), (const struct iovec *)iov, (int)iovcnt); + error = blocking_op_writev(exec_env, fo->file_handle, iov, (int)iovcnt, + nwritten); #else - ssize_t len = 0; /* redirect stdout/stderr output to BH_VPRINTF function */ - if (fd_number(fo) == 1 || fd_number(fo) == 2) { + if (fo->is_stdio) { int i; - const struct iovec *iov1 = (const struct iovec *)iov; - - for (i = 0; i < (int)iovcnt; i++, iov1++) { - if (iov1->iov_len > 0 && iov1->iov_base) { + *nwritten = 0; + for (i = 0; i < (int)iovcnt; i++) { + if (iov[i].buf_len > 0 && iov[i].buf != NULL) { char format[16]; /* make up format string "%.ns" */ - snprintf(format, sizeof(format), "%%.%ds", (int)iov1->iov_len); - len += (ssize_t)os_printf(format, iov1->iov_base); + snprintf(format, sizeof(format), "%%.%ds", (int)iov[i].buf_len); + *nwritten += (size_t)os_printf(format, iov[i].buf); } } } else { - len = writev(fd_number(fo), (const struct iovec *)iov, (int)iovcnt); + error = blocking_op_writev(exec_env, fo->file_handle, iov, (int)iovcnt, + nwritten); } #endif /* end of BH_VPRINTF */ - fd_object_release(fo); - if (len < 0) - return convert_errno(errno); - *nwritten = (size_t)len; - return 0; + fd_object_release(exec_env, fo); + + return error; } __wasi_errno_t -wasmtime_ssp_fd_advise( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_filesize_t offset, __wasi_filesize_t len, - __wasi_advice_t advice) -{ -#ifdef POSIX_FADV_NORMAL - int nadvice; - switch (advice) { - case __WASI_ADVICE_DONTNEED: - nadvice = POSIX_FADV_DONTNEED; - break; - case __WASI_ADVICE_NOREUSE: - nadvice = POSIX_FADV_NOREUSE; - break; - case __WASI_ADVICE_NORMAL: - nadvice = POSIX_FADV_NORMAL; - break; - case __WASI_ADVICE_RANDOM: - nadvice = POSIX_FADV_RANDOM; - break; - case __WASI_ADVICE_SEQUENTIAL: - nadvice = POSIX_FADV_SEQUENTIAL; - break; - case __WASI_ADVICE_WILLNEED: - nadvice = POSIX_FADV_WILLNEED; - break; - default: - return __WASI_EINVAL; - } - +wasmtime_ssp_fd_advise(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_filesize_t offset, + __wasi_filesize_t len, __wasi_advice_t advice) +{ struct fd_object *fo; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, __WASI_RIGHT_FD_ADVISE, 0); if (error != 0) return error; - int ret = posix_fadvise(fd_number(fo), (off_t)offset, (off_t)len, nadvice); - fd_object_release(fo); - if (ret != 0) - return convert_errno(ret); - return 0; -#else - // Advisory information can safely be ignored if unsupported. - switch (advice) { - case __WASI_ADVICE_DONTNEED: - case __WASI_ADVICE_NOREUSE: - case __WASI_ADVICE_NORMAL: - case __WASI_ADVICE_RANDOM: - case __WASI_ADVICE_SEQUENTIAL: - case __WASI_ADVICE_WILLNEED: - break; - default: - return __WASI_EINVAL; + if (fo->type == __WASI_FILETYPE_DIRECTORY) { + fd_object_release(exec_env, fo); + return __WASI_EBADF; } - // At least check for file descriptor existence. - struct fd_table *ft = curfds; - rwlock_rdlock(&ft->lock); - struct fd_entry *fe; - __wasi_errno_t error = - fd_table_get_entry(ft, fd, __WASI_RIGHT_FD_ADVISE, 0, &fe); - rwlock_unlock(&ft->lock); + error = os_fadvise(fo->file_handle, offset, len, advice); + + fd_object_release(exec_env, fo); + return error; -#endif } __wasi_errno_t -wasmtime_ssp_fd_allocate( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_filesize_t offset, __wasi_filesize_t len) +wasmtime_ssp_fd_allocate(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_filesize_t offset, + __wasi_filesize_t len) { struct fd_object *fo; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, __WASI_RIGHT_FD_ALLOCATE, 0); - if (error != 0) + if (error != __WASI_ESUCCESS) return error; -#if CONFIG_HAS_POSIX_FALLOCATE - int ret = posix_fallocate(fd_number(fo), (off_t)offset, (off_t)len); -#else - // At least ensure that the file is grown to the right size. - // TODO(ed): See if this can somehow be implemented without any race - // conditions. We may end up shrinking the file right now. - struct stat sb; - int ret = fstat(fd_number(fo), &sb); - off_t newsize = (off_t)(offset + len); - if (ret == 0 && sb.st_size < newsize) - ret = ftruncate(fd_number(fo), newsize); -#endif + error = os_fallocate(fo->file_handle, offset, len); - fd_object_release(fo); - if (ret != 0) - return convert_errno(ret); - return 0; + fd_object_release(exec_env, fo); + + return error; } // Reads the entire contents of a symbolic link, returning the contents // in an allocated buffer. The allocated buffer is large enough to fit // at least one extra byte, so the caller may append a trailing slash to // it. This is needed by path_get(). -static char * -readlinkat_dup(int fd, const char *path, size_t *p_len) +__wasi_errno_t +readlinkat_dup(os_file_handle handle, const char *path, size_t *p_len, + char **out_buf) { char *buf = NULL; size_t len = 32; @@ -1500,7 +1203,8 @@ readlinkat_dup(int fd, const char *path, size_t *p_len) if (newbuf == NULL) { if (buf) wasm_runtime_free(buf); - return NULL; + *out_buf = NULL; + return __WASI_ENOMEM; } if (buf != NULL) { @@ -1509,15 +1213,20 @@ readlinkat_dup(int fd, const char *path, size_t *p_len) } buf = newbuf; - ssize_t ret = readlinkat(fd, path, buf, len); - if (ret < 0) { + size_t bytes_read = 0; + __wasi_errno_t error = + os_readlinkat(handle, path, buf, len, &bytes_read); + if (error != __WASI_ESUCCESS) { wasm_runtime_free(buf); - return NULL; + *out_buf = NULL; + return error; } - if ((size_t)ret + 1 < len) { - buf[ret] = '\0'; + if ((size_t)bytes_read + 1 < len) { + buf[bytes_read] = '\0'; *p_len = len; - return buf; + *out_buf = buf; + + return __WASI_ESUCCESS; } len_org = len; len *= 2; @@ -1531,7 +1240,7 @@ readlinkat_dup(int fd, const char *path, size_t *p_len) // descriptor representing the directory where the lookup needs to start // and the actual pathname string. struct path_access { - int fd; // Directory file descriptor. + os_file_handle fd; // Directory file descriptor. const char *path; // Pathname. bool follow; // Whether symbolic links should be followed. char *path_start; // Internal: pathname to free. @@ -1543,10 +1252,10 @@ struct path_access { // pathname to ensure the target path is placed underneath the // directory. static __wasi_errno_t -path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd, - __wasi_lookupflags_t flags, const char *upath, size_t upathlen, - __wasi_rights_t rights_base, __wasi_rights_t rights_inheriting, - bool needs_final_component) +path_get(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct path_access *pa, __wasi_fd_t fd, __wasi_lookupflags_t flags, + const char *upath, size_t upathlen, __wasi_rights_t rights_base, + __wasi_rights_t rights_inheriting, bool needs_final_component) TRYLOCKS_EXCLUSIVE(0, pa->fd_object->refcount) { char *path = str_nullterminate(upath, upathlen); @@ -1565,7 +1274,7 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd, #if CONFIG_HAS_CAP_ENTER // Rely on the kernel to constrain access to automatically constrain // access to files stored underneath this directory. - pa->fd = fd_number(fo); + pa->fd = fo->file_handle; pa->path = pa->path_start = path; pa->follow = (flags & __WASI_LOOKUP_SYMLINK_FOLLOW) != 0; pa->fd_object = fo; @@ -1580,8 +1289,8 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd, // causes a file descriptor to be pushed, while handling ".." entries // causes an entry to be popped. Index 0 cannot be popped, as this // would imply escaping the base directory. - int fds[128]; - fds[0] = fd_number(fo); + os_file_handle fds[128]; + fds[0] = fo->file_handle; size_t curfd = 0; // Stack of pathname strings used for symlink expansion. By using a @@ -1592,8 +1301,13 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd, paths[0] = paths_start[0] = path; size_t curpath = 0; size_t expansions = 0; - char *symlink; + char *symlink = NULL; size_t symlink_len; +#ifdef BH_PLATFORM_WINDOWS +#define PATH_SEPARATORS "/\\" +#else +#define PATH_SEPARATORS "/" +#endif for (;;) { // Extract the next pathname component from 'paths[curpath]', null @@ -1601,9 +1315,10 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd, // whether the pathname component is followed by one or more // trailing slashes, as this requires it to be a directory. char *file = paths[curpath]; - char *file_end = file + strcspn(file, "/"); - paths[curpath] = file_end + strspn(file_end, "/"); - bool ends_with_slashes = *file_end == '/'; + char *file_end = file + strcspn(file, PATH_SEPARATORS); + paths[curpath] = file_end + strspn(file_end, PATH_SEPARATORS); + bool ends_with_slashes = + (*file_end != '\0' && strchr(PATH_SEPARATORS, *file_end)); *file_end = '\0'; // Test for empty pathname strings and absolute paths. @@ -1623,7 +1338,10 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd, error = __WASI_ENOTCAPABLE; goto fail; } - close(fds[curfd--]); + error = os_close(fds[curfd--], false); + + if (error != __WASI_ESUCCESS) + goto fail; } else if (curpath > 0 || *paths[curpath] != '\0' || (ends_with_slashes && !needs_final_component)) { @@ -1632,16 +1350,14 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd, // components. In other words, a pathname component that must be a // directory. First attempt to obtain a directory file descriptor // for it. - int newdir = -#ifdef O_SEARCH - openat(fds[curfd], file, O_SEARCH | O_DIRECTORY | O_NOFOLLOW); -#else - openat(fds[curfd], file, O_RDONLY | O_DIRECTORY | O_NOFOLLOW); -#endif - if (newdir != -1) { + os_file_handle newdir; + error = blocking_op_openat( + exec_env, fds[curfd], file, __WASI_O_DIRECTORY, 0, 0, + WASI_LIBC_ACCESS_MODE_READ_ONLY, &newdir); + if (error == __WASI_ESUCCESS) { // Success. Push it onto the directory stack. if (curfd + 1 == sizeof(fds) / sizeof(fds[0])) { - close(newdir); + os_close(newdir, false); error = __WASI_ENAMETOOLONG; goto fail; } @@ -1649,20 +1365,23 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd, } else { // Failed to open it. Attempt symlink expansion. - if (errno != ELOOP && errno != EMLINK && errno != ENOTDIR) { - error = convert_errno(errno); + if (error != __WASI_ELOOP && error != __WASI_EMLINK + && error != __WASI_ENOTDIR) { goto fail; } - symlink = readlinkat_dup(fds[curfd], file, &symlink_len); - if (symlink != NULL) + error = + readlinkat_dup(fds[curfd], file, &symlink_len, &symlink); + + if (error == __WASI_ESUCCESS) { + bh_assert(symlink != NULL); goto push_symlink; + } // readlink returns EINVAL if the path isn't a symlink. In that // case, it's more informative to return ENOTDIR. - if (errno == EINVAL) - errno = ENOTDIR; + if (error == __WASI_EINVAL) + error = __WASI_ENOTDIR; - error = convert_errno(errno); goto fail; } } @@ -1672,11 +1391,13 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd, // expansion. if (ends_with_slashes || (flags & __WASI_LOOKUP_SYMLINK_FOLLOW) != 0) { - symlink = readlinkat_dup(fds[curfd], file, &symlink_len); - if (symlink != NULL) + error = + readlinkat_dup(fds[curfd], file, &symlink_len, &symlink); + if (error == __WASI_ESUCCESS) { + bh_assert(symlink != NULL); goto push_symlink; - if (errno != EINVAL && errno != ENOENT) { - error = convert_errno(errno); + } + if (error != __WASI_EINVAL && error != __WASI_ENOENT) { goto fail; } } @@ -1753,7 +1474,7 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd, // Return the lease. Close all directories, except the one the caller // needs to use. for (size_t i = 1; i < curfd; ++i) - close(fds[i]); + os_close(fds[i], false); pa->fd = fds[curfd]; pa->follow = false; pa->fd_object = fo; @@ -1762,23 +1483,23 @@ path_get(struct fd_table *curfds, struct path_access *pa, __wasi_fd_t fd, fail: // Failure. Free all resources. for (size_t i = 1; i <= curfd; ++i) - close(fds[i]); + os_close(fds[i], false); for (size_t i = 0; i <= curpath; ++i) wasm_runtime_free(paths_start[i]); - fd_object_release(fo); + fd_object_release(NULL, fo); return error; #endif } static __wasi_errno_t -path_get_nofollow(struct fd_table *curfds, struct path_access *pa, - __wasi_fd_t fd, const char *path, size_t pathlen, - __wasi_rights_t rights_base, +path_get_nofollow(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct path_access *pa, __wasi_fd_t fd, const char *path, + size_t pathlen, __wasi_rights_t rights_base, __wasi_rights_t rights_inheriting, bool needs_final_component) TRYLOCKS_EXCLUSIVE(0, pa->fd_object->refcount) { __wasi_lookupflags_t flags = 0; - return path_get(curfds, pa, fd, flags, path, pathlen, rights_base, + return path_get(exec_env, curfds, pa, fd, flags, path, pathlen, rights_base, rights_inheriting, needs_final_component); } @@ -1787,30 +1508,27 @@ path_put(struct path_access *pa) UNLOCKS(pa->fd_object->refcount) { if (pa->path_start) wasm_runtime_free(pa->path_start); - if (fd_number(pa->fd_object) != pa->fd) - close(pa->fd); - fd_object_release(pa->fd_object); + if (pa->fd_object->file_handle != pa->fd) + os_close(pa->fd, false); + fd_object_release(NULL, pa->fd_object); } __wasi_errno_t -wasmtime_ssp_path_create_directory( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, const char *path, size_t pathlen) +wasmtime_ssp_path_create_directory(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + const char *path, size_t pathlen) { struct path_access pa; __wasi_errno_t error = - path_get_nofollow(curfds, &pa, fd, path, pathlen, + path_get_nofollow(exec_env, curfds, &pa, fd, path, pathlen, __WASI_RIGHT_PATH_CREATE_DIRECTORY, 0, true); if (error != 0) return error; - int ret = mkdirat(pa.fd, pa.path, 0777); + error = os_mkdirat(pa.fd, pa.path); path_put(&pa); - if (ret < 0) - return convert_errno(errno); - return 0; + + return error; } static bool @@ -1820,7 +1538,7 @@ validate_path(const char *path, struct fd_prestats *pt) char path_resolved[PATH_MAX], prestat_dir_resolved[PATH_MAX]; char *path_real, *prestat_dir_real; - if (!(path_real = realpath(path, path_resolved))) + if (!(path_real = os_realpath(path, path_resolved))) /* path doesn't exist, creating a link to this file is allowed: if this file is to be created in the future, WASI will strictly check whether it @@ -1830,7 +1548,7 @@ validate_path(const char *path, struct fd_prestats *pt) for (i = 0; i < pt->size; i++) { if (pt->prestats[i].dir) { if (!(prestat_dir_real = - realpath(pt->prestats[i].dir, prestat_dir_resolved))) + os_realpath(pt->prestats[i].dir, prestat_dir_resolved))) return false; if (!strncmp(path_real, prestat_dir_real, strlen(prestat_dir_real))) return true; @@ -1841,24 +1559,23 @@ validate_path(const char *path, struct fd_prestats *pt) } __wasi_errno_t -wasmtime_ssp_path_link( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, struct fd_prestats *prestats, -#endif - __wasi_fd_t old_fd, __wasi_lookupflags_t old_flags, const char *old_path, - size_t old_path_len, __wasi_fd_t new_fd, const char *new_path, - size_t new_path_len) +wasmtime_ssp_path_link(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct fd_prestats *prestats, __wasi_fd_t old_fd, + __wasi_lookupflags_t old_flags, const char *old_path, + size_t old_path_len, __wasi_fd_t new_fd, + const char *new_path, size_t new_path_len) { struct path_access old_pa; __wasi_errno_t error = - path_get(curfds, &old_pa, old_fd, old_flags, old_path, old_path_len, - __WASI_RIGHT_PATH_LINK_SOURCE, 0, false); + path_get(exec_env, curfds, &old_pa, old_fd, old_flags, old_path, + old_path_len, __WASI_RIGHT_PATH_LINK_SOURCE, 0, false); if (error != 0) return error; struct path_access new_pa; - error = path_get_nofollow(curfds, &new_pa, new_fd, new_path, new_path_len, - __WASI_RIGHT_PATH_LINK_TARGET, 0, true); + error = + path_get_nofollow(exec_env, curfds, &new_pa, new_fd, new_path, + new_path_len, __WASI_RIGHT_PATH_LINK_TARGET, 0, true); if (error != 0) { path_put(&old_pa); return error; @@ -1872,14 +1589,18 @@ wasmtime_ssp_path_link( } rwlock_unlock(&prestats->lock); - int ret = linkat(old_pa.fd, old_pa.path, new_pa.fd, new_pa.path, - old_pa.follow ? AT_SYMLINK_FOLLOW : 0); - if (ret < 0 && errno == ENOTSUP && !old_pa.follow) { + error = os_linkat(old_pa.fd, old_pa.path, new_pa.fd, new_pa.path, + old_pa.follow ? __WASI_LOOKUP_SYMLINK_FOLLOW : 0); + +#if defined(__APPLE__) + if (error == __WASI_ENOTSUP && !old_pa.follow) { // OS X doesn't allow creating hardlinks to symbolic links. // Duplicate the symbolic link instead. size_t target_len; - char *target = readlinkat_dup(old_pa.fd, old_pa.path, &target_len); - if (target != NULL) { + char *target = NULL; + error = readlinkat_dup(old_pa.fd, old_pa.path, &target_len, &target); + if (error == __WASI_ESUCCESS) { + bh_assert(target != NULL); bh_assert(target[target_len] == '\0'); rwlock_rdlock(&prestats->lock); if (!validate_path(target, prestats)) { @@ -1888,26 +1609,25 @@ wasmtime_ssp_path_link( return __WASI_EBADF; } rwlock_unlock(&prestats->lock); - ret = symlinkat(target, new_pa.fd, new_pa.path); + error = os_symlinkat(target, new_pa.fd, new_pa.path); wasm_runtime_free(target); } } +#endif + path_put(&old_pa); path_put(&new_pa); - if (ret < 0) - return convert_errno(errno); - return 0; + + return error; } __wasi_errno_t -wasmtime_ssp_path_open( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t dirfd, __wasi_lookupflags_t dirflags, const char *path, - size_t pathlen, __wasi_oflags_t oflags, __wasi_rights_t fs_rights_base, - __wasi_rights_t fs_rights_inheriting, __wasi_fdflags_t fs_flags, - __wasi_fd_t *fd) +wasmtime_ssp_path_open(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t dirfd, __wasi_lookupflags_t dirflags, + const char *path, size_t pathlen, __wasi_oflags_t oflags, + __wasi_rights_t fs_rights_base, + __wasi_rights_t fs_rights_inheriting, + __wasi_fdflags_t fs_flags, __wasi_fd_t *fd) { // Rights that should be installed on the new file descriptor. __wasi_rights_t rights_base = fs_rights_base; @@ -1921,7 +1641,11 @@ wasmtime_ssp_path_open( & (__WASI_RIGHT_FD_DATASYNC | __WASI_RIGHT_FD_WRITE | __WASI_RIGHT_FD_ALLOCATE | __WASI_RIGHT_FD_FILESTAT_SET_SIZE)) != 0; - int noflags = write ? read ? O_RDWR : O_WRONLY : O_RDONLY; + + wasi_libc_file_access_mode access_mode = + write ? read ? WASI_LIBC_ACCESS_MODE_READ_WRITE + : WASI_LIBC_ACCESS_MODE_WRITE_ONLY + : WASI_LIBC_ACCESS_MODE_READ_ONLY; // Which rights are needed on the directory file descriptor. __wasi_rights_t needed_base = __WASI_RIGHT_PATH_OPEN; @@ -1929,113 +1653,58 @@ wasmtime_ssp_path_open( // Convert open flags. if ((oflags & __WASI_O_CREAT) != 0) { - noflags |= O_CREAT; needed_base |= __WASI_RIGHT_PATH_CREATE_FILE; } - if ((oflags & __WASI_O_DIRECTORY) != 0) - noflags |= O_DIRECTORY; - if ((oflags & __WASI_O_EXCL) != 0) - noflags |= O_EXCL; if ((oflags & __WASI_O_TRUNC) != 0) { - noflags |= O_TRUNC; needed_base |= __WASI_RIGHT_PATH_FILESTAT_SET_SIZE; } // Convert file descriptor flags. - if ((fs_flags & __WASI_FDFLAG_APPEND) != 0) - noflags |= O_APPEND; - if ((fs_flags & __WASI_FDFLAG_DSYNC) != 0) { -#ifdef O_DSYNC - noflags |= O_DSYNC; -#else - noflags |= O_SYNC; -#endif - needed_inheriting |= __WASI_RIGHT_FD_DATASYNC; + if ((fs_flags & __WASI_FDFLAG_SYNC) != 0) { + needed_inheriting |= __WASI_RIGHT_FD_SYNC; } - if ((fs_flags & __WASI_FDFLAG_NONBLOCK) != 0) - noflags |= O_NONBLOCK; if ((fs_flags & __WASI_FDFLAG_RSYNC) != 0) { -#ifdef O_RSYNC - noflags |= O_RSYNC; -#else - noflags |= O_SYNC; -#endif needed_inheriting |= __WASI_RIGHT_FD_SYNC; } - if ((fs_flags & __WASI_FDFLAG_SYNC) != 0) { - noflags |= O_SYNC; - needed_inheriting |= __WASI_RIGHT_FD_SYNC; + if ((fs_flags & __WASI_FDFLAG_DSYNC) != 0) { + needed_inheriting |= __WASI_RIGHT_FD_DATASYNC; } - if (write && (noflags & (O_APPEND | O_TRUNC)) == 0) + + if (write + && !((fs_flags & __WASI_FDFLAG_APPEND) || (__WASI_O_TRUNC & oflags))) needed_inheriting |= __WASI_RIGHT_FD_SEEK; struct path_access pa; - __wasi_errno_t error = - path_get(curfds, &pa, dirfd, dirflags, path, pathlen, needed_base, - needed_inheriting, (oflags & __WASI_O_CREAT) != 0); + __wasi_errno_t error = path_get( + exec_env, curfds, &pa, dirfd, dirflags, path, pathlen, needed_base, + needed_inheriting, (oflags & __WASI_O_CREAT) != 0); + if (error != 0) return error; - if (!pa.follow) - noflags |= O_NOFOLLOW; - - int nfd = openat(pa.fd, pa.path, noflags, 0666); - if (nfd < 0) { - int openat_errno = errno; - // Linux returns ENXIO instead of EOPNOTSUPP when opening a socket. - if (openat_errno == ENXIO) { - struct stat sb; - int ret = fstatat(pa.fd, pa.path, &sb, - pa.follow ? 0 : AT_SYMLINK_NOFOLLOW); - path_put(&pa); - return ret == 0 && S_ISSOCK(sb.st_mode) ? __WASI_ENOTSUP - : __WASI_ENXIO; - } - // Linux returns ENOTDIR instead of ELOOP when using - // O_NOFOLLOW|O_DIRECTORY on a symlink. - if (openat_errno == ENOTDIR - && (noflags & (O_NOFOLLOW | O_DIRECTORY)) != 0) { - struct stat sb; - int ret = fstatat(pa.fd, pa.path, &sb, AT_SYMLINK_NOFOLLOW); - if (S_ISLNK(sb.st_mode)) { - path_put(&pa); - return __WASI_ELOOP; - } - (void)ret; - } - path_put(&pa); - // FreeBSD returns EMLINK instead of ELOOP when using O_NOFOLLOW on - // a symlink. - if (!pa.follow && openat_errno == EMLINK) - return __WASI_ELOOP; - return convert_errno(openat_errno); - } + + os_file_handle handle; + error = blocking_op_openat(exec_env, pa.fd, pa.path, oflags, fs_flags, + dirflags, access_mode, &handle); + path_put(&pa); + if (error != __WASI_ESUCCESS) + return error; + // Determine the type of the new file descriptor and which rights // contradict with this type. __wasi_filetype_t type; __wasi_rights_t max_base, max_inheriting; - error = fd_determine_type_rights(nfd, &type, &max_base, &max_inheriting); - if (error != 0) { - close(nfd); - return error; - } - - { - struct stat sb; - if (fstat(nfd, &sb) < 0) { - close(nfd); - return convert_errno(errno); - } + error = fd_determine_type_rights(handle, &type, &max_base, &max_inheriting); - if (S_ISDIR(sb.st_mode)) - rights_base |= (__wasi_rights_t)RIGHTS_DIRECTORY_BASE; - else if (S_ISREG(sb.st_mode)) - rights_base |= (__wasi_rights_t)RIGHTS_REGULAR_FILE_BASE; + if (error != __WASI_ESUCCESS) { + os_close(handle, false); + return error; } - return fd_table_insert_fd(curfds, nfd, type, rights_base & max_base, + return fd_table_insert_fd(exec_env, curfds, handle, type, + rights_base & max_base, rights_inheriting & max_inheriting, fd); } @@ -2054,12 +1723,9 @@ fd_readdir_put(void *buf, size_t bufsize, size_t *bufused, const void *elem, } __wasi_errno_t -wasmtime_ssp_fd_readdir( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, void *buf, size_t nbyte, __wasi_dircookie_t cookie, - size_t *bufused) +wasmtime_ssp_fd_readdir(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, void *buf, size_t nbyte, + __wasi_dircookie_t cookie, size_t *bufused) { struct fd_object *fo; __wasi_errno_t error = @@ -2070,15 +1736,13 @@ wasmtime_ssp_fd_readdir( // Create a directory handle if none has been opened yet. mutex_lock(&fo->directory.lock); - DIR *dp = fo->directory.handle; - if (dp == NULL) { - dp = fdopendir(fd_number(fo)); - if (dp == NULL) { + if (!os_is_dir_stream_valid(&fo->directory.handle)) { + error = os_fdopendir(fo->file_handle, &fo->directory.handle); + if (error != __WASI_ESUCCESS) { mutex_unlock(&fo->directory.lock); - fd_object_release(fo); - return convert_errno(errno); + fd_object_release(exec_env, fo); + return error; } - fo->directory.handle = dp; fo->directory.offset = __WASI_DIRCOOKIE_START; } @@ -2086,173 +1750,102 @@ wasmtime_ssp_fd_readdir( // the current offset. if (fo->directory.offset != cookie) { if (cookie == __WASI_DIRCOOKIE_START) - rewinddir(dp); + os_rewinddir(fo->directory.handle); else - seekdir(dp, (long)cookie); + os_seekdir(fo->directory.handle, cookie); fo->directory.offset = cookie; } *bufused = 0; while (*bufused < nbyte) { // Read the next directory entry. - errno = 0; - struct dirent *de = readdir(dp); - if (de == NULL) { + __wasi_dirent_t cde; + const char *d_name = NULL; + + error = os_readdir(fo->directory.handle, &cde, &d_name); + if (d_name == NULL) { mutex_unlock(&fo->directory.lock); - fd_object_release(fo); - return errno == 0 || *bufused > 0 ? 0 : convert_errno(errno); - } - fo->directory.offset = (__wasi_dircookie_t)telldir(dp); - - // Craft a directory entry and copy that back. - size_t namlen = strlen(de->d_name); - __wasi_dirent_t cde = { - .d_next = fo->directory.offset, -#if CONFIG_HAS_D_INO - .d_ino = de->d_ino, -#else - .d_ino = 0, -#endif - .d_namlen = (uint32)namlen, - }; - switch (de->d_type) { - case DT_BLK: - cde.d_type = __WASI_FILETYPE_BLOCK_DEVICE; - break; - case DT_CHR: - cde.d_type = __WASI_FILETYPE_CHARACTER_DEVICE; - break; - case DT_DIR: - cde.d_type = __WASI_FILETYPE_DIRECTORY; - break; - case DT_FIFO: - cde.d_type = __WASI_FILETYPE_SOCKET_STREAM; - break; - case DT_LNK: - cde.d_type = __WASI_FILETYPE_SYMBOLIC_LINK; - break; - case DT_REG: - cde.d_type = __WASI_FILETYPE_REGULAR_FILE; - break; -#ifdef DT_SOCK - case DT_SOCK: - // Technically not correct, but good enough. - cde.d_type = __WASI_FILETYPE_SOCKET_STREAM; - break; -#endif - default: - cde.d_type = __WASI_FILETYPE_UNKNOWN; - break; + fd_object_release(exec_env, fo); + + return *bufused > 0 ? __WASI_ESUCCESS : error; } + + fo->directory.offset = cde.d_next; + fd_readdir_put(buf, nbyte, bufused, &cde, sizeof(cde)); - fd_readdir_put(buf, nbyte, bufused, de->d_name, namlen); + fd_readdir_put(buf, nbyte, bufused, d_name, cde.d_namlen); } mutex_unlock(&fo->directory.lock); - fd_object_release(fo); - return 0; + fd_object_release(exec_env, fo); + return __WASI_ESUCCESS; } __wasi_errno_t -wasmtime_ssp_path_readlink( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, const char *path, size_t pathlen, char *buf, size_t bufsize, - size_t *bufused) +wasmtime_ssp_path_readlink(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, const char *path, size_t pathlen, + char *buf, size_t bufsize, size_t *bufused) { struct path_access pa; - __wasi_errno_t error = path_get_nofollow( - curfds, &pa, fd, path, pathlen, __WASI_RIGHT_PATH_READLINK, 0, false); + __wasi_errno_t error = + path_get_nofollow(exec_env, curfds, &pa, fd, path, pathlen, + __WASI_RIGHT_PATH_READLINK, 0, false); + if (error != 0) return error; - // Linux requires that the buffer size is positive. whereas POSIX does - // not. Use a fake buffer to store the results if the size is zero. - char fakebuf[1]; - ssize_t len = readlinkat(pa.fd, pa.path, bufsize == 0 ? fakebuf : buf, - bufsize == 0 ? sizeof(fakebuf) : bufsize); + error = os_readlinkat(pa.fd, pa.path, buf, bufsize, bufused); + path_put(&pa); - if (len < 0) - return convert_errno(errno); - *bufused = (size_t)len < bufsize ? (size_t)len : bufsize; - return 0; + + return error; } __wasi_errno_t -wasmtime_ssp_path_rename( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t old_fd, const char *old_path, size_t old_path_len, - __wasi_fd_t new_fd, const char *new_path, size_t new_path_len) +wasmtime_ssp_path_rename(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t old_fd, const char *old_path, + size_t old_path_len, __wasi_fd_t new_fd, + const char *new_path, size_t new_path_len) { struct path_access old_pa; - __wasi_errno_t error = - path_get_nofollow(curfds, &old_pa, old_fd, old_path, old_path_len, - __WASI_RIGHT_PATH_RENAME_SOURCE, 0, true); + __wasi_errno_t error = path_get_nofollow( + exec_env, curfds, &old_pa, old_fd, old_path, old_path_len, + __WASI_RIGHT_PATH_RENAME_SOURCE, 0, true); if (error != 0) return error; struct path_access new_pa; - error = path_get_nofollow(curfds, &new_pa, new_fd, new_path, new_path_len, - __WASI_RIGHT_PATH_RENAME_TARGET, 0, true); + error = path_get_nofollow(exec_env, curfds, &new_pa, new_fd, new_path, + new_path_len, __WASI_RIGHT_PATH_RENAME_TARGET, 0, + true); if (error != 0) { path_put(&old_pa); return error; } - int ret = renameat(old_pa.fd, old_pa.path, new_pa.fd, new_pa.path); + error = os_renameat(old_pa.fd, old_pa.path, new_pa.fd, new_pa.path); + path_put(&old_pa); path_put(&new_pa); - if (ret < 0) { - return convert_errno(errno); - } - return 0; -} -// Converts a POSIX stat structure to a CloudABI filestat structure. -static void -convert_stat(const struct stat *in, __wasi_filestat_t *out) -{ - *out = (__wasi_filestat_t){ - .st_dev = in->st_dev, - .st_ino = in->st_ino, - .st_nlink = (__wasi_linkcount_t)in->st_nlink, - .st_size = (__wasi_filesize_t)in->st_size, - .st_atim = convert_timespec(&in->st_atim), - .st_mtim = convert_timespec(&in->st_mtim), - .st_ctim = convert_timespec(&in->st_ctim), - }; + return error; } __wasi_errno_t -wasmtime_ssp_fd_filestat_get( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_filestat_t *buf) +wasmtime_ssp_fd_filestat_get(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_filestat_t *buf) { struct fd_object *fo; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, __WASI_RIGHT_FD_FILESTAT_GET, 0); + if (error != 0) return error; - int ret; - switch (fo->type) { - default: - { - struct stat sb; - ret = fstat(fd_number(fo), &sb); - convert_stat(&sb, buf); - break; - } - } - buf->st_filetype = fo->type; - fd_object_release(fo); - if (ret < 0) - return convert_errno(errno); - return 0; + error = os_fstat(fo->file_handle, buf); + + fd_object_release(exec_env, fo); + + return error; } static void @@ -2270,61 +1863,30 @@ convert_timestamp(__wasi_timestamp_t in, struct timespec *out) out->tv_sec = (time_t)in < BH_TIME_T_MAX ? (time_t)in : BH_TIME_T_MAX; } -// Converts the provided timestamps and flags to a set of arguments for -// futimens() and utimensat(). -static void -convert_utimens_arguments(__wasi_timestamp_t st_atim, - __wasi_timestamp_t st_mtim, - __wasi_fstflags_t fstflags, struct timespec *ts) -{ - if ((fstflags & __WASI_FILESTAT_SET_ATIM_NOW) != 0) { - ts[0].tv_nsec = UTIME_NOW; - } - else if ((fstflags & __WASI_FILESTAT_SET_ATIM) != 0) { - convert_timestamp(st_atim, &ts[0]); - } - else { - ts[0].tv_nsec = UTIME_OMIT; - } - - if ((fstflags & __WASI_FILESTAT_SET_MTIM_NOW) != 0) { - ts[1].tv_nsec = UTIME_NOW; - } - else if ((fstflags & __WASI_FILESTAT_SET_MTIM) != 0) { - convert_timestamp(st_mtim, &ts[1]); - } - else { - ts[1].tv_nsec = UTIME_OMIT; - } -} - __wasi_errno_t -wasmtime_ssp_fd_filestat_set_size( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_filesize_t st_size) +wasmtime_ssp_fd_filestat_set_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_filesize_t st_size) { struct fd_object *fo; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, __WASI_RIGHT_FD_FILESTAT_SET_SIZE, 0); + if (error != 0) return error; - int ret = ftruncate(fd_number(fo), (off_t)st_size); - fd_object_release(fo); - if (ret < 0) - return convert_errno(errno); - return 0; + error = os_ftruncate(fo->file_handle, st_size); + fd_object_release(exec_env, fo); + + return error; } __wasi_errno_t -wasmtime_ssp_fd_filestat_set_times( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_timestamp_t st_atim, __wasi_timestamp_t st_mtim, - __wasi_fstflags_t fstflags) +wasmtime_ssp_fd_filestat_set_times(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_timestamp_t st_atim, + __wasi_timestamp_t st_mtim, + __wasi_fstflags_t fstflags) { if ((fstflags & ~(__WASI_FILESTAT_SET_ATIM | __WASI_FILESTAT_SET_ATIM_NOW @@ -2338,64 +1900,42 @@ wasmtime_ssp_fd_filestat_set_times( if (error != 0) return error; - struct timespec ts[2]; - convert_utimens_arguments(st_atim, st_mtim, fstflags, ts); - int ret = futimens(fd_number(fo), ts); + error = os_futimens(fo->file_handle, st_atim, st_mtim, fstflags); - fd_object_release(fo); - if (ret < 0) - return convert_errno(errno); - return 0; + fd_object_release(exec_env, fo); + + return error; } __wasi_errno_t -wasmtime_ssp_path_filestat_get( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_lookupflags_t flags, const char *path, - size_t pathlen, __wasi_filestat_t *buf) +wasmtime_ssp_path_filestat_get(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_lookupflags_t flags, const char *path, + size_t pathlen, __wasi_filestat_t *buf) { struct path_access pa; - __wasi_errno_t error = path_get(curfds, &pa, fd, flags, path, pathlen, - __WASI_RIGHT_PATH_FILESTAT_GET, 0, false); + __wasi_errno_t error = + path_get(exec_env, curfds, &pa, fd, flags, path, pathlen, + __WASI_RIGHT_PATH_FILESTAT_GET, 0, false); if (error != 0) return error; - struct stat sb; - int ret = fstatat(pa.fd, pa.path, &sb, pa.follow ? 0 : AT_SYMLINK_NOFOLLOW); + error = os_fstatat(pa.fd, pa.path, buf, + pa.follow ? __WASI_LOOKUP_SYMLINK_FOLLOW : 0); + path_put(&pa); - if (ret < 0) - return convert_errno(errno); - convert_stat(&sb, buf); - - // Convert the file type. In the case of sockets there is no way we - // can easily determine the exact socket type. - if (S_ISBLK(sb.st_mode)) - buf->st_filetype = __WASI_FILETYPE_BLOCK_DEVICE; - else if (S_ISCHR(sb.st_mode)) - buf->st_filetype = __WASI_FILETYPE_CHARACTER_DEVICE; - else if (S_ISDIR(sb.st_mode)) - buf->st_filetype = __WASI_FILETYPE_DIRECTORY; - else if (S_ISFIFO(sb.st_mode)) - buf->st_filetype = __WASI_FILETYPE_SOCKET_STREAM; - else if (S_ISLNK(sb.st_mode)) - buf->st_filetype = __WASI_FILETYPE_SYMBOLIC_LINK; - else if (S_ISREG(sb.st_mode)) - buf->st_filetype = __WASI_FILETYPE_REGULAR_FILE; - else if (S_ISSOCK(sb.st_mode)) - buf->st_filetype = __WASI_FILETYPE_SOCKET_STREAM; - return 0; + + return error; } __wasi_errno_t -wasmtime_ssp_path_filestat_set_times( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_lookupflags_t flags, const char *path, - size_t pathlen, __wasi_timestamp_t st_atim, __wasi_timestamp_t st_mtim, - __wasi_fstflags_t fstflags) +wasmtime_ssp_path_filestat_set_times(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_lookupflags_t flags, + const char *path, size_t pathlen, + __wasi_timestamp_t st_atim, + __wasi_timestamp_t st_mtim, + __wasi_fstflags_t fstflags) { if (((fstflags & ~(__WASI_FILESTAT_SET_ATIM | __WASI_FILESTAT_SET_ATIM_NOW @@ -2411,29 +1951,23 @@ wasmtime_ssp_path_filestat_set_times( struct path_access pa; __wasi_errno_t error = - path_get(curfds, &pa, fd, flags, path, pathlen, + path_get(exec_env, curfds, &pa, fd, flags, path, pathlen, __WASI_RIGHT_PATH_FILESTAT_SET_TIMES, 0, false); if (error != 0) return error; - struct timespec ts[2]; - convert_utimens_arguments(st_atim, st_mtim, fstflags, ts); - int ret = - utimensat(pa.fd, pa.path, ts, pa.follow ? 0 : AT_SYMLINK_NOFOLLOW); + error = os_utimensat(pa.fd, pa.path, st_atim, st_mtim, fstflags, + pa.follow ? __WASI_LOOKUP_SYMLINK_FOLLOW : 0); path_put(&pa); - if (ret < 0) - return convert_errno(errno); - return 0; + return error; } __wasi_errno_t -wasmtime_ssp_path_symlink( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, struct fd_prestats *prestats, -#endif - const char *old_path, size_t old_path_len, __wasi_fd_t fd, - const char *new_path, size_t new_path_len) +wasmtime_ssp_path_symlink(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct fd_prestats *prestats, const char *old_path, + size_t old_path_len, __wasi_fd_t fd, + const char *new_path, size_t new_path_len) { char *target = str_nullterminate(old_path, old_path_len); if (target == NULL) @@ -2441,7 +1975,7 @@ wasmtime_ssp_path_symlink( struct path_access pa; __wasi_errno_t error = - path_get_nofollow(curfds, &pa, fd, new_path, new_path_len, + path_get_nofollow(exec_env, curfds, &pa, fd, new_path, new_path_len, __WASI_RIGHT_PATH_SYMLINK, 0, true); if (error != 0) { wasm_runtime_free(target); @@ -2456,88 +1990,60 @@ wasmtime_ssp_path_symlink( } rwlock_unlock(&prestats->lock); - int ret = symlinkat(target, pa.fd, pa.path); + error = os_symlinkat(target, pa.fd, pa.path); + path_put(&pa); wasm_runtime_free(target); - if (ret < 0) - return convert_errno(errno); - return 0; + + return error; } __wasi_errno_t -wasmtime_ssp_path_unlink_file( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, const char *path, size_t pathlen) +wasmtime_ssp_path_unlink_file(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, const char *path, size_t pathlen) { struct path_access pa; - __wasi_errno_t error = path_get_nofollow( - curfds, &pa, fd, path, pathlen, __WASI_RIGHT_PATH_UNLINK_FILE, 0, true); - if (error != 0) + __wasi_errno_t error = + path_get_nofollow(exec_env, curfds, &pa, fd, path, pathlen, + __WASI_RIGHT_PATH_UNLINK_FILE, 0, true); + if (error != __WASI_ESUCCESS) return error; - int ret = unlinkat(pa.fd, pa.path, 0); -#ifndef __linux__ - // Non-Linux implementations may return EPERM when attempting to remove a - // directory without REMOVEDIR. While that's what POSIX specifies, it's - // less useful. Adjust this to EISDIR. It doesn't matter that this is not - // atomic with the unlinkat, because if the file is removed and a directory - // is created before fstatat sees it, we're racing with that change anyway - // and unlinkat could have legitimately seen the directory if the race had - // turned out differently. - if (ret < 0 && errno == EPERM) { - struct stat statbuf; - if (fstatat(pa.fd, pa.path, &statbuf, AT_SYMLINK_NOFOLLOW) == 0 - && S_ISDIR(statbuf.st_mode)) { - errno = EISDIR; - } - } -#endif + error = os_unlinkat(pa.fd, pa.path, false); + path_put(&pa); - if (ret < 0) { - return convert_errno(errno); - } - return 0; + + return error; } __wasi_errno_t -wasmtime_ssp_path_remove_directory( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, const char *path, size_t pathlen) +wasmtime_ssp_path_remove_directory(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + const char *path, size_t pathlen) { struct path_access pa; __wasi_errno_t error = - path_get_nofollow(curfds, &pa, fd, path, pathlen, + path_get_nofollow(exec_env, curfds, &pa, fd, path, pathlen, __WASI_RIGHT_PATH_REMOVE_DIRECTORY, 0, true); if (error != 0) return error; - int ret = unlinkat(pa.fd, pa.path, AT_REMOVEDIR); -#ifndef __linux__ - // POSIX permits either EEXIST or ENOTEMPTY when the directory is not empty. - // Map it to ENOTEMPTY. - if (ret < 0 && errno == EEXIST) { - errno = ENOTEMPTY; - } -#endif + error = os_unlinkat(pa.fd, pa.path, true); + path_put(&pa); - if (ret < 0) { - return convert_errno(errno); - } - return 0; + + return error; } __wasi_errno_t -wasmtime_ssp_poll_oneoff( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - const __wasi_subscription_t *in, __wasi_event_t *out, size_t nsubscriptions, - size_t *nevents) NO_LOCK_ANALYSIS +wasmtime_ssp_poll_oneoff(wasm_exec_env_t exec_env, struct fd_table *curfds, + const __wasi_subscription_t *in, __wasi_event_t *out, + size_t nsubscriptions, + size_t *nevents) NO_LOCK_ANALYSIS { +#ifdef BH_PLATFORM_WINDOWS + return __WASI_ENOSYS; +#else // Sleeping. if (nsubscriptions == 1 && in[0].u.type == __WASI_EVENTTYPE_CLOCK) { out[0] = (__wasi_event_t){ @@ -2546,7 +2052,7 @@ wasmtime_ssp_poll_oneoff( }; #if CONFIG_HAS_CLOCK_NANOSLEEP clockid_t clock_id; - if (convert_clockid(in[0].u.u.clock.clock_id, &clock_id)) { + if (wasi_clockid_to_clockid(in[0].u.u.clock.clock_id, &clock_id)) { struct timespec ts; convert_timestamp(in[0].u.u.clock.timeout, &ts); int ret = clock_nanosleep( @@ -2653,7 +2159,7 @@ wasmtime_ssp_poll_oneoff( if (error == 0) { // Proper file descriptor on which we can poll(). pfds[i] = (struct pollfd){ - .fd = fd_number(fos[i]), + .fd = fos[i]->file_handle, .events = s->u.type == __WASI_EVENTTYPE_FD_READ ? POLLIN : POLLOUT, @@ -2709,6 +2215,7 @@ wasmtime_ssp_poll_oneoff( else { timeout = -1; } + int ret = poll(pfds, nsubscriptions, timeout); __wasi_errno_t error = 0; @@ -2729,7 +2236,7 @@ wasmtime_ssp_poll_oneoff( __wasi_filesize_t nbytes = 0; if (in[i].u.type == __WASI_EVENTTYPE_FD_READ) { int l; - if (ioctl(fd_number(fos[i]), FIONREAD, &l) == 0) + if (ioctl(fos[i]->file_handle, FIONREAD, &l) == 0) nbytes = (__wasi_filesize_t)l; } if ((pfds[i].revents & POLLNVAL) != 0) { @@ -2781,147 +2288,28 @@ wasmtime_ssp_poll_oneoff( for (size_t i = 0; i < nsubscriptions; ++i) if (fos[i] != NULL) - fd_object_release(fos[i]); + fd_object_release(exec_env, fos[i]); wasm_runtime_free(fos); wasm_runtime_free(pfds); return error; -} - -#if 0 -/** - * We throw exception in libc-wasi wrapper function wasi_proc_exit() - * but not call this function. - */ -void wasmtime_ssp_proc_exit( - __wasi_exitcode_t rval -) { - _Exit((int32)rval); -} -#endif - -__wasi_errno_t -wasmtime_ssp_proc_raise(__wasi_signal_t sig) -{ - static const int signals[] = { -#define X(v) [__WASI_##v] = v -#if defined(SIGABRT) - X(SIGABRT), -#endif -#if defined(SIGALRM) - X(SIGALRM), -#endif -#if defined(SIGBUS) - X(SIGBUS), #endif -#if defined(SIGCHLD) - X(SIGCHLD), -#endif -#if defined(SIGCONT) - X(SIGCONT), -#endif -#if defined(SIGFPE) - X(SIGFPE), -#endif -#if defined(SIGHUP) - X(SIGHUP), -#endif -#if defined(SIGILL) - X(SIGILL), -#endif -#if defined(SIGINT) - X(SIGINT), -#endif -#if defined(SIGKILL) - X(SIGKILL), -#endif -#if defined(SIGPIPE) - X(SIGPIPE), -#endif -#if defined(SIGQUIT) - X(SIGQUIT), -#endif -#if defined(SIGSYS) - X(SIGSEGV), -#endif -#if defined(SIGSTOP) - X(SIGSTOP), -#endif -#if defined(SIGSYS) - X(SIGSYS), -#endif -#if defined(SIGTERM) - X(SIGTERM), -#endif -#if defined(SIGTRAP) - X(SIGTRAP), -#endif -#if defined(SIGTSTP) - X(SIGTSTP), -#endif -#if defined(SIGTTIN) - X(SIGTTIN), -#endif -#if defined(SIGTTOU) - X(SIGTTOU), -#endif -#if defined(SIGURG) - X(SIGURG), -#endif -#if defined(SIGUSR1) - X(SIGUSR1), -#endif -#if defined(SIGUSR2) - X(SIGUSR2), -#endif -#if defined(SIGVTALRM) - X(SIGVTALRM), -#endif -#if defined(SIGXCPU) - X(SIGXCPU), -#endif -#if defined(SIGXFSZ) - X(SIGXFSZ), -#endif -#undef X - }; - if (sig >= sizeof(signals) / sizeof(signals[0]) || signals[sig] == 0) - return __WASI_EINVAL; - -#if CONFIG_TLS_USE_GSBASE - // TLS on OS X depends on installing a SIGSEGV handler. Reset SIGSEGV - // to the default action before raising. - if (sig == __WASI_SIGSEGV) { - struct sigaction sa = { - .sa_handler = SIG_DFL, - }; - sigemptyset(&sa.sa_mask); - sigaction(SIGSEGV, &sa, NULL); - } -#endif - - if (raise(signals[sig]) < 0) - return convert_errno(errno); - return 0; } __wasi_errno_t wasmtime_ssp_random_get(void *buf, size_t nbyte) { - random_buf(buf, nbyte); - return 0; + return random_buf(buf, nbyte); } __wasi_errno_t -wasi_ssp_sock_accept( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_fdflags_t flags, __wasi_fd_t *fd_new) +wasi_ssp_sock_accept(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_fdflags_t flags, + __wasi_fd_t *fd_new) { __wasi_filetype_t wasi_type; __wasi_rights_t max_base, max_inheriting; struct fd_object *fo; - bh_socket_t new_sock = -1; + bh_socket_t new_sock = os_get_invalid_handle(); int ret; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, __WASI_RIGHT_SOCK_ACCEPT, 0); @@ -2929,8 +2317,9 @@ wasi_ssp_sock_accept( goto fail; } - ret = os_socket_accept(fd_number(fo), &new_sock, NULL, NULL); - fd_object_release(fo); + ret = blocking_op_socket_accept(exec_env, fo->file_handle, &new_sock, NULL, + NULL); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { error = convert_errno(errno); goto fail; @@ -2942,29 +2331,26 @@ wasi_ssp_sock_accept( goto fail; } - error = fd_table_insert_fd(curfds, new_sock, wasi_type, max_base, + error = fd_table_insert_fd(exec_env, curfds, new_sock, wasi_type, max_base, max_inheriting, fd_new); if (error != __WASI_ESUCCESS) { /* released in fd_table_insert_fd() */ - new_sock = -1; + new_sock = os_get_invalid_handle(); goto fail; } return __WASI_ESUCCESS; fail: - if (-1 != new_sock) { + if (os_is_handle_valid(&new_sock)) { os_socket_close(new_sock); } return error; } __wasi_errno_t -wasi_ssp_sock_addr_local( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_addr_t *addr) +wasi_ssp_sock_addr_local(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_addr_t *addr) { struct fd_object *fo; bh_sockaddr_t bh_addr; @@ -2975,8 +2361,8 @@ wasi_ssp_sock_addr_local( if (error != __WASI_ESUCCESS) return error; - ret = os_socket_addr_local(fd_number(fo), &bh_addr); - fd_object_release(fo); + ret = os_socket_addr_local(fo->file_handle, &bh_addr); + fd_object_release(exec_env, fo); if (ret != BHT_OK) { return convert_errno(errno); } @@ -2987,11 +2373,8 @@ wasi_ssp_sock_addr_local( } __wasi_errno_t -wasi_ssp_sock_addr_remote( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_addr_t *addr) +wasi_ssp_sock_addr_remote(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_addr_t *addr) { struct fd_object *fo; bh_sockaddr_t bh_addr; @@ -3002,8 +2385,8 @@ wasi_ssp_sock_addr_remote( if (error != __WASI_ESUCCESS) return error; - ret = os_socket_addr_remote(fd_number(fo), &bh_addr); - fd_object_release(fo); + ret = os_socket_addr_remote(fo->file_handle, &bh_addr); + fd_object_release(exec_env, fo); if (ret != BHT_OK) { return convert_errno(errno); } @@ -3043,11 +2426,9 @@ wasi_addr_to_string(const __wasi_addr_t *addr, char *buf, size_t buflen) } __wasi_errno_t -wasi_ssp_sock_bind( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, struct addr_pool *addr_pool, -#endif - __wasi_fd_t fd, __wasi_addr_t *addr) +wasi_ssp_sock_bind(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct addr_pool *addr_pool, __wasi_fd_t fd, + __wasi_addr_t *addr) { char buf[48] = { 0 }; struct fd_object *fo; @@ -3067,8 +2448,8 @@ wasi_ssp_sock_bind( if (error != __WASI_ESUCCESS) return error; - ret = os_socket_bind(fd_number(fo), buf, &port); - fd_object_release(fo); + ret = os_socket_bind(fo->file_handle, buf, &port); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } @@ -3077,13 +2458,12 @@ wasi_ssp_sock_bind( } __wasi_errno_t -wasi_ssp_sock_addr_resolve( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, char **ns_lookup_list, -#endif - const char *host, const char *service, __wasi_addr_info_hints_t *hints, - __wasi_addr_info_t *addr_info, __wasi_size_t addr_info_size, - __wasi_size_t *max_info_size) +wasi_ssp_sock_addr_resolve(wasm_exec_env_t exec_env, struct fd_table *curfds, + char **ns_lookup_list, const char *host, + const char *service, __wasi_addr_info_hints_t *hints, + __wasi_addr_info_t *addr_info, + __wasi_size_t addr_info_size, + __wasi_size_t *max_info_size) { bh_addr_info_t *wamr_addr_info = wasm_runtime_malloc(addr_info_size * sizeof(bh_addr_info_t)); @@ -3101,10 +2481,13 @@ wasi_ssp_sock_addr_resolve( return __WASI_EACCES; } - int ret = os_socket_addr_resolve( - host, service, hints->hints_enabled ? &hints_is_tcp : NULL, - hints->hints_enabled ? &hints_is_ipv4 : NULL, wamr_addr_info, - addr_info_size, &_max_info_size); + int ret = blocking_op_socket_addr_resolve( + exec_env, host, service, + hints->hints_enabled && hints->type != SOCKET_ANY ? &hints_is_tcp + : NULL, + hints->hints_enabled && hints->family != INET_UNSPEC ? &hints_is_ipv4 + : NULL, + wamr_addr_info, addr_info_size, &_max_info_size); if (ret != BHT_OK) { wasm_runtime_free(wamr_addr_info); @@ -3127,11 +2510,9 @@ wasi_ssp_sock_addr_resolve( } __wasi_errno_t -wasi_ssp_sock_connect( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, struct addr_pool *addr_pool, -#endif - __wasi_fd_t fd, __wasi_addr_t *addr) +wasi_ssp_sock_connect(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct addr_pool *addr_pool, __wasi_fd_t fd, + __wasi_addr_t *addr) { char buf[48] = { 0 }; struct fd_object *fo; @@ -3150,10 +2531,10 @@ wasi_ssp_sock_connect( if (error != __WASI_ESUCCESS) return error; - ret = os_socket_connect(fd_number(fo), buf, - addr->kind == IPv4 ? addr->addr.ip4.port - : addr->addr.ip6.port); - fd_object_release(fo); + ret = blocking_op_socket_connect(exec_env, fo->file_handle, buf, + addr->kind == IPv4 ? addr->addr.ip4.port + : addr->addr.ip6.port); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } @@ -3162,127 +2543,97 @@ wasi_ssp_sock_connect( } __wasi_errno_t -wasi_ssp_sock_get_recv_buf_size( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_size_t *size) +wasi_ssp_sock_get_recv_buf_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_size_t *size) { struct fd_object *fo; - int ret; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, 0, 0); if (error != __WASI_ESUCCESS) return error; - int optval; - socklen_t optlen = sizeof(optval); - - ret = getsockopt(fd_number(fo), SOL_SOCKET, SO_RCVBUF, &optval, &optlen); - fd_object_release(fo); + size_t bufsize = 0; + int ret = os_socket_get_recv_buf_size(fo->file_handle, &bufsize); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } - *size = optval; + *size = (__wasi_size_t)bufsize; return __WASI_ESUCCESS; } __wasi_errno_t -wasi_ssp_sock_get_reuse_addr( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, uint8_t *reuse) +wasi_ssp_sock_get_reuse_addr(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, uint8_t *reuse) { - struct fd_object *fo; - int ret; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, 0, 0); if (error != __WASI_ESUCCESS) return error; - int optval; - socklen_t optlen = sizeof(optval); + bool enabled = false; - ret = getsockopt(fd_number(fo), SOL_SOCKET, SO_REUSEADDR, &optval, &optlen); - fd_object_release(fo); + int ret = os_socket_get_reuse_addr(fo->file_handle, &enabled); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } - *reuse = optval; + *reuse = (uint8_t)enabled; return __WASI_ESUCCESS; } __wasi_errno_t -wasi_ssp_sock_get_reuse_port( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, uint8_t *reuse) +wasi_ssp_sock_get_reuse_port(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, uint8_t *reuse) { struct fd_object *fo; - int ret; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, 0, 0); if (error != __WASI_ESUCCESS) return error; - int optval; - socklen_t optlen = sizeof(optval); - -#if defined(SO_REUSEPORT) /* NuttX doesn't have SO_REUSEPORT */ - ret = getsockopt(fd_number(fo), SOL_SOCKET, SO_REUSEPORT, &optval, &optlen); -#else - errno = ENOTSUP; - ret = BHT_ERROR; - optval = 0; -#endif /* defined(SO_REUSEPORT) */ + bool enabled = false; + int ret = os_socket_get_reuse_port(fo->file_handle, &enabled); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } - *reuse = optval; + *reuse = (uint8_t)enabled; return __WASI_ESUCCESS; } __wasi_errno_t -wasi_ssp_sock_get_send_buf_size( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_size_t *size) +wasi_ssp_sock_get_send_buf_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_size_t *size) { struct fd_object *fo; - int ret; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, 0, 0); if (error != __WASI_ESUCCESS) return error; - int optval; - socklen_t optlen = sizeof(optval); + size_t bufsize = 0; + int ret = os_socket_get_send_buf_size(fo->file_handle, &bufsize); - ret = getsockopt(fd_number(fo), SOL_SOCKET, SO_SNDBUF, &optval, &optlen); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } - *size = optval; + *size = (__wasi_size_t)bufsize; return __WASI_ESUCCESS; } __wasi_errno_t -wasi_ssp_sock_listen( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_size_t backlog) +wasi_ssp_sock_listen(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, __wasi_size_t backlog) { struct fd_object *fo; int ret; @@ -3291,8 +2642,8 @@ wasi_ssp_sock_listen( if (error != __WASI_ESUCCESS) return error; - ret = os_socket_listen(fd_number(fo), backlog); - fd_object_release(fo); + ret = os_socket_listen(fo->file_handle, backlog); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } @@ -3301,19 +2652,16 @@ wasi_ssp_sock_listen( } __wasi_errno_t -wasi_ssp_sock_open( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t poolfd, __wasi_address_family_t af, __wasi_sock_type_t socktype, - __wasi_fd_t *sockfd) +wasi_ssp_sock_open(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t poolfd, __wasi_address_family_t af, + __wasi_sock_type_t socktype, __wasi_fd_t *sockfd) { bh_socket_t sock; bool is_tcp = SOCKET_DGRAM == socktype ? false : true; bool is_ipv4 = INET6 == af ? false : true; int ret; - __wasi_filetype_t wasi_type; - __wasi_rights_t max_base, max_inheriting; + __wasi_filetype_t wasi_type = __WASI_FILETYPE_UNKNOWN; + __wasi_rights_t max_base = 0, max_inheriting = 0; __wasi_errno_t error; (void)poolfd; @@ -3338,7 +2686,7 @@ wasi_ssp_sock_open( } // TODO: base rights and inheriting rights ? - error = fd_table_insert_fd(curfds, sock, wasi_type, max_base, + error = fd_table_insert_fd(exec_env, curfds, sock, wasi_type, max_base, max_inheriting, sockfd); if (error != __WASI_ESUCCESS) { return error; @@ -3348,23 +2696,18 @@ wasi_ssp_sock_open( } __wasi_errno_t -wasi_ssp_sock_set_recv_buf_size( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_size_t size) +wasi_ssp_sock_set_recv_buf_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_size_t size) { struct fd_object *fo; - int ret; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, 0, 0); if (error != __WASI_ESUCCESS) return error; - int optval = size; + int ret = os_socket_set_recv_buf_size(fo->file_handle, size); - ret = setsockopt(fd_number(fo), SOL_SOCKET, SO_RCVBUF, &optval, - sizeof(optval)); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } @@ -3373,23 +2716,17 @@ wasi_ssp_sock_set_recv_buf_size( } __wasi_errno_t -wasi_ssp_sock_set_reuse_addr( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, uint8_t reuse) +wasi_ssp_sock_set_reuse_addr(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, uint8_t reuse) { struct fd_object *fo; - int ret; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, 0, 0); if (error != __WASI_ESUCCESS) return error; - int optval = reuse; + int ret = os_socket_set_reuse_addr(fo->file_handle, (bool)reuse); - ret = setsockopt(fd_number(fo), SOL_SOCKET, SO_REUSEADDR, &optval, - sizeof(optval)); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } @@ -3398,29 +2735,17 @@ wasi_ssp_sock_set_reuse_addr( } __wasi_errno_t -wasi_ssp_sock_set_reuse_port( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, uint8_t reuse) +wasi_ssp_sock_set_reuse_port(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t fd, uint8_t reuse) { struct fd_object *fo; - int ret; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, 0, 0); if (error != __WASI_ESUCCESS) return error; - int optval = reuse; - -#if defined(SO_REUSEPORT) /* NuttX doesn't have SO_REUSEPORT */ - ret = setsockopt(fd_number(fo), SOL_SOCKET, SO_REUSEPORT, &optval, - sizeof(optval)); -#else - errno = ENOTSUP; - ret = BHT_ERROR; -#endif /* defined(SO_REUSEPORT) */ + int ret = os_socket_set_reuse_port(fo->file_handle, (bool)reuse); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } @@ -3429,24 +2754,18 @@ wasi_ssp_sock_set_reuse_port( } __wasi_errno_t -wasi_ssp_sock_set_send_buf_size( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t fd, __wasi_size_t size) +wasi_ssp_sock_set_send_buf_size(wasm_exec_env_t exec_env, + struct fd_table *curfds, __wasi_fd_t fd, + __wasi_size_t size) { struct fd_object *fo; - int ret; __wasi_errno_t error = fd_object_get(curfds, &fo, fd, 0, 0); if (error != __WASI_ESUCCESS) return error; - int optval = size; - - ret = setsockopt(fd_number(fo), SOL_SOCKET, SO_SNDBUF, &optval, - sizeof(optval)); + int ret = os_socket_set_send_buf_size(fo->file_handle, size); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) { return convert_errno(errno); } @@ -3455,25 +2774,21 @@ wasi_ssp_sock_set_send_buf_size( } __wasi_errno_t -wasmtime_ssp_sock_recv( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, void *buf, size_t buf_len, size_t *recv_len) +wasmtime_ssp_sock_recv(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock, void *buf, size_t buf_len, + size_t *recv_len) { __wasi_addr_t src_addr; - return wasmtime_ssp_sock_recv_from(curfds, sock, buf, buf_len, 0, &src_addr, - recv_len); + return wasmtime_ssp_sock_recv_from(exec_env, curfds, sock, buf, buf_len, 0, + &src_addr, recv_len); } __wasi_errno_t -wasmtime_ssp_sock_recv_from( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, void *buf, size_t buf_len, __wasi_riflags_t ri_flags, - __wasi_addr_t *src_addr, size_t *recv_len) +wasmtime_ssp_sock_recv_from(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock, void *buf, size_t buf_len, + __wasi_riflags_t ri_flags, __wasi_addr_t *src_addr, + size_t *recv_len) { struct fd_object *fo; __wasi_errno_t error; @@ -3485,8 +2800,9 @@ wasmtime_ssp_sock_recv_from( return error; } - ret = os_socket_recv_from(fd_number(fo), buf, buf_len, 0, &sockaddr); - fd_object_release(fo); + ret = blocking_op_socket_recv_from(exec_env, fo->file_handle, buf, buf_len, + 0, &sockaddr); + fd_object_release(exec_env, fo); if (-1 == ret) { return convert_errno(errno); } @@ -3498,11 +2814,9 @@ wasmtime_ssp_sock_recv_from( } __wasi_errno_t -wasmtime_ssp_sock_send( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, const void *buf, size_t buf_len, size_t *sent_len) +wasmtime_ssp_sock_send(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock, const void *buf, size_t buf_len, + size_t *sent_len) { struct fd_object *fo; __wasi_errno_t error; @@ -3513,8 +2827,8 @@ wasmtime_ssp_sock_send( return error; } - ret = os_socket_send(fd_number(fo), buf, buf_len); - fd_object_release(fo); + ret = os_socket_send(fo->file_handle, buf, buf_len); + fd_object_release(exec_env, fo); if (-1 == ret) { return convert_errno(errno); } @@ -3524,12 +2838,11 @@ wasmtime_ssp_sock_send( } __wasi_errno_t -wasmtime_ssp_sock_send_to( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, struct addr_pool *addr_pool, -#endif - __wasi_fd_t sock, const void *buf, size_t buf_len, - __wasi_siflags_t si_flags, const __wasi_addr_t *dest_addr, size_t *sent_len) +wasmtime_ssp_sock_send_to(wasm_exec_env_t exec_env, struct fd_table *curfds, + struct addr_pool *addr_pool, __wasi_fd_t sock, + const void *buf, size_t buf_len, + __wasi_siflags_t si_flags, + const __wasi_addr_t *dest_addr, size_t *sent_len) { char addr_buf[48] = { 0 }; struct fd_object *fo; @@ -3552,8 +2865,9 @@ wasmtime_ssp_sock_send_to( wasi_addr_to_bh_sockaddr(dest_addr, &sockaddr); - ret = os_socket_send_to(fd_number(fo), buf, buf_len, 0, &sockaddr); - fd_object_release(fo); + ret = blocking_op_socket_send_to(exec_env, fo->file_handle, buf, buf_len, 0, + &sockaddr); + fd_object_release(exec_env, fo); if (-1 == ret) { return convert_errno(errno); } @@ -3563,42 +2877,37 @@ wasmtime_ssp_sock_send_to( } __wasi_errno_t -wasmtime_ssp_sock_shutdown( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock) +wasmtime_ssp_sock_shutdown(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock) { struct fd_object *fo; __wasi_errno_t error; - int ret; error = fd_object_get(curfds, &fo, sock, 0, 0); if (error != 0) return error; - ret = os_socket_shutdown(fd_number(fo)); - fd_object_release(fo); - if (BHT_OK != ret) - return convert_errno(errno); + error = os_socket_shutdown(fo->file_handle); + fd_object_release(exec_env, fo); - return __WASI_ESUCCESS; + return error; } __wasi_errno_t wasmtime_ssp_sched_yield(void) { +#ifdef BH_PLATFORM_WINDOWS + SwitchToThread(); +#else if (sched_yield() < 0) return convert_errno(errno); +#endif return 0; } __wasi_errno_t -wasmtime_ssp_args_get( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct argv_environ_values *argv_environ, -#endif - char **argv, char *argv_buf) +wasmtime_ssp_args_get(struct argv_environ_values *argv_environ, char **argv, + char *argv_buf) { for (size_t i = 0; i < argv_environ->argc; ++i) { argv[i] = @@ -3611,11 +2920,8 @@ wasmtime_ssp_args_get( } __wasi_errno_t -wasmtime_ssp_args_sizes_get( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct argv_environ_values *argv_environ, -#endif - size_t *argc, size_t *argv_buf_size) +wasmtime_ssp_args_sizes_get(struct argv_environ_values *argv_environ, + size_t *argc, size_t *argv_buf_size) { *argc = argv_environ->argc; *argv_buf_size = argv_environ->argv_buf_size; @@ -3623,18 +2929,15 @@ wasmtime_ssp_args_sizes_get( } __wasi_errno_t -wasmtime_ssp_environ_get( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct argv_environ_values *argv_environ, -#endif - char **environ, char *environ_buf) +wasmtime_ssp_environ_get(struct argv_environ_values *argv_environ, + char **environs, char *environ_buf) { for (size_t i = 0; i < argv_environ->environ_count; ++i) { - environ[i] = + environs[i] = environ_buf + (argv_environ->environ_list[i] - argv_environ->environ_buf); } - environ[argv_environ->environ_count] = NULL; + environs[argv_environ->environ_count] = NULL; bh_memcpy_s(environ_buf, (uint32)argv_environ->environ_buf_size, argv_environ->environ_buf, (uint32)argv_environ->environ_buf_size); @@ -3642,11 +2945,8 @@ wasmtime_ssp_environ_get( } __wasi_errno_t -wasmtime_ssp_environ_sizes_get( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct argv_environ_values *argv_environ, -#endif - size_t *environ_count, size_t *environ_buf_size) +wasmtime_ssp_environ_sizes_get(struct argv_environ_values *argv_environ, + size_t *environ_count, size_t *environ_buf_size) { *environ_count = argv_environ->environ_count; *environ_buf_size = argv_environ->environ_buf_size; @@ -3682,7 +2982,7 @@ fd_table_destroy(struct fd_table *ft) if (ft->entries) { for (uint32 i = 0; i < ft->size; i++) { if (ft->entries[i].object != NULL) { - fd_object_release(ft->entries[i].object); + fd_object_release(NULL, ft->entries[i].object); } } rwlock_destroy(&ft->lock); @@ -3753,12 +3053,6 @@ addr_pool_insert(struct addr_pool *addr_pool, const char *addr, uint8 mask) return true; } -static inline size_t -min(size_t a, size_t b) -{ - return a > b ? b : a; -} - static void init_address_mask(uint8_t *buf, size_t buflen, size_t mask) { @@ -3871,16 +3165,13 @@ addr_pool_destroy(struct addr_pool *addr_pool) } } -#ifndef WASMTIME_SSP_STATIC_CURFDS #define WASMTIME_SSP_PASSTHROUGH_FD_TABLE struct fd_table *curfds, -#else -#define WASMTIME_SSP_PASSTHROUGH_FD_TABLE -#endif // Defines a function that passes through the socket option to the OS // implementation #define WASMTIME_SSP_PASSTHROUGH_SOCKET_OPTION(FUNC_NAME, OPTION_TYPE) \ __wasi_errno_t wasmtime_ssp_sock_##FUNC_NAME( \ + wasm_exec_env_t exec_env, \ WASMTIME_SSP_PASSTHROUGH_FD_TABLE __wasi_fd_t sock, \ OPTION_TYPE option) \ { \ @@ -3890,8 +3181,8 @@ addr_pool_destroy(struct addr_pool *addr_pool) error = fd_object_get(curfds, &fo, sock, 0, 0); \ if (error != 0) \ return error; \ - ret = os_socket_##FUNC_NAME(fd_number(fo), option); \ - fd_object_release(fo); \ + ret = os_socket_##FUNC_NAME(fo->file_handle, option); \ + fd_object_release(exec_env, fo); \ if (BHT_OK != ret) \ return convert_errno(errno); \ return __WASI_ESUCCESS; \ @@ -3934,11 +3225,8 @@ WASMTIME_SSP_PASSTHROUGH_SOCKET_OPTION(get_ipv6_only, bool *) #undef WASMTIME_SSP_PASSTHROUGH_SOCKET_OPTION __wasi_errno_t -wasmtime_ssp_sock_set_linger( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, bool is_enabled, int linger_s) +wasmtime_ssp_sock_set_linger(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock, bool is_enabled, int linger_s) { struct fd_object *fo; __wasi_errno_t error; @@ -3947,19 +3235,16 @@ wasmtime_ssp_sock_set_linger( if (error != 0) return error; - ret = os_socket_set_linger(fd_number(fo), is_enabled, linger_s); - fd_object_release(fo); + ret = os_socket_set_linger(fo->file_handle, is_enabled, linger_s); + fd_object_release(exec_env, fo); if (BHT_OK != ret) return convert_errno(errno); return __WASI_ESUCCESS; } __wasi_errno_t -wasmtime_ssp_sock_get_linger( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, bool *is_enabled, int *linger_s) +wasmtime_ssp_sock_get_linger(wasm_exec_env_t exec_env, struct fd_table *curfds, + __wasi_fd_t sock, bool *is_enabled, int *linger_s) { struct fd_object *fo; __wasi_errno_t error; @@ -3968,8 +3253,8 @@ wasmtime_ssp_sock_get_linger( if (error != 0) return error; - ret = os_socket_get_linger(fd_number(fo), is_enabled, linger_s); - fd_object_release(fo); + ret = os_socket_get_linger(fo->file_handle, is_enabled, linger_s); + fd_object_release(exec_env, fo); if (BHT_OK != ret) return convert_errno(errno); @@ -3977,11 +3262,11 @@ wasmtime_ssp_sock_get_linger( } __wasi_errno_t -wasmtime_ssp_sock_set_ip_add_membership( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, __wasi_addr_ip_t *imr_multiaddr, uint32_t imr_interface) +wasmtime_ssp_sock_set_ip_add_membership(wasm_exec_env_t exec_env, + struct fd_table *curfds, + __wasi_fd_t sock, + __wasi_addr_ip_t *imr_multiaddr, + uint32_t imr_interface) { struct fd_object *fo; __wasi_errno_t error; @@ -3994,20 +3279,20 @@ wasmtime_ssp_sock_set_ip_add_membership( wasi_addr_ip_to_bh_ip_addr_buffer(imr_multiaddr, &addr_info); is_ipv6 = imr_multiaddr->kind == IPv6; - ret = os_socket_set_ip_add_membership(fd_number(fo), &addr_info, + ret = os_socket_set_ip_add_membership(fo->file_handle, &addr_info, imr_interface, is_ipv6); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) return convert_errno(errno); return __WASI_ESUCCESS; } __wasi_errno_t -wasmtime_ssp_sock_set_ip_drop_membership( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, __wasi_addr_ip_t *imr_multiaddr, uint32_t imr_interface) +wasmtime_ssp_sock_set_ip_drop_membership(wasm_exec_env_t exec_env, + struct fd_table *curfds, + __wasi_fd_t sock, + __wasi_addr_ip_t *imr_multiaddr, + uint32_t imr_interface) { struct fd_object *fo; __wasi_errno_t error; @@ -4020,20 +3305,19 @@ wasmtime_ssp_sock_set_ip_drop_membership( wasi_addr_ip_to_bh_ip_addr_buffer(imr_multiaddr, &addr_info); is_ipv6 = imr_multiaddr->kind == IPv6; - ret = os_socket_set_ip_drop_membership(fd_number(fo), &addr_info, + ret = os_socket_set_ip_drop_membership(fo->file_handle, &addr_info, imr_interface, is_ipv6); - fd_object_release(fo); + fd_object_release(exec_env, fo); if (BHT_OK != ret) return convert_errno(errno); return __WASI_ESUCCESS; } __wasi_errno_t -wasmtime_ssp_sock_set_ip_multicast_loop( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, bool ipv6, bool is_enabled) +wasmtime_ssp_sock_set_ip_multicast_loop(wasm_exec_env_t exec_env, + struct fd_table *curfds, + __wasi_fd_t sock, bool ipv6, + bool is_enabled) { struct fd_object *fo; __wasi_errno_t error; @@ -4042,19 +3326,18 @@ wasmtime_ssp_sock_set_ip_multicast_loop( if (error != 0) return error; - ret = os_socket_set_ip_multicast_loop(fd_number(fo), ipv6, is_enabled); - fd_object_release(fo); + ret = os_socket_set_ip_multicast_loop(fo->file_handle, ipv6, is_enabled); + fd_object_release(exec_env, fo); if (BHT_OK != ret) return convert_errno(errno); return __WASI_ESUCCESS; } __wasi_errno_t -wasmtime_ssp_sock_get_ip_multicast_loop( -#if !defined(WASMTIME_SSP_STATIC_CURFDS) - struct fd_table *curfds, -#endif - __wasi_fd_t sock, bool ipv6, bool *is_enabled) +wasmtime_ssp_sock_get_ip_multicast_loop(wasm_exec_env_t exec_env, + struct fd_table *curfds, + __wasi_fd_t sock, bool ipv6, + bool *is_enabled) { struct fd_object *fo; __wasi_errno_t error; @@ -4063,8 +3346,8 @@ wasmtime_ssp_sock_get_ip_multicast_loop( if (error != 0) return error; - ret = os_socket_get_ip_multicast_loop(fd_number(fo), ipv6, is_enabled); - fd_object_release(fo); + ret = os_socket_get_ip_multicast_loop(fo->file_handle, ipv6, is_enabled); + fd_object_release(exec_env, fo); if (BHT_OK != ret) return convert_errno(errno); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.h similarity index 94% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.h index 7a593390a30..75ed5978462 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.h @@ -60,7 +60,8 @@ struct addr_pool { bool fd_table_init(struct fd_table *); bool -fd_table_insert_existing(struct fd_table *, __wasi_fd_t, int); +fd_table_insert_existing(struct fd_table *, __wasi_fd_t, os_file_handle, + bool is_stdio); bool fd_prestats_init(struct fd_prestats *); bool diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/queue.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/queue.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/queue.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/queue.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.c similarity index 52% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.c index 01a1dab3a6a..29c50dd870d 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.c @@ -13,14 +13,16 @@ #include "ssp_config.h" #include "bh_platform.h" +#include "libc_errno.h" #include "random.h" #if CONFIG_HAS_ARC4RANDOM_BUF -void +__wasi_errno_t random_buf(void *buf, size_t len) { arc4random_buf(buf, len); + return __WASI_ESUCCESS; } #elif CONFIG_HAS_GETRANDOM @@ -29,7 +31,7 @@ random_buf(void *buf, size_t len) #include #endif -void +__wasi_errno_t random_buf(void *buf, size_t len) { for (;;) { @@ -37,40 +39,71 @@ random_buf(void *buf, size_t len) if (x < 0) { if (errno == EINTR) continue; - os_printf("getrandom failed: %s", strerror(errno)); - abort(); + return convert_errno(errno); } if ((size_t)x == len) - return; + break; buf = (void *)((unsigned char *)buf + x); len -= (size_t)x; } + return __WASI_ESUCCESS; +} + +#elif defined(BH_PLATFORM_WINDOWS) + +#include +#pragma comment(lib, "Bcrypt.lib") + +__wasi_errno_t +random_buf(void *buf, size_t len) +{ + NTSTATUS ret = + BCryptGenRandom(NULL, buf, (ULONG)len, BCRYPT_USE_SYSTEM_PREFERRED_RNG); + + // Since we pass NULL for the algorithm handle, the only way BCryptGenRandom + // can fail is if one of the parameters is invalid + // (STATUS_INVALID_PARAMETER). + return ret ? __WASI_EINVAL : __WASI_ESUCCESS; } #else -static int urandom; +static int urandom = -1; +static __wasi_errno_t urandom_error = __WASI_ESUCCESS; static void open_urandom(void) { urandom = open("/dev/urandom", O_RDONLY); - if (urandom < 0) { - os_printf("Failed to open /dev/urandom\n"); - abort(); - } + if (urandom < 0) + urandom_error = convert_errno(errno); } -void +__wasi_errno_t random_buf(void *buf, size_t len) { static pthread_once_t open_once = PTHREAD_ONCE_INIT; - pthread_once(&open_once, open_urandom); + int pthread_ret = pthread_once(&open_once, open_urandom); + + if (pthread_ret != 0) + return convert_errno(pthread_ret); - if ((size_t)read(urandom, buf, len) != len) { - os_printf("Short read on /dev/urandom\n"); - abort(); + if (urandom < 0) + return urandom_error; + + size_t bytes_read = 0; + + while (bytes_read < len) { + ssize_t bytes_read_now = + read(urandom, buf + bytes_read, len - bytes_read); + + if (bytes_read_now < 0) + return convert_errno(errno); + + bytes_read += (size_t)bytes_read_now; } + + return __WASI_ESUCCESS; } #endif @@ -82,8 +115,8 @@ random_buf(void *buf, size_t len) // arc4random() until it lies within the range [2^k % upper, 2^k). As // this range has length k * upper, we can safely obtain a number // without any modulo bias. -uintmax_t -random_uniform(uintmax_t upper) +__wasi_errno_t +random_uniform(uintmax_t upper, uintmax_t *out) { // Compute 2^k % upper // == (2^k - upper) % upper @@ -91,8 +124,14 @@ random_uniform(uintmax_t upper) uintmax_t lower = -upper % upper; for (;;) { uintmax_t value; - random_buf(&value, sizeof(value)); - if (value >= lower) - return value % upper; + __wasi_errno_t error = random_buf(&value, sizeof(value)); + + if (error != __WASI_ESUCCESS) + return error; + + if (value >= lower) { + *out = value % upper; + return error; + } } } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.h similarity index 84% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.h index 23c2da4dbd6..7cd94d74dbd 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.h @@ -14,8 +14,12 @@ #ifndef RANDOM_H #define RANDOM_H -void +#include "bh_platform.h" + +__wasi_errno_t random_buf(void *, size_t); -uintmax_t random_uniform(uintmax_t); + +__wasi_errno_t +random_uniform(uintmax_t upper, uintmax_t *out); #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/refcount.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/refcount.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/refcount.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/refcount.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/rights.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/rights.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/rights.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/rights.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h similarity index 68% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h index 7f6e9b94192..bcc750c2621 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/ssp_config.h @@ -14,8 +14,8 @@ #ifndef SSP_CONFIG_H #define SSP_CONFIG_H +#include "bh_platform.h" #include "gnuc.h" -#include #if defined(__FreeBSD__) || defined(__APPLE__) \ || (defined(ANDROID) && __ANDROID_API__ < 28) @@ -26,8 +26,8 @@ // On Linux, prefer to use getrandom, though it isn't available in // GLIBC before 2.25. -#if (defined(__linux__) || defined(ESP_PLATFORM)) \ - && (!defined(__GLIBC__) || __GLIBC__ > 2 \ +#if (defined(__linux__) || defined(ESP_PLATFORM) || defined(__COSMOPOLITAN__)) \ + && (!defined(__GLIBC__) || __GLIBC__ > 2 \ || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25)) #define CONFIG_HAS_GETRANDOM 1 #else @@ -47,66 +47,19 @@ #define CONFIG_HAS_CLOCK_NANOSLEEP 0 #endif -#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(ESP_PLATFORM) -#define CONFIG_HAS_FDATASYNC 1 -#else -#define CONFIG_HAS_FDATASYNC 0 -#endif - -/* - * For NuttX, CONFIG_HAS_ISATTY is provided by its platform header. - * (platform_internal.h) - */ -#ifndef __NuttX__ -#ifndef __CloudABI__ -#define CONFIG_HAS_ISATTY 1 -#else -#define CONFIG_HAS_ISATTY 0 -#endif -#endif - -#if !defined(__APPLE__) && !defined(ESP_PLATFORM) -#define CONFIG_HAS_POSIX_FALLOCATE 1 -#else -#define CONFIG_HAS_POSIX_FALLOCATE 0 -#endif - -#if !defined(__APPLE__) && !defined(ESP_PLATFORM) -#define CONFIG_HAS_PREADV 1 -#else -#define CONFIG_HAS_PREADV 0 -#endif - #if defined(__APPLE__) || defined(__CloudABI__) #define CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP 1 #else #define CONFIG_HAS_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP 0 #endif -#if !defined(__APPLE__) && !defined(BH_PLATFORM_LINUX_SGX) +#if !defined(__APPLE__) && !defined(BH_PLATFORM_LINUX_SGX) && !defined(_WIN32) \ + && !defined(__COSMOPOLITAN__) #define CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK 1 #else #define CONFIG_HAS_PTHREAD_CONDATTR_SETCLOCK 0 #endif -#if !defined(__APPLE__) && !defined(ESP_PLATFORM) -#define CONFIG_HAS_PWRITEV 1 -#else -#define CONFIG_HAS_PWRITEV 0 -#endif - -#ifdef __APPLE__ -#define st_atim st_atimespec -#define st_ctim st_ctimespec -#define st_mtim st_mtimespec -#endif - -#ifdef __APPLE__ -#define CONFIG_TLS_USE_GSBASE 1 -#else -#define CONFIG_TLS_USE_GSBASE 0 -#endif - #if !defined(BH_PLATFORM_LINUX_SGX) /* Clang's __GNUC_PREREQ macro has a different meaning than GCC one, so we have to handle this case specially */ @@ -134,10 +87,4 @@ not implemented until 4.9. See #define CONFIG_HAS_STD_ATOMIC 0 #endif /* end of !defined(BH_PLATFORM_LINUX_SGX) */ -#if !defined(__NuttX__) -#define CONFIG_HAS_D_INO 1 -#else -#define CONFIG_HAS_D_INO 0 -#endif - #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/str.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/SConscript similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/SConscript rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/SConscript diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/thread_manager.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/thread_manager.c similarity index 87% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/thread_manager.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/thread_manager.c index 9303eb3f5e2..dbf002468ba 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/thread_manager.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/thread_manager.c @@ -16,10 +16,6 @@ #include "debug_engine.h" #endif -#if WASM_ENABLE_SHARED_MEMORY != 0 -#include "wasm_shared_memory.h" -#endif - typedef struct { bh_list_link l; void (*destroy_cb)(WASMCluster *); @@ -32,6 +28,8 @@ static bh_list cluster_list_head; static bh_list *const cluster_list = &cluster_list_head; static korp_mutex cluster_list_lock; +static korp_mutex _exception_lock; + typedef void (*list_visitor)(void *, void *); static uint32 cluster_max_thread_num = CLUSTER_MAX_THREAD_NUM; @@ -52,6 +50,10 @@ thread_manager_init() return false; if (os_mutex_init(&cluster_list_lock) != 0) return false; + if (os_mutex_init(&_exception_lock) != 0) { + os_mutex_destroy(&cluster_list_lock); + return false; + } return true; } @@ -66,6 +68,7 @@ thread_manager_destroy() cluster = next; } wasm_cluster_cancel_all_callbacks(); + os_mutex_destroy(&_exception_lock); os_mutex_destroy(&cluster_list_lock); } @@ -477,9 +480,6 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env) wasm_module_inst_t module_inst = get_module_inst(exec_env); wasm_module_t module; wasm_module_inst_t new_module_inst; -#if WASM_ENABLE_LIBC_WASI != 0 - WASIContext *wasi_ctx; -#endif WASMExecEnv *new_exec_env; uint32 aux_stack_start, aux_stack_size; uint32 stack_size = 8192; @@ -509,7 +509,7 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env) #endif if (!(new_module_inst = wasm_runtime_instantiate_internal( - module, true, exec_env, stack_size, 0, NULL, 0))) { + module, module_inst, exec_env, stack_size, 0, NULL, 0))) { goto fail1; } @@ -517,10 +517,7 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env) wasm_runtime_set_custom_data_internal( new_module_inst, wasm_runtime_get_custom_data(module_inst)); -#if WASM_ENABLE_LIBC_WASI != 0 - wasi_ctx = wasm_runtime_get_wasi_ctx(module_inst); - wasm_runtime_set_wasi_ctx(new_module_inst, wasi_ctx); -#endif + wasm_native_inherit_contexts(new_module_inst, module_inst); new_exec_env = wasm_exec_env_create_internal(new_module_inst, exec_env->wasm_stack_size); @@ -606,7 +603,8 @@ thread_manager_start_routine(void *arg) #ifdef OS_ENABLE_HW_BOUND_CHECK os_mutex_lock(&exec_env->wait_lock); - if (exec_env->suspend_flags.flags & 0x08) + if (WASM_SUSPEND_FLAGS_GET(exec_env->suspend_flags) + & WASM_SUSPEND_FLAG_EXIT) ret = exec_env->thread_ret_value; os_mutex_unlock(&exec_env->wait_lock); #endif @@ -745,10 +743,10 @@ wasm_cluster_dup_c_api_imports(WASMModuleInstanceCommon *module_inst_dst, #if WASM_ENABLE_INTERP != 0 if (module_inst_src->module_type == Wasm_Module_Bytecode) { - new_c_api_func_imports = - &(((WASMModuleInstance *)module_inst_dst)->e->c_api_func_imports); + new_c_api_func_imports = &(((WASMModuleInstance *)module_inst_dst) + ->e->common.c_api_func_imports); c_api_func_imports = ((const WASMModuleInstance *)module_inst_src) - ->e->c_api_func_imports; + ->e->common.c_api_func_imports; import_func_count = ((WASMModule *)(((const WASMModuleInstance *)module_inst_src) ->module)) @@ -759,10 +757,10 @@ wasm_cluster_dup_c_api_imports(WASMModuleInstanceCommon *module_inst_dst, if (module_inst_src->module_type == Wasm_Module_AoT) { AOTModuleInstanceExtra *e = (AOTModuleInstanceExtra *)((AOTModuleInstance *)module_inst_dst)->e; - new_c_api_func_imports = &(e->c_api_func_imports); + new_c_api_func_imports = &(e->common.c_api_func_imports); e = (AOTModuleInstanceExtra *)((AOTModuleInstance *)module_inst_src)->e; - c_api_func_imports = e->c_api_func_imports; + c_api_func_imports = e->common.c_api_func_imports; import_func_count = ((AOTModule *)(((AOTModuleInstance *)module_inst_src)->module)) @@ -993,7 +991,9 @@ wasm_cluster_exit_thread(WASMExecEnv *exec_env, void *retval) if (exec_env->jmpbuf_stack_top) { /* Store the return value in exec_env */ exec_env->thread_ret_value = retval; - exec_env->suspend_flags.flags |= 0x08; + + WASM_SUSPEND_FLAGS_FETCH_OR(exec_env->suspend_flags, + WASM_SUSPEND_FLAG_EXIT); #ifndef BH_PLATFORM_WINDOWS /* Pop all jmpbuf_node except the last one */ @@ -1055,8 +1055,22 @@ set_thread_cancel_flags(WASMExecEnv *exec_env) #if WASM_ENABLE_DEBUG_INTERP != 0 wasm_cluster_thread_send_signal(exec_env, WAMR_SIG_TERM); #endif - exec_env->suspend_flags.flags |= 0x01; + WASM_SUSPEND_FLAGS_FETCH_OR(exec_env->suspend_flags, + WASM_SUSPEND_FLAG_TERMINATE); + + os_mutex_unlock(&exec_env->wait_lock); + +#ifdef OS_ENABLE_WAKEUP_BLOCKING_OP + wasm_runtime_interrupt_blocking_op(exec_env); +#endif +} +static void +clear_thread_cancel_flags(WASMExecEnv *exec_env) +{ + os_mutex_lock(&exec_env->wait_lock); + WASM_SUSPEND_FLAGS_FETCH_AND(exec_env->suspend_flags, + ~WASM_SUSPEND_FLAG_TERMINATE); os_mutex_unlock(&exec_env->wait_lock); } @@ -1178,7 +1192,8 @@ void wasm_cluster_suspend_thread(WASMExecEnv *exec_env) { /* Set the suspend flag */ - exec_env->suspend_flags.flags |= 0x02; + WASM_SUSPEND_FLAGS_FETCH_OR(exec_env->suspend_flags, + WASM_SUSPEND_FLAG_SUSPEND); } static void @@ -1214,7 +1229,8 @@ wasm_cluster_suspend_all_except_self(WASMCluster *cluster, void wasm_cluster_resume_thread(WASMExecEnv *exec_env) { - exec_env->suspend_flags.flags &= ~0x02; + WASM_SUSPEND_FLAGS_FETCH_AND(exec_env->suspend_flags, + ~WASM_SUSPEND_FLAG_SUSPEND); os_cond_signal(&exec_env->wait_cond); } @@ -1234,76 +1250,55 @@ wasm_cluster_resume_all(WASMCluster *cluster) os_mutex_unlock(&cluster->lock); } +struct spread_exception_data { + WASMExecEnv *skip; + const char *exception; +}; + static void set_exception_visitor(void *node, void *user_data) { - WASMExecEnv *curr_exec_env = (WASMExecEnv *)node; - WASMExecEnv *exec_env = (WASMExecEnv *)user_data; - WASMModuleInstanceCommon *module_inst = get_module_inst(exec_env); - WASMModuleInstance *wasm_inst = (WASMModuleInstance *)module_inst; - - if (curr_exec_env != exec_env) { - WASMModuleInstance *curr_wasm_inst = - (WASMModuleInstance *)get_module_inst(curr_exec_env); - - /* Only spread non "wasi proc exit" exception */ -#if WASM_ENABLE_SHARED_MEMORY != 0 - WASMSharedMemNode *shared_mem_node = wasm_module_get_shared_memory( - (WASMModuleCommon *)curr_wasm_inst->module); - if (shared_mem_node) - os_mutex_lock(&shared_mem_node->shared_mem_lock); -#endif - if (!strstr(wasm_inst->cur_exception, "wasi proc exit")) { - bh_memcpy_s(curr_wasm_inst->cur_exception, - sizeof(curr_wasm_inst->cur_exception), - wasm_inst->cur_exception, - sizeof(wasm_inst->cur_exception)); - } -#if WASM_ENABLE_SHARED_MEMORY != 0 - if (shared_mem_node) - os_mutex_unlock(&shared_mem_node->shared_mem_lock); -#endif + const struct spread_exception_data *data = user_data; + WASMExecEnv *exec_env = (WASMExecEnv *)node; - /* Terminate the thread so it can exit from dead loops */ - set_thread_cancel_flags(curr_exec_env); - } -} + if (exec_env != data->skip) { + WASMModuleInstance *wasm_inst = + (WASMModuleInstance *)get_module_inst(exec_env); -static void -clear_exception_visitor(void *node, void *user_data) -{ - WASMExecEnv *exec_env = (WASMExecEnv *)user_data; - WASMExecEnv *curr_exec_env = (WASMExecEnv *)node; - - if (curr_exec_env != exec_env) { - WASMModuleInstance *curr_wasm_inst = - (WASMModuleInstance *)get_module_inst(curr_exec_env); + exception_lock(wasm_inst); + if (data->exception != NULL) { + snprintf(wasm_inst->cur_exception, sizeof(wasm_inst->cur_exception), + "Exception: %s", data->exception); + } + else { + wasm_inst->cur_exception[0] = '\0'; + } + exception_unlock(wasm_inst); -#if WASM_ENABLE_SHARED_MEMORY != 0 - WASMSharedMemNode *shared_mem_node = wasm_module_get_shared_memory( - (WASMModuleCommon *)curr_wasm_inst->module); - if (shared_mem_node) - os_mutex_lock(&shared_mem_node->shared_mem_lock); -#endif - curr_wasm_inst->cur_exception[0] = '\0'; -#if WASM_ENABLE_SHARED_MEMORY != 0 - if (shared_mem_node) - os_mutex_unlock(&shared_mem_node->shared_mem_lock); -#endif + /* Terminate the thread so it can exit from dead loops */ + if (data->exception != NULL) { + set_thread_cancel_flags(exec_env); + } + else { + clear_thread_cancel_flags(exec_env); + } } } void -wasm_cluster_spread_exception(WASMExecEnv *exec_env, bool clear) +wasm_cluster_set_exception(WASMExecEnv *exec_env, const char *exception) { + const bool has_exception = exception != NULL; WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env); bh_assert(cluster); + struct spread_exception_data data; + data.skip = NULL; + data.exception = exception; + os_mutex_lock(&cluster->lock); - cluster->has_exception = !clear; - traverse_list(&cluster->exec_env_list, - clear ? clear_exception_visitor : set_exception_visitor, - exec_env); + cluster->has_exception = has_exception; + traverse_list(&cluster->exec_env_list, set_exception_visitor, &data); os_mutex_unlock(&cluster->lock); } @@ -1339,13 +1334,91 @@ wasm_cluster_spread_custom_data(WASMModuleInstanceCommon *module_inst, } } +#if WASM_ENABLE_MODULE_INST_CONTEXT != 0 +struct inst_set_context_data { + void *key; + void *ctx; +}; + +static void +set_context_visitor(void *node, void *user_data) +{ + WASMExecEnv *curr_exec_env = (WASMExecEnv *)node; + WASMModuleInstanceCommon *module_inst = get_module_inst(curr_exec_env); + const struct inst_set_context_data *data = user_data; + + wasm_runtime_set_context(module_inst, data->key, data->ctx); +} + +void +wasm_cluster_set_context(WASMModuleInstanceCommon *module_inst, void *key, + void *ctx) +{ + WASMExecEnv *exec_env = wasm_clusters_search_exec_env(module_inst); + + if (exec_env == NULL) { + /* Maybe threads have not been started yet. */ + wasm_runtime_set_context(module_inst, key, ctx); + } + else { + WASMCluster *cluster; + struct inst_set_context_data data; + data.key = key; + data.ctx = ctx; + + cluster = wasm_exec_env_get_cluster(exec_env); + bh_assert(cluster); + + os_mutex_lock(&cluster->lock); + traverse_list(&cluster->exec_env_list, set_context_visitor, &data); + os_mutex_unlock(&cluster->lock); + } +} +#endif /* WASM_ENABLE_MODULE_INST_CONTEXT != 0 */ + bool wasm_cluster_is_thread_terminated(WASMExecEnv *exec_env) { os_mutex_lock(&exec_env->wait_lock); - bool is_thread_terminated = - (exec_env->suspend_flags.flags & 0x01) ? true : false; + bool is_thread_terminated = (WASM_SUSPEND_FLAGS_GET(exec_env->suspend_flags) + & WASM_SUSPEND_FLAG_TERMINATE) + ? true + : false; os_mutex_unlock(&exec_env->wait_lock); return is_thread_terminated; } + +void +exception_lock(WASMModuleInstance *module_inst) +{ + /* + * Note: this lock could be per module instance if desirable. + * We can revisit on AOT version bump. + * It probably doesn't matter though because the exception handling + * logic should not be executed too frequently anyway. + */ + os_mutex_lock(&_exception_lock); +} + +void +exception_unlock(WASMModuleInstance *module_inst) +{ + os_mutex_unlock(&_exception_lock); +} + +void +wasm_cluster_traverse_lock(WASMExecEnv *exec_env) +{ + WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env); + bh_assert(cluster); + os_mutex_lock(&cluster->lock); +} + +void +wasm_cluster_traverse_unlock(WASMExecEnv *exec_env) +{ + WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env); + bh_assert(cluster); + os_mutex_unlock(&cluster->lock); +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/thread_manager.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/thread_manager.h similarity index 94% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/thread_manager.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/thread_manager.h index 2060869c280..b95f434ae0d 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/thread_manager.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/thread_manager.h @@ -139,7 +139,7 @@ WASMExecEnv * wasm_clusters_search_exec_env(WASMModuleInstanceCommon *module_inst); void -wasm_cluster_spread_exception(WASMExecEnv *exec_env, bool clear); +wasm_cluster_set_exception(WASMExecEnv *exec_env, const char *exception); WASMExecEnv * wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env); @@ -151,6 +151,10 @@ void wasm_cluster_spread_custom_data(WASMModuleInstanceCommon *module_inst, void *custom_data); +void +wasm_cluster_set_context(WASMModuleInstanceCommon *module_inst, void *key, + void *ctx); + bool wasm_cluster_is_thread_terminated(WASMExecEnv *exec_env); @@ -211,6 +215,12 @@ wasm_cluster_set_debug_inst(WASMCluster *cluster, WASMDebugInstance *inst); #endif /* end of WASM_ENABLE_DEBUG_INTERP != 0 */ +void +wasm_cluster_traverse_lock(WASMExecEnv *exec_env); + +void +wasm_cluster_traverse_unlock(WASMExecEnv *exec_env); + #ifdef __cplusplus } #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/thread_mgr.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/thread_mgr.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/thread-mgr/thread_mgr.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/thread-mgr/thread_mgr.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/.gitignore new file mode 100644 index 00000000000..81c0ff6aaa1 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/.gitignore @@ -0,0 +1,2 @@ +**/*.wasm +**/*.tflite diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/README.md similarity index 59% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/README.md index ac737c28115..fbc99ccbb27 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/README.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/README.md @@ -25,6 +25,7 @@ Build the runtime image for your execution target type. * `cpu` * `nvidia-gpu` * `vx-delegate` +* `tpu` ``` EXECUTION_TYPE=cpu @@ -55,42 +56,59 @@ Tests: passed! ``` docker run \ - -v $PWD/core/iwasm/libraries/wasi-nn/test:/assets wasi-nn-cpu \ - --dir=/assets \ + -v $PWD/core/iwasm/libraries/wasi-nn/test:/assets \ + -v $PWD/core/iwasm/libraries/wasi-nn/test/models:/models \ + wasi-nn-cpu \ + --dir=/ \ --env="TARGET=cpu" \ /assets/test_tensorflow.wasm ``` * (NVIDIA) GPU + * Requirements: + * [NVIDIA docker](https://github.com/NVIDIA/nvidia-docker). ``` docker run \ --runtime=nvidia \ - -v $PWD/core/iwasm/libraries/wasi-nn/test:/assets wasi-nn-nvidia-gpu \ - --dir=/assets \ + -v $PWD/core/iwasm/libraries/wasi-nn/test:/assets \ + -v $PWD/core/iwasm/libraries/wasi-nn/test/models:/models \ + wasi-nn-nvidia-gpu \ + --dir=/ \ --env="TARGET=gpu" \ /assets/test_tensorflow.wasm ``` -* vx-delegate for NPU (x86 simulater) +* vx-delegate for NPU (x86 simulator) ``` docker run \ - -v $PWD/core/iwasm/libraries/wasi-nn/test:/assets wasi-nn-vx-delegate \ - --dir=/assets \ + -v $PWD/core/iwasm/libraries/wasi-nn/test:/assets \ + wasi-nn-vx-delegate \ + --dir=/ \ --env="TARGET=gpu" \ - /assets/test_tensorflow.wasm + /assets/test_tensorflow_quantized.wasm ``` +* (Coral) TPU + * Requirements: + * [Coral USB](https://coral.ai/products/accelerator/). - -Requirements: -* [NVIDIA docker](https://github.com/NVIDIA/nvidia-docker). +``` +docker run \ + --privileged \ + --device=/dev/bus/usb:/dev/bus/usb \ + -v $PWD/core/iwasm/libraries/wasi-nn/test:/assets \ + wasi-nn-tpu \ + --dir=/ \ + --env="TARGET=tpu" \ + /assets/test_tensorflow_quantized.wasm +``` ## What is missing Supported: * Graph encoding: `tensorflowlite`. -* Execution target: `cpu` and `gpu`. +* Execution target: `cpu`, `gpu` and `tpu`. * Tensor type: `fp32`. diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake new file mode 100644 index 00000000000..59fdaf758bf --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/Findtensorflow_lite.cmake @@ -0,0 +1,42 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + + +find_library(TENSORFLOW_LITE + NAMES tensorflow-lite +) + +if(NOT EXISTS ${TENSORFLOW_LITE}) + if(NOT EXISTS "${WAMR_ROOT_DIR}/core/deps/tensorflow-src") + execute_process( + COMMAND "${WAMR_ROOT_DIR}/core/deps/install_tensorflow.sh" + RESULT_VARIABLE TENSORFLOW_RESULT + ) + else() + message("Tensorflow is already downloaded.") + endif() + + set(TENSORFLOW_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/tensorflow-src") + + if(WAMR_BUILD_WASI_NN_ENABLE_GPU EQUAL 1) + # Tensorflow specific: + # * https://www.tensorflow.org/lite/guide/build_cmake#available_options_to_build_tensorflow_lite + set (TFLITE_ENABLE_GPU ON) + endif() + + if (CMAKE_SIZEOF_VOID_P EQUAL 4) + set (TFLITE_ENABLE_XNNPACK OFF) + endif() + + add_subdirectory( + "${TENSORFLOW_SOURCE_DIR}/tensorflow/lite" + "${CMAKE_CURRENT_BINARY_DIR}/tensorflow-lite" + EXCLUDE_FROM_ALL + ) + + set(TENSORFLOW_LITE_INCLUDE_DIR "${TENSORFLOW_SOURCE_DIR}") + set(FLATBUFFER_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/flatbuffers/include") + + include_directories(${TENSORFLOW_LITE_INCLUDE_DIR}) + include_directories(${FLATBUFFER_INCLUDE_DIR}) +endif() diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/iwasm_helper.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/iwasm_helper.cmake new file mode 100644 index 00000000000..670988e1d8d --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/iwasm_helper.cmake @@ -0,0 +1,46 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +if (NOT DEFINED WAMR_BUILD_PLATFORM) + string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) +endif () + +set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") +set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") + +set (CMAKE_C_STANDARD 99) + +if (NOT DEFINED WAMR_BUILD_TARGET) + if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)") + set (WAMR_BUILD_TARGET "AARCH64") + elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64") + set (WAMR_BUILD_TARGET "RISCV64") + elseif (CMAKE_SIZEOF_VOID_P EQUAL 8) + set (WAMR_BUILD_TARGET "X86_64") + elseif (CMAKE_SIZEOF_VOID_P EQUAL 4) + set (WAMR_BUILD_TARGET "X86_32") + else () + message(SEND_ERROR "Unsupported build target platform!") + endif () +endif () + +set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow -Wno-unused-parameter") + +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused") + +if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64") + if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register") + endif () +endif () + +set (WAMR_BUILD_INTERP 1) +set (WAMR_BUILD_AOT 1) +set (WAMR_BUILD_JIT 0) +set (WAMR_BUILD_LIBC_WASI 1) +set (WAMR_BUILD_FAST_INTERP 1) + +if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) + set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") +endif () +set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/wasi_nn.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/wasi_nn.cmake new file mode 100644 index 00000000000..48af9babf72 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/cmake/wasi_nn.cmake @@ -0,0 +1,22 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) + +# Find tensorflow-lite +find_package(tensorflow_lite REQUIRED) + +set(WASI_NN_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/..) + +include_directories (${WASI_NN_ROOT_DIR}/include) +include_directories (${WASI_NN_ROOT_DIR}/src) +include_directories (${WASI_NN_ROOT_DIR}/src/utils) + +set ( + WASI_NN_SOURCES + ${WASI_NN_ROOT_DIR}/src/wasi_nn.c + ${WASI_NN_ROOT_DIR}/src/wasi_nn_tensorflowlite.cpp + ${WASI_NN_ROOT_DIR}/src/utils/wasi_nn_app_native.c +) + +set (WASI_NN_LIBS tensorflow-lite) diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/external/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/external/CMakeLists.txt new file mode 100644 index 00000000000..4157e194c84 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/external/CMakeLists.txt @@ -0,0 +1,58 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +cmake_minimum_required(VERSION 3.16) +project(wasi-nn C CXX) + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../..) +set(WASI_NN_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/..) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Debug) +endif() + +#### libvmlib #### +# NOTE: we build vmlib as a shared library here so that it can be +# shared between iwasm and native libraries. +include(${WASI_NN_ROOT_DIR}/cmake/iwasm_helper.cmake) +include(${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) + +add_library(vmlib SHARED ${WAMR_RUNTIME_LIB_SOURCE}) + +# iwasm +include(${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) +set(RUNTIME_SOURCE_ALL + ${WAMR_ROOT_DIR}/product-mini/platforms/${WAMR_BUILD_PLATFORM}/main.c + ${UNCOMMON_SHARED_SOURCE} +) + +add_executable(iwasm ${RUNTIME_SOURCE_ALL}) +target_link_libraries(iwasm vmlib -lpthread -lm -ldl) + +#### TensorFlow #### + +include(${WASI_NN_ROOT_DIR}/cmake/wasi_nn.cmake) + +#### WASI-NN #### + +include_directories( + ${WAMR_ROOT_DIR}/core/iwasm/include + ${WAMR_ROOT_DIR}/core/shared/utils + ${WAMR_ROOT_DIR}/core/shared/platform/linux +) + +add_library(wasi-nn SHARED + ${WASI_NN_SOURCES} +) + +# Add `get_native_lib` symbol +target_compile_definitions(wasi-nn PUBLIC + WASI_NN_SHARED +) + +target_link_libraries(wasi-nn + ${WASI_NN_LIBS} + vmlib +) diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/external/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/external/README.md new file mode 100644 index 00000000000..b255185ed7e --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/external/README.md @@ -0,0 +1,13 @@ +# wasi-nn as shared library + +Example on how to create libwasi-nn (external library) instead of embedding wasi-nn inside iwasm + +From folder `core/iwasm/libraries/wasi-nn/test`, build the test and run + +```sh +../external/build/iwasm \ + --dir=. \ + --env="TARGET=cpu" \ + --native-lib=../external/build/libwasi-nn.so \ + test_tensorflow.wasm +``` diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/wasi_nn.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/include/wasi_nn.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/wasi_nn.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/include/wasi_nn.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/wasi_nn_types.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/include/wasi_nn_types.h similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/wasi_nn_types.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/include/wasi_nn_types.h index a2cebe49ecb..7cfc70f341e 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/wasi_nn_types.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/include/wasi_nn_types.h @@ -6,6 +6,9 @@ #ifndef WASI_NN_TYPES_H #define WASI_NN_TYPES_H +#include +#include + /** * ERRORS * diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/utils/logger.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/utils/logger.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/utils/logger.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/utils/logger.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/utils/wasi_nn_app_native.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn.c similarity index 76% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn.c index 466630f99f1..c234e450a15 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn.c @@ -9,16 +9,18 @@ #include #include #include +#include #include "wasi_nn.h" +#include "wasi_nn_private.h" #include "wasi_nn_app_native.h" -#include "logger.h" #include "wasi_nn_tensorflowlite.hpp" +#include "logger.h" #include "bh_platform.h" #include "wasm_export.h" -#include "wasm_runtime.h" -#include "aot_runtime.h" + +#define HASHMAP_INITIAL_SIZE 20 /* Definition of 'wasi_nn.h' structs in WASM app format (using offset) */ @@ -51,6 +53,120 @@ static api_function lookup[] = { tensorflowlite_get_output } }; +static HashMap *hashmap; + +static void +wasi_nn_ctx_destroy(WASINNContext *wasi_nn_ctx); + +/* Get wasi-nn context from module instance */ + +static uint32 +hash_func(const void *key) +{ + // fnv1a_hash + const uint32 FNV_PRIME = 16777619; + const uint32 FNV_OFFSET_BASIS = 2166136261U; + + uint32 hash = FNV_OFFSET_BASIS; + const unsigned char *bytes = (const unsigned char *)key; + + for (size_t i = 0; i < sizeof(uintptr_t); ++i) { + hash ^= bytes[i]; + hash *= FNV_PRIME; + } + + return hash; +} + +static bool +key_equal_func(void *key1, void *key2) +{ + return key1 == key2; +} + +static void +key_destroy_func(void *key1) +{} + +static void +value_destroy_func(void *value) +{ + wasi_nn_ctx_destroy((WASINNContext *)value); +} + +static WASINNContext * +wasi_nn_initialize_context() +{ + NN_DBG_PRINTF("Initializing wasi-nn context"); + WASINNContext *wasi_nn_ctx = + (WASINNContext *)wasm_runtime_malloc(sizeof(WASINNContext)); + if (wasi_nn_ctx == NULL) { + NN_ERR_PRINTF("Error when allocating memory for WASI-NN context"); + return NULL; + } + wasi_nn_ctx->is_model_loaded = false; + tensorflowlite_initialize(&wasi_nn_ctx->tflite_ctx); + return wasi_nn_ctx; +} + +static bool +wasi_nn_initialize() +{ + NN_DBG_PRINTF("Initializing wasi-nn"); + hashmap = bh_hash_map_create(HASHMAP_INITIAL_SIZE, true, hash_func, + key_equal_func, key_destroy_func, + value_destroy_func); + if (hashmap == NULL) { + NN_ERR_PRINTF("Error while initializing hashmap"); + return false; + } + return true; +} + +static WASINNContext * +wasm_runtime_get_wasi_nn_ctx(wasm_module_inst_t instance) +{ + WASINNContext *wasi_nn_ctx = + (WASINNContext *)bh_hash_map_find(hashmap, (void *)instance); + if (wasi_nn_ctx == NULL) { + wasi_nn_ctx = wasi_nn_initialize_context(); + if (wasi_nn_ctx == NULL) + return NULL; + bool ok = + bh_hash_map_insert(hashmap, (void *)instance, (void *)wasi_nn_ctx); + if (!ok) { + NN_ERR_PRINTF("Error while storing context"); + wasi_nn_ctx_destroy(wasi_nn_ctx); + return NULL; + } + } + NN_DBG_PRINTF("Returning ctx"); + return wasi_nn_ctx; +} + +static void +wasi_nn_ctx_destroy(WASINNContext *wasi_nn_ctx) +{ + if (wasi_nn_ctx == NULL) { + NN_ERR_PRINTF( + "Error when deallocating memory. WASI-NN context is NULL"); + return; + } + NN_DBG_PRINTF("Freeing wasi-nn"); + NN_DBG_PRINTF("-> is_model_loaded: %d", wasi_nn_ctx->is_model_loaded); + NN_DBG_PRINTF("-> current_encoding: %d", wasi_nn_ctx->current_encoding); + tensorflowlite_destroy(wasi_nn_ctx->tflite_ctx); + wasm_runtime_free(wasi_nn_ctx); +} + +void +wasi_nn_destroy(wasm_module_inst_t instance) +{ + WASINNContext *wasi_nn_ctx = wasm_runtime_get_wasi_nn_ctx(instance); + bh_hash_map_remove(hashmap, (void *)instance, NULL, NULL); + wasi_nn_ctx_destroy(wasi_nn_ctx); +} + /* Utils */ static bool @@ -64,36 +180,13 @@ is_encoding_implemented(graph_encoding encoding) static error is_model_initialized(WASINNContext *wasi_nn_ctx) { - if (!wasi_nn_ctx->is_initialized) { + if (!wasi_nn_ctx->is_model_loaded) { NN_ERR_PRINTF("Model not initialized."); return runtime_error; } return success; } -WASINNContext * -wasm_runtime_get_wasi_nn_ctx(wasm_module_inst_t instance) -{ - WASINNContext *wasi_nn_ctx = NULL; -#if WASM_ENABLE_INTERP != 0 - if (instance->module_type == Wasm_Module_Bytecode) { - NN_DBG_PRINTF("Getting ctx from WASM"); - WASMModuleInstance *module_inst = (WASMModuleInstance *)instance; - wasi_nn_ctx = ((WASMModuleInstanceExtra *)module_inst->e)->wasi_nn_ctx; - } -#endif -#if WASM_ENABLE_AOT != 0 - if (instance->module_type == Wasm_Module_AoT) { - NN_DBG_PRINTF("Getting ctx from AOT"); - AOTModuleInstance *module_inst = (AOTModuleInstance *)instance; - wasi_nn_ctx = ((AOTModuleInstanceExtra *)module_inst->e)->wasi_nn_ctx; - } -#endif - bh_assert(wasi_nn_ctx != NULL); - NN_DBG_PRINTF("Returning ctx"); - return wasi_nn_ctx; -} - /* WASI-NN implementation */ error @@ -131,7 +224,7 @@ wasi_nn_load(wasm_exec_env_t exec_env, graph_builder_array_wasm *builder, NN_DBG_PRINTF("wasi_nn_load finished with status %d [graph=%d]", res, *g); wasi_nn_ctx->current_encoding = encoding; - wasi_nn_ctx->is_initialized = true; + wasi_nn_ctx->is_model_loaded = true; fail: // XXX: Free intermediate structure pointers @@ -250,39 +343,6 @@ wasi_nn_get_output(wasm_exec_env_t exec_env, graph_execution_context ctx, return res; } -/* Non-exposed public functions */ - -WASINNContext * -wasi_nn_initialize() -{ - NN_DBG_PRINTF("Initializing wasi-nn"); - WASINNContext *wasi_nn_ctx = - (WASINNContext *)wasm_runtime_malloc(sizeof(WASINNContext)); - if (wasi_nn_ctx == NULL) { - NN_ERR_PRINTF("Error when allocating memory for WASI-NN context"); - return NULL; - } - wasi_nn_ctx->is_initialized = true; - wasi_nn_ctx->current_encoding = 3; - tensorflowlite_initialize(&wasi_nn_ctx->tflite_ctx); - return wasi_nn_ctx; -} - -void -wasi_nn_destroy(WASINNContext *wasi_nn_ctx) -{ - if (wasi_nn_ctx == NULL) { - NN_ERR_PRINTF( - "Error when deallocating memory. WASI-NN context is NULL"); - return; - } - NN_DBG_PRINTF("Freeing wasi-nn"); - NN_DBG_PRINTF("-> is_initialized: %d", wasi_nn_ctx->is_initialized); - NN_DBG_PRINTF("-> current_encoding: %d", wasi_nn_ctx->current_encoding); - tensorflowlite_destroy(wasi_nn_ctx->tflite_ctx); - wasm_runtime_free(wasi_nn_ctx); -} - /* Register WASI-NN in WAMR */ /* clang-format off */ @@ -299,8 +359,19 @@ static NativeSymbol native_symbols_wasi_nn[] = { }; uint32_t -get_wasi_nn_export_apis(NativeSymbol **p_libc_wasi_apis) +get_wasi_nn_export_apis(NativeSymbol **p_native_symbols) { - *p_libc_wasi_apis = native_symbols_wasi_nn; + if (!wasi_nn_initialize()) + return 0; + *p_native_symbols = native_symbols_wasi_nn; return sizeof(native_symbols_wasi_nn) / sizeof(NativeSymbol); } + +#if defined(WASI_NN_SHARED) +uint32_t +get_native_lib(char **p_module_name, NativeSymbol **p_native_symbols) +{ + *p_module_name = "wasi_nn"; + return get_wasi_nn_export_apis(p_native_symbols); +} +#endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn_private.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn_private.h similarity index 71% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn_private.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn_private.h index 52d16bd1da0..e66c274a093 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn_private.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn_private.h @@ -7,25 +7,20 @@ #define WASI_NN_PRIVATE_H #include "wasi_nn_types.h" +#include "wasm_export.h" typedef struct { - bool is_initialized; + bool is_model_loaded; graph_encoding current_encoding; void *tflite_ctx; } WASINNContext; -/** - * @brief Initialize wasi-nn - * - */ -WASINNContext * -wasi_nn_initialize(); /** * @brief Destroy wasi-nn on app exists * */ void -wasi_nn_destroy(WASINNContext *wasi_nn_ctx); +wasi_nn_destroy(wasm_module_inst_t instance); #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.cpp similarity index 74% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.cpp rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.cpp index dfd21787cd8..65e38f867c0 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.cpp +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.cpp @@ -7,9 +7,8 @@ #include "wasi_nn_tensorflowlite.hpp" #include "logger.h" -#include "bh_common.h" #include "bh_platform.h" -#include "platform_common.h" +#include "wasm_export.h" #include #include @@ -17,11 +16,11 @@ #include #include -#if defined(WASI_NN_ENABLE_GPU) +#if WASM_ENABLE_WASI_NN_GPU != 0 #include #endif -#if defined(WASI_NN_ENABLE_EXTERNAL_DELEGATE) +#if WASM_ENABLE_WASI_NN_EXTERNAL_DELEGATE != 0 #include #endif @@ -131,8 +130,8 @@ tensorflowlite_load(void *tflite_ctx, graph_builder_array *builder, return invalid_argument; } - if (target != cpu && target != gpu) { - NN_ERR_PRINTF("Only CPU and GPU target is supported."); + if (target != cpu && target != gpu && target != tpu) { + NN_ERR_PRINTF("Only CPU, GPU and TPU target is supported."); return invalid_argument; } @@ -196,7 +195,7 @@ tensorflowlite_init_execution_context(void *tflite_ctx, graph g, switch (tfl_ctx->models[g].target) { case gpu: { -#if defined(WASI_NN_ENABLE_GPU) +#if WASM_ENABLE_WASI_NN_GPU != 0 NN_WARN_PRINTF("GPU enabled."); // https://www.tensorflow.org/lite/performance/gpu TfLiteGpuDelegateOptionsV2 options = @@ -217,10 +216,19 @@ tensorflowlite_init_execution_context(void *tflite_ctx, graph g, NN_ERR_PRINTF("Error when enabling GPU delegate."); use_default = true; } -#elif defined(WASI_NN_ENABLE_EXTERNAL_DELEGATE) +#else + NN_WARN_PRINTF("GPU not enabled."); + use_default = true; +#endif + break; + } + case tpu: + { +#if WASM_ENABLE_WASI_NN_EXTERNAL_DELEGATE != 0 NN_WARN_PRINTF("external delegation enabled."); TfLiteExternalDelegateOptions options = - TfLiteExternalDelegateOptionsDefault(WASI_NN_EXT_DELEGATE_PATH); + TfLiteExternalDelegateOptionsDefault( + WASM_WASI_NN_EXTERNAL_DELEGATE_PATH); tfl_ctx->delegate = TfLiteExternalDelegateCreate(&options); if (tfl_ctx->delegate == NULL) { NN_ERR_PRINTF("Error when generating External delegate."); @@ -234,7 +242,7 @@ tensorflowlite_init_execution_context(void *tflite_ctx, graph g, use_default = true; } #else - NN_WARN_PRINTF("GPU not enabled."); + NN_WARN_PRINTF("External delegate not enabled."); use_default = true; #endif break; @@ -286,14 +294,37 @@ tensorflowlite_set_input(void *tflite_ctx, graph_execution_context ctx, return invalid_argument; } - auto *input = - tfl_ctx->interpreters[ctx].interpreter->typed_input_tensor( - index); - if (input == NULL) - return missing_memory; + if (tensor->quantization.type == kTfLiteNoQuantization) { + NN_DBG_PRINTF("No quantization information. Using float as default"); + float *it = + tfl_ctx->interpreters[ctx].interpreter->typed_input_tensor( + index); + + int size = model_tensor_size * sizeof(float); + bh_memcpy_s(it, size, input_tensor->data, size); + } + else { // TODO: Assumming uint8 quantized networks. + TfLiteAffineQuantization *quant_info = + (TfLiteAffineQuantization *)tensor->quantization.params; + if (quant_info->scale->size != 1 || quant_info->zero_point->size != 1) { + NN_ERR_PRINTF("Quantization per channel is not supported"); + return runtime_error; + } + uint8_t *it = + tfl_ctx->interpreters[ctx].interpreter->typed_input_tensor( + index); + + float scale = quant_info->scale->data[0]; + float zero_point = (float)quant_info->zero_point->data[0]; + NN_DBG_PRINTF("input tensor: (scale, offset) = (%f, %f)", scale, + zero_point); + + float *input_tensor_f = (float *)input_tensor->data; + for (uint32_t i = 0; i < model_tensor_size; ++i) { + it[i] = (uint8_t)(input_tensor_f[i] / scale + zero_point); + } + } - bh_memcpy_s(input, model_tensor_size * sizeof(float), input_tensor->data, - model_tensor_size * sizeof(float)); return success; } @@ -326,6 +357,7 @@ tensorflowlite_get_output(void *tflite_ctx, graph_execution_context ctx, NN_DBG_PRINTF("Number of tensors (%d)", num_output_tensors); if (index + 1 > num_output_tensors) { + NN_ERR_PRINTF("Index %d is invalid.", index); return runtime_error; } @@ -344,15 +376,37 @@ tensorflowlite_get_output(void *tflite_ctx, graph_execution_context ctx, return missing_memory; } - float *tensor_f = - tfl_ctx->interpreters[ctx].interpreter->typed_output_tensor( - index); - for (uint32_t i = 0; i < model_tensor_size; ++i) - NN_DBG_PRINTF("output: %f", tensor_f[i]); + if (tensor->quantization.type == kTfLiteNoQuantization) { + NN_DBG_PRINTF("No quantization information"); + float *ot = + tfl_ctx->interpreters[ctx].interpreter->typed_output_tensor( + index); + + int size = model_tensor_size * sizeof(float); + bh_memcpy_s(output_tensor, size, ot, size); + } + else { // TODO: Assumming uint8 quantized networks. + TfLiteAffineQuantization *quant_info = + (TfLiteAffineQuantization *)tensor->quantization.params; + if (quant_info->scale->size != 1 || quant_info->zero_point->size != 1) { + NN_ERR_PRINTF("Quantization per channel is not supported"); + return runtime_error; + } + uint8_t *ot = tfl_ctx->interpreters[ctx] + .interpreter->typed_output_tensor(index); + + float scale = quant_info->scale->data[0]; + float zero_point = (float)quant_info->zero_point->data[0]; + NN_DBG_PRINTF("output tensor: (scale, offset) = (%f, %f)", scale, + zero_point); + + float *output_tensor_f = (float *)output_tensor; + for (uint32_t i = 0; i < model_tensor_size; ++i) { + output_tensor_f[i] = (ot[i] - zero_point) * scale; + } + } *output_tensor_size = model_tensor_size; - bh_memcpy_s(output_tensor, model_tensor_size * sizeof(float), tensor_f, - model_tensor_size * sizeof(float)); return success; } @@ -393,19 +447,35 @@ tensorflowlite_destroy(void *tflite_ctx) */ TFLiteContext *tfl_ctx = (TFLiteContext *)tflite_ctx; - if (tfl_ctx->delegate != NULL) { -#if defined(WASI_NN_ENABLE_GPU) - TfLiteGpuDelegateV2Delete(tfl_ctx->delegate); -#elif defined(WASI_NN_ENABLE_EXTERNAL_DELEGATE) - TfLiteExternalDelegateDelete(tfl_ctx->delegate); -#endif - } - NN_DBG_PRINTF("Freeing memory."); for (int i = 0; i < MAX_GRAPHS_PER_INST; ++i) { tfl_ctx->models[i].model.reset(); - if (tfl_ctx->models[i].model_pointer) + if (tfl_ctx->models[i].model_pointer) { + if (tfl_ctx->delegate) { + switch (tfl_ctx->models[i].target) { + case gpu: + { +#if WASM_ENABLE_WASI_NN_GPU != 0 + TfLiteGpuDelegateV2Delete(tfl_ctx->delegate); +#else + NN_ERR_PRINTF("GPU delegate delete but not enabled."); +#endif + break; + } + case tpu: + { +#if WASM_ENABLE_WASI_NN_EXTERNAL_DELEGATE != 0 + TfLiteExternalDelegateDelete(tfl_ctx->delegate); +#else + NN_ERR_PRINTF( + "External delegate delete but not enabled."); +#endif + break; + } + } + } wasm_runtime_free(tfl_ctx->models[i].model_pointer); + } tfl_ctx->models[i].model_pointer = NULL; } for (int i = 0; i < MAX_GRAPH_EXEC_CONTEXTS_PER_INST; ++i) { diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.hpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.hpp similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.hpp rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/src/wasi_nn_tensorflowlite.hpp diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.compile b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.compile new file mode 100644 index 00000000000..b20d0111afa --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.compile @@ -0,0 +1,26 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +FROM ubuntu:20.04 + +ENV DEBIAN_FRONTEND=noninteractive + +# hadolint ignore=DL3008 +RUN apt-get update && apt-get install -y \ + cmake build-essential git wget python3.10 python3-pip --no-install-recommends \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* + +ARG WASI_SDK_VER=19 +RUN wget -c --progress=dot:giga https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VER}/wasi-sdk-${WASI_SDK_VER}.0-linux.tar.gz -P /opt \ + && tar xf /opt/wasi-sdk-${WASI_SDK_VER}.0-linux.tar.gz -C /opt \ + && ln -fs /opt/wasi-sdk-${WASI_SDK_VER}.0 /opt/wasi-sdk \ + && rm /opt/wasi-sdk-${WASI_SDK_VER}.0-linux.tar.gz + +WORKDIR /wasi-nn/test + +COPY core/iwasm/libraries/wasi-nn/test/requirements.txt . + +RUN pip3 install --no-cache-dir -r requirements.txt && rm requirements.txt + +ENTRYPOINT [ "bash", "./build.sh" ] diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.cpu b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.cpu new file mode 100644 index 00000000000..6fe56567e7c --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.cpu @@ -0,0 +1,35 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +FROM ubuntu:20.04 AS base + +ENV DEBIAN_FRONTEND=noninteractive + +# hadolint ignore=DL3008 +RUN apt-get update && apt-get install -y \ + cmake build-essential git --no-install-recommends + +WORKDIR /home/wamr + +COPY . . + +WORKDIR /home/wamr/product-mini/platforms/linux/build + +# hadolint ignore=DL3008 +RUN apt-get install -y wget ca-certificates --no-install-recommends \ + && mkdir /usr/local/share/ca-certificates/cacert.org \ + && wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \ + && update-ca-certificates \ + && git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt + +RUN cmake \ + -DWAMR_BUILD_WASI_NN=1 \ + .. + +RUN make -j "$(grep -c ^processor /proc/cpuinfo)" + +FROM ubuntu:22.04 + +COPY --from=base /home/wamr/product-mini/platforms/linux/build/iwasm /iwasm + +ENTRYPOINT [ "/iwasm" ] diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.nvidia-gpu b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.nvidia-gpu new file mode 100644 index 00000000000..737b2d3f043 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.nvidia-gpu @@ -0,0 +1,49 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +FROM ubuntu:20.04 AS base + +ENV DEBIAN_FRONTEND=noninteractive + +# hadolint ignore=DL3008 +RUN apt-get update && apt-get install -y \ + cmake build-essential git --no-install-recommends + +WORKDIR /home/wamr + +COPY . . + +WORKDIR /home/wamr/product-mini/platforms/linux/build + +# hadolint ignore=DL3008 +RUN apt-get install -y wget ca-certificates --no-install-recommends \ + && mkdir /usr/local/share/ca-certificates/cacert.org \ + && wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \ + && update-ca-certificates \ + && git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt + +RUN cmake \ + -DWAMR_BUILD_WASI_NN=1 \ + -DWAMR_BUILD_WASI_NN_ENABLE_GPU=1 \ + .. + +RUN make -j "$(grep -c ^processor /proc/cpuinfo)" + +FROM nvidia/cuda:11.3.0-runtime-ubuntu20.04 + +# hadolint ignore=DL3008 +RUN apt-get update && apt-get install -y --no-install-recommends \ + ocl-icd-libopencl1 \ + ocl-icd-opencl-dev \ + clinfo && \ + rm -rf /var/lib/apt/lists/* + +RUN mkdir -p /etc/OpenCL/vendors && \ + echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd + +ENV NVIDIA_VISIBLE_DEVICES=all +ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility + +COPY --from=base /home/wamr/product-mini/platforms/linux/build/iwasm /iwasm + +ENTRYPOINT [ "/iwasm" ] diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.tpu b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.tpu new file mode 100644 index 00000000000..742645b06ae --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.tpu @@ -0,0 +1,37 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +FROM ubuntu:20.04 AS base + +ENV DEBIAN_FRONTEND=noninteractive + +# hadolint ignore=DL3008 +RUN apt-get update && apt-get install -y \ + cmake build-essential git curl gnupg --no-install-recommends && \ + rm -rf /var/lib/apt/lists/* + +# hadolint ignore=DL3008,DL4006 +RUN echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | tee /etc/apt/sources.list.d/coral-edgetpu.list && \ + curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \ + apt-get update && apt-get install -y libedgetpu1-std --no-install-recommends && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /home/wamr + +COPY . . + +WORKDIR /home/wamr/product-mini/platforms/linux/build + +RUN cmake \ + -DWAMR_BUILD_WASI_NN=1 \ + -DWAMR_BUILD_WASI_NN_ENABLE_EXTERNAL_DELEGATE=1 \ + -DWAMR_BUILD_WASI_NN_EXTERNAL_DELEGATE_PATH="libedgetpu.so.1.0" \ + -DWAMR_BUILD_WASI_NN_ENABLE_GPU=1 \ + .. + +RUN make -j "$(grep -c ^processor /proc/cpuinfo)" && \ + cp /home/wamr/product-mini/platforms/linux/build/iwasm /iwasm + +WORKDIR /assets + +ENTRYPOINT [ "/iwasm" ] diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.vx-delegate b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.vx-delegate new file mode 100644 index 00000000000..f078045b946 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/Dockerfile.vx-delegate @@ -0,0 +1,113 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +FROM ubuntu:20.04 AS base + +ENV DEBIAN_FRONTEND=noninteractive + + +# hadolint ignore=DL3008 +RUN apt-get update && apt-get install -y \ + cmake build-essential git curl libssl-dev python3 --no-install-recommends \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* + +# hadolint ignore=DL3008 +RUN apt-get update && apt-get install -y wget ca-certificates --no-install-recommends \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* \ + && mkdir /usr/local/share/ca-certificates/cacert.org \ + && wget -qP /usr/local/share/ca-certificates/cacert.org http://www.cacert.org/certs/root.crt http://www.cacert.org/certs/class3.crt \ + && update-ca-certificates \ + && git config --global http.sslCAinfo /etc/ssl/certs/ca-certificates.crt + +# Build TensorFlow Lite VX delegate default built for x86-64 simulator +WORKDIR /tmp +RUN git clone https://github.com/VeriSilicon/TIM-VX.git tim-vx \ + && git clone https://github.com/VeriSilicon/tflite-vx-delegate.git \ + && git clone https://github.com/tensorflow/tensorflow.git + + +# Build TIM-VX +WORKDIR /tmp/tim-vx/host_build +RUN cmake -DCMAKE_INSTALL_PREFIX=/usr/local ../ \ + && make -j "$(grep -c ^processor /proc/cpuinfo)" \ + && make install + +WORKDIR /tmp/tim-vx +#RUN mkdir -p prebuilt-sdk/x86_64_linux/lib/include +#RUN cp prebuilt-sdk/x86_64_linux/include/CL prebuilt-sdk/x86_64_linux/lib/include -fr + + +# Build TensorFlow Lite +WORKDIR /tmp/tensorflow/build +RUN cmake \ + -DBUILD_SHARED_LIBS=ON=on \ + -DTFLITE_ENABLE_RUY=on \ + -DTFLITE_ENABLE_NNAPI=off \ + -DTFLITE_ENABLE_XNNPACK=on \ + -DTFLITE_ENABLE_EXTERNAL_DELEGATE=on \ + ../tensorflow/lite/ +RUN make -j "$(grep -c ^processor /proc/cpuinfo)" \ + && make install \ + && cp --no-preserve=ownership -d lib*.so* /usr/local/lib \ + && cp -r --no-preserve=ownership -d flatbuffers/include/flatbuffers /usr/local/include +# install header files +RUN install -d /usr/local/include/tensorflow/lite +WORKDIR /tmp/tensorflow/tensorflow/lite +# hadolint ignore=SC2046 +RUN cp --parents \ + $(find . -name "*.h*") \ + /usr/local/include/tensorflow/lite +# install version.h from core +RUN install -d /usr/local/include/tensorflow/core/public && \ + cp /tmp/tensorflow/tensorflow/core/public/version.h /usr/local/include/tensorflow/core/public + + +# Build Vx Delegate default built for x86-64 simulator +WORKDIR /tmp/tflite-vx-delegate/build +RUN cmake \ + -DBUILD_SHARED_LIBS=ON \ + -DFETCHCONTENT_SOURCE_DIR_TENSORFLOW=/tmp/tensorflow \ + -DTFLITE_LIB_LOC=/usr/local/lib/libtensorflow-lite.so \ + -DTIM_VX_INSTALL=/usr/local \ + -DCMAKE_INSTALL_PREFIX=/usr/ \ + ../ +RUN make vx_delegate -j "$(grep -c ^processor /proc/cpuinfo)" \ + && make install \ + && cp --no-preserve=ownership -d lib*.so* /usr/lib +# install header files +RUN install -d /usr/local/include/tensorflow-lite-vx-delegate +WORKDIR /tmp/tflite-vx-delegate/ +# hadolint ignore=SC2046 +RUN cp --parents \ + $(find . -name "*.h*") \ + /usr/local/include/tensorflow-lite-vx-delegate + +ENV VIVANTE_SDK_DIR=/tmp/tim-vx/prebuilt-sdk/x86_64_linux/ +ENV VSIMULATOR_CONFIG=czl + +ENV LD_LIBRARY_PATH=/tmp/tim-vx/prebuilt-sdk/x86_64_linux/lib:/usr/local/lib:/lib/x86_64-linux-gnu/:/lib64/:/usr/lib:$LD_LIBRARY_PATH + + +# Build WASI-NN +WORKDIR /home/wamr + +COPY . . + +WORKDIR /home/wamr/core/iwasm/libraries/wasi-nn/test/build + +# hadolint ignore=SC2086 +RUN cmake \ + -DCMAKE_LIBRARY_PATH=${CMAKE_LIBRARY_PATH}:/usr/local/lib/ \ + -DCMAKE_INCLUDE_PATH=${CMAKE_INCLUDE_PATH}:/usr/local/include/ \ + -DWAMR_BUILD_WASI_NN=1 \ + -DWAMR_BUILD_WASI_NN_ENABLE_EXT=1 \ + -DWASI_NN_EXT_DELEGATE_PATH="/usr/lib/libvx_delegate.so" \ + .. + +RUN make -j "$(grep -c ^processor /proc/cpuinfo)" + +RUN cp /home/wamr/core/iwasm/libraries/wasi-nn/test/build/iwasm /run/iwasm + +ENTRYPOINT [ "/run/iwasm" ] diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/build.sh similarity index 51% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/build.sh index 33879eaf7ce..da6cfa5f8e0 100755 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/build.sh +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/build.sh @@ -1,21 +1,41 @@ +#!/bin/sh + # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +CURR_PATH=$(cd $(dirname $0) && pwd -P) + # WASM application that uses WASI-NN /opt/wasi-sdk/bin/clang \ -Wl,--allow-undefined \ -Wl,--strip-all,--no-entry \ --sysroot=/opt/wasi-sdk/share/wasi-sysroot \ - -I.. -I../src/utils \ + -I../include -I../src/utils \ -o test_tensorflow.wasm \ test_tensorflow.c utils.c # TFLite models to use in the tests -cd models +cd ${CURR_PATH}/models python3 average.py python3 max.py python3 mult_dimension.py python3 mult_outputs.py python3 sum.py + +# Specific tests for TPU + +cd ${CURR_PATH} +/opt/wasi-sdk/bin/clang \ + -Wl,--allow-undefined \ + -Wl,--strip-all,--no-entry \ + --sysroot=/opt/wasi-sdk/share/wasi-sysroot \ + -I../include -I../src/utils \ + -o test_tensorflow_quantized.wasm \ + test_tensorflow_quantized.c utils.c + +cd ${CURR_PATH}/models +python3 quantized.py + +cd ${CURR_PATH} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/average.py b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/average.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/average.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/average.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/max.py b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/max.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/max.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/max.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/mult_dimension.py b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/mult_dimension.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/mult_dimension.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/mult_dimension.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/mult_outputs.py b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/mult_outputs.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/mult_outputs.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/mult_outputs.py diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/quantized.py b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/quantized.py new file mode 100644 index 00000000000..b195b319f5d --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/quantized.py @@ -0,0 +1,30 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +import tensorflow as tf +import numpy as np +import pathlib + +model = tf.keras.Sequential([ + tf.keras.layers.InputLayer(input_shape=[5, 5, 1]), + tf.keras.layers.AveragePooling2D( + pool_size=(5, 5), strides=None, padding="valid", data_format=None) + +]) + +def representative_dataset(): + for _ in range(1000): + data = np.random.randint(0, 25, (1, 5, 5, 1)) + yield [data.astype(np.float32)] + +converter = tf.lite.TFLiteConverter.from_keras_model(model) +converter.optimizations = [tf.lite.Optimize.DEFAULT] +converter.representative_dataset = representative_dataset +converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8] +converter.inference_input_type = tf.uint8 # or tf.int8 +converter.inference_output_type = tf.uint8 # or tf.int8 +tflite_model = converter.convert() + +tflite_models_dir = pathlib.Path("./") +tflite_model_file = tflite_models_dir / "quantized_model.tflite" +tflite_model_file.write_bytes(tflite_model) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/sum.py b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/sum.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/sum.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/sum.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/utils.py b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/utils.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/models/utils.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/models/utils.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/requirements.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/requirements.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/requirements.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/requirements.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/test_tensorflow.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/test_tensorflow.c similarity index 83% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/test_tensorflow.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/test_tensorflow.c index 2fa5165384c..6a9e20702f4 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/test_tensorflow.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/test_tensorflow.c @@ -20,7 +20,7 @@ test_sum(execution_target target) uint32_t output_size = 0; float *output = run_inference(target, input.input_tensor, input.dim, - &output_size, "/assets/models/sum.tflite", 1); + &output_size, "./models/sum.tflite", 1); assert(output_size == 1); assert(fabs(output[0] - 300.0) < EPSILON); @@ -38,7 +38,7 @@ test_max(execution_target target) uint32_t output_size = 0; float *output = run_inference(target, input.input_tensor, input.dim, - &output_size, "/assets/models/max.tflite", 1); + &output_size, "./models/max.tflite", 1); assert(output_size == 1); assert(fabs(output[0] - 24.0) < EPSILON); @@ -56,9 +56,8 @@ test_average(execution_target target) input_info input = create_input(dims); uint32_t output_size = 0; - float *output = - run_inference(target, input.input_tensor, input.dim, &output_size, - "/assets/models/average.tflite", 1); + float *output = run_inference(target, input.input_tensor, input.dim, + &output_size, "./models/average.tflite", 1); assert(output_size == 1); assert(fabs(output[0] - 12.0) < EPSILON); @@ -76,9 +75,8 @@ test_mult_dimensions(execution_target target) input_info input = create_input(dims); uint32_t output_size = 0; - float *output = - run_inference(target, input.input_tensor, input.dim, &output_size, - "/assets/models/mult_dim.tflite", 1); + float *output = run_inference(target, input.input_tensor, input.dim, + &output_size, "./models/mult_dim.tflite", 1); assert(output_size == 9); for (int i = 0; i < 9; i++) @@ -96,9 +94,8 @@ test_mult_outputs(execution_target target) input_info input = create_input(dims); uint32_t output_size = 0; - float *output = - run_inference(target, input.input_tensor, input.dim, &output_size, - "/assets/models/mult_out.tflite", 2); + float *output = run_inference(target, input.input_tensor, input.dim, + &output_size, "./models/mult_out.tflite", 2); assert(output_size == 8); // first tensor check diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/test_tensorflow_quantized.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/test_tensorflow_quantized.c new file mode 100644 index 00000000000..3ed7c751e3b --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/test_tensorflow_quantized.c @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include +#include +#include +#include +#include + +#include "utils.h" +#include "logger.h" + +#undef EPSILON +#define EPSILON 1e-2 + +void +test_average_quantized(execution_target target) +{ + int dims[] = { 1, 5, 5, 1 }; + input_info input = create_input(dims); + + uint32_t output_size = 0; + float *output = + run_inference(target, input.input_tensor, input.dim, &output_size, + "./models/quantized_model.tflite", 1); + + NN_INFO_PRINTF("Output size: %d", output_size); + NN_INFO_PRINTF("Result: average is %f", output[0]); + // NOTE: 11.95 instead of 12 because of errors due quantization + assert(fabs(output[0] - 11.95) < EPSILON); + + free(input.dim); + free(input.input_tensor); + free(output); +} + +int +main() +{ + char *env = getenv("TARGET"); + if (env == NULL) { + NN_INFO_PRINTF("Usage:\n--env=\"TARGET=[cpu|gpu|tpu]\""); + return 1; + } + execution_target target; + if (strcmp(env, "cpu") == 0) + target = cpu; + else if (strcmp(env, "gpu") == 0) + target = gpu; + else if (strcmp(env, "tpu") == 0) + target = tpu; + else { + NN_ERR_PRINTF("Wrong target!"); + return 1; + } + NN_INFO_PRINTF("################### Testing quantized model..."); + test_average_quantized(target); + + NN_INFO_PRINTF("Tests: passed!"); + return 0; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/utils.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/utils.c similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/utils.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/utils.c index e0704cab421..7b4f65d16b8 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/utils.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/utils.c @@ -132,8 +132,8 @@ run_inference(execution_target target, float *input, uint32_t *input_size, *output_size = MAX_OUTPUT_TENSOR_SIZE - *output_size; if (wasm_get_output(ctx, i, &out_tensor[offset], output_size) != success) { - NN_ERR_PRINTF("Error when getting output."); - exit(1); + NN_ERR_PRINTF("Error when getting index %d.", i); + break; } offset += *output_size; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/utils.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/utils.h similarity index 96% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/utils.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/utils.h index 6373be54214..0b2328406ea 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/utils.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/iwasm/libraries/wasi-nn/test/utils.h @@ -11,7 +11,7 @@ #include "wasi_nn.h" #define MAX_MODEL_SIZE 85000000 -#define MAX_OUTPUT_TENSOR_SIZE 200 +#define MAX_OUTPUT_TENSOR_SIZE 1000000 #define INPUT_TENSOR_DIMS 4 #define EPSILON 1e-8 diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/coap/er-coap/LICENSE.md b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/coap/er-coap/LICENSE.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/coap/er-coap/LICENSE.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/coap/er-coap/LICENSE.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/coap/er-coap/coap-constants.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/coap/er-coap/coap-constants.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/coap/er-coap/coap-constants.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/coap/er-coap/coap-constants.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/coap/extension/coap_ext.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/coap/extension/coap_ext.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/coap/extension/coap_ext.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/coap/extension/coap_ext.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/coap/lib_coap.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/coap/lib_coap.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/coap/lib_coap.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/coap/lib_coap.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/SConscript similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/SConscript rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/SConscript diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_alloc.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_alloc.c similarity index 94% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_alloc.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_alloc.c index 5c2a628a261..0e2c4da7cae 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_alloc.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_alloc.c @@ -24,19 +24,23 @@ hmu_is_in_heap(void *hmu, gc_uint8 *heap_base_addr, gc_uint8 *heap_end_addr) static bool remove_tree_node(gc_heap_t *heap, hmu_tree_node_t *p) { - hmu_tree_node_t *q = NULL, **slot = NULL, *parent; - hmu_tree_node_t *root = heap->kfc_tree_root; + hmu_tree_node_t *q = NULL, **slot = NULL; +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 + hmu_tree_node_t *root = heap->kfc_tree_root, *parent; gc_uint8 *base_addr = heap->base_addr; gc_uint8 *end_addr = base_addr + heap->current_size; +#endif bh_assert(p); +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 parent = p->parent; if (!parent || p == root /* p can not be the ROOT node */ || !hmu_is_in_heap(p, base_addr, end_addr) || (parent != root && !hmu_is_in_heap(parent, base_addr, end_addr))) { goto fail; } +#endif /* get the slot which holds pointer to node p */ if (p == p->parent->right) { @@ -67,9 +71,11 @@ remove_tree_node(gc_heap_t *heap, hmu_tree_node_t *p) /* move right child up*/ *slot = p->right; if (p->right) { +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (!hmu_is_in_heap(p->right, base_addr, end_addr)) { goto fail; } +#endif p->right->parent = p->parent; } @@ -80,9 +86,11 @@ remove_tree_node(gc_heap_t *heap, hmu_tree_node_t *p) if (!p->right) { /* move left child up*/ *slot = p->left; +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (!hmu_is_in_heap(p->left, base_addr, end_addr)) { goto fail; } +#endif /* p->left can never be NULL unless it is corrupted. */ p->left->parent = p->parent; @@ -92,14 +100,18 @@ remove_tree_node(gc_heap_t *heap, hmu_tree_node_t *p) /* both left & right exist, find p's predecessor at first*/ q = p->left; +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (!hmu_is_in_heap(q, base_addr, end_addr)) { goto fail; } +#endif while (q->right) { q = q->right; +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (!hmu_is_in_heap(q, base_addr, end_addr)) { goto fail; } +#endif } /* remove from the tree*/ @@ -111,15 +123,19 @@ remove_tree_node(gc_heap_t *heap, hmu_tree_node_t *p) q->left = p->left; q->right = p->right; if (q->left) { +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (!hmu_is_in_heap(q->left, base_addr, end_addr)) { goto fail; } +#endif q->left->parent = q; } if (q->right) { +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (!hmu_is_in_heap(q->right, base_addr, end_addr)) { goto fail; } +#endif q->right->parent = q; } @@ -127,27 +143,35 @@ remove_tree_node(gc_heap_t *heap, hmu_tree_node_t *p) return true; fail: +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 heap->is_heap_corrupted = true; +#endif return false; } static bool unlink_hmu(gc_heap_t *heap, hmu_t *hmu) { +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 gc_uint8 *base_addr, *end_addr; +#endif gc_size_t size; bh_assert(gci_is_heap_valid(heap)); bh_assert(hmu && (gc_uint8 *)hmu >= heap->base_addr && (gc_uint8 *)hmu < heap->base_addr + heap->current_size); +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (hmu_get_ut(hmu) != HMU_FC) { heap->is_heap_corrupted = true; return false; } +#endif +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 base_addr = heap->base_addr; end_addr = base_addr + heap->current_size; +#endif size = hmu_get_size(hmu); if (HMU_IS_FC_NORMAL(size)) { @@ -156,10 +180,12 @@ unlink_hmu(gc_heap_t *heap, hmu_t *hmu) hmu_normal_node_t *node = heap->kfc_normal_list[node_idx].next; while (node) { +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (!hmu_is_in_heap(node, base_addr, end_addr)) { heap->is_heap_corrupted = true; return false; } +#endif node_next = get_hmu_normal_node_next(node); if ((hmu_t *)node == hmu) { if (!node_prev) /* list head */ @@ -205,7 +231,9 @@ hmu_set_free_size(hmu_t *hmu) bool gci_add_fc(gc_heap_t *heap, hmu_t *hmu, gc_size_t size) { +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 gc_uint8 *base_addr, *end_addr; +#endif hmu_normal_node_t *np = NULL; hmu_tree_node_t *root = NULL, *tp = NULL, *node = NULL; uint32 node_idx; @@ -219,8 +247,10 @@ gci_add_fc(gc_heap_t *heap, hmu_t *hmu, gc_size_t size) <= heap->base_addr + heap->current_size); bh_assert(!(size & 7)); +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 base_addr = heap->base_addr; end_addr = base_addr + heap->current_size; +#endif hmu_set_ut(hmu, HMU_FC); hmu_set_size(hmu, size); @@ -228,10 +258,12 @@ gci_add_fc(gc_heap_t *heap, hmu_t *hmu, gc_size_t size) if (HMU_IS_FC_NORMAL(size)) { np = (hmu_normal_node_t *)hmu; +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (!hmu_is_in_heap(np, base_addr, end_addr)) { heap->is_heap_corrupted = true; return false; } +#endif node_idx = size >> 3; set_hmu_normal_node_next(np, heap->kfc_normal_list[node_idx].next); @@ -265,10 +297,12 @@ gci_add_fc(gc_heap_t *heap, hmu_t *hmu, gc_size_t size) } tp = tp->left; } +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (!hmu_is_in_heap(tp, base_addr, end_addr)) { heap->is_heap_corrupted = true; return false; } +#endif } return true; } @@ -321,15 +355,19 @@ alloc_hmu(gc_heap_t *heap, gc_size_t size) bh_assert(node_idx >= init_node_idx); p = normal_head->next; +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (!hmu_is_in_heap(p, base_addr, end_addr)) { heap->is_heap_corrupted = true; return NULL; } +#endif normal_head->next = get_hmu_normal_node_next(p); +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (((gc_int32)(uintptr_t)hmu_to_obj(p) & 7) != 0) { heap->is_heap_corrupted = true; return NULL; } +#endif if ((gc_size_t)node_idx != (uint32)init_node_idx /* with bigger size*/ @@ -365,10 +403,12 @@ alloc_hmu(gc_heap_t *heap, gc_size_t size) bh_assert(root); tp = root->right; while (tp) { +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (!hmu_is_in_heap(tp, base_addr, end_addr)) { heap->is_heap_corrupted = true; return NULL; } +#endif if (tp->size < size) { tp = tp->right; @@ -462,10 +502,12 @@ gc_alloc_vo_internal(void *vheap, gc_size_t size, const char *file, int line) /* integer overflow */ return NULL; +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (heap->is_heap_corrupted) { os_printf("[GC_ERROR]Heap is corrupted, allocate memory failed.\n"); return NULL; } +#endif os_mutex_lock(&heap->lock); @@ -522,10 +564,12 @@ gc_realloc_vo_internal(void *vheap, void *ptr, gc_size_t size, const char *file, /* integer overflow */ return NULL; +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (heap->is_heap_corrupted) { os_printf("[GC_ERROR]Heap is corrupted, allocate memory failed.\n"); return NULL; } +#endif if (obj_old) { hmu_old = obj_to_hmu(obj_old); @@ -564,6 +608,7 @@ gc_realloc_vo_internal(void *vheap, void *ptr, gc_size_t size, const char *file, os_mutex_unlock(&heap->lock); return NULL; } + hmu_mark_pinuse(hmu_next); } os_mutex_unlock(&heap->lock); return obj_old; @@ -646,10 +691,12 @@ gc_free_vo_internal(void *vheap, gc_object_t obj, const char *file, int line) return GC_SUCCESS; } +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (heap->is_heap_corrupted) { os_printf("[GC_ERROR]Heap is corrupted, free memory failed.\n"); return GC_ERROR; } +#endif hmu = obj_to_hmu(obj); @@ -766,11 +813,13 @@ gci_dump(gc_heap_t *heap) else if (ut == HMU_FC) inuse = 'F'; +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (size == 0 || size > (uint32)((uint8 *)end - (uint8 *)cur)) { os_printf("[GC_ERROR]Heap is corrupted, heap dump failed.\n"); heap->is_heap_corrupted = true; return; } +#endif os_printf("#%d %08" PRIx32 " %" PRIx32 " %d %d" " %c %" PRId32 "\n", @@ -787,8 +836,12 @@ gci_dump(gc_heap_t *heap) i++; } +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (cur != end) { os_printf("[GC_ERROR]Heap is corrupted, heap dump failed.\n"); heap->is_heap_corrupted = true; } +#else + bh_assert(cur == end); +#endif } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_gc.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_gc.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_gc.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_gc.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_gc_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_gc_internal.h similarity index 97% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_gc_internal.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_gc_internal.h index e1ff9d61d85..6abe2b12a50 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_gc_internal.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_gc_internal.h @@ -214,13 +214,16 @@ set_hmu_normal_node_next(hmu_normal_node_t *node, hmu_normal_node_t *next) #if defined(_MSC_VER) __pragma(pack(push, 1)); #define __attr_packed +#define __attr_aligned(a) #elif defined(__GNUC__) || defined(__clang__) #define __attr_packed __attribute__((packed)) +#define __attr_aligned(a) __attribute__((aligned(a))) #else #error "packed attribute isn't used to define struct hmu_tree_node" #endif #else /* else of UINTPTR_MAX == UINT64_MAX */ #define __attr_packed +#define __attr_aligned(a) #endif typedef struct hmu_tree_node { @@ -229,7 +232,7 @@ typedef struct hmu_tree_node { struct hmu_tree_node *right; struct hmu_tree_node *parent; gc_size_t size; -} __attr_packed hmu_tree_node_t; +} __attr_packed __attr_aligned(4) hmu_tree_node_t; #if UINTPTR_MAX == UINT64_MAX #if defined(_MSC_VER) @@ -268,9 +271,11 @@ typedef struct gc_heap_struct { size[left] <= size[cur] < size[right] */ hmu_tree_node_t *kfc_tree_root; +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 /* whether heap is corrupted, e.g. the hmu nodes are modified by user */ bool is_heap_corrupted; +#endif gc_size_t init_size; gc_size_t highmark_size; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_hmu.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_hmu.c similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_hmu.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_hmu.c index 41745e161ed..f9d7c0f4a79 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_hmu.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_hmu.c @@ -83,7 +83,9 @@ hmu_verify(void *vheap, hmu_t *hmu) os_printf("Invalid padding for object created at %s:%d\n", (prefix->file_name ? prefix->file_name : ""), prefix->line_no); +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 heap->is_heap_corrupted = true; +#endif } } } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_kfc.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_kfc.c similarity index 95% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_kfc.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_kfc.c index 80d20267943..1dda3ae031a 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/ems/ems_kfc.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/ems/ems_kfc.c @@ -133,8 +133,11 @@ gc_destroy_with_pool(gc_handle_t handle) hmu_t *cur = (hmu_t *)heap->base_addr; hmu_t *end = (hmu_t *)((char *)heap->base_addr + heap->current_size); - if (!heap->is_heap_corrupted - && (hmu_t *)((char *)cur + hmu_get_size(cur)) != end) { + if ( +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 + !heap->is_heap_corrupted && +#endif + (hmu_t *)((char *)cur + hmu_get_size(cur)) != end) { os_printf("Memory leak detected:\n"); gci_dump(heap); ret = GC_ERROR; @@ -186,10 +189,12 @@ gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size) if (offset == 0) return 0; +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (heap->is_heap_corrupted) { os_printf("[GC_ERROR]Heap is corrupted, heap migrate failed.\n"); return GC_ERROR; } +#endif heap->base_addr = (uint8 *)base_addr_new; @@ -211,11 +216,13 @@ gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size) while (cur < end) { size = hmu_get_size(cur); +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (size <= 0 || size > (uint32)((uint8 *)end - (uint8 *)cur)) { os_printf("[GC_ERROR]Heap is corrupted, heap migrate failed.\n"); heap->is_heap_corrupted = true; return GC_ERROR; } +#endif if (hmu_get_ut(cur) == HMU_FC && !HMU_IS_FC_NORMAL(size)) { tree_node = (hmu_tree_node_t *)cur; @@ -238,11 +245,15 @@ gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size) cur = (hmu_t *)((char *)cur + size); } +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 if (cur != end) { os_printf("[GC_ERROR]Heap is corrupted, heap migrate failed.\n"); heap->is_heap_corrupted = true; return GC_ERROR; } +#else + bh_assert(cur == end); +#endif return 0; } @@ -250,9 +261,13 @@ gc_migrate(gc_handle_t handle, char *pool_buf_new, gc_size_t pool_buf_size) bool gc_is_heap_corrupted(gc_handle_t handle) { +#if BH_ENABLE_GC_CORRUPTION_CHECK != 0 gc_heap_t *heap = (gc_heap_t *)handle; return heap->is_heap_corrupted ? true : false; +#else + return false; +#endif } #if BH_ENABLE_GC_VERIFY != 0 diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/mem_alloc.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/mem_alloc.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/mem_alloc.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/mem_alloc.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/mem_alloc.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/mem_alloc.cmake similarity index 69% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/mem_alloc.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/mem_alloc.cmake index c0b4157f43e..1754a1acaa0 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/mem_alloc.cmake +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/mem_alloc.cmake @@ -10,6 +10,14 @@ if (WAMR_BUILD_GC_VERIFY EQUAL 1) add_definitions (-DBH_ENABLE_GC_VERIFY=1) endif () +if (NOT DEFINED WAMR_BUILD_GC_CORRUPTION_CHECK) + set (WAMR_BUILD_GC_CORRUPTION_CHECK 1) +endif () + +if (WAMR_BUILD_GC_CORRUPTION_CHECK EQUAL 0) + add_definitions (-DBH_ENABLE_GC_CORRUPTION_CHECK=0) +endif () + file (GLOB_RECURSE source_all ${MEM_ALLOC_DIR}/ems/*.c ${MEM_ALLOC_DIR}/tlsf/*.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/mem_alloc.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/mem_alloc.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/mem-alloc/mem_alloc.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/mem-alloc/mem_alloc.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/alios_platform.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/alios_platform.c similarity index 87% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/alios_platform.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/alios_platform.c index c9f5f17e641..24bf9c7ffb5 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/alios_platform.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/alios_platform.c @@ -47,7 +47,7 @@ os_dumps_proc_mem_info(char *out, unsigned int size) } void * -os_mmap(void *hint, size_t size, int prot, int flags) +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) { if ((uint64)size >= UINT32_MAX) return NULL; @@ -69,3 +69,7 @@ os_mprotect(void *addr, size_t size, int prot) void os_dcache_flush() {} + +void +os_icache_flush(void *start, size_t len) +{} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/alios_thread.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/alios_thread.c similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/alios_thread.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/alios_thread.c index 0efd2f39448..9fe927db0e7 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/alios_thread.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/alios_thread.c @@ -359,3 +359,7 @@ os_thread_get_stack_boundary() /* TODO: get alios stack boundary */ return NULL; } + +void +os_thread_jit_write_protect_np(bool enabled) +{} \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/alios_time.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/alios_time.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/alios_time.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/alios_time.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/platform_internal.h similarity index 78% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/platform_internal.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/platform_internal.h index f6a4ba11e83..d2897a6b599 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/platform_internal.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/platform_internal.h @@ -32,6 +32,12 @@ typedef aos_task_t *aos_tid_t; typedef aos_mutex_t korp_mutex; typedef aos_sem_t korp_sem; +/* korp_rwlock is used in platform_api_extension.h, + we just define the type to make the compiler happy */ +typedef struct { + int dummy; +} korp_rwlock; + struct os_thread_wait_node; typedef struct os_thread_wait_node *os_thread_wait_list; typedef struct korp_cond { @@ -64,4 +70,16 @@ int signbit(double x); int isnan(double x); /* clang-format on */ +/* The below types are used in platform_api_extension.h, + we just define them to make the compiler happy */ +typedef int os_file_handle; +typedef void *os_dir_stream; +typedef int os_raw_file_handle; + +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #endif /* end of _BH_PLATFORM_H */ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/shared_platform.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/alios/shared_platform.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/alios/shared_platform.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/android/platform_init.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/android/platform_init.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/android/platform_init.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/android/platform_init.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/android/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/android/platform_internal.h similarity index 93% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/android/platform_internal.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/android/platform_internal.h index 521fa0c555b..42e4e726c40 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/android/platform_internal.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/android/platform_internal.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,7 @@ typedef pthread_t korp_tid; typedef pthread_mutex_t korp_mutex; typedef pthread_cond_t korp_cond; typedef pthread_t korp_thread; +typedef pthread_rwlock_t korp_rwlock; typedef sem_t korp_sem; #define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER @@ -138,15 +140,21 @@ seekdir(DIR *__dir, long __location); #endif -#if __ANDROID_API__ < 24 - ssize_t preadv(int __fd, const struct iovec *__iov, int __count, off_t __offset); ssize_t pwritev(int __fd, const struct iovec *__iov, int __count, off_t __offset); -#endif +typedef int os_file_handle; +typedef DIR *os_dir_stream; +typedef int os_raw_file_handle; + +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} #ifdef __cplusplus } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/android/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/android/shared_platform.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/android/shared_platform.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/android/shared_platform.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/freertos/freertos_malloc.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/freertos/freertos_malloc.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/freertos/freertos_malloc.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/freertos/freertos_malloc.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/freertos/freertos_thread.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/freertos/freertos_thread.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/freertos/freertos_thread.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/freertos/freertos_thread.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/freertos/freertos_time.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/freertos/freertos_time.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/freertos/freertos_time.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/freertos/freertos_time.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/freertos/platform_api_freertos.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/freertos/platform_api_freertos.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/freertos/platform_api_freertos.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/freertos/platform_api_freertos.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/libc_errno.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/libc_errno.c new file mode 100644 index 00000000000..e6c26c839a5 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/libc_errno.c @@ -0,0 +1,256 @@ +/* + * Copyright (C) 2023 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "errno.h" +#include "libc_errno.h" + +__wasi_errno_t +convert_errno(int error) +{ + // The C standard library only requires EDOM, EILSEQ and ERANGE to be + // defined. Other error codes are POSIX-specific and hence may or may + // not be available on non-POSIX platforms. + __wasi_errno_t code = __WASI_ENOSYS; +#define X(v) \ + case v: \ + code = __WASI_##v; \ + break; + switch (error) { + X(EDOM) + X(EILSEQ) + X(ERANGE) +#ifdef E2BIG + X(E2BIG) +#endif +#ifdef EACCES + X(EACCES) +#endif +#ifdef EADDRINUSE + X(EADDRINUSE) +#endif +#ifdef EADDRNOTAVAIL + X(EADDRNOTAVAIL) +#endif +#ifdef EAFNOSUPPORT + X(EAFNOSUPPORT) +#endif +#ifdef EAGAIN + X(EAGAIN) +#endif +#ifdef EALREADY + X(EALREADY) +#endif +#ifdef EBADF + X(EBADF) +#endif +#ifdef EBADMSG + X(EBADMSG) +#endif +#ifdef EBUSY + X(EBUSY) +#endif +#ifdef ECANCELED + X(ECANCELED) +#endif +#ifdef ECHILD + X(ECHILD) +#endif +#ifdef ECONNABORTED + X(ECONNABORTED) +#endif +#ifdef ECONNREFUSED + X(ECONNREFUSED) +#endif +#ifdef ECONNRESET + X(ECONNRESET) +#endif +#ifdef EDEADLK + X(EDEADLK) +#endif +#ifdef EDESTADDRREQ + X(EDESTADDRREQ) +#endif +#ifdef EDQUOT + X(EDQUOT) +#endif +#ifdef EEXIST + X(EEXIST) +#endif +#ifdef EFAULT + X(EFAULT) +#endif +#ifdef EFBIG + X(EFBIG) +#endif +#ifdef EHOSTUNREACH + X(EHOSTUNREACH) +#endif +#ifdef EIDRM + X(EIDRM) +#endif +#ifdef EINPROGRESS + X(EINPROGRESS) +#endif +#ifdef EINTR + X(EINTR) +#endif +#ifdef EINVAL + X(EINVAL) +#endif +#ifdef EIO + X(EIO) +#endif +#ifdef EISCONN + X(EISCONN) +#endif +#ifdef EISDIR + X(EISDIR) +#endif +#ifdef ELOOP + X(ELOOP) +#endif +#ifdef EMFILE + X(EMFILE) +#endif +#ifdef EMLINK + X(EMLINK) +#endif +#ifdef EMSGSIZE + X(EMSGSIZE) +#endif +#ifdef EMULTIHOP + X(EMULTIHOP) +#endif +#ifdef ENAMETOOLONG + X(ENAMETOOLONG) +#endif +#ifdef ENETDOWN + X(ENETDOWN) +#endif +#ifdef ENETRESET + X(ENETRESET) +#endif +#ifdef ENETUNREACH + X(ENETUNREACH) +#endif +#ifdef ENFILE + X(ENFILE) +#endif +#ifdef ENOBUFS + X(ENOBUFS) +#endif +#ifdef ENODEV + X(ENODEV) +#endif +#ifdef ENOENT + X(ENOENT) +#endif +#ifdef ENOEXEC + X(ENOEXEC) +#endif +#ifdef ENOLCK + X(ENOLCK) +#endif +#ifdef ENOLINK + X(ENOLINK) +#endif +#ifdef ENOMEM + X(ENOMEM) +#endif +#ifdef ENOMSG + X(ENOMSG) +#endif +#ifdef ENOPROTOOPT + X(ENOPROTOOPT) +#endif +#ifdef ENOSPC + X(ENOSPC) +#endif +#ifdef ENOSYS + X(ENOSYS) +#endif +#ifdef ENOTCAPABLE + X(ENOTCAPABLE) +#endif +#ifdef ENOTCONN + X(ENOTCONN) +#endif +#ifdef ENOTDIR + X(ENOTDIR) +#endif +#ifdef ENOTEMPTY + X(ENOTEMPTY) +#endif +#ifdef ENOTRECOVERABLE + X(ENOTRECOVERABLE) +#endif +#ifdef ENOTSOCK + X(ENOTSOCK) +#endif +#ifdef ENOTSUP + X(ENOTSUP) +#endif +#ifdef ENOTTY + X(ENOTTY) +#endif +#ifdef ENXIO + X(ENXIO) +#endif +#ifdef EOVERFLOW + X(EOVERFLOW) +#endif +#ifdef EOWNERDEAD + X(EOWNERDEAD) +#endif +#ifdef EPERM + X(EPERM) +#endif +#ifdef EPIPE + X(EPIPE) +#endif +#ifdef EPROTO + X(EPROTO) +#endif +#ifdef EPROTONOSUPPORT + X(EPROTONOSUPPORT) +#endif +#ifdef EPROTOTYPE + X(EPROTOTYPE) +#endif +#ifdef EROFS + X(EROFS) +#endif +#ifdef ESPIPE + X(ESPIPE) +#endif +#ifdef ESRCH + X(ESRCH) +#endif +#ifdef ESTALE + X(ESTALE) +#endif +#ifdef ETIMEDOUT + X(ETIMEDOUT) +#endif +#ifdef ETXTBSY + X(ETXTBSY) +#endif +#ifdef EXDEV + X(EXDEV) +#endif + default: +#ifdef EOPNOTSUPP + if (error == EOPNOTSUPP) + code = __WASI_ENOTSUP; +#endif +#ifdef EWOULDBLOCK + if (error == EWOULDBLOCK) + code = __WASI_EAGAIN; +#endif + break; + } +#undef X + return code; +} \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/libc_errno.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/libc_errno.h new file mode 100644 index 00000000000..b0a8b78c6af --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/libc_errno.h @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2023 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#ifndef WASI_ERRNO_H +#define WASI_ERRNO_H + +#include "platform_wasi_types.h" + +// Converts an errno error code to a WASI error code. +__wasi_errno_t +convert_errno(int error); + +#endif /* end of WASI_ERRNO_H */ \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/platform_common_libc_util.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/platform_common_libc_util.cmake new file mode 100644 index 00000000000..a7c7645ce3d --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/libc-util/platform_common_libc_util.cmake @@ -0,0 +1,8 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +set (PLATFORM_COMMON_LIBC_UTIL_DIR ${CMAKE_CURRENT_LIST_DIR}) + +include_directories(${PLATFORM_COMMON_LIBC_UTIL_DIR}) + +file (GLOB_RECURSE PLATFORM_COMMON_LIBC_UTIL_SOURCE ${PLATFORM_COMMON_LIBC_UTIL_DIR}/*.c) \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/math/COPYRIGHT b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/math/COPYRIGHT similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/math/COPYRIGHT rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/math/COPYRIGHT diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/math/math.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/math/math.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/math/math.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/math/math.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/math/platform_api_math.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/math/platform_api_math.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/math/platform_api_math.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/math/platform_api_math.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/platform_api_posix.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/platform_api_posix.cmake new file mode 100644 index 00000000000..2bf9fab4afa --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/platform_api_posix.cmake @@ -0,0 +1,19 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +set (PLATFORM_COMMON_POSIX_DIR ${CMAKE_CURRENT_LIST_DIR}) + +file (GLOB_RECURSE source_all ${PLATFORM_COMMON_POSIX_DIR}/*.c) + +if (NOT WAMR_BUILD_LIBC_WASI EQUAL 1) + list(REMOVE_ITEM source_all + ${PLATFORM_COMMON_POSIX_DIR}/posix_file.c + ${PLATFORM_COMMON_POSIX_DIR}/posix_clock.c + ${PLATFORM_COMMON_POSIX_DIR}/posix_socket.c + ) +else() + include (${CMAKE_CURRENT_LIST_DIR}/../libc-util/platform_common_libc_util.cmake) + set(source_all ${source_all} ${PLATFORM_COMMON_LIBC_UTIL_SOURCE}) +endif() + +set (PLATFORM_COMMON_POSIX_SOURCE ${source_all} ) diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_blocking_op.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_blocking_op.c new file mode 100644 index 00000000000..560828a06eb --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_blocking_op.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2023 Midokura Japan KK. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "platform_api_extension.h" + +#ifdef OS_ENABLE_WAKEUP_BLOCKING_OP + +static bool g_blocking_op_inited = false; +static int g_blocking_op_signo = SIGUSR1; +static sigset_t g_blocking_op_sigmask; + +static void +blocking_op_sighandler(int signo) +{ + /* nothing */ +} + +void +os_set_signal_number_for_blocking_op(int signo) +{ + g_blocking_op_signo = signo; +} + +int +os_blocking_op_init() +{ + if (g_blocking_op_inited) { + return BHT_OK; + } + + sigemptyset(&g_blocking_op_sigmask); + sigaddset(&g_blocking_op_sigmask, g_blocking_op_signo); + + struct sigaction sa; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sa.sa_handler = blocking_op_sighandler; + if (sigaction(g_blocking_op_signo, &sa, NULL)) { + return BHT_ERROR; + } + g_blocking_op_inited = true; + return BHT_OK; +} + +void +os_begin_blocking_op() +{ + pthread_sigmask(SIG_UNBLOCK, &g_blocking_op_sigmask, NULL); +} + +void +os_end_blocking_op() +{ + pthread_sigmask(SIG_BLOCK, &g_blocking_op_sigmask, NULL); +} + +int +os_wakeup_blocking_op(korp_tid tid) +{ + int ret = pthread_kill(tid, g_blocking_op_signo); + if (ret != 0) { + return BHT_ERROR; + } + return BHT_OK; +} + +#endif /* OS_ENABLE_WAKEUP_BLOCKING_OP */ diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_clock.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_clock.c new file mode 100644 index 00000000000..280306c422c --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_clock.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2023 Amazon Inc. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "libc_errno.h" +#include "platform_api_extension.h" + +#define NANOSECONDS_PER_SECOND 1000000000ULL + +static __wasi_errno_t +wasi_clockid_to_clockid(__wasi_clockid_t in, clockid_t *out) +{ + switch (in) { + case __WASI_CLOCK_MONOTONIC: + *out = CLOCK_MONOTONIC; + return __WASI_ESUCCESS; + case __WASI_CLOCK_REALTIME: + *out = CLOCK_REALTIME; + return __WASI_ESUCCESS; + case __WASI_CLOCK_PROCESS_CPUTIME_ID: +#if defined(CLOCK_PROCESS_CPUTIME_ID) + *out = CLOCK_PROCESS_CPUTIME_ID; + return __WASI_ESUCCESS; +#else + return __WASI_ENOTSUP; +#endif + case __WASI_CLOCK_THREAD_CPUTIME_ID: +#if defined(CLOCK_THREAD_CPUTIME_ID) + *out = CLOCK_THREAD_CPUTIME_ID; + return __WASI_ESUCCESS; +#else + return __WASI_ENOTSUP; +#endif + default: + return __WASI_EINVAL; + } +} + +static __wasi_timestamp_t +timespec_to_nanoseconds(const struct timespec *ts) +{ + if (ts->tv_sec < 0) + return 0; + if ((__wasi_timestamp_t)ts->tv_sec >= UINT64_MAX / NANOSECONDS_PER_SECOND) + return UINT64_MAX; + return (__wasi_timestamp_t)ts->tv_sec * NANOSECONDS_PER_SECOND + + (__wasi_timestamp_t)ts->tv_nsec; +} + +__wasi_errno_t +os_clock_res_get(__wasi_clockid_t clock_id, __wasi_timestamp_t *resolution) +{ + clockid_t nclock_id; + __wasi_errno_t error = wasi_clockid_to_clockid(clock_id, &nclock_id); + + if (error != __WASI_ESUCCESS) + return error; + + struct timespec ts; + if (clock_getres(nclock_id, &ts) < 0) + return convert_errno(errno); + + *resolution = timespec_to_nanoseconds(&ts); + + return error; +} + +__wasi_errno_t +os_clock_time_get(__wasi_clockid_t clock_id, __wasi_timestamp_t precision, + __wasi_timestamp_t *time) +{ + clockid_t nclock_id; + __wasi_errno_t error = wasi_clockid_to_clockid(clock_id, &nclock_id); + + if (error != __WASI_ESUCCESS) + return error; + + struct timespec ts; + if (clock_gettime(nclock_id, &ts) < 0) + return convert_errno(errno); + + *time = timespec_to_nanoseconds(&ts); + + return error; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_file.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_file.c new file mode 100644 index 00000000000..8c4f7aa9d24 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_file.c @@ -0,0 +1,1007 @@ +/* + * Copyright (C) 2023 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "platform_api_extension.h" +#include "libc_errno.h" +#include + +#if !defined(__APPLE__) && !defined(ESP_PLATFORM) +#define CONFIG_HAS_PWRITEV 1 +#define CONFIG_HAS_PREADV 1 +#else +#define CONFIG_HAS_PWRITEV 0 +#define CONFIG_HAS_PREADV 0 +#endif + +#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(ESP_PLATFORM) +#define CONFIG_HAS_FDATASYNC 1 +#else +#define CONFIG_HAS_FDATASYNC 0 +#endif + +/* + * For NuttX, CONFIG_HAS_ISATTY is provided by its platform header. + * (platform_internal.h) + */ +#if !defined(__NuttX__) +#define CONFIG_HAS_D_INO 1 +#define CONFIG_HAS_ISATTY 1 +#else +#define CONFIG_HAS_D_INO 0 +#endif + +#if !defined(__APPLE__) && !defined(ESP_PLATFORM) && !defined(__COSMOPOLITAN__) +#define CONFIG_HAS_POSIX_FALLOCATE 1 +#else +#define CONFIG_HAS_POSIX_FALLOCATE 0 +#endif + +#if defined(O_DSYNC) +#define CONFIG_HAS_O_DSYNC +#endif + +// POSIX requires O_RSYNC to be defined, but Linux explicitly doesn't support +// it. +#if defined(O_RSYNC) && !defined(__linux__) +#define CONFIG_HAS_O_RSYNC +#endif + +#if defined(O_SYNC) +#define CONFIG_HAS_O_SYNC +#endif + +// Converts a POSIX timespec to a WASI timestamp. +static __wasi_timestamp_t +convert_timespec(const struct timespec *ts) +{ + if (ts->tv_sec < 0) + return 0; + if ((__wasi_timestamp_t)ts->tv_sec >= UINT64_MAX / 1000000000) + return UINT64_MAX; + return (__wasi_timestamp_t)ts->tv_sec * 1000000000 + + (__wasi_timestamp_t)ts->tv_nsec; +} + +// Converts a POSIX stat structure to a WASI filestat structure +static void +convert_stat(os_file_handle handle, const struct stat *in, + __wasi_filestat_t *out) +{ + out->st_dev = in->st_dev; + out->st_ino = in->st_ino; + out->st_nlink = (__wasi_linkcount_t)in->st_nlink; + out->st_size = (__wasi_filesize_t)in->st_size; +#ifdef __APPLE__ + out->st_atim = convert_timespec(&in->st_atimespec); + out->st_mtim = convert_timespec(&in->st_mtimespec); + out->st_ctim = convert_timespec(&in->st_ctimespec); +#else + out->st_atim = convert_timespec(&in->st_atim); + out->st_mtim = convert_timespec(&in->st_mtim); + out->st_ctim = convert_timespec(&in->st_ctim); +#endif + + // Convert the file type. In the case of sockets there is no way we + // can easily determine the exact socket type. + if (S_ISBLK(in->st_mode)) { + out->st_filetype = __WASI_FILETYPE_BLOCK_DEVICE; + } + else if (S_ISCHR(in->st_mode)) { + out->st_filetype = __WASI_FILETYPE_CHARACTER_DEVICE; + } + else if (S_ISDIR(in->st_mode)) { + out->st_filetype = __WASI_FILETYPE_DIRECTORY; + } + else if (S_ISFIFO(in->st_mode)) { + out->st_filetype = __WASI_FILETYPE_SOCKET_STREAM; + } + else if (S_ISLNK(in->st_mode)) { + out->st_filetype = __WASI_FILETYPE_SYMBOLIC_LINK; + } + else if (S_ISREG(in->st_mode)) { + out->st_filetype = __WASI_FILETYPE_REGULAR_FILE; + } + else if (S_ISSOCK(in->st_mode)) { + int socktype; + socklen_t socktypelen = sizeof(socktype); + + if (getsockopt(handle, SOL_SOCKET, SO_TYPE, &socktype, &socktypelen) + < 0) { + out->st_filetype = __WASI_FILETYPE_UNKNOWN; + return; + } + + switch (socktype) { + case SOCK_DGRAM: + out->st_filetype = __WASI_FILETYPE_SOCKET_DGRAM; + break; + case SOCK_STREAM: + out->st_filetype = __WASI_FILETYPE_SOCKET_STREAM; + break; + default: + out->st_filetype = __WASI_FILETYPE_UNKNOWN; + return; + } + } + else { + out->st_filetype = __WASI_FILETYPE_UNKNOWN; + } +} + +static void +convert_timestamp(__wasi_timestamp_t in, struct timespec *out) +{ + // Store sub-second remainder. +#if defined(__SYSCALL_SLONG_TYPE) + out->tv_nsec = (__SYSCALL_SLONG_TYPE)(in % 1000000000); +#else + out->tv_nsec = (long)(in % 1000000000); +#endif + in /= 1000000000; + + // Clamp to the maximum in case it would overflow our system's time_t. + out->tv_sec = (time_t)in < BH_TIME_T_MAX ? (time_t)in : BH_TIME_T_MAX; +} + +// Converts the provided timestamps and flags to a set of arguments for +// futimens() and utimensat(). +static void +convert_utimens_arguments(__wasi_timestamp_t st_atim, + __wasi_timestamp_t st_mtim, + __wasi_fstflags_t fstflags, struct timespec *ts) +{ + if ((fstflags & __WASI_FILESTAT_SET_ATIM_NOW) != 0) { + ts[0].tv_nsec = UTIME_NOW; + } + else if ((fstflags & __WASI_FILESTAT_SET_ATIM) != 0) { + convert_timestamp(st_atim, &ts[0]); + } + else { + ts[0].tv_nsec = UTIME_OMIT; + } + + if ((fstflags & __WASI_FILESTAT_SET_MTIM_NOW) != 0) { + ts[1].tv_nsec = UTIME_NOW; + } + else if ((fstflags & __WASI_FILESTAT_SET_MTIM) != 0) { + convert_timestamp(st_mtim, &ts[1]); + } + else { + ts[1].tv_nsec = UTIME_OMIT; + } +} + +__wasi_errno_t +os_fstat(os_file_handle handle, struct __wasi_filestat_t *buf) +{ + struct stat stat_buf; + int ret = fstat(handle, &stat_buf); + + if (ret < 0) + return convert_errno(errno); + + convert_stat(handle, &stat_buf, buf); + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_fstatat(os_file_handle handle, const char *path, + struct __wasi_filestat_t *buf, __wasi_lookupflags_t lookup_flags) +{ + struct stat stat_buf; + int ret = fstatat(handle, path, &stat_buf, + (lookup_flags & __WASI_LOOKUP_SYMLINK_FOLLOW) + ? AT_SYMLINK_FOLLOW + : AT_SYMLINK_NOFOLLOW); + + if (ret < 0) + return convert_errno(errno); + + convert_stat(handle, &stat_buf, buf); + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_file_get_fdflags(os_file_handle handle, __wasi_fdflags_t *flags) +{ + int ret = fcntl(handle, F_GETFL); + + if (ret < 0) + return convert_errno(errno); + + *flags = 0; + + if ((ret & O_APPEND) != 0) + *flags |= __WASI_FDFLAG_APPEND; +#ifdef CONFIG_HAS_O_DSYNC + if ((ret & O_DSYNC) != 0) + *flags |= __WASI_FDFLAG_DSYNC; +#endif + if ((ret & O_NONBLOCK) != 0) + *flags |= __WASI_FDFLAG_NONBLOCK; +#ifdef CONFIG_HAS_O_RSYNC + if ((ret & O_RSYNC) != 0) + *flags |= __WASI_FDFLAG_RSYNC; +#endif +#ifdef CONFIG_HAS_O_SYNC + if ((ret & O_SYNC) != 0) + *flags |= __WASI_FDFLAG_SYNC; +#endif + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_file_set_fdflags(os_file_handle handle, __wasi_fdflags_t flags) +{ + int fcntl_flags = 0; + + if ((flags & __WASI_FDFLAG_APPEND) != 0) + fcntl_flags |= O_APPEND; + if ((flags & __WASI_FDFLAG_DSYNC) != 0) +#ifdef CONFIG_HAS_O_DSYNC + fcntl_flags |= O_DSYNC; +#else + return __WASI_ENOTSUP; +#endif + if ((flags & __WASI_FDFLAG_NONBLOCK) != 0) + fcntl_flags |= O_NONBLOCK; + if ((flags & __WASI_FDFLAG_RSYNC) != 0) +#ifdef CONFIG_HAS_O_RSYNC + fcntl_flags |= O_RSYNC; +#else + return __WASI_ENOTSUP; +#endif + if ((flags & __WASI_FDFLAG_SYNC) != 0) +#ifdef CONFIG_HAS_O_SYNC + fcntl_flags |= O_SYNC; +#else + return __WASI_ENOTSUP; +#endif + + int ret = fcntl(handle, F_SETFL, fcntl_flags); + + if (ret < 0) + return convert_errno(errno); + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_fdatasync(os_file_handle handle) +{ +#if CONFIG_HAS_FDATASYNC + int ret = fdatasync(handle); +#else + int ret = fsync(handle); +#endif + + if (ret < 0) + return convert_errno(errno); + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_fsync(os_file_handle handle) +{ + int ret = fsync(handle); + + if (ret < 0) + return convert_errno(errno); + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_open_preopendir(const char *path, os_file_handle *out) +{ + + int fd = open(path, O_RDONLY | O_DIRECTORY, 0); + + if (fd < 0) + return convert_errno(errno); + + *out = fd; + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_openat(os_file_handle handle, const char *path, __wasi_oflags_t oflags, + __wasi_fdflags_t fs_flags, __wasi_lookupflags_t lookup_flags, + wasi_libc_file_access_mode read_write_mode, os_file_handle *out) +{ + int open_flags = 0; + + // Convert open flags. + if ((oflags & __WASI_O_CREAT) != 0) { + open_flags |= O_CREAT; + } + if ((oflags & __WASI_O_DIRECTORY) != 0) + open_flags |= O_DIRECTORY; + if ((oflags & __WASI_O_EXCL) != 0) + open_flags |= O_EXCL; + if ((oflags & __WASI_O_TRUNC) != 0) { + open_flags |= O_TRUNC; + } + + // Convert file descriptor flags. + if ((fs_flags & __WASI_FDFLAG_APPEND) != 0) + open_flags |= O_APPEND; + if ((fs_flags & __WASI_FDFLAG_DSYNC) != 0) { +#ifdef CONFIG_HAS_O_DSYNC + open_flags |= O_DSYNC; +#else + return __WASI_ENOTSUP; +#endif + } + if ((fs_flags & __WASI_FDFLAG_NONBLOCK) != 0) + open_flags |= O_NONBLOCK; + if ((fs_flags & __WASI_FDFLAG_RSYNC) != 0) { +#ifdef CONFIG_HAS_O_RSYNC + open_flags |= O_RSYNC; +#else + return __WASI_ENOTSUP; +#endif + } + if ((fs_flags & __WASI_FDFLAG_SYNC) != 0) { +#ifdef CONFIG_HAS_O_SYNC + open_flags |= O_SYNC; +#else + return __WASI_ENOTSUP; +#endif + } + + if ((lookup_flags & __WASI_LOOKUP_SYMLINK_FOLLOW) == 0) { + open_flags |= O_NOFOLLOW; + } + + switch (read_write_mode) { + case WASI_LIBC_ACCESS_MODE_READ_WRITE: + open_flags |= O_RDWR; + break; + case WASI_LIBC_ACCESS_MODE_READ_ONLY: + open_flags |= O_RDONLY; + break; + case WASI_LIBC_ACCESS_MODE_WRITE_ONLY: + open_flags |= O_WRONLY; + break; + default: + return __WASI_EINVAL; + } + + int fd = openat(handle, path, open_flags, 0666); + + if (fd < 0) { + int openat_errno = errno; + // Linux returns ENXIO instead of EOPNOTSUPP when opening a socket. + if (openat_errno == ENXIO) { + struct stat sb; + int ret = fstatat(fd, path, &sb, + (lookup_flags & __WASI_LOOKUP_SYMLINK_FOLLOW) + ? 0 + : AT_SYMLINK_NOFOLLOW); + return ret == 0 && S_ISSOCK(sb.st_mode) ? __WASI_ENOTSUP + : __WASI_ENXIO; + } + // Linux returns ENOTDIR instead of ELOOP when using + // O_NOFOLLOW|O_DIRECTORY on a symlink. + if (openat_errno == ENOTDIR + && (open_flags & (O_NOFOLLOW | O_DIRECTORY)) != 0) { + struct stat sb; + int ret = fstatat(fd, path, &sb, AT_SYMLINK_NOFOLLOW); + if (S_ISLNK(sb.st_mode)) { + return __WASI_ELOOP; + } + (void)ret; + } + // FreeBSD returns EMLINK instead of ELOOP when using O_NOFOLLOW on + // a symlink. + if ((lookup_flags & __WASI_LOOKUP_SYMLINK_FOLLOW) == 0 + && openat_errno == EMLINK) + return __WASI_ELOOP; + + return convert_errno(openat_errno); + } + + *out = fd; + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_file_get_access_mode(os_file_handle handle, + wasi_libc_file_access_mode *access_mode) +{ + int ret = fcntl(handle, F_GETFL, 0); + + if (ret < 0) + return convert_errno(errno); + + switch (ret & O_ACCMODE) { + case O_RDONLY: + *access_mode = WASI_LIBC_ACCESS_MODE_READ_ONLY; + break; + case O_WRONLY: + *access_mode = WASI_LIBC_ACCESS_MODE_WRITE_ONLY; + break; + case O_RDWR: + *access_mode = WASI_LIBC_ACCESS_MODE_READ_WRITE; + break; + default: + return __WASI_EINVAL; + } + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_close(os_file_handle handle, bool is_stdio) +{ + if (is_stdio) + return __WASI_ESUCCESS; + + int ret = close(handle); + + if (ret < 0) + return convert_errno(errno); + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_preadv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt, + __wasi_filesize_t offset, size_t *nread) +{ +#if CONFIG_HAS_PREADV + ssize_t len = + preadv(handle, (const struct iovec *)iov, (int)iovcnt, (off_t)offset); + if (len < 0) + return convert_errno(errno); + + *nread = (size_t)len; + return __WASI_ESUCCESS; +#else + if (iovcnt == 1) { + ssize_t len = pread(handle, iov->buf, iov->buf_len, offset); + + if (len < 0) + return convert_errno(errno); + + *nread = len; + return __WASI_ESUCCESS; + } + + // Allocate a single buffer to fit all data. + size_t totalsize = 0; + for (int i = 0; i < iovcnt; ++i) + totalsize += iov[i].buf_len; + + char *buf = BH_MALLOC(totalsize); + + if (buf == NULL) { + return __WASI_ENOMEM; + } + + // Perform a single read operation. + ssize_t len = pread(handle, buf, totalsize, offset); + + if (len < 0) { + BH_FREE(buf); + return convert_errno(errno); + } + + // Copy data back to vectors. + size_t bufoff = 0; + for (int i = 0; i < iovcnt; ++i) { + if (bufoff + iov[i].buf_len < (size_t)len) { + memcpy(iov[i].buf, buf + bufoff, iov[i].buf_len); + bufoff += iov[i].buf_len; + } + else { + memcpy(iov[i].buf, buf + bufoff, len - bufoff); + break; + } + } + BH_FREE(buf); + *nread = len; + + return __WASI_ESUCCESS; +#endif +} + +__wasi_errno_t +os_pwritev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt, + __wasi_filesize_t offset, size_t *nwritten) +{ + if (iovcnt == 0) + return __WASI_EINVAL; + + ssize_t len = 0; +#if CONFIG_HAS_PWRITEV + len = + pwritev(handle, (const struct iovec *)iov, (int)iovcnt, (off_t)offset); +#else + if (iovcnt == 1) { + len = pwrite(handle, iov->buf, iov->buf_len, offset); + } + else { + // Allocate a single buffer to fit all data. + size_t totalsize = 0; + for (int i = 0; i < iovcnt; ++i) + totalsize += iov[i].buf_len; + char *buf = BH_MALLOC(totalsize); + if (buf == NULL) { + return __WASI_ENOMEM; + } + size_t bufoff = 0; + for (int i = 0; i < iovcnt; ++i) { + memcpy(buf + bufoff, iov[i].buf, iov[i].buf_len); + bufoff += iov[i].buf_len; + } + + // Perform a single write operation. + len = pwrite(handle, buf, totalsize, offset); + BH_FREE(buf); + } +#endif + if (len < 0) + return convert_errno(errno); + + *nwritten = (size_t)len; + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_readv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt, + size_t *nread) +{ + ssize_t len = readv(handle, (const struct iovec *)iov, (int)iovcnt); + + if (len < 0) + return convert_errno(errno); + + *nread = (size_t)len; + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_writev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt, + size_t *nwritten) +{ + ssize_t len = writev(handle, (const struct iovec *)iov, (int)iovcnt); + + if (len < 0) + return convert_errno(errno); + + *nwritten = (size_t)len; + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_fallocate(os_file_handle handle, __wasi_filesize_t offset, + __wasi_filesize_t length) +{ +#if CONFIG_HAS_POSIX_FALLOCATE + int ret = posix_fallocate(handle, (off_t)offset, (off_t)length); +#else + // At least ensure that the file is grown to the right size. + // TODO(ed): See if this can somehow be implemented without any race + // conditions. We may end up shrinking the file right now. + struct stat sb; + int ret = fstat(handle, &sb); + off_t newsize = (off_t)(offset + length); + + if (ret == 0 && sb.st_size < newsize) + ret = ftruncate(handle, newsize); +#endif + + if (ret != 0) + return convert_errno(ret); + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_ftruncate(os_file_handle handle, __wasi_filesize_t size) +{ + int ret = ftruncate(handle, (off_t)size); + + if (ret < 0) + return convert_errno(errno); + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_futimens(os_file_handle handle, __wasi_timestamp_t access_time, + __wasi_timestamp_t modification_time, __wasi_fstflags_t fstflags) +{ + struct timespec ts[2]; + convert_utimens_arguments(access_time, modification_time, fstflags, ts); + + int ret = futimens(handle, ts); + + if (ret < 0) + return convert_errno(errno); + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_utimensat(os_file_handle handle, const char *path, + __wasi_timestamp_t access_time, + __wasi_timestamp_t modification_time, __wasi_fstflags_t fstflags, + __wasi_lookupflags_t lookup_flags) +{ + struct timespec ts[2]; + convert_utimens_arguments(access_time, modification_time, fstflags, ts); + + int ret = utimensat(handle, path, ts, + (lookup_flags & __WASI_LOOKUP_SYMLINK_FOLLOW) + ? 0 + : AT_SYMLINK_NOFOLLOW); + + if (ret < 0) + return convert_errno(errno); + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_readlinkat(os_file_handle handle, const char *path, char *buf, + size_t bufsize, size_t *nread) +{ + // Linux requires that the buffer size is positive. whereas POSIX does + // not. Use a fake buffer to store the results if the size is zero. + char fakebuf[1]; + ssize_t len = readlinkat(handle, path, bufsize == 0 ? fakebuf : buf, + bufsize == 0 ? sizeof(fakebuf) : bufsize); + + if (len < 0) + return convert_errno(errno); + + *nread = (size_t)len < bufsize ? (size_t)len : bufsize; + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_linkat(os_file_handle from_handle, const char *from_path, + os_file_handle to_handle, const char *to_path, + __wasi_lookupflags_t lookup_flags) +{ + int ret = linkat( + from_handle, from_path, to_handle, to_path, + (lookup_flags & __WASI_LOOKUP_SYMLINK_FOLLOW) ? AT_SYMLINK_FOLLOW : 0); + + if (ret < 0) + return convert_errno(errno); + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_symlinkat(const char *old_path, os_file_handle handle, const char *new_path) +{ + int ret = symlinkat(old_path, handle, new_path); + + if (ret < 0) + return convert_errno(errno); + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_mkdirat(os_file_handle handle, const char *path) +{ + int ret = mkdirat(handle, path, 0777); + + if (ret < 0) + return convert_errno(errno); + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_renameat(os_file_handle old_handle, const char *old_path, + os_file_handle new_handle, const char *new_path) +{ + + int ret = renameat(old_handle, old_path, new_handle, new_path); + + if (ret < 0) + return convert_errno(errno); + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_unlinkat(os_file_handle handle, const char *path, bool is_dir) +{ + int ret = unlinkat(handle, path, is_dir ? AT_REMOVEDIR : 0); + +#ifndef __linux__ + if (ret < 0) { + // Non-Linux implementations may return EPERM when attempting to remove + // a directory without REMOVEDIR. While that's what POSIX specifies, + // it's less useful. Adjust this to EISDIR. It doesn't matter that this + // is not atomic with the unlinkat, because if the file is removed and a + // directory is created before fstatat sees it, we're racing with that + // change anyway and unlinkat could have legitimately seen the directory + // if the race had turned out differently. + if (errno == EPERM) { + struct stat statbuf; + if (fstatat(handle, path, &statbuf, AT_SYMLINK_NOFOLLOW) == 0 + && S_ISDIR(statbuf.st_mode)) { + errno = EISDIR; + } + } + // POSIX permits either EEXIST or ENOTEMPTY when the directory is not + // empty. Map it to ENOTEMPTY. + else if (errno == EEXIST) { + errno = ENOTEMPTY; + } + + return convert_errno(errno); + } +#endif + + if (ret < 0) + return convert_errno(errno); + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_lseek(os_file_handle handle, __wasi_filedelta_t offset, + __wasi_whence_t whence, __wasi_filesize_t *new_offset) +{ + int nwhence; + + switch (whence) { + case __WASI_WHENCE_CUR: + nwhence = SEEK_CUR; + break; + case __WASI_WHENCE_END: + nwhence = SEEK_END; + break; + case __WASI_WHENCE_SET: + nwhence = SEEK_SET; + break; + default: + return __WASI_EINVAL; + } + + off_t ret = lseek(handle, offset, nwhence); + + if (ret < 0) + return convert_errno(errno); + + *new_offset = (__wasi_filesize_t)ret; + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_fadvise(os_file_handle handle, __wasi_filesize_t offset, + __wasi_filesize_t length, __wasi_advice_t advice) +{ +#ifdef POSIX_FADV_NORMAL + int nadvice; + switch (advice) { + case __WASI_ADVICE_DONTNEED: + nadvice = POSIX_FADV_DONTNEED; + break; + case __WASI_ADVICE_NOREUSE: + nadvice = POSIX_FADV_NOREUSE; + break; + case __WASI_ADVICE_NORMAL: + nadvice = POSIX_FADV_NORMAL; + break; + case __WASI_ADVICE_RANDOM: + nadvice = POSIX_FADV_RANDOM; + break; + case __WASI_ADVICE_SEQUENTIAL: + nadvice = POSIX_FADV_SEQUENTIAL; + break; + case __WASI_ADVICE_WILLNEED: + nadvice = POSIX_FADV_WILLNEED; + break; + default: + return __WASI_EINVAL; + } + + int ret = posix_fadvise(handle, (off_t)offset, (off_t)length, nadvice); + + if (ret < 0) + return convert_errno(ret); + + return __WASI_ESUCCESS; +#else + // Advisory information can be safely ignored if not supported + switch (advice) { + case __WASI_ADVICE_DONTNEED: + case __WASI_ADVICE_NOREUSE: + case __WASI_ADVICE_NORMAL: + case __WASI_ADVICE_RANDOM: + case __WASI_ADVICE_SEQUENTIAL: + case __WASI_ADVICE_WILLNEED: + return __WASI_ESUCCESS; + default: + return __WASI_EINVAL; + } +#endif +} + +__wasi_errno_t +os_isatty(os_file_handle handle) +{ +#if CONFIG_HAS_ISATTY + int ret = isatty(handle); + + if (ret == 1) + return __WASI_ESUCCESS; + + return __WASI_ENOTTY; +#else + return __WASI_ENOTSUP; +#endif +} + +os_file_handle +os_convert_stdin_handle(os_raw_file_handle raw_stdin) +{ +#ifndef STDIN_FILENO +#define STDIN_FILENO 0 +#endif + return raw_stdin >= 0 ? raw_stdin : STDIN_FILENO; +} + +os_file_handle +os_convert_stdout_handle(os_raw_file_handle raw_stdout) +{ +#ifndef STDOUT_FILENO +#define STDOUT_FILENO 1 +#endif + return raw_stdout >= 0 ? raw_stdout : STDOUT_FILENO; +} + +os_file_handle +os_convert_stderr_handle(os_raw_file_handle raw_stderr) +{ +#ifndef STDERR_FILENO +#define STDERR_FILENO 2 +#endif + return raw_stderr >= 0 ? raw_stderr : STDERR_FILENO; +} + +__wasi_errno_t +os_fdopendir(os_file_handle handle, os_dir_stream *dir_stream) +{ + *dir_stream = fdopendir(handle); + + if (*dir_stream == NULL) + return convert_errno(errno); + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_rewinddir(os_dir_stream dir_stream) +{ + rewinddir(dir_stream); + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_seekdir(os_dir_stream dir_stream, __wasi_dircookie_t position) +{ + seekdir(dir_stream, (long)position); + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_readdir(os_dir_stream dir_stream, __wasi_dirent_t *entry, + const char **d_name) +{ + errno = 0; + + struct dirent *dent = readdir(dir_stream); + + if (dent == NULL) { + *d_name = NULL; + return convert_errno(errno); + } + + long offset = (__wasi_dircookie_t)telldir(dir_stream); + + size_t namlen = strlen(dent->d_name); + + *d_name = dent->d_name; + entry->d_next = offset; + entry->d_namlen = (__wasi_dirnamlen_t)namlen; +#if CONFIG_HAS_D_INO + entry->d_ino = dent->d_ino; +#else + entry->d_ino = 0; +#endif + + switch (dent->d_type) { + case DT_BLK: + entry->d_type = __WASI_FILETYPE_BLOCK_DEVICE; + break; + case DT_CHR: + entry->d_type = __WASI_FILETYPE_CHARACTER_DEVICE; + break; + case DT_DIR: + entry->d_type = __WASI_FILETYPE_DIRECTORY; + break; + case DT_FIFO: + entry->d_type = __WASI_FILETYPE_SOCKET_STREAM; + break; + case DT_LNK: + entry->d_type = __WASI_FILETYPE_SYMBOLIC_LINK; + break; + case DT_REG: + entry->d_type = __WASI_FILETYPE_REGULAR_FILE; + break; +#ifdef DT_SOCK + case DT_SOCK: + // Technically not correct, but good enough. + entry->d_type = __WASI_FILETYPE_SOCKET_STREAM; + break; +#endif + default: + entry->d_type = __WASI_FILETYPE_UNKNOWN; + break; + } + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_closedir(os_dir_stream dir_stream) +{ + int ret = closedir(dir_stream); + + if (ret < 0) + return convert_errno(errno); + + return __WASI_ESUCCESS; +} + +os_dir_stream +os_get_invalid_dir_stream() +{ + return NULL; +} + +bool +os_is_dir_stream_valid(os_dir_stream *dir_stream) +{ + assert(dir_stream != NULL); + + return *dir_stream != NULL; +} + +bool +os_is_handle_valid(os_file_handle *handle) +{ + assert(handle != NULL); + + return *handle > -1; +} + +char * +os_realpath(const char *path, char *resolved_path) +{ + return realpath(path, resolved_path); +} \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_malloc.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_malloc.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_malloc.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_malloc.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_memmap.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_memmap.c similarity index 93% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_memmap.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_memmap.c index 2dfbee453f7..583557bb855 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_memmap.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_memmap.c @@ -5,6 +5,10 @@ #include "platform_api_vmcore.h" +#if (defined(__APPLE__) || defined(__MACH__)) && defined(__arm64__) +#include +#endif + #ifndef BH_ENABLE_TRACE_MMAP #define BH_ENABLE_TRACE_MMAP 0 #endif @@ -33,10 +37,14 @@ round_down(uintptr_t v, uintptr_t b) #endif void * -os_mmap(void *hint, size_t size, int prot, int flags) +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) { int map_prot = PROT_NONE; +#if (defined(__APPLE__) || defined(__MACH__)) && defined(__arm64__) + int map_flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_JIT; +#else int map_flags = MAP_ANONYMOUS | MAP_PRIVATE; +#endif uint64 request_size, page_size; uint8 *addr = MAP_FAILED; uint32 i; @@ -106,7 +114,7 @@ os_mmap(void *hint, size_t size, int prot, int flags) /* try 10 times, step with 1MB each time */ for (i = 0; i < 10 && hint_addr < (uint8 *)(uintptr_t)(2ULL * BH_GB); i++) { - addr = mmap(hint_addr, request_size, map_prot, map_flags, -1, 0); + addr = mmap(hint_addr, request_size, map_prot, map_flags, file, 0); if (addr != MAP_FAILED) { if (addr > (uint8 *)(uintptr_t)(2ULL * BH_GB)) { /* unmap and try again if the mapped address doesn't @@ -128,7 +136,7 @@ os_mmap(void *hint, size_t size, int prot, int flags) if (addr == MAP_FAILED) { /* try 5 times */ for (i = 0; i < 5; i++) { - addr = mmap(hint, request_size, map_prot, map_flags, -1, 0); + addr = mmap(hint, request_size, map_prot, map_flags, file, 0); if (addr != MAP_FAILED) break; } @@ -251,3 +259,11 @@ os_mprotect(void *addr, size_t size, int prot) void os_dcache_flush(void) {} + +void +os_icache_flush(void *start, size_t len) +{ +#if (defined(__APPLE__) || defined(__MACH__)) && defined(__arm64__) + sys_icache_invalidate(start, len); +#endif +} diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_sleep.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_sleep.c new file mode 100644 index 00000000000..fa0645037a8 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_sleep.c @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2023 Midokura Japan KK. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include + +#include "platform_api_extension.h" + +int +os_usleep(uint32 usec) +{ + struct timespec ts; + int ret; + + ts.tv_sec = usec / 1000000; + ts.tv_nsec = (usec % 1000000) * 1000; + ret = nanosleep(&ts, NULL); + return ret == 0 ? 0 : -1; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_socket.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_socket.c similarity index 96% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_socket.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_socket.c index e33781d7d2e..7bdcb529e61 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_socket.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_socket.c @@ -5,6 +5,7 @@ #include "platform_api_vmcore.h" #include "platform_api_extension.h" +#include "libc_errno.h" #include #include @@ -53,7 +54,7 @@ sockaddr_to_bh_sockaddr(const struct sockaddr *sockaddr, struct sockaddr_in *addr = (struct sockaddr_in *)sockaddr; bh_sockaddr->port = ntohs(addr->sin_port); - bh_sockaddr->addr_bufer.ipv4 = ntohl(addr->sin_addr.s_addr); + bh_sockaddr->addr_buffer.ipv4 = ntohl(addr->sin_addr.s_addr); bh_sockaddr->is_ipv4 = true; return BHT_OK; } @@ -65,12 +66,12 @@ sockaddr_to_bh_sockaddr(const struct sockaddr *sockaddr, bh_sockaddr->port = ntohs(addr->sin6_port); - for (i = 0; i < sizeof(bh_sockaddr->addr_bufer.ipv6) - / sizeof(bh_sockaddr->addr_bufer.ipv6[0]); + for (i = 0; i < sizeof(bh_sockaddr->addr_buffer.ipv6) + / sizeof(bh_sockaddr->addr_buffer.ipv6[0]); i++) { uint16 part_addr = addr->sin6_addr.s6_addr[i * 2] | (addr->sin6_addr.s6_addr[i * 2 + 1] << 8); - bh_sockaddr->addr_bufer.ipv6[i] = ntohs(part_addr); + bh_sockaddr->addr_buffer.ipv6[i] = ntohs(part_addr); } bh_sockaddr->is_ipv4 = false; @@ -91,7 +92,7 @@ bh_sockaddr_to_sockaddr(const bh_sockaddr_t *bh_sockaddr, struct sockaddr_in *addr = (struct sockaddr_in *)sockaddr; addr->sin_port = htons(bh_sockaddr->port); addr->sin_family = AF_INET; - addr->sin_addr.s_addr = htonl(bh_sockaddr->addr_bufer.ipv4); + addr->sin_addr.s_addr = htonl(bh_sockaddr->addr_buffer.ipv4); *socklen = sizeof(*addr); } #ifdef IPPROTO_IPV6 @@ -101,10 +102,10 @@ bh_sockaddr_to_sockaddr(const bh_sockaddr_t *bh_sockaddr, addr->sin6_port = htons(bh_sockaddr->port); addr->sin6_family = AF_INET6; - for (i = 0; i < sizeof(bh_sockaddr->addr_bufer.ipv6) - / sizeof(bh_sockaddr->addr_bufer.ipv6[0]); + for (i = 0; i < sizeof(bh_sockaddr->addr_buffer.ipv6) + / sizeof(bh_sockaddr->addr_buffer.ipv6[0]); i++) { - uint16 part_addr = htons(bh_sockaddr->addr_bufer.ipv6[i]); + uint16 part_addr = htons(bh_sockaddr->addr_buffer.ipv6[i]); addr->sin6_addr.s6_addr[i * 2] = 0xff & part_addr; addr->sin6_addr.s6_addr[i * 2 + 1] = (0xff00 & part_addr) >> 8; } @@ -275,6 +276,9 @@ os_socket_recv_from(bh_socket_t socket, void *buf, unsigned int len, int flags, return -1; } } + else if (src_addr) { + memset(src_addr, 0, sizeof(*src_addr)); + } return ret; } @@ -305,11 +309,13 @@ os_socket_close(bh_socket_t socket) return BHT_OK; } -int +__wasi_errno_t os_socket_shutdown(bh_socket_t socket) { - shutdown(socket, O_RDWR); - return BHT_OK; + if (shutdown(socket, O_RDWR) != 0) { + return convert_errno(errno); + } + return __WASI_ESUCCESS; } int @@ -796,7 +802,7 @@ os_socket_set_ip_add_membership(bh_socket_t socket, { assert(imr_multiaddr); if (is_ipv6) { -#ifdef IPPROTO_IPV6 +#if defined(IPPROTO_IPV6) && !defined(BH_PLATFORM_COSMOPOLITAN) struct ipv6_mreq mreq; for (int i = 0; i < 8; i++) { ((uint16_t *)mreq.ipv6mr_multiaddr.s6_addr)[i] = @@ -834,7 +840,7 @@ os_socket_set_ip_drop_membership(bh_socket_t socket, { assert(imr_multiaddr); if (is_ipv6) { -#ifdef IPPROTO_IPV6 +#if defined(IPPROTO_IPV6) && !defined(BH_PLATFORM_COSMOPOLITAN) struct ipv6_mreq mreq; for (int i = 0; i < 8; i++) { ((uint16_t *)mreq.ipv6mr_multiaddr.s6_addr)[i] = diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_thread.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_thread.c similarity index 86% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_thread.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_thread.c index 5e814c41824..616420c948c 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_thread.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_thread.c @@ -39,6 +39,9 @@ os_thread_wrapper(void *arg) #ifdef OS_ENABLE_HW_BOUND_CHECK if (os_thread_signal_init(handler) != 0) return NULL; +#endif +#ifdef OS_ENABLE_WAKEUP_BLOCKING_OP + os_end_blocking_op(); #endif start_func(thread_arg); #ifdef OS_ENABLE_HW_BOUND_CHECK @@ -326,6 +329,61 @@ os_cond_broadcast(korp_cond *cond) return BHT_OK; } +int +os_rwlock_init(korp_rwlock *lock) +{ + assert(lock); + + if (pthread_rwlock_init(lock, NULL) != BHT_OK) + return BHT_ERROR; + + return BHT_OK; +} + +int +os_rwlock_rdlock(korp_rwlock *lock) +{ + assert(lock); + + if (pthread_rwlock_rdlock(lock) != BHT_OK) + return BHT_ERROR; + + return BHT_OK; +} + +int +os_rwlock_wrlock(korp_rwlock *lock) +{ + assert(lock); + + if (pthread_rwlock_wrlock(lock) != BHT_OK) + return BHT_ERROR; + + return BHT_OK; +} + +int +os_rwlock_unlock(korp_rwlock *lock) +{ + assert(lock); + + if (pthread_rwlock_unlock(lock) != BHT_OK) + return BHT_ERROR; + + return BHT_OK; +} + +int +os_rwlock_destroy(korp_rwlock *lock) +{ + assert(lock); + + if (pthread_rwlock_destroy(lock) != BHT_OK) + return BHT_ERROR; + + return BHT_OK; +} + int os_thread_join(korp_tid thread, void **value_ptr) { @@ -415,6 +473,14 @@ os_thread_get_stack_boundary() return addr; } +void +os_thread_jit_write_protect_np(bool enabled) +{ +#if (defined(__APPLE__) || defined(__MACH__)) && defined(__arm64__) + pthread_jit_write_protect_np(enabled); +#endif +} + #ifdef OS_ENABLE_HW_BOUND_CHECK #define SIG_ALT_STACK_SIZE (32 * 1024) @@ -430,8 +496,14 @@ static os_thread_local_attribute bool thread_signal_inited = false; /* The signal alternate stack base addr */ static os_thread_local_attribute uint8 *sigalt_stack_base_addr; +/* + * ASAN is not designed to work with custom stack unwind or other low-level + * things. Ignore a function that does some low-level magic. (e.g. walking + * through the thread's stack bypassing the frame boundaries) + */ #if defined(__clang__) #pragma clang optimize off +__attribute__((no_sanitize_address)) #elif defined(__GNUC__) #pragma GCC push_options #pragma GCC optimize("O0") @@ -492,6 +564,14 @@ destroy_stack_guard_pages() } #endif /* end of WASM_DISABLE_STACK_HW_BOUND_CHECK == 0 */ +/* + * ASAN is not designed to work with custom stack unwind or other low-level + * things. Ignore a function that does some low-level magic. (e.g. walking + * through the thread's stack bypassing the frame boundaries) + */ +#if defined(__GNUC__) || defined(__clang__) +__attribute__((no_sanitize_address)) +#endif static void mask_signals(int how) { @@ -503,9 +583,17 @@ mask_signals(int how) pthread_sigmask(how, &set, NULL); } -static os_thread_local_attribute struct sigaction prev_sig_act_SIGSEGV; -static os_thread_local_attribute struct sigaction prev_sig_act_SIGBUS; +static struct sigaction prev_sig_act_SIGSEGV; +static struct sigaction prev_sig_act_SIGBUS; +/* + * ASAN is not designed to work with custom stack unwind or other low-level + * things. Ignore a function that does some low-level magic. (e.g. walking + * through the thread's stack bypassing the frame boundaries) + */ +#if defined(__GNUC__) || defined(__clang__) +__attribute__((no_sanitize_address)) +#endif static void signal_callback(int sig_num, siginfo_t *sig_info, void *sig_ucontext) { @@ -529,9 +617,12 @@ signal_callback(int sig_num, siginfo_t *sig_info, void *sig_ucontext) prev_sig_act->sa_sigaction(sig_num, sig_info, sig_ucontext); } else if (prev_sig_act - && ((void *)prev_sig_act->sa_sigaction == SIG_DFL - || (void *)prev_sig_act->sa_sigaction == SIG_IGN)) { - sigaction(sig_num, prev_sig_act, NULL); + && prev_sig_act->sa_handler + /* Filter out SIG_DFL and SIG_IGN here, they will + run into the else branch below */ + && (void *)prev_sig_act->sa_handler != SIG_DFL + && (void *)prev_sig_act->sa_handler != SIG_IGN) { + prev_sig_act->sa_handler(sig_num); } /* Output signal info and then crash if signal is unhandled */ else { @@ -573,7 +664,7 @@ os_thread_signal_init(os_signal_handler handler) /* Initialize memory for signal alternate stack of current thread */ if (!(map_addr = os_mmap(NULL, map_size, MMAP_PROT_READ | MMAP_PROT_WRITE, - MMAP_MAP_NONE))) { + MMAP_MAP_NONE, os_get_invalid_handle()))) { os_printf("Failed to mmap memory for alternate stack\n"); goto fail1; } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_time.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_time.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/common/posix/posix_time.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/common/posix/posix_time.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/darwin/platform_init.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan/platform_init.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/darwin/platform_init.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan/platform_init.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan/platform_internal.h similarity index 72% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux/platform_internal.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan/platform_internal.h index 0ac63cf5e75..02cd78be496 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux/platform_internal.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan/platform_internal.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2019 Intel Corporation. All rights reserved. + * Copyright (C) 2023 Dylibso. All rights reserved. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ @@ -31,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -41,8 +41,8 @@ extern "C" { #endif -#ifndef BH_PLATFORM_LINUX -#define BH_PLATFORM_LINUX +#ifndef BH_PLATFORM_COSMOPOLITAN +#define BH_PLATFORM_COSMOPOLITAN #endif /* Stack size of applet threads's native part. */ @@ -63,6 +63,26 @@ typedef sem_t korp_sem; #define bh_socket_t int +typedef int os_file_handle; +typedef DIR *os_dir_stream; +typedef int os_raw_file_handle; + +#if WASM_DISABLE_WRITE_GS_BASE == 0 +#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) +#define os_writegsbase(base_addr) \ + do { \ + uint64 __gs_value = (uint64)(uintptr_t)base_addr; \ + asm volatile("wrgsbase %0" ::"r"(__gs_value) : "memory"); \ + } while (0) +#if 0 +/* _writegsbase_u64 also works, but need to add -mfsgsbase flag for gcc */ +#include +#define os_writegsbase(base_addr) \ + _writegsbase_u64(((uint64)(uintptr_t)base_addr)) +#endif +#endif +#endif + #if WASM_DISABLE_HW_BOUND_CHECK == 0 #if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \ || defined(BUILD_TARGET_AARCH64) || defined(BUILD_TARGET_RISCV64_LP64D) \ diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan/shared_platform.cmake new file mode 100644 index 00000000000..929ecb9e4a3 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/cosmopolitan/shared_platform.cmake @@ -0,0 +1,19 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# Copyright (C) 2023 Dylibso. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +set (PLATFORM_SHARED_DIR ${CMAKE_CURRENT_LIST_DIR}) + +add_definitions(-DBH_PLATFORM_COSMOPOLITAN) + +include_directories(${PLATFORM_SHARED_DIR}) +include_directories(${PLATFORM_SHARED_DIR}/../include) + +include (${CMAKE_CURRENT_LIST_DIR}/../common/posix/platform_api_posix.cmake) + +file (GLOB_RECURSE source_all ${PLATFORM_SHARED_DIR}/*.c) + +set (PLATFORM_SHARED_SOURCE ${source_all} ${PLATFORM_COMMON_POSIX_SOURCE}) + +file (GLOB header ${PLATFORM_SHARED_DIR}/../include/*.h) +LIST (APPEND RUNTIME_LIB_HEADER_LIST ${header}) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/freebsd/platform_init.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/darwin/platform_init.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/freebsd/platform_init.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/darwin/platform_init.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/darwin/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/darwin/platform_internal.h similarity index 86% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/darwin/platform_internal.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/darwin/platform_internal.h index 3fd1c258e25..30b89624e99 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/darwin/platform_internal.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/darwin/platform_internal.h @@ -58,6 +58,7 @@ typedef pthread_t korp_tid; typedef pthread_mutex_t korp_mutex; typedef pthread_cond_t korp_cond; typedef pthread_t korp_thread; +typedef pthread_rwlock_t korp_rwlock; typedef sem_t korp_sem; #define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER @@ -102,6 +103,22 @@ os_sigreturn(); #endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */ #endif /* end of WASM_DISABLE_HW_BOUND_CHECK */ +#if WASM_DISABLE_WAKEUP_BLOCKING_OP == 0 +#define OS_ENABLE_WAKEUP_BLOCKING_OP +#endif +void +os_set_signal_number_for_blocking_op(int signo); + +typedef int os_file_handle; +typedef DIR *os_dir_stream; +typedef int os_raw_file_handle; + +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #ifdef __cplusplus } #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/darwin/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/darwin/shared_platform.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/darwin/shared_platform.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/darwin/shared_platform.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/ego/platform_init.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/ego/platform_init.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/ego/platform_init.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/ego/platform_init.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/ego/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/ego/platform_internal.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/ego/platform_internal.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/ego/platform_internal.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/ego/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/ego/shared_platform.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/ego/shared_platform.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/ego/shared_platform.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_malloc.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_malloc.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_malloc.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_malloc.c diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_memmap.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_memmap.c new file mode 100644 index 00000000000..9f3ec47a6a3 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_memmap.c @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "platform_api_vmcore.h" +#include "platform_api_extension.h" +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) +#include "soc/mmu.h" +#include "rom/cache.h" + +#define MEM_DUAL_BUS_OFFSET (IRAM0_CACHE_ADDRESS_LOW - DRAM0_CACHE_ADDRESS_LOW) + +#define in_ibus_ext(addr) \ + (((uint32)addr >= IRAM0_CACHE_ADDRESS_LOW) \ + && ((uint32)addr < IRAM0_CACHE_ADDRESS_HIGH)) + +static portMUX_TYPE s_spinlock = portMUX_INITIALIZER_UNLOCKED; +#endif + +void * +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) +{ + if (prot & MMAP_PROT_EXEC) { +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) + uint32_t mem_caps = MALLOC_CAP_SPIRAM; +#else + uint32_t mem_caps = MALLOC_CAP_EXEC; +#endif + + // Memory allocation with MALLOC_CAP_EXEC will return 4-byte aligned + // Reserve extra 4 byte to fixup alignment and size for the pointer to + // the originally allocated address + void *buf_origin = + heap_caps_malloc(size + 4 + sizeof(uintptr_t), mem_caps); + if (!buf_origin) { + return NULL; + } + void *buf_fixed = buf_origin + sizeof(void *); + if ((uintptr_t)buf_fixed & (uintptr_t)0x7) { + buf_fixed = (void *)((uintptr_t)(buf_fixed + 4) & (~(uintptr_t)7)); + } + + uintptr_t *addr_field = buf_fixed - sizeof(uintptr_t); + *addr_field = (uintptr_t)buf_origin; +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) + return buf_fixed + MEM_DUAL_BUS_OFFSET; +#else + return buf_fixed; +#endif + } + else { +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) + uint32_t mem_caps = MALLOC_CAP_SPIRAM; +#else + uint32_t mem_caps = MALLOC_CAP_8BIT; +#endif + return heap_caps_malloc(size, mem_caps); + } +} + +void +os_munmap(void *addr, size_t size) +{ + char *ptr = (char *)addr; + +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) + if (in_ibus_ext(ptr)) { + ptr -= MEM_DUAL_BUS_OFFSET; + } +#endif + // We don't need special handling of the executable allocations + // here, free() of esp-idf handles it properly + return os_free(ptr); +} + +int +os_mprotect(void *addr, size_t size, int prot) +{ + return 0; +} + +void +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) + IRAM_ATTR +#endif + os_dcache_flush() +{ +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) + uint32_t preload; + extern void Cache_WriteBack_All(void); + + portENTER_CRITICAL(&s_spinlock); + + Cache_WriteBack_All(); + preload = Cache_Disable_ICache(); + Cache_Enable_ICache(preload); + + portEXIT_CRITICAL(&s_spinlock); +#endif +} + +void +os_icache_flush(void *start, size_t len) +{} + +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) +void * +os_get_dbus_mirror(void *ibus) +{ + if (in_ibus_ext(ibus)) { + return (void *)((char *)ibus - MEM_DUAL_BUS_OFFSET); + } + else { + return ibus; + } +} +#endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_platform.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_platform.c similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_platform.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_platform.c index 35b893d814f..bbc18f69bf6 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_platform.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_platform.c @@ -53,6 +53,10 @@ os_thread_get_stack_boundary(void) #endif } +void +os_thread_jit_write_protect_np(bool enabled) +{} + int os_usleep(uint32 usec) { diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_socket.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_socket.c similarity index 95% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_socket.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_socket.c index 9f441b71218..a75d82975d0 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_socket.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_socket.c @@ -5,6 +5,7 @@ #include "platform_api_vmcore.h" #include "platform_api_extension.h" +#include "libc_errno.h" #include @@ -30,7 +31,7 @@ sockaddr_to_bh_sockaddr(const struct sockaddr *sockaddr, socklen_t socklen, assert(socklen >= sizeof(struct sockaddr_in)); bh_sockaddr->port = ntohs(addr->sin_port); - bh_sockaddr->addr_bufer.ipv4 = ntohl(addr->sin_addr.s_addr); + bh_sockaddr->addr_buffer.ipv4 = ntohl(addr->sin_addr.s_addr); bh_sockaddr->is_ipv4 = true; return BHT_OK; } @@ -167,11 +168,13 @@ os_socket_close(bh_socket_t socket) return BHT_OK; } -int +__wasi_errno_t os_socket_shutdown(bh_socket_t socket) { - shutdown(socket, O_RDWR); - return BHT_OK; + if (shutdown(socket, O_RDWR) != 0) { + return convert_errno(errno); + } + return __WASI_ESUCCESS; } int diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_thread.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_thread.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/espidf_thread.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/espidf_thread.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/platform_internal.h similarity index 92% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/platform_internal.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/platform_internal.h index 81304ea80c6..70c4fe7b1d5 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/platform_internal.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/platform_internal.h @@ -39,6 +39,7 @@ typedef pthread_t korp_tid; typedef pthread_mutex_t korp_mutex; typedef pthread_cond_t korp_cond; typedef pthread_t korp_thread; +typedef pthread_rwlock_t korp_rwlock; typedef unsigned int korp_sem; #define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER @@ -108,6 +109,16 @@ typedef unsigned int korp_sem; #define DT_LNK DTYPE_LINK #define DT_SOCK DTYPE_SOCK +typedef int os_file_handle; +typedef DIR *os_dir_stream; +typedef int os_raw_file_handle; + +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #ifdef __cplusplus } #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/shared_platform.cmake similarity index 66% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/shared_platform.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/shared_platform.cmake index 13bc45dcb1f..8d7fe5d808a 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/esp-idf/shared_platform.cmake +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/esp-idf/shared_platform.cmake @@ -11,3 +11,9 @@ include_directories(${PLATFORM_SHARED_DIR}/../include) file (GLOB_RECURSE source_all ${PLATFORM_SHARED_DIR}/*.c) set (PLATFORM_SHARED_SOURCE ${source_all} ${PLATFORM_COMMON_MATH_SOURCE}) + +# If enable PSRAM of ESP32-S3, it had better to put AOT into PSRAM, so that +# users can use SRAM to for Wi-Fi/BLE and peripheral driver. +if(CONFIG_ESP32S3_SPIRAM_SUPPORT) + add_definitions(-DWASM_MEM_DUAL_BUS_MIRROR=1) +endif() diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux/platform_init.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/freebsd/platform_init.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux/platform_init.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/freebsd/platform_init.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/freebsd/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/freebsd/platform_internal.h similarity index 85% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/freebsd/platform_internal.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/freebsd/platform_internal.h index 7b4789c9922..5241c64569c 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/freebsd/platform_internal.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/freebsd/platform_internal.h @@ -57,6 +57,7 @@ typedef pthread_t korp_tid; typedef pthread_mutex_t korp_mutex; typedef pthread_cond_t korp_cond; typedef pthread_t korp_thread; +typedef pthread_rwlock_t korp_rwlock; typedef sem_t korp_sem; #define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER @@ -65,6 +66,10 @@ typedef sem_t korp_sem; #define bh_socket_t int +typedef int os_file_handle; +typedef DIR *os_dir_stream; +typedef int os_raw_file_handle; + #if WASM_DISABLE_HW_BOUND_CHECK == 0 #if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \ || defined(BUILD_TARGET_AARCH64) || defined(BUILD_TARGET_RISCV64_LP64D) \ @@ -101,6 +106,20 @@ os_sigreturn(); #endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */ #endif /* end of WASM_DISABLE_HW_BOUND_CHECK */ +#if WASM_DISABLE_WAKEUP_BLOCKING_OP == 0 +#define OS_ENABLE_WAKEUP_BLOCKING_OP +#endif +void +os_set_signal_number_for_blocking_op(int signo); + +typedef int os_file_handle; + +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #ifdef __cplusplus } #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/freebsd/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/freebsd/shared_platform.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/freebsd/shared_platform.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/freebsd/shared_platform.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/include/platform_api_extension.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_api_extension.h similarity index 58% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/include/platform_api_extension.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_api_extension.h index 94fe16ea3a8..7c6120ba206 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/include/platform_api_extension.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_api_extension.h @@ -7,6 +7,7 @@ #define PLATFORM_API_EXTENSION_H #include "platform_common.h" +#include "platform_wasi_types.h" /** * The related data structures should be defined * in platform_internal.h @@ -130,6 +131,7 @@ os_thread_exit(void *retval); #define os_memory_order_release memory_order_release #define os_memory_order_seq_cst memory_order_seq_cst #define os_atomic_thread_fence atomic_thread_fence +#define os_atomic_cmpxchg atomic_compare_exchange_strong #endif #endif /* end of os_atomic_thread_fence */ @@ -237,6 +239,56 @@ os_cond_signal(korp_cond *cond); int os_cond_broadcast(korp_cond *cond); +/** + * Initialize readwrite lock object + * + * @param cond [OUTPUT] pointer to a lock object variable + * + * @return 0 if success + */ +int +os_rwlock_init(korp_rwlock *lock); + +/** + * Acquire the read lock + * + * @param lock lock variable + * + * @return 0 if success + */ +int +os_rwlock_rdlock(korp_rwlock *lock); + +/** + * Acquire the write lock + * + * @param lock lock variable + * + * @return 0 if success + */ +int +os_rwlock_wrlock(korp_rwlock *lock); + +/** + * Unlocks the lock object + * + * @param lock lock variable + * + * @return 0 if success + */ +int +os_rwlock_unlock(korp_rwlock *lock); + +/** + * Destroy a lock object + * + * @param lock lock variable + * + * @return 0 if success + */ +int +os_rwlock_destroy(korp_rwlock *lock); + /** * Creates a new POSIX-like semaphore or opens an existing * semaphore. The semaphore is identified by name. For details of @@ -322,6 +374,34 @@ os_sem_getvalue(korp_sem *sem, int *sval); int os_sem_unlink(const char *name); +/** + * Initialize process-global state for os_wakeup_blocking_op. + */ +int +os_blocking_op_init(); + +/** + * Start accepting os_wakeup_blocking_op requests for the calling thread. + */ +void +os_begin_blocking_op(); + +/** + * Stop accepting os_wakeup_blocking_op requests for the calling thread. + */ +void +os_end_blocking_op(); + +/** + * Wake up the specified thread. + * + * For example, on posix-like platforms, this can be implemented by + * sending a signal (w/o SA_RESTART) which interrupts a blocking + * system call. + */ +int +os_wakeup_blocking_op(korp_tid tid); + /**************************************************** * Section 2 * * Socket support * @@ -341,7 +421,7 @@ typedef union { } bh_ip_addr_buffer_t; typedef struct { - bh_ip_addr_buffer_t addr_bufer; + bh_ip_addr_buffer_t addr_buffer; uint16 port; bool is_ipv4; } bh_sockaddr_t; @@ -493,9 +573,9 @@ os_socket_close(bh_socket_t socket); * * @param socket the socket to be shutdown * - * @return always return 0 + * @return returns corresponding error code */ -int +__wasi_errno_t os_socket_shutdown(bh_socket_t socket); /** @@ -1032,6 +1112,526 @@ os_socket_get_broadcast(bh_socket_t socket, bool *is_enabled); int os_dumps_proc_mem_info(char *out, unsigned int size); +/**************************************************** + * Section 3 * + * Filesystem support * + ****************************************************/ + +/** + * NOTES: + * Fileystem APIs are required for WASI libc support. If you don't need to + * support WASI libc, there is no need to implement these APIs. With a + * few exceptions, each filesystem function has been named after the equivalent + * POSIX filesystem function with an os_ prefix. + * + * Filesystem types + * + * os_raw_file_handle: the underlying OS file handle type e.g. int on POSIX + * systems and HANDLE on Windows. This type exists to allow embedders to provide + * custom file handles for stdout/stdin/stderr. + * + * os_file_handle: the file handle type used in the WASI libc fd + * table. Filesystem implementations can use it as a means to store any + * necessary platform-specific information which may not be directly available + * through the raw OS file handle. Similiar to POSIX file descriptors, file + * handles may also refer to sockets, directories, symbolic links or character + * devices and any of the filesystem operations which make sense for these + * resource types should be supported as far as possible. + * + * os_dir_stream: a directory stream type in which fileystem implementations + * can store any necessary state to iterate over the entries in a directory. + */ + +/** + * Obtain information about an open file associated with the given handle. + * + * @param handle the handle for which to obtain file information + * @param buf a buffer in which to store the information + */ +__wasi_errno_t +os_fstat(os_file_handle handle, struct __wasi_filestat_t *buf); + +/** + * Obtain information about an open file or directory. + * @param handle the directory handle from which to resolve the file/directory + * path + * @param path the relative path of the file or directory for which to obtain + * information + * @param buf a buffer in which to store the information + * @param follow_symlink whether to follow symlinks when resolving the path + */ +__wasi_errno_t +os_fstatat(os_file_handle handle, const char *path, + struct __wasi_filestat_t *buf, __wasi_lookupflags_t lookup_flags); + +/** + * Obtain the file status flags for the provided handle. This is similiar to the + * POSIX function fcntl called with the F_GETFL command. + * + * @param handle the handle for which to obtain the file status flags + * @param flags a pointer in which to store the output + */ +__wasi_errno_t +os_file_get_fdflags(os_file_handle handle, __wasi_fdflags_t *flags); + +/** + * Set the file status flags for the provided handle. This is similiar to the + * POSIX function fcntl called with the F_SETFL command. + * + * @param handle the handle for which to set the file status flags + * @param flags the flags to set + */ +__wasi_errno_t +os_file_set_fdflags(os_file_handle handle, __wasi_fdflags_t flags); + +/** + * Synchronize the data of a file to disk. + * + * @param handle + */ +__wasi_errno_t +os_fdatasync(os_file_handle handle); + +/** + * Synchronize the data and metadata of a file to disk. + * + * @param handle + */ +__wasi_errno_t +os_fsync(os_file_handle handle); + +/** + * Open a preopen directory. The path provided must refer to a directory and the + * returned handle will allow only readonly operations. + * + * @param path the path of the preopen directory to open + * @param out a pointer in which to store the newly opened handle + */ +__wasi_errno_t +os_open_preopendir(const char *path, os_file_handle *out); + +typedef uint8 wasi_libc_file_access_mode; +#define WASI_LIBC_ACCESS_MODE_READ_ONLY 0 +#define WASI_LIBC_ACCESS_MODE_WRITE_ONLY 1 +#define WASI_LIBC_ACCESS_MODE_READ_WRITE 2 + +/** + * Open a file or directory at the given path. + * + * @param handle a handle to the directory in which to open the new file or + * directory + * @param path the relative path of the file or directory to open + * @param oflags the flags to determine how the file or directory is opened + * @param fd_flags the flags to set on the returned handle + * @param lookup_flags whether to follow symlinks when resolving the path + * @param access_mode whether the file is opened as read only, write only or + * both + * @param out a pointer in which to store the newly opened handle + */ +__wasi_errno_t +os_openat(os_file_handle handle, const char *path, __wasi_oflags_t oflags, + __wasi_fdflags_t fd_flags, __wasi_lookupflags_t lookup_flags, + wasi_libc_file_access_mode access_mode, os_file_handle *out); + +/** + * Obtain the file access mode for the provided handle. This is similiar to the + * POSIX function fcntl called with the F_GETFL command combined with the + * O_ACCMODE mask. + * + * @param handle the handle for which to obtain the access mode + * @param access_mode a pointer in which to store the access mode + */ +__wasi_errno_t +os_file_get_access_mode(os_file_handle handle, + wasi_libc_file_access_mode *access_mode); + +/** + * Close the provided handle. If is_stdio is true, the raw file handle + * associated with the given file handle will not be closed. + * + * @param handle the handle to close + * @param is_stdio whether the provided handle refers to a stdio device + */ +__wasi_errno_t +os_close(os_file_handle handle, bool is_stdio); + +/** + * Read data from the provided handle at the given offset into multiple buffers. + * + * @param handle the handle to read from + * @param iov the buffers to read into + * @param iovcnt the number of buffers to read into + * @param offset the offset to read from + * @param nread a pointer in which to store the number of bytes read + */ +__wasi_errno_t +os_preadv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt, + __wasi_filesize_t offset, size_t *nread); + +/** + * Write data from multiple buffers at the given offset to the provided handle. + * + * @param handle the handle to write to + * @param iov the buffers to write from + * @param iovcnt the number of buffers to write from + * @param offset the offset to write from + * @param nwritten a pointer in which to store the number of bytes written + */ +__wasi_errno_t +os_pwritev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt, + __wasi_filesize_t offset, size_t *nwritten); + +/** + * Read data from the provided handle into multiple buffers. + * + * @param handle the handle to read from + * @param iov the buffers to read into + * @param iovcnt the number of buffers to read into + * @param nread a pointer in which to store the number of bytes read + */ +__wasi_errno_t +os_readv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt, + size_t *nread); + +/** + * Write data from multiple buffers to the provided handle. + * + * @param handle the handle to write to + * @param iov the buffers to write from + * @param iovcnt the number of buffers to write from + * @param nwritten a pointer in which to store the number of bytes written + */ +__wasi_errno_t +os_writev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt, + size_t *nwritten); + +/** + * Allocate storage space for the file associated with the provided handle. This + * is similar to the POSIX function posix_fallocate. + * + * @param handle the handle to allocate space for + * @param offset the offset to allocate space at + * @param length the amount of space to allocate + */ +__wasi_errno_t +os_fallocate(os_file_handle handle, __wasi_filesize_t offset, + __wasi_filesize_t length); + +/** + * Adjust the size of an open file. + * + * @param handle the associated file handle for which to adjust the size + * @param size the new size of the file + */ +__wasi_errno_t +os_ftruncate(os_file_handle handle, __wasi_filesize_t size); + +/** + * Set file access and modification times on an open file or directory. + * + * @param handle the associated file handle for which to adjust the + * access/modification times + * @param access_time the timestamp for the new access time + * @param modification_time the timestamp for the new modification time + * @param fstflags a bitmask to indicate which timestamps to adjust + */ +__wasi_errno_t +os_futimens(os_file_handle handle, __wasi_timestamp_t access_time, + __wasi_timestamp_t modification_time, __wasi_fstflags_t fstflags); + +/** + * Set file access and modification times on an open file or directory. + * + * @param handle the directory handle from which to resolve the path + * @param path the relative path of the file or directory for which to adjust + * the access/modification times + * @param access_time the timestamp for the new access time + * @param modification_time the timestamp for the new modification time + * @param fstflags a bitmask to indicate which timestamps to adjust + * @param lookup_flags whether to follow symlinks when resolving the path + */ +__wasi_errno_t +os_utimensat(os_file_handle handle, const char *path, + __wasi_timestamp_t access_time, + __wasi_timestamp_t modification_time, __wasi_fstflags_t fstflags, + __wasi_lookupflags_t lookup_flags); + +/** + * Read the contents of a symbolic link relative to the provided directory + * handle. + * + * @param handle the directory handle + * @param path the relative path of the symbolic link from which to read + * @param buf the buffer to read the link contents into + * @param bufsize the size of the provided buffer + * @param nread a pointer in which to store the number of bytes read into the + * buffer + */ +__wasi_errno_t +os_readlinkat(os_file_handle handle, const char *path, char *buf, + size_t bufsize, size_t *nread); + +/** + * Create a link from one path to another path. + * + * @param from_handle the directory handle from which to resolve the origin path + * @param from_path the origin path to link from + * @param to_handle the directory handle from which to resolve the destination + * path + * @param to_path the destination path at which to create the link + * @param lookup_flags whether to follow symlinks when resolving the origin path + */ +__wasi_errno_t +os_linkat(os_file_handle from_handle, const char *from_path, + os_file_handle to_handle, const char *to_path, + __wasi_lookupflags_t lookup_flags); + +/** + * Create a symbolic link from one path to another path. + * + * @param old_path the symbolic link contents + * @param handle the directory handle from which to resolve the destination path + * @param new_path the destination path at which to create the symbolic link + */ +__wasi_errno_t +os_symlinkat(const char *old_path, os_file_handle handle, const char *new_path); + +/** + * Create a directory relative to the provided directory handle. + * + * @param handle the directory handle + * @param path the relative path of the directory to create + */ +__wasi_errno_t +os_mkdirat(os_file_handle handle, const char *path); + +/** + * Rename a file or directory. + * + * @param old_handle the directory handle from which to resolve the old path + * @param old_path the source path to rename + * @param new_handle the directory handle from which to resolve the destination + * path + * @param new_path the destination path to which to rename the file or directory + */ +__wasi_errno_t +os_renameat(os_file_handle old_handle, const char *old_path, + os_file_handle new_handle, const char *new_path); + +/** + * Unlink a file or directory. + * + * @param handle the directory handle from which to resolve the path + * @param path the relative path of the file or directory to unlink + * @param is_dir whether the provided handle refers to a directory or file + */ +__wasi_errno_t +os_unlinkat(os_file_handle handle, const char *path, bool is_dir); + +/** + * Move the read/write offset of an open file. + * + * @param handle the associated file handle for which to adjust the offset + * @param offset the number of bytes to adjust the offset by + * @param whence the position whence to adjust the offset + * @param new_offset a pointer in which to store the new offset + */ +__wasi_errno_t +os_lseek(os_file_handle handle, __wasi_filedelta_t offset, + __wasi_whence_t whence, __wasi_filesize_t *new_offset); + +/** + * Provide file advisory information for the given handle. This is similar to + * the POSIX function posix_fadvise. + * + * @param handle the associated file handle for which to provide advisory + * information + * @param offset the offset within the file to which the advisory + * information applies + * @param length the length of the region for which the advisory information + * applies + * @param advice the advice to provide + */ +__wasi_errno_t +os_fadvise(os_file_handle handle, __wasi_filesize_t offset, + __wasi_filesize_t length, __wasi_advice_t advice); + +/** + * Determine if the given handle refers to a terminal device. __WASI_ESUCCESS + * will be returned if the handle is associated with a terminal device, + * otherwise an appropriate error code will be returned. + * + * @param handle + */ +__wasi_errno_t +os_isatty(os_file_handle handle); + +/** + * Converts a raw file handle to STDIN to a corresponding file handle to STDIN. + * If the provided raw file handle is invalid, the platform-default raw handle + * for STDIN will be used. + * + * @param raw_stdin a raw file handle to STDIN + * + * @return a handle to STDIN + */ +os_file_handle +os_convert_stdin_handle(os_raw_file_handle raw_stdin); + +/** + * Converts a raw file handle to STDOUT to a correponding file handle to STDOUT. + * If the provided raw file handle is invalid, the platform-default raw handle + * for STDOUT will be used. + * + * @param raw_stdout a raw file handle to STDOUT + * + * @return a handle to STDOUT + */ +os_file_handle +os_convert_stdout_handle(os_raw_file_handle raw_stdout); + +/** + * Converts a raw file handle to STDERR to a correponding file handle to STDERR. + * If the provided raw file handle is invalid, the platform-default raw handle + * for STDERR will be used. + * + * @param raw_stderr a raw file handle to STDERR + * + * @return a handle to STDERR + */ +os_file_handle +os_convert_stderr_handle(os_raw_file_handle raw_stderr); + +/** + * Open a directory stream for the provided directory handle. The returned + * directory stream will be positioned at the first entry in the directory. + * + * @param handle the directory handle + * @param dir_stream a pointer in which to store the new directory stream + */ +__wasi_errno_t +os_fdopendir(os_file_handle handle, os_dir_stream *dir_stream); + +/** + * Reset the position of a directory stream to the beginning of the directory. + * + * @param dir_stream the directory stream for which to reset the position + */ +__wasi_errno_t +os_rewinddir(os_dir_stream dir_stream); + +/** + * Set the position of the given directory stream. + * + * @param dir_stream the directory stream for which to set the position + * @param position the position to set + */ +__wasi_errno_t +os_seekdir(os_dir_stream dir_stream, __wasi_dircookie_t position); + +/** + * Read a directory entry from the given directory stream. The directory name + * will be NULL if the end of the directory is reached or an error is + * encountered. + * + * @param dir_stream the directory stream from which to read the entry + * @param entry a pointer in which to store the directory entry + * @param d_name a pointer in which to store the directory entry name + */ +__wasi_errno_t +os_readdir(os_dir_stream dir_stream, __wasi_dirent_t *entry, + const char **d_name); + +/** + * Close the given directory stream. The handle associated with the directory + * stream will also be closed. + * + * @param dir_stream the directory stream to close + */ +__wasi_errno_t +os_closedir(os_dir_stream dir_stream); + +/** + * Returns an invalid directory stream that is guaranteed to cause failure when + * called with any directory filesystem operation. + * + * @return the invalid directory stream + */ +os_dir_stream +os_get_invalid_dir_stream(); + +/** + * Checks whether the given directory stream is valid. An invalid directory + * stream is guaranteed to cause failure when called with any directory + * filesystem operation. + * + * @param dir_stream a pointer to a directory stream + */ +bool +os_is_dir_stream_valid(os_dir_stream *dir_stream); + +/** + * Returns an invalid handle that is guaranteed to cause failure when + * called with any filesystem operation. + * + * @return the invalid handle + */ +os_file_handle +os_get_invalid_handle(); + +/** + * Checks whether the given file handle is valid. An invalid handle is + * guaranteed to cause failure when called with any filesystem operation. + * + * @param handle a pointer to a file handle + */ +bool +os_is_handle_valid(os_file_handle *handle); + +/** + * Resolve a pathname. The generated pathname will be stored as a + * null-terminated string, with a maximum length of PATH_MAX bytes. + * + * @param path the path to resolve + * @param resolved_path the buffer to store the resolved path in + * + * @return the resolved path if success, NULL otherwise + */ +char * +os_realpath(const char *path, char *resolved_path); + +/**************************************************** + * Section 4 * + * Clock functions * + ****************************************************/ + +/** + * NOTES: + * Clock functions are required for WASI libc support. If you don't need to + * support WASI libc, there is no need to implement these APIs. + */ + +/** + * Get the resolution of the specified clock. + * + * @param clock_id clock identifier + * @param resolution output variable to store the clock resolution + */ +__wasi_errno_t +os_clock_res_get(__wasi_clockid_t clock_id, __wasi_timestamp_t *resolution); + +/** + * Get the current time of the specified clock. + * + * @param clock_id clock identifier + * @param precision the maximum lag that the returned time value may have, + * compared to its actual value. + * @param time output variable to store the clock time + */ +__wasi_errno_t +os_clock_time_get(__wasi_clockid_t clock_id, __wasi_timestamp_t precision, + __wasi_timestamp_t *time); + #ifdef __cplusplus } #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/include/platform_api_vmcore.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_api_vmcore.h similarity index 87% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/include/platform_api_vmcore.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_api_vmcore.h index c2f03c9e502..559141f75f3 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/include/platform_api_vmcore.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_api_vmcore.h @@ -81,6 +81,13 @@ os_self_thread(void); uint8 * os_thread_get_stack_boundary(void); +/** + * Set whether the MAP_JIT region write protection is enabled for this thread. + * Pass true to make the region executable, false to make it writable. + */ +void +os_thread_jit_write_protect_np(bool enabled); + /** ************** mutext APIs *********** * vmcore: Not required until pthread is supported by runtime @@ -123,12 +130,17 @@ enum { }; void * -os_mmap(void *hint, size_t size, int prot, int flags); +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file); void os_munmap(void *addr, size_t size); int os_mprotect(void *addr, size_t size, int prot); +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) +void * +os_get_dbus_mirror(void *ibus); +#endif + /** * Flush cpu data cache, in some CPUs, after applying relocation to the * AOT code, the code may haven't been written back to the cpu data cache, @@ -138,6 +150,12 @@ os_mprotect(void *addr, size_t size, int prot); void os_dcache_flush(void); +/** + * Flush instruction cache. + */ +void +os_icache_flush(void *start, size_t len); + #ifdef __cplusplus } #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/include/platform_common.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_common.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/include/platform_common.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_common.h diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_wasi_types.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_wasi_types.h new file mode 100644 index 00000000000..ac1a95ea1eb --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/include/platform_wasi_types.h @@ -0,0 +1,610 @@ +/* + * Copyright (C) 2023 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +/* + * This file declares the WASI interface. The definitions of types, macros and + * structures in this file should be consistent with those in wasi-libc: + * https://github.com/WebAssembly/wasi-libc/blob/main/libc-bottom-half/headers/public/wasi/api.h + */ + +#ifndef _PLATFORM_WASI_TYPES_H +#define _PLATFORM_WASI_TYPES_H + +#include "../../../config.h" + +#include +#include + +/* clang-format off */ + +#ifdef __cplusplus +#ifndef _Static_assert +#define _Static_assert static_assert +#endif /* _Static_assert */ + +#ifndef _Alignof +#define _Alignof alignof +#endif /* _Alignof */ + +extern "C" { +#endif + +/* There is no need to check the WASI layout if we're using uvwasi or libc-wasi + * is not enabled at all. */ +#if WASM_ENABLE_UVWASI != 0 || WASM_ENABLE_LIBC_WASI == 0 +#define assert_wasi_layout(expr, message) /* nothing */ +#else +#define assert_wasi_layout(expr, message) _Static_assert(expr, message) +#endif + +assert_wasi_layout(_Alignof(int8_t) == 1, "non-wasi data layout"); +assert_wasi_layout(_Alignof(uint8_t) == 1, "non-wasi data layout"); +assert_wasi_layout(_Alignof(int16_t) == 2, "non-wasi data layout"); +assert_wasi_layout(_Alignof(uint16_t) == 2, "non-wasi data layout"); +assert_wasi_layout(_Alignof(int32_t) == 4, "non-wasi data layout"); +assert_wasi_layout(_Alignof(uint32_t) == 4, "non-wasi data layout"); +#if 0 +assert_wasi_layout(_Alignof(int64_t) == 8, "non-wasi data layout"); +assert_wasi_layout(_Alignof(uint64_t) == 8, "non-wasi data layout"); +#endif + +typedef uint32_t __wasi_size_t; +assert_wasi_layout(_Alignof(__wasi_size_t) == 4, "non-wasi data layout"); + +typedef uint8_t __wasi_advice_t; +#define __WASI_ADVICE_NORMAL (0) +#define __WASI_ADVICE_SEQUENTIAL (1) +#define __WASI_ADVICE_RANDOM (2) +#define __WASI_ADVICE_WILLNEED (3) +#define __WASI_ADVICE_DONTNEED (4) +#define __WASI_ADVICE_NOREUSE (5) + +typedef uint32_t __wasi_clockid_t; +#define __WASI_CLOCK_REALTIME (0) +#define __WASI_CLOCK_MONOTONIC (1) +#define __WASI_CLOCK_PROCESS_CPUTIME_ID (2) +#define __WASI_CLOCK_THREAD_CPUTIME_ID (3) + +typedef uint64_t __wasi_device_t; + +typedef uint64_t __wasi_dircookie_t; +#define __WASI_DIRCOOKIE_START (0) + +typedef uint32_t __wasi_dirnamlen_t; + +typedef uint16_t __wasi_errno_t; +#define __WASI_ESUCCESS (0) +#define __WASI_E2BIG (1) +#define __WASI_EACCES (2) +#define __WASI_EADDRINUSE (3) +#define __WASI_EADDRNOTAVAIL (4) +#define __WASI_EAFNOSUPPORT (5) +#define __WASI_EAGAIN (6) +#define __WASI_EALREADY (7) +#define __WASI_EBADF (8) +#define __WASI_EBADMSG (9) +#define __WASI_EBUSY (10) +#define __WASI_ECANCELED (11) +#define __WASI_ECHILD (12) +#define __WASI_ECONNABORTED (13) +#define __WASI_ECONNREFUSED (14) +#define __WASI_ECONNRESET (15) +#define __WASI_EDEADLK (16) +#define __WASI_EDESTADDRREQ (17) +#define __WASI_EDOM (18) +#define __WASI_EDQUOT (19) +#define __WASI_EEXIST (20) +#define __WASI_EFAULT (21) +#define __WASI_EFBIG (22) +#define __WASI_EHOSTUNREACH (23) +#define __WASI_EIDRM (24) +#define __WASI_EILSEQ (25) +#define __WASI_EINPROGRESS (26) +#define __WASI_EINTR (27) +#define __WASI_EINVAL (28) +#define __WASI_EIO (29) +#define __WASI_EISCONN (30) +#define __WASI_EISDIR (31) +#define __WASI_ELOOP (32) +#define __WASI_EMFILE (33) +#define __WASI_EMLINK (34) +#define __WASI_EMSGSIZE (35) +#define __WASI_EMULTIHOP (36) +#define __WASI_ENAMETOOLONG (37) +#define __WASI_ENETDOWN (38) +#define __WASI_ENETRESET (39) +#define __WASI_ENETUNREACH (40) +#define __WASI_ENFILE (41) +#define __WASI_ENOBUFS (42) +#define __WASI_ENODEV (43) +#define __WASI_ENOENT (44) +#define __WASI_ENOEXEC (45) +#define __WASI_ENOLCK (46) +#define __WASI_ENOLINK (47) +#define __WASI_ENOMEM (48) +#define __WASI_ENOMSG (49) +#define __WASI_ENOPROTOOPT (50) +#define __WASI_ENOSPC (51) +#define __WASI_ENOSYS (52) +#define __WASI_ENOTCONN (53) +#define __WASI_ENOTDIR (54) +#define __WASI_ENOTEMPTY (55) +#define __WASI_ENOTRECOVERABLE (56) +#define __WASI_ENOTSOCK (57) +#define __WASI_ENOTSUP (58) +#define __WASI_ENOTTY (59) +#define __WASI_ENXIO (60) +#define __WASI_EOVERFLOW (61) +#define __WASI_EOWNERDEAD (62) +#define __WASI_EPERM (63) +#define __WASI_EPIPE (64) +#define __WASI_EPROTO (65) +#define __WASI_EPROTONOSUPPORT (66) +#define __WASI_EPROTOTYPE (67) +#define __WASI_ERANGE (68) +#define __WASI_EROFS (69) +#define __WASI_ESPIPE (70) +#define __WASI_ESRCH (71) +#define __WASI_ESTALE (72) +#define __WASI_ETIMEDOUT (73) +#define __WASI_ETXTBSY (74) +#define __WASI_EXDEV (75) +#define __WASI_ENOTCAPABLE (76) + +#if defined(_MSC_VER) +#define ALIGNED_(x) __declspec(align(x)) +#define WARN_UNUSED _Check_return_ +#elif defined(__GNUC__) +#define ALIGNED_(x) __attribute__ ((aligned(x))) +#define WARN_UNUSED __attribute__((__warn_unused_result__)) +#endif + +#define ALIGNED_TYPE(t,x) typedef t ALIGNED_(x) + +typedef uint16_t __wasi_eventrwflags_t; +#define __WASI_EVENT_FD_READWRITE_HANGUP (0x0001) + +typedef uint8_t __wasi_eventtype_t; +#define __WASI_EVENTTYPE_CLOCK (0) +#define __WASI_EVENTTYPE_FD_READ (1) +#define __WASI_EVENTTYPE_FD_WRITE (2) + +typedef uint32_t __wasi_exitcode_t; + +typedef uint32_t __wasi_fd_t; + +typedef uint16_t __wasi_fdflags_t; +#define __WASI_FDFLAG_APPEND (0x0001) +#define __WASI_FDFLAG_DSYNC (0x0002) +#define __WASI_FDFLAG_NONBLOCK (0x0004) +#define __WASI_FDFLAG_RSYNC (0x0008) +#define __WASI_FDFLAG_SYNC (0x0010) + +typedef int64_t __wasi_filedelta_t; + +typedef uint64_t __wasi_filesize_t; + +typedef uint8_t __wasi_filetype_t; +#define __WASI_FILETYPE_UNKNOWN (0) +#define __WASI_FILETYPE_BLOCK_DEVICE (1) +#define __WASI_FILETYPE_CHARACTER_DEVICE (2) +#define __WASI_FILETYPE_DIRECTORY (3) +#define __WASI_FILETYPE_REGULAR_FILE (4) +#define __WASI_FILETYPE_SOCKET_DGRAM (5) +#define __WASI_FILETYPE_SOCKET_STREAM (6) +#define __WASI_FILETYPE_SYMBOLIC_LINK (7) + +typedef uint16_t __wasi_fstflags_t; +#define __WASI_FILESTAT_SET_ATIM (0x0001) +#define __WASI_FILESTAT_SET_ATIM_NOW (0x0002) +#define __WASI_FILESTAT_SET_MTIM (0x0004) +#define __WASI_FILESTAT_SET_MTIM_NOW (0x0008) + +typedef uint64_t __wasi_inode_t; + +ALIGNED_TYPE(uint64_t, 8) __wasi_linkcount_t; + +typedef uint32_t __wasi_lookupflags_t; +#define __WASI_LOOKUP_SYMLINK_FOLLOW (0x00000001) + +typedef uint16_t __wasi_oflags_t; +#define __WASI_O_CREAT (0x0001) +#define __WASI_O_DIRECTORY (0x0002) +#define __WASI_O_EXCL (0x0004) +#define __WASI_O_TRUNC (0x0008) + +typedef uint16_t __wasi_riflags_t; +#define __WASI_SOCK_RECV_PEEK (0x0001) +#define __WASI_SOCK_RECV_WAITALL (0x0002) + +typedef uint64_t __wasi_rights_t; + +/** + * Observe that WASI defines rights in the plural form + * TODO: refactor to use RIGHTS instead of RIGHT + */ +#define __WASI_RIGHT_FD_DATASYNC ((__wasi_rights_t)(UINT64_C(1) << 0)) +#define __WASI_RIGHT_FD_READ ((__wasi_rights_t)(UINT64_C(1) << 1)) +#define __WASI_RIGHT_FD_SEEK ((__wasi_rights_t)(UINT64_C(1) << 2)) +#define __WASI_RIGHT_FD_FDSTAT_SET_FLAGS ((__wasi_rights_t)(UINT64_C(1) << 3)) +#define __WASI_RIGHT_FD_SYNC ((__wasi_rights_t)(UINT64_C(1) << 4)) +#define __WASI_RIGHT_FD_TELL ((__wasi_rights_t)(UINT64_C(1) << 5)) +#define __WASI_RIGHT_FD_WRITE ((__wasi_rights_t)(UINT64_C(1) << 6)) +#define __WASI_RIGHT_FD_ADVISE ((__wasi_rights_t)(UINT64_C(1) << 7)) +#define __WASI_RIGHT_FD_ALLOCATE ((__wasi_rights_t)(UINT64_C(1) << 8)) +#define __WASI_RIGHT_PATH_CREATE_DIRECTORY ((__wasi_rights_t)(UINT64_C(1) << 9)) +#define __WASI_RIGHT_PATH_CREATE_FILE ((__wasi_rights_t)(UINT64_C(1) << 10)) +#define __WASI_RIGHT_PATH_LINK_SOURCE ((__wasi_rights_t)(UINT64_C(1) << 11)) +#define __WASI_RIGHT_PATH_LINK_TARGET ((__wasi_rights_t)(UINT64_C(1) << 12)) +#define __WASI_RIGHT_PATH_OPEN ((__wasi_rights_t)(UINT64_C(1) << 13)) +#define __WASI_RIGHT_FD_READDIR ((__wasi_rights_t)(UINT64_C(1) << 14)) +#define __WASI_RIGHT_PATH_READLINK ((__wasi_rights_t)(UINT64_C(1) << 15)) +#define __WASI_RIGHT_PATH_RENAME_SOURCE ((__wasi_rights_t)(UINT64_C(1) << 16)) +#define __WASI_RIGHT_PATH_RENAME_TARGET ((__wasi_rights_t)(UINT64_C(1) << 17)) +#define __WASI_RIGHT_PATH_FILESTAT_GET ((__wasi_rights_t)(UINT64_C(1) << 18)) +#define __WASI_RIGHT_PATH_FILESTAT_SET_SIZE ((__wasi_rights_t)(UINT64_C(1) << 19)) +#define __WASI_RIGHT_PATH_FILESTAT_SET_TIMES ((__wasi_rights_t)(UINT64_C(1) << 20)) +#define __WASI_RIGHT_FD_FILESTAT_GET ((__wasi_rights_t)(UINT64_C(1) << 21)) +#define __WASI_RIGHT_FD_FILESTAT_SET_SIZE ((__wasi_rights_t)(UINT64_C(1) << 22)) +#define __WASI_RIGHT_FD_FILESTAT_SET_TIMES ((__wasi_rights_t)(UINT64_C(1) << 23)) +#define __WASI_RIGHT_PATH_SYMLINK ((__wasi_rights_t)(UINT64_C(1) << 24)) +#define __WASI_RIGHT_PATH_REMOVE_DIRECTORY ((__wasi_rights_t)(UINT64_C(1) << 25)) +#define __WASI_RIGHT_PATH_UNLINK_FILE ((__wasi_rights_t)(UINT64_C(1) << 26)) +#define __WASI_RIGHT_POLL_FD_READWRITE ((__wasi_rights_t)(UINT64_C(1) << 27)) +#define __WASI_RIGHT_SOCK_CONNECT ((__wasi_rights_t)(UINT64_C(1) << 28)) +#define __WASI_RIGHT_SOCK_LISTEN ((__wasi_rights_t)(UINT64_C(1) << 29)) +#define __WASI_RIGHT_SOCK_BIND ((__wasi_rights_t)(UINT64_C(1) << 30)) +#define __WASI_RIGHT_SOCK_ACCEPT ((__wasi_rights_t)(UINT64_C(1) << 31)) +#define __WASI_RIGHT_SOCK_RECV ((__wasi_rights_t)(UINT64_C(1) << 32)) +#define __WASI_RIGHT_SOCK_SEND ((__wasi_rights_t)(UINT64_C(1) << 33)) +#define __WASI_RIGHT_SOCK_ADDR_LOCAL ((__wasi_rights_t)(UINT64_C(1) << 34)) +#define __WASI_RIGHT_SOCK_ADDR_REMOTE ((__wasi_rights_t)(UINT64_C(1) << 35)) +#define __WASI_RIGHT_SOCK_RECV_FROM ((__wasi_rights_t)(UINT64_C(1) << 36)) +#define __WASI_RIGHT_SOCK_SEND_TO ((__wasi_rights_t)(UINT64_C(1) << 37)) + +typedef uint16_t __wasi_roflags_t; +#define __WASI_SOCK_RECV_DATA_TRUNCATED (0x0001) + +typedef uint8_t __wasi_sdflags_t; +#define __WASI_SHUT_RD (0x01) +#define __WASI_SHUT_WR (0x02) + +typedef uint16_t __wasi_siflags_t; + +typedef uint8_t __wasi_signal_t; + +typedef uint16_t __wasi_subclockflags_t; +#define __WASI_SUBSCRIPTION_CLOCK_ABSTIME (0x0001) + +typedef uint64_t __wasi_timestamp_t; + +typedef uint64_t __wasi_userdata_t; + +typedef uint8_t __wasi_whence_t; +#define __WASI_WHENCE_SET (0) +#define __WASI_WHENCE_CUR (1) +#define __WASI_WHENCE_END (2) + +typedef uint8_t __wasi_preopentype_t; +#define __WASI_PREOPENTYPE_DIR (0) + +struct fd_table; +struct fd_prestats; +struct argv_environ_values; +struct addr_pool; + +typedef struct ALIGNED_(8) __wasi_dirent_t { + __wasi_dircookie_t d_next; + __wasi_inode_t d_ino; + __wasi_dirnamlen_t d_namlen; + __wasi_filetype_t d_type; +} __wasi_dirent_t; +assert_wasi_layout(offsetof(__wasi_dirent_t, d_next) == 0, "non-wasi data layout"); +assert_wasi_layout(offsetof(__wasi_dirent_t, d_ino) == 8, "non-wasi data layout"); +assert_wasi_layout(offsetof(__wasi_dirent_t, d_namlen) == 16, "non-wasi data layout"); +assert_wasi_layout(offsetof(__wasi_dirent_t, d_type) == 20, "non-wasi data layout"); +assert_wasi_layout(sizeof(__wasi_dirent_t) == 24, "non-wasi data layout"); +assert_wasi_layout(_Alignof(__wasi_dirent_t) == 8, "non-wasi data layout"); + +typedef struct ALIGNED_(8) __wasi_event_t { + __wasi_userdata_t userdata; + __wasi_errno_t error; + __wasi_eventtype_t type; + uint8_t __paddings[5]; + union __wasi_event_u { + struct __wasi_event_u_fd_readwrite_t { + __wasi_filesize_t nbytes; + __wasi_eventrwflags_t flags; + uint8_t __paddings[6]; + } fd_readwrite; + } u; +} __wasi_event_t; +assert_wasi_layout(offsetof(__wasi_event_t, userdata) == 0, "non-wasi data layout"); +assert_wasi_layout(offsetof(__wasi_event_t, error) == 8, "non-wasi data layout"); +assert_wasi_layout(offsetof(__wasi_event_t, type) == 10, "non-wasi data layout"); +assert_wasi_layout( + offsetof(__wasi_event_t, u.fd_readwrite.nbytes) == 16, "non-wasi data layout"); +assert_wasi_layout( + offsetof(__wasi_event_t, u.fd_readwrite.flags) == 24, "non-wasi data layout"); +assert_wasi_layout(sizeof(__wasi_event_t) == 32, "non-wasi data layout"); +assert_wasi_layout(_Alignof(__wasi_event_t) == 8, "non-wasi data layout"); + +typedef struct __wasi_prestat_t { + __wasi_preopentype_t pr_type; + union __wasi_prestat_u { + struct __wasi_prestat_u_dir_t { + size_t pr_name_len; + } dir; + } u; +} __wasi_prestat_t; +assert_wasi_layout(offsetof(__wasi_prestat_t, pr_type) == 0, "non-wasi data layout"); +assert_wasi_layout(sizeof(void *) != 4 || + offsetof(__wasi_prestat_t, u.dir.pr_name_len) == 4, "non-wasi data layout"); +assert_wasi_layout(sizeof(void *) != 8 || + offsetof(__wasi_prestat_t, u.dir.pr_name_len) == 8, "non-wasi data layout"); +assert_wasi_layout(sizeof(void *) != 4 || + sizeof(__wasi_prestat_t) == 8, "non-wasi data layout"); +assert_wasi_layout(sizeof(void *) != 8 || + sizeof(__wasi_prestat_t) == 16, "non-wasi data layout"); +assert_wasi_layout(sizeof(void *) != 4 || + _Alignof(__wasi_prestat_t) == 4, "non-wasi data layout"); +assert_wasi_layout(sizeof(void *) != 8 || + _Alignof(__wasi_prestat_t) == 8, "non-wasi data layout"); + +typedef struct ALIGNED_(8) __wasi_fdstat_t { + __wasi_filetype_t fs_filetype; + __wasi_fdflags_t fs_flags; + uint8_t __paddings[4]; + __wasi_rights_t fs_rights_base; + __wasi_rights_t fs_rights_inheriting; +} __wasi_fdstat_t; +assert_wasi_layout( + offsetof(__wasi_fdstat_t, fs_filetype) == 0, "non-wasi data layout"); +assert_wasi_layout(offsetof(__wasi_fdstat_t, fs_flags) == 2, "non-wasi data layout"); +assert_wasi_layout( + offsetof(__wasi_fdstat_t, fs_rights_base) == 8, "non-wasi data layout"); +assert_wasi_layout( + offsetof(__wasi_fdstat_t, fs_rights_inheriting) == 16, + "non-wasi data layout"); +assert_wasi_layout(sizeof(__wasi_fdstat_t) == 24, "non-wasi data layout"); +assert_wasi_layout(_Alignof(__wasi_fdstat_t) == 8, "non-wasi data layout"); + +typedef struct ALIGNED_(8) __wasi_filestat_t { + __wasi_device_t st_dev; + __wasi_inode_t st_ino; + __wasi_filetype_t st_filetype; + __wasi_linkcount_t st_nlink; + __wasi_filesize_t st_size; + __wasi_timestamp_t st_atim; + __wasi_timestamp_t st_mtim; + __wasi_timestamp_t st_ctim; +} __wasi_filestat_t; +assert_wasi_layout(offsetof(__wasi_filestat_t, st_dev) == 0, "non-wasi data layout"); +assert_wasi_layout(offsetof(__wasi_filestat_t, st_ino) == 8, "non-wasi data layout"); +assert_wasi_layout( + offsetof(__wasi_filestat_t, st_filetype) == 16, "non-wasi data layout"); +assert_wasi_layout( + offsetof(__wasi_filestat_t, st_nlink) == 24, "non-wasi data layout"); +assert_wasi_layout( + offsetof(__wasi_filestat_t, st_size) == 32, "non-wasi data layout"); +assert_wasi_layout( + offsetof(__wasi_filestat_t, st_atim) == 40, "non-wasi data layout"); +assert_wasi_layout( + offsetof(__wasi_filestat_t, st_mtim) == 48, "non-wasi data layout"); +assert_wasi_layout( + offsetof(__wasi_filestat_t, st_ctim) == 56, "non-wasi data layout"); +assert_wasi_layout(sizeof(__wasi_filestat_t) == 64, "non-wasi data layout"); +assert_wasi_layout(_Alignof(__wasi_filestat_t) == 8, "non-wasi data layout"); + +typedef struct __wasi_ciovec_t { + const void *buf; + size_t buf_len; +} __wasi_ciovec_t; +assert_wasi_layout(offsetof(__wasi_ciovec_t, buf) == 0, "non-wasi data layout"); +assert_wasi_layout(sizeof(void *) != 4 || + offsetof(__wasi_ciovec_t, buf_len) == 4, "non-wasi data layout"); +assert_wasi_layout(sizeof(void *) != 8 || + offsetof(__wasi_ciovec_t, buf_len) == 8, "non-wasi data layout"); +assert_wasi_layout(sizeof(void *) != 4 || + sizeof(__wasi_ciovec_t) == 8, "non-wasi data layout"); +assert_wasi_layout(sizeof(void *) != 8 || + sizeof(__wasi_ciovec_t) == 16, "non-wasi data layout"); +assert_wasi_layout(sizeof(void *) != 4 || + _Alignof(__wasi_ciovec_t) == 4, "non-wasi data layout"); +assert_wasi_layout(sizeof(void *) != 8 || + _Alignof(__wasi_ciovec_t) == 8, "non-wasi data layout"); + +typedef struct __wasi_iovec_t { + void *buf; + size_t buf_len; +} __wasi_iovec_t; +assert_wasi_layout(offsetof(__wasi_iovec_t, buf) == 0, "non-wasi data layout"); +assert_wasi_layout(sizeof(void *) != 4 || + offsetof(__wasi_iovec_t, buf_len) == 4, "non-wasi data layout"); +assert_wasi_layout(sizeof(void *) != 8 || + offsetof(__wasi_iovec_t, buf_len) == 8, "non-wasi data layout"); +assert_wasi_layout(sizeof(void *) != 4 || + sizeof(__wasi_iovec_t) == 8, "non-wasi data layout"); +assert_wasi_layout(sizeof(void *) != 8 || + sizeof(__wasi_iovec_t) == 16, "non-wasi data layout"); +assert_wasi_layout(sizeof(void *) != 4 || + _Alignof(__wasi_iovec_t) == 4, "non-wasi data layout"); +assert_wasi_layout(sizeof(void *) != 8 || + _Alignof(__wasi_iovec_t) == 8, "non-wasi data layout"); + +/** + * The contents of a `subscription` when type is `eventtype::clock`. + */ +typedef struct ALIGNED_(8) __wasi_subscription_clock_t { + /** + * The clock against which to compare the timestamp. + */ + __wasi_clockid_t clock_id; + + uint8_t __paddings1[4]; + + /** + * The absolute or relative timestamp. + */ + __wasi_timestamp_t timeout; + + /** + * The amount of time that the implementation may wait additionally + * to coalesce with other events. + */ + __wasi_timestamp_t precision; + + /** + * Flags specifying whether the timeout is absolute or relative + */ + __wasi_subclockflags_t flags; + + uint8_t __paddings2[4]; + +} __wasi_subscription_clock_t; + +assert_wasi_layout(sizeof(__wasi_subscription_clock_t) == 32, "witx calculated size"); +assert_wasi_layout(_Alignof(__wasi_subscription_clock_t) == 8, "witx calculated align"); +assert_wasi_layout(offsetof(__wasi_subscription_clock_t, clock_id) == 0, "witx calculated offset"); +assert_wasi_layout(offsetof(__wasi_subscription_clock_t, timeout) == 8, "witx calculated offset"); +assert_wasi_layout(offsetof(__wasi_subscription_clock_t, precision) == 16, "witx calculated offset"); +assert_wasi_layout(offsetof(__wasi_subscription_clock_t, flags) == 24, "witx calculated offset"); + +/** + * The contents of a `subscription` when type is type is + * `eventtype::fd_read` or `eventtype::fd_write`. + */ +typedef struct __wasi_subscription_fd_readwrite_t { + /** + * The file descriptor on which to wait for it to become ready for reading or writing. + */ + __wasi_fd_t fd; + +} __wasi_subscription_fd_readwrite_t; + +assert_wasi_layout(sizeof(__wasi_subscription_fd_readwrite_t) == 4, "witx calculated size"); +assert_wasi_layout(_Alignof(__wasi_subscription_fd_readwrite_t) == 4, "witx calculated align"); +assert_wasi_layout(offsetof(__wasi_subscription_fd_readwrite_t, fd) == 0, "witx calculated offset"); + +/** + * The contents of a `subscription`. + */ +typedef union __wasi_subscription_u_u_t { + __wasi_subscription_clock_t clock; + __wasi_subscription_fd_readwrite_t fd_readwrite; +} __wasi_subscription_u_u_t ; + +typedef struct ALIGNED_(8) __wasi_subscription_u_t { + __wasi_eventtype_t type; + __wasi_subscription_u_u_t u; +} __wasi_subscription_u_t; + +assert_wasi_layout(sizeof(__wasi_subscription_u_t) == 40, "witx calculated size"); +assert_wasi_layout(_Alignof(__wasi_subscription_u_t) == 8, "witx calculated align"); +assert_wasi_layout(offsetof(__wasi_subscription_u_t, u) == 8, "witx calculated union offset"); +assert_wasi_layout(sizeof(__wasi_subscription_u_u_t) == 32, "witx calculated union size"); +assert_wasi_layout(_Alignof(__wasi_subscription_u_u_t) == 8, "witx calculated union align"); + +/** + * Subscription to an event. + */ +typedef struct __wasi_subscription_t { + /** + * User-provided value that is attached to the subscription in the + * implementation and returned through `event::userdata`. + */ + __wasi_userdata_t userdata; + + /** + * The type of the event to which to subscribe, and its contents + */ + __wasi_subscription_u_t u; + +} __wasi_subscription_t; + +assert_wasi_layout(sizeof(__wasi_subscription_t) == 48, "witx calculated size"); +assert_wasi_layout(_Alignof(__wasi_subscription_t) == 8, "witx calculated align"); +assert_wasi_layout(offsetof(__wasi_subscription_t, userdata) == 0, "witx calculated offset"); +assert_wasi_layout(offsetof(__wasi_subscription_t, u) == 8, "witx calculated offset"); + +/* keep syncing with wasi_socket_ext.h */ +typedef enum { + /* Used only for sock_addr_resolve hints */ + SOCKET_ANY = -1, + SOCKET_DGRAM = 0, + SOCKET_STREAM, +} __wasi_sock_type_t; + +typedef uint16_t __wasi_ip_port_t; + +typedef enum { IPv4 = 0, IPv6 } __wasi_addr_type_t; + +/* n0.n1.n2.n3 */ +typedef struct __wasi_addr_ip4_t { + uint8_t n0; + uint8_t n1; + uint8_t n2; + uint8_t n3; +} __wasi_addr_ip4_t; + +typedef struct __wasi_addr_ip4_port_t { + __wasi_addr_ip4_t addr; + __wasi_ip_port_t port; +} __wasi_addr_ip4_port_t; + +typedef struct __wasi_addr_ip6_t { + uint16_t n0; + uint16_t n1; + uint16_t n2; + uint16_t n3; + uint16_t h0; + uint16_t h1; + uint16_t h2; + uint16_t h3; +} __wasi_addr_ip6_t; + +typedef struct __wasi_addr_ip6_port_t { + __wasi_addr_ip6_t addr; + __wasi_ip_port_t port; +} __wasi_addr_ip6_port_t; + +typedef struct __wasi_addr_ip_t { + __wasi_addr_type_t kind; + union { + __wasi_addr_ip4_t ip4; + __wasi_addr_ip6_t ip6; + } addr; +} __wasi_addr_ip_t; + +typedef struct __wasi_addr_t { + __wasi_addr_type_t kind; + union { + __wasi_addr_ip4_port_t ip4; + __wasi_addr_ip6_port_t ip6; + } addr; +} __wasi_addr_t; + +typedef enum { INET4 = 0, INET6, INET_UNSPEC } __wasi_address_family_t; + +typedef struct __wasi_addr_info_t { + __wasi_addr_t addr; + __wasi_sock_type_t type; +} __wasi_addr_info_t; + +typedef struct __wasi_addr_info_hints_t { + __wasi_sock_type_t type; + __wasi_address_family_t family; + // this is to workaround lack of optional parameters + uint8_t hints_enabled; +} __wasi_addr_info_hints_t; + +#undef assert_wasi_layout + +/* clang-format on */ +#ifdef __cplusplus +} +#endif + +#endif /* end of _PLATFORM_WASI_TYPES_H */ \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/platform_internal.h similarity index 89% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/platform_internal.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/platform_internal.h index d18f015ee1f..c96768e321d 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/platform_internal.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/platform_internal.h @@ -50,6 +50,7 @@ typedef pthread_t korp_thread; typedef pthread_t korp_tid; typedef pthread_mutex_t korp_mutex; typedef pthread_cond_t korp_cond; +typedef pthread_rwlock_t korp_rwlock; typedef unsigned int korp_sem; #ifndef SGX_DISABLE_PTHREAD @@ -68,6 +69,16 @@ strcpy(char *dest, const char *src); #define os_memory_order_seq_cst __ATOMIC_SEQ_CST #define os_atomic_thread_fence __atomic_thread_fence +typedef int os_file_handle; +typedef DIR *os_dir_stream; +typedef int os_raw_file_handle; + +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #ifdef __cplusplus } #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_file.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_file.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_file.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_file.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_file.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_file.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_file.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_file.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_ipfs.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_ipfs.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_ipfs.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_ipfs.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_ipfs.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_ipfs.h similarity index 97% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_ipfs.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_ipfs.h index e4de90274f4..3a911d2b6ed 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_ipfs.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_ipfs.h @@ -7,7 +7,6 @@ #define _LIBC_WASI_SGX_PFS_H #include "bh_hashmap.h" -#include "wasmtime_ssp.h" #ifdef __cplusplus extern "C" { diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_platform.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_platform.c similarity index 91% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_platform.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_platform.c index b40eaf79c43..32b95682670 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_platform.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_platform.c @@ -120,13 +120,20 @@ strcpy(char *dest, const char *src) } void * -os_mmap(void *hint, size_t size, int prot, int flags) +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) { int mprot = 0; uint64 aligned_size, page_size; void *ret = NULL; sgx_status_t st = 0; + if (os_is_handle_valid(&file)) { + os_printf("os_mmap(size=%u, prot=0x%x, file=%x) failed: file is not " + "supported.\n", + size, prot, file); + return NULL; + } + page_size = getpagesize(); aligned_size = (size + page_size - 1) & ~(page_size - 1); @@ -195,3 +202,7 @@ os_mprotect(void *addr, size_t size, int prot) void os_dcache_flush(void) {} + +void +os_icache_flush(void *start, size_t len) +{} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_pthread.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_pthread.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_pthread.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_pthread.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_pthread.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_pthread.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_pthread.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_pthread.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_rsrv_mem_mngr.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_rsrv_mem_mngr.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_rsrv_mem_mngr.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_rsrv_mem_mngr.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_signal.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_signal.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_signal.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_signal.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_signal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_signal.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_signal.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_signal.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_socket.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_socket.c similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_socket.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_socket.c index afb6d6014bf..cd1a6ceade8 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_socket.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_socket.c @@ -5,6 +5,7 @@ #include "platform_api_vmcore.h" #include "platform_api_extension.h" +#include "libc_errno.h" #ifndef SGX_DISABLE_WASI @@ -261,7 +262,7 @@ sockaddr_to_bh_sockaddr(const struct sockaddr *sockaddr, socklen_t socklen, assert(socklen >= sizeof(struct sockaddr_in)); bh_sockaddr->port = ntohs(addr->sin_port); - bh_sockaddr->addr_bufer.ipv4 = ntohl(addr->sin_addr.s_addr); + bh_sockaddr->addr_buffer.ipv4 = ntohl(addr->sin_addr.s_addr); bh_sockaddr->is_ipv4 = true; return BHT_OK; } @@ -279,7 +280,7 @@ bh_sockaddr_to_sockaddr(const bh_sockaddr_t *bh_sockaddr, struct sockaddr_in *addr = (struct sockaddr_in *)sockaddr; addr->sin_port = htons(bh_sockaddr->port); addr->sin_family = AF_INET; - addr->sin_addr.s_addr = htonl(bh_sockaddr->addr_bufer.ipv4); + addr->sin_addr.s_addr = htonl(bh_sockaddr->addr_buffer.ipv4); *socklen = sizeof(*addr); return BHT_OK; } @@ -855,10 +856,13 @@ os_socket_send_to(bh_socket_t socket, const void *buf, unsigned int len, return ret; } -int +__wasi_errno_t os_socket_shutdown(bh_socket_t socket) { - return shutdown(socket, O_RDWR); + if (shutdown(socket, O_RDWR) != 0) { + return convert_errno(errno); + } + return __WASI_ESUCCESS; } int diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_socket.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_socket.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_socket.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_socket.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_thread.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_thread.c similarity index 78% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_thread.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_thread.c index 1cb2f5d09a3..73f3005fab2 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_thread.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_thread.c @@ -210,3 +210,72 @@ os_thread_get_stack_boundary() /* TODO: get sgx stack boundary */ return NULL; } + +void +os_thread_jit_write_protect_np(bool enabled) +{} + +int +os_rwlock_init(korp_rwlock *lock) +{ +#ifndef SGX_DISABLE_PTHREAD + assert(lock); + + if (pthread_rwlock_init(lock, NULL) != BHT_OK) + return BHT_ERROR; +#endif + + return BHT_OK; +} + +int +os_rwlock_rdlock(korp_rwlock *lock) +{ +#ifndef SGX_DISABLE_PTHREAD + assert(lock); + + if (pthread_rwlock_rdlock(lock) != BHT_OK) + return BHT_ERROR; +#endif + + return BHT_OK; +} + +int +os_rwlock_wrlock(korp_rwlock *lock) +{ +#ifndef SGX_DISABLE_PTHREAD + assert(lock); + + if (pthread_rwlock_wrlock(lock) != BHT_OK) + return BHT_ERROR; +#endif + + return BHT_OK; +} + +int +os_rwlock_unlock(korp_rwlock *lock) +{ +#ifndef SGX_DISABLE_PTHREAD + assert(lock); + + if (pthread_rwlock_unlock(lock) != BHT_OK) + return BHT_ERROR; +#endif + + return BHT_OK; +} + +int +os_rwlock_destroy(korp_rwlock *lock) +{ +#ifndef SGX_DISABLE_PTHREAD + assert(lock); + + if (pthread_rwlock_destroy(lock) != BHT_OK) + return BHT_ERROR; +#endif + + return BHT_OK; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_time.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_time.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_time.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_time.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_time.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_time.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_time.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_time.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_wamr.edl b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_wamr.edl similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/sgx_wamr.edl rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/sgx_wamr.edl diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/shared_platform.cmake similarity index 76% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/shared_platform.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/shared_platform.cmake index b2de1ab06a6..e8e1670058f 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/shared_platform.cmake +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/shared_platform.cmake @@ -20,16 +20,23 @@ if (NOT BUILD_UNTRUST_PART EQUAL 1) ${SGX_SDK_DIR}/include/libcxx) endif () -if (NOT WAMR_BUILD_LIBC_WASI EQUAL 1) - add_definitions(-DSGX_DISABLE_WASI) -endif () - if (NOT WAMR_BUILD_THREAD_MGR EQUAL 1) add_definitions(-DSGX_DISABLE_PTHREAD) endif () file (GLOB source_all ${PLATFORM_SHARED_DIR}/*.c) +if (NOT WAMR_BUILD_LIBC_WASI EQUAL 1) + add_definitions(-DSGX_DISABLE_WASI) +else() + list(APPEND source_all + ${PLATFORM_SHARED_DIR}/../common/posix/posix_file.c + ${PLATFORM_SHARED_DIR}/../common/posix/posix_clock.c + ) + include (${CMAKE_CURRENT_LIST_DIR}/../common/libc-util/platform_common_libc_util.cmake) + set(source_all ${source_all} ${PLATFORM_COMMON_LIBC_UTIL_SOURCE}) +endif() + file (GLOB source_all_untrusted ${PLATFORM_SHARED_DIR}/untrusted/*.c) set (PLATFORM_SHARED_SOURCE ${source_all}) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/file.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/file.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/file.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/file.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/pthread.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/pthread.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/pthread.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/pthread.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/signal.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/signal.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/signal.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/signal.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/socket.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/socket.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/socket.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/socket.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/time.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/time.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux-sgx/untrusted/time.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux-sgx/untrusted/time.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/vxworks/platform_init.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux/platform_init.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/vxworks/platform_init.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux/platform_init.c diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux/platform_internal.h new file mode 100644 index 00000000000..335070bf80f --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux/platform_internal.h @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#ifndef _PLATFORM_INTERNAL_H +#define _PLATFORM_INTERNAL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef BH_PLATFORM_LINUX +#define BH_PLATFORM_LINUX +#endif + +/* Stack size of applet threads's native part. */ +#define BH_APPLET_PRESERVED_STACK_SIZE (32 * 1024) + +/* Default thread priority */ +#define BH_THREAD_DEFAULT_PRIORITY 0 + +typedef pthread_t korp_tid; +typedef pthread_mutex_t korp_mutex; +typedef pthread_cond_t korp_cond; +typedef pthread_t korp_thread; +typedef pthread_rwlock_t korp_rwlock; +typedef sem_t korp_sem; + +#define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER + +#define os_thread_local_attribute __thread + +#define bh_socket_t int + +#if WASM_DISABLE_WRITE_GS_BASE == 0 +#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) +#define os_writegsbase(base_addr) \ + do { \ + uint64 __gs_value = (uint64)(uintptr_t)base_addr; \ + asm volatile("wrgsbase %0" ::"r"(__gs_value) : "memory"); \ + } while (0) +#if 0 +/* _writegsbase_u64 also works, but need to add -mfsgsbase flag for gcc */ +#include +#define os_writegsbase(base_addr) \ + _writegsbase_u64(((uint64)(uintptr_t)base_addr)) +#endif +#endif +#endif + +#if WASM_DISABLE_HW_BOUND_CHECK == 0 +#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \ + || defined(BUILD_TARGET_AARCH64) || defined(BUILD_TARGET_RISCV64_LP64D) \ + || defined(BUILD_TARGET_RISCV64_LP64) + +#include + +#define OS_ENABLE_HW_BOUND_CHECK + +typedef jmp_buf korp_jmpbuf; + +#define os_setjmp setjmp +#define os_longjmp longjmp +#define os_alloca alloca + +#define os_getpagesize getpagesize + +typedef void (*os_signal_handler)(void *sig_addr); + +int +os_thread_signal_init(os_signal_handler handler); + +void +os_thread_signal_destroy(); + +bool +os_thread_signal_inited(); + +void +os_signal_unmask(); + +void +os_sigreturn(); +#endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64/RISCV64 */ +#endif /* end of WASM_DISABLE_HW_BOUND_CHECK */ + +#if WASM_DISABLE_WAKEUP_BLOCKING_OP == 0 +#define OS_ENABLE_WAKEUP_BLOCKING_OP +#endif +void +os_set_signal_number_for_blocking_op(int signo); + +typedef int os_file_handle; +typedef DIR *os_dir_stream; +typedef int os_raw_file_handle; + +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + +#ifdef __cplusplus +} +#endif + +#endif /* end of _PLATFORM_INTERNAL_H */ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux/shared_platform.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/linux/shared_platform.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/linux/shared_platform.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/nuttx/nuttx_platform.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/nuttx/nuttx_platform.c similarity index 67% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/nuttx/nuttx_platform.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/nuttx/nuttx_platform.c index 9cb123e0172..38e70076d16 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/nuttx/nuttx_platform.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/nuttx/nuttx_platform.c @@ -10,6 +10,46 @@ #include #endif +#if defined(CONFIG_ARCH_CHIP_ESP32S3) +/* + * TODO: Move these methods below the operating system level + */ +#define MEM_DUAL_BUS_OFFSET (0x42000000 - 0x3C000000) +#define IRAM0_CACHE_ADDRESS_LOW 0x42000000 +#define IRAM0_CACHE_ADDRESS_HIGH 0x44000000 +#define IRAM_ATTR locate_data(".iram1") + +#define in_ibus_ext(addr) \ + (((uint32)addr >= IRAM0_CACHE_ADDRESS_LOW) \ + && ((uint32)addr < IRAM0_CACHE_ADDRESS_HIGH)) +void IRAM_ATTR +bus_sync(void) +{ + extern void cache_writeback_all(void); + extern uint32_t Cache_Disable_ICache(void); + extern void Cache_Enable_ICache(uint32_t autoload); + + irqstate_t flags; + uint32_t preload; + + flags = enter_critical_section(); + + cache_writeback_all(); + preload = Cache_Disable_ICache(); + Cache_Enable_ICache(preload); + + leave_critical_section(flags); +} +#else +#define MEM_DUAL_BUS_OFFSET (0) +#define IRAM0_CACHE_ADDRESS_LOW (0) +#define IRAM0_CACHE_ADDRESS_HIGH (0) +#define in_ibus_ext(addr) (0) +static void +bus_sync(void) +{} +#endif + int bh_platform_init() { @@ -45,8 +85,12 @@ os_dumps_proc_mem_info(char *out, unsigned int size) } void * -os_mmap(void *hint, size_t size, int prot, int flags) +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) { +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) + void *i_addr, *d_addr; +#endif + #if defined(CONFIG_ARCH_USE_TEXT_HEAP) if ((prot & MMAP_PROT_EXEC) != 0) { return up_textheap_memalign(sizeof(void *), size); @@ -55,6 +99,17 @@ os_mmap(void *hint, size_t size, int prot, int flags) if ((uint64)size >= UINT32_MAX) return NULL; + +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) + if ((prot & MMAP_PROT_EXEC) != 0) { + d_addr = malloc((uint32)size); + if (d_addr == NULL) { + return NULL; + } + i_addr = (void *)((uint8 *)d_addr + MEM_DUAL_BUS_OFFSET); + return in_ibus_ext(i_addr) ? i_addr : d_addr; + } +#endif return malloc((uint32)size); } @@ -67,7 +122,14 @@ os_munmap(void *addr, size_t size) return; } #endif - return free(addr); + +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) + if (in_ibus_ext(addr)) { + free((void *)((uint8 *)addr - MEM_DUAL_BUS_OFFSET)); + return; + } +#endif + free(addr); } int @@ -78,8 +140,27 @@ os_mprotect(void *addr, size_t size, int prot) void os_dcache_flush() +{ + bus_sync(); +} + +void +os_icache_flush(void *start, size_t len) {} +#if (WASM_MEM_DUAL_BUS_MIRROR != 0) +void * +os_get_dbus_mirror(void *ibus) +{ + if (in_ibus_ext(ibus)) { + return (void *)((uint8 *)ibus - MEM_DUAL_BUS_OFFSET); + } + else { + return ibus; + } +} +#endif + /* If AT_FDCWD is provided, maybe we have openat family */ #if !defined(AT_FDCWD) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/nuttx/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/nuttx/platform_internal.h similarity index 88% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/nuttx/platform_internal.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/nuttx/platform_internal.h index b5bbdacd04c..2fb80a6e3a8 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/nuttx/platform_internal.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/nuttx/platform_internal.h @@ -41,6 +41,7 @@ typedef pthread_t korp_tid; typedef pthread_mutex_t korp_mutex; typedef pthread_cond_t korp_cond; typedef pthread_t korp_thread; +typedef pthread_rwlock_t korp_rwlock; typedef sem_t korp_sem; #define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER @@ -123,6 +124,22 @@ utimensat(int fd, const char *path, const struct timespec ts[2], int flag); DIR * fdopendir(int fd); +#if WASM_DISABLE_WAKEUP_BLOCKING_OP == 0 +#define OS_ENABLE_WAKEUP_BLOCKING_OP +#endif +void +os_set_signal_number_for_blocking_op(int signo); + +typedef int os_file_handle; +typedef DIR *os_dir_stream; +typedef int os_raw_file_handle; + +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #ifdef __cplusplus } #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/nuttx/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/nuttx/shared_platform.cmake similarity index 61% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/nuttx/shared_platform.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/nuttx/shared_platform.cmake index 7b29b5f0925..1cbe2218b02 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/nuttx/shared_platform.cmake +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/nuttx/shared_platform.cmake @@ -10,5 +10,11 @@ include_directories(${PLATFORM_SHARED_DIR}/../include) file (GLOB_RECURSE source_all ${PLATFORM_SHARED_DIR}/*.c) +if (WAMR_BUILD_LIBC_WASI EQUAL 1) + list(APPEND source_all ${PLATFORM_SHARED_DIR}/../common/posix/posix_file.c) + include (${CMAKE_CURRENT_LIST_DIR}/../common/libc-util/platform_common_libc_util.cmake) + set(source_all ${source_all} ${PLATFORM_COMMON_LIBC_UTIL_SOURCE}) +endif () + set (PLATFORM_SHARED_SOURCE ${source_all} ${PLATFORM_COMMON_MATH_SOURCE}) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/riot/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/riot/platform_internal.h similarity index 80% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/riot/platform_internal.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/riot/platform_internal.h index 8fec6dd0b16..e88b25d4031 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/riot/platform_internal.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/riot/platform_internal.h @@ -40,6 +40,12 @@ typedef kernel_pid_t korp_tid; typedef mutex_t korp_mutex; typedef unsigned int korp_sem; +/* korp_rwlock is used in platform_api_extension.h, + we just define the type to make the compiler happy */ +typedef struct { + int dummy; +} korp_rwlock; + /* typedef sema_t korp_sem; */ struct os_thread_wait_node; @@ -52,6 +58,12 @@ typedef struct korp_cond { #define os_printf printf #define os_vprintf vprintf +/* The below types are used in platform_api_extension.h, + we just define them to make the compiler happy */ +typedef int os_file_handle; +typedef void *os_dir_stream; +typedef int os_raw_file_handle; + #if WA_MATH /* clang-format off */ /* math functions which are not provided by os*/ @@ -76,4 +88,10 @@ int isnan(double x); /* clang-format on */ #endif +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #endif /* end of _BH_PLATFORM_H */ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/riot/riot_platform.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/riot/riot_platform.c similarity index 90% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/riot/riot_platform.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/riot/riot_platform.c index a0c38e8c94c..ad5927e513b 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/riot/riot_platform.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/riot/riot_platform.c @@ -50,7 +50,7 @@ os_dumps_proc_mem_info(char *out, unsigned int size) } void * -os_mmap(void *hint, size_t size, int prot, int flags) +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) { if (size > ((unsigned)~0)) return NULL; @@ -79,3 +79,7 @@ os_dcache_flush(void) irq_unlock(key); #endif } + +void +os_icache_flush(void *start, size_t len) +{} \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/riot/riot_thread.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/riot/riot_thread.c similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/riot/riot_thread.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/riot/riot_thread.c index 0ebcf30e009..a9062bfece6 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/riot/riot_thread.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/riot/riot_thread.c @@ -430,3 +430,7 @@ os_thread_get_stack_boundary() return NULL; #endif } + +void +os_thread_jit_write_protect_np(bool enabled) +{} \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/riot/riot_time.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/riot/riot_time.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/riot/riot_time.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/riot/riot_time.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/riot/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/riot/shared_platform.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/riot/shared_platform.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/riot/shared_platform.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/rt-thread/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/rt-thread/SConscript similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/rt-thread/SConscript rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/rt-thread/SConscript diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/rt-thread/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/rt-thread/platform_internal.h similarity index 73% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/rt-thread/platform_internal.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/rt-thread/platform_internal.h index 5f9cc8bc80e..4ebdabb10b7 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/rt-thread/platform_internal.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/rt-thread/platform_internal.h @@ -38,6 +38,12 @@ typedef struct rt_thread korp_cond; typedef struct rt_thread korp_thread; typedef unsigned int korp_sem; +/* korp_rwlock is used in platform_api_extension.h, + we just define the type to make the compiler happy */ +typedef struct { + int dummy; +} korp_rwlock; + typedef rt_uint8_t uint8_t; typedef rt_int8_t int8_t; typedef rt_uint16_t uint16_t; @@ -45,4 +51,16 @@ typedef rt_int16_t int16_t; typedef rt_uint64_t uint64_t; typedef rt_int64_t int64_t; +/* The below types are used in platform_api_extension.h, + we just define them to make the compiler happy */ +typedef int os_file_handle; +typedef void *os_dir_stream; +typedef int os_raw_file_handle; + +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #endif /* RTTHREAD_PLATFORM_INTERNAL_H */ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/rt-thread/rtt_platform.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/rt-thread/rtt_platform.c similarity index 95% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/rt-thread/rtt_platform.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/rt-thread/rtt_platform.c index 4685e1ea318..37b247d35fe 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/rt-thread/rtt_platform.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/rt-thread/rtt_platform.c @@ -140,6 +140,10 @@ os_thread_get_stack_boundary(void) return tid->stack_addr; } +void +os_thread_jit_write_protect_np(bool enabled) +{} + int os_mutex_init(korp_mutex *mutex) { @@ -187,7 +191,7 @@ os_cond_wait(korp_cond *cond, korp_mutex *mutex) } void * -os_mmap(void *hint, size_t size, int prot, int flags) +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) { return rt_malloc(size); } @@ -207,3 +211,7 @@ os_mprotect(void *addr, size_t size, int prot) void os_dcache_flush(void) {} + +void +os_icache_flush(void *start, size_t len) +{} \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/rt-thread/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/rt-thread/shared_platform.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/rt-thread/shared_platform.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/rt-thread/shared_platform.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/vxworks/platform_init.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/vxworks/platform_init.c new file mode 100644 index 00000000000..2aae13fa14e --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/vxworks/platform_init.c @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "platform_api_vmcore.h" + +int +bh_platform_init() +{ + return 0; +} + +void +bh_platform_destroy() +{} + +int +os_printf(const char *format, ...) +{ + int ret = 0; + va_list ap; + + va_start(ap, format); +#ifndef BH_VPRINTF + ret += vprintf(format, ap); +#else + ret += BH_VPRINTF(format, ap); +#endif + va_end(ap); + + return ret; +} + +int +os_vprintf(const char *format, va_list ap) +{ +#ifndef BH_VPRINTF + return vprintf(format, ap); +#else + return BH_VPRINTF(format, ap); +#endif +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/vxworks/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/vxworks/platform_internal.h similarity index 91% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/vxworks/platform_internal.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/vxworks/platform_internal.h index f72f6032253..930ff7777bf 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/vxworks/platform_internal.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/vxworks/platform_internal.h @@ -54,12 +54,17 @@ typedef pthread_t korp_tid; typedef pthread_mutex_t korp_mutex; typedef pthread_cond_t korp_cond; typedef pthread_t korp_thread; +typedef pthread_rwlock_t korp_rwlock; typedef sem_t korp_sem; #define OS_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER #define os_thread_local_attribute __thread +typedef int os_file_handle; +typedef DIR *os_dir_stream; +typedef int os_raw_file_handle; + #if WASM_DISABLE_HW_BOUND_CHECK == 0 #if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \ || defined(BUILD_TARGET_AARCH64) @@ -95,6 +100,12 @@ os_sigreturn(); #endif /* end of BUILD_TARGET_X86_64/AMD_64/AARCH64 */ #endif /* end of WASM_DISABLE_HW_BOUND_CHECK */ +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #ifdef __cplusplus } #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/vxworks/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/vxworks/shared_platform.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/vxworks/shared_platform.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/vxworks/shared_platform.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/platform_init.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/platform_init.c similarity index 95% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/platform_init.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/platform_init.c index db5885387ea..96bcf9ab1a9 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/platform_init.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/platform_init.c @@ -73,3 +73,7 @@ os_getpagesize() void os_dcache_flush(void) {} + +void +os_icache_flush(void *start, size_t len) +{} \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/platform_internal.h similarity index 64% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/platform_internal.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/platform_internal.h index 500ab200c7f..8bb77e7cba4 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/platform_internal.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/platform_internal.h @@ -25,10 +25,14 @@ #include #include #include +#include #include #include #include #include +#include + +#include "platform_wasi_types.h" #ifdef __cplusplus extern "C" { @@ -57,6 +61,11 @@ typedef void *korp_tid; typedef void *korp_mutex; typedef void *korp_sem; +typedef struct { + SRWLOCK lock; + bool exclusive; +} korp_rwlock; + /** * Create the mutex when os_mutex_lock is called, and no need to * CloseHandle() for the static lock's lifetime, since @@ -76,8 +85,6 @@ typedef struct korp_cond { struct os_thread_wait_node *thread_wait_list_end; } korp_cond; -#define bh_socket_t SOCKET - unsigned os_getpagesize(); void * @@ -131,6 +138,61 @@ bh_atomic_thread_fence(int mem_order); #define os_atomic_thread_fence bh_atomic_thread_fence +typedef enum windows_handle_type { + windows_handle_type_socket, + windows_handle_type_file +} windows_handle_type; + +typedef enum windows_access_mode { + windows_access_mode_read = 1 << 0, + windows_access_mode_write = 1 << 1 +} windows_access_mode; + +typedef struct windows_handle { + windows_handle_type type; + __wasi_fdflags_t fdflags; + windows_access_mode access_mode; + union { + HANDLE handle; + SOCKET socket; + } raw; +} windows_handle; + +typedef struct windows_dir_stream { + // Enough space for the wide filename and the info struct itself + char info_buf[PATH_MAX * sizeof(wchar_t) + sizeof(FILE_ID_BOTH_DIR_INFO)]; + char current_entry_name[PATH_MAX]; + // An offset into info_buf to read the next entry from + DWORD cursor; + int cookie; + windows_handle *handle; +} windows_dir_stream; + +typedef windows_handle *os_file_handle; +typedef windows_dir_stream *os_dir_stream; + +#if WASM_ENABLE_UVWASI != 1 +typedef HANDLE os_raw_file_handle; +#else +typedef uint32_t os_raw_file_handle; +#endif + +#define bh_socket_t windows_handle * + +// UWP apps do not have stdout/stderr handles so provide a default +// implementation of vprintf on debug builds so output from WASI libc is sent to +// the debugger and not lost completely. +#if !defined(BH_VPRINTF) && !defined(NDEBUG) && WINAPI_PARTITION_DESKTOP == 0 +#define BH_VPRINTF uwp_print_to_debugger +#define UWP_DEFAULT_VPRINTF +#endif + +static inline os_file_handle +os_get_invalid_handle() +{ + return NULL; +} + #ifdef __cplusplus } #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/shared_platform.cmake similarity index 69% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/shared_platform.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/shared_platform.cmake index a68d6317767..3c531c17c4e 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/shared_platform.cmake +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/shared_platform.cmake @@ -13,6 +13,13 @@ include_directories(${PLATFORM_SHARED_DIR}/../include) file (GLOB_RECURSE source_all ${PLATFORM_SHARED_DIR}/*.c ${PLATFORM_SHARED_DIR}/*.cpp) +if (NOT WAMR_BUILD_LIBC_WASI EQUAL 1) + list(REMOVE_ITEM source_all ${PLATFORM_SHARED_DIR}/win_file.c) +else() + include (${CMAKE_CURRENT_LIST_DIR}/../common/libc-util/platform_common_libc_util.cmake) + set(source_all ${source_all} ${PLATFORM_COMMON_LIBC_UTIL_SOURCE}) +endif() + set (PLATFORM_SHARED_SOURCE ${source_all}) file (GLOB header ${PLATFORM_SHARED_DIR}/../include/*.h) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/win_atomic.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_atomic.cpp similarity index 72% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/win_atomic.cpp rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_atomic.cpp index 80e8ef51841..4e09405bb03 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/win_atomic.cpp +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_atomic.cpp @@ -14,8 +14,8 @@ void bh_atomic_thread_fence(int mem_order) { std::memory_order order = - (std::memory_order)(std::memory_order::memory_order_relaxed + mem_order - - os_memory_order_relaxed); + (std::memory_order)((int)std::memory_order::memory_order_relaxed + + mem_order - os_memory_order_relaxed); std::atomic_thread_fence(order); } diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_clock.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_clock.c new file mode 100644 index 00000000000..c96bdfb3b4f --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_clock.c @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2023 Amazon Inc. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "platform_api_extension.h" +#include +#include "win_util.h" + +#define NANOSECONDS_PER_SECOND 1000000000ULL +#define NANOSECONDS_PER_TICK 100 + +static __wasi_errno_t +calculate_monotonic_clock_frequency(uint64 *out_frequency) +{ + LARGE_INTEGER frequency; + if (!QueryPerformanceFrequency(&frequency)) + return convert_windows_error_code(GetLastError()); + + *out_frequency = (uint64)frequency.QuadPart; + return __WASI_ESUCCESS; +} + +static __wasi_errno_t +get_performance_counter_value(uint64 *out_counter) +{ + LARGE_INTEGER counter; + if (!QueryPerformanceCounter(&counter)) + return convert_windows_error_code(GetLastError()); + + *out_counter = counter.QuadPart; + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_clock_res_get(__wasi_clockid_t clock_id, __wasi_timestamp_t *resolution) +{ + __wasi_errno_t error = __WASI_ESUCCESS; + + switch (clock_id) { + case __WASI_CLOCK_MONOTONIC: + { + uint64 frequency; + error = calculate_monotonic_clock_frequency(&frequency); + + if (error != __WASI_ESUCCESS) + return error; + + const uint64 result = (uint64)NANOSECONDS_PER_SECOND / frequency; + *resolution = result; + return error; + } + case __WASI_CLOCK_REALTIME: + case __WASI_CLOCK_PROCESS_CPUTIME_ID: + case __WASI_CLOCK_THREAD_CPUTIME_ID: + { +#if WINAPI_PARTITION_DESKTOP + ULONG maximum_time; + ULONG minimum_time; + ULONG current_time; + NTSTATUS + status = NtQueryTimerResolution(&maximum_time, &minimum_time, + ¤t_time); + uint64 result = (uint64)current_time * NANOSECONDS_PER_TICK; + *resolution = result / (uint64)NANOSECONDS_PER_SECOND; + return error; +#else + return __WASI_ENOTSUP; +#endif + } + default: + return __WASI_EINVAL; + } +} + +__wasi_errno_t +os_clock_time_get(__wasi_clockid_t clock_id, __wasi_timestamp_t precision, + __wasi_timestamp_t *time) +{ + __wasi_errno_t error = __WASI_ESUCCESS; + + switch (clock_id) { + case __WASI_CLOCK_REALTIME: + { + FILETIME sys_now; +#if NTDDI_VERSION >= NTDDI_WIN8 + GetSystemTimePreciseAsFileTime(&sys_now); +#else + GetSystemTimeAsFileTime(&sys_now); +#endif + *time = convert_filetime_to_wasi_timestamp(&sys_now); + return BHT_OK; + } + case __WASI_CLOCK_MONOTONIC: + { + uint64 frequency; + error = calculate_monotonic_clock_frequency(&frequency); + + if (error != __WASI_ESUCCESS) + return error; + + uint64 counter; + error = get_performance_counter_value(&counter); + + if (error != __WASI_ESUCCESS) + return error; + + if (NANOSECONDS_PER_SECOND % frequency == 0) { + *time = counter * NANOSECONDS_PER_SECOND / frequency; + } + else { + uint64 seconds = counter / frequency; + uint64 fractions = counter % frequency; + *time = seconds * NANOSECONDS_PER_SECOND + + (fractions * NANOSECONDS_PER_SECOND) / frequency; + } + return error; + } + case __WASI_CLOCK_PROCESS_CPUTIME_ID: + case __WASI_CLOCK_THREAD_CPUTIME_ID: + { + FILETIME creation_time; + FILETIME exit_time; + FILETIME kernel_time; + FILETIME user_time; + + HANDLE handle = (clock_id == __WASI_CLOCK_PROCESS_CPUTIME_ID) + ? GetCurrentProcess() + : GetCurrentThread(); + + if (!GetProcessTimes(handle, &creation_time, &exit_time, + &kernel_time, &user_time)) + return convert_windows_error_code(GetLastError()); + + *time = convert_filetime_to_wasi_timestamp(&kernel_time) + + convert_filetime_to_wasi_timestamp(&user_time); + + return error; + } + default: + return __WASI_EINVAL; + } +} \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_file.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_file.c new file mode 100644 index 00000000000..2c4e19f8bc8 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_file.c @@ -0,0 +1,1447 @@ +/* + * Copyright (C) 2023 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "platform_api_extension.h" +#include "libc_errno.h" +#include "win_util.h" + +#include "PathCch.h" + +#pragma comment(lib, "Pathcch.lib") + +#define CHECK_VALID_HANDLE_WITH_RETURN_VALUE(win_handle, ret) \ + do { \ + if ((win_handle) == NULL \ + || ((win_handle)->type == windows_handle_type_socket \ + && (win_handle)->raw.socket == INVALID_SOCKET) \ + || ((win_handle)->type == windows_handle_type_file \ + && (win_handle)->raw.handle == INVALID_HANDLE_VALUE)) \ + return (ret); \ + \ + } while (0) + +#define CHECK_VALID_HANDLE(win_handle) \ + CHECK_VALID_HANDLE_WITH_RETURN_VALUE(win_handle, __WASI_EBADF) + +#define CHECK_VALID_FILE_HANDLE(win_handle) \ + do { \ + if ((win_handle) == NULL) \ + return __WASI_EBADF; \ + \ + if ((win_handle)->type == windows_handle_type_socket) \ + return __WASI_EINVAL; \ + \ + if (((win_handle)->type == windows_handle_type_file \ + && (win_handle)->raw.handle == INVALID_HANDLE_VALUE)) \ + return __WASI_EBADF; \ + \ + } while (0) + +#define CHECK_VALID_WIN_DIR_STREAM(win_dir_stream) \ + do { \ + if ((win_dir_stream) == NULL) \ + return __WASI_EINVAL; \ + CHECK_VALID_FILE_HANDLE((win_dir_stream)->handle); \ + } while (0) + +static __wasi_filetype_t +get_disk_filetype(DWORD attribute) +{ + if (attribute == INVALID_FILE_ATTRIBUTES) + return __WASI_FILETYPE_UNKNOWN; + if (attribute & FILE_ATTRIBUTE_REPARSE_POINT) + return __WASI_FILETYPE_SYMBOLIC_LINK; + if (attribute & FILE_ATTRIBUTE_DIRECTORY) + return __WASI_FILETYPE_DIRECTORY; + + return __WASI_FILETYPE_REGULAR_FILE; +} + +static __wasi_filetype_t +get_socket_filetype(SOCKET socket) +{ + char socket_type = 0; + int size = sizeof(socket_type); + + if (getsockopt(socket, SOL_SOCKET, SO_TYPE, &socket_type, &size) == 0) { + switch (socket_type) { + case SOCK_STREAM: + return __WASI_FILETYPE_SOCKET_STREAM; + case SOCK_DGRAM: + return __WASI_FILETYPE_SOCKET_DGRAM; + } + } + return __WASI_FILETYPE_UNKNOWN; +} + +static __wasi_errno_t +convert_windows_filetype(os_file_handle handle, DWORD filetype, + __wasi_filetype_t *out_filetype) +{ + __wasi_errno_t error = __WASI_ESUCCESS; + + switch (filetype) { + case FILE_TYPE_DISK: + FILE_ATTRIBUTE_TAG_INFO file_info; + + bool success = GetFileInformationByHandleEx( + handle->raw.handle, FileAttributeTagInfo, &file_info, + sizeof(file_info)); + + if (!success + || file_info.FileAttributes == INVALID_FILE_ATTRIBUTES) { + error = convert_windows_error_code(GetLastError()); + break; + } + + *out_filetype = get_disk_filetype(file_info.FileAttributes); + break; + case FILE_TYPE_CHAR: + *out_filetype = __WASI_FILETYPE_CHARACTER_DEVICE; + break; + case FILE_TYPE_PIPE: + if (handle->type == windows_handle_type_socket) + *out_filetype = get_socket_filetype(handle->raw.socket); + else + *out_filetype = __WASI_FILETYPE_BLOCK_DEVICE; + + break; + case FILE_TYPE_REMOTE: + case FILE_TYPE_UNKNOWN: + default: + *out_filetype = __WASI_FILETYPE_UNKNOWN; + } + + return error; +} + +// Converts the input string to a wchar string. +static __wasi_errno_t +convert_to_wchar(const char *str, wchar_t *buf, size_t buf_size) +{ + int converted_chars = + MultiByteToWideChar(CP_UTF8, 0, str, -1, buf, (int)buf_size); + + if (converted_chars == 0) + return convert_windows_error_code(GetLastError()); + + return __WASI_ESUCCESS; +} + +// Get the filepath for a handle. The size of the buffer should be specified in +// terms of wchar. +static __wasi_errno_t +get_handle_filepath(HANDLE handle, wchar_t *buf, DWORD buf_size) +{ + DWORD bufsize_in_chars = buf_size * (sizeof(wchar_t) / sizeof(char)); + DWORD size = GetFinalPathNameByHandleW( + handle, buf, bufsize_in_chars, FILE_NAME_NORMALIZED | VOLUME_NAME_NONE); + + if (size > bufsize_in_chars) + return __WASI_ENAMETOOLONG; + + if (size == 0) + return convert_windows_error_code(GetLastError()); + + return __WASI_ESUCCESS; +} + +static __wasi_errno_t +convert_hresult_error_code(HRESULT error_code) +{ + switch (error_code) { + case E_OUTOFMEMORY: + return __WASI_ENOMEM; + case E_INVALIDARG: + default: + return __WASI_EINVAL; + } +} + +// Returns the absolute filepath from the relative path to the directory +// associated with the provided handle. +static __wasi_errno_t +get_absolute_filepath(HANDLE handle, const char *relative_path, + wchar_t *absolute_path, size_t buf_len) +{ + wchar_t handle_path[PATH_MAX]; + + __wasi_errno_t error = get_handle_filepath(handle, handle_path, PATH_MAX); + + if (error != __WASI_ESUCCESS) + return error; + + wchar_t relative_wpath[PATH_MAX]; + error = convert_to_wchar(relative_path, relative_wpath, PATH_MAX); + + if (error != __WASI_ESUCCESS) + return error; + + HRESULT ret = + PathCchCombine(absolute_path, buf_len, handle_path, relative_wpath); + if (ret != S_OK) + error = convert_hresult_error_code(ret); + + return error; +} + +static bool +has_directory_attribute(DWORD attributes) +{ + if (attributes == INVALID_FILE_ATTRIBUTES) + return false; + + return (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0; +} + +static bool +is_directory(const wchar_t *path) +{ + DWORD attributes = GetFileAttributesW(path); + + return has_directory_attribute(attributes); +} + +static bool +has_symlink_attribute(DWORD attributes) +{ + if (attributes == INVALID_FILE_ATTRIBUTES) + return false; + + return (attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0; +} + +static bool +is_symlink(const wchar_t *path) +{ + DWORD attributes = GetFileAttributesW(path); + + return has_symlink_attribute(attributes); +} + +static void +init_dir_stream(os_dir_stream dir_stream, os_file_handle handle) +{ + dir_stream->cursor = 0; + dir_stream->handle = handle; + dir_stream->cookie = 0; +} + +// Advances to the next directory entry and optionally reads into to the +// provided buffer if not NULL. +static __wasi_errno_t +read_next_dir_entry(os_dir_stream dir_stream, FILE_ID_BOTH_DIR_INFO **out_entry) +{ + FILE_INFO_BY_HANDLE_CLASS file_info_class; + + if (dir_stream->cookie == 0) + file_info_class = FileIdBothDirectoryRestartInfo; + else + file_info_class = FileIdBothDirectoryInfo; + + if (dir_stream->cursor == 0 + && !GetFileInformationByHandleEx(dir_stream->handle->raw.handle, + file_info_class, dir_stream->info_buf, + sizeof(dir_stream->info_buf))) { + if (out_entry != NULL) + *out_entry = NULL; + DWORD win_error = GetLastError(); + // We've reached the end of the directory - return success + if (win_error == ERROR_NO_MORE_FILES) { + dir_stream->cookie = 0; + dir_stream->cursor = 0; + return __WASI_ESUCCESS; + } + + return convert_windows_error_code(win_error); + } + + FILE_ID_BOTH_DIR_INFO *current_info = + (FILE_ID_BOTH_DIR_INFO *)(dir_stream->info_buf + dir_stream->cursor); + + if (current_info->NextEntryOffset == 0) + dir_stream->cursor = 0; + else + dir_stream->cursor += current_info->NextEntryOffset; + + ++dir_stream->cookie; + + if (out_entry != NULL) + *out_entry = current_info; + else + return __WASI_ESUCCESS; + + // Convert and copy over the wchar filename into the entry_name buf + int ret = WideCharToMultiByte( + CP_UTF8, 0, current_info->FileName, + current_info->FileNameLength / (sizeof(wchar_t) / sizeof(char)), + dir_stream->current_entry_name, sizeof(dir_stream->current_entry_name), + NULL, NULL); + + if (ret == 0) + return convert_windows_error_code(GetLastError()); + + return __WASI_ESUCCESS; +} + +static HANDLE +create_handle(wchar_t *path, bool is_dir, bool follow_symlink, bool readonly) +{ + CREATEFILE2_EXTENDED_PARAMETERS create_params; + + create_params.dwSize = sizeof(create_params); + create_params.dwFileAttributes = FILE_ATTRIBUTE_NORMAL; + create_params.dwSecurityQosFlags = 0; + create_params.dwFileFlags = 0; + create_params.lpSecurityAttributes = NULL; + create_params.hTemplateFile = NULL; + + if (is_dir) { + create_params.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY; + create_params.dwFileFlags |= FILE_FLAG_BACKUP_SEMANTICS; + } + + if (!follow_symlink) + create_params.dwFileFlags |= FILE_FLAG_OPEN_REPARSE_POINT; + + DWORD desired_access = GENERIC_READ; + + if (!readonly) + desired_access |= GENERIC_WRITE; + else + create_params.dwFileAttributes |= FILE_ATTRIBUTE_READONLY; + + return CreateFile2(path, desired_access, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + OPEN_EXISTING, &create_params); +} + +#if WINAPI_PARTITION_DESKTOP == 0 +// Modifies the given path in place and replaces it with the filename component +// (including the extension) of the path. +static __wasi_errno_t +extract_filename_from_path(wchar_t *path, size_t buf_size) +{ + wchar_t extension[256]; + wchar_t filename[256]; + __wasi_errno_t error = __WASI_ESUCCESS; + + // Get the filename from the fullpath. + errno_t ret = + _wsplitpath_s(path, NULL, 0, NULL, 0, filename, 256, extension, 256); + if (ret != 0) { + error = convert_errno(ret); + return error; + } + + ret = wcscat_s(filename, 256, extension); + + if (ret != 0) { + error = convert_errno(ret); + return error; + } + + ret = wcscpy_s(path, buf_size, filename); + + if (ret != 0) + error = convert_errno(ret); + + return error; +} + +static __wasi_errno_t +get_handle_to_parent_directory(HANDLE handle, HANDLE *out_dir_handle) +{ + wchar_t path[PATH_MAX]; + __wasi_errno_t error = get_handle_filepath(handle, path, PATH_MAX); + + if (error != __WASI_ESUCCESS) + return error; + + wchar_t parent_dir_path[PATH_MAX]; + errno_t ret = wcscpy_s(parent_dir_path, PATH_MAX, path); + + if (ret != 0) { + error = convert_errno(ret); + return error; + } + + ret = wcscat_s(parent_dir_path, PATH_MAX, L"/.."); + + if (ret != 0) { + error = convert_errno(ret); + return error; + } + + HANDLE dir_handle = create_handle(parent_dir_path, true, true, true); + + if (dir_handle == INVALID_HANDLE_VALUE) { + error = convert_windows_error_code(GetLastError()); + return error; + } + + *out_dir_handle = dir_handle; + return error; +} + +// The easiest way to get all the necessary file information for files is to +// open a handle to the parent directory and iterate through the entries via +// FileIdBothDirectoryInfo. Other file information classes are only +// available on desktop. +static __wasi_errno_t +get_disk_file_information(HANDLE handle, __wasi_filestat_t *buf) +{ + __wasi_errno_t error = __WASI_ESUCCESS; + HANDLE raw_dir_handle = INVALID_HANDLE_VALUE; + + wchar_t path[PATH_MAX] = L"."; + + if (buf->st_filetype != __WASI_FILETYPE_DIRECTORY) { + error = get_handle_filepath(handle, path, PATH_MAX); + + if (error != __WASI_ESUCCESS) + goto fail; + + error = get_handle_to_parent_directory(handle, &raw_dir_handle); + + if (error != __WASI_ESUCCESS) + goto fail; + + error = extract_filename_from_path(path, PATH_MAX); + + if (error != __WASI_ESUCCESS) + goto fail; + } + else { + raw_dir_handle = handle; + } + + windows_handle dir_handle = { .access_mode = windows_access_mode_read, + .raw = { .handle = raw_dir_handle }, + .fdflags = 0, + .type = windows_handle_type_file }; + windows_dir_stream dir_stream; + init_dir_stream(&dir_stream, &dir_handle); + + do { + FILE_ID_BOTH_DIR_INFO *file_id_both_dir_info = NULL; + __wasi_errno_t error = + read_next_dir_entry(&dir_stream, &file_id_both_dir_info); + + if (error != __WASI_ESUCCESS || file_id_both_dir_info == NULL) + goto fail; + + const DWORD filename_length = file_id_both_dir_info->FileNameLength + / (sizeof(wchar_t) / sizeof(char)); + + if (wcsncmp(file_id_both_dir_info->FileName, path, filename_length) + == 0) { + buf->st_ino = + (__wasi_inode_t)(file_id_both_dir_info->FileId.QuadPart); + buf->st_atim = convert_filetime_to_wasi_timestamp( + (LPFILETIME)&file_id_both_dir_info->LastAccessTime.QuadPart); + buf->st_mtim = convert_filetime_to_wasi_timestamp( + (LPFILETIME)&file_id_both_dir_info->LastWriteTime.QuadPart); + buf->st_ctim = convert_filetime_to_wasi_timestamp( + (LPFILETIME)&file_id_both_dir_info->ChangeTime.QuadPart); + buf->st_size = + (__wasi_filesize_t)(file_id_both_dir_info->EndOfFile.QuadPart); + + break; + } + } while (dir_stream.cookie != 0); + + FILE_STANDARD_INFO file_standard_info; + + bool success = GetFileInformationByHandleEx(handle, FileStandardInfo, + &file_standard_info, + sizeof(file_standard_info)); + + if (!success) { + error = convert_windows_error_code(GetLastError()); + goto fail; + } + + buf->st_nlink = (__wasi_linkcount_t)file_standard_info.NumberOfLinks; +fail: + if (buf->st_filetype != __WASI_FILETYPE_DIRECTORY + && raw_dir_handle != INVALID_HANDLE_VALUE) + CloseHandle(raw_dir_handle); + + return error; +} + +#else + +static __wasi_errno_t +get_disk_file_information(HANDLE handle, __wasi_filestat_t *buf) +{ + __wasi_errno_t error = __WASI_ESUCCESS; + FILE_BASIC_INFO file_basic_info; + + int ret = GetFileInformationByHandleEx( + handle, FileBasicInfo, &file_basic_info, sizeof(file_basic_info)); + + if (ret == 0) { + error = convert_windows_error_code(GetLastError()); + return error; + } + + buf->st_atim = convert_filetime_to_wasi_timestamp( + (LPFILETIME)&file_basic_info.LastAccessTime.QuadPart); + buf->st_mtim = convert_filetime_to_wasi_timestamp( + (LPFILETIME)&file_basic_info.LastWriteTime.QuadPart); + buf->st_ctim = convert_filetime_to_wasi_timestamp( + (LPFILETIME)&file_basic_info.ChangeTime.QuadPart); + + BY_HANDLE_FILE_INFORMATION file_info; + ret = GetFileInformationByHandle(handle, &file_info); + + if (ret == 0) { + error = convert_windows_error_code(GetLastError()); + return error; + } + + ULARGE_INTEGER file_size = { .LowPart = file_info.nFileSizeLow, + .HighPart = file_info.nFileSizeHigh }; + buf->st_size = (__wasi_filesize_t)(file_size.QuadPart); + + ULARGE_INTEGER file_id = { .LowPart = file_info.nFileIndexLow, + .HighPart = file_info.nFileIndexHigh }; + buf->st_ino = (__wasi_inode_t)(file_id.QuadPart); + + buf->st_dev = (__wasi_device_t)file_info.dwVolumeSerialNumber; + buf->st_nlink = (__wasi_linkcount_t)file_info.nNumberOfLinks; + + return error; +} + +#endif /* end of WINAPI_PARTITION_DESKTOP == 0 */ + +static __wasi_errno_t +get_file_information(os_file_handle handle, __wasi_filestat_t *buf) +{ + __wasi_errno_t error = __WASI_ESUCCESS; + + DWORD windows_filetype = GetFileType(handle->raw.handle); + error = + convert_windows_filetype(handle, windows_filetype, &buf->st_filetype); + + if (error != __WASI_ESUCCESS) + return error; + + buf->st_dev = 0; + + if (windows_filetype != FILE_TYPE_DISK) { + buf->st_atim = 0; + buf->st_ctim = 0; + buf->st_mtim = 0; + buf->st_nlink = 0; + buf->st_size = 0; + buf->st_ino = 0; + + return error; + } + + return get_disk_file_information(handle->raw.handle, buf); +} + +__wasi_errno_t +os_fstat(os_file_handle handle, struct __wasi_filestat_t *buf) +{ + CHECK_VALID_HANDLE(handle); + + return get_file_information(handle, buf); +} + +__wasi_errno_t +os_fstatat(os_file_handle handle, const char *path, + struct __wasi_filestat_t *buf, __wasi_lookupflags_t lookup_flags) +{ + CHECK_VALID_FILE_HANDLE(handle); + + return __WASI_ENOSYS; +} + +__wasi_errno_t +os_file_get_fdflags(os_file_handle handle, __wasi_fdflags_t *flags) +{ + CHECK_VALID_HANDLE(handle); + + *flags = handle->fdflags; + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_file_set_fdflags(os_file_handle handle, __wasi_fdflags_t flags) +{ + CHECK_VALID_HANDLE(handle); + + return __WASI_ENOSYS; +} + +__wasi_errno_t +os_file_get_access_mode(os_file_handle handle, + wasi_libc_file_access_mode *access_mode) +{ + CHECK_VALID_HANDLE(handle); + + if ((handle->access_mode & windows_access_mode_read) != 0 + && (handle->access_mode & windows_access_mode_write) != 0) + *access_mode = WASI_LIBC_ACCESS_MODE_READ_WRITE; + else if ((handle->access_mode & windows_access_mode_write) != 0) + *access_mode = WASI_LIBC_ACCESS_MODE_WRITE_ONLY; + else + *access_mode = WASI_LIBC_ACCESS_MODE_READ_ONLY; + + return __WASI_ESUCCESS; +} + +__wasi_errno_t +os_fdatasync(os_file_handle handle) +{ + CHECK_VALID_FILE_HANDLE(handle); + + return __WASI_ENOSYS; +} + +__wasi_errno_t +os_fsync(os_file_handle handle) +{ + CHECK_VALID_FILE_HANDLE(handle); + + return __WASI_ENOSYS; +} + +__wasi_errno_t +os_open_preopendir(const char *path, os_file_handle *out) +{ + *out = NULL; + + wchar_t wpath[PATH_MAX]; + __wasi_errno_t error = convert_to_wchar(path, wpath, PATH_MAX); + + if (error != __WASI_ESUCCESS) + return error; + + HANDLE dir_handle = create_handle(wpath, true, true, true); + + if (dir_handle == INVALID_HANDLE_VALUE) + return convert_windows_error_code(GetLastError()); + + *out = BH_MALLOC(sizeof(windows_handle)); + + if (*out == NULL) { + CloseHandle(dir_handle); + return __WASI_ENOMEM; + } + + (*out)->type = windows_handle_type_file; + (*out)->raw.handle = dir_handle; + (*out)->fdflags = 0; + (*out)->access_mode = windows_access_mode_read; + + return error; +} + +__wasi_errno_t +os_openat(os_file_handle handle, const char *path, __wasi_oflags_t oflags, + __wasi_fdflags_t fs_flags, __wasi_lookupflags_t lookup_flags, + wasi_libc_file_access_mode access_mode, os_file_handle *out) +{ + CHECK_VALID_FILE_HANDLE(handle); + *out = BH_MALLOC(sizeof(windows_handle)); + + if (*out == NULL) + return __WASI_ENOMEM; + + (*out)->type = windows_handle_type_file; + (*out)->fdflags = fs_flags; + (*out)->raw.handle = INVALID_HANDLE_VALUE; + + DWORD attributes = FILE_FLAG_BACKUP_SEMANTICS; + + if ((fs_flags & (__WASI_FDFLAG_SYNC | __WASI_FDFLAG_RSYNC)) != 0) + attributes |= (FILE_FLAG_WRITE_THROUGH | FILE_FLAG_NO_BUFFERING); + if ((fs_flags & __WASI_FDFLAG_DSYNC) != 0) + attributes |= FILE_FLAG_WRITE_THROUGH; + + if ((oflags & __WASI_O_DIRECTORY) != 0) { + attributes |= FILE_ATTRIBUTE_DIRECTORY; + oflags &= ~(__WASI_O_DIRECTORY); + } + // Use async operations on the handle if it's not a directory + else { + attributes |= FILE_FLAG_OVERLAPPED; + } + + __wasi_errno_t error = __WASI_ESUCCESS; + + DWORD access_flags = 0; + if ((fs_flags & __WASI_FDFLAG_APPEND) != 0) { + if ((attributes & (FILE_FLAG_NO_BUFFERING)) != 0) { + // FILE_APPEND_DATA and FILE_FLAG_NO_BUFFERING are mutually + // exclusive - CreateFile2 returns 87 (invalid parameter) when they + // are combined. + error = __WASI_ENOTSUP; + goto fail; + } + access_flags |= FILE_APPEND_DATA; + } + + switch (access_mode) { + case WASI_LIBC_ACCESS_MODE_READ_ONLY: + access_flags |= GENERIC_READ; + (*out)->access_mode = windows_access_mode_read; + break; + case WASI_LIBC_ACCESS_MODE_WRITE_ONLY: + access_flags |= GENERIC_WRITE; + (*out)->access_mode = windows_access_mode_write; + break; + case WASI_LIBC_ACCESS_MODE_READ_WRITE: + access_flags |= GENERIC_WRITE | GENERIC_READ; + (*out)->access_mode = + windows_access_mode_read | windows_access_mode_write; + break; + } + + DWORD creation_disposition = 0; + + switch (oflags) { + case __WASI_O_CREAT | __WASI_O_EXCL: + case __WASI_O_CREAT | __WASI_O_EXCL | __WASI_O_TRUNC: + creation_disposition = CREATE_NEW; + break; + case __WASI_O_CREAT | __WASI_O_TRUNC: + creation_disposition = CREATE_ALWAYS; + break; + case __WASI_O_CREAT: + creation_disposition = OPEN_ALWAYS; + break; + case 0: + case __WASI_O_EXCL: + creation_disposition = OPEN_EXISTING; + break; + case __WASI_O_TRUNC: + case __WASI_O_EXCL | __WASI_O_TRUNC: + creation_disposition = TRUNCATE_EXISTING; + // CreateFile2 requires write access if we truncate the file upon + // opening + access_flags |= GENERIC_WRITE; + break; + } + + wchar_t absolute_path[PATH_MAX]; + error = get_absolute_filepath(handle->raw.handle, path, absolute_path, + PATH_MAX); + + if (error != __WASI_ESUCCESS) + goto fail; + + if ((lookup_flags & __WASI_LOOKUP_SYMLINK_FOLLOW) == 0) + attributes |= FILE_FLAG_OPEN_REPARSE_POINT; + + // Check that we're not trying to open an existing file as a directory. + // Windows doesn't seem to throw an error in this case so add an + // explicit check. + if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0 + && creation_disposition == OPEN_EXISTING + && !is_directory(absolute_path)) { + error = __WASI_ENOTDIR; + goto fail; + } + + CREATEFILE2_EXTENDED_PARAMETERS create_params; + create_params.dwSize = sizeof(create_params); + create_params.dwFileAttributes = attributes & 0xFFF; + create_params.dwFileFlags = attributes & 0xFFF00000; + create_params.dwSecurityQosFlags = 0; + create_params.lpSecurityAttributes = NULL; + create_params.hTemplateFile = NULL; + + (*out)->raw.handle = + CreateFile2(absolute_path, access_flags, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + creation_disposition, &create_params); + + if ((*out)->raw.handle == INVALID_HANDLE_VALUE) { + error = convert_windows_error_code(GetLastError()); + goto fail; + } + + return error; +fail: + if (*out != NULL) { + if ((*out)->raw.handle != INVALID_HANDLE_VALUE) + CloseHandle((*out)->raw.handle); + + BH_FREE(*out); + } + + return error; +} + +__wasi_errno_t +os_close(os_file_handle handle, bool is_stdio) +{ + CHECK_VALID_HANDLE(handle); + + // We don't own the underlying raw handle so just free the handle and return + // success. + if (is_stdio) { + BH_FREE(handle); + return __WASI_ESUCCESS; + } + + switch (handle->type) { + case windows_handle_type_file: + bool success = CloseHandle(handle->raw.handle); + + if (!success) + return convert_windows_error_code(GetLastError()); + + break; + case windows_handle_type_socket: + int ret = closesocket(handle->raw.socket); + + if (ret != 0) + return convert_winsock_error_code(WSAGetLastError()); + + break; + default: + assert(false && "unreachable"); + } + + BH_FREE(handle); + + return __WASI_ESUCCESS; +} + +static __wasi_errno_t +read_data_at_offset(HANDLE handle, const struct __wasi_iovec_t *iov, int iovcnt, + __wasi_filesize_t offset, size_t *nwritten) +{ + OVERLAPPED *read_operations = + BH_MALLOC((uint32_t)(sizeof(OVERLAPPED) * (uint32_t)iovcnt)); + + if (read_operations == NULL) + return __WASI_ENOMEM; + + ULARGE_INTEGER query_offset = { .QuadPart = offset }; + __wasi_errno_t error = __WASI_ESUCCESS; + size_t total_bytes_read = 0; + + const __wasi_iovec_t *current = iov; + int successful_read_count = 0; + + for (int i = 0; i < iovcnt; ++i, ++current) { + read_operations[i].Internal = 0; + read_operations[i].InternalHigh = 0; + read_operations[i].Offset = query_offset.LowPart; + read_operations[i].OffsetHigh = query_offset.HighPart; + read_operations[i].hEvent = NULL; + + if (!ReadFileEx(handle, current->buf, (DWORD)current->buf_len, + &read_operations[i], NULL)) { + DWORD win_error = GetLastError(); + if (win_error != ERROR_IO_PENDING) { + error = convert_windows_error_code(win_error); + break; + } + } + ++successful_read_count; + query_offset.QuadPart += (DWORD)current->buf_len; + } + + // Get the result of all the asynchronous read operations + for (int i = 0; i < successful_read_count; ++i) { + DWORD bytes_transferred = 0; + if (!GetOverlappedResult(handle, &read_operations[i], + &bytes_transferred, true)) { + DWORD win_error = GetLastError(); + + if (win_error != ERROR_HANDLE_EOF) + error = convert_windows_error_code(win_error); + else + total_bytes_read += (size_t)bytes_transferred; + + CancelIo(handle); + + for (int j = i + 1; j < iovcnt; ++j) { + GetOverlappedResult(handle, &read_operations[j], + &bytes_transferred, true); + } + break; + } + + total_bytes_read += (size_t)bytes_transferred; + } + + *nwritten = total_bytes_read; + + BH_FREE(read_operations); + return error; +} + +__wasi_errno_t +os_preadv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt, + __wasi_filesize_t offset, size_t *nread) +{ + CHECK_VALID_FILE_HANDLE(handle); + + return read_data_at_offset(handle->raw.handle, iov, iovcnt, offset, nread); +} + +__wasi_errno_t +os_readv(os_file_handle handle, const struct __wasi_iovec_t *iov, int iovcnt, + size_t *nread) +{ + CHECK_VALID_HANDLE(handle); + + LARGE_INTEGER current_offset = { .QuadPart = 0 }; + + // Seek to the current offset before reading + int ret = SetFilePointerEx(handle->raw.handle, current_offset, + ¤t_offset, FILE_CURRENT); + if (ret == 0) + return convert_windows_error_code(GetLastError()); + + __wasi_errno_t error = + read_data_at_offset(handle->raw.handle, iov, iovcnt, + (__wasi_filesize_t)current_offset.QuadPart, nread); + + if (error != __WASI_ESUCCESS) + return error; + + current_offset.QuadPart += (LONGLONG)(*nread); + + // Update the current offset to match how many bytes we've read + ret = + SetFilePointerEx(handle->raw.handle, current_offset, NULL, FILE_BEGIN); + + if (ret == 0) + error = convert_windows_error_code(GetLastError()); + + return error; +} + +static __wasi_errno_t +write_data_at_offset(HANDLE handle, const struct __wasi_ciovec_t *iov, + int iovcnt, __wasi_filesize_t offset, size_t *nwritten) +{ + OVERLAPPED *write_operations = + BH_MALLOC((uint32_t)(sizeof(OVERLAPPED) * (uint32_t)iovcnt)); + + if (write_operations == NULL) + return __WASI_ENOMEM; + + ULARGE_INTEGER query_offset = { .QuadPart = offset }; + __wasi_errno_t error = __WASI_ESUCCESS; + size_t total_bytes_written = 0; + + const __wasi_ciovec_t *current = iov; + int successful_write_count = 0; + for (int i = 0; i < iovcnt; ++i, ++current) { + write_operations[i].Internal = 0; + write_operations[i].InternalHigh = 0; + write_operations[i].Offset = query_offset.LowPart; + write_operations[i].OffsetHigh = query_offset.HighPart; + write_operations[i].hEvent = NULL; + + if (!WriteFileEx(handle, current->buf, (DWORD)current->buf_len, + &write_operations[i], NULL)) { + DWORD win_error = GetLastError(); + if (win_error != ERROR_IO_PENDING) { + error = convert_windows_error_code(win_error); + break; + } + } + ++successful_write_count; + query_offset.QuadPart += (DWORD)current->buf_len; + } + + // Get the result of all the asynchronous writes + for (int i = 0; i < successful_write_count; ++i) { + DWORD bytes_transferred = 0; + if (!GetOverlappedResult(handle, &write_operations[i], + &bytes_transferred, true)) { + error = convert_windows_error_code(GetLastError()); + CancelIo(handle); + + for (int j = i + 1; j < iovcnt; ++j) { + GetOverlappedResult(handle, &write_operations[j], + &bytes_transferred, true); + } + break; + } + + total_bytes_written += (size_t)bytes_transferred; + } + + *nwritten = total_bytes_written; + + BH_FREE(write_operations); + return error; +} + +__wasi_errno_t +os_pwritev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt, + __wasi_filesize_t offset, size_t *nwritten) +{ + CHECK_VALID_FILE_HANDLE(handle); + + return write_data_at_offset(handle->raw.handle, iov, iovcnt, offset, + nwritten); +} + +__wasi_errno_t +os_writev(os_file_handle handle, const struct __wasi_ciovec_t *iov, int iovcnt, + size_t *nwritten) +{ + CHECK_VALID_HANDLE(handle); + + bool append = (handle->fdflags & __WASI_FDFLAG_APPEND) != 0; + LARGE_INTEGER write_offset = { .QuadPart = 0 }; + DWORD move_method = append ? FILE_END : FILE_CURRENT; + + int ret = SetFilePointerEx(handle->raw.handle, write_offset, &write_offset, + move_method); + if (ret == 0) + return convert_windows_error_code(GetLastError()); + + __wasi_errno_t error = write_data_at_offset( + handle->raw.handle, iov, iovcnt, + (__wasi_filesize_t)write_offset.QuadPart, nwritten); + + if (error != __WASI_ESUCCESS) + return error; + + write_offset.QuadPart += (LONGLONG)(*nwritten); + + // Update the write offset to match how many bytes we've written + ret = SetFilePointerEx(handle->raw.handle, write_offset, NULL, FILE_BEGIN); + + if (ret == 0) + error = convert_windows_error_code(GetLastError()); + + return error; +} + +__wasi_errno_t +os_fallocate(os_file_handle handle, __wasi_filesize_t offset, + __wasi_filesize_t length) +{ + CHECK_VALID_FILE_HANDLE(handle); + + return __WASI_ENOSYS; +} + +__wasi_errno_t +os_ftruncate(os_file_handle handle, __wasi_filesize_t size) +{ + CHECK_VALID_FILE_HANDLE(handle); + + return __WASI_ENOSYS; +} + +__wasi_errno_t +os_futimens(os_file_handle handle, __wasi_timestamp_t access_time, + __wasi_timestamp_t modification_time, __wasi_fstflags_t fstflags) +{ + CHECK_VALID_FILE_HANDLE(handle); + + return __WASI_ENOSYS; +} + +__wasi_errno_t +os_utimensat(os_file_handle handle, const char *path, + __wasi_timestamp_t access_time, + __wasi_timestamp_t modification_time, __wasi_fstflags_t fstflags, + __wasi_lookupflags_t lookup_flags) +{ + CHECK_VALID_FILE_HANDLE(handle); + + return __WASI_ENOSYS; +} + +__wasi_errno_t +os_readlinkat(os_file_handle handle, const char *path, char *buf, + size_t bufsize, size_t *nread) +{ + CHECK_VALID_FILE_HANDLE(handle); + + wchar_t symlink_path[PATH_MAX]; + __wasi_errno_t error = + get_absolute_filepath(handle->raw.handle, path, symlink_path, PATH_MAX); + + if (error != __WASI_ESUCCESS) + return error; + + DWORD symlink_attributes = GetFileAttributesW(symlink_path); + + if (!has_symlink_attribute(symlink_attributes)) + return __WASI_EINVAL; + + HANDLE link_handle = create_handle( + symlink_path, has_directory_attribute(symlink_attributes), false, true); + + if (link_handle == INVALID_HANDLE_VALUE) + return convert_windows_error_code(GetLastError()); + +#if WINAPI_PARTITION_DESKTOP != 0 +// MinGW32 already has a definition for REPARSE_DATA_BUFFER +#if defined(_MSC_VER) || defined(__MINGW64_VERSION_MAJOR) + // See + // https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_reparse_data_buffer + // for more details. + typedef struct _REPARSE_DATA_BUFFER { + ULONG ReparseTag; + USHORT ReparseDataLength; + USHORT Reserved; + union { + struct { + USHORT SubstituteNameOffset; + USHORT SubstituteNameLength; + USHORT PrintNameOffset; + USHORT PrintNameLength; + ULONG Flags; + WCHAR PathBuffer[1]; + } SymbolicLinkReparseBuffer; + struct { + USHORT SubstituteNameOffset; + USHORT SubstituteNameLength; + USHORT PrintNameOffset; + USHORT PrintNameLength; + WCHAR PathBuffer[1]; + } MountPointReparseBuffer; + struct { + UCHAR DataBuffer[1]; + } GenericReparseBuffer; + } DUMMYUNIONNAME; + } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER; +#endif + + char buffer[MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; + + REPARSE_DATA_BUFFER *reparse_data = (REPARSE_DATA_BUFFER *)buffer; + + if (!DeviceIoControl(link_handle, FSCTL_GET_REPARSE_POINT, NULL, 0, &buffer, + sizeof(buffer), NULL, NULL)) { + error = convert_windows_error_code(GetLastError()); + goto fail; + } + + int wbufsize = 0; + wchar_t *wbuf = NULL; + + // The following checks are taken from the libuv windows filesystem + // implementation, + // https://github.com/libuv/libuv/blob/v1.x/src/win/fs.c#L181-L244. Real + // symlinks can contain pretty much anything, but the only thing we really + // care about is undoing the implicit conversion to an NT namespaced path + // that CreateSymbolicLink will perform on absolute paths. + if (reparse_data->ReparseTag == IO_REPARSE_TAG_SYMLINK) { + wbuf = reparse_data->SymbolicLinkReparseBuffer.PathBuffer + + (reparse_data->SymbolicLinkReparseBuffer.SubstituteNameOffset + / sizeof(wchar_t)); + wbufsize = reparse_data->SymbolicLinkReparseBuffer.SubstituteNameLength + / sizeof(wchar_t); + + if (wbufsize >= 4 && wbuf[0] == L'\\' && wbuf[1] == L'?' + && wbuf[2] == L'?' && wbuf[3] == L'\\') { + // Starts with \??\ + if (wbufsize >= 6 + && ((wbuf[4] >= L'A' && wbuf[4] <= L'Z') + || (wbuf[4] >= L'a' && wbuf[4] <= L'z')) + && wbuf[5] == L':' && (wbufsize == 6 || wbuf[6] == L'\\')) + { + // \??\:\ + wbuf += 4; + wbufsize -= 4; + } + else if (wbufsize >= 8 && (wbuf[4] == L'U' || wbuf[4] == L'u') + && (wbuf[5] == L'N' || wbuf[5] == L'n') + && (wbuf[6] == L'C' || wbuf[6] == L'c') + && wbuf[7] == L'\\') + { + // \??\UNC\\\ - make sure the final path looks like \\\\ + wbuf += 6; + wbuf[0] = L'\\'; + wbufsize -= 6; + } + } + } + else if (reparse_data->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT) { + // Junction + wbuf = reparse_data->MountPointReparseBuffer.PathBuffer + + (reparse_data->MountPointReparseBuffer.SubstituteNameOffset + / sizeof(wchar_t)); + wbufsize = reparse_data->MountPointReparseBuffer.SubstituteNameLength + / sizeof(wchar_t); + + // Only treat junctions that look like \??\:\ as a symlink. + if (!(wbufsize >= 6 && wbuf[0] == L'\\' && wbuf[1] == L'?' + && wbuf[2] == L'?' && wbuf[3] == L'\\' + && ((wbuf[4] >= L'A' && wbuf[4] <= L'Z') + || (wbuf[4] >= L'a' && wbuf[4] <= L'z')) + && wbuf[5] == L':' && (wbufsize == 6 || wbuf[6] == L'\\'))) { + error = __WASI_EINVAL; + goto fail; + } + + /* Remove leading \??\ */ + wbuf += 4; + wbufsize -= 4; + } + else { + error = __WASI_EINVAL; + goto fail; + } + + if (wbuf != NULL) + *nread = (size_t)WideCharToMultiByte(CP_UTF8, 0, wbuf, wbufsize, buf, + (int)bufsize, NULL, NULL); + + if (*nread == 0 && wbuf != NULL) { + DWORD win_error = GetLastError(); + if (win_error == ERROR_INSUFFICIENT_BUFFER) + *nread = bufsize; + else + error = convert_windows_error_code(win_error); + } +#else + error = __WASI_ENOTSUP; +#endif +fail: + CloseHandle(link_handle); + return error; +} + +__wasi_errno_t +os_linkat(os_file_handle from_handle, const char *from_path, + os_file_handle to_handle, const char *to_path, + __wasi_lookupflags_t lookup_flags) +{ + CHECK_VALID_FILE_HANDLE(from_handle); + CHECK_VALID_FILE_HANDLE(to_handle); + + return __WASI_ENOSYS; +} + +__wasi_errno_t +os_symlinkat(const char *old_path, os_file_handle handle, const char *new_path) +{ + CHECK_VALID_FILE_HANDLE(handle); + + return __WASI_ENOSYS; +} + +__wasi_errno_t +os_mkdirat(os_file_handle handle, const char *path) +{ + CHECK_VALID_FILE_HANDLE(handle); + + wchar_t absolute_path[PATH_MAX]; + __wasi_errno_t error = get_absolute_filepath(handle->raw.handle, path, + absolute_path, PATH_MAX); + + if (error != __WASI_ESUCCESS) + return error; + + bool success = CreateDirectoryW(absolute_path, NULL); + + if (!success) + error = convert_windows_error_code(GetLastError()); + + return error; +} + +__wasi_errno_t +os_renameat(os_file_handle old_handle, const char *old_path, + os_file_handle new_handle, const char *new_path) +{ + CHECK_VALID_FILE_HANDLE(old_handle); + CHECK_VALID_FILE_HANDLE(new_handle); + + return __WASI_ENOSYS; +} + +__wasi_errno_t +os_unlinkat(os_file_handle handle, const char *path, bool is_dir) +{ + CHECK_VALID_FILE_HANDLE(handle); + + wchar_t absolute_path[PATH_MAX]; + __wasi_errno_t error = get_absolute_filepath(handle->raw.handle, path, + absolute_path, PATH_MAX); + + if (error != __WASI_ESUCCESS) + return error; + + DWORD attributes = GetFileAttributesW(absolute_path); + + if (has_symlink_attribute(attributes)) { + // Override is_dir for symlinks. A symlink to a directory counts + // as a directory itself in Windows. + is_dir = has_directory_attribute(attributes); + } + + int ret = + is_dir ? RemoveDirectoryW(absolute_path) : DeleteFileW(absolute_path); + + if (ret == 0) + error = convert_windows_error_code(GetLastError()); + + return error; +} + +__wasi_errno_t +os_lseek(os_file_handle handle, __wasi_filedelta_t offset, + __wasi_whence_t whence, __wasi_filesize_t *new_offset) +{ + CHECK_VALID_FILE_HANDLE(handle); + + return __WASI_ENOSYS; +} + +__wasi_errno_t +os_fadvise(os_file_handle handle, __wasi_filesize_t offset, + __wasi_filesize_t length, __wasi_advice_t advice) +{ + CHECK_VALID_FILE_HANDLE(handle); + + return __WASI_ENOSYS; +} + +__wasi_errno_t +os_isatty(os_file_handle handle) +{ + CHECK_VALID_HANDLE(handle); + + DWORD console_mode; + return GetConsoleMode(handle->raw.handle, &console_mode) ? __WASI_ESUCCESS + : __WASI_ENOTTY; +} + +static os_file_handle +create_stdio_handle(HANDLE raw_stdio_handle, DWORD stdio) +{ + os_file_handle stdio_handle = BH_MALLOC(sizeof(windows_handle)); + + if (stdio_handle == NULL) + return NULL; + + stdio_handle->type = windows_handle_type_file; + stdio_handle->access_mode = + windows_access_mode_read | windows_access_mode_write; + stdio_handle->fdflags = 0; + + if (raw_stdio_handle == INVALID_HANDLE_VALUE) + raw_stdio_handle = GetStdHandle(stdio); + + stdio_handle->raw.handle = raw_stdio_handle; + + return stdio_handle; +} + +os_file_handle +os_convert_stdin_handle(os_raw_file_handle raw_stdin) +{ + return create_stdio_handle(raw_stdin, STD_INPUT_HANDLE); +} + +os_file_handle +os_convert_stdout_handle(os_raw_file_handle raw_stdout) +{ + return create_stdio_handle(raw_stdout, STD_OUTPUT_HANDLE); +} + +os_file_handle +os_convert_stderr_handle(os_raw_file_handle raw_stderr) +{ + return create_stdio_handle(raw_stderr, STD_ERROR_HANDLE); +} + +__wasi_errno_t +os_fdopendir(os_file_handle handle, os_dir_stream *dir_stream) +{ + return __WASI_ENOSYS; +} + +__wasi_errno_t +os_rewinddir(os_dir_stream dir_stream) +{ + CHECK_VALID_WIN_DIR_STREAM(dir_stream); + + return __WASI_ENOSYS; +} + +__wasi_errno_t +os_seekdir(os_dir_stream dir_stream, __wasi_dircookie_t position) +{ + CHECK_VALID_WIN_DIR_STREAM(dir_stream); + + return __WASI_ENOSYS; +} + +__wasi_errno_t +os_readdir(os_dir_stream dir_stream, __wasi_dirent_t *entry, + const char **d_name) +{ + CHECK_VALID_WIN_DIR_STREAM(dir_stream); + + return __WASI_ENOSYS; +} + +__wasi_errno_t +os_closedir(os_dir_stream dir_stream) +{ + CHECK_VALID_WIN_DIR_STREAM(dir_stream); + + return __WASI_ENOSYS; +} + +os_dir_stream +os_get_invalid_dir_stream() +{ + return NULL; +} + +bool +os_is_dir_stream_valid(os_dir_stream *dir_stream) +{ + assert(dir_stream != NULL); + + if (((*dir_stream) == NULL) || ((*dir_stream)->handle == NULL) + || ((*dir_stream)->handle->type != windows_handle_type_file) + || ((*dir_stream)->handle->raw.handle == INVALID_HANDLE_VALUE)) + return false; + + return true; +} + +bool +os_is_handle_valid(os_file_handle *handle) +{ + assert(handle != NULL); + + CHECK_VALID_HANDLE_WITH_RETURN_VALUE(*handle, false); + + return true; +} + +char * +os_realpath(const char *path, char *resolved_path) +{ + resolved_path = _fullpath(resolved_path, path, PATH_MAX); + + // Check the file/directory actually exists + DWORD attributes = GetFileAttributesA(resolved_path); + + if (attributes == INVALID_FILE_ATTRIBUTES) + return NULL; + + return resolved_path; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/win_malloc.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_malloc.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/win_malloc.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_malloc.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/win_memmap.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_memmap.c similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/win_memmap.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_memmap.c index c4a6b075629..db0f38a5635 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/win_memmap.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_memmap.c @@ -29,7 +29,7 @@ access_to_win32_flags(int prot) } void * -os_mmap(void *hint, size_t size, int prot, int flags) +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) { DWORD alloc_type = MEM_RESERVE; DWORD protect; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/win_socket.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_socket.c similarity index 64% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/win_socket.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_socket.c index 9a1c7a3c94f..91d38fd8b60 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/win_socket.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_socket.c @@ -5,12 +5,30 @@ #include "platform_api_vmcore.h" #include "platform_api_extension.h" +#include "platform_wasi_types.h" +#include "win_util.h" /* link with Ws2_32.lib */ #pragma comment(lib, "ws2_32.lib") static bool is_winsock_inited = false; +#define CHECK_VALID_SOCKET_HANDLE(win_handle) \ + do { \ + if ((win_handle) == NULL) { \ + errno = EBADF; \ + return BHT_ERROR; \ + } \ + if ((win_handle)->type != windows_handle_type_socket) { \ + errno = ENOTSOCK; \ + return BHT_ERROR; \ + } \ + if ((win_handle)->raw.socket == INVALID_SOCKET) { \ + errno = EBADF; \ + return BHT_ERROR; \ + } \ + } while (0) + int init_winsock() { @@ -45,6 +63,17 @@ os_socket_create(bh_socket_t *sock, bool is_ipv4, bool is_tcp) return BHT_ERROR; } + *(sock) = BH_MALLOC(sizeof(windows_handle)); + + if ((*sock) == NULL) { + errno = ENOMEM; + return BHT_ERROR; + } + + (*sock)->type = windows_handle_type_socket; + (*sock)->access_mode = windows_access_mode_read | windows_access_mode_write; + (*sock)->fdflags = 0; + if (is_ipv4) { af = AF_INET; } @@ -54,18 +83,24 @@ os_socket_create(bh_socket_t *sock, bool is_ipv4, bool is_tcp) } if (is_tcp) { - *sock = socket(af, SOCK_STREAM, IPPROTO_TCP); + (*sock)->raw.socket = socket(af, SOCK_STREAM, IPPROTO_TCP); } else { - *sock = socket(af, SOCK_DGRAM, 0); + (*sock)->raw.socket = socket(af, SOCK_DGRAM, 0); } - return (*sock == -1) ? BHT_ERROR : BHT_OK; + if ((*sock)->raw.socket == INVALID_SOCKET) { + BH_FREE(*sock); + return BHT_ERROR; + } + + return BHT_OK; } int os_socket_bind(bh_socket_t socket, const char *host, int *port) { + CHECK_VALID_SOCKET_HANDLE(socket); struct sockaddr_in addr; int socklen, ret; @@ -76,13 +111,13 @@ os_socket_bind(bh_socket_t socket, const char *host, int *port) addr.sin_port = htons(*port); addr.sin_family = AF_INET; - ret = bind(socket, (struct sockaddr *)&addr, sizeof(addr)); + ret = bind(socket->raw.socket, (struct sockaddr *)&addr, sizeof(addr)); if (ret < 0) { goto fail; } socklen = sizeof(addr); - if (getsockname(socket, (void *)&addr, &socklen) == -1) { + if (getsockname(socket->raw.socket, (void *)&addr, &socklen) == -1) { os_printf("getsockname failed with error %d\n", WSAGetLastError()); goto fail; } @@ -98,10 +133,12 @@ os_socket_bind(bh_socket_t socket, const char *host, int *port) int os_socket_settimeout(bh_socket_t socket, uint64 timeout_us) { + CHECK_VALID_SOCKET_HANDLE(socket); + DWORD tv = (DWORD)(timeout_us / 1000UL); - if (setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tv, - sizeof(tv)) + if (setsockopt(socket->raw.socket, SOL_SOCKET, SO_RCVTIMEO, + (const char *)&tv, sizeof(tv)) != 0) { return BHT_ERROR; } @@ -112,7 +149,9 @@ os_socket_settimeout(bh_socket_t socket, uint64 timeout_us) int os_socket_listen(bh_socket_t socket, int max_client) { - if (listen(socket, max_client) != 0) { + CHECK_VALID_SOCKET_HANDLE(socket); + + if (listen(socket->raw.socket, max_client) != 0) { os_printf("socket listen failed with error %d\n", WSAGetLastError()); return BHT_ERROR; } @@ -124,12 +163,26 @@ int os_socket_accept(bh_socket_t server_sock, bh_socket_t *sock, void *addr, unsigned int *addrlen) { + CHECK_VALID_SOCKET_HANDLE(server_sock); + struct sockaddr addr_tmp; unsigned int len = sizeof(struct sockaddr); - *sock = accept(server_sock, (struct sockaddr *)&addr_tmp, &len); + *sock = BH_MALLOC(sizeof(windows_handle)); - if (*sock < 0) { + if (*sock == NULL) { + errno = ENOMEM; + return BHT_ERROR; + } + + (*sock)->type = windows_handle_type_socket; + (*sock)->access_mode = windows_access_mode_read | windows_access_mode_write; + (*sock)->fdflags = 0; + (*sock)->raw.socket = + accept(server_sock->raw.socket, (struct sockaddr *)&addr_tmp, &len); + + if ((*sock)->raw.socket == INVALID_SOCKET) { + BH_FREE(*sock); os_printf("socket accept failed with error %d\n", WSAGetLastError()); return BHT_ERROR; } @@ -140,13 +193,17 @@ os_socket_accept(bh_socket_t server_sock, bh_socket_t *sock, void *addr, int os_socket_recv(bh_socket_t socket, void *buf, unsigned int len) { - return recv(socket, buf, len, 0); + CHECK_VALID_SOCKET_HANDLE(socket); + + return recv(socket->raw.socket, buf, len, 0); } int os_socket_recv_from(bh_socket_t socket, void *buf, unsigned int len, int flags, bh_sockaddr_t *src_addr) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -155,13 +212,17 @@ os_socket_recv_from(bh_socket_t socket, void *buf, unsigned int len, int flags, int os_socket_send(bh_socket_t socket, const void *buf, unsigned int len) { - return send(socket, buf, len, 0); + CHECK_VALID_SOCKET_HANDLE(socket); + + return send(socket->raw.socket, buf, len, 0); } int os_socket_send_to(bh_socket_t socket, const void *buf, unsigned int len, int flags, const bh_sockaddr_t *dest_addr) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -170,15 +231,24 @@ os_socket_send_to(bh_socket_t socket, const void *buf, unsigned int len, int os_socket_close(bh_socket_t socket) { - closesocket(socket); + CHECK_VALID_SOCKET_HANDLE(socket); + + closesocket(socket->raw.socket); + + BH_FREE(socket); + return BHT_OK; } -int +__wasi_errno_t os_socket_shutdown(bh_socket_t socket) { - shutdown(socket, SD_BOTH); - return BHT_OK; + CHECK_VALID_SOCKET_HANDLE(socket); + + if (shutdown(socket->raw.socket, SD_BOTH) != 0) { + return convert_winsock_error_code(WSAGetLastError()); + } + return __WASI_ESUCCESS; } int @@ -206,6 +276,16 @@ os_socket_inet_network(bool is_ipv4, const char *cp, bh_ip_addr_buffer_t *out) return BHT_OK; } +int +os_socket_connect(bh_socket_t socket, const char *addr, int port) +{ + CHECK_VALID_SOCKET_HANDLE(socket); + + errno = ENOSYS; + + return BHT_ERROR; +} + int os_socket_addr_resolve(const char *host, const char *service, uint8_t *hint_is_tcp, uint8_t *hint_is_ipv4, @@ -220,6 +300,8 @@ os_socket_addr_resolve(const char *host, const char *service, int os_socket_addr_local(bh_socket_t socket, bh_sockaddr_t *sockaddr) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -228,6 +310,8 @@ os_socket_addr_local(bh_socket_t socket, bh_sockaddr_t *sockaddr) int os_socket_set_send_timeout(bh_socket_t socket, uint64 timeout_us) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -236,6 +320,8 @@ os_socket_set_send_timeout(bh_socket_t socket, uint64 timeout_us) int os_socket_get_send_timeout(bh_socket_t socket, uint64 *timeout_us) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -244,6 +330,8 @@ os_socket_get_send_timeout(bh_socket_t socket, uint64 *timeout_us) int os_socket_set_recv_timeout(bh_socket_t socket, uint64 timeout_us) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -252,6 +340,8 @@ os_socket_set_recv_timeout(bh_socket_t socket, uint64 timeout_us) int os_socket_get_recv_timeout(bh_socket_t socket, uint64 *timeout_us) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -260,6 +350,8 @@ os_socket_get_recv_timeout(bh_socket_t socket, uint64 *timeout_us) int os_socket_addr_remote(bh_socket_t socket, bh_sockaddr_t *sockaddr) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -268,6 +360,8 @@ os_socket_addr_remote(bh_socket_t socket, bh_sockaddr_t *sockaddr) int os_socket_set_send_buf_size(bh_socket_t socket, size_t bufsiz) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -276,6 +370,8 @@ os_socket_set_send_buf_size(bh_socket_t socket, size_t bufsiz) int os_socket_get_send_buf_size(bh_socket_t socket, size_t *bufsiz) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -284,6 +380,8 @@ os_socket_get_send_buf_size(bh_socket_t socket, size_t *bufsiz) int os_socket_set_recv_buf_size(bh_socket_t socket, size_t bufsiz) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -292,6 +390,8 @@ os_socket_set_recv_buf_size(bh_socket_t socket, size_t bufsiz) int os_socket_get_recv_buf_size(bh_socket_t socket, size_t *bufsiz) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -300,6 +400,8 @@ os_socket_get_recv_buf_size(bh_socket_t socket, size_t *bufsiz) int os_socket_set_keep_alive(bh_socket_t socket, bool is_enabled) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -308,6 +410,8 @@ os_socket_set_keep_alive(bh_socket_t socket, bool is_enabled) int os_socket_get_keep_alive(bh_socket_t socket, bool *is_enabled) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -316,6 +420,8 @@ os_socket_get_keep_alive(bh_socket_t socket, bool *is_enabled) int os_socket_set_reuse_addr(bh_socket_t socket, bool is_enabled) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -324,6 +430,8 @@ os_socket_set_reuse_addr(bh_socket_t socket, bool is_enabled) int os_socket_get_reuse_addr(bh_socket_t socket, bool *is_enabled) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -332,6 +440,8 @@ os_socket_get_reuse_addr(bh_socket_t socket, bool *is_enabled) int os_socket_set_reuse_port(bh_socket_t socket, bool is_enabled) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -340,6 +450,8 @@ os_socket_set_reuse_port(bh_socket_t socket, bool is_enabled) int os_socket_get_reuse_port(bh_socket_t socket, bool *is_enabled) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -348,6 +460,8 @@ os_socket_get_reuse_port(bh_socket_t socket, bool *is_enabled) int os_socket_set_linger(bh_socket_t socket, bool is_enabled, int linger_s) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -356,6 +470,8 @@ os_socket_set_linger(bh_socket_t socket, bool is_enabled, int linger_s) int os_socket_get_linger(bh_socket_t socket, bool *is_enabled, int *linger_s) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -364,6 +480,8 @@ os_socket_get_linger(bh_socket_t socket, bool *is_enabled, int *linger_s) int os_socket_set_tcp_no_delay(bh_socket_t socket, bool is_enabled) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -372,6 +490,8 @@ os_socket_set_tcp_no_delay(bh_socket_t socket, bool is_enabled) int os_socket_get_tcp_no_delay(bh_socket_t socket, bool *is_enabled) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -380,6 +500,8 @@ os_socket_get_tcp_no_delay(bh_socket_t socket, bool *is_enabled) int os_socket_set_tcp_quick_ack(bh_socket_t socket, bool is_enabled) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -388,6 +510,8 @@ os_socket_set_tcp_quick_ack(bh_socket_t socket, bool is_enabled) int os_socket_get_tcp_quick_ack(bh_socket_t socket, bool *is_enabled) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -396,6 +520,8 @@ os_socket_get_tcp_quick_ack(bh_socket_t socket, bool *is_enabled) int os_socket_set_tcp_keep_idle(bh_socket_t socket, uint32 time_s) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -404,6 +530,8 @@ os_socket_set_tcp_keep_idle(bh_socket_t socket, uint32 time_s) int os_socket_get_tcp_keep_idle(bh_socket_t socket, uint32 *time_s) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -412,6 +540,8 @@ os_socket_get_tcp_keep_idle(bh_socket_t socket, uint32 *time_s) int os_socket_set_tcp_keep_intvl(bh_socket_t socket, uint32 time_s) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -420,6 +550,8 @@ os_socket_set_tcp_keep_intvl(bh_socket_t socket, uint32 time_s) int os_socket_get_tcp_keep_intvl(bh_socket_t socket, uint32 *time_s) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -428,6 +560,8 @@ os_socket_get_tcp_keep_intvl(bh_socket_t socket, uint32 *time_s) int os_socket_set_tcp_fastopen_connect(bh_socket_t socket, bool is_enabled) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -436,6 +570,8 @@ os_socket_set_tcp_fastopen_connect(bh_socket_t socket, bool is_enabled) int os_socket_get_tcp_fastopen_connect(bh_socket_t socket, bool *is_enabled) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -444,6 +580,8 @@ os_socket_get_tcp_fastopen_connect(bh_socket_t socket, bool *is_enabled) int os_socket_set_ip_multicast_loop(bh_socket_t socket, bool ipv6, bool is_enabled) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -452,6 +590,8 @@ os_socket_set_ip_multicast_loop(bh_socket_t socket, bool ipv6, bool is_enabled) int os_socket_get_ip_multicast_loop(bh_socket_t socket, bool ipv6, bool *is_enabled) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -462,6 +602,8 @@ os_socket_set_ip_add_membership(bh_socket_t socket, bh_ip_addr_buffer_t *imr_multiaddr, uint32_t imr_interface, bool is_ipv6) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -472,6 +614,8 @@ os_socket_set_ip_drop_membership(bh_socket_t socket, bh_ip_addr_buffer_t *imr_multiaddr, uint32_t imr_interface, bool is_ipv6) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -480,6 +624,8 @@ os_socket_set_ip_drop_membership(bh_socket_t socket, int os_socket_set_ip_ttl(bh_socket_t socket, uint8_t ttl_s) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -488,6 +634,8 @@ os_socket_set_ip_ttl(bh_socket_t socket, uint8_t ttl_s) int os_socket_get_ip_ttl(bh_socket_t socket, uint8_t *ttl_s) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -496,6 +644,8 @@ os_socket_get_ip_ttl(bh_socket_t socket, uint8_t *ttl_s) int os_socket_set_ip_multicast_ttl(bh_socket_t socket, uint8_t ttl_s) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -504,6 +654,8 @@ os_socket_set_ip_multicast_ttl(bh_socket_t socket, uint8_t ttl_s) int os_socket_get_ip_multicast_ttl(bh_socket_t socket, uint8_t *ttl_s) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -512,6 +664,8 @@ os_socket_get_ip_multicast_ttl(bh_socket_t socket, uint8_t *ttl_s) int os_socket_set_ipv6_only(bh_socket_t socket, bool option) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -520,6 +674,8 @@ os_socket_set_ipv6_only(bh_socket_t socket, bool option) int os_socket_get_ipv6_only(bh_socket_t socket, bool *option) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -528,6 +684,8 @@ os_socket_get_ipv6_only(bh_socket_t socket, bool *option) int os_socket_set_broadcast(bh_socket_t socket, bool is_enabled) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; @@ -536,6 +694,8 @@ os_socket_set_broadcast(bh_socket_t socket, bool is_enabled) int os_socket_get_broadcast(bh_socket_t socket, bool *is_enabled) { + CHECK_VALID_SOCKET_HANDLE(socket); + errno = ENOSYS; return BHT_ERROR; } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/win_thread.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_thread.c similarity index 95% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/win_thread.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_thread.c index 09cf0c63f79..f37250fa4e0 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/win_thread.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_thread.c @@ -541,6 +541,62 @@ os_mutex_unlock(korp_mutex *mutex) return ReleaseMutex(*mutex) ? BHT_OK : BHT_ERROR; } +int +os_rwlock_init(korp_rwlock *lock) +{ + bh_assert(lock); + + InitializeSRWLock(&(lock->lock)); + lock->exclusive = false; + + return BHT_OK; +} + +int +os_rwlock_rdlock(korp_rwlock *lock) +{ + bh_assert(lock); + + AcquireSRWLockShared(&(lock->lock)); + + return BHT_OK; +} + +int +os_rwlock_wrlock(korp_rwlock *lock) +{ + bh_assert(lock); + + AcquireSRWLockExclusive(&(lock->lock)); + lock->exclusive = true; + + return BHT_OK; +} + +int +os_rwlock_unlock(korp_rwlock *lock) +{ + bh_assert(lock); + + if (lock->exclusive) { + lock->exclusive = false; + ReleaseSRWLockExclusive(&(lock->lock)); + } + else { + ReleaseSRWLockShared(&(lock->lock)); + } + + return BHT_OK; +} + +int +os_rwlock_destroy(korp_rwlock *lock) +{ + (void)lock; + + return BHT_OK; +} + int os_cond_init(korp_cond *cond) { @@ -712,6 +768,10 @@ os_thread_get_stack_boundary() return thread_stack_boundary; } +void +os_thread_jit_write_protect_np(bool enabled) +{} + #ifdef OS_ENABLE_HW_BOUND_CHECK static os_thread_local_attribute bool thread_signal_inited = false; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/win_time.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_time.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/windows/win_time.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_time.c diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_util.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_util.c new file mode 100644 index 00000000000..ee0e82fb9a9 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_util.c @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2023 Amazon Inc. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "platform_common.h" +#include "win_util.h" + +__wasi_timestamp_t +convert_filetime_to_wasi_timestamp(LPFILETIME filetime) +{ + // From 1601-01-01 to 1970-01-01 there are 134774 days. + static const uint64_t NT_to_UNIX_epoch = + 134774ull * 86400ull * 1000ull * 1000ull * 1000ull; + + ULARGE_INTEGER temp = { .HighPart = filetime->dwHighDateTime, + .LowPart = filetime->dwLowDateTime }; + + // WASI timestamps are measured in nanoseconds whereas FILETIME structs are + // represented in terms 100-nanosecond intervals. + return (temp.QuadPart * 100ull) - NT_to_UNIX_epoch; +} + +__wasi_errno_t +convert_windows_error_code(DWORD windows_error_code) +{ + switch (windows_error_code) { + case ERROR_INVALID_PARAMETER: + case ERROR_INVALID_HANDLE: + case ERROR_NEGATIVE_SEEK: + return __WASI_EINVAL; + case ERROR_SHARING_VIOLATION: + case ERROR_PIPE_BUSY: + return __WASI_EBUSY; + case ERROR_ACCESS_DENIED: + return __WASI_EACCES; + case ERROR_ALREADY_EXISTS: + case ERROR_FILE_EXISTS: + return __WASI_EEXIST; + case ERROR_NO_MORE_FILES: + case ERROR_FILE_NOT_FOUND: + case ERROR_INVALID_NAME: + return __WASI_ENOENT; + case ERROR_PRIVILEGE_NOT_HELD: + return __WASI_EPERM; + case ERROR_NOT_ENOUGH_MEMORY: + return __WASI_ENOMEM; + case ERROR_NOACCESS: + return __WASI_EFAULT; + case ERROR_DIR_NOT_EMPTY: + return __WASI_ENOTEMPTY; + case ERROR_DIRECTORY: + return __WASI_ENOTDIR; + case ERROR_IO_PENDING: + case ERROR_INSUFFICIENT_BUFFER: + case ERROR_INVALID_FLAGS: + case ERROR_NO_UNICODE_TRANSLATION: + default: + return __WASI_EINVAL; + } +} + +#ifdef UWP_DEFAULT_VPRINTF +int +uwp_print_to_debugger(const char *format, va_list ap) +{ + // Provide a stack buffer which should be large enough for any realistic + // string so we avoid making an allocation on every printf call. + char stack_buf[2048]; + char *buf = stack_buf; + int ret = vsnprintf(stack_buf, sizeof(stack_buf), format, ap); + + if ((size_t)ret >= sizeof(stack_buf)) { + // Allocate an extra byte for the null terminator. + char *heap_buf = BH_MALLOC((unsigned int)(ret) + 1); + buf = heap_buf; + + if (heap_buf == NULL) { + // Output as much as we can to the debugger if allocating a buffer + // fails. + OutputDebugStringA(stack_buf); + return ret; + } + + ret = vsnprintf(heap_buf, (size_t)ret + 1, format, ap); + } + + if (ret >= 0) + OutputDebugStringA(buf); + + if (buf != stack_buf) + BH_FREE(buf); + + return ret; +} +#endif + +__wasi_errno_t +convert_winsock_error_code(int error_code) +{ + switch (error_code) { + case WSASYSNOTREADY: + case WSAEWOULDBLOCK: + return __WASI_EAGAIN; + case WSAVERNOTSUPPORTED: + return __WASI_ENOTSUP; + case WSAEINPROGRESS: + return __WASI_EINPROGRESS; + case WSAEPROCLIM: + return __WASI_EBUSY; + case WSAEFAULT: + return __WASI_EFAULT; + case WSAENETDOWN: + return __WASI_ENETDOWN; + case WSAENOTSOCK: + return __WASI_ENOTSOCK; + case WSAEINTR: + return __WASI_EINTR; + case WSAEAFNOSUPPORT: + return __WASI_EAFNOSUPPORT; + case WSAEMFILE: + return __WASI_ENFILE; + case WSAEINVAL: + return __WASI_EINVAL; + case WSAENOBUFS: + return __WASI_ENOBUFS; + case WSAEPROTONOSUPPORT: + return __WASI_EPROTONOSUPPORT; + case WSAEPROTOTYPE: + return __WASI_EPROTOTYPE; + case WSAESOCKTNOSUPPORT: + return __WASI_ENOTSUP; + case WSAECONNABORTED: + return __WASI_ECONNABORTED; + case WSAECONNRESET: + return __WASI_ECONNRESET; + case WSAENOTCONN: + return __WASI_ENOTCONN; + case WSAEINVALIDPROCTABLE: + case WSAEINVALIDPROVIDER: + case WSAEPROVIDERFAILEDINIT: + case WSANOTINITIALISED: + default: + return __WASI_EINVAL; + } +} diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_util.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_util.h new file mode 100644 index 00000000000..3960fe946f2 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/windows/win_util.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2023 Amazon Inc. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#ifndef _WIN_UTIL_H +#define _WIN_UTIL_H + +#include "platform_wasi_types.h" +#include "windows.h" + +__wasi_timestamp_t +convert_filetime_to_wasi_timestamp(LPFILETIME filetime); + +/* Convert a Windows error code to a WASI error code */ +__wasi_errno_t +convert_windows_error_code(DWORD windows_error_code); + +/* Convert a Winsock error code to a WASI error code */ +__wasi_errno_t +convert_winsock_error_code(int error_code); + +#endif /* end of _WIN_UTIL_H */ \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/zephyr/platform_internal.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/zephyr/platform_internal.h similarity index 84% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/zephyr/platform_internal.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/zephyr/platform_internal.h index d2a94e4ad5f..a5d563a6c8f 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/zephyr/platform_internal.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/zephyr/platform_internal.h @@ -42,21 +42,23 @@ #include #include #include - -#ifdef CONFIG_ARM_MPU -#include -#endif #else /* else of KERNEL_VERSION_NUMBER < 0x030200 */ #include #include #include #include #include +#endif /* end of KERNEL_VERSION_NUMBER < 0x030200 */ #ifdef CONFIG_ARM_MPU +#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */ +#include +#elif KERNEL_VERSION_NUMBER < 0x030400 /* version 3.4.0 */ #include +#else /* > 3.4.0 */ +#include +#endif #endif -#endif /* end of KERNEL_VERSION_NUMBER < 0x030200 */ #ifndef BH_PLATFORM_ZEPHYR #define BH_PLATFORM_ZEPHYR @@ -72,6 +74,12 @@ typedef korp_thread *korp_tid; typedef struct k_mutex korp_mutex; typedef unsigned int korp_sem; +/* korp_rwlock is used in platform_api_extension.h, + we just define the type to make the compiler happy */ +typedef struct { + int dummy; +} korp_rwlock; + struct os_thread_wait_node; typedef struct os_thread_wait_node *os_thread_wait_list; typedef struct korp_cond { @@ -123,7 +131,7 @@ float strtof(const char *nptr, char **endptr); #endif /** - * @brief Allocate executable memroy + * @brief Allocate executable memory * * @param size size of the memory to be allocated * @@ -132,7 +140,7 @@ float strtof(const char *nptr, char **endptr); typedef void *(*exec_mem_alloc_func_t)(unsigned int size); /** - * @brief Release executable memroy + * @brief Release executable memory * * @param the address of the executable memory to be released */ @@ -146,4 +154,16 @@ void set_exec_mem_alloc_func(exec_mem_alloc_func_t alloc_func, exec_mem_free_func_t free_func); +/* The below types are used in platform_api_extension.h, + we just define them to make the compiler happy */ +typedef int os_file_handle; +typedef void *os_dir_stream; +typedef int os_raw_file_handle; + +static inline os_file_handle +os_get_invalid_handle() +{ + return -1; +} + #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/zephyr/shared_platform.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/zephyr/shared_platform.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/zephyr/shared_platform.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/zephyr/shared_platform.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/zephyr/zephyr_platform.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/zephyr/zephyr_platform.c similarity index 97% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/zephyr/zephyr_platform.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/zephyr/zephyr_platform.c index b4f2e5ec740..1a5b6621d1f 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/zephyr/zephyr_platform.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/zephyr/zephyr_platform.c @@ -173,7 +173,7 @@ strcspn(const char *s, const char *reject) #endif void * -os_mmap(void *hint, size_t size, int prot, int flags) +os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file) { if ((uint64)size >= UINT32_MAX) return NULL; @@ -214,6 +214,10 @@ os_dcache_flush() #endif } +void +os_icache_flush(void *start, size_t len) +{} + void set_exec_mem_alloc_func(exec_mem_alloc_func_t alloc_func, exec_mem_free_func_t free_func) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/zephyr/zephyr_thread.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/zephyr/zephyr_thread.c similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/zephyr/zephyr_thread.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/zephyr/zephyr_thread.c index 1ee2c5cefc3..105d53993e5 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/zephyr/zephyr_thread.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/zephyr/zephyr_thread.c @@ -574,3 +574,7 @@ os_thread_get_stack_boundary() return NULL; #endif } + +void +os_thread_jit_write_protect_np(bool enabled) +{} \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/zephyr/zephyr_time.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/zephyr/zephyr_time.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/platform/zephyr/zephyr_time.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/platform/zephyr/zephyr_time.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/SConscript similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/SConscript rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/SConscript diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_assert.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_assert.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_assert.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_assert.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_assert.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_assert.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_assert.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_assert.h diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_atomic.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_atomic.h new file mode 100644 index 00000000000..5744a64c03e --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_atomic.h @@ -0,0 +1,221 @@ +/* + * Copyright (C) 2023 Amazon Inc. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#ifndef _BH_ATOMIC_H +#define _BH_ATOMIC_H + +#include "gnuc.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Why don't we use C11 stdatomics here? + * + * Unlike C11 stdatomics, + * + * - bh_atomic_xxx_t is guaranteed to have the same size as the base type. + * Thus more friendly to our AOT conventions. + * + * - It's available for C++. + * Although C++23 will have C-compatible stdatomics.h, it isn't widely + * available yet. + */ + +/* + * Note about BH_ATOMIC_32_IS_ATOMIC + * + * If BH_ATOMIC_32_IS_ATOMIC == 0, BH_ATOMIC_xxx operations defined below + * are not really atomic and require an external lock. + * + * Expected usage is: + * + * bh_atomic_32_t var = 0; + * uint32 old; + * #if BH_ATOMIC_32_IS_ATOMIC == 0 + * lock(&some_lock); + * #endif + * old = BH_ATOMIC_32_FETCH_AND(var, 1); + * #if BH_ATOMIC_32_IS_ATOMIC == 0 + * unlock(&some_lock); + * #endif + */ + +typedef uint32 bh_atomic_32_t; +typedef uint16 bh_atomic_16_t; + +/* The flag can be defined by the user if the platform + * supports atomic 32-bit operations. + * If left undefined, it will be automatically defined + * according to the platform. + */ +#ifdef WASM_UINT32_IS_ATOMIC +#define BH_ATOMIC_32_IS_ATOMIC WASM_UINT32_IS_ATOMIC +#endif /* WASM_UINT32_IS_ATOMIC */ + +#ifdef WASM_UINT16_IS_ATOMIC +#define BH_ATOMIC_16_IS_ATOMIC WASM_UINT16_IS_ATOMIC +#endif /* WASM_UINT16_IS_ATOMIC */ + +#if defined(__GNUC_PREREQ) +#if __GNUC_PREREQ(4, 7) +#define CLANG_GCC_HAS_ATOMIC_BUILTIN +#endif +#elif defined(__clang__) +#if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 0) +#define CLANG_GCC_HAS_ATOMIC_BUILTIN +#endif +#endif + +#if defined(CLANG_GCC_HAS_ATOMIC_BUILTIN) +#ifndef BH_ATOMIC_32_IS_ATOMIC +#define BH_ATOMIC_32_IS_ATOMIC 1 +#endif +#ifndef BH_ATOMIC_16_IS_ATOMIC +#define BH_ATOMIC_16_IS_ATOMIC 1 +#endif +#else +#ifndef BH_ATOMIC_32_IS_ATOMIC +#define BH_ATOMIC_32_IS_ATOMIC 0 +#endif +#ifndef BH_ATOMIC_16_IS_ATOMIC +#define BH_ATOMIC_16_IS_ATOMIC 0 +#endif +#endif + +/* Force disable atomic 16-bit operations on bare-metal RISC-V + * because the 16-bit atomic operations is emulated by 32-bit + * atomic operations, which has linkage problem on current toolchain: + * in function `shared_memory_inc_reference': + * wasm_shared_memory.c:85:(.text.shared_memory_inc_reference+0x10): undefined + * reference to `__atomic_fetch_add_2' + */ +#ifndef WASM_UINT16_IS_ATOMIC +#if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) \ + && !defined(__OpenBSD__) && defined(__riscv) +#undef BH_ATOMIC_16_IS_ATOMIC +#define BH_ATOMIC_16_IS_ATOMIC 0 +#endif +#endif + +#if BH_ATOMIC_32_IS_ATOMIC != 0 + +#define BH_ATOMIC_32_LOAD(v) __atomic_load_n(&(v), __ATOMIC_SEQ_CST) +#define BH_ATOMIC_32_STORE(v, val) __atomic_store_n(&(v), val, __ATOMIC_SEQ_CST) +#define BH_ATOMIC_32_FETCH_OR(v, val) \ + __atomic_fetch_or(&(v), (val), __ATOMIC_SEQ_CST) +#define BH_ATOMIC_32_FETCH_AND(v, val) \ + __atomic_fetch_and(&(v), (val), __ATOMIC_SEQ_CST) +#define BH_ATOMIC_32_FETCH_ADD(v, val) \ + __atomic_fetch_add(&(v), (val), __ATOMIC_SEQ_CST) +#define BH_ATOMIC_32_FETCH_SUB(v, val) \ + __atomic_fetch_sub(&(v), (val), __ATOMIC_SEQ_CST) + +#else /* else of BH_ATOMIC_32_IS_ATOMIC != 0 */ + +#define BH_ATOMIC_32_LOAD(v) (v) +#define BH_ATOMIC_32_STORE(v, val) (v) = val +#define BH_ATOMIC_32_FETCH_OR(v, val) nonatomic_32_fetch_or(&(v), val) +#define BH_ATOMIC_32_FETCH_AND(v, val) nonatomic_32_fetch_and(&(v), val) +#define BH_ATOMIC_32_FETCH_ADD(v, val) nonatomic_32_fetch_add(&(v), val) +#define BH_ATOMIC_32_FETCH_SUB(v, val) nonatomic_32_fetch_sub(&(v), val) + +static inline uint32 +nonatomic_32_fetch_or(bh_atomic_32_t *p, uint32 val) +{ + uint32 old = *p; + *p |= val; + return old; +} + +static inline uint32 +nonatomic_32_fetch_and(bh_atomic_32_t *p, uint32 val) +{ + uint32 old = *p; + *p &= val; + return old; +} + +static inline uint32 +nonatomic_32_fetch_add(bh_atomic_32_t *p, uint32 val) +{ + uint32 old = *p; + *p += val; + return old; +} + +static inline uint32 +nonatomic_32_fetch_sub(bh_atomic_32_t *p, uint32 val) +{ + uint32 old = *p; + *p -= val; + return old; +} + +#endif + +#if BH_ATOMIC_16_IS_ATOMIC != 0 + +#define BH_ATOMIC_16_IS_ATOMIC 1 +#define BH_ATOMIC_16_LOAD(v) __atomic_load_n(&(v), __ATOMIC_SEQ_CST) +#define BH_ATOMIC_16_STORE(v, val) __atomic_store_n(&(v), val, __ATOMIC_SEQ_CST) +#define BH_ATOMIC_16_FETCH_OR(v, val) \ + __atomic_fetch_or(&(v), (val), __ATOMIC_SEQ_CST) +#define BH_ATOMIC_16_FETCH_AND(v, val) \ + __atomic_fetch_and(&(v), (val), __ATOMIC_SEQ_CST) +#define BH_ATOMIC_16_FETCH_ADD(v, val) \ + __atomic_fetch_add(&(v), (val), __ATOMIC_SEQ_CST) +#define BH_ATOMIC_16_FETCH_SUB(v, val) \ + __atomic_fetch_sub(&(v), (val), __ATOMIC_SEQ_CST) + +#else /* else of BH_ATOMIC_16_IS_ATOMIC != 0 */ + +#define BH_ATOMIC_16_LOAD(v) (v) +#define BH_ATOMIC_16_STORE(v) (v) = val +#define BH_ATOMIC_16_FETCH_OR(v, val) nonatomic_16_fetch_or(&(v), val) +#define BH_ATOMIC_16_FETCH_AND(v, val) nonatomic_16_fetch_and(&(v), val) +#define BH_ATOMIC_16_FETCH_ADD(v, val) nonatomic_16_fetch_add(&(v), val) +#define BH_ATOMIC_16_FETCH_SUB(v, val) nonatomic_16_fetch_sub(&(v), val) + +static inline uint16 +nonatomic_16_fetch_or(bh_atomic_16_t *p, uint16 val) +{ + uint16 old = *p; + *p |= val; + return old; +} + +static inline uint16 +nonatomic_16_fetch_and(bh_atomic_16_t *p, uint16 val) +{ + uint16 old = *p; + *p &= val; + return old; +} + +static inline uint16 +nonatomic_16_fetch_add(bh_atomic_16_t *p, uint16 val) +{ + uint16 old = *p; + *p += val; + return old; +} + +static inline uint16 +nonatomic_16_fetch_sub(bh_atomic_16_t *p, uint16 val) +{ + uint16 old = *p; + *p -= val; + return old; +} + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* end of _BH_ATOMIC_H */ diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_bitmap.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_bitmap.c new file mode 100644 index 00000000000..2ee918049cc --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_bitmap.c @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2021 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "bh_bitmap.h" + +bh_bitmap * +bh_bitmap_new(uintptr_t begin_index, unsigned bitnum) +{ + bh_bitmap *bitmap; + uint32 bitmap_size = (bitnum + 7) / 8; + uint32 total_size = offsetof(bh_bitmap, map) + bitmap_size; + + if (bitnum > UINT32_MAX - 7 || total_size < offsetof(bh_bitmap, map) + || (total_size - offsetof(bh_bitmap, map)) != bitmap_size) { + return NULL; /* integer overflow */ + } + + if ((bitmap = BH_MALLOC(total_size)) != NULL) { + memset(bitmap, 0, total_size); + bitmap->begin_index = begin_index; + bitmap->end_index = begin_index + bitnum; + } + + return bitmap; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_utils.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_bitmap.h similarity index 66% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_utils.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_bitmap.h index c165b7a3cf1..c0e56cb9951 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/fast-jit/jit_utils.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_bitmap.h @@ -3,8 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#ifndef _JIT_UTILS_H_ -#define _JIT_UTILS_H_ +#ifndef _BH_BITMAP_H +#define _BH_BITMAP_H #include "bh_platform.h" @@ -15,7 +15,7 @@ extern "C" { /** * A simple fixed size bitmap. */ -typedef struct JitBitmap { +typedef struct bh_bitmap { /* The first valid bit index. */ uintptr_t begin_index; @@ -24,30 +24,7 @@ typedef struct JitBitmap { /* The bitmap. */ uint8 map[1]; -} JitBitmap; - -static inline void * -jit_malloc(unsigned int size) -{ - return wasm_runtime_malloc(size); -} - -static inline void * -jit_calloc(unsigned int size) -{ - void *ret = wasm_runtime_malloc(size); - if (ret) { - memset(ret, 0, size); - } - return ret; -} - -static inline void -jit_free(void *ptr) -{ - if (ptr) - wasm_runtime_free(ptr); -} +} bh_bitmap; /** * Create a new bitmap. @@ -57,8 +34,8 @@ jit_free(void *ptr) * * @return the new bitmap if succeeds, NULL otherwise. */ -JitBitmap * -jit_bitmap_new(uintptr_t begin_index, unsigned bitnum); +bh_bitmap * +bh_bitmap_new(uintptr_t begin_index, unsigned bitnum); /** * Delete a bitmap. @@ -66,9 +43,10 @@ jit_bitmap_new(uintptr_t begin_index, unsigned bitnum); * @param bitmap the bitmap to be deleted */ static inline void -jit_bitmap_delete(JitBitmap *bitmap) +bh_bitmap_delete(bh_bitmap *bitmap) { - jit_free(bitmap); + if (bitmap != NULL) + BH_FREE(bitmap); } /** @@ -80,7 +58,7 @@ jit_bitmap_delete(JitBitmap *bitmap) * @return true if the index is in range, false otherwise */ static inline bool -jit_bitmap_is_in_range(JitBitmap *bitmap, unsigned n) +bh_bitmap_is_in_range(bh_bitmap *bitmap, uintptr_t n) { return n >= bitmap->begin_index && n < bitmap->end_index; } @@ -94,9 +72,9 @@ jit_bitmap_is_in_range(JitBitmap *bitmap, unsigned n) * @return value of the bit */ static inline int -jit_bitmap_get_bit(JitBitmap *bitmap, unsigned n) +bh_bitmap_get_bit(bh_bitmap *bitmap, uintptr_t n) { - unsigned idx = n - bitmap->begin_index; + uintptr_t idx = n - bitmap->begin_index; bh_assert(n >= bitmap->begin_index && n < bitmap->end_index); return (bitmap->map[idx / 8] >> (idx % 8)) & 1; } @@ -108,9 +86,9 @@ jit_bitmap_get_bit(JitBitmap *bitmap, unsigned n) * @param n the n-th bit to be set */ static inline void -jit_bitmap_set_bit(JitBitmap *bitmap, unsigned n) +bh_bitmap_set_bit(bh_bitmap *bitmap, uintptr_t n) { - unsigned idx = n - bitmap->begin_index; + uintptr_t idx = n - bitmap->begin_index; bh_assert(n >= bitmap->begin_index && n < bitmap->end_index); bitmap->map[idx / 8] |= 1 << (idx % 8); } @@ -122,9 +100,9 @@ jit_bitmap_set_bit(JitBitmap *bitmap, unsigned n) * @param n the n-th bit to be cleared */ static inline void -jit_bitmap_clear_bit(JitBitmap *bitmap, unsigned n) +bh_bitmap_clear_bit(bh_bitmap *bitmap, uintptr_t n) { - unsigned idx = n - bitmap->begin_index; + uintptr_t idx = n - bitmap->begin_index; bh_assert(n >= bitmap->begin_index && n < bitmap->end_index); bitmap->map[idx / 8] &= ~(1 << (idx % 8)); } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_common.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_common.c similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_common.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_common.c index aeeab26bd88..7fe123c912f 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_common.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_common.c @@ -31,6 +31,10 @@ b_memcpy_wa(void *s1, unsigned int s1max, const void *s2, unsigned int n) unsigned int *p; char *ps; + if (n == 0) { + return 0; + } + if (pa > src) { pa -= 4; } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_common.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_common.h similarity index 55% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_common.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_common.h index edb962eb1c7..adae722bbce 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_common.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_common.h @@ -12,25 +12,25 @@ extern "C" { #endif -#define bh_memcpy_s(dest, dlen, src, slen) \ - do { \ - int _ret = slen == 0 ? 0 : b_memcpy_s(dest, dlen, src, slen); \ - (void)_ret; \ - bh_assert(_ret == 0); \ +#define bh_memcpy_s(dest, dlen, src, slen) \ + do { \ + int _ret = b_memcpy_s(dest, dlen, src, slen); \ + (void)_ret; \ + bh_assert(_ret == 0); \ } while (0) -#define bh_memcpy_wa(dest, dlen, src, slen) \ - do { \ - int _ret = slen == 0 ? 0 : b_memcpy_wa(dest, dlen, src, slen); \ - (void)_ret; \ - bh_assert(_ret == 0); \ +#define bh_memcpy_wa(dest, dlen, src, slen) \ + do { \ + int _ret = b_memcpy_wa(dest, dlen, src, slen); \ + (void)_ret; \ + bh_assert(_ret == 0); \ } while (0) -#define bh_memmove_s(dest, dlen, src, slen) \ - do { \ - int _ret = slen == 0 ? 0 : b_memmove_s(dest, dlen, src, slen); \ - (void)_ret; \ - bh_assert(_ret == 0); \ +#define bh_memmove_s(dest, dlen, src, slen) \ + do { \ + int _ret = b_memmove_s(dest, dlen, src, slen); \ + (void)_ret; \ + bh_assert(_ret == 0); \ } while (0) #define bh_strcat_s(dest, dlen, src) \ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_hashmap.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_hashmap.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_hashmap.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_hashmap.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_hashmap.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_hashmap.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_hashmap.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_hashmap.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_list.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_list.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_list.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_list.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_list.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_list.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_list.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_list.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_log.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_log.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_log.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_log.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_log.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_log.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_log.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_log.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_platform.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_platform.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_platform.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_platform.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_queue.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_queue.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_queue.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_queue.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_queue.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_queue.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_queue.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_queue.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_vector.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_vector.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_vector.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_vector.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_vector.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_vector.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/bh_vector.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/bh_vector.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/gnuc.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/gnuc.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/gnuc.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/gnuc.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/runtime_timer.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/runtime_timer.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/runtime_timer.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/runtime_timer.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/runtime_timer.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/runtime_timer.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/runtime_timer.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/runtime_timer.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/shared_utils.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/shared_utils.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/shared_utils.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/shared_utils.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/uncommon/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/uncommon/SConscript similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/uncommon/SConscript rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/uncommon/SConscript diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/uncommon/bh_getopt.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/uncommon/bh_getopt.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/uncommon/bh_getopt.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/uncommon/bh_getopt.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/uncommon/bh_getopt.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/uncommon/bh_getopt.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/uncommon/bh_getopt.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/uncommon/bh_getopt.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/uncommon/bh_read_file.c b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/uncommon/bh_read_file.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/uncommon/bh_read_file.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/uncommon/bh_read_file.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/uncommon/bh_read_file.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/uncommon/bh_read_file.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/uncommon/bh_read_file.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/uncommon/bh_read_file.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/uncommon/shared_uncommon.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/uncommon/shared_uncommon.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/shared/utils/uncommon/shared_uncommon.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/shared/utils/uncommon/shared_uncommon.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/version.h b/lib/wasm-micro-runtime-WAMR-1.3.0/core/version.h similarity index 78% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/version.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/core/version.h index de24b30bc35..9bb76b2625b 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/version.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/core/version.h @@ -6,6 +6,6 @@ #ifndef _WAMR_VERSION_H_ #define _WAMR_VERSION_H_ #define WAMR_VERSION_MAJOR 1 -#define WAMR_VERSION_MINOR 2 -#define WAMR_VERSION_PATCH 2 +#define WAMR_VERSION_MINOR 3 +#define WAMR_VERSION_PATCH 0 #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/build_wamr.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/build_wamr.md similarity index 81% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/build_wamr.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/build_wamr.md index a66f27be0d7..12cbb41258e 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/build_wamr.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/build_wamr.md @@ -27,8 +27,8 @@ The script `runtime_lib.cmake` defines a number of variables for configuring the - **WAMR_BUILD_TARGET**: set the target CPU architecture. Current supported targets are: X86_64, X86_32, AARCH64, ARM, THUMB, XTENSA, ARC, RISCV32, RISCV64 and MIPS. - For ARM and THUMB, the format is \\[\]\[_VFP], where \ is the ARM sub-architecture and the "_VFP" suffix means using VFP coprocessor registers s0-s15 (d0-d7) for passing arguments or returning results in standard procedure-call. Both \ and "_VFP" are optional, e.g. ARMV7, ARMV7_VFP, THUMBV7, THUMBV7_VFP and so on. - For AARCH64, the format is\[\], VFP is enabled by default. \ is optional, e.g. AARCH64, AARCH64V8, AARCH64V8.1 and so on. - - For RISCV64, the format is \[_abi], where "_abi" is optional, currently the supported formats are RISCV64, RISCV64_LP64D and RISCV64_LP64: RISCV64 and RISCV64_LP64D are identical, using [LP64D](https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#-named-abis) as abi (LP64 with hardware floating-point calling convention for FLEN=64). And RISCV64_LP64 uses [LP64](https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#-named-abis) as abi (Integer calling-convention only, and hardware floating-point calling convention is not used). - - For RISCV32, the format is \[_abi], where "_abi" is optional, currently the supported formats are RISCV32, RISCV32_ILP32D and RISCV32_ILP32: RISCV32 and RISCV32_ILP32D are identical, using [ILP32D](https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#-named-abis) as abi (ILP32 with hardware floating-point calling convention for FLEN=64). And RISCV32_ILP32 uses [ILP32](https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#-named-abis) as abi (Integer calling-convention only, and hardware floating-point calling convention is not used). + - For RISCV64, the format is \[_abi], where "_abi" is optional, currently the supported formats are RISCV64, RISCV64_LP64D and RISCV64_LP64: RISCV64 and RISCV64_LP64D are identical, using [LP64D](https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc#named-abis) as abi (LP64 with hardware floating-point calling convention for FLEN=64). And RISCV64_LP64 uses [LP64](https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc#named-abis) as abi (Integer calling-convention only, and hardware floating-point calling convention is not used). + - For RISCV32, the format is \[_abi], where "_abi" is optional, currently the supported formats are RISCV32, RISCV32_ILP32D and RISCV32_ILP32: RISCV32 and RISCV32_ILP32D are identical, using [ILP32D](https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc#named-abis) as abi (ILP32 with hardware floating-point calling convention for FLEN=64). And RISCV32_ILP32 uses [ILP32](https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc#named-abis) as abi (Integer calling-convention only, and hardware floating-point calling convention is not used). ```bash cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM @@ -94,16 +94,25 @@ cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM - **WAMR_BUILD_WASI_NN**=1/0, default to disable if not set #### **Enable lib wasi-nn GPU mode** -- **WASI_NN_ENABLE_GPU**=1/0, default to disable if not set +- **WAMR_BUILD_WASI_NN_ENABLE_GPU**=1/0, default to disable if not set + +#### **Enable lib wasi-nn external delegate mode** +- **WAMR_BUILD_WASI_NN_ENABLE_EXTERNAL_DELEGATE**=1/0, default to disable if not set + +- **WAMR_BUILD_WASI_NN_EXTERNAL_DELEGATE_PATH**=Path to the external delegate shared library (e.g. `libedgetpu.so.1.0` for Coral USB) #### **Disable boundary check with hardware trap** - **WAMR_DISABLE_HW_BOUND_CHECK**=1/0, default to enable if not set and supported by platform -> Note: by default only platform linux/darwin/android/windows/vxworks 64-bit will enable the boundary check with hardware trap feature, and the wamrc tool will generate AOT code without boundary check instructions in all 64-bit targets except SGX to improve performance. The boundary check includes linear memory access boundary and native stack access boundary, if `WAMR_DISABLE_STACK_HW_BOUND_CHECK` below isn't set. +> Note: by default only platform [linux/darwin/android/windows/vxworks 64-bit](https://github.com/bytecodealliance/wasm-micro-runtime/blob/5fb5119239220b0803e7045ca49b0a29fe65e70e/core/shared/platform/linux/platform_internal.h#L81) will enable the boundary check with hardware trap feature, for 32-bit platforms it's automatically disabled even when the flag is set to 0, and the wamrc tool will generate AOT code without boundary check instructions in all 64-bit targets except SGX to improve performance. The boundary check includes linear memory access boundary and native stack access boundary, if `WAMR_DISABLE_STACK_HW_BOUND_CHECK` below isn't set. #### **Disable native stack boundary check with hardware trap** - **WAMR_DISABLE_STACK_HW_BOUND_CHECK**=1/0, default to enable if not set and supported by platform, same as `WAMR_DISABLE_HW_BOUND_CHECK`. > Note: When boundary check with hardware trap is disabled, or `WAMR_DISABLE_HW_BOUND_CHECK` is set to 1, the native stack boundary check with hardware trap will be disabled too, no matter what value is set to `WAMR_DISABLE_STACK_HW_BOUND_CHECK`. And when boundary check with hardware trap is enabled, the status of this feature is set according to the value of `WAMR_DISABLE_STACK_HW_BOUND_CHECK`. +#### **Disable async wakeup of blocking operation** +- **WAMR_DISABLE_WAKEUP_BLOCKING_OP**=1/0, default to enable if supported by the platform +> Note: The feature helps async termination of blocking threads. If you disable it, the runtime can wait for termination of blocking threads possibly forever. + #### **Enable tail call feature** - **WAMR_BUILD_TAIL_CALL**=1/0, default to disable if not set @@ -198,6 +207,13 @@ Currently we only profile the memory consumption of module, module_instance and - **WAMR_BUILD_STACK_GUARD_SIZE**=n, default to N/A if not set. > Note: By default, the stack guard size is 1K (1024) or 24K (if uvwasi enabled). +### **Disable the writing linear memory base address to x86 GS segment register +- **WAMR_DISABLE_WRITE_GS_BASE**=1/0, default to enable if not set and supported by platform +> Note: by default only platform [linux x86-64](https://github.com/bytecodealliance/wasm-micro-runtime/blob/5fb5119239220b0803e7045ca49b0a29fe65e70e/core/shared/platform/linux/platform_internal.h#L67) will enable this feature, for 32-bit platforms it's automatically disabled even when the flag is set to 0. In linux x86-64, writing the linear memory base address to x86 GS segment register may be used to speedup the linear memory access for LLVM AOT/JIT, when `--enable-segue=[]` option is added for `wamrc` or `iwasm`. + +### **Enable running PGO(Profile-Guided Optimization) instrumented AOT file** +- **WAMR_BUILD_STATIC_PGO**=1/0, default to disable if not set + **Combination of configurations:** We can combine the configurations. For example, if we want to disable interpreter, enable AOT and WASI, we can run command: diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/build_wasm_app.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/build_wasm_app.md similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/build_wasm_app.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/build_wasm_app.md index 40f1b89dd78..4475824dcb7 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/build_wasm_app.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/build_wasm_app.md @@ -394,7 +394,7 @@ Examples: wamrc -o test.aot test.wasm ### Usage example ``` bash -WAMRC_LLC_COMPILER= ./wamrc -o test.aot test.wasm +WAMRC_LLC_COMPILER=/usr/local/opt/llvm@14/bin/clang WAMRC_LLC_FLAGS="--target=x86_64-pc-linux-gnu -mcmodel=medium -c -O3" ./wamrc -o test.aot test.wasm ``` > Note: `wamrc` will verify whether the specified file exists and executable. If verification failed, `wamrc` will report a warning and fallback to normal pipeline. Since the verification is based on file, you **must specify the absolute path to the binary** even if it's in `$PATH` @@ -403,6 +403,8 @@ WAMRC_LLC_COMPILER= ./wamrc -o test.aot test.wasm > Note: the `LLC` and `ASM` in the env name just means this compiler will be used to compile the `LLVM IR file`/`assembly file` to object file, usually passing the compiler driver is the simplest way. (e.g. for LLVM toolchain, you don't need to pass `/usr/bin/llc`, using `/usr/bin/clang` is OK) +> Note: You might need to set `WAMRC_LLC_FLAGS`/`WAMRC_ASM_FLAGS` to match whatever the `wamrc` command would automatically do. In the above example, `-mcmodel=medium` corresponds to `wamrc --size-level=1`, which is the default of `wamrc` on macOS. + Run WASM app in WAMR mini product build ======================================= diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/devcontainer.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/devcontainer.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/devcontainer.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/devcontainer.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/embed_wamr.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/embed_wamr.md similarity index 81% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/embed_wamr.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/embed_wamr.md index 0503840277a..b83817589b3 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/embed_wamr.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/embed_wamr.md @@ -258,68 +258,69 @@ We can't pass structure data or class objects through the pointer since the memo ## Execute wasm functions in multiple threads -The `exec_env` is not thread safety, it will cause unexpected behavior if the same `exec_env` is used in multiple threads. However, we've provided two ways to execute wasm functions concurrently: +It isn't safe to use an `exec_env` object in multiple threads concurrently. +To run a multi-threaded application, you basically need a separate `exec_env` +for each threads. -- You can use `pthread` APIs in your wasm application, see [pthread library](./pthread_library.md) for more details. +### Approaches to manage `exec_env` objects and threads -- The `spawn exec_env` and `spawn thread` APIs are available, you can use these APIs to manage the threads in native: +WAMR supports two approaches to manage `exec_env` and threads as described +below. While they are not exclusive, you usually only need to use one of +them. - *spawn exec_env:* +#### Make your WASM application manage threads - `spawn exec_env` API spawns a `new_exec_env` base on the original `exec_env`, use can use it in other threads: + You can make your WASM application spawn threads by itself, + typically using `pthread` APIs like `pthread_create`. + See [pthread library](./pthread_library.md) and + [pthread implementations](./pthread_impls.md) for more details. + In this case, WAMR manages `exec_env` for the spawned threads. - ```C - new_exec_env = wasm_runtime_spawn_exec_env(exec_env); +#### Make your embedder manage threads + + The `spawn exec_env` and `spawn thread` APIs are available for the embedder. + You can use these APIs to manage the threads. + See [Thread related embedder API](./embed_wamr_spawn_api.md) for details. + +### Other notes about threads - /* Then you can use new_exec_env in your new thread */ - module_inst = wasm_runtime_get_module_inst(new_exec_env); - func_inst = wasm_runtime_lookup_function(module_inst, ...); - wasm_runtime_call_wasm(new_exec_env, func_inst, ...); +* You can manage the maximum number of threads - /* you need to use this API to manually destroy the spawned exec_env */ - wasm_runtime_destroy_spawned_exec_env(new_exec_env); + ```C + init_args.max_thread_num = THREAD_NUM; + /* If this init argument is not set, the default maximum thread number is 4 */ ``` - *spawn thread:* +* To share memory among threads, you need to build your WASM application with shared memory - You can also use `spawn thread` API to avoid manually manage the spawned exec_env: + For example, it can be done with `--shared-memory` and `-pthread`. - ```C - wasm_thread_t wasm_tid; - void *wamr_thread_cb(wasm_exec_env_t exec_env, void *arg) - { - module_inst = wasm_runtime_get_module_inst(exec_env); - func_inst = wasm_runtime_lookup_function(module_inst, ...); - wasm_runtime_call_wasm(exec_env, func_inst, ...); - } - wasm_runtime_spawn_thread(exec_env, &wasm_tid, wamr_thread_cb, NULL); - /* Use wasm_runtime_join_thread to join the spawned thread */ - wasm_runtime_join_thread(wasm_tid, NULL); + ```bash + /opt/wasi-sdk/bin/clang -o test.wasm test.c -nostdlib -pthread \ + -Wl,--shared-memory,--max-memory=131072 \ + -Wl,--no-entry,--export=__heap_base,--export=__data_end \ + -Wl,--export=__wasm_call_ctors,--export=${your_func_name} ``` -**Note1: You can manage the maximum number of threads can be created:** +* The corresponding threading feature should be enabled while building the runtime -```C -init_args.max_thread_num = THREAD_NUM; -/* If this init argument is not set, the default maximum thread number is 4 */ -``` + - WAMR lib-pthread (legacy) -**Note2: The wasm application should be built with `--shared-memory` and `-pthread` enabled:** + ```bash + cmake .. -DWAMR_BUILD_LIB_PTHREAD=1 + ``` -```bash - /opt/wasi-sdk/bin/clang -o test.wasm test.c -nostdlib -pthread \ - -Wl,--shared-memory,--max-memory=131072 \ - -Wl,--no-entry,--export=__heap_base,--export=__data_end \ - -Wl,--export=__wasm_call_ctors,--export=${your_func_name} -``` + - wasi-threads - **Note3: The pthread library feature should be enabled while building the runtime:** + ```bash + cmake .. -DWAMR_BUILD_LIB_WASI_THREADS=1 + ``` - ```bash - cmake .. -DWAMR_BUILD_LIB_PTHREAD=1 - ``` + - `wasm_runtime_spawn_exec_env` and `wasm_runtime_spawn_thread` -[Here](../samples/spawn-thread) is a sample to show how to use these APIs. + ```bash + cmake .. -DWAMR_BUILD_THREAD_MGR=1 -DWAMR_BUILD_SHARED_MEMORY=1 + ``` ## The deinitialization procedure diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/doc/embed_wamr_spawn_api.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/embed_wamr_spawn_api.md new file mode 100644 index 00000000000..f0e637f305f --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/embed_wamr_spawn_api.md @@ -0,0 +1,38 @@ +# Thread related embedder API + +This document explains `wasm_runtime_spawn_exec_env` and +`wasm_runtime_spawn_thread`. +[Here](../samples/spawn-thread) is a sample to show how to use these APIs. + + * spawn exec_env + + `spawn exec_env` API creates a new `exec_env` based on the original `exec_env`. You can use it in other threads. It's up to the embedder how to manage host threads to run the new `exec_env`. + + ```C + new_exec_env = wasm_runtime_spawn_exec_env(exec_env); + + /* Then you can use new_exec_env in your new thread */ + module_inst = wasm_runtime_get_module_inst(new_exec_env); + func_inst = wasm_runtime_lookup_function(module_inst, ...); + wasm_runtime_call_wasm(new_exec_env, func_inst, ...); + + /* you need to use this API to manually destroy the spawned exec_env */ + wasm_runtime_destroy_spawned_exec_env(new_exec_env); + ``` + + * spawn thread + + Alternatively, you can use `spawn thread` API to avoid managing the extra exec_env and the corresponding host thread manually: + + ```C + wasm_thread_t wasm_tid; + void *wamr_thread_cb(wasm_exec_env_t exec_env, void *arg) + { + module_inst = wasm_runtime_get_module_inst(exec_env); + func_inst = wasm_runtime_lookup_function(module_inst, ...); + wasm_runtime_call_wasm(exec_env, func_inst, ...); + } + wasm_runtime_spawn_thread(exec_env, &wasm_tid, wamr_thread_cb, NULL); + /* Use wasm_runtime_join_thread to join the spawned thread */ + wasm_runtime_join_thread(wasm_tid, NULL); + ``` diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/export_native_api.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/export_native_api.md similarity index 86% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/export_native_api.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/export_native_api.md index b87d925522f..ed738553910 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/export_native_api.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/export_native_api.md @@ -155,7 +155,7 @@ As function parameters are always passed in 32 bits numbers, you can also use 'i // // If the function signature used i32 data type ("i") // for buffer address or string parameters, here -// is how to do address conversation and boundary check manually +// is how to do address conversion and boundary check manually // void foo2(wasm_exec_env_t exec_env, uint32 msg_offset, @@ -261,4 +261,32 @@ wasm_response_send(wasm_exec_env_t exec_env, char *buffer, int size) ``` +## Native API implementation notes +### Async thread termination + +When threading support is enabled, a thread can be requested to terminate +itself either explicitly by the `wasm_runtime_terminate` API or implicitly +by cluster-wide activities like WASI `proc_exit`. +If a call to your native function can take long or even forever, +you should make it to respond to termination requests in a timely manner. +There are a few implementation approaches for that: + +* Design your API so that it always returns in a timely manner. + This is the most simple approach when possible. + +* Make your native function check the cluster state by calling + `wasm_cluster_is_thread_terminated` from time to time. + If `wasm_cluster_is_thread_terminated` returns true, make your + native function return. + Note: as of writing this, `wasm_cluster_is_thread_terminated` is not + exported as a runtime API. + +* If your native function is a simple wrapper of blocking system call, + you can probably use the `wasm_runtime_begin_blocking_op` and + `wasm_runtime_end_blocking_op` runtime API. + See the comment in `wamr_export.h` for details. + +* If your native function is very complex, it might be simpler to put the + guts of it into a separate worker process so that it can be cleaned up + by simply killing it. diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/linux_sgx.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/linux_sgx.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/linux_sgx.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/linux_sgx.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/memory_tune.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/memory_tune.md similarity index 90% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/memory_tune.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/memory_tune.md index e14a1a164d4..05a1a633f99 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/memory_tune.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/memory_tune.md @@ -16,7 +16,7 @@ Note: - **linear memory**: a contiguous, mutable array of raw bytes. It is created with an initial size but might be grown dynamically. For most compilers, e.g. wasi-sdk, emsdk, rustc or asc, normally it includes three parts, data area, auxiliary stack area and heap area. For wasi-sdk, the initial/max size can be specified with `-Wl,--initial-memory=n1,--max-memory=n2`, for emsdk, the initial/max size can be specified with `-s INITIAL_MEMORY=n1 -s MAXIMUM_MEMORY=n2 -s ALLOW_MEMORY_GROWTH=1` or `-s TOTAL_MEMORY=n`, and for asc, they can be specified with `--initialMemory` and `--maximumMemory` flags. - If the memory access boundary check with hardware trap feature is enabled, e.g. in Linux/MacOS/Windows x86-64 by default, the linear memory is allocated by `os_mmap` from virtual address space instead of global heap. - **aux stack**: the auxiliary stack resides in linear memory to store some temporary data when calling wasm functions, for example, calling a wasm function with complex struct arguments. For wasi-sdk, the size can be specified with `-z stack-size=n`, for emsdk, the size can be specified with `-s TOTAL_STACK=n`. -- **app heap and libc heap**: the heap to allocate memory for wasm app, note that app heap is created only when the malloc/free functions (or __new/__release functions for AssemblyScript) are not exported and runtime can not detect the libc heap. To export the malloc/free functions, for wasi-sdk and emsdk, developer can use `-Wl,--export=malloc -Wl,--export=free` options, for asc, developer can use `--exportRuntime` option. For app heap, the size is specified by `wasm_runtime_instantiate`. It is recommended to export the malloc/free functions and disable app heap in single thread mode, and for multi-threading, as the libc heap isn't thread-safe, it is recommended to remove the dlmalloc.o from libc.a for wasi-sdk and use `-s MALLOC="none"` for emsdk, refer to [WAMR pthread library](./pthread_library.md) for more details. And developer can use `wasm_runtime_module_malloc/wasm_runtime_module_free` to allocate/free memory from/to app heap (or libc heap if malloc/free functions are exported). +- **app heap and libc heap**: the heap to allocate memory for wasm app, note that app heap is created only when the malloc/free functions (or __new/__release functions for AssemblyScript) are not exported and runtime can not detect the libc heap. To export the malloc/free functions, for wasi-sdk and emsdk, developer can use `-Wl,--export=malloc -Wl,--export=free` options, for asc, developer can use `--exportRuntime` option. For app heap, the size is specified by `wasm_runtime_instantiate`. It is recommended to export the malloc/free functions and disable app heap. However, if you are using [the old pthread implementation](./pthread_impls.md), you might need some workaround to avoid the libc heap as mentioned in [WAMR pthread library](./pthread_library.md). And developer can use `wasm_runtime_module_malloc/wasm_runtime_module_free` to allocate/free memory from/to app heap (or libc heap if malloc/free functions are exported). - **__data_end global and __heap_base global**: two globals exported by wasm application to indicate the end of data area and the base address of libc heap. For WAMR, it is recommended to export them as when there are no possible memory grow operations, runtime will truncate the linear memory into the size indicated by `__heap_base`, so as to reduce the footprint, or at least one page (64KB) is required by linear memory. ## Tune the memory usage diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/memory_usage.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/memory_usage.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/memory_usage.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/memory_usage.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/multi_module.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/multi_module.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/multi_module.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/multi_module.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/other_wasm_compilers.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/other_wasm_compilers.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/other_wasm_compilers.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/other_wasm_compilers.md diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/doc/perf_tune.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/perf_tune.md new file mode 100644 index 00000000000..f57abe068ca --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/perf_tune.md @@ -0,0 +1,179 @@ +# Tune the performance of running wasm/aot file + +Normally there are some methods to tune the performance: + +## 1. Use `wasm-opt` tool + +Download the [binaryen release](https://github.com/WebAssembly/binaryen/releases), and use the `wasm-opt` tool in it to optimize the wasm file, for example: + +```bash +wasm-opt -O4 -o test_opt.wasm test.wasm +``` + +## 2. Enable `simd128` option when compiling wasm source files + +WebAssembly [128-bit SIMD](https://github.com/WebAssembly/simd) is supported by WAMR on x86-64 and aarch64 targets, enabling it when compiling wasm source files may greatly improve the performance. For [wasi-sdk](https://github.com/WebAssembly/wasi-sdk) and [emsdk](https://github.com/emscripten-core/emsdk), please add `-msimd128` flag for `clang` and `emcc/em++`: + +```bash +/opt/wasi-sdk/bin/clang -msimd128 -O3 -o + +emcc -msimd128 -O3 -o +``` + +## 3. Enable segue optimization for wamrc when generating the aot file + +[Segue](https://plas2022.github.io/files/pdf/SegueColorGuard.pdf) is an optimization technology which uses x86 segment register to store the WebAssembly linear memory base address, so as to remove most of the cost of SFI (Software-based Fault Isolation) base addition and free up a general purpose register, by this way it may: + +- Improve the performance of JIT/AOT +- Reduce the footprint of JIT/AOT, the JIT/AOT code generated is smaller +- Reduce the compilation time of JIT/AOT + +Currently it is supported on linux x86-64, developer can use `--enable-segue=[]` for wamrc: + +```bash +wamrc --enable-segue -o aot_file wasm_file +# or +wamrc --enable-segue=[] -o aot_file wasm_file +``` + +`flags` can be: i32.load, i64.load, f32.load, f64.load, v128.load, i32.store, i64.store, f32.store, f64.store and v128.store, use comma to separate them, e.g. `--enable-segue=i32.load,i64.store`, and `--enable-segue` means all flags are added. + +> Note: Normally for most cases, using `--enable-segue` is enough, but for some cases, using `--enable-segue=` may be better, for example for CoreMark benchmark, `--enable-segue=i32.store` may lead to better performance than `--enable-segue`. + +## 4. Enable segue optimization for iwasm when running wasm file + +Similar to segue optimization for wamrc, run: + +```bash +iwasm --enable-segue wasm_file (iwasm is built with llvm-jit enabled) +# or +iwasm --enable-segue=[] wasm_file +``` + +## 5. Use the AOT static PGO method + +LLVM PGO (Profile-Guided Optimization) allows the compiler to better optimize code for how it actually runs. WAMR supports AOT static PGO, currently it is tested on Linux x86-64 and x86-32. The basic steps are: + +1. Use `wamrc --enable-llvm-pgo -o ` to generate an instrumented aot file. + +2. Compile iwasm with `cmake -DWAMR_BUILD_STATIC_PGO=1` and run `iwasm --gen-prof-file= ` to generate the raw profile file. + +> Note: Directly dumping raw profile data to file system may be unsupported in some environments, developer can dump the profile data into memory buffer instead and try outputting it through network (e.g. uart or socket): + +```C +uint32_t +wasm_runtime_get_pgo_prof_data_size(wasm_module_inst_t module_inst); + +uint32_t +wasm_runtime_dump_pgo_prof_data_to_buf(wasm_module_inst_t module_inst, char *buf, uint32_t len); +``` + +3. Install or compile `llvm-profdata` tool,refer to [here](../tests/benchmarks/README.md#install-llvm-profdata) for the details. + +4. Run `llvm-profdata merge -output= ` to merge the raw profile file into the profile file. + +5. Run `wamrc --use-prof-file= -o ` to generate the optimized aot file. + +6. Run the optimized aot_file: `iwasm `. + +Developer can refer to the `test_pgo.sh` files under each benchmark folder for more details, e.g. [test_pgo.sh](../tests/benchmarks/coremark/test_pgo.sh) of CoreMark benchmark. + +## 6. Disable the memory boundary check + +Please notice that this method is not a general solution since it may lead to security issues. And only boost the performance for some platforms in AOT mode and don't support hardware trap for memory boundary check. + +1. Build WAMR with `-DWAMR_CONFIGUABLE_BOUNDS_CHECKS=1` option. + +2. Compile AOT module by wamrc with `--bounds-check=0` option. + +3. Run the AOT module by iwasm with `--disable-bounds-checks` option. + +> Note: The size of AOT file will be much smaller than the default, and some tricks are possible such as let the wasm application access the memory of host os directly. +> Please notice that if this option is enabled, the wasm spec test will fail since it requires the memory boundary check. For example, the runtime will crash when accessing the memory out of the boundary in some cases instead of throwing an exception as the spec requires. + +You should only use this method for well tested wasm applications and make sure the memory access is safe. + +## 7. Use linux-perf + +Linux perf is a powerful tool to analyze the performance of a program, developer can use it to find the hot functions and optimize them. It is one profiler supported by WAMR. In order to use it, you need to add `--perf-profile` while running _iwasm_. By default, it is disabled. + +> [!CAUTION] +> For now, only llvm-jit mode supports linux-perf. + +Here is a basic example, if there is a Wasm application _foo.wasm_, you'll execute. + +``` +$ perf record --output=perf.data.raw -- iwasm --perf-profile foo.wasm +``` + +This will create a _perf.data_ and a _jit-xxx.dump_ under _~/.debug.jit/_ folder. This extra file is WAMR generated at runtime, and it contains the mapping between the JIT code and the original Wasm function names. + +The next thing need to do is to merge _jit-xxx.dump_ file into the _perf.data_. + +``` +$ perf inject --jit --input=perf.data.raw --output=perf.data +``` + +This step will create a lot of _jitted-xxxx-N.so_ which are ELF images for all JIT functions created at runtime. + +> [!TIP] +> add `-v` and check if there is output likes _write ELF image ..._. If yes, it means above merge is successful. + +Finally, you can use _perf report_ to analyze the performance. + +``` +$ perf report --input=perf.data +``` + +> [!CAUTION] +> Using release builds of llvm and iwasm will produce "[unknown]" functions in the call graph. It is not only because +> of the missing debug information, but also because of removing frame pointers. To get the complete result, please +> use debug builds of both llvm and iwasm. +> +> Wasm functions names are stored in _the custom name section_. Toolchains always generate the custom name section in both debug and release builds. However, the custom name section is stripped to pursue smallest size in release build. So, if you want to get a understandable result, please search the manual of toolchain to look for a way to keep the custom name section. +> +> For example, with EMCC, you can add `-g2`. +> +> If not able to get the context of the custom name section, WAMR will use `aot_func#N` to represent the function name. `N` is from 0. `aot_func#0` represents the first *not imported wasm function*. + +### 7.1 Flamegraph + +[Flamegraph](https://www.brendangregg.com/flamegraphs.html) is a powerful tool to visualize stack traces of profiled software so that the most frequent code-paths can be identified quickly and accurately. In order to use it, you need to [capture graphs](https://github.com/brendangregg/FlameGraph#1-capture-stacks) when running `perf record` + +``` +$ perf record -k mono --call-graph=fp --output=perf.data.raw -- iwasm --perf-profile foo.wasm +``` + +merge the _jit-xxx.dump_ file into the _perf.data.raw_. + +``` +$ perf inject --jit --input=perf.data.raw --output=perf.data +``` + +generate the stack trace file. + +``` +$ perf script > out.perf +``` + +[fold stacks](https://github.com/brendangregg/FlameGraph#2-fold-stacks). + +``` +$ ./FlameGraph/stackcollapse-perf.pl out.perf > out.folded +``` + +[render a flamegraph](https://github.com/brendangregg/FlameGraph#3-flamegraphpl) + +``` +$ ./FlameGraph/flamegraph.pl out.folded > perf.foo.wasm.svg +``` + +> [!TIP] +> use `grep` to pick up folded stacks you are interested in or filter out something. +> +> For example, if just want to see stacks of wasm functions, you can use +> +> ```bash +> # only jitted functions +> $ grep "wasm_runtime_invoke_native" out.folded | ./FlameGraph/flamegraph.pl > perf.foo.wasm.only.svg +> ``` diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/app_framework.PNG b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/app_framework.PNG similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/app_framework.PNG rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/app_framework.PNG diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/embed.PNG b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/embed.PNG similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/embed.PNG rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/embed.PNG diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/extend_library.PNG b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/extend_library.PNG similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/extend_library.PNG rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/extend_library.PNG diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/multi_module_pic1.png b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/multi_module_pic1.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/multi_module_pic1.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/multi_module_pic1.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/native_call_wasm.PNG b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/native_call_wasm.PNG similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/native_call_wasm.PNG rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/native_call_wasm.PNG diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/request.PNG b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/request.PNG similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/request.PNG rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/request.PNG diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/safe.PNG b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/safe.PNG similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/safe.PNG rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/safe.PNG diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/sensor_callflow.PNG b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/sensor_callflow.PNG similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/sensor_callflow.PNG rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/sensor_callflow.PNG diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/sub.PNG b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/sub.PNG similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/sub.PNG rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/sub.PNG diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/vgl_demo.png b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/vgl_demo.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/vgl_demo.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/vgl_demo.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/vgl_demo2.png b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/vgl_demo2.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/vgl_demo2.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/vgl_demo2.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/vgl_demo_linux.png b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/vgl_demo_linux.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/vgl_demo_linux.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/vgl_demo_linux.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/vgl_linux.PNG b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/vgl_linux.PNG similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/vgl_linux.PNG rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/vgl_linux.PNG diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/wamr-arch.JPG b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/wamr-arch.JPG similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/wamr-arch.JPG rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/wamr-arch.JPG diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/wamr_memory_model.png b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/wamr_memory_model.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/wamr_memory_model.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/wamr_memory_model.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/wamr_menu_config.png b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/wamr_menu_config.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/pics/wamr_menu_config.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/pics/wamr_menu_config.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/port_wamr.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/port_wamr.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/port_wamr.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/port_wamr.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/pthread_impls.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/pthread_impls.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/pthread_impls.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/pthread_impls.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/pthread_library.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/pthread_library.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/pthread_library.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/pthread_library.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/ref_types.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/ref_types.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/ref_types.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/ref_types.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/release_ack.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/release_ack.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/release_ack.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/release_ack.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/roadmap.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/roadmap.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/roadmap.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/roadmap.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/semantic_version.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/semantic_version.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/semantic_version.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/semantic_version.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/socket_api.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/socket_api.md similarity index 97% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/socket_api.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/socket_api.md index 9e65d33cd5e..eff93761799 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/socket_api.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/socket_api.md @@ -58,7 +58,7 @@ enabled. _iwasm_ accepts address ranges via an option, `--addr-pool`, to implement the capability control. All IP address the WebAssembly application may need to `bind()` or `connect()` -should be announced first. Every IP address should be in CIRD notation. +should be announced first. Every IP address should be in CIDR notation. ```bash $ iwasm --addr-pool=1.2.3.4/15,2.3.4.6/16 socket_example.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/source_debugging.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/source_debugging.md similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/source_debugging.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/source_debugging.md index a9fa0930713..513185fe88c 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/source_debugging.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/source_debugging.md @@ -44,7 +44,7 @@ iwasm -g=127.0.0.1:1234 test.wasm ``` bash git clone --branch release/13.x --depth=1 https://github.com/llvm/llvm-project cd llvm-project -git apply ${WAMR_ROOT}/build-scripts/lldb-wasm.patch +git apply ${WAMR_ROOT}/build-scripts/lldb_wasm.patch mkdir build-lldb cmake -S ./llvm -B build-lldb \ -G Ninja \ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/wamr_api.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/wamr_api.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/wamr_api.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/wamr_api.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/doc/wasm_c_api.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/wasm_c_api.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/doc/wasm_c_api.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/doc/wasm_c_api.md diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/doc/xip.md b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/xip.md new file mode 100644 index 00000000000..a76c7615c8c --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/doc/xip.md @@ -0,0 +1,131 @@ +# WAMR XIP (Execution In Place) feature introduction + +Some IoT devices may require to run the AOT file from flash or ROM which is read-only, so as to reduce the memory consumption, or resolve the issue that there is no executable memory available to run AOT code. In such case, the AOT code inside the AOT file shouldn't be duplicated into memory and shouldn't be modified (or patched) by the AOT relocations. To address this, WAMR implements the XIP (Execution In Place) feature, which generates the AOT relocations as few as possible: +- In the AOT code, an AOT function calls other functions with indirect mode: it doesn't call other functions directly, but looks up their pointers from the function pointer table passed by its first argument exec_env, and then calls the function pointer found. By this way the relocations to other functions are eliminated. +- Eliminate the calls to the LLVM intrinsic functions, or, replace calling them with calling runtime self implemented functions instead, e.g. the calling to `llvm.experimental.constrained.fadd.f32` is replaced by the calling to `aot_intrinsic_fadd_f32`. + +The XIP file is an AOT file without (or with few) relocations to patch the AOT code (or text section). Developer can use the option `--enable-indirect-mode --disable-llvm-intrinsics` for wamrc to generate the AOT file, e.g.: +```bash +wamrc --enable-indirect-mode --disable-llvm-intrinsics -o +or +wamrc --xip -o +``` + +Note: --xip is a short option for --enable-indirect-mode --disable-llvm-intrinsics + +## Known issues + +There may be some relocations to the ".rodata" like sections which require to patch the AOT code. More work will be done to resolve it in the future. + +## Tuning the XIP intrinsic functions + +WAMR provides a default mapping table for some targets, but it may not be the best one for your target. And it doesn't cover all the supported targets. + +So, wamrc provides the option `--enable-builtin-intrinsics=` to make it possible to tune the intrinsic functions for your target. + +Firstly, you should understand why we don't use the LLVM intrinsic functions directly. The reason is that the LLVM intrinsic functions can't map to the native instructions directly, e.g. the LLVM intrinsic function `i32.div_s` can't map to the native instruction if the target doesn't support the division instruction, it will be translated to a function call to the runtime function from libgcc/compiler-rt. This will cause the AOT code to have the relocations to the libgcc/compiler-rt, which is not acceptable for the XIP feature. + +So, we need to replace the LLVM intrinsic functions with the runtime self implemented functions, which can be called through the function pointer table (--enable-indirect-mode) and don't have the relocations to the libgcc/compiler-rt (--disable-llvm-intrinsics). + +Available intrinsic functions for tuning: + +| LLVM intrinsic function | Explanation | +| --- | --- | +| llvm.experimental.constrained.fadd.f32 | float32 add | +| llvm.experimental.constrained.fadd.f64 | float64 add | +| llvm.experimental.constrained.fsub.f32 | float32 sub | +| llvm.experimental.constrained.fsub.f64 | float64 sub | +| llvm.experimental.constrained.fmul.f32 | float32 mul | +| llvm.experimental.constrained.fmul.f64 | float64 mul | +| llvm.experimental.constrained.fdiv.f32 | float32 div | +| llvm.experimental.constrained.fdiv.f64 | float64 div | +| llvm.fabs.f32 | float32 abs | +| llvm.fabs.f64 | float64 abs | +| llvm.ceil.f32 | float32 ceil | +| llvm.ceil.f64 | float64 ceil | +| llvm.floor.f32 | float32 floor | +| llvm.floor.f64 | float64 floor | +| llvm.trunc.f32 | float32 trunc | +| llvm.trunc.f64 | float64 trunc | +| llvm.rint.f32 | float32 rint | +| llvm.rint.f64 | float64 rint | +| llvm.sqrt.f32 | float32 sqrt | +| llvm.sqrt.f64 | float64 sqrt | +| llvm.copysign.f32 | float32 copysign | +| llvm.copysign.f64 | float64 copysign | +| llvm.minnum.f32 | float32 minnum | +| llvm.minnum.f64 | float64 minnum | +| llvm.maxnum.f32 | float32 maxnum | +| llvm.maxnum.f64 | float64 maxnum | +| llvm.ctlz.i32 | int32 count leading zeros | +| llvm.ctlz.i64 | int64 count leading zeros | +| llvm.cttz.i32 | int32 count trailing zeros | +| llvm.cttz.i64 | int64 count trailing zeros | +| llvm.ctpop.i32 | int32 count population | +| llvm.ctpop.i64 | int64 count population | +| f64_convert_i32_s | int32 to float64 | +| f64_convert_i32_u | uint32 to float64 | +| f32_convert_i32_s | int32 to float32 | +| f32_convert_i32_u | uint32 to float32 | +| f64_convert_i64_s | int64 to float64 | +| f64_convert_i64_u | uint64 to float64 | +| f32_convert_i64_s | int64 to float32 | +| f32_convert_i64_u | uint64 to float32 | +| i32_trunc_f32_s | float32 to int32 | +| i32_trunc_f32_u | float32 to uint32 | +| i32_trunc_f64_s | float64 to int32 | +| i32_trunc_f64_u | float64 to uint32 | +| i64_trunc_f64_s | float64 to int64 | +| i64_trunc_f64_u | float64 to uint64 | +| i64_trunc_f32_s | float32 to int64 | +| i64_trunc_f32_u | float32 to uint64 | +| f32_demote_f64 | float64 to float32 | +| f64_promote_f32 | float32 to float64 | +| f32_cmp | float32 compare | +| f64_cmp | float64 compare | +| i64.div_s | int64 div | +| i64.div_u | uint64 div | +| i32.div_s | int32 div | +| i32.div_u | uint32 div | +| i64.rem_s | int64 rem | +| i64.rem_u | uint64 rem | +| i32.rem_s | int32 rem | +| i32.rem_u | uint32 rem | +| i64.or | int64 or | +| i64.and | int64 and | +| i32.const | emit i32 const into constant table | +| i64.const | emit i64 const into constant table | +| f32.const | emit f32 const into constant table | +| f64.const | emit f64 const into constant table | + +And also provide combined intrinsic functions to simplify the tuning: + +* all: all the above intrinsic functions +* i32.common: i32.div_s, i32.div_u, i32.rem_s, i32.rem_u +* i64.common: i64.div_s, i64.div_u, i64.rem_s, i64.rem_u, i64.or, i64.and +* f32.common: f32_cmp, llvm.experimental.constrained.fadd.f32, llvm.experimental.constrained.fsub.f32, llvm.experimental.constrained.fmul.f32, llvm.experimental.constrained.fdiv.f32, llvm.fabs.f32, llvm.ceil.f32, llvm.floor.f32, llvm.trunc.f32, llvm.rint.f32, llvm.sqrt.f32, llvm.copysign.f32, llvm.minnum.f32, llvm.maxnum.f32 +* f64.common: f32_demote_f64, f64_promote_f32, f64_cmp, llvm.experimental.constrained.fadd.f64, llvm.experimental.constrained.fsub.f64, llvm.experimental.constrained.fmul.f64, llvm.experimental.constrained.fdiv.f64, llvm.fabs.f64, llvm.ceil.f64, llvm.floor.f64, llvm.trunc.f64, llvm.rint.f64, llvm.sqrt.f64, llvm.copysign.f64, llvm.minnum.f64, llvm.maxnum.f64 +* f32xi32: i32_trunc_f32_s, i32_trunc_f32_u, f32_convert_i32_s, f32_convert_i32_u +* f64xi32: i32_trunc_f64_s, i32_trunc_f64_u, f64_convert_i32_s, f64_convert_i32_u +* f32xi64: i64_trunc_f32_s, i64_trunc_f32_u, f32_convert_i64_s, f32_convert_i64_u +* f64xi64: i64_trunc_f64_s, i64_trunc_f64_u, f64_convert_i64_s, f64_convert_i64_u +* constop: i32.const, i64.const, f32.const, f64.const +* fpxint: f32xi32, f64xi32, f32xi64, f64xi64 +* fp.common: f32.common, f64.common + + +### Example + +For ARM Cortex-M55, since it has double precision floating point unit, so it can support f32/f64 operations. But as a 32-bit MCU, it can only support 32-bit integer operations. So we can use the following command to generate the XIP binary: + +``` +wamrc --target=thumbv8m.main --cpu=cortex-m55 --xip --enable-builtin-intrinsics=i64.common -o hello.aot hello.wasm +``` + +For ARM Cortex-M3, since it has no floating point unit, and it can only support 32-bit integer operations. So we can use the following command to generate the XIP binary: + +``` +wamrc --target=thumbv7m --cpu=cortex-m3 --xip --enable-builtin-intrinsics=i64.common,fp.common,fpxint -o hello.aot hello.wasm +``` + +Other platforms can be tuned in the same way, which intrinsic should be enabled depends on the target platform's hardware capability. diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/build.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/build.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/go.mod b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/go.mod new file mode 100644 index 00000000000..b7e428654cb --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/go.mod @@ -0,0 +1,5 @@ +module github.com/bytecodealliance/wasm-micro-runtime/language-bindings/go + +go 1.15 + +require github.com/stretchr/testify v1.7.0 diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/go.sum b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/go.sum similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/go.sum rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/go.sum diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/samples/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/samples/build.sh new file mode 100755 index 00000000000..0799fe5a0da --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/samples/build.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +CUR_DIR=$PWD + +pushd ${CUR_DIR}/.. > /dev/null 2>&1 +./build.sh +popd > /dev/null 2>& 1 + +cd ${CUR_DIR} +rm -f test +go build test.go +./test diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/samples/run.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/samples/run.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/samples/run.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/samples/run.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/samples/test.go b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/samples/test.go similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/samples/test.go rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/samples/test.go index aacb4a95047..d0fc7d8b24a 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/samples/test.go +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/samples/test.go @@ -6,7 +6,7 @@ package main import ( - "gitlab.alipay-inc.com/TNT_Runtime/ant-runtime/bindings/go/wamr" + "github.com/bytecodealliance/wasm-micro-runtime/language-bindings/go/wamr" "fmt" ) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/samples/wasm-app/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/samples/wasm-app/build.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/samples/wasm-app/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/samples/wasm-app/build.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/samples/wasm-app/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/samples/wasm-app/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/samples/wasm-app/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/samples/wasm-app/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/cgo.go b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/cgo.go similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/cgo.go rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/cgo.go diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/instance.go b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/instance.go similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/instance.go rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/instance.go index 08757f4dc6e..7c761ee99b1 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/instance.go +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/instance.go @@ -272,7 +272,9 @@ func (self *Instance) CallFuncV(funcName string, for i = 0; i < result_count; i++ { switch result_types[i] { case C.WASM_I32: + fallthrough case C.WASM_FUNCREF: + fallthrough case C.WASM_ANYREF: i32 := (int32)(argv[argc]) results[i] = i32 diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/instance_test.go b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/instance_test.go similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/instance_test.go rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/instance_test.go diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/module.go b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/module.go similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/module.go rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/module.go diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/module_test.go b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/module_test.go similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/module_test.go rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/module_test.go diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/packaged/include/dummy.go b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/packaged/include/dummy.go similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/packaged/include/dummy.go rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/packaged/include/dummy.go diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/packaged/lib/darwin-aarch64/dummy.go b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/packaged/lib/darwin-aarch64/dummy.go similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/packaged/lib/darwin-aarch64/dummy.go rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/packaged/lib/darwin-aarch64/dummy.go diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/packaged/lib/darwin-amd64/dummy.go b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/packaged/lib/darwin-amd64/dummy.go similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/packaged/lib/darwin-amd64/dummy.go rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/packaged/lib/darwin-amd64/dummy.go diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/packaged/lib/dummy.go b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/packaged/lib/dummy.go similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/packaged/lib/dummy.go rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/packaged/lib/dummy.go diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/packaged/lib/linux-amd64/dummy.go b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/packaged/lib/linux-amd64/dummy.go similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/packaged/lib/linux-amd64/dummy.go rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/packaged/lib/linux-amd64/dummy.go diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/runtime.go b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/runtime.go similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/runtime.go rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/runtime.go diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/runtime_test.go b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/runtime_test.go similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/go/wamr/runtime_test.go rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/go/wamr/runtime_test.go diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/.gitignore similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/.gitignore rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/.gitignore diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/LICENSE b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/LICENSE similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/LICENSE rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/LICENSE diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/MANIFEST.in b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/MANIFEST.in similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/MANIFEST.in rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/MANIFEST.in diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/README.md similarity index 92% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/README.md index ec82ee191c6..96b7a7ff9b3 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/README.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/README.md @@ -4,6 +4,8 @@ The WAMR Python package contains a set of high-level bindings for WAMR API and W ## Installation +* **Notice**: This python package need python >= `3.9`. + To Install from local source tree in _development mode_ run the following command, ```bash diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/pyproject.toml b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/pyproject.toml similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/pyproject.toml rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/pyproject.toml diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/setup.py b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/setup.py similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/setup.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/setup.py index fb7993e683a..ec080e4eeda 100755 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/setup.py +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/setup.py @@ -62,4 +62,5 @@ def run(self): 'install': PreInstallCommand, 'egg_info': PreEggInfoCommand, }, + python_requires='>=3.9' ) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/src/wamr/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/src/wamr/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/src/wamr/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/src/wamr/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/src/wamr/libs/.placeholder b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/src/wamr/libs/.placeholder similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/src/wamr/libs/.placeholder rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/src/wamr/libs/.placeholder diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/src/wamr/wamrapi/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/src/wamr/wamrapi/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/src/wamr/wamrapi/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/src/wamr/wamrapi/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/src/wamr/wamrapi/wamr.py b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/src/wamr/wamrapi/wamr.py similarity index 55% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/src/wamr/wamrapi/wamr.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/src/wamr/wamrapi/wamr.py index abbd23227c4..1bd6e547d7c 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/src/wamr/wamrapi/wamr.py +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/src/wamr/wamrapi/wamr.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception from ctypes import Array +from ctypes import addressof from ctypes import c_char from ctypes import c_uint from ctypes import c_uint8 @@ -10,6 +11,8 @@ from ctypes import create_string_buffer from ctypes import POINTER from ctypes import pointer +from typing import List +from typing import Tuple from wamr.wamrapi.iwasm import String from wamr.wamrapi.iwasm import Alloc_With_Pool from wamr.wamrapi.iwasm import RuntimeInitArgs @@ -31,6 +34,14 @@ from wamr.wamrapi.iwasm import wasm_runtime_module_free from wamr.wamrapi.iwasm import wasm_runtime_register_natives from wamr.wamrapi.iwasm import NativeSymbol +from wamr.wamrapi.iwasm import wasm_runtime_start_debug_instance +from wamr.wamrapi.iwasm import wasm_runtime_call_indirect +from wamr.wamrapi.iwasm import wasm_runtime_get_module_inst +from wamr.wamrapi.iwasm import wasm_runtime_addr_app_to_native +from wamr.wamrapi.iwasm import wasm_runtime_addr_native_to_app +from wamr.wamrapi.iwasm import wasm_runtime_set_wasi_args + +ID_TO_EXEC_ENV_MAPPING = {} class Engine: @@ -43,16 +54,26 @@ def __del__(self): print("deleting Engine") wasm_runtime_destroy() - def _get_init_args(self, heap_size: int = 1024 * 512) -> RuntimeInitArgs: + def _get_init_args( + self, + heap_size: int = 1024 * 1024 * 2, + ip_addr: str = "127.0.0.1", + instance_port: int = 1234, + ) -> RuntimeInitArgs: init_args = RuntimeInitArgs() init_args.mem_alloc_type = Alloc_With_Pool init_args.mem_alloc_option.pool.heap_buf = cast( (c_char * heap_size)(), c_void_p ) init_args.mem_alloc_option.pool.heap_size = heap_size + # Debug port setting + init_args.ip_addr = bytes(ip_addr, "utf-8") + init_args.instance_port = instance_port return init_args - def register_natives(self, module_name: str, native_symbols: list[NativeSymbol]) -> None: + def register_natives( + self, module_name: str, native_symbols: List[NativeSymbol] + ) -> None: module_name = String.from_param(module_name) # WAMR does not copy the symbols. We must store them. for native in native_symbols: @@ -62,12 +83,13 @@ def register_natives(self, module_name: str, native_symbols: list[NativeSymbol]) module_name, cast( (NativeSymbol * len(native_symbols))(*native_symbols), - POINTER(NativeSymbol) + POINTER(NativeSymbol), ), - len(native_symbols) + len(native_symbols), ): raise Exception("Error while registering symbols") + class Module: __create_key = object() @@ -86,7 +108,7 @@ def __del__(self): print("deleting Module") wasm_runtime_unload(self.module) - def _create_module(self, fp: str) -> tuple[wasm_module_t, Array[c_uint]]: + def _create_module(self, fp: str) -> Tuple[wasm_module_t, "Array[c_uint]"]: with open(fp, "rb") as f: data = f.read() data = (c_uint8 * len(data))(*data) @@ -99,14 +121,52 @@ def _create_module(self, fp: str) -> tuple[wasm_module_t, Array[c_uint]]: class Instance: - def __init__(self, module: Module, stack_size: int = 65536, heap_size: int = 16384): + def __init__( + self, + module: Module, + stack_size: int = 65536, + heap_size: int = 16384, + dir_list: List[str] | None = None, + preinitialized_module_inst: wasm_module_inst_t | None = None, + ): + # Store module ensures GC does not remove it self.module = module - self.module_inst = self._create_module_inst(module, stack_size, heap_size) + if dir_list: + self._set_wasi_args(module, dir_list) + if preinitialized_module_inst is None: + self.module_inst = self._create_module_inst(module, stack_size, heap_size) + else: + self.module_inst = preinitialized_module_inst def __del__(self): print("deleting Instance") wasm_runtime_deinstantiate(self.module_inst) + def _set_wasi_args(self, module: Module, dir_list: List[str]) -> None: + LP_c_char = POINTER(c_char) + LP_LP_c_char = POINTER(LP_c_char) + + p = (LP_c_char * len(dir_list))() + for i, dir in enumerate(dir_list): + enc_dir = dir.encode("utf-8") + p[i] = create_string_buffer(enc_dir) + + na = cast(p, LP_LP_c_char) + wasm_runtime_set_wasi_args( + module.module, na, len(dir_list), None, 0, None, 0, None, 0 + ) + + def _create_module_inst( + self, module: Module, stack_size: int, heap_size: int + ) -> wasm_module_inst_t: + error_buf = create_string_buffer(128) + module_inst = wasm_runtime_instantiate( + module.module, stack_size, heap_size, error_buf, len(error_buf) + ) + if not module_inst: + raise Exception("Error while creating module instance") + return module_inst + def malloc(self, nbytes: int, native_handler) -> c_uint: return wasm_runtime_module_malloc(self.module_inst, nbytes, native_handler) @@ -119,31 +179,70 @@ def lookup_function(self, name: str) -> wasm_function_inst_t: raise Exception("Error while looking-up function") return func - def _create_module_inst(self, module: Module, stack_size: int, heap_size: int) -> wasm_module_inst_t: - error_buf = create_string_buffer(128) - module_inst = wasm_runtime_instantiate( - module.module, stack_size, heap_size, error_buf, len(error_buf) - ) - if not module_inst: - raise Exception("Error while creating module instance") - return module_inst + def native_addr_to_app_addr(self, native_addr) -> c_void_p: + return wasm_runtime_addr_native_to_app(self.module_inst, native_addr) + + def app_addr_to_native_addr(self, app_addr) -> c_void_p: + return wasm_runtime_addr_app_to_native(self.module_inst, app_addr) class ExecEnv: def __init__(self, module_inst: Instance, stack_size: int = 65536): self.module_inst = module_inst self.exec_env = self._create_exec_env(module_inst, stack_size) + self.env = addressof(self.exec_env.contents) + self.own_c = True + + ID_TO_EXEC_ENV_MAPPING[str(self.env)] = self def __del__(self): - print("deleting ExecEnv") - wasm_runtime_destroy_exec_env(self.exec_env) + if self.own_c: + print("deleting ExecEnv") + wasm_runtime_destroy_exec_env(self.exec_env) + del ID_TO_EXEC_ENV_MAPPING[str(self.env)] + + def _create_exec_env( + self, module_inst: Instance, stack_size: int + ) -> wasm_exec_env_t: + exec_env = wasm_runtime_create_exec_env(module_inst.module_inst, stack_size) + if not exec_env: + raise Exception("Error while creating execution environment") + return exec_env def call(self, func: wasm_function_inst_t, argc: int, argv: "POINTER[c_uint]"): if not wasm_runtime_call_wasm(self.exec_env, func, argc, argv): raise Exception("Error while calling function") - def _create_exec_env(self, module_inst: Instance, stack_size: int) -> wasm_exec_env_t: - exec_env = wasm_runtime_create_exec_env(module_inst.module_inst, stack_size) - if not exec_env: - raise Exception("Error while creating execution environment") - return exec_env + def get_module_inst(self) -> Instance: + return self.module_inst + + def start_debugging(self) -> int: + return wasm_runtime_start_debug_instance(self.exec_env) + + def call_indirect(self, element_index: int, argc: int, argv: "POINTER[c_uint]"): + if not wasm_runtime_call_indirect(self.exec_env, element_index, argc, argv): + raise Exception("Error while calling function") + + @staticmethod + def wrap(env: int) -> "ExecEnv": + if str(env) in ID_TO_EXEC_ENV_MAPPING: + return ID_TO_EXEC_ENV_MAPPING[str(env)] + return InternalExecEnv(env) + + +class InternalExecEnv(ExecEnv): + """ + Generate Python ExecEnv-like object from a `wasm_exec_env_t` index. + """ + + def __init__(self, env: int): + self.env = env + self.exec_env = cast(env, wasm_exec_env_t) + self.module_inst = Instance( + module=object(), + preinitialized_module_inst=wasm_runtime_get_module_inst(self.exec_env), + ) + ID_TO_EXEC_ENV_MAPPING[str(env)] = self + + def __del__(self): + del ID_TO_EXEC_ENV_MAPPING[str(self.env)] diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/src/wamr/wasmcapi/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/src/wamr/wasmcapi/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/src/wamr/wasmcapi/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/src/wamr/wasmcapi/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/src/wamr/wasmcapi/binding.py b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/src/wamr/wasmcapi/binding.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/src/wamr/wasmcapi/binding.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/src/wamr/wasmcapi/binding.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/src/wamr/wasmcapi/ffi.py b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/src/wamr/wasmcapi/ffi.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/src/wamr/wasmcapi/ffi.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/src/wamr/wasmcapi/ffi.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/utils/create_lib.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/utils/create_lib.sh similarity index 81% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/utils/create_lib.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/utils/create_lib.sh index b7e10d3ee53..801186e9792 100755 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/utils/create_lib.sh +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/utils/create_lib.sh @@ -12,7 +12,12 @@ WAMR_BUILD_PLATFORM=${WAMR_BUILD_PLATFORM:-${UNAME}} cd ${ROOT_DIR}/product-mini/platforms/${WAMR_BUILD_PLATFORM} mkdir -p build && cd build -cmake .. +cmake \ + -DWAMR_BUILD_DEBUG_INTERP=1 \ + -DWAMR_BUILD_LIB_PTHREAD=1 \ + -DWAMR_BUILD_LIB_WASI_THREADS=1 \ + -DWAMR_BUILD_LIB_WASI=1 \ + .. make -j case ${UNAME} in diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wamr-api/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/README.md similarity index 53% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wamr-api/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/README.md index 5ee672e29b7..236150ce4c0 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wamr-api/README.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/README.md @@ -1,5 +1,7 @@ # WARM API +* **Notice**: The python package `wamr.wamrapi.wamr` need python >= `3.9`. + ## Setup ### Pre-requisites @@ -20,10 +22,7 @@ bash language-bindings/python/utils/create_lib.sh This will build and copy libiwasm into the package. -## Examples - -There is a [simple example](./samples/main.py) to show how to use bindings. +## Samples -``` -python samples/main.py -``` +- **[basic](./samples/basic)**: Demonstrating how to use basic python bindings. +- **[native-symbol](./samples/native-symbol)**: Desmostrate how to call WASM from Python and how to export Python functions into WASM. diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wamr-api/requirements.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/requirements.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wamr-api/requirements.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/requirements.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wamr-api/samples/compile.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/basic/compile.sh old mode 100644 new mode 100755 similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wamr-api/samples/compile.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/basic/compile.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wamr-api/samples/main.py b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/basic/main.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wamr-api/samples/main.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/basic/main.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wamr-api/samples/sum.c b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/basic/sum.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wamr-api/samples/sum.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/basic/sum.c diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/native-symbol/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/native-symbol/README.md new file mode 100644 index 00000000000..75d4fab46f4 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/native-symbol/README.md @@ -0,0 +1,44 @@ +# Native Symbol + +This sample demonstrates how to declare a Python function as `NativeSymbol`. + +Steps of the example: +1. Load WASM from Python +2. Call `c_func` from WASM. +3. `c_func` calls `python_func` from Python. +4. `python_func` calls `add` from WASM. +5. Result shown by Python. + +## Build + +Follow instructions [build wamr Python package](../../README.md). + +Compile WASM app example, + +```sh +./compile.sh +``` + +## Run sample + +```sh +python main.py +``` + +Output: + +``` +python: calling c_func(10) +c: in c_func with input: 10 +c: calling python_func(11) +python: in python_func with input: 11 +python: calling add(11, 1000) +python: result from add: 1011 +c: result from python_func: 1012 +c: returning 1013 +python: result from c_func: 1013 +deleting ExecEnv +deleting Instance +deleting Module +deleting Engine +``` diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/native-symbol/compile.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/native-symbol/compile.sh new file mode 100755 index 00000000000..4e504b018b1 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/native-symbol/compile.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +/opt/wasi-sdk/bin/clang \ + -O0 -z stack-size=4096 -Wl,--initial-memory=65536 \ + -Wl,--export=main -Wl,--export=__main_argc_argv \ + -Wl,--export=__data_end -Wl,--export=__heap_base \ + -Wl,--strip-all,--no-entry \ + -Wl,--allow-undefined \ + -Wl,--export=c_func\ + -Wl,--export=add\ + -o func.wasm func.c diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/native-symbol/func.c b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/native-symbol/func.c new file mode 100644 index 00000000000..4411a6b2cf1 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/native-symbol/func.c @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include + +int +python_func(int val); + +int +add(int val1, int val2) +{ + return val1 + val2; +} + +int +c_func(int val) +{ + printf("c: in c_func with input: %d\n", val); + printf("c: calling python_func(%d)\n", val + 1); + int res = python_func(val + 1); + printf("c: result from python_func: %d\n", res); + printf("c: returning %d\n", res + 1); + return res + 1; +} + +int +main() +{} diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/native-symbol/main.py b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/native-symbol/main.py new file mode 100644 index 00000000000..3871ef1398a --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wamr-api/samples/native-symbol/main.py @@ -0,0 +1,59 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +from wamr.wamrapi.wamr import Engine, Module, Instance, ExecEnv +from ctypes import c_uint +import pathlib +from ctypes import c_int32 +from ctypes import c_uint +from ctypes import c_void_p +from ctypes import cast +from ctypes import CFUNCTYPE + +from wamr.wamrapi.iwasm import NativeSymbol +from wamr.wamrapi.iwasm import String +from wamr.wamrapi.wamr import ExecEnv + +def python_func(env: int, value: int) -> int: + print("python: in python_func with input:", value) + # Example of generating ExecEnv from `wasm_exec_env_t`` + exec_env = ExecEnv.wrap(env) + add = exec_env.get_module_inst().lookup_function("add") + const = 1000 + argv = (c_uint * 2)(value, const) + print(f"python: calling add({value}, {const})") + exec_env.call(add, 2, argv) + res = argv[0] + print("python: result from add:", res) + return res + 1 + + +native_symbols = (NativeSymbol * 1)( + *[ + NativeSymbol( + symbol=String.from_param("python_func"), + func_ptr=cast( + CFUNCTYPE(c_int32, c_void_p, c_int32)(python_func), c_void_p + ), + signature=String.from_param("(i)i"), + ) + ] +) + +def main(): + engine = Engine() + engine.register_natives("env", native_symbols) + module = Module.from_file(engine, pathlib.Path(__file__).parent / "func.wasm") + module_inst = Instance(module) + exec_env = ExecEnv(module_inst) + + func = module_inst.lookup_function("c_func") + + inp = 10 + print(f"python: calling c_func({inp})") + argv = (c_uint)(inp) + exec_env.call(func, 1, argv) + print("python: result from c_func:", argv.value) + +if __name__ == "__main__": + main() diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/docs/design.md b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/docs/design.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/docs/design.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/docs/design.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/docs/images/python_package_life_cycle.png b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/docs/images/python_package_life_cycle.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/docs/images/python_package_life_cycle.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/docs/images/python_package_life_cycle.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/docs/setup_dev_env.md b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/docs/setup_dev_env.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/docs/setup_dev_env.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/docs/setup_dev_env.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/requirements.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/requirements.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/requirements.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/requirements.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/samples/hello.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/samples/hello.wat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/samples/hello.wat rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/samples/hello.wat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/samples/hello_oop.py b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/samples/hello_oop.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/samples/hello_oop.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/samples/hello_oop.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/samples/hello_procedural.py b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/samples/hello_procedural.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/samples/hello_procedural.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/samples/hello_procedural.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/tests/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/tests/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/context.py b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/tests/context.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/context.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/tests/context.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/test_advanced.py b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/tests/test_advanced.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/test_advanced.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/tests/test_advanced.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/test_basic.py b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/tests/test_basic.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/test_basic.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/tests/test_basic.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/utils/bindgen.py b/lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/utils/bindgen.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/utils/bindgen.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/language-bindings/python/wasm-c-api/utils/bindgen.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/README.md similarity index 94% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/README.md index 5847b246853..22acfeaf46a 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/README.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/README.md @@ -251,17 +251,7 @@ WAMR provides some features which can be easily configured by passing options to ## Zephyr -You need to prepare Zephyr first as described [here](https://docs.zephyrproject.org/latest/getting_started/index.html#get-zephyr-and-install-python-dependencies). - -After that you need to point the `ZEPHYR_BASE` variable to e.g. `~/zephyrproject/zephyr`. Also, it is important that you have `west` available for subsequent actions. - -``` Bash -cd /product-mini/platforms/zephyr/simple -# Execute the ./build_and_run.sh script with board name as parameter. Here take x86 as example: -./build_and_run.sh x86 -``` - -The [Zephyr SDK](https://github.com/zephyrproject-rtos/sdk-ng) provides toolchains for all supported targets. Follow the instructions in the [documentation](https://docs.zephyrproject.org/latest/develop/getting_started/index.html#install-zephyr-sdk) to ensure it is installed and configured correctly. +Please refer to this [README](./platforms/zephyr/simple/README.md) under the Zephyr sample directory for details. Note: WAMR provides some features which can be easily configured by passing options to cmake, please see [WAMR vmcore cmake building configurations](../doc/build_wamr.md#wamr-vmcore-cmake-building-configurations) for details. Currently in Zephyr, interpreter, AOT and builtin libc are enabled by default. @@ -453,3 +443,23 @@ make aos make ``` download the binary to developerkit board, check the output from serial port + +## Cosmopolitan Libc +Currently, only x86_64 architecture with interpreter modes is supported. + +Clone the Cosmopolitan Libc. Setup `cosmocc` as described in [Getting Started](https://github.com/jart/cosmopolitan/#getting-started) being sure to get it into `PATH`. + +Build iwasm +``` Bash +export CC=cosmocc +export CXX=cosmoc++ +rm -rf build +mkdir build +cmake -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=1 -B build +cmake --build build -j +``` + +Run like +``` Bash +./build/iwasm.com +``` diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/app-samples/hello-world-cmake/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/app-samples/hello-world-cmake/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/app-samples/hello-world-cmake/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/app-samples/hello-world-cmake/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/app-samples/hello-world-cmake/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/app-samples/hello-world-cmake/build.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/app-samples/hello-world-cmake/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/app-samples/hello-world-cmake/build.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/app-samples/hello-world-cmake/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/app-samples/hello-world-cmake/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/app-samples/hello-world-cmake/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/app-samples/hello-world-cmake/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/app-samples/hello-world-cmake/print.c b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/app-samples/hello-world-cmake/print.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/app-samples/hello-world-cmake/print.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/app-samples/hello-world-cmake/print.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/app-samples/hello-world/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/app-samples/hello-world/build.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/app-samples/hello-world/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/app-samples/hello-world/build.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/app-samples/hello-world/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/app-samples/hello-world/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/app-samples/hello-world/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/app-samples/hello-world/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/alios-things/aos.mk b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/alios-things/aos.mk similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/alios-things/aos.mk rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/alios-things/aos.mk index 383e0b23970..3f25cb98044 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/alios-things/aos.mk +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/alios-things/aos.mk @@ -98,6 +98,7 @@ $(NAME)_SOURCES := ${SHARED_ROOT}/platform/alios/alios_platform.c \ ${SHARED_ROOT}/mem-alloc/ems/ems_alloc.c \ ${SHARED_ROOT}/mem-alloc/ems/ems_hmu.c \ ${SHARED_ROOT}/utils/bh_assert.c \ + ${SHARED_ROOT}/utils/bh_bitmap.c \ ${SHARED_ROOT}/utils/bh_common.c \ ${SHARED_ROOT}/utils/bh_hashmap.c \ ${SHARED_ROOT}/utils/bh_list.c \ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/alios-things/src/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/alios-things/src/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/alios-things/src/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/alios-things/src/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/alios-things/src/test_wasm.h b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/alios-things/src/test_wasm.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/alios-things/src/test_wasm.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/alios-things/src/test_wasm.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/android/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/android/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/android/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/android/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/android/build_jit.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/android/build_jit.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/android/build_jit.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/android/build_jit.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/android/build_llvm.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/android/build_llvm.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/android/build_llvm.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/android/build_llvm.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/android/wasm-jni.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/android/wasm-jni.cpp similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/android/wasm-jni.cpp rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/android/wasm-jni.cpp diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/common/libc_wasi.c b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/common/libc_wasi.c new file mode 100644 index 00000000000..84e133bc052 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/common/libc_wasi.c @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include + +#include "bh_platform.h" +#include "wasm_export.h" + +typedef struct { + const char *dir_list[8]; + uint32 dir_list_size; + const char *map_dir_list[8]; + uint32 map_dir_list_size; + const char *env_list[8]; + uint32 env_list_size; + const char *addr_pool[8]; + uint32 addr_pool_size; + const char *ns_lookup_pool[8]; + uint32 ns_lookup_pool_size; +} libc_wasi_parse_context_t; + +typedef enum { + LIBC_WASI_PARSE_RESULT_OK = 0, + LIBC_WASI_PARSE_RESULT_NEED_HELP, + LIBC_WASI_PARSE_RESULT_BAD_PARAM +} libc_wasi_parse_result_t; + +static void +libc_wasi_print_help() +{ + printf(" --env= Pass wasi environment variables with " + "\"key=value\"\n"); + printf(" to the program, for example:\n"); + printf(" --env=\"key1=value1\" " + "--env=\"key2=value2\"\n"); + printf(" --dir= Grant wasi access to the given host " + "directories\n"); + printf(" to the program, for example:\n"); + printf(" --dir= --dir=\n"); + printf(" --map-dir= Grant wasi access to the given host " + "directories\n"); + printf(" to the program at a specific guest " + "path, for example:\n"); + printf(" --map-dir= " + "--map-dir=\n"); + printf(" --addr-pool= Grant wasi access to the given network " + "addresses in\n"); + printf(" CIDR notation to the program, seperated " + "with ',',\n"); + printf(" for example:\n"); + printf(" --addr-pool=1.2.3.4/15,2.3.4.5/16\n"); + printf(" --allow-resolve= Allow the lookup of the specific domain " + "name or domain\n"); + printf(" name suffixes using a wildcard, for " + "example:\n"); + printf(" --allow-resolve=example.com # allow the " + "lookup of the specific domain\n"); + printf(" --allow-resolve=*.example.com # allow " + "the lookup of all subdomains\n"); + printf(" --allow-resolve=* # allow any lookup\n"); +} + +static bool +validate_env_str(char *env) +{ + char *p = env; + int key_len = 0; + + while (*p != '\0' && *p != '=') { + key_len++; + p++; + } + + if (*p != '=' || key_len == 0) + return false; + + return true; +} + +libc_wasi_parse_result_t +libc_wasi_parse(char *arg, libc_wasi_parse_context_t *ctx) +{ + if (!strncmp(arg, "--dir=", 6)) { + if (arg[6] == '\0') + return LIBC_WASI_PARSE_RESULT_NEED_HELP; + if (ctx->dir_list_size >= sizeof(ctx->dir_list) / sizeof(char *)) { + printf("Only allow max dir number %d\n", + (int)(sizeof(ctx->dir_list) / sizeof(char *))); + return LIBC_WASI_PARSE_RESULT_BAD_PARAM; + } + ctx->dir_list[ctx->dir_list_size++] = arg + 6; + } + else if (!strncmp(arg, "--map-dir=", 10)) { + if (arg[10] == '\0') + return LIBC_WASI_PARSE_RESULT_NEED_HELP; + if (ctx->map_dir_list_size + >= sizeof(ctx->map_dir_list) / sizeof(char *)) { + printf("Only allow max map dir number %d\n", + (int)(sizeof(ctx->map_dir_list) / sizeof(char *))); + return 1; + } + ctx->map_dir_list[ctx->map_dir_list_size++] = arg + 10; + } + else if (!strncmp(arg, "--env=", 6)) { + char *tmp_env; + + if (arg[6] == '\0') + return LIBC_WASI_PARSE_RESULT_NEED_HELP; + if (ctx->env_list_size >= sizeof(ctx->env_list) / sizeof(char *)) { + printf("Only allow max env number %d\n", + (int)(sizeof(ctx->env_list) / sizeof(char *))); + return LIBC_WASI_PARSE_RESULT_BAD_PARAM; + } + tmp_env = arg + 6; + if (validate_env_str(tmp_env)) + ctx->env_list[ctx->env_list_size++] = tmp_env; + else { + printf("Wasm parse env string failed: expect \"key=value\", " + "got \"%s\"\n", + tmp_env); + return LIBC_WASI_PARSE_RESULT_NEED_HELP; + } + } + /* TODO: parse the configuration file via --addr-pool-file */ + else if (!strncmp(arg, "--addr-pool=", strlen("--addr-pool="))) { + /* like: --addr-pool=100.200.244.255/30 */ + char *token = NULL; + + if ('\0' == arg[12]) + return LIBC_WASI_PARSE_RESULT_NEED_HELP; + + token = strtok(arg + strlen("--addr-pool="), ","); + while (token) { + if (ctx->addr_pool_size + >= sizeof(ctx->addr_pool) / sizeof(char *)) { + printf("Only allow max address number %d\n", + (int)(sizeof(ctx->addr_pool) / sizeof(char *))); + return LIBC_WASI_PARSE_RESULT_BAD_PARAM; + } + + ctx->addr_pool[ctx->addr_pool_size++] = token; + token = strtok(NULL, ";"); + } + } + else if (!strncmp(arg, "--allow-resolve=", 16)) { + if (arg[16] == '\0') + return LIBC_WASI_PARSE_RESULT_NEED_HELP; + if (ctx->ns_lookup_pool_size + >= sizeof(ctx->ns_lookup_pool) / sizeof(ctx->ns_lookup_pool[0])) { + printf("Only allow max ns lookup number %d\n", + (int)(sizeof(ctx->ns_lookup_pool) + / sizeof(ctx->ns_lookup_pool[0]))); + return LIBC_WASI_PARSE_RESULT_BAD_PARAM; + } + ctx->ns_lookup_pool[ctx->ns_lookup_pool_size++] = arg + 16; + } + else { + return LIBC_WASI_PARSE_RESULT_NEED_HELP; + } + return LIBC_WASI_PARSE_RESULT_OK; +} + +void +libc_wasi_init(wasm_module_t wasm_module, int argc, char **argv, + libc_wasi_parse_context_t *ctx) +{ + wasm_runtime_set_wasi_args(wasm_module, ctx->dir_list, ctx->dir_list_size, + ctx->map_dir_list, ctx->map_dir_list_size, + ctx->env_list, ctx->env_list_size, argv, argc); + + wasm_runtime_set_wasi_addr_pool(wasm_module, ctx->addr_pool, + ctx->addr_pool_size); + wasm_runtime_set_wasi_ns_lookup_pool(wasm_module, ctx->ns_lookup_pool, + ctx->ns_lookup_pool_size); +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/cosmopolitan/CMakeLists.txt similarity index 73% rename from lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/cosmopolitan/CMakeLists.txt index 33fad71eb5f..8533ea68cec 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/libraries/wasi-nn/test/CMakeLists.txt +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/cosmopolitan/CMakeLists.txt @@ -1,20 +1,25 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. +# Copyright (C) 2023 Dylibso. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -cmake_minimum_required (VERSION 2.9) +cmake_minimum_required (VERSION 3.14) + +include(CheckPIESupported) project (iwasm) set (CMAKE_VERBOSE_MAKEFILE OFF) + +set (WAMR_BUILD_PLATFORM "cosmopolitan") + +set(CMAKE_EXECUTABLE_SUFFIX ".com") + # Reset default linker flags -set (CMAKE_C_STANDARD 99) -set (CMAKE_CXX_STANDARD 14) set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") -if (NOT DEFINED WAMR_BUILD_PLATFORM) - set (WAMR_BUILD_PLATFORM "linux") -endif () +set (CMAKE_C_STANDARD 99) +set (CMAKE_CXX_STANDARD 17) # Set WAMR_BUILD_TARGET, currently values supported: # "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", @@ -84,6 +89,12 @@ if (NOT DEFINED WAMR_BUILD_LIB_PTHREAD) set (WAMR_BUILD_LIB_PTHREAD 0) endif () +if (NOT DEFINED WAMR_BUILD_LIB_WASI_THREADS) + # Disable wasi threads library by default + set (WAMR_BUILD_LIB_WASI_THREADS 0) +endif() + + if (NOT DEFINED WAMR_BUILD_MINI_LOADER) # Disable wasm mini loader by default set (WAMR_BUILD_MINI_LOADER 0) @@ -110,12 +121,19 @@ if (WAMR_BUILD_DEBUG_INTERP EQUAL 1) set (WAMR_BUILD_SIMD 0) endif () -set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..) +set (WAMR_DISABLE_STACK_HW_BOUND_CHECK 1) +set (WAMR_BUILD_AOT 0) +set (WAMR_DISABLE_WRITE_GS_BASE 1) + +set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) + +check_pie_supported() add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE}) +set_target_properties (vmlib PROPERTIES POSITION_INDEPENDENT_CODE ON) -set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -pie -fPIE") +set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow") # set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion") @@ -127,24 +145,6 @@ if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mindirect-branch-register") # UNDEFINED BEHAVIOR, refer to https://en.cppreference.com/w/cpp/language/ub - if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT WAMR_BUILD_JIT EQUAL 1) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined \ - -fno-sanitize=bounds,bounds-strict,alignment \ - -fno-sanitize-recover") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined \ - -fno-sanitize=bounds,bounds-strict,alignment \ - -fno-sanitize-recover") - endif() - else () - # UNDEFINED BEHAVIOR, refer to https://en.cppreference.com/w/cpp/language/ub - if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT WAMR_BUILD_JIT EQUAL 1) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined \ - -fno-sanitize=bounds,alignment \ - -fno-sanitize-recover") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined \ - -fno-sanitize=bounds,alignment \ - -fno-sanitize-recover") - endif() endif () endif () @@ -158,16 +158,18 @@ endif () include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) -add_executable (iwasm ${WAMR_ROOT_DIR}/product-mini/platforms/${WAMR_BUILD_PLATFORM}/main.c ${UNCOMMON_SHARED_SOURCE}) +add_executable (iwasm main.c ${UNCOMMON_SHARED_SOURCE}) + +set_target_properties (iwasm PROPERTIES POSITION_INDEPENDENT_CODE ON) install (TARGETS iwasm DESTINATION bin) -target_link_libraries (iwasm vmlib ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} ${TENSORFLOW_LIB} -lm -ldl -lpthread) +target_link_libraries (iwasm vmlib ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} ${WASI_NN_LIBS} -lm -ldl -lpthread) -add_library (libiwasm SHARED ${WAMR_RUNTIME_LIB_SOURCE}) +add_library (libiwasm STATIC ${WAMR_RUNTIME_LIB_SOURCE}) install (TARGETS libiwasm DESTINATION lib) set_target_properties (libiwasm PROPERTIES OUTPUT_NAME iwasm) -target_link_libraries (libiwasm ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread) +target_link_libraries (libiwasm ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} ${WASI_NN_LIBS} -lm -ldl -lpthread) diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/cosmopolitan/build_cosmocc.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/cosmopolitan/build_cosmocc.sh new file mode 100755 index 00000000000..b2ce15d33a9 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/cosmopolitan/build_cosmocc.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +# Copyright (C) 2023 Dylibso. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +export CC=cosmocc +export CXX=cosmoc++ +rm -rf build +mkdir build +cmake -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=1 -B build +cmake --build build -j diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/darwin/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/cosmopolitan/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/darwin/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/cosmopolitan/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/darwin/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/darwin/CMakeLists.txt similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/darwin/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/darwin/CMakeLists.txt index 4d68066b0c1..865e516fcae 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/darwin/CMakeLists.txt +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/darwin/CMakeLists.txt @@ -34,7 +34,7 @@ if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif () -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) if (NOT DEFINED WAMR_BUILD_INTERP) # Enable Interpreter by default diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/darwin/build_jit.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/darwin/build_jit.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/darwin/build_jit.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/darwin/build_jit.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/darwin/build_llvm.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/darwin/build_llvm.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/darwin/build_llvm.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/darwin/build_llvm.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/freebsd/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/darwin/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/freebsd/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/darwin/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/.gitignore similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/.gitignore rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/.gitignore diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/build_and_run.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/build_and_run.sh similarity index 80% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/build_and_run.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/build_and_run.sh index dd8dd5ca9b5..f764a301304 100755 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/build_and_run.sh +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/build_and_run.sh @@ -5,14 +5,16 @@ ESP32_TARGET="esp32" ESP32C3_TARGET="esp32c3" +ESP32S3_TARGET="esp32s3" usage () { echo "USAGE:" - echo "$0 $ESP32_TARGET|$ESP32C3_TARGET" + echo "$0 $ESP32_TARGET|$ESP32C3_TARGET|$ESP32S3_TARGET" echo "Example:" echo " $0 $ESP32_TARGET" echo " $0 $ESP32C3_TARGET" + echo " $0 $ESP32S3_TARGET" exit 1 } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/main/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/main/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/main/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/main/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/main/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/main/main.c similarity index 96% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/main/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/main/main.c index 417fad561bf..fbfb04c2164 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/main/main.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/main/main.c @@ -12,6 +12,12 @@ #include "esp_log.h" +#ifdef CONFIG_IDF_TARGET_ESP32S3 +#define IWASM_MAIN_STACK_SIZE 5120 +#else +#define IWASM_MAIN_STACK_SIZE 4096 +#endif + #define LOG_TAG "wamr" static void * @@ -146,7 +152,7 @@ app_main(void) pthread_attr_t tattr; pthread_attr_init(&tattr); pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE); - pthread_attr_setstacksize(&tattr, 4096); + pthread_attr_setstacksize(&tattr, IWASM_MAIN_STACK_SIZE); res = pthread_create(&t, &tattr, iwasm_main, (void *)NULL); assert(res == 0); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/main/test_wasm.h b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/main/test_wasm.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/main/test_wasm.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/main/test_wasm.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/sdkconfig.defaults b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/sdkconfig.defaults similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/sdkconfig.defaults rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/sdkconfig.defaults diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/sdkconfig.defaults.esp32 b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/sdkconfig.defaults.esp32 similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/sdkconfig.defaults.esp32 rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/sdkconfig.defaults.esp32 diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/sdkconfig.defaults.esp32c3 b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/sdkconfig.defaults.esp32c3 similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/esp-idf/sdkconfig.defaults.esp32c3 rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/esp-idf/sdkconfig.defaults.esp32c3 diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/freebsd/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/freebsd/CMakeLists.txt similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/freebsd/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/freebsd/CMakeLists.txt index fee2934c017..dd1bbc41a58 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/freebsd/CMakeLists.txt +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/freebsd/CMakeLists.txt @@ -34,7 +34,7 @@ if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif () -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) if (NOT DEFINED WAMR_BUILD_INTERP) # Enable Interpreter by default diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/freebsd/build_jit.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/freebsd/build_jit.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/freebsd/build_jit.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/freebsd/build_jit.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/freebsd/build_llvm.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/freebsd/build_llvm.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/freebsd/build_llvm.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/freebsd/build_llvm.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/freebsd/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/freebsd/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/ios/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/ios/CMakeLists.txt similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/ios/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/ios/CMakeLists.txt index 764bc7f65a6..4bbff4cff9b 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/ios/CMakeLists.txt +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/ios/CMakeLists.txt @@ -41,7 +41,7 @@ if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif () -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) if (NOT DEFINED WAMR_BUILD_INTERP) # Enable Interpreter by default diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/ios/generate_xcodeproj.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/ios/generate_xcodeproj.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/ios/generate_xcodeproj.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/ios/generate_xcodeproj.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux-sgx/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux-sgx/CMakeLists.txt similarity index 89% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux-sgx/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux-sgx/CMakeLists.txt index e1cbe2cc794..a9aef355c49 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux-sgx/CMakeLists.txt +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux-sgx/CMakeLists.txt @@ -89,6 +89,11 @@ if (NOT DEFINED WAMR_BUILD_SGX_IPFS) set (WAMR_BUILD_SGX_IPFS 0) endif () +if (NOT DEFINED WAMR_BUILD_STATIC_PGO) + # Disable static PGO by default + set (WAMR_BUILD_STATIC_PGO 0) +endif () + set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11 -ffunction-sections -fdata-sections \ -Wall -Wno-unused-parameter -Wno-pedantic \ @@ -107,6 +112,18 @@ add_custom_command ( add_custom_target (vmlib_untrusted ALL DEPENDS libvmlib_untrusted.a) +if ((WAMR_BUILD_STATIC_PGO EQUAL 1) AND (WAMR_BUILD_AOT EQUAL 1)) + execute_process( + COMMAND bash -c "sed -i -E 's/^WAMR_BUILD_STATIC_PGO = 0/WAMR_BUILD_STATIC_PGO = 1/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile" + OUTPUT_VARIABLE cmdOutput + ) +else() + execute_process( + COMMAND bash -c "sed -i -E 's/^WAMR_BUILD_STATIC_PGO = 1/WAMR_BUILD_STATIC_PGO = 0/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile" + OUTPUT_VARIABLE cmdOutput + ) +endif() + if (DEFINED WAMR_BUILD_GLOBAL_HEAP_POOL) execute_process( COMMAND bash -c "sed -i -E 's/^WAMR_BUILD_GLOBAL_HEAP_POOL = .*/WAMR_BUILD_GLOBAL_HEAP_POOL = ${WAMR_BUILD_GLOBAL_HEAP_POOL}/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile" diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux-sgx/CMakeLists_minimal.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux-sgx/CMakeLists_minimal.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux-sgx/CMakeLists_minimal.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux-sgx/CMakeLists_minimal.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux-sgx/enclave-sample/Makefile b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux-sgx/enclave-sample/Makefile similarity index 94% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux-sgx/enclave-sample/Makefile rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux-sgx/enclave-sample/Makefile index b598aad5494..dae97a06998 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux-sgx/enclave-sample/Makefile +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux-sgx/enclave-sample/Makefile @@ -15,6 +15,7 @@ WAMR_BUILD_SGX_IPFS = 0 WAMR_BUILD_LIB_RATS = 0 WAMR_BUILD_GLOBAL_HEAP_POOL = 0 WAMR_BUILD_GLOBAL_HEAP_SIZE = 10485760 +WAMR_BUILD_STATIC_PGO = 0 VMLIB_BUILD_DIR ?= $(CURDIR)/../build LIB_RATS_SRC ?= $(VMLIB_BUILD_DIR)/_deps/librats-build @@ -65,7 +66,7 @@ ifeq ($(WAMR_BUILD_LIB_RATS), 1) App_Include_Paths += -I$(LIB_RATS_INCLUDE_DIR) endif -App_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths) +App_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths) -DWASM_ENABLE_STATIC_PGO=$(WAMR_BUILD_STATIC_PGO) # Three configuration modes - Debug, prerelease, release # Debug - Macro DEBUG enabled. @@ -134,7 +135,7 @@ ifeq ($(WAMR_BUILD_LIB_RATS), 1) Enclave_Include_Paths += -I$(LIB_RATS_INCLUDE_DIR) -I$(SGX_SSL)/include endif -Enclave_C_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -fstack-protector $(Enclave_Include_Paths) -DWASM_GLOBAL_HEAP_SIZE=$(WAMR_BUILD_GLOBAL_HEAP_SIZE) -DWASM_ENABLE_GLOBAL_HEAP_POOL=$(WAMR_BUILD_GLOBAL_HEAP_POOL) -DWASM_ENABLE_LIB_RATS=$(WAMR_BUILD_LIB_RATS) +Enclave_C_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -fstack-protector $(Enclave_Include_Paths) -DWASM_GLOBAL_HEAP_SIZE=$(WAMR_BUILD_GLOBAL_HEAP_SIZE) -DWASM_ENABLE_GLOBAL_HEAP_POOL=$(WAMR_BUILD_GLOBAL_HEAP_POOL) -DWASM_ENABLE_LIB_RATS=$(WAMR_BUILD_LIB_RATS) -DWASM_ENABLE_STATIC_PGO=$(WAMR_BUILD_STATIC_PGO) ifeq ($(SPEC_TEST), 1) Enclave_C_Flags += -DWASM_ENABLE_SPEC_TEST=1 else @@ -142,10 +143,10 @@ else endif ifeq ($(WAMR_BUILD_LIB_RATS), 1) - Rats_Lib_Link_Dirs := -L$(LIB_RATS_INSTALL_DIR) -L$(LIB_RATS_INSTALL_DIR)/attesters -L$(LIB_RATS_INSTALL_DIR)/verifiers -L$(SGX_SSL)/lib64 + Rats_Lib_Link_Dirs := -L$(LIB_RATS_INSTALL_DIR) -L$(LIB_RATS_INSTALL_DIR)/attesters -L$(LIB_RATS_INSTALL_DIR)/verifiers -L$(SGX_SSL)/lib64 -L$(VMLIB_BUILD_DIR)/external/libcbor/src/libcbor/lib -L$(LIB_RATS_INSTALL_DIR)/crypto_wrappers Rats_Lib_W_Link_libs := -lattester_nullattester -lattester_sgx_ecdsa -lattester_sgx_la \ - -lverifier_nullverifier -lverifier_sgx_ecdsa -lverifier_sgx_la -lverifier_sgx_ecdsa_qve \ - -lrats_lib -lsgx_tsgxssl + -lverifier_nullverifier -lverifier_sgx_la -lverifier_sgx_ecdsa_qve -lcbor \ + -lrats_lib -lsgx_tsgxssl -lcrypto_wrapper_nullcrypto -lcrypto_wrapper_openssl Rats_Lib_NW_Link_libs := -lsgx_dcap_tvl -lsgx_tsgxssl_crypto endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux-sgx/enclave-sample/Makefile_minimal b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux-sgx/enclave-sample/Makefile_minimal similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux-sgx/enclave-sample/Makefile_minimal rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux-sgx/enclave-sample/Makefile_minimal diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux/CMakeLists.txt similarity index 80% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux/CMakeLists.txt index 4c6af78ea94..ecd08655c30 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux/CMakeLists.txt +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux/CMakeLists.txt @@ -16,7 +16,7 @@ set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") set (CMAKE_C_STANDARD 99) -set (CMAKE_CXX_STANDARD 14) +set (CMAKE_CXX_STANDARD 17) # Set WAMR_BUILD_TARGET, currently values supported: # "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", @@ -121,7 +121,10 @@ endif () set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) + +check_pie_supported() add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE}) +set_target_properties (vmlib PROPERTIES POSITION_INDEPENDENT_CODE ON) set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") @@ -135,24 +138,6 @@ if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mindirect-branch-register") # UNDEFINED BEHAVIOR, refer to https://en.cppreference.com/w/cpp/language/ub - if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT WAMR_BUILD_JIT EQUAL 1) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined \ - -fno-sanitize=bounds,bounds-strict,alignment \ - -fno-sanitize-recover") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined \ - -fno-sanitize=bounds,bounds-strict,alignment \ - -fno-sanitize-recover") - endif() - else () - # UNDEFINED BEHAVIOR, refer to https://en.cppreference.com/w/cpp/language/ub - if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT WAMR_BUILD_JIT EQUAL 1) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined \ - -fno-sanitize=bounds,alignment \ - -fno-sanitize-recover") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined \ - -fno-sanitize=bounds,alignment \ - -fno-sanitize-recover") - endif() endif () endif () @@ -168,12 +153,11 @@ include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) add_executable (iwasm main.c ${UNCOMMON_SHARED_SOURCE}) -check_pie_supported() set_target_properties (iwasm PROPERTIES POSITION_INDEPENDENT_CODE ON) install (TARGETS iwasm DESTINATION bin) -target_link_libraries (iwasm vmlib ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread) +target_link_libraries (iwasm vmlib ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} ${WASI_NN_LIBS} -lm -ldl -lpthread) add_library (libiwasm SHARED ${WAMR_RUNTIME_LIB_SOURCE}) @@ -181,4 +165,4 @@ install (TARGETS libiwasm DESTINATION lib) set_target_properties (libiwasm PROPERTIES OUTPUT_NAME iwasm) -target_link_libraries (libiwasm ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread) +target_link_libraries (libiwasm ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} ${WASI_NN_LIBS} -lm -ldl -lpthread) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux/build_jit.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux/build_jit.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux/build_jit.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux/build_jit.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux/build_llvm.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux/build_llvm.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/linux/build_llvm.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux/build_llvm.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/nuttx/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/nuttx/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/linux/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/vxworks/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/nuttx/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/vxworks/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/nuttx/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/nuttx/wamr.mk b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/nuttx/wamr.mk similarity index 87% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/nuttx/wamr.mk rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/nuttx/wamr.mk index 78cf3eea1d7..b91fac9a86c 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/nuttx/wamr.mk +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/nuttx/wamr.mk @@ -13,6 +13,8 @@ else ifeq ($(CONFIG_ARCH_ARMV7M),y) WAMR_BUILD_TARGET := THUMBV7EM else ifeq ($(CONFIG_ARCH_ARMV8M),y) WAMR_BUILD_TARGET := THUMBV8M +else ifeq ($(CONFIG_ARCH_ARM64),y) +WAMR_BUILD_TARGET := AARCH64 else ifeq ($(CONFIG_ARCH_X86),y) WAMR_BUILD_TARGET := X86_32 else ifeq ($(CONFIG_ARCH_X86_64),y) @@ -141,6 +143,12 @@ else CFLAGS += -DWASM_ENABLE_WORD_ALIGN_READ=0 endif +ifeq ($(CONFIG_INTERPRETERS_WAMR_MEM_DUAL_BUS_MIRROR),y) +CFLAGS += -DWASM_MEM_DUAL_BUS_MIRROR=1 +else +CFLAGS += -DWASM_MEM_DUAL_BUS_MIRROR=0 +endif + ifeq ($(CONFIG_INTERPRETERS_WAMR_FAST), y) CFLAGS += -DWASM_ENABLE_FAST_INTERP=1 CFLAGS += -DWASM_ENABLE_INTERP=1 @@ -230,21 +238,40 @@ else CFLAGS += -DWASM_ENABLE_LIBC_BUILTIN=0 endif +ifeq ($(CONFIG_INTERPRETERS_WAMR_CONFIGURABLE_BOUNDS_CHECKS),y) +CFLAGS += -DWASM_CONFIGURABLE_BOUNDS_CHECKS=1 +else +CFLAGS += -DWASM_CONFIGURABLE_BOUNDS_CHECKS=0 +endif + ifeq ($(CONFIG_INTERPRETERS_WAMR_LIBC_WASI),y) CFLAGS += -DWASM_ENABLE_LIBC_WASI=1 CFLAGS += -I$(IWASM_ROOT)/libraries/libc-wasi/sandboxed-system-primitives/src CFLAGS += -I$(IWASM_ROOT)/libraries/libc-wasi/sandboxed-system-primitives/include +CFLAGS += -I${SHARED_ROOT}/platform/common/libc-util +CSRCS += blocking_op.c CSRCS += posix_socket.c +CSRCS += posix_file.c +CSRCS += posix_clock.c +CSRCS += libc_errno.c CSRCS += libc_wasi_wrapper.c VPATH += $(IWASM_ROOT)/libraries/libc-wasi CSRCS += posix.c CSRCS += random.c CSRCS += str.c VPATH += $(IWASM_ROOT)/libraries/libc-wasi/sandboxed-system-primitives/src +# todo: use Kconfig select instead +CONFIG_INTERPRETERS_WAMR_MODULE_INSTANCE_CONTEXT = y else CFLAGS += -DWASM_ENABLE_LIBC_WASI=0 endif +ifeq ($(CONFIG_INTERPRETERS_WAMR_MODULE_INSTANCE_CONTEXT),y) +CFLAGS += -DWASM_ENABLE_MODULE_INST_CONTEXT=1 +else +CFLAGS += -DWASM_ENABLE_MODULE_INST_CONTEXT=0 +endif + ifeq ($(CONFIG_INTERPRETERS_WAMR_MULTI_MODULE),y) CFLAGS += -DWASM_ENABLE_MULTI_MODULE=1 else @@ -259,6 +286,15 @@ else CFLAGS += -DWASM_ENABLE_THREAD_MGR=0 endif +ifeq ($(CONFIG_INTERPRETERS_WAMR_LIB_WASI_THREADS),y) +CFLAGS += -DWASM_ENABLE_LIB_WASI_THREADS=1 +CSRCS += lib_wasi_threads_wrapper.c +CSRCS += tid_allocator.c +VPATH += $(IWASM_ROOT)/libraries/lib-wasi-threads +else +CFLAGS += -DWASM_ENABLE_LIB_WASI_THREADS=0 +endif + ifeq ($(CONFIG_INTERPRETERS_WAMR_LIB_PTHREAD),y) CFLAGS += -DWASM_ENABLE_LIB_PTHREAD=1 CSRCS += lib_pthread_wrapper.c @@ -280,6 +316,15 @@ CFLAGS += -DWASM_DISABLE_HW_BOUND_CHECK=0 CFLAGS += -DWASM_DISABLE_STACK_HW_BOUND_CHECK=0 endif +# REVISIT: is this worth to have a Kconfig? +CFLAGS += -DWASM_DISABLE_WAKEUP_BLOCKING_OP=0 + +ifeq ($(CONFIG_INTERPRETERS_WAMR_LOAD_CUSTOM_SECTIONS),y) +CFLAGS += -DWASM_ENABLE_LOAD_CUSTOM_SECTION=1 +else +CFLAGS += -DWASM_ENABLE_LOAD_CUSTOM_SECTION=0 +endif + ifeq ($(CONFIG_INTERPRETERS_WAMR_CUSTOM_NAME_SECTIONS),y) CFLAGS += -DWASM_ENABLE_CUSTOM_NAME_SECTION=1 else @@ -325,13 +370,16 @@ CFLAGS += -I$(IWASM_ROOT)/interpreter endif CSRCS += nuttx_platform.c \ + posix_blocking_op.c \ posix_thread.c \ posix_time.c \ + posix_sleep.c \ mem_alloc.c \ ems_kfc.c \ ems_alloc.c \ ems_hmu.c \ bh_assert.c \ + bh_bitmap.c \ bh_common.c \ bh_hashmap.c \ bh_list.c \ @@ -341,6 +389,7 @@ CSRCS += nuttx_platform.c \ bh_read_file.c \ runtime_timer.c \ wasm_application.c \ + wasm_blocking_op.c \ wasm_runtime_common.c \ wasm_native.c \ wasm_exec_env.c \ @@ -351,6 +400,7 @@ ASRCS += $(INVOKE_NATIVE) VPATH += $(SHARED_ROOT)/platform/nuttx VPATH += $(SHARED_ROOT)/platform/common/posix +VPATH += $(SHARED_ROOT)/platform/common/libc-util VPATH += $(SHARED_ROOT)/mem-alloc VPATH += $(SHARED_ROOT)/mem-alloc/ems VPATH += $(SHARED_ROOT)/utils diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/posix/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/posix/main.c similarity index 57% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/posix/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/posix/main.c index 2e96ccddd6c..85185549791 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/posix/main.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/posix/main.c @@ -14,6 +14,10 @@ #include "bh_read_file.h" #include "wasm_export.h" +#if WASM_ENABLE_LIBC_WASI != 0 +#include "../common/libc_wasi.c" +#endif + #if BH_HAS_DLFCN #include #endif @@ -54,25 +58,23 @@ print_help() #if WASM_ENABLE_JIT != 0 printf(" --llvm-jit-size-level=n Set LLVM JIT size level, default is 3\n"); printf(" --llvm-jit-opt-level=n Set LLVM JIT optimization level, default is 3\n"); + printf(" --perf-profile Enable linux perf support. For now, it only works in llvm-jit.\n"); +#if defined(os_writegsbase) + printf(" --enable-segue[=] Enable using segment register GS as the base address of\n"); + printf(" linear memory, which may improve performance, flags can be:\n"); + printf(" i32.load, i64.load, f32.load, f64.load, v128.load,\n"); + printf(" i32.store, i64.store, f32.store, f64.store, v128.store\n"); + printf(" Use comma to separate, e.g. --enable-segue=i32.load,i64.store\n"); + printf(" and --enable-segue means all flags are added.\n"); +#endif #endif printf(" --repl Start a very simple REPL (read-eval-print-loop) mode\n" " that runs commands in the form of \"FUNC ARG...\"\n"); +#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0 + printf(" --disable-bounds-checks Disable bounds checks for memory accesses\n"); +#endif #if WASM_ENABLE_LIBC_WASI != 0 - printf(" --env= Pass wasi environment variables with \"key=value\"\n"); - printf(" to the program, for example:\n"); - printf(" --env=\"key1=value1\" --env=\"key2=value2\"\n"); - printf(" --dir= Grant wasi access to the given host directories\n"); - printf(" to the program, for example:\n"); - printf(" --dir= --dir=\n"); - printf(" --addr-pool= Grant wasi access to the given network addresses in\n"); - printf(" CIRD notation to the program, seperated with ',',\n"); - printf(" for example:\n"); - printf(" --addr-pool=1.2.3.4/15,2.3.4.5/16\n"); - printf(" --allow-resolve= Allow the lookup of the specific domain name or domain\n"); - printf(" name suffixes using a wildcard, for example:\n"); - printf(" --allow-resolve=example.com # allow the lookup of the specific domain\n"); - printf(" --allow-resolve=*.example.com # allow the lookup of all subdomains\n"); - printf(" --allow-resolve=* # allow any lookup\n"); + libc_wasi_print_help(); #endif #if BH_HAS_DLFCN printf(" --native-lib= Register native libraries to the WASM module, which\n"); @@ -86,9 +88,17 @@ print_help() #if WASM_ENABLE_LIB_PTHREAD != 0 || WASM_ENABLE_LIB_WASI_THREADS != 0 printf(" --max-threads=n Set maximum thread number per cluster, default is 4\n"); #endif +#if WASM_ENABLE_THREAD_MGR != 0 + printf(" --timeout=ms Set the maximum execution time in ms.\n"); + printf(" If it expires, the runtime aborts the execution\n"); + printf(" with a trap.\n"); +#endif #if WASM_ENABLE_DEBUG_INTERP != 0 printf(" -g=ip:port Set the debug sever address, default is debug disabled\n"); printf(" if port is 0, then a random port will be used\n"); +#endif +#if WASM_ENABLE_STATIC_PGO != 0 + printf(" --gen-prof-file= Generate LLVM PGO (Profile-Guided Optimization) profile file\n"); #endif printf(" --version Show version information\n"); return 1; @@ -101,8 +111,7 @@ app_instance_main(wasm_module_inst_t module_inst) const char *exception; wasm_application_execute_main(module_inst, app_argc, app_argv); - if ((exception = wasm_runtime_get_exception(module_inst))) - printf("%s\n", exception); + exception = wasm_runtime_get_exception(module_inst); return exception; } @@ -117,13 +126,13 @@ app_instance_func(wasm_module_inst_t module_inst, const char *func_name) } /** - * Split a space separated strings into an array of strings + * Split a string into an array of strings * Returns NULL on failure * Memory must be freed by caller * Based on: http://stackoverflow.com/a/11198630/471795 */ static char ** -split_string(char *str, int *count) +split_string(char *str, int *count, const char *delimer) { char **res = NULL, **res1; char *p; @@ -131,7 +140,7 @@ split_string(char *str, int *count) /* split string and append tokens to 'res' */ do { - p = strtok(str, " "); + p = strtok(str, delimer); str = NULL; res1 = res; res = (char **)realloc(res1, sizeof(char *) * (uint32)(idx + 1)); @@ -180,14 +189,17 @@ app_instance_repl(wasm_module_inst_t module_inst) printf("exit repl mode\n"); break; } - app_argv = split_string(cmd, &app_argc); + app_argv = split_string(cmd, &app_argc, " "); if (app_argv == NULL) { LOG_ERROR("Wasm prepare param failed: split string failed.\n"); break; } if (app_argc != 0) { + const char *exception; wasm_application_execute_func(module_inst, app_argv[0], app_argc - 1, app_argv + 1); + if ((exception = wasm_runtime_get_exception(module_inst))) + printf("%s\n", exception); } free(app_argv); } @@ -195,113 +207,178 @@ app_instance_repl(wasm_module_inst_t module_inst) return NULL; } -#if WASM_ENABLE_LIBC_WASI != 0 -static bool -validate_env_str(char *env) +#if WASM_ENABLE_JIT != 0 +static uint32 +resolve_segue_flags(char *str_flags) { - char *p = env; - int key_len = 0; - - while (*p != '\0' && *p != '=') { - key_len++; - p++; + uint32 segue_flags = 0; + int32 flag_count, i; + char **flag_list; + + flag_list = split_string(str_flags, &flag_count, ","); + if (flag_list) { + for (i = 0; i < flag_count; i++) { + if (!strcmp(flag_list[i], "i32.load")) { + segue_flags |= 1 << 0; + } + else if (!strcmp(flag_list[i], "i64.load")) { + segue_flags |= 1 << 1; + } + else if (!strcmp(flag_list[i], "f32.load")) { + segue_flags |= 1 << 2; + } + else if (!strcmp(flag_list[i], "f64.load")) { + segue_flags |= 1 << 3; + } + else if (!strcmp(flag_list[i], "v128.load")) { + segue_flags |= 1 << 4; + } + else if (!strcmp(flag_list[i], "i32.store")) { + segue_flags |= 1 << 8; + } + else if (!strcmp(flag_list[i], "i64.store")) { + segue_flags |= 1 << 9; + } + else if (!strcmp(flag_list[i], "f32.store")) { + segue_flags |= 1 << 10; + } + else if (!strcmp(flag_list[i], "f64.store")) { + segue_flags |= 1 << 11; + } + else if (!strcmp(flag_list[i], "v128.store")) { + segue_flags |= 1 << 12; + } + else { + /* invalid flag */ + segue_flags = (uint32)-1; + break; + } + } + free(flag_list); } - - if (*p != '=' || key_len == 0) - return false; - - return true; + return segue_flags; } -#endif +#endif /* end of WASM_ENABLE_JIT != 0 */ #if BH_HAS_DLFCN -typedef uint32 (*get_native_lib_func)(char **p_module_name, - NativeSymbol **p_native_symbols); +struct native_lib { + void *handle; + + uint32 (*get_native_lib)(char **p_module_name, + NativeSymbol **p_native_symbols); + int (*init_native_lib)(void); + void (*deinit_native_lib)(void); -static uint32 -load_and_register_native_libs(const char **native_lib_list, - uint32 native_lib_count, - void **native_handle_list) -{ - uint32 i, native_handle_count = 0, n_native_symbols; - NativeSymbol *native_symbols; char *module_name; - void *handle; + NativeSymbol *native_symbols; + uint32 n_native_symbols; +}; - for (i = 0; i < native_lib_count; i++) { - /* open the native library */ - if (!(handle = dlopen(native_lib_list[i], RTLD_NOW | RTLD_GLOBAL)) - && !(handle = dlopen(native_lib_list[i], RTLD_LAZY))) { - LOG_WARNING("warning: failed to load native library %s", - native_lib_list[i]); - continue; +struct native_lib * +load_native_lib(const char *name) +{ + struct native_lib *lib = wasm_runtime_malloc(sizeof(*lib)); + if (lib == NULL) { + LOG_WARNING("warning: failed to load native library %s because of " + "allocation failure", + name); + goto fail; + } + memset(lib, 0, sizeof(*lib)); + + /* open the native library */ + if (!(lib->handle = dlopen(name, RTLD_NOW | RTLD_GLOBAL)) + && !(lib->handle = dlopen(name, RTLD_LAZY))) { + LOG_WARNING("warning: failed to load native library %s", name); + goto fail; + } + + lib->init_native_lib = dlsym(lib->handle, "init_native_lib"); + lib->get_native_lib = dlsym(lib->handle, "get_native_lib"); + lib->deinit_native_lib = dlsym(lib->handle, "deinit_native_lib"); + + if (!lib->get_native_lib) { + LOG_WARNING("warning: failed to lookup `get_native_lib` function " + "from native lib %s", + name); + goto fail; + } + + if (lib->init_native_lib) { + int ret = lib->init_native_lib(); + if (ret != 0) { + LOG_WARNING("warning: `init_native_lib` function from native " + "lib %s failed with %d", + name, ret); + goto fail; } + } - /* lookup get_native_lib func */ - get_native_lib_func get_native_lib = dlsym(handle, "get_native_lib"); - if (!get_native_lib) { - LOG_WARNING("warning: failed to lookup `get_native_lib` function " - "from native lib %s", - native_lib_list[i]); - dlclose(handle); - continue; + lib->n_native_symbols = + lib->get_native_lib(&lib->module_name, &lib->native_symbols); + + /* register native symbols */ + if (!(lib->n_native_symbols > 0 && lib->module_name && lib->native_symbols + && wasm_runtime_register_natives( + lib->module_name, lib->native_symbols, lib->n_native_symbols))) { + LOG_WARNING("warning: failed to register native lib %s", name); + if (lib->deinit_native_lib) { + lib->deinit_native_lib(); + } + goto fail; + } + return lib; +fail: + if (lib != NULL) { + if (lib->handle != NULL) { + dlclose(lib->handle); } + wasm_runtime_free(lib); + } + return NULL; +} - n_native_symbols = get_native_lib(&module_name, &native_symbols); +static uint32 +load_and_register_native_libs(const char **native_lib_list, + uint32 native_lib_count, + struct native_lib **native_lib_loaded_list) +{ + uint32 i, native_lib_loaded_count = 0; - /* register native symbols */ - if (!(n_native_symbols > 0 && module_name && native_symbols - && wasm_runtime_register_natives(module_name, native_symbols, - n_native_symbols))) { - LOG_WARNING("warning: failed to register native lib %s", - native_lib_list[i]); - dlclose(handle); + for (i = 0; i < native_lib_count; i++) { + struct native_lib *lib = load_native_lib(native_lib_list[i]); + if (lib == NULL) { continue; } - - native_handle_list[native_handle_count++] = handle; + native_lib_loaded_list[native_lib_loaded_count++] = lib; } - return native_handle_count; + return native_lib_loaded_count; } static void unregister_and_unload_native_libs(uint32 native_lib_count, - void **native_handle_list) + struct native_lib **native_lib_loaded_list) { - uint32 i, n_native_symbols; - NativeSymbol *native_symbols; - char *module_name; - void *handle; + uint32 i; for (i = 0; i < native_lib_count; i++) { - handle = native_handle_list[i]; - - /* lookup get_native_lib func */ - get_native_lib_func get_native_lib = dlsym(handle, "get_native_lib"); - if (!get_native_lib) { - LOG_WARNING("warning: failed to lookup `get_native_lib` function " - "from native lib %p", - handle); - continue; - } + struct native_lib *lib = native_lib_loaded_list[i]; - n_native_symbols = get_native_lib(&module_name, &native_symbols); - if (n_native_symbols == 0 || module_name == NULL - || native_symbols == NULL) { - LOG_WARNING("warning: get_native_lib returned different values for " - "native lib %p", - handle); + /* unregister native symbols */ + if (!wasm_runtime_unregister_natives(lib->module_name, + lib->native_symbols)) { + LOG_WARNING("warning: failed to unregister native lib %p", + lib->handle); continue; } - /* unregister native symbols */ - if (!wasm_runtime_unregister_natives(module_name, native_symbols)) { - LOG_WARNING("warning: failed to unregister native lib %p", handle); - continue; + if (lib->deinit_native_lib) { + lib->deinit_native_lib(); } - dlclose(handle); + dlclose(lib->handle); + wasm_runtime_free(lib); } } #endif /* BH_HAS_DLFCN */ @@ -317,19 +394,28 @@ handle_module_path(const char *module_path) static char *module_search_path = "."; static bool -module_reader_callback(const char *module_name, uint8 **p_buffer, - uint32 *p_size) +module_reader_callback(package_type_t module_type, const char *module_name, + uint8 **p_buffer, uint32 *p_size) { - const char *format = "%s/%s.wasm"; + char *file_format = NULL; +#if WASM_ENABLE_INTERP != 0 + if (module_type == Wasm_Module_Bytecode) + file_format = ".wasm"; +#endif +#if WASM_ENABLE_AOT != 0 + if (module_type == Wasm_Module_AoT) + file_format = ".aot"; +#endif + bh_assert(file_format); + const char *format = "%s/%s%s"; int sz = strlen(module_search_path) + strlen("/") + strlen(module_name) - + strlen(".wasm") + 1; - char *wasm_file_name = BH_MALLOC(sz); + + strlen(file_format) + 1; + char *wasm_file_name = wasm_runtime_malloc(sz); if (!wasm_file_name) { return false; } - - snprintf(wasm_file_name, sz, format, module_search_path, module_name); - + snprintf(wasm_file_name, sz, format, module_search_path, module_name, + file_format); *p_buffer = (uint8_t *)bh_read_file_to_buffer(wasm_file_name, p_size); wasm_runtime_free(wasm_file_name); @@ -350,6 +436,108 @@ moudle_destroyer(uint8 *buffer, uint32 size) #if WASM_ENABLE_GLOBAL_HEAP_POOL != 0 static char global_heap_buf[WASM_GLOBAL_HEAP_SIZE] = { 0 }; +#else +static void * +malloc_func( +#if WASM_MEM_ALLOC_WITH_USER_DATA != 0 + void *user_data, +#endif + unsigned int size) +{ + return malloc(size); +} + +static void * +realloc_func( +#if WASM_MEM_ALLOC_WITH_USER_DATA != 0 + void *user_data, +#endif + void *ptr, unsigned int size) +{ + return realloc(ptr, size); +} + +static void +free_func( +#if WASM_MEM_ALLOC_WITH_USER_DATA != 0 + void *user_data, +#endif + void *ptr) +{ + free(ptr); +} +#endif /* end of WASM_ENABLE_GLOBAL_HEAP_POOL */ + +#if WASM_ENABLE_STATIC_PGO != 0 +static void +dump_pgo_prof_data(wasm_module_inst_t module_inst, const char *path) +{ + char *buf; + uint32 len; + FILE *file; + + if (!(len = wasm_runtime_get_pgo_prof_data_size(module_inst))) { + printf("failed to get LLVM PGO profile data size\n"); + return; + } + + if (!(buf = wasm_runtime_malloc(len))) { + printf("allocate memory failed\n"); + return; + } + + if (len != wasm_runtime_dump_pgo_prof_data_to_buf(module_inst, buf, len)) { + printf("failed to dump LLVM PGO profile data\n"); + wasm_runtime_free(buf); + return; + } + + if (!(file = fopen(path, "wb"))) { + printf("failed to create file %s", path); + wasm_runtime_free(buf); + return; + } + fwrite(buf, len, 1, file); + fclose(file); + + wasm_runtime_free(buf); + + printf("LLVM raw profile file %s was generated.\n", path); +} +#endif + +#if WASM_ENABLE_THREAD_MGR != 0 +struct timeout_arg { + uint32 timeout_ms; + wasm_module_inst_t inst; +#if defined(BH_HAS_STD_ATOMIC) + _Atomic +#endif + bool cancel; +}; + +void * +timeout_thread(void *vp) +{ + const struct timeout_arg *arg = vp; + uint32 left = arg->timeout_ms; + while (!arg->cancel) { + uint32 ms; + if (left >= 100) { + ms = 100; + } + else { + ms = left; + } + os_usleep((uint64)ms * 1000); + left -= ms; + if (left == 0) { + wasm_runtime_terminate(arg->inst); + break; + } + } + return NULL; +} #endif int @@ -360,13 +548,20 @@ main(int argc, char *argv[]) const char *func_name = NULL; uint8 *wasm_file_buf = NULL; uint32 wasm_file_size; - uint32 stack_size = 64 * 1024, heap_size = 16 * 1024; + uint32 stack_size = 64 * 1024; +#if WASM_ENABLE_LIBC_WASI != 0 + uint32 heap_size = 0; +#else + uint32 heap_size = 16 * 1024; +#endif #if WASM_ENABLE_FAST_JIT != 0 uint32 jit_code_cache_size = FAST_JIT_DEFAULT_CODE_CACHE_SIZE; #endif #if WASM_ENABLE_JIT != 0 uint32 llvm_jit_size_level = 3; uint32 llvm_jit_opt_level = 3; + uint32 segue_flags = 0; + bool enable_linux_perf_support = false; #endif wasm_module_t wasm_module = NULL; wasm_module_inst_t wasm_module_inst = NULL; @@ -378,26 +573,32 @@ main(int argc, char *argv[]) #endif bool is_repl_mode = false; bool is_xip_file = false; +#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0 + bool disable_bounds_checks = false; +#endif #if WASM_ENABLE_LIBC_WASI != 0 - const char *dir_list[8] = { NULL }; - uint32 dir_list_size = 0; - const char *env_list[8] = { NULL }; - uint32 env_list_size = 0; - const char *addr_pool[8] = { NULL }; - uint32 addr_pool_size = 0; - const char *ns_lookup_pool[8] = { NULL }; - uint32 ns_lookup_pool_size = 0; + libc_wasi_parse_context_t wasi_parse_ctx; #endif #if BH_HAS_DLFCN const char *native_lib_list[8] = { NULL }; uint32 native_lib_count = 0; - void *native_handle_list[8] = { NULL }; - uint32 native_handle_count = 0; + struct native_lib *native_lib_loaded_list[8]; + uint32 native_lib_loaded_count = 0; #endif #if WASM_ENABLE_DEBUG_INTERP != 0 char *ip_addr = NULL; int instance_port = 0; #endif +#if WASM_ENABLE_STATIC_PGO != 0 + const char *gen_prof_file = NULL; +#endif +#if WASM_ENABLE_THREAD_MGR != 0 + int timeout_ms = -1; +#endif + +#if WASM_ENABLE_LIBC_WASI != 0 + memset(&wasi_parse_ctx, 0, sizeof(wasi_parse_ctx)); +#endif /* Process options. */ for (argc--, argv++; argc > 0 && argv[0][0] == '-'; argc--, argv++) { @@ -439,6 +640,11 @@ main(int argc, char *argv[]) else if (!strcmp(argv[0], "--repl")) { is_repl_mode = true; } +#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0 + else if (!strcmp(argv[0], "--disable-bounds-checks")) { + disable_bounds_checks = true; + } +#endif else if (!strncmp(argv[0], "--stack-size=", 13)) { if (argv[0][13] == '\0') return print_help(); @@ -487,71 +693,19 @@ main(int argc, char *argv[]) llvm_jit_opt_level = 3; } } -#endif -#if WASM_ENABLE_LIBC_WASI != 0 - else if (!strncmp(argv[0], "--dir=", 6)) { - if (argv[0][6] == '\0') - return print_help(); - if (dir_list_size >= sizeof(dir_list) / sizeof(char *)) { - printf("Only allow max dir number %d\n", - (int)(sizeof(dir_list) / sizeof(char *))); - return 1; - } - dir_list[dir_list_size++] = argv[0] + 6; - } - else if (!strncmp(argv[0], "--env=", 6)) { - char *tmp_env; - - if (argv[0][6] == '\0') - return print_help(); - if (env_list_size >= sizeof(env_list) / sizeof(char *)) { - printf("Only allow max env number %d\n", - (int)(sizeof(env_list) / sizeof(char *))); - return 1; - } - tmp_env = argv[0] + 6; - if (validate_env_str(tmp_env)) - env_list[env_list_size++] = tmp_env; - else { - printf("Wasm parse env string failed: expect \"key=value\", " - "got \"%s\"\n", - tmp_env); - return print_help(); - } + else if (!strcmp(argv[0], "--enable-segue")) { + /* all flags are enabled */ + segue_flags = 0x1F1F; } - /* TODO: parse the configuration file via --addr-pool-file */ - else if (!strncmp(argv[0], "--addr-pool=", strlen("--addr-pool="))) { - /* like: --addr-pool=100.200.244.255/30 */ - char *token = NULL; - - if ('\0' == argv[0][12]) + else if (!strncmp(argv[0], "--enable-segue=", 15)) { + segue_flags = resolve_segue_flags(argv[0] + 15); + if (segue_flags == (uint32)-1) return print_help(); - - token = strtok(argv[0] + strlen("--addr-pool="), ","); - while (token) { - if (addr_pool_size >= sizeof(addr_pool) / sizeof(char *)) { - printf("Only allow max address number %d\n", - (int)(sizeof(addr_pool) / sizeof(char *))); - return 1; - } - - addr_pool[addr_pool_size++] = token; - token = strtok(NULL, ";"); - } } - else if (!strncmp(argv[0], "--allow-resolve=", 16)) { - if (argv[0][16] == '\0') - return print_help(); - if (ns_lookup_pool_size - >= sizeof(ns_lookup_pool) / sizeof(ns_lookup_pool[0])) { - printf( - "Only allow max ns lookup number %d\n", - (int)(sizeof(ns_lookup_pool) / sizeof(ns_lookup_pool[0]))); - return 1; - } - ns_lookup_pool[ns_lookup_pool_size++] = argv[0] + 16; + else if (!strncmp(argv[0], "--perf-profile", 14)) { + enable_linux_perf_support = true; } -#endif /* WASM_ENABLE_LIBC_WASI */ +#endif /* end of WASM_ENABLE_JIT != 0 */ #if BH_HAS_DLFCN else if (!strncmp(argv[0], "--native-lib=", 13)) { if (argv[0][13] == '\0') @@ -580,6 +734,13 @@ main(int argc, char *argv[]) wasm_runtime_set_max_thread_num(atoi(argv[0] + 14)); } #endif +#if WASM_ENABLE_THREAD_MGR != 0 + else if (!strncmp(argv[0], "--timeout=", 10)) { + if (argv[0][10] == '\0') + return print_help(); + timeout_ms = atoi(argv[0] + 10); + } +#endif #if WASM_ENABLE_DEBUG_INTERP != 0 else if (!strncmp(argv[0], "-g=", 3)) { char *port_str = strchr(argv[0] + 3, ':'); @@ -592,6 +753,13 @@ main(int argc, char *argv[]) return print_help(); ip_addr = argv[0] + 3; } +#endif +#if WASM_ENABLE_STATIC_PGO != 0 + else if (!strncmp(argv[0], "--gen-prof-file=", 16)) { + if (argv[0][16] == '\0') + return print_help(); + gen_prof_file = argv[0] + 16; + } #endif else if (!strncmp(argv[0], "--version", 9)) { uint32 major, minor, patch; @@ -600,8 +768,22 @@ main(int argc, char *argv[]) patch); return 0; } - else + else { +#if WASM_ENABLE_LIBC_WASI != 0 + libc_wasi_parse_result_t result = + libc_wasi_parse(argv[0], &wasi_parse_ctx); + switch (result) { + case LIBC_WASI_PARSE_RESULT_OK: + continue; + case LIBC_WASI_PARSE_RESULT_NEED_HELP: + return print_help(); + case LIBC_WASI_PARSE_RESULT_BAD_PARAM: + return 1; + } +#else return print_help(); +#endif + } } if (argc == 0) @@ -620,9 +802,13 @@ main(int argc, char *argv[]) init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf); #else init_args.mem_alloc_type = Alloc_With_Allocator; - init_args.mem_alloc_option.allocator.malloc_func = malloc; - init_args.mem_alloc_option.allocator.realloc_func = realloc; - init_args.mem_alloc_option.allocator.free_func = free; +#if WASM_MEM_ALLOC_WITH_USER_DATA != 0 + /* Set user data for the allocator is needed */ + /* init_args.mem_alloc_option.allocator.user_data = user_data; */ +#endif + init_args.mem_alloc_option.allocator.malloc_func = malloc_func; + init_args.mem_alloc_option.allocator.realloc_func = realloc_func; + init_args.mem_alloc_option.allocator.free_func = free_func; #endif #if WASM_ENABLE_FAST_JIT != 0 @@ -632,6 +818,8 @@ main(int argc, char *argv[]) #if WASM_ENABLE_JIT != 0 init_args.llvm_jit_size_level = llvm_jit_size_level; init_args.llvm_jit_opt_level = llvm_jit_opt_level; + init_args.segue_flags = segue_flags; + init_args.linux_perf_support = enable_linux_perf_support; #endif #if WASM_ENABLE_DEBUG_INTERP != 0 @@ -651,8 +839,8 @@ main(int argc, char *argv[]) #endif #if BH_HAS_DLFCN - native_handle_count = load_and_register_native_libs( - native_lib_list, native_lib_count, native_handle_list); + native_lib_loaded_count = load_and_register_native_libs( + native_lib_list, native_lib_count, native_lib_loaded_list); #endif /* load WASM byte buffer from WASM bin file */ @@ -666,8 +854,8 @@ main(int argc, char *argv[]) int map_prot = MMAP_PROT_READ | MMAP_PROT_WRITE | MMAP_PROT_EXEC; int map_flags = MMAP_MAP_32BIT; - if (!(wasm_file_mapped = - os_mmap(NULL, (uint32)wasm_file_size, map_prot, map_flags))) { + if (!(wasm_file_mapped = os_mmap(NULL, (uint32)wasm_file_size, map_prot, + map_flags, os_get_invalid_handle()))) { printf("mmap memory failed\n"); wasm_runtime_free(wasm_file_buf); goto fail1; @@ -693,12 +881,7 @@ main(int argc, char *argv[]) } #if WASM_ENABLE_LIBC_WASI != 0 - wasm_runtime_set_wasi_args(wasm_module, dir_list, dir_list_size, NULL, 0, - env_list, env_list_size, argv, argc); - - wasm_runtime_set_wasi_addr_pool(wasm_module, addr_pool, addr_pool_size); - wasm_runtime_set_wasi_ns_lookup_pool(wasm_module, ns_lookup_pool, - ns_lookup_pool_size); + libc_wasi_init(wasm_module, argc, argv, &wasi_parse_ctx); #endif /* instantiate the module */ @@ -709,6 +892,12 @@ main(int argc, char *argv[]) goto fail3; } +#if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0 + if (disable_bounds_checks) { + wasm_runtime_set_bounds_checks(wasm_module_inst, false); + } +#endif + #if WASM_ENABLE_DEBUG_INTERP != 0 if (ip_addr != NULL) { wasm_exec_env_t exec_env = @@ -726,18 +915,37 @@ main(int argc, char *argv[]) } #endif +#if WASM_ENABLE_THREAD_MGR != 0 + struct timeout_arg timeout_arg; + korp_tid timeout_tid; + if (timeout_ms >= 0) { + timeout_arg.timeout_ms = timeout_ms; + timeout_arg.inst = wasm_module_inst; + timeout_arg.cancel = false; + ret = os_thread_create(&timeout_tid, timeout_thread, &timeout_arg, + APP_THREAD_STACK_SIZE_DEFAULT); + if (ret != 0) { + printf("Failed to start timeout\n"); + goto fail5; + } + } +#endif + ret = 0; + const char *exception = NULL; if (is_repl_mode) { app_instance_repl(wasm_module_inst); } else if (func_name) { - if (app_instance_func(wasm_module_inst, func_name)) { + exception = app_instance_func(wasm_module_inst, func_name); + if (exception) { /* got an exception */ ret = 1; } } else { - if (app_instance_main(wasm_module_inst)) { + exception = app_instance_main(wasm_module_inst); + if (exception) { /* got an exception */ ret = 1; } @@ -745,15 +953,30 @@ main(int argc, char *argv[]) #if WASM_ENABLE_LIBC_WASI != 0 if (ret == 0) { - /* wait for threads to finish and propagate wasi exit code. */ + /* propagate wasi exit code. */ ret = wasm_runtime_get_wasi_exit_code(wasm_module_inst); - if (wasm_runtime_get_exception(wasm_module_inst)) { - /* got an exception in spawned thread */ - ret = 1; - } } #endif + if (exception) + printf("%s\n", exception); + +#if WASM_ENABLE_STATIC_PGO != 0 && WASM_ENABLE_AOT != 0 + if (get_package_type(wasm_file_buf, wasm_file_size) == Wasm_Module_AoT + && gen_prof_file) + dump_pgo_prof_data(wasm_module_inst, gen_prof_file); +#endif + +#if WASM_ENABLE_THREAD_MGR != 0 + if (timeout_ms >= 0) { + timeout_arg.cancel = true; + os_thread_join(timeout_tid, NULL); + } +#endif + +#if WASM_ENABLE_THREAD_MGR != 0 +fail5: +#endif #if WASM_ENABLE_DEBUG_INTERP != 0 fail4: #endif @@ -774,7 +997,8 @@ main(int argc, char *argv[]) fail1: #if BH_HAS_DLFCN /* unload the native libraries */ - unregister_and_unload_native_libs(native_handle_count, native_handle_list); + unregister_and_unload_native_libs(native_lib_loaded_count, + native_lib_loaded_list); #endif /* destroy runtime environment */ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/riot/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/riot/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/riot/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/riot/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/riot/Makefile b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/riot/Makefile similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/riot/Makefile rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/riot/Makefile diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/riot/iwasmt.c b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/riot/iwasmt.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/riot/iwasmt.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/riot/iwasmt.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/riot/test_wasm.h b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/riot/test_wasm.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/riot/test_wasm.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/riot/test_wasm.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/rt-thread/SConscript b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/rt-thread/SConscript similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/rt-thread/SConscript rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/rt-thread/SConscript diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/rt-thread/iwasm.c b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/rt-thread/iwasm.c similarity index 97% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/rt-thread/iwasm.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/rt-thread/iwasm.c index 8ae4da76173..9a21301d831 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/rt-thread/iwasm.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/rt-thread/iwasm.c @@ -10,7 +10,6 @@ #include #include #include -#include #ifdef WAMR_ENABLE_RTT_EXPORT @@ -183,8 +182,6 @@ rt_uint8_t * my_read_file_to_buffer(char *filename, rt_uint32_t *size) { struct stat f_stat; - dfs_file_stat(filename, &f_stat); - struct dfs_fd fd; rt_uint8_t *buff = rt_malloc(f_stat.st_size); *size = 0; @@ -193,16 +190,16 @@ my_read_file_to_buffer(char *filename, rt_uint32_t *size) return RT_NULL; } - int ret = dfs_file_open(&fd, filename, O_RDONLY); - if (ret) { + int fd = open(filename, O_RDONLY); + if (fd < 0) { rt_free(buff); - rt_set_errno(ret); + rt_set_errno(fd); return RT_NULL; } - *size = dfs_file_read(&fd, buff, f_stat.st_size); + *size = read(fd, buff, f_stat.st_size); - dfs_file_close(&fd); + close(fd); if (*size != f_stat.st_size) { rt_free(buff); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/rt-thread/iwasm.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/rt-thread/iwasm.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/rt-thread/iwasm.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/rt-thread/iwasm.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/vxworks/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/vxworks/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/vxworks/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/vxworks/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/vxworks/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/vxworks/main.c new file mode 100644 index 00000000000..8f0e84a97f0 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/vxworks/main.c @@ -0,0 +1,6 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "../posix/main.c" diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/windows/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/windows/CMakeLists.txt similarity index 93% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/windows/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/windows/CMakeLists.txt index db88f42bc15..02aa3f31b4b 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/windows/CMakeLists.txt +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/windows/CMakeLists.txt @@ -4,7 +4,6 @@ cmake_minimum_required (VERSION 2.9) project (iwasm C ASM CXX) -enable_language(ASM_MASM) # set (CMAKE_VERBOSE_MAKEFILE 1) set (WAMR_BUILD_PLATFORM "windows") @@ -13,8 +12,6 @@ set (WAMR_BUILD_PLATFORM "windows") set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") -set (CMAKE_C_STANDARD 99) - add_definitions(-DCOMPILING_WASM_RUNTIME_API=1) # Set WAMR_BUILD_TARGET, currently values supported: @@ -96,6 +93,15 @@ if (WAMR_BUILD_DEBUG_INTERP EQUAL 1) set (WAMR_BUILD_SIMD 0) endif () +if (WAMR_BUILD_LIBC_WASI EQUAL 1) + set (CMAKE_C_STANDARD 11) + if (MSVC) + add_compile_options(/experimental:c11atomics) + endif() +else() + set (CMAKE_C_STANDARD 99) +endif() + set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) @@ -147,3 +153,9 @@ target_link_libraries (libiwasm ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS}) if (MINGW) target_link_libraries (libiwasm ws2_32) endif () + +if (WIN32) + target_link_libraries(libiwasm ntdll) + + target_link_libraries(iwasm ntdll) +endif() diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/windows/build_llvm.py b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/windows/build_llvm.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/windows/build_llvm.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/windows/build_llvm.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/windows/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/windows/main.c similarity index 81% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/windows/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/windows/main.c index 26fa7dcc968..921b7726541 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/windows/main.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/windows/main.c @@ -10,6 +10,10 @@ #include "bh_read_file.h" #include "wasm_export.h" +#if WASM_ENABLE_LIBC_WASI != 0 +#include "../common/libc_wasi.c" +#endif + static int app_argc; static char **app_argv; @@ -48,12 +52,7 @@ print_help() printf(" --repl Start a very simple REPL (read-eval-print-loop) mode\n" " that runs commands in the form of `FUNC ARG...`\n"); #if WASM_ENABLE_LIBC_WASI != 0 - printf(" --env= Pass wasi environment variables with \"key=value\"\n"); - printf(" to the program, for example:\n"); - printf(" --env=\"key1=value1\" --env=\"key2=value2\"\n"); - printf(" --dir= Grant wasi access to the given host directories\n"); - printf(" to the program, for example:\n"); - printf(" --dir= --dir=\n"); + libc_wasi_print_help(); #endif #if WASM_ENABLE_MULTI_MODULE != 0 printf(" --module-path= Indicate a module search path. default is current\n" @@ -77,8 +76,7 @@ app_instance_main(wasm_module_inst_t module_inst) const char *exception; wasm_application_execute_main(module_inst, app_argc, app_argv); - if ((exception = wasm_runtime_get_exception(module_inst))) - printf("%s\n", exception); + exception = wasm_runtime_get_exception(module_inst); return exception; } @@ -142,7 +140,8 @@ app_instance_repl(wasm_module_inst_t module_inst) char *cmd; size_t n; - while ((printf("webassembly> "), cmd = fgets(buffer, sizeof(buffer), stdin)) + while ((printf("webassembly> "), fflush(stdout), + cmd = fgets(buffer, sizeof(buffer), stdin)) != NULL) { bh_assert(cmd); n = strlen(cmd); @@ -162,8 +161,11 @@ app_instance_repl(wasm_module_inst_t module_inst) break; } if (app_argc != 0) { + const char *exception; wasm_application_execute_func(module_inst, app_argv[0], app_argc - 1, app_argv + 1); + if ((exception = wasm_runtime_get_exception(module_inst))) + printf("%s\n", exception); } free(app_argv); } @@ -171,28 +173,39 @@ app_instance_repl(wasm_module_inst_t module_inst) return NULL; } -#if WASM_ENABLE_LIBC_WASI != 0 -static bool -validate_env_str(char *env) +#if WASM_ENABLE_GLOBAL_HEAP_POOL != 0 +static char global_heap_buf[WASM_GLOBAL_HEAP_SIZE] = { 0 }; +#else +static void * +malloc_func( +#if WASM_MEM_ALLOC_WITH_USER_DATA != 0 + void *user_data, +#endif + unsigned int size) { - char *p = env; - int key_len = 0; - - while (*p != '\0' && *p != '=') { - key_len++; - p++; - } - - if (*p != '=' || key_len == 0) - return false; - - return true; + return malloc(size); } + +static void * +realloc_func( +#if WASM_MEM_ALLOC_WITH_USER_DATA != 0 + void *user_data, #endif + void *ptr, unsigned int size) +{ + return realloc(ptr, size); +} -#if WASM_ENABLE_GLOBAL_HEAP_POOL != 0 -static char global_heap_buf[WASM_GLOBAL_HEAP_SIZE] = { 0 }; +static void +free_func( +#if WASM_MEM_ALLOC_WITH_USER_DATA != 0 + void *user_data, #endif + void *ptr) +{ + free(ptr); +} +#endif /* end of WASM_ENABLE_GLOBAL_HEAP_POOL */ #if WASM_ENABLE_MULTI_MODULE != 0 static char * @@ -204,20 +217,29 @@ handle_module_path(const char *module_path) static char *module_search_path = "."; static bool -module_reader_callback(const char *module_name, uint8 **p_buffer, - uint32 *p_size) +module_reader_callback(package_type_t module_type, const char *module_name, + uint8 **p_buffer, uint32 *p_size) { - const char *format = "%s/%s.wasm"; - uint32 sz = (uint32)(strlen(module_search_path) + strlen("/") - + strlen(module_name) + strlen(".wasm") + 1); - char *wasm_file_name = BH_MALLOC(sz); + char *file_format = NULL; +#if WASM_ENABLE_INTERP != 0 + if (module_type == Wasm_Module_Bytecode) + file_format = ".wasm"; +#endif +#if WASM_ENABLE_AOT != 0 + if (module_type == Wasm_Module_AoT) + file_format = ".aot"; +#endif + bh_assert(file_format); + const char *format = "%s/%s%s"; + int sz = strlen(module_search_path) + strlen("/") + strlen(module_name) + + strlen(file_format) + 1; + char *wasm_file_name = wasm_runtime_malloc(sz); if (!wasm_file_name) { return false; } - - snprintf(wasm_file_name, sz, format, module_search_path, module_name); - - *p_buffer = (uint8 *)bh_read_file_to_buffer(wasm_file_name, p_size); + snprintf(wasm_file_name, sz, format, module_search_path, module_name, + file_format); + *p_buffer = (uint8_t *)bh_read_file_to_buffer(wasm_file_name, p_size); wasm_runtime_free(wasm_file_name); return *p_buffer != NULL; @@ -243,7 +265,12 @@ main(int argc, char *argv[]) const char *func_name = NULL; uint8 *wasm_file_buf = NULL; uint32 wasm_file_size; - uint32 stack_size = 64 * 1024, heap_size = 16 * 1024; + uint32 stack_size = 64 * 1024; +#if WASM_ENABLE_LIBC_WASI != 0 + uint32 heap_size = 0; +#else + uint32 heap_size = 16 * 1024; +#endif #if WASM_ENABLE_JIT != 0 uint32 llvm_jit_size_level = 3; uint32 llvm_jit_opt_level = 3; @@ -259,16 +286,17 @@ main(int argc, char *argv[]) bool is_repl_mode = false; bool is_xip_file = false; #if WASM_ENABLE_LIBC_WASI != 0 - const char *dir_list[8] = { NULL }; - uint32 dir_list_size = 0; - const char *env_list[8] = { NULL }; - uint32 env_list_size = 0; + libc_wasi_parse_context_t wasi_parse_ctx; #endif #if WASM_ENABLE_DEBUG_INTERP != 0 char *ip_addr = NULL; int instance_port = 0; #endif +#if WASM_ENABLE_LIBC_WASI != 0 + memset(&wasi_parse_ctx, 0, sizeof(wasi_parse_ctx)); +#endif + /* Process options. */ for (argc--, argv++; argc > 0 && argv[0][0] == '-'; argc--, argv++) { if (!strcmp(argv[0], "-f") || !strcmp(argv[0], "--function")) { @@ -350,38 +378,6 @@ main(int argc, char *argv[]) } } #endif -#if WASM_ENABLE_LIBC_WASI != 0 - else if (!strncmp(argv[0], "--dir=", 6)) { - if (argv[0][6] == '\0') - return print_help(); - if (dir_list_size >= sizeof(dir_list) / sizeof(char *)) { - printf("Only allow max dir number %d\n", - (int)(sizeof(dir_list) / sizeof(char *))); - return 1; - } - dir_list[dir_list_size++] = argv[0] + 6; - } - else if (!strncmp(argv[0], "--env=", 6)) { - char *tmp_env; - - if (argv[0][6] == '\0') - return print_help(); - if (env_list_size >= sizeof(env_list) / sizeof(char *)) { - printf("Only allow max env number %d\n", - (int)(sizeof(env_list) / sizeof(char *))); - return 1; - } - tmp_env = argv[0] + 6; - if (validate_env_str(tmp_env)) - env_list[env_list_size++] = tmp_env; - else { - printf("Wasm parse env string failed: expect \"key=value\", " - "got \"%s\"\n", - tmp_env); - return print_help(); - } - } -#endif /* WASM_ENABLE_LIBC_WASI */ #if WASM_ENABLE_MULTI_MODULE != 0 else if (!strncmp(argv[0], MODULE_PATH, strlen(MODULE_PATH))) { module_search_path = handle_module_path(argv[0]); @@ -417,8 +413,22 @@ main(int argc, char *argv[]) patch); return 0; } - else + else { +#if WASM_ENABLE_LIBC_WASI != 0 + libc_wasi_parse_result_t result = + libc_wasi_parse(argv[0], &wasi_parse_ctx); + switch (result) { + case LIBC_WASI_PARSE_RESULT_OK: + continue; + case LIBC_WASI_PARSE_RESULT_NEED_HELP: + return print_help(); + case LIBC_WASI_PARSE_RESULT_BAD_PARAM: + return 1; + } +#else return print_help(); +#endif + } } if (argc == 0) @@ -437,9 +447,13 @@ main(int argc, char *argv[]) init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf); #else init_args.mem_alloc_type = Alloc_With_Allocator; - init_args.mem_alloc_option.allocator.malloc_func = malloc; - init_args.mem_alloc_option.allocator.realloc_func = realloc; - init_args.mem_alloc_option.allocator.free_func = free; +#if WASM_MEM_ALLOC_WITH_USER_DATA != 0 + /* Set user data for the allocator is needed */ + /* init_args.mem_alloc_option.allocator.user_data = user_data; */ +#endif + init_args.mem_alloc_option.allocator.malloc_func = malloc_func; + init_args.mem_alloc_option.allocator.realloc_func = realloc_func; + init_args.mem_alloc_option.allocator.free_func = free_func; #endif #if WASM_ENABLE_JIT != 0 @@ -474,8 +488,8 @@ main(int argc, char *argv[]) int map_prot = MMAP_PROT_READ | MMAP_PROT_WRITE | MMAP_PROT_EXEC; int map_flags = MMAP_MAP_32BIT; - if (!(wasm_file_mapped = - os_mmap(NULL, (uint32)wasm_file_size, map_prot, map_flags))) { + if (!(wasm_file_mapped = os_mmap(NULL, (uint32)wasm_file_size, map_prot, + map_flags, os_get_invalid_handle()))) { printf("mmap memory failed\n"); wasm_runtime_free(wasm_file_buf); goto fail1; @@ -501,8 +515,7 @@ main(int argc, char *argv[]) } #if WASM_ENABLE_LIBC_WASI != 0 - wasm_runtime_set_wasi_args(wasm_module, dir_list, dir_list_size, NULL, 0, - env_list, env_list_size, argv, argc); + libc_wasi_init(wasm_module, argc, argv, &wasi_parse_ctx); #endif /* instantiate the module */ @@ -531,17 +544,20 @@ main(int argc, char *argv[]) #endif ret = 0; + const char *exception = NULL; if (is_repl_mode) { app_instance_repl(wasm_module_inst); } else if (func_name) { - if (app_instance_func(wasm_module_inst, func_name)) { + exception = app_instance_func(wasm_module_inst, func_name); + if (exception) { /* got an exception */ ret = 1; } } else { - if (app_instance_main(wasm_module_inst)) { + exception = app_instance_main(wasm_module_inst); + if (exception) { /* got an exception */ ret = 1; } @@ -549,15 +565,14 @@ main(int argc, char *argv[]) #if WASM_ENABLE_LIBC_WASI != 0 if (ret == 0) { - /* wait for threads to finish and propagate wasi exit code. */ + /* propagate wasi exit code. */ ret = wasm_runtime_get_wasi_exit_code(wasm_module_inst); - if (wasm_runtime_get_exception(wasm_module_inst)) { - /* got an exception in spawned thread */ - ret = 1; - } } #endif + if (exception) + printf("%s\n", exception); + #if WASM_ENABLE_DEBUG_INTERP != 0 fail4: #endif diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/windows/wasi_filtered_tests.json b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/windows/wasi_filtered_tests.json new file mode 100644 index 00000000000..492a746eb07 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/windows/wasi_filtered_tests.json @@ -0,0 +1,51 @@ +{ + "WASI C tests": { + "fdopendir-with-access": "Not implemented", + "lseek": "Not implemented" + }, + "WASI Rust tests": { + "dangling_symlink": "Not implemented", + "directory_seek": "Not implemented", + "dir_fd_op_failures": "Not implemented", + "fd_advise": "Not implemented", + "fd_fdstat_set_rights": "Not implemented", + "fd_filestat_set": "Not implemented", + "fd_flags_set": "Not implemented", + "fd_readdir": "Not implemented", + "file_allocate": "Not implemented", + "file_seek_tell": "Not implemented", + "file_truncation": "Not implemented", + "nofollow_errors": "Not implemented", + "path_exists": "Not implemented", + "path_filestat": "Not implemented", + "path_link": "Not implemented", + "path_open_preopen": "Not implemented", + "path_rename": "Not implemented", + "path_rename_dir_trailing_slashes": "Not implemented", + "path_symlink_trailing_slashes": "Not implemented", + "poll_oneoff_stdio": "Not implemented", + "readlink": "Not implemented (path_symlink)", + "symlink_create": "Not implemented", + "symlink_filestat": "Not implemented", + "symlink_loop": "Not implemented", + "truncation_rights": "Not implemented" + }, + "WASI threads proposal": { + "wasi_threads_exit_main_wasi_read": "Blocking ops not implemented", + "wasi_threads_exit_nonmain_wasi_read": "Blocking ops not implemented", + "wasi_threads_return_main_wasi_read": "Blocking ops not implemented", + "wasi_threads_return_main_wasi": "Blocking ops not implemented", + "wasi_threads_exit_nonmain_wasi": "Blocking ops not implemented", + "wasi_threads_exit_main_wasi": "Blocking ops not implemented" + }, + "WAMR lib-socket tests": { + "nslookup": "Not implemented", + "tcp_udp": "Not implemented" + }, + "lib-wasi-threads tests": { + "nonmain_proc_exit_sleep": "poll_oneoff not implemented", + "main_proc_exit_sleep": "poll_oneoff not implemented", + "main_trap_sleep": "poll_oneoff not implemented", + "nonmain_trap_sleep": "poll_oneoff not implemented" + } +} \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/Dockerfile b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/Dockerfile new file mode 100644 index 00000000000..a4c69a8ff39 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/Dockerfile @@ -0,0 +1,43 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +FROM ubuntu:22.04 + +ARG DEBIAN_FRONTEND=noninteractive +ENV TZ=Asian/Shanghai + +# Install dependencies for Zephyr +# hadolint ignore=DL3008 +RUN apt-get update && apt-get install -y --no-install-recommends git cmake ninja-build gperf \ + ccache dfu-util device-tree-compiler wget \ + python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \ + make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 \ + && apt-get clean -y && rm -rf /var/lib/apt/lists/* + +# Install the Zephyr Software Development Kit (SDK) +WORKDIR /opt +# hadolint ignore=DL4006 +RUN wget --progress=dot:giga https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.3/zephyr-sdk-0.16.3_linux-x86_64.tar.xz \ + && wget --progress=dot:giga -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.3/sha256.sum | shasum --check --ignore-missing \ + && tar xvf zephyr-sdk-0.16.3_linux-x86_64.tar.xz && rm zephyr-sdk-0.16.3_linux-x86_64.tar.xz + +WORKDIR /opt/zephyr-sdk-0.16.3 +# hadolint ignore=DL4006 +RUN yes | ./setup.sh + +# Get Zephyr +# hadolint ignore=DL3013 +RUN pip3 install --no-cache-dir west && west init -m https://github.com/zephyrproject-rtos/zephyr --mr v3.5.0 /root/zephyrproject + +WORKDIR /root/zephyrproject +RUN west update + +WORKDIR /root/zephyrproject/zephyr +RUN west zephyr-export && pip install --no-cache-dir -r ~/zephyrproject/zephyr/scripts/requirements.txt + +# Git clone wamr +WORKDIR /root +RUN git clone https://github.com/bytecodealliance/wasm-micro-runtime.git + +WORKDIR /root/wasm-micro-runtime/product-mini/platforms/zephyr/simple + +ENV ZEPHYR_BASE="/root/zephyrproject/zephyr" diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/README.md new file mode 100644 index 00000000000..5f8bd41ae40 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/README.md @@ -0,0 +1,108 @@ +# How to use WAMR with Zephyr + +[Zephyr](https://www.zephyrproject.org/) is an open source real-time operating +system (RTOS) with a focus on security and broad hardware support. WAMR is +compatible with Zephyr via the [Zephyr WAMR +port](../../../../core/shared/platform/zephyr). + +## Setup + +Using WAMR with Zephyr can be accomplished by either using the provided Docker +image, or by installing Zephyr locally. Both approaches are described below. + +### Docker + +The provided Docker image sets up Zephyr and its dependencies for all +architectures, meaning that you are ready to build for any [supported +board](https://docs.zephyrproject.org/latest/boards/index.html). This comes at +the expense of building a rather large image, which both can take a long time to +build and uses up a large amount of storage (~15 GB). + +Execute the following command to build the Docker image. This may take an +extended period of time to complete. + +```shell +docker build -t wamr-zephyr . +``` + +Execute the following command to run the image built in the previous step. If +you are planning to flash a device after building, make sure to specify it with +[`--device`](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities). + +```shell +docker run -it --rm --device=/dev/ttyUSB0 wamr-zephyr +``` + +### Local Environment + +Zephyr can also be setup locally to enable building this sample application. +This allows you have have more control over what modules and tools are +installed, which can drastically reduce the storage required compared to the +Docker image. + +Follow the steps provided in the [Zephyr Getting Started +guide](https://docs.zephyrproject.org/latest/develop/getting_started/index.html) +to setup for local development. + +## Building for a Specific Board + +With an environment setup either locally or in a Docker container, you can build +for a Zephyr suppported board using +[`west`](https://docs.zephyrproject.org/latest/develop/west/index.html). There +are already [configuaration files](./boards) for a few boards in this sample. +However, if you are using a new board, you will need to add your own file for +the board, or define configuration in the [`prj.conf](./prj.conf). After doing +so, use the following command with your board identifier to build the sample +application. + +```shell +west build . -b --pristine -- -DWAMR_BUILD_TARGET= +``` + +The `` can be found in the Zephyr supported boards +documentation. It must also be used as the name of the board configuration file. +You must define the architecture for WAMR to target with `WAMR_BUILD_TARGET`. +The list of supported architectures can be found in the main project +[README.md](../../../../README.md#supported-architectures-and-platforms). + +It may be necessary to define additional symbols for some boards. For example, +WAMR AOT execution may not be supported on all architectures. It and other +options can be disabled by modifying the [CMakeLists.txt](./CMakeLists.txt) +file, or by passing additional arguments at build (e.g. `-DWAMR_BUILD_AOT=0`). + +### Example Targets + +[ESP32-C3](https://docs.zephyrproject.org/latest/boards/riscv/esp32c3_devkitm/doc/index.html) +is a 32-bit RISC-V target that does not currently support AOT. + +```shell +west build . -b esp32c3_devkitm -p always -- -DWAMR_BUILD_TARGET=RISCV32_ILP32 -DWAMR_BUILD_AOT=0 +``` + +[ARM Cortex-A53 QEMU +(ARM)](https://docs.zephyrproject.org/latest/boards/arm64/qemu_cortex_a53/doc/index.html) +is a 64-bit ARM target for emulating the Cortex-A53 platform. + +```shell +west build . -b qemu_cortex_a53 -p always -- -DWAMR_BUILD_TARGET=AARCH64 +``` + + +## Flashing or Running Image + +The board can be flashed with the built image with the following command. + +```shell +west flash +``` + +`west` will automatically identify the board if it is connected to the host +machine. + +When using emulated targets, such as those that utilize QEMU, there is no +physical device to flash, but `west` can be used to run the image under +emulation. + +```shell +west build -t run +``` diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/nucleo767zi.conf b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/boards/nucleo_f767zi.conf similarity index 72% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/nucleo767zi.conf rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/boards/nucleo_f767zi.conf index c495644b79b..c920e6fd0cc 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/nucleo767zi.conf +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/boards/nucleo_f767zi.conf @@ -2,6 +2,3 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception CONFIG_ARM_MPU=y -CONFIG_STACK_SENTINEL=y -CONFIG_PRINTK=y -CONFIG_LOG=y diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_cortex_a53.conf b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/boards/qemu_cortex_a53.conf similarity index 72% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_cortex_a53.conf rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/boards/qemu_cortex_a53.conf index d248565fa01..2cc2dd4b472 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_cortex_a53.conf +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/boards/qemu_cortex_a53.conf @@ -2,6 +2,3 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception CONFIG_ARM_MMU=n -CONFIG_STACK_SENTINEL=y -CONFIG_PRINTK=y -CONFIG_LOG=y diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/build_and_run.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/build_and_run.sh similarity index 74% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/build_and_run.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/build_and_run.sh index 921f8836375..6b8fb4f8724 100755 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/build_and_run.sh +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/build_and_run.sh @@ -5,7 +5,6 @@ X86_TARGET="x86" STM32_TARGET="stm32" -ESP32_TARGET="esp32" ESP32C3_TARGET="esp32c3" PARTICLE_ARGON_TARGET="particle_argon" QEMU_CORTEX_A53="qemu_cortex_a53" @@ -17,11 +16,10 @@ QEMU_ARC_TARGET="qemu_arc" usage () { echo "USAGE:" - echo "$0 $X86_TARGET|$STM32_TARGET|$ESP32_TARGET|$ESP32C3_TARGET|$PARTICLE_ARGON_TARGET|$QEMU_CORTEX_A53|$QEMU_XTENSA_TARGET|$QEMU_RISCV64_TARGET|$QEMU_RISCV32_TARGET|$QEMU_ARC_TARGET" + echo "$0 $X86_TARGET|$STM32_TARGET|$ESP32C3_TARGET|$PARTICLE_ARGON_TARGET|$QEMU_CORTEX_A53|$QEMU_XTENSA_TARGET|$QEMU_RISCV64_TARGET|$QEMU_RISCV32_TARGET|$QEMU_ARC_TARGET" echo "Example:" echo " $0 $X86_TARGET" echo " $0 $STM32_TARGET" - echo " $0 $ESP32_TARGET" echo " $0 $ESP32C3_TARGET" echo " $0 $PARTICLE_ARGON_TARGET" echo " $0 $QEMU_CORTEX_A53" @@ -51,27 +49,11 @@ case $TARGET in -DWAMR_BUILD_TARGET=THUMBV7 west flash ;; - $ESP32_TARGET) - export ZEPHYR_TOOLCHAIN_VARIANT="espressif" - if [[ -z "${ESPRESSIF_TOOLCHAIN_PATH}" ]]; then - echo "Set ESPRESSIF_TOOLCHAIN_PATH to your espressif toolchain" - exit 1 - fi - west build -b esp32 \ - . -p always -- \ - -DWAMR_BUILD_TARGET=XTENSA - # west flash will discover the device - west flash - ;; $ESP32C3_TARGET) - export ZEPHYR_TOOLCHAIN_VARIANT="espressif" - if [[ -z "${ESPRESSIF_TOOLCHAIN_PATH}" ]]; then - echo "Set ESPRESSIF_TOOLCHAIN_PATH to your espressif toolchain" - exit 1 - fi west build -b esp32c3_devkitm \ . -p always -- \ - -DWAMR_BUILD_TARGET=RISCV32_ILP32 + -DWAMR_BUILD_TARGET=RISCV32_ILP32 \ + -DWAMR_BUILD_AOT=0 # west flash will discover the device west flash ;; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_arc.conf b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/prj.conf similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/boards/qemu_arc.conf rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/prj.conf diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/src/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/src/main.c similarity index 74% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/src/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/src/main.c index 8799e737a07..5d209a86875 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/src/main.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/src/main.c @@ -68,7 +68,7 @@ app_instance_main(wasm_module_inst_t module_inst) if (wasm_runtime_lookup_function(module_inst, "main", NULL) || wasm_runtime_lookup_function(module_inst, "__main_argc_argv", NULL)) { - LOG_VERBOSE("Calling main funciton\n"); + LOG_VERBOSE("Calling main function\n"); wasm_application_execute_main(module_inst, app_argc, app_argv); } else if ((func = wasm_runtime_lookup_function(module_inst, "app_main", @@ -80,7 +80,7 @@ app_instance_main(wasm_module_inst_t module_inst) return NULL; } - LOG_VERBOSE("Calling app_main funciton\n"); + LOG_VERBOSE("Calling app_main function\n"); wasm_runtime_call_wasm(exec_env, func, 0, argv); if (!wasm_runtime_get_exception(module_inst)) { @@ -104,56 +104,6 @@ app_instance_main(wasm_module_inst_t module_inst) static char global_heap_buf[CONFIG_GLOBAL_HEAP_BUF_SIZE] = { 0 }; #endif -#ifdef CONFIG_BOARD_ESP32 -#include "mem_alloc.h" -/* -esp32_technical_reference_manual: -" -The capacity of Internal SRAM 1 is 128 KB. Either CPU can read and write this -memory at addresses 0x3FFE_0000 ~ 0x3FFF_FFFF of the data bus, and also at -addresses 0x400A_0000 ~ 0x400B_FFFF of the instruction bus. -" - -The custom linker script defines dram0_1_seg and map it to 0x400A_0000 ~ -0x400B_FFFF for instruction bus access. Here we define the buffer that will be -placed to dram0_1_seg. -*/ -static char esp32_executable_memory_buf[100 * 1024] - __attribute__((section(".aot_code_buf"))) = { 0 }; - -/* the poll allocator for executable memory */ -static mem_allocator_t esp32_exec_mem_pool_allocator; - -static int -esp32_exec_mem_init() -{ - if (!(esp32_exec_mem_pool_allocator = - mem_allocator_create(esp32_executable_memory_buf, - sizeof(esp32_executable_memory_buf)))) - return -1; - - return 0; -} - -static void -esp32_exec_mem_destroy() -{ - mem_allocator_destroy(esp32_exec_mem_pool_allocator); -} - -static void * -esp32_exec_mem_alloc(unsigned int size) -{ - return mem_allocator_malloc(esp32_exec_mem_pool_allocator, size); -} - -static void -esp32_exec_mem_free(void *addr) -{ - mem_allocator_free(esp32_exec_mem_pool_allocator, addr); -} -#endif /* end of #ifdef CONFIG_BOARD_ESP32 */ - void iwasm_main(void *arg1, void *arg2, void *arg3) { @@ -189,16 +139,6 @@ iwasm_main(void *arg1, void *arg2, void *arg3) return; } -#ifdef CONFIG_BOARD_ESP32 - /* Initialize executable memory */ - if (esp32_exec_mem_init() != 0) { - printf("Init executable memory failed.\n"); - goto fail1; - } - /* Set hook functions for executable memory management */ - set_exec_mem_alloc_func(esp32_exec_mem_alloc, esp32_exec_mem_free); -#endif - #if WASM_ENABLE_LOG != 0 bh_log_set_verbose_level(log_verbose_level); #endif @@ -211,11 +151,7 @@ iwasm_main(void *arg1, void *arg2, void *arg3) if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size, error_buf, sizeof(error_buf)))) { printf("%s\n", error_buf); -#ifdef CONFIG_BOARD_ESP32 - goto fail1_1; -#else goto fail1; -#endif } /* instantiate the module */ @@ -236,19 +172,13 @@ iwasm_main(void *arg1, void *arg2, void *arg3) /* unload the module */ wasm_runtime_unload(wasm_module); -#ifdef CONFIG_BOARD_ESP32 -fail1_1: - /* destroy executable memory */ - esp32_exec_mem_destroy(); -#endif - fail1: /* destroy runtime environment */ wasm_runtime_destroy(); end = k_uptime_get_32(); - printf("elpase: %d\n", (end - start)); + printf("elapsed: %d\n", (end - start)); } #define MAIN_THREAD_STACK_SIZE (CONFIG_MAIN_THREAD_STACK_SIZE) @@ -265,8 +195,18 @@ iwasm_init(void) iwasm_main, NULL, NULL, NULL, MAIN_THREAD_PRIORITY, 0, K_NO_WAIT); return tid ? true : false; } + +#if KERNEL_VERSION_NUMBER < 0x030400 /* version 3.4.0 */ void main(void) { iwasm_init(); } +#else +int +main(void) +{ + iwasm_init(); + return 0; +} +#endif diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/src/test_wasm.h b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/src/test_wasm.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/src/test_wasm.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/src/test_wasm.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/src/test_wasm_riscv64.h b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/src/test_wasm_riscv64.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/src/test_wasm_riscv64.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/src/test_wasm_riscv64.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/src/wasm-app-riscv64/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/src/wasm-app-riscv64/build.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/src/wasm-app-riscv64/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/src/wasm-app-riscv64/build.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/src/wasm-app-riscv64/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/src/wasm-app-riscv64/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/product-mini/platforms/zephyr/simple/src/wasm-app-riscv64/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/product-mini/platforms/zephyr/simple/src/wasm-app-riscv64/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/basic/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/basic/.gitignore similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/basic/.gitignore rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/basic/.gitignore diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/basic/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/basic/CMakeLists.txt similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/basic/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/basic/CMakeLists.txt index 4191ad15d1c..62edf08fb75 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/basic/CMakeLists.txt +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/basic/CMakeLists.txt @@ -9,7 +9,6 @@ if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows") project (basic) else() project (basic C ASM) - enable_language (ASM_MASM) endif() ################ runtime settings ################ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/basic/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/basic/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/basic/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/basic/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/basic/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/basic/build.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/basic/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/basic/build.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/basic/run.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/basic/run.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/basic/run.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/basic/run.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/basic/src/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/basic/src/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/basic/src/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/basic/src/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/basic/src/native_impl.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/basic/src/native_impl.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/basic/src/native_impl.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/basic/src/native_impl.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/basic/wasm-apps/testapp.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/basic/wasm-apps/testapp.c similarity index 96% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/basic/wasm-apps/testapp.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/basic/wasm-apps/testapp.c index ea575e20ce6..8db293071c9 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/basic/wasm-apps/testapp.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/basic/wasm-apps/testapp.c @@ -58,7 +58,7 @@ float_to_string(float n, char *res, int res_size, int afterpoint) // is needed to handle cases like 233.007 fpart = fpart * get_pow(10, afterpoint); - intToStr((int)fpart, res + i + 1, sizeof(res + i + 1), afterpoint); + intToStr((int)fpart, res + i + 1, res_size - i - 1, afterpoint); } } diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/bh-atomic/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/bh-atomic/CMakeLists.txt new file mode 100644 index 00000000000..f6905274213 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/bh-atomic/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright (C) 2023 Midokura Japan KK. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +cmake_minimum_required(VERSION 3.0) +project(bh_atomic) + +string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) +if(APPLE) + add_definitions(-DBH_PLATFORM_DARWIN) +endif() + +set(WAMR_BUILD_INTERP 1) +set(WAMR_BUILD_LIBC_BUILTIN 0) + +set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../..) +include(${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) + +add_executable(bh_atomic main.c) + +target_link_libraries(bh_atomic) diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/bh-atomic/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/bh-atomic/main.c new file mode 100644 index 00000000000..61c52800bdd --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/bh-atomic/main.c @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2023 Midokura Japan KK. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include + +#include "bh_platform.h" +#include "bh_atomic.h" + +int +main(int argc, char **argv) +{ + bh_atomic_32_t v; + uint32 o; + + v = 0x00ff00ff; + o = BH_ATOMIC_32_LOAD(v); + assert(o == 0x00ff00ff); + + v = 0x00ff00ff; + o = BH_ATOMIC_32_FETCH_OR(v, 0xffff0000); + assert(o == 0x00ff00ff); + assert(v == 0xffff00ff); + + v = 0x00ff00ff; + o = BH_ATOMIC_32_FETCH_AND(v, 0xffff0000); + assert(o == 0x00ff00ff); + assert(v == 0x00ff0000); + + v = 0x00ff00ff; + o = BH_ATOMIC_32_FETCH_ADD(v, 0x10101); + assert(o == 0x00ff00ff); + assert(v == 0x00ff00ff + 0x10101); + + v = 0x00ff00ff; + o = BH_ATOMIC_32_FETCH_SUB(v, 0x10101); + assert(o == 0x00ff00ff); + assert(v == 0x00ff00ff - 0x10101); + + return 0; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/file/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/file/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/file/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/file/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/file/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/file/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/file/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/file/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/file/src/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/file/src/CMakeLists.txt similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/file/src/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/file/src/CMakeLists.txt index 2bc3bec6415..1f7a2435f0a 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/file/src/CMakeLists.txt +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/file/src/CMakeLists.txt @@ -9,7 +9,6 @@ if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows") project (iwasm) else() project (iwasm C ASM) - enable_language (ASM_MASM) endif() ################ runtime settings ################ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/file/src/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/file/src/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/file/src/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/file/src/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/file/wasm-app/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/file/wasm-app/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/file/wasm-app/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/file/wasm-app/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/file/wasm-app/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/file/wasm-app/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/file/wasm-app/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/file/wasm-app/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/build.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/build.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/lv_config/lv_conf.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/lv_config/lv_conf.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/lv_config/lv_conf.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/lv_config/lv_conf.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/lv_config/lv_drv_conf.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/lv_config/lv_drv_conf.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/lv_config/lv_drv_conf.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/lv_config/lv_drv_conf.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/lv_config/system_header.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/lv_config/system_header.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/lv_config/system_header.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/lv_config/system_header.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wamr_config_gui.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wamr_config_gui.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wamr_config_gui.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wamr_config_gui.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-apps/build_apps.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-apps/build_apps.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-apps/build_apps.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-apps/build_apps.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-apps/decrease/Makefile b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-apps/decrease/Makefile similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-apps/decrease/Makefile rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-apps/decrease/Makefile diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-apps/decrease/src/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-apps/decrease/src/main.c similarity index 84% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-apps/decrease/src/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-apps/decrease/src/main.c index a6c30aa1a6c..9635ebea83b 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-apps/decrease/src/main.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-apps/decrease/src/main.c @@ -46,14 +46,14 @@ on_init() count_label = lv_label_create(NULL, NULL); lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0); - btn1 = lv_btn_create( - NULL, NULL); /*Create a button on the currently loaded screen*/ - lv_obj_set_event_cb( - btn1, - btn_event_cb); /*Set function to be called when the button is released*/ - lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align below the label*/ + /* Create a button on the currently loaded screen */ + btn1 = lv_btn_create(NULL, NULL); + /* Set function to be called when the button is released */ + lv_obj_set_event_cb(btn1, (lv_event_cb_t)btn_event_cb); + /* Align below the label */ + lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0); - /*Create a label on the button*/ + /* Create a label on the button */ lv_obj_t *btn_label = lv_label_create(btn1, NULL); lv_label_set_text(btn_label, "Click --"); @@ -61,7 +61,7 @@ on_init() lv_label_set_text(label_count1, "100"); lv_obj_align(label_count1, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); - /* set up a timer */ + /* Set up a timer */ user_timer_t timer; timer = api_timer_create(10, true, false, timer1_update); if (timer) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-apps/increase/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-apps/increase/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-apps/increase/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-apps/increase/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-apps/increase/Makefile b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-apps/increase/Makefile similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-apps/increase/Makefile rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-apps/increase/Makefile diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-apps/increase/src/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-apps/increase/src/main.c similarity index 84% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-apps/increase/src/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-apps/increase/src/main.c index b5271830a05..31118f7be4d 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-apps/increase/src/main.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-apps/increase/src/main.c @@ -46,14 +46,14 @@ on_init() count_label = lv_label_create(NULL, NULL); lv_obj_align(count_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0); - btn1 = lv_btn_create( - NULL, NULL); /*Create a button on the currently loaded screen*/ - lv_obj_set_event_cb( - btn1, - btn_event_cb); /*Set function to be called when the button is released*/ - lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align below the label*/ + /* Create a button on the current loaded screen */ + btn1 = lv_btn_create(NULL, NULL); + /* Set function to be called when the button is released */ + lv_obj_set_event_cb(btn1, (lv_event_cb_t)btn_event_cb); + /* Align below the label */ + lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0); - /*Create a label on the button*/ + /* Create a label on the button */ lv_obj_t *btn_label = lv_label_create(btn1, NULL); lv_label_set_text(btn_label, "Click ++"); @@ -61,7 +61,7 @@ on_init() lv_label_set_text(label_count1, "1"); lv_obj_align(label_count1, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); - /* set up a timer */ + /* Set up a timer */ user_timer_t timer; timer = api_timer_create(10, true, false, timer1_update); if (timer) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/linux/iwasm_main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/linux/iwasm_main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/linux/iwasm_main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/linux/iwasm_main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/linux/lv_drv_conf.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/linux/lv_drv_conf.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/linux/lv_drv_conf.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/linux/lv_drv_conf.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/linux/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/linux/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/linux/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/linux/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/LICENSE b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/LICENSE similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/LICENSE rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/LICENSE diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/XPT2046.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/board_config.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/board_config.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/board_config.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/board_config.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340_adafruit_1480.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340_adafruit_1480.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340_adafruit_1480.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/display_ili9340_adafruit_1480.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/iwasm_main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/iwasm_main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/iwasm_main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/iwasm_main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/pin_config_jlf.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/pin_config_jlf.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/pin_config_jlf.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/pin_config_jlf.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/pin_config_stm32.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/pin_config_stm32.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/gui/wasm-runtime-wgl/src/platform/zephyr/pin_config_stm32.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/gui/wasm-runtime-wgl/src/platform/zephyr/pin_config_stm32.h diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/.gitignore new file mode 100644 index 00000000000..0fa8a76bdaf --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/.gitignore @@ -0,0 +1 @@ +/out/ \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/CMakeLists.txt new file mode 100644 index 00000000000..5ce8696d8d2 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/CMakeLists.txt @@ -0,0 +1,91 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +cmake_minimum_required (VERSION 3.14) + +include(CheckPIESupported) + +if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows") + project (inst-context) +else() + project (inst-context C ASM) +endif() + +################ runtime settings ################ +string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) +if (APPLE) + add_definitions(-DBH_PLATFORM_DARWIN) +endif () + +# Reset default linker flags +set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") +set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") + +# WAMR features switch + +# Set WAMR_BUILD_TARGET, currently values supported: +# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", +# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]" +if (NOT DEFINED WAMR_BUILD_TARGET) + if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)") + set (WAMR_BUILD_TARGET "AARCH64") + elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64") + set (WAMR_BUILD_TARGET "RISCV64") + elseif (CMAKE_SIZEOF_VOID_P EQUAL 8) + # Build as X86_64 by default in 64-bit platform + set (WAMR_BUILD_TARGET "X86_64") + elseif (CMAKE_SIZEOF_VOID_P EQUAL 4) + # Build as X86_32 by default in 32-bit platform + set (WAMR_BUILD_TARGET "X86_32") + else () + message(SEND_ERROR "Unsupported build target platform!") + endif () +endif () + +if (NOT CMAKE_BUILD_TYPE) + set (CMAKE_BUILD_TYPE Debug) +endif () + +set (WAMR_BUILD_INTERP 1) +set (WAMR_BUILD_AOT 1) +set (WAMR_BUILD_JIT 0) +set (WAMR_BUILD_LIBC_BUILTIN 0) +set (WAMR_BUILD_LIB_WASI_THREADS 1) + +if (NOT MSVC) + set (WAMR_BUILD_LIBC_WASI 1) +endif () + +if (NOT MSVC) + # linker flags + if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) + set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") + endif () + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") + if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64") + if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register") + endif () + endif () +endif () + +# build out vmlib +set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) +include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) + +add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE}) + +################ application related ################ +include_directories(${CMAKE_CURRENT_LIST_DIR}/src) +include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) + +add_executable (inst-context src/main.c src/native_impl.c ${UNCOMMON_SHARED_SOURCE}) + +check_pie_supported() +set_target_properties (inst-context PROPERTIES POSITION_INDEPENDENT_CODE ON) + +if (APPLE) + target_link_libraries (inst-context vmlib -lm -ldl -lpthread) +else () + target_link_libraries (inst-context vmlib -lm -ldl -lpthread -lrt) +endif () diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/README.md new file mode 100644 index 00000000000..d64cbff52b9 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/README.md @@ -0,0 +1,5 @@ +The "inst-context-threads" sample project +========================================= + +This sample demonstrates some interactions between +module instance context API and wasi-threads. diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/build.sh new file mode 100755 index 00000000000..35f76eccf84 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/build.sh @@ -0,0 +1,61 @@ +# +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# + +#!/bin/bash + +CURR_DIR=$PWD +WAMR_DIR=${PWD}/../.. +OUT_DIR=${PWD}/out + +WASM_APPS=${PWD}/wasm-apps + + +rm -rf ${OUT_DIR} +mkdir ${OUT_DIR} +mkdir ${OUT_DIR}/wasm-apps + + +echo "#####################build inst-context project" +cd ${CURR_DIR} +mkdir -p cmake_build +cd cmake_build +cmake .. +make -j ${nproc} +if [ $? != 0 ];then + echo "BUILD_FAIL inst-context exit as $?\n" + exit 2 +fi + +cp -a inst-context ${OUT_DIR} + +echo -e "\n" + +echo "#####################build wasm apps" + +cd ${WASM_APPS} + +for i in `ls *.c` +do +APP_SRC="$i" +OUT_FILE=${i%.*}.wasm + +# use WAMR SDK to build out the .wasm binary +# require wasi-sdk with wasi-threads support. (wasi-sdk-20.0 or later) +/opt/wasi-sdk/bin/clang \ + --target=wasm32-wasi-threads \ + -pthread \ + -Wl,--import-memory \ + -Wl,--export-memory \ + -Wl,--max-memory=655360 \ + -o ${OUT_DIR}/wasm-apps/${OUT_FILE} ${APP_SRC} + + +if [ -f ${OUT_DIR}/wasm-apps/${OUT_FILE} ]; then + echo "build ${OUT_FILE} success" +else + echo "build ${OUT_FILE} fail" +fi +done +echo "####################build wasm apps done" diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/run.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/run.sh new file mode 100755 index 00000000000..919ed016661 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +out/inst-context -f out/wasm-apps/testapp.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/src/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/src/main.c new file mode 100644 index 00000000000..2a20363c552 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/src/main.c @@ -0,0 +1,151 @@ + +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "wasm_export.h" +#include "bh_read_file.h" +#include "bh_getopt.h" +#include "my_context.h" + +void +set_context(wasm_exec_env_t exec_env, int32_t n); +int32_t +get_context(wasm_exec_env_t exec_env); + +void *my_context_key; +struct my_context my_context; +int my_dtor_called; + +wasm_module_inst_t module_inst = NULL; + +void +print_usage(void) +{ + fprintf(stdout, "Options:\r\n"); + fprintf(stdout, " -f [path of wasm file] \n"); +} + +void +my_context_dtor(wasm_module_inst_t inst, void *ctx) +{ + printf("%s called\n", __func__); + my_dtor_called++; + bh_assert(ctx == &my_context); + bh_assert(inst == module_inst); +} + +int +main(int argc, char *argv_main[]) +{ + static char global_heap_buf[512 * 1024]; + char *buffer; + char error_buf[128]; + int opt; + char *wasm_path = NULL; + int exit_code = 1; + + wasm_module_t module = NULL; + uint32 buf_size, stack_size = 8092, heap_size = 8092; + + RuntimeInitArgs init_args; + memset(&init_args, 0, sizeof(RuntimeInitArgs)); + + while ((opt = getopt(argc, argv_main, "hf:")) != -1) { + switch (opt) { + case 'f': + wasm_path = optarg; + break; + case 'h': + print_usage(); + return 0; + case '?': + print_usage(); + return 0; + } + } + if (optind == 1) { + print_usage(); + return 0; + } + + // Define an array of NativeSymbol for the APIs to be exported. + // Note: the array must be static defined since runtime + // will keep it after registration + // For the function signature specifications, goto the link: + // https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/export_native_api.md + + static NativeSymbol native_symbols[] = { + { "set_context", set_context, "(i)", NULL }, + { "get_context", get_context, "()i", NULL }, + }; + + init_args.mem_alloc_type = Alloc_With_Pool; + init_args.mem_alloc_option.pool.heap_buf = global_heap_buf; + init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf); + + // Native symbols need below registration phase + init_args.n_native_symbols = sizeof(native_symbols) / sizeof(NativeSymbol); + init_args.native_module_name = "env"; + init_args.native_symbols = native_symbols; + + if (!wasm_runtime_full_init(&init_args)) { + printf("Init runtime environment failed.\n"); + return -1; + } + + my_context_key = wasm_runtime_create_context_key(my_context_dtor); + if (!my_context_key) { + printf("wasm_runtime_create_context_key failed.\n"); + return -1; + } + + buffer = bh_read_file_to_buffer(wasm_path, &buf_size); + + if (!buffer) { + printf("Open wasm app file [%s] failed.\n", wasm_path); + goto fail; + } + + module = wasm_runtime_load((uint8 *)buffer, buf_size, error_buf, + sizeof(error_buf)); + if (!module) { + printf("Load wasm module failed. error: %s\n", error_buf); + goto fail; + } + + module_inst = wasm_runtime_instantiate(module, stack_size, heap_size, + error_buf, sizeof(error_buf)); + + if (!module_inst) { + printf("Instantiate wasm module failed. error: %s\n", error_buf); + goto fail; + } + + char *args[] = { + "testapp", + }; + wasm_application_execute_main(module_inst, 1, args); + const char *exc = wasm_runtime_get_exception(module_inst); + if (exc != NULL) { + printf("call wasm function calculate failed. error: %s\n", exc); + goto fail; + } + + exit_code = 0; +fail: + if (module_inst) { + bh_assert(my_dtor_called == 0); + wasm_runtime_deinstantiate(module_inst); + bh_assert(my_dtor_called == 1); + } + if (module) + wasm_runtime_unload(module); + if (buffer) + BH_FREE(buffer); + if (my_context_key) + wasm_runtime_destroy_context_key(my_context_key); + wasm_runtime_destroy(); + return exit_code; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/src/my_context.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/src/my_context.h new file mode 100644 index 00000000000..008be71ff12 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/src/my_context.h @@ -0,0 +1,11 @@ +/* + * Copyright (C) 2023 Midokura Japan KK. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +struct my_context { + int x; +}; + +extern void *my_context_key; +extern struct my_context my_context; diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/src/native_impl.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/src/native_impl.c new file mode 100644 index 00000000000..0733e1976dd --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/src/native_impl.c @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2023 Midokura Japan KK. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include +#include + +#include "wasm_export.h" +#include "my_context.h" + +void +set_context(wasm_exec_env_t exec_env, int32_t n) +{ + wasm_module_inst_t inst = wasm_runtime_get_module_inst(exec_env); + printf("%s called on module inst %p\n", __func__, inst); + struct my_context *ctx = &my_context; + ctx->x = n; + wasm_runtime_set_context_spread(inst, my_context_key, ctx); +} + +int32_t +get_context(wasm_exec_env_t exec_env) +{ + wasm_module_inst_t inst = wasm_runtime_get_module_inst(exec_env); + printf("%s called on module inst %p\n", __func__, inst); + struct my_context *ctx = wasm_runtime_get_context(inst, my_context_key); + if (ctx == NULL) { + return -1; + } + return ctx->x; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/wasm-apps/testapp.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/wasm-apps/testapp.c new file mode 100644 index 00000000000..429b0875fa9 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context-threads/wasm-apps/testapp.c @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2023 Midokura Japan KK. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include +#include +#include +#include +#include + +void +set_context(int32_t n) __attribute__((import_module("env"))) +__attribute__((import_name("set_context"))); + +int32_t +get_context() __attribute__((import_module("env"))) +__attribute__((import_name("get_context"))); + +void * +start(void *vp) +{ + int32_t v; + + printf("thread started\n"); + + printf("confirming the initial state on thread\n"); + v = get_context(); + assert(v == -1); + + printf("setting the context on thread\n"); + set_context(1234); + + printf("confirming the context on thread\n"); + v = get_context(); + assert(v == 1234); + return NULL; +} + +int +main() +{ + pthread_t t1; + int32_t v; + int ret; + + printf("confirming the initial state on main\n"); + v = get_context(); + assert(v == -1); + + printf("creating a thread\n"); + ret = pthread_create(&t1, NULL, start, NULL); + assert(ret == 0); + void *val; + ret = pthread_join(t1, &val); + assert(ret == 0); + printf("joined the thread\n"); + + printf("confirming the context propagated from the thread on main\n"); + v = get_context(); + assert(v == 1234); + + printf("success\n"); + return 0; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/.gitignore new file mode 100644 index 00000000000..0fa8a76bdaf --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/.gitignore @@ -0,0 +1 @@ +/out/ \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/CMakeLists.txt new file mode 100644 index 00000000000..af387ca2676 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/CMakeLists.txt @@ -0,0 +1,90 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +cmake_minimum_required (VERSION 3.14) + +include(CheckPIESupported) + +if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows") + project (inst-context) +else() + project (inst-context C ASM) +endif() + +################ runtime settings ################ +string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) +if (APPLE) + add_definitions(-DBH_PLATFORM_DARWIN) +endif () + +# Reset default linker flags +set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") +set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") + +# WAMR features switch + +# Set WAMR_BUILD_TARGET, currently values supported: +# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", +# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]" +if (NOT DEFINED WAMR_BUILD_TARGET) + if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)") + set (WAMR_BUILD_TARGET "AARCH64") + elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64") + set (WAMR_BUILD_TARGET "RISCV64") + elseif (CMAKE_SIZEOF_VOID_P EQUAL 8) + # Build as X86_64 by default in 64-bit platform + set (WAMR_BUILD_TARGET "X86_64") + elseif (CMAKE_SIZEOF_VOID_P EQUAL 4) + # Build as X86_32 by default in 32-bit platform + set (WAMR_BUILD_TARGET "X86_32") + else () + message(SEND_ERROR "Unsupported build target platform!") + endif () +endif () + +if (NOT CMAKE_BUILD_TYPE) + set (CMAKE_BUILD_TYPE Debug) +endif () + +set (WAMR_BUILD_INTERP 1) +set (WAMR_BUILD_AOT 1) +set (WAMR_BUILD_JIT 0) +set (WAMR_BUILD_LIBC_BUILTIN 1) + +if (NOT MSVC) + set (WAMR_BUILD_LIBC_WASI 1) +endif () + +if (NOT MSVC) + # linker flags + if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) + set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") + endif () + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") + if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64") + if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register") + endif () + endif () +endif () + +# build out vmlib +set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) +include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) + +add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE}) + +################ application related ################ +include_directories(${CMAKE_CURRENT_LIST_DIR}/src) +include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) + +add_executable (inst-context src/main.c src/native_impl.c ${UNCOMMON_SHARED_SOURCE}) + +check_pie_supported() +set_target_properties (inst-context PROPERTIES POSITION_INDEPENDENT_CODE ON) + +if (APPLE) + target_link_libraries (inst-context vmlib -lm -ldl -lpthread) +else () + target_link_libraries (inst-context vmlib -lm -ldl -lpthread -lrt) +endif () diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/README.md new file mode 100644 index 00000000000..43b13c66bb3 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/README.md @@ -0,0 +1,4 @@ +The "inst-context" sample project +================================= + +This sample demonstrates module instance context API. diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/build.sh new file mode 100755 index 00000000000..816e1cc08ef --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/build.sh @@ -0,0 +1,63 @@ +# +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# + +#!/bin/bash + +CURR_DIR=$PWD +WAMR_DIR=${PWD}/../.. +OUT_DIR=${PWD}/out + +WASM_APPS=${PWD}/wasm-apps + + +rm -rf ${OUT_DIR} +mkdir ${OUT_DIR} +mkdir ${OUT_DIR}/wasm-apps + + +echo "#####################build inst-context project" +cd ${CURR_DIR} +mkdir -p cmake_build +cd cmake_build +cmake .. +make -j ${nproc} +if [ $? != 0 ];then + echo "BUILD_FAIL inst-context exit as $?\n" + exit 2 +fi + +cp -a inst-context ${OUT_DIR} + +echo -e "\n" + +echo "#####################build wasm apps" + +cd ${WASM_APPS} + +for i in `ls *.c` +do +APP_SRC="$i" +OUT_FILE=${i%.*}.wasm + +# use WAMR SDK to build out the .wasm binary +/opt/wasi-sdk/bin/clang \ + --target=wasm32 -O0 -z stack-size=4096 -Wl,--initial-memory=65536 \ + --sysroot=${WAMR_DIR}/wamr-sdk/app/libc-builtin-sysroot \ + -Wl,--allow-undefined-file=${WAMR_DIR}/wamr-sdk/app/libc-builtin-sysroot/share/defined-symbols.txt \ + -Wl,--strip-all,--no-entry -nostdlib \ + -Wl,--export=generate_float \ + -Wl,--export=float_to_string \ + -Wl,--export=calculate\ + -Wl,--allow-undefined \ + -o ${OUT_DIR}/wasm-apps/${OUT_FILE} ${APP_SRC} + + +if [ -f ${OUT_DIR}/wasm-apps/${OUT_FILE} ]; then + echo "build ${OUT_FILE} success" +else + echo "build ${OUT_FILE} fail" +fi +done +echo "####################build wasm apps done" diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/run.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/run.sh new file mode 100755 index 00000000000..919ed016661 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +out/inst-context -f out/wasm-apps/testapp.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/src/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/src/main.c new file mode 100644 index 00000000000..0d774735e47 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/src/main.c @@ -0,0 +1,166 @@ + +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "wasm_export.h" +#include "bh_read_file.h" +#include "bh_getopt.h" +#include "my_context.h" + +int32_t +add_native(int32_t n); +void *my_context_key; +struct my_context my_context; +int my_dtor_called; + +wasm_module_inst_t module_inst = NULL; + +void +print_usage(void) +{ + fprintf(stdout, "Options:\r\n"); + fprintf(stdout, " -f [path of wasm file] \n"); +} + +void +my_context_dtor(wasm_module_inst_t inst, void *ctx) +{ + printf("%s called\n", __func__); + my_dtor_called++; + bh_assert(ctx == &my_context); + bh_assert(inst == module_inst); +} + +int +main(int argc, char *argv_main[]) +{ + static char global_heap_buf[512 * 1024]; + char *buffer; + char error_buf[128]; + int opt; + char *wasm_path = NULL; + + wasm_module_t module = NULL; + wasm_exec_env_t exec_env = NULL; + uint32 buf_size, stack_size = 8092, heap_size = 8092; + + RuntimeInitArgs init_args; + memset(&init_args, 0, sizeof(RuntimeInitArgs)); + + while ((opt = getopt(argc, argv_main, "hf:")) != -1) { + switch (opt) { + case 'f': + wasm_path = optarg; + break; + case 'h': + print_usage(); + return 0; + case '?': + print_usage(); + return 0; + } + } + if (optind == 1) { + print_usage(); + return 0; + } + + // Define an array of NativeSymbol for the APIs to be exported. + // Note: the array must be static defined since runtime + // will keep it after registration + // For the function signature specifications, goto the link: + // https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/export_native_api.md + + static NativeSymbol native_symbols[] = { { "add_native", add_native, "(i)i", + NULL } }; + + init_args.mem_alloc_type = Alloc_With_Pool; + init_args.mem_alloc_option.pool.heap_buf = global_heap_buf; + init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf); + + // Native symbols need below registration phase + init_args.n_native_symbols = sizeof(native_symbols) / sizeof(NativeSymbol); + init_args.native_module_name = "env"; + init_args.native_symbols = native_symbols; + + if (!wasm_runtime_full_init(&init_args)) { + printf("Init runtime environment failed.\n"); + return -1; + } + + my_context_key = wasm_runtime_create_context_key(my_context_dtor); + if (!my_context_key) { + printf("wasm_runtime_create_context_key failed.\n"); + return -1; + } + + buffer = bh_read_file_to_buffer(wasm_path, &buf_size); + + if (!buffer) { + printf("Open wasm app file [%s] failed.\n", wasm_path); + goto fail; + } + + module = wasm_runtime_load((uint8 *)buffer, buf_size, error_buf, + sizeof(error_buf)); + if (!module) { + printf("Load wasm module failed. error: %s\n", error_buf); + goto fail; + } + + module_inst = wasm_runtime_instantiate(module, stack_size, heap_size, + error_buf, sizeof(error_buf)); + + if (!module_inst) { + printf("Instantiate wasm module failed. error: %s\n", error_buf); + goto fail; + } + + my_context.x = 100; + wasm_runtime_set_context(module_inst, my_context_key, &my_context); + + exec_env = wasm_runtime_create_exec_env(module_inst, stack_size); + if (!exec_env) { + printf("Create wasm execution environment failed.\n"); + goto fail; + } + + wasm_function_inst_t func3 = + wasm_runtime_lookup_function(module_inst, "calculate", NULL); + if (!func3) { + printf("The wasm function calculate is not found.\n"); + goto fail; + } + + uint32_t argv3[1] = { 3 }; + if (wasm_runtime_call_wasm(exec_env, func3, 1, argv3)) { + uint32_t result = *(uint32_t *)argv3; + printf("Native finished calling wasm function: calculate, return: %d\n", + result); + bh_assert(result == 103); /* argv3[0] + my_context.x */ + } + else { + printf("call wasm function calculate failed. error: %s\n", + wasm_runtime_get_exception(module_inst)); + goto fail; + } + +fail: + if (exec_env) + wasm_runtime_destroy_exec_env(exec_env); + if (module_inst) { + bh_assert(my_dtor_called == 0); + wasm_runtime_deinstantiate(module_inst); + bh_assert(my_dtor_called == 1); + } + if (module) + wasm_runtime_unload(module); + if (buffer) + BH_FREE(buffer); + if (my_context_key) + wasm_runtime_destroy_context_key(my_context_key); + wasm_runtime_destroy(); + return 0; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/src/my_context.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/src/my_context.h new file mode 100644 index 00000000000..db49c1e3b5f --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/src/my_context.h @@ -0,0 +1,10 @@ +/* + * Copyright (C) 2023 Midokura Japan KK. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +struct my_context { + int x; +}; + +extern void *my_context_key; diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/src/native_impl.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/src/native_impl.c new file mode 100644 index 00000000000..1254b4a2291 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/src/native_impl.c @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2023 Midokura Japan KK. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "wasm_export.h" +#include "my_context.h" + +int32_t +add_native(wasm_exec_env_t exec_env, int32_t n) +{ + wasm_module_inst_t inst = wasm_runtime_get_module_inst(exec_env); + struct my_context *ctx = wasm_runtime_get_context(inst, my_context_key); + return n + ctx->x; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/wasm-apps/testapp.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/wasm-apps/testapp.c new file mode 100644 index 00000000000..1774dcd070b --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/inst-context/wasm-apps/testapp.c @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include +#include +#include +#include + +int32_t +add_native(int32_t n); + +int32_t +calculate(int32_t n) +{ + printf("calling into WASM function: %s\n", __FUNCTION__); + return add_native(n); +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/LICENCE.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/LICENCE.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/LICENCE.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/LICENCE.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/build.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/build.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/lv_config/lv_conf.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/lv_config/lv_conf.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/lv_config/lv_conf.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/lv_config/lv_conf.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/lv_config/lv_drv_conf.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/lv_config/lv_drv_conf.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/lv_config/lv_drv_conf.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/lv_config/lv_drv_conf.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt.in b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt.in similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt.in rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-native-ui-app/CMakeLists.txt.in diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-native-ui-app/lv-drivers/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-native-ui-app/lv-drivers/.gitignore similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-native-ui-app/lv-drivers/.gitignore rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-native-ui-app/lv-drivers/.gitignore diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-native-ui-app/lv-drivers/display_indev.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-native-ui-app/lv-drivers/display_indev.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-native-ui-app/lv-drivers/display_indev.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-native-ui-app/lv-drivers/display_indev.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-native-ui-app/lv-drivers/indev/mouse.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-native-ui-app/lv-drivers/indev/mouse.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-native-ui-app/lv-drivers/indev/mouse.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-native-ui-app/lv-drivers/indev/mouse.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-native-ui-app/lv-drivers/indev/mouse.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-native-ui-app/lv-drivers/indev/mouse.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-native-ui-app/lv-drivers/indev/mouse.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-native-ui-app/lv-drivers/indev/mouse.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-native-ui-app/lv-drivers/linux_display_indev.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-native-ui-app/lv-drivers/linux_display_indev.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-native-ui-app/lv-drivers/linux_display_indev.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-native-ui-app/lv-drivers/linux_display_indev.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-native-ui-app/lv-drivers/system_header.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-native-ui-app/lv-drivers/system_header.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-native-ui-app/lv-drivers/system_header.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-native-ui-app/lv-drivers/system_header.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-native-ui-app/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-native-ui-app/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-native-ui-app/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-native-ui-app/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/display_indev.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/display_indev.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/display_indev.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/display_indev.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/display_indev.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/display_indev.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/display_indev.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/display_indev.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/iwasm_main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/iwasm_main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/iwasm_main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/iwasm_main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/mouse.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/mouse.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/mouse.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/mouse.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/LICENSE b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/LICENSE similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/LICENSE rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/LICENSE diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/XPT2046.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/board_config.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/board_config.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/board_config.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/board_config.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340_adafruit_1480.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340_adafruit_1480.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340_adafruit_1480.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_ili9340_adafruit_1480.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_indev.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_indev.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_indev.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/display_indev.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/iwasm_main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/iwasm_main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/iwasm_main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/iwasm_main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/pin_config_jlf.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/pin_config_jlf.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/pin_config_jlf.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/pin_config_jlf.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/pin_config_stm32.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/pin_config_stm32.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/pin_config_stm32.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/vgl-wasm-runtime/src/platform/zephyr/pin_config_stm32.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/wamr_config_littlevgl.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/wamr_config_littlevgl.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/wamr_config_littlevgl.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/wamr_config_littlevgl.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/wasm-apps/Makefile_wasm_app b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/wasm-apps/Makefile_wasm_app similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/wasm-apps/Makefile_wasm_app rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/wasm-apps/Makefile_wasm_app diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/wasm-apps/Makefile_wasm_app_no_wasi b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/wasm-apps/Makefile_wasm_app_no_wasi similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/wasm-apps/Makefile_wasm_app_no_wasi rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/wasm-apps/Makefile_wasm_app_no_wasi diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/wasm-apps/build_wasm_app.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/wasm-apps/build_wasm_app.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/wasm-apps/build_wasm_app.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/wasm-apps/build_wasm_app.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/wasm-apps/src/display_indev.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/wasm-apps/src/display_indev.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/wasm-apps/src/display_indev.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/wasm-apps/src/display_indev.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/wasm-apps/src/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/wasm-apps/src/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/wasm-apps/src/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/wasm-apps/src/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/wasm-apps/src/system_header.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/wasm-apps/src/system_header.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/littlevgl/wasm-apps/src/system_header.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/littlevgl/wasm-apps/src/system_header.h diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/mem-allocator/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/mem-allocator/CMakeLists.txt new file mode 100644 index 00000000000..f157dfbde5c --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/mem-allocator/CMakeLists.txt @@ -0,0 +1,22 @@ +# Copyright (C) 2023 Midokura Japan KK. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +cmake_minimum_required(VERSION 3.0) +project(mem_allocator_create) + +string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) +if(APPLE) + add_definitions(-DBH_PLATFORM_DARWIN) +endif() + +set(WAMR_BUILD_INTERP 1) +set(WAMR_BUILD_LIBC_BUILTIN 0) + +set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../..) +include(${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) + +add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE}) + +add_executable(mem_alloc_test main.c) + +target_link_libraries(mem_alloc_test vmlib -lm -lpthread) diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/mem-allocator/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/mem-allocator/main.c new file mode 100644 index 00000000000..a309d2e62e4 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/mem-allocator/main.c @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2023 Midokura Japan KK. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include +#include +#include + +#include "mem_alloc.h" + +char store[1000]; + +int +main(int argc, char **argv) +{ + mem_allocator_t a = mem_allocator_create(store, sizeof(store)); + uint8_t *p; + uint8_t *p2; + + p = mem_allocator_malloc(a, 256); + printf("%p\n", p); + if (p == NULL) { + exit(1); + } + p = mem_allocator_realloc(a, p, 256 + 12); + printf("%p\n", p); + if (p == NULL) { + exit(1); + } + + /* + * write some values to confuse the ems allocator. + * + * hmu = p + 256 + * hmu_set_ut(hmu, HMU_FC) + * hmu_set_size(hmu, 256) + * hmu_set_free_size(hmu) + */ + *(uint32_t *)(p + 256) = (1 << 30) | 0x20; + *(uint32_t *)(p + 256 + 12 - 4) = 12; + + p2 = mem_allocator_malloc(a, 256); + printf("%p\n", p2); + if (p2 == NULL) { + exit(1); + } + mem_allocator_free(a, p2); + + p2 = mem_allocator_malloc(a, 256); + printf("%p\n", p2); + if (p2 == NULL) { + exit(1); + } + mem_allocator_free(a, p2); + + mem_allocator_free(a, p); +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-module/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/CMakeLists.txt similarity index 81% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-module/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/CMakeLists.txt index 2769b97796a..ee6c98df469 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-module/CMakeLists.txt +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/CMakeLists.txt @@ -43,8 +43,12 @@ if (NOT CMAKE_BUILD_TYPE) endif () set(WAMR_BUILD_INTERP 1) -set(WAMR_BUILD_AOT 0) -set(WAMR_BUILD_JIT 0) +if (NOT DEFINED WAMR_BUILD_AOT) + set(WAMR_BUILD_AOT 0) +endif () +if (NOT DEFINED WAMR_BUILD_JIT) + set(WAMR_BUILD_JIT 0) +endif () set(WAMR_BUILD_LIBC_BUILTIN 1) set(WAMR_BUILD_LIBC_WASI 1) set(WAMR_BUILD_MULTI_MODULE 1) @@ -144,6 +148,43 @@ ExternalProject_Add(WASM_MODULE ./mE.wasm ${CMAKE_BINARY_DIR} ) +################ WASM MODULES TO AOT +if (WAMR_BUILD_AOT EQUAL 1) + set(WAMR_COMPILER_DIR ${CMAKE_CURRENT_LIST_DIR}/../../wamr-compiler/build) + message(CHECK_START "Detecting WAMR_COMPILER at ${WAMR_COMPILER_DIR}") + find_file(WAMR_COMPILER + wamrc + PATHS "${CMAKE_CURRENT_LIST_DIR}/../../wamr-compiler/build" + NO_DEFAULT_PATH + NO_CMAKE_FIND_ROOT_PATH + ) + if(WAMR_COMPILER) + message(CHECK_PASS "found") + else() + message(CHECK_FAIL "not found") + endif() + if((NOT EXISTS ${WAMR_COMPILER}) ) + message(FATAL_ERROR "Please build wamrc under the path=${WAMR_ROOT_DIR}/wamr-compiler/ ") + else() + message(STATUS "WAMR_COMPILER is ${WAMR_COMPILER}") + endif() + + add_custom_target( + wasm_to_aot + ALL + DEPENDS + WASM_MODULE ${WAMR_COMPILER} + COMMAND + ${WAMR_COMPILER} -o mA.aot ./mA.wasm + COMMAND + ${WAMR_COMPILER} -o mB.aot ./mB.wasm + COMMAND + ${WAMR_COMPILER} -o mC.aot ./mC.wasm + WORKING_DIRECTORY + ${CMAKE_BINARY_DIR} + ) +endif() + ################ NATIVE include_directories(${CMAKE_CURRENT_LIST_DIR}/src) include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/README.md new file mode 100644 index 00000000000..731ba62c241 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/README.md @@ -0,0 +1,20 @@ +# WAMR MULTI-MODUEL SAMPLE +**WAMR supports *multi-module* in both *interpreter* mode and *aot* mode.** + +Multi-modules will determine the running mode based on the type of the main module. + + +``` shell +$ mkdir build +$ cd build +$ cmake .. +$ make +$ # It will build multi_module runtime and +$ # wasm file under the ./build . +$ # If you have built wamrc, +$ # aot file will also genrate. +$ ./multi_module mC.wasm +$ ... +$ ./multi_module mC.aot +$ ... + diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-module/src/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/src/main.c similarity index 78% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-module/src/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/src/main.c index ca95ded5fab..c63cf6b8c2b 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-module/src/main.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/src/main.c @@ -1,59 +1,64 @@ #include #include #include - #include "bh_read_file.h" #include "platform_common.h" #include "wasm_export.h" -static char * -build_module_path(const char *module_name) +#if WASM_ENABLE_MULTI_MODULE != 0 +static char *module_search_path = "."; +static bool +module_reader_callback(package_type_t module_type, const char *module_name, + uint8 **p_buffer, uint32 *p_size) { - const char *module_search_path = "."; - const char *format = "%s/%s.wasm"; + char *file_format = NULL; +#if WASM_ENABLE_INTERP != 0 + if (module_type == Wasm_Module_Bytecode) + file_format = ".wasm"; +#endif +#if WASM_ENABLE_AOT != 0 + if (module_type == Wasm_Module_AoT) + file_format = ".aot"; + +#endif + bh_assert(file_format != NULL); + const char *format = "%s/%s%s"; int sz = strlen(module_search_path) + strlen("/") + strlen(module_name) - + strlen(".wasm") + 1; - char *wasm_file_name = BH_MALLOC(sz); + + strlen(file_format) + 1; + char *wasm_file_name = wasm_runtime_malloc(sz); if (!wasm_file_name) { - return NULL; - } - - snprintf(wasm_file_name, sz, format, module_search_path, module_name); - return wasm_file_name; -} - -static bool -module_reader_cb(const char *module_name, uint8 **p_buffer, uint32 *p_size) -{ - char *wasm_file_path = build_module_path(module_name); - if (!wasm_file_path) { return false; } + snprintf(wasm_file_name, sz, format, module_search_path, module_name, + file_format); + *p_buffer = (uint8_t *)bh_read_file_to_buffer(wasm_file_name, p_size); - printf("- bh_read_file_to_buffer %s\n", wasm_file_path); - *p_buffer = (uint8_t *)bh_read_file_to_buffer(wasm_file_path, p_size); - BH_FREE(wasm_file_path); + wasm_runtime_free(wasm_file_name); return *p_buffer != NULL; } static void -module_destroyer_cb(uint8 *buffer, uint32 size) +moudle_destroyer(uint8 *buffer, uint32 size) { - printf("- release the read file buffer\n"); if (!buffer) { return; } - BH_FREE(buffer); + wasm_runtime_free(buffer); buffer = NULL; } +#endif /* WASM_ENABLE_MULTI_MODULE */ /* 10M */ static char sandbox_memory_space[10 * 1024 * 1024] = { 0 }; int -main() +main(int argc, char *argv[]) { bool ret = false; + if (argc != 2) { + return -1; + } + char *wasm_file = argv[1]; /* 16K */ const uint32 stack_size = 16 * 1024; const uint32 heap_size = 16 * 1024; @@ -84,16 +89,16 @@ main() #if WASM_ENABLE_MULTI_MODULE != 0 printf("- wasm_runtime_set_module_reader\n"); /* set module reader and destroyer */ - wasm_runtime_set_module_reader(module_reader_cb, module_destroyer_cb); + wasm_runtime_set_module_reader(module_reader_callback, moudle_destroyer); #endif /* load WASM byte buffer from WASM bin file */ - if (!module_reader_cb("mC", &file_buf, &file_buf_size)) { + if (!(file_buf = + (uint8 *)bh_read_file_to_buffer(wasm_file, &file_buf_size))) goto RELEASE_RUNTIME; - } - /* load mC and let WAMR load mA and mB */ printf("- wasm_runtime_load\n"); + if (!(module = wasm_runtime_load(file_buf, file_buf_size, error_buf, sizeof(error_buf)))) { printf("%s\n", error_buf); @@ -158,7 +163,7 @@ main() printf("- wasm_runtime_unload\n"); wasm_runtime_unload(module); RELEASE_BINARY: - module_destroyer_cb(file_buf, file_buf_size); + moudle_destroyer(file_buf, file_buf_size); RELEASE_RUNTIME: printf("- wasm_runtime_destroy\n"); wasm_runtime_destroy(); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-module/wasm-apps/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/wasm-apps/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-module/wasm-apps/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/wasm-apps/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-module/wasm-apps/mA.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/wasm-apps/mA.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-module/wasm-apps/mA.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/wasm-apps/mA.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-module/wasm-apps/mB.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/wasm-apps/mB.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-module/wasm-apps/mB.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/wasm-apps/mB.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-module/wasm-apps/mC.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/wasm-apps/mC.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-module/wasm-apps/mC.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/wasm-apps/mC.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-module/wasm-apps/mD.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/wasm-apps/mD.cpp similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-module/wasm-apps/mD.cpp rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/wasm-apps/mD.cpp diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-module/wasm-apps/mE.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/wasm-apps/mE.cpp similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-module/wasm-apps/mE.cpp rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-module/wasm-apps/mE.cpp diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-thread/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-thread/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-thread/wasm-apps/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-thread/wasm-apps/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-thread/wasm-apps/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-thread/wasm-apps/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/main_global_atomic.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-thread/wasm-apps/main_global_atomic.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/main_global_atomic.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-thread/wasm-apps/main_global_atomic.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/main_thread_exception.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-thread/wasm-apps/main_thread_exception.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/main_thread_exception.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/multi-thread/wasm-apps/main_thread_exception.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/native-lib/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/native-lib/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/native-lib/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/native-lib/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/native-lib/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/native-lib/README.md similarity index 94% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/native-lib/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/native-lib/README.md index 2bf65814d36..80500ade0fd 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/native-lib/README.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/native-lib/README.md @@ -62,6 +62,7 @@ cd build The output is: ```bash +init_native_lib in test_hello2.c called Hello World! 10 + 20 = 30 sqrt(10, 20) = 500 @@ -72,5 +73,6 @@ Message from test_hello: Hello, main. This is test_hello_wrapper! test_hello2("main", 0x0, 0) = 85 malloc(86) = 0x24e8 test_hello2("main", 0x24e8, 86) = 85 -Message from test_hello2: Hello, main. This is test_hello2_wrapper! Your wasm_module_inst_t is 0x7fd443704990. +Message from test_hello2: Hello, main. This is test_hello2_wrapper! Your wasm_module_inst_t is 0x7fe0e6804280. +deinit_native_lib in test_hello2.c called ``` diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/native-lib/test_add.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/native-lib/test_add.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/native-lib/test_add.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/native-lib/test_add.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/native-lib/test_hello.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/native-lib/test_hello.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/native-lib/test_hello.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/native-lib/test_hello.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/native-lib/test_hello2.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/native-lib/test_hello2.c similarity index 90% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/native-lib/test_hello2.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/native-lib/test_hello2.c index 2c8f69ed6b5..5dae79ca486 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/native-lib/test_hello2.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/native-lib/test_hello2.c @@ -57,3 +57,16 @@ get_native_lib(char **p_module_name, NativeSymbol **p_native_symbols) *p_native_symbols = native_symbols; return sizeof(native_symbols) / sizeof(NativeSymbol); } + +int +init_native_lib() +{ + printf("%s in test_hello2.c called\n", __func__); + return 0; +} + +void +deinit_native_lib() +{ + printf("%s in test_hello2.c called\n", __func__); +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/native-lib/test_sqrt.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/native-lib/test_sqrt.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/native-lib/test_sqrt.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/native-lib/test_sqrt.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/native-lib/wasm-app/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/native-lib/wasm-app/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/native-lib/wasm-app/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/native-lib/wasm-app/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/native-lib/wasm-app/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/native-lib/wasm-app/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/native-lib/wasm-app/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/native-lib/wasm-app/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/ref-types/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/ref-types/CMakeLists.txt similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/ref-types/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/ref-types/CMakeLists.txt index 325699b2084..fd18e637808 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/ref-types/CMakeLists.txt +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/ref-types/CMakeLists.txt @@ -9,7 +9,6 @@ if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows") project(ref-types) else() project (ref-types C ASM) - enable_language (ASM_MASM) endif() ################ runtime settings ################ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/ref-types/src/hello.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/ref-types/src/hello.c similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/ref-types/src/hello.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/ref-types/src/hello.c index db2f7997fc1..0ee1aee88e1 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/ref-types/src/hello.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/ref-types/src/hello.c @@ -142,8 +142,8 @@ set_and_cmp(wasm_exec_env_t exec_env, wasm_module_inst_t inst, int32 i, wasm_set_externref(exec_env, inst, i, externref); local_set_externref(i, externref); - wasm_get_externref(exec_env, inst, 0, &wasm_externref); - if (!local_chk_externref(exec_env, 0, wasm_externref)) { + wasm_get_externref(exec_env, inst, i, &wasm_externref); + if (!local_chk_externref(exec_env, i, wasm_externref)) { printf("#%d, In host language world Wasm Externref 0x%lx Vs. Native " "Externref 0x%lx FAILED\n", i, wasm_externref, externref); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/ref-types/src/hello.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/ref-types/src/hello.wat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/ref-types/src/hello.wat rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/ref-types/src/hello.wat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/sgx-ra/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/sgx-ra/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/sgx-ra/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/sgx-ra/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/sgx-ra/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/sgx-ra/README.md similarity index 83% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/sgx-ra/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/sgx-ra/README.md index 39a2f2d9ca6..9270c96f163 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/sgx-ra/README.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/sgx-ra/README.md @@ -7,52 +7,52 @@ This sample demonstrates how to execute Remote Attestation on SGX with [librats] SGX-RA requires to have installed: - the WASI-SDK, located in `/opt/wasi-sdk` - - CMake >= 3.11, which is not provided on Ubuntu 18.04 (use [Kitware APT Repository](https://apt.kitware.com/)) ### Intel SGX dependencies Before starting, we need to download and install [SGX SDK](https://download.01.org/intel-sgx/latest/linux-latest/distro) and [SGX DCAP Library](https://download.01.org/intel-sgx/latest/dcap-latest) referring to this [guide](https://download.01.org/intel-sgx/sgx-dcap/1.8/linux/docs/Intel_SGX_DCAP_Linux_SW_Installation_Guide.pdf). -The following commands are an example of the SGX environment installation on Ubuntu 18.04. +The following commands are an example of the SGX environment installation on Ubuntu 20.04. ``` shell # Set your platform, you can get the platforms list on # https://download.01.org/intel-sgx/latest/linux-latest/distro $ cd $HOME -$ SGX_PLATFORM=ubuntu18.04-server -$ SGX_SDK_VERSION=2.17.100.3 +$ OS_PLATFORM=ubuntu20.04 +$ SGX_PLATFORM=$OS_PLATFORM-server +$ SGX_RELEASE_VERSION=1.17 $ SGX_DRIVER_VERSION=1.41 +$ SGX_SDK_VERSION=2.20.100.4 # install the dependencies $ sudo apt-get update -$ sudo apt-get install -y dkms +$ sudo apt-get install -y build-essential ocaml automake autoconf libtool wget python3 libssl-dev dkms zip cmake +$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1 # install SGX Driver -$ wget https://download.01.org/intel-sgx/latest/linux-latest/distro/$SGX_PLATFORM/sgx_linux_x64_driver_$SGX_DRIVER_VERSION.bin +$ wget https://download.01.org/intel-sgx/sgx-dcap/$SGX_RELEASE_VERSION/linux/distro/$SGX_PLATFORM/sgx_linux_x64_driver_$SGX_DRIVER_VERSION.bin $ chmod +x sgx_linux_x64_driver_$SGX_DRIVER_VERSION.bin $ sudo ./sgx_linux_x64_driver_$SGX_DRIVER_VERSION.bin # install SGX SDK -$ wget https://download.01.org/intel-sgx/latest/linux-latest/distro/$SGX_PLATFORM/sgx_linux_x64_sdk_$SGX_SDK_VERSION.bin +$ wget https://download.01.org/intel-sgx/sgx-dcap/$SGX_RELEASE_VERSION/linux/distro/$SGX_PLATFORM/sgx_linux_x64_sdk_$SGX_SDK_VERSION.bin $ chmod +x sgx_linux_x64_sdk_$SGX_SDK_VERSION.bin -$ sudo ./sgx_linux_x64_sdk_$SGX_SDK_VERSION.bin +$ sudo ./sgx_linux_x64_sdk_$SGX_SDK_VERSION.bin --prefix /opt/intel # install SGX DCAP Library -$ echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu bionic main' | sudo tee /etc/apt/sources.list.d/intel-sgx.list > /dev/null -$ wget -O - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | sudo apt-key add - +$ echo 'deb [arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu focal main' | sudo tee /etc/apt/sources.list.d/intel-sgx.list +$ wget -O - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | sudo apt-key add $ sudo apt-get update -$ sudo apt-get install -y libsgx-uae-service libsgx-dcap-default-qpl-dev libsgx-dcap-ql-dev libsgx-dcap-quote-verify-dev +$ sudo apt-get install -y libsgx-epid libsgx-quote-ex libsgx-dcap-ql libsgx-enclave-common-dev libsgx-dcap-ql-dev libsgx-dcap-default-qpl-dev libsgx-dcap-quote-verify-dev # install SGX SSL Library $ git clone https://github.com/intel/linux-sgx.git $ cd linux-sgx && make preparation -$ sudo cp external/toolset/{current_distr}/* /usr/local/bin +$ sudo cp external/toolset/$OS_PLATFORM/* /usr/local/bin $ # Verify that the paths are correctly set $ which ar as ld objcopy objdump ranlib $ cd ../ $ git clone https://github.com/intel/intel-sgx-ssl.git -$ wget https://www.openssl.org/source/openssl-1.1.1q.tar.gz -$ cp openssl-1.1.1q.tar.gz intel-sgx-ssl/openssl_source -$ rm -f openssl-1.1.1q.tar.gz +$ wget https://www.openssl.org/source/openssl-1.1.1v.tar.gz -O intel-sgx-ssl/openssl_source/openssl-1.1.1v.tar.gz $ cd intel-sgx-ssl/Linux $ source /opt/intel/sgxsdk/environment $ make all @@ -70,7 +70,7 @@ sudo usermod -a -G sgx_prv Intel DCAP connects to Intel PCS to download the attestation collateral for SGX-enabled machines. Intel provides a [quick install guide](https://www.intel.com/content/www/us/en/developer/articles/guide/intel-software-guard-extensions-data-center-attestation-primitives-quick-install-guide.html) to set up a simplified environment. -This section summarizes the commands to issue for setting up a working environment on Ubuntu 18.04. +This section summarizes the commands to issue for setting up a working environment on Ubuntu 20.04. ### Subscribe to Intel PCS Web services @@ -86,11 +86,9 @@ Intel provides an implementation of the cache mechanism. The following commands set up Intel PCCS. ```shell # install Node.js -$ curl -o setup.sh -sL https://deb.nodesource.com/setup_14.x -$ chmod a+x setup.sh -$ sudo ./setup.sh +$ curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt-get install -y nodejs # install PCCS software -$ sudo apt-get install -y cracklib-runtime sqlite3 python build-essential +$ sudo apt-get install -y cracklib-runtime $ sudo apt-get install -y sgx-dcap-pccs ``` @@ -160,9 +158,10 @@ Adapt the configuration file of `PCKIDRetrievalTool` located in `/opt/intel/sgx- Save your changes and run the provisioning tool. ```shell -$ PCKIDRetrievalTool -Intel(R) Software Guard Extensions PCK Cert ID Retrieval Tool Version 1.14.100.3 +$ sudo PCKIDRetrievalTool +Intel(R) Software Guard Extensions PCK Cert ID Retrieval Tool Version 1.17.100.4 +Registration status has been set to completed status. the data has been sent to cache server successfully and pckid_retrieval.csv has been generated successfully! ``` diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/sgx-ra/wasm-app/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/sgx-ra/wasm-app/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/sgx-ra/wasm-app/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/sgx-ra/wasm-app/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/sgx-ra/wasm-app/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/sgx-ra/wasm-app/main.c similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/sgx-ra/wasm-app/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/sgx-ra/wasm-app/main.c index 89c4144aa78..6f506e06a85 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/sgx-ra/wasm-app/main.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/sgx-ra/wasm-app/main.c @@ -106,7 +106,7 @@ main(int argc, char **argv) err: if (evidence_json) { - free(evidence_json); + librats_dispose_evidence_json(evidence_json); } if (evidence) { diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/.gitignore new file mode 100644 index 00000000000..0fa8a76bdaf --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/.gitignore @@ -0,0 +1 @@ +/out/ \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/CMakeLists.txt new file mode 100644 index 00000000000..c094b071c91 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/CMakeLists.txt @@ -0,0 +1,95 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +cmake_minimum_required (VERSION 3.14) + +include(CheckPIESupported) + +project (shared-module) + +set (CMAKE_CXX_STANDARD 17) + +################ runtime settings ################ +string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) +if (APPLE) + add_definitions(-DBH_PLATFORM_DARWIN) +endif () + +# Reset default linker flags +set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") +set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") + +# WAMR features switch + +# Set WAMR_BUILD_TARGET, currently values supported: +# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", +# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]" +if (NOT DEFINED WAMR_BUILD_TARGET) + if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)") + set (WAMR_BUILD_TARGET "AARCH64") + elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64") + set (WAMR_BUILD_TARGET "RISCV64") + elseif (CMAKE_SIZEOF_VOID_P EQUAL 8) + # Build as X86_64 by default in 64-bit platform + set (WAMR_BUILD_TARGET "X86_64") + elseif (CMAKE_SIZEOF_VOID_P EQUAL 4) + # Build as X86_32 by default in 32-bit platform + set (WAMR_BUILD_TARGET "X86_32") + else () + message(SEND_ERROR "Unsupported build target platform!") + endif () +endif () + +if (NOT CMAKE_BUILD_TYPE) + set (CMAKE_BUILD_TYPE Debug) +endif () + +set (WAMR_BUILD_INTERP 1) +set (WAMR_BUILD_AOT 1) +set (WAMR_BUILD_JIT 0) + +# fast interpreter +# set (WAMR_BUILD_FAST_INTERP 1) + +# fast-jit +# set (WAMR_BUILD_FAST_JIT 1) + +# llvm jit +# set (WAMR_BUILD_JIT 1) +# set (LLVM_DIR /usr/local/opt/llvm@14/lib/cmake/llvm) + +set (WAMR_BUILD_REF_TYPES 1) + +if (NOT MSVC) + # linker flags + if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) + set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") + endif () + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security") + if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64") + if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register") + endif () + endif () +endif () + +# build out vmlib +set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) +include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) + +add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE}) + +################ application related ################ +include_directories(${CMAKE_CURRENT_LIST_DIR}/src) +include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) + +add_executable (shared-module src/main.c ${UNCOMMON_SHARED_SOURCE}) + +check_pie_supported() +set_target_properties (shared-module PROPERTIES POSITION_INDEPENDENT_CODE ON) + +if (APPLE) + target_link_libraries (shared-module vmlib -lm -ldl -lpthread ${LLVM_AVAILABLE_LIBS}) +else () + target_link_libraries (shared-module vmlib -lm -ldl -lpthread -lrt ${LLVM_AVAILABLE_LIBS}) +endif () diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/README.md new file mode 100644 index 00000000000..14baa8cbf7a --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/README.md @@ -0,0 +1,5 @@ +The "shared-module" sample project +================================== + +This sample demonstrates a bug described in: +https://github.com/bytecodealliance/wasm-micro-runtime/issues/2735. diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/build.sh new file mode 100755 index 00000000000..9af5b3edd73 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/build.sh @@ -0,0 +1,63 @@ +# +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# + +#!/bin/bash + +CURR_DIR=$PWD +WAMR_DIR=${PWD}/../.. +OUT_DIR=${PWD}/out + +WASM_APPS=${PWD}/wasm-apps + + +rm -rf ${OUT_DIR} +mkdir ${OUT_DIR} +mkdir ${OUT_DIR}/wasm-apps + + +echo "##################### build shared-module project" +cd ${CURR_DIR} +mkdir -p cmake_build +cd cmake_build +cmake .. +make -j ${nproc} +if [ $? != 0 ];then + echo "BUILD_FAIL shared-module exit as $?\n" + exit 2 +fi + +cp -a shared-module ${OUT_DIR} + +printf "\n" + +echo "##################### build wasm apps" + +cd ${WASM_APPS} + +for i in `ls *.wat` +do +APP_SRC="$i" +OUT_FILE=${i%.*}.wasm + +# Note: the CI installs wabt in /opt/wabt +if type wat2wasm; then + WAT2WASM=${WAT2WASM:-wat2wasm} +elif [ -x /opt/wabt/bin/wat2wasm ]; then + WAT2WASM=${WAT2WASM:-/opt/wabt/bin/wat2wasm} +fi + +${WAT2WASM} -o ${OUT_DIR}/wasm-apps/${OUT_FILE} ${APP_SRC} + +# aot +# wamrc -o ${OUT_DIR}/wasm-apps/${OUT_FILE}.aot ${OUT_DIR}/wasm-apps/${OUT_FILE} +# mv ${OUT_DIR}/wasm-apps/${OUT_FILE}.aot ${OUT_DIR}/wasm-apps/${OUT_FILE} + +if [ -f ${OUT_DIR}/wasm-apps/${OUT_FILE} ]; then + echo "build ${OUT_FILE} success" +else + echo "build ${OUT_FILE} fail" +fi +done +echo "##################### build wasm apps done" diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/run.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/run.sh new file mode 100755 index 00000000000..3cb2e623e73 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +out/shared-module -f out/wasm-apps/testapp.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/src/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/src/main.c new file mode 100644 index 00000000000..ebea0c6bfdb --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/src/main.c @@ -0,0 +1,206 @@ + +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "wasm_export.h" +#include "bh_read_file.h" +#include "bh_getopt.h" + +void +print_usage(void) +{ + fprintf(stdout, "Options:\r\n"); + fprintf(stdout, " -f [path of wasm file] \n"); +} + +int +main(int argc, char *argv_main[]) +{ + int exit_code = 1; + static char global_heap_buf[512 * 1024]; + char *buffer; + char error_buf[128]; + int opt; + char *wasm_path = NULL; + + const unsigned int N = 4; + wasm_module_t module = NULL; + wasm_module_inst_t module_inst[N]; + wasm_exec_env_t exec_env[N]; + const char *name_test_data_drop = "test_data_drop"; + const char *name_test_elem_drop = "test_elem_drop"; + wasm_function_inst_t func_test_data_drop[N]; + wasm_function_inst_t func_test_elem_drop[N]; + unsigned int i; + unsigned int iter; + uint32 buf_size, stack_size = 8092, heap_size = 8092; + + for (i = 0; i < N; i++) { + module_inst[i] = NULL; + exec_env[i] = NULL; + func_test_data_drop[i] = NULL; + func_test_elem_drop[i] = NULL; + } + + RuntimeInitArgs init_args; + memset(&init_args, 0, sizeof(RuntimeInitArgs)); + + while ((opt = getopt(argc, argv_main, "hf:")) != -1) { + switch (opt) { + case 'f': + wasm_path = optarg; + break; + case 'h': + print_usage(); + return 0; + case '?': + print_usage(); + return 0; + } + } + if (optind == 1) { + print_usage(); + return 0; + } + + memset(&init_args, 0, sizeof(init_args)); + init_args.mem_alloc_type = Alloc_With_Pool; + init_args.mem_alloc_option.pool.heap_buf = global_heap_buf; + init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf); + + if (!wasm_runtime_full_init(&init_args)) { + printf("Init runtime environment failed.\n"); + return -1; + } + + buffer = bh_read_file_to_buffer(wasm_path, &buf_size); + + if (!buffer) { + printf("Open wasm app file [%s] failed.\n", wasm_path); + goto fail; + } + + module = wasm_runtime_load((uint8 *)buffer, buf_size, error_buf, + sizeof(error_buf)); + if (!module) { + printf("Load wasm module failed. error: %s\n", error_buf); + goto fail; + } + + for (i = 0; i < N; i++) { + module_inst[i] = wasm_runtime_instantiate(module, stack_size, heap_size, + error_buf, sizeof(error_buf)); + + if (!module_inst[i]) { + printf("Instantiate wasm module failed. error: %s\n", error_buf); + goto fail; + } + + exec_env[i] = wasm_runtime_create_exec_env(module_inst[i], stack_size); + if (!exec_env[i]) { + printf("Create wasm execution environment failed.\n"); + goto fail; + } + + func_test_data_drop[i] = wasm_runtime_lookup_function( + module_inst[i], name_test_data_drop, NULL); + if (!func_test_data_drop[i]) { + printf("The wasm function %s is not found.\n", name_test_data_drop); + goto fail; + } + + func_test_elem_drop[i] = wasm_runtime_lookup_function( + module_inst[i], name_test_elem_drop, NULL); + if (!func_test_elem_drop[i]) { + printf("The wasm function %s is not found.\n", name_test_elem_drop); + goto fail; + } + } + + for (iter = 0; iter < 2; iter++) { + /* + * as we drop data/table in the first iteration, + * the later iterations should trap. + */ + const bool should_trap = iter > 0; + + for (i = 0; i < N; i++) { + uint32_t argv[1] = {}; + if (wasm_runtime_call_wasm(exec_env[i], func_test_data_drop[i], 0, + argv)) { + uint32_t result = argv[0]; + printf( + "Native finished calling wasm function: %s, return: %x\n", + name_test_data_drop, result); + if (result != 0x64636261) { /* "abcd" */ + printf("unexpected return value\n"); + goto fail; + } + if (should_trap) { + printf("a trap is expected\n"); + goto fail; + } + } + else if (should_trap) { + printf("call wasm function %s failed as expected. error: %s\n", + name_test_data_drop, + wasm_runtime_get_exception(module_inst[i])); + } + else { + printf("call wasm function %s failed. error: %s\n", + name_test_data_drop, + wasm_runtime_get_exception(module_inst[i])); + goto fail; + } + } + + for (i = 0; i < N; i++) { + wasm_runtime_clear_exception(module_inst[i]); + + uint32_t argv[1] = {}; + if (wasm_runtime_call_wasm(exec_env[i], func_test_elem_drop[i], 0, + argv)) { + uint32_t result = argv[0]; + printf( + "Native finished calling wasm function: %s, return: %x\n", + name_test_elem_drop, result); + if (result != 0) { + printf("unexpected return value\n"); + goto fail; + } + if (should_trap) { + printf("a trap is expected\n"); + goto fail; + } + } + else if (should_trap) { + printf("call wasm function %s failed as expected. error: %s\n", + name_test_elem_drop, + wasm_runtime_get_exception(module_inst[i])); + } + else { + printf("call wasm function %s failed. error: %s\n", + name_test_elem_drop, + wasm_runtime_get_exception(module_inst[i])); + goto fail; + } + } + } + + exit_code = 0; +fail: + for (i = 0; i < N; i++) { + if (exec_env[i]) + wasm_runtime_destroy_exec_env(exec_env[i]); + if (module_inst[i]) + wasm_runtime_deinstantiate(module_inst[i]); + } + if (module) + wasm_runtime_unload(module); + if (buffer) + BH_FREE(buffer); + wasm_runtime_destroy(); + return exit_code; +} diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/wasm-apps/testapp.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/wasm-apps/testapp.wat new file mode 100644 index 00000000000..263a8703689 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/shared-module/wasm-apps/testapp.wat @@ -0,0 +1,22 @@ +;; Copyright (C) 2023 Midokura Japan KK. All rights reserved. +;; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +(module + (func (export "test_data_drop") (result i32) + (memory.init 0 (i32.const 0) (i32.const 0) (i32.const 4)) + data.drop 0 + (i32.load (i32.const 0)) + ) + (func (export "test_elem_drop") (result i32) + (table.init 0 (i32.const 0) (i32.const 0) (i32.const 4)) + elem.drop 0 + i32.const 3 + table.get 0 + ref.is_null + ) + (func $f) + (memory 1 1) + (table 4 4 funcref) + (data "abcd") + (elem func $f $f $f $f) +) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/.gitignore similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/.gitignore rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/.gitignore diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/build.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/build.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/profiles/arm-interp/toolchain.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/profiles/arm-interp/toolchain.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/profiles/arm-interp/toolchain.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/profiles/arm-interp/toolchain.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/profiles/arm-interp/wamr_config_simple.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/profiles/arm-interp/wamr_config_simple.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/profiles/arm-interp/wamr_config_simple.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/profiles/arm-interp/wamr_config_simple.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/profiles/arm64-aot/toolchain.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/profiles/arm64-aot/toolchain.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/profiles/arm64-aot/toolchain.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/profiles/arm64-aot/toolchain.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/profiles/arm64-aot/wamr_config_simple.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/profiles/arm64-aot/wamr_config_simple.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/profiles/arm64-aot/wamr_config_simple.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/profiles/arm64-aot/wamr_config_simple.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/profiles/arm64-interp/toolchain.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/profiles/arm64-interp/toolchain.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/profiles/arm64-interp/toolchain.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/profiles/arm64-interp/toolchain.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/profiles/arm64-interp/wamr_config_simple.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/profiles/arm64-interp/wamr_config_simple.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/profiles/arm64-interp/wamr_config_simple.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/profiles/arm64-interp/wamr_config_simple.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/profiles/host-aot/wamr_config_simple.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/profiles/host-aot/wamr_config_simple.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/profiles/host-aot/wamr_config_simple.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/profiles/host-aot/wamr_config_simple.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/profiles/host-interp/wamr_config_simple.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/profiles/host-interp/wamr_config_simple.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/profiles/host-interp/wamr_config_simple.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/profiles/host-interp/wamr_config_simple.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/profiles/macos-interp/wamr_config_simple.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/profiles/macos-interp/wamr_config_simple.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/profiles/macos-interp/wamr_config_simple.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/profiles/macos-interp/wamr_config_simple.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/sample_test_run.py b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/sample_test_run.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/sample_test_run.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/sample_test_run.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/src/iwasm_main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/src/iwasm_main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/src/iwasm_main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/src/iwasm_main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/src/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/src/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/src/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/src/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/wasm-apps/connection.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/wasm-apps/connection.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/wasm-apps/connection.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/wasm-apps/connection.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/wasm-apps/event_publisher.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/wasm-apps/event_publisher.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/wasm-apps/event_publisher.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/wasm-apps/event_publisher.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/wasm-apps/event_subscriber.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/wasm-apps/event_subscriber.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/wasm-apps/event_subscriber.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/wasm-apps/event_subscriber.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/wasm-apps/request_handler.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/wasm-apps/request_handler.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/wasm-apps/request_handler.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/wasm-apps/request_handler.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/wasm-apps/request_sender.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/wasm-apps/request_sender.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/wasm-apps/request_sender.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/wasm-apps/request_sender.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/wasm-apps/sensor.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/wasm-apps/sensor.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/wasm-apps/sensor.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/wasm-apps/sensor.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/wasm-apps/timer.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/wasm-apps/timer.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/simple/wasm-apps/timer.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/simple/wasm-apps/timer.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/sample_test_run.py b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/sample_test_run.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/sample_test_run.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/sample_test_run.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/addr_resolve.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/addr_resolve.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/addr_resolve.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/addr_resolve.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/inc/.gitkeep b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/inc/.gitkeep similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/inc/.gitkeep rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/inc/.gitkeep diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/multicast_client.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/multicast_client.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/multicast_client.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/multicast_client.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/multicast_server.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/multicast_server.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/multicast_server.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/multicast_server.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/send_recv.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/send_recv.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/send_recv.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/send_recv.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/socket_opts.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/socket_opts.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/socket_opts.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/socket_opts.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/socket_utils.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/socket_utils.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/socket_utils.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/socket_utils.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/tcp_client.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/tcp_client.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/tcp_client.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/tcp_client.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/tcp_server.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/tcp_server.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/tcp_server.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/tcp_server.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/timeout_client.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/timeout_client.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/timeout_client.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/timeout_client.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/timeout_server.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/timeout_server.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/timeout_server.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/timeout_server.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/udp_client.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/udp_client.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/udp_client.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/udp_client.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/udp_server.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/udp_server.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/socket-api/wasm-src/udp_server.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/socket-api/wasm-src/udp_server.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/spawn-thread/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/spawn-thread/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/spawn-thread/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/spawn-thread/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/spawn-thread/src/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/spawn-thread/src/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/spawn-thread/src/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/spawn-thread/src/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/spawn-thread/wasm-apps/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/spawn-thread/wasm-apps/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/spawn-thread/wasm-apps/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/spawn-thread/wasm-apps/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/spawn-thread/wasm-apps/sum.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/spawn-thread/wasm-apps/sum.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/spawn-thread/wasm-apps/sum.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/spawn-thread/wasm-apps/sum.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasi-threads/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasi-threads/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasi-threads/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasi-threads/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasi-threads/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasi-threads/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasi-threads/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasi-threads/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasi-threads/wasm-apps/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasi-threads/wasm-apps/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasi-threads/wasm-apps/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasi-threads/wasm-apps/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasi-threads/wasm-apps/no_pthread.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasi-threads/wasm-apps/no_pthread.c similarity index 88% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasi-threads/wasm-apps/no_pthread.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasi-threads/wasm-apps/no_pthread.c index dc3c9553023..16661bd830c 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasi-threads/wasm-apps/no_pthread.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasi-threads/wasm-apps/no_pthread.c @@ -50,16 +50,11 @@ main(int argc, char **argv) } thread_id = __wasi_thread_spawn(&data); - if (thread_id < 0) { - printf("Failed to create thread: %d\n", thread_id); - ret = EXIT_FAILURE; - goto final; - } + ASSERT_VALID_TID(thread_id); if (__builtin_wasm_memory_atomic_wait32(&data.th_ready, 0, SECOND) == 2) { printf("Timeout\n"); - ret = EXIT_FAILURE; - goto final; + return EXIT_FAILURE; } printf("Thread completed, new value: %d, thread id: %d\n", data.value, @@ -67,7 +62,6 @@ main(int argc, char **argv) assert(thread_id == data.thread_id); -final: start_args_deinit(&data.base); return ret; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasi-threads/wasm-apps/wasi_thread_start.S b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasi-threads/wasm-apps/wasi_thread_start.S similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasi-threads/wasm-apps/wasi_thread_start.S rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasi-threads/wasm-apps/wasi_thread_start.S diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasi-threads/wasm-apps/wasi_thread_start.h b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasi-threads/wasm-apps/wasi_thread_start.h similarity index 78% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasi-threads/wasm-apps/wasi_thread_start.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasi-threads/wasm-apps/wasi_thread_start.h index a46917d0a0d..2427fd2b9bc 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasi-threads/wasm-apps/wasi_thread_start.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasi-threads/wasm-apps/wasi_thread_start.h @@ -7,6 +7,10 @@ #define STACK_SIZE 32 * 1024 // same as the main stack +/* See https://github.com/WebAssembly/wasi-threads#design-choice-thread-ids */ +#define ASSERT_VALID_TID(TID) \ + assert(TID >= 1 && TID <= 0x1FFFFFFF && "Invalid thread ID") + typedef struct { void *stack; } start_args_t; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api-imports/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api-imports/.gitignore similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api-imports/.gitignore rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api-imports/.gitignore diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api-imports/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api-imports/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api-imports/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api-imports/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api-imports/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api-imports/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api-imports/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api-imports/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api-imports/host/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api-imports/host/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api-imports/host/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api-imports/host/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api-imports/host/example1.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api-imports/host/example1.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api-imports/host/example1.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api-imports/host/example1.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api-imports/wasm/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api-imports/wasm/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api-imports/wasm/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api-imports/wasm/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api-imports/wasm/inc/.gitkeep b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api-imports/wasm/inc/.gitkeep similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api-imports/wasm/inc/.gitkeep rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api-imports/wasm/inc/.gitkeep diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api-imports/wasm/send_recv.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api-imports/wasm/send_recv.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api-imports/wasm/send_recv.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api-imports/wasm/send_recv.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/CMakeLists.txt similarity index 92% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/CMakeLists.txt index c528fe16d6f..4189f728087 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/CMakeLists.txt +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/CMakeLists.txt @@ -9,14 +9,13 @@ if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows") project(c-api) else() project (c-api C ASM) - enable_language (ASM_MASM) endif() if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) ################ runtime settings ################ string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) @@ -87,15 +86,6 @@ endif() set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) -if (NOT DEFINED SANITIZER) - set(SANITIZER "") -elseif (SANITIZER STREQUAL "ubsan") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all -fno-sanitize=alignment" ) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined") -elseif (NOT (SANITIZER STREQUAL "") ) - message(SEND_ERROR "Unsupported sanitizer: ${SANITIZER}") -endif() - add_library(vmlib STATIC ${WAMR_RUNTIME_LIB_SOURCE}) if (MSVC) target_compile_definitions(vmlib PRIVATE WASM_API_EXTERN=) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/LICENSE b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/LICENSE similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/LICENSE rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/LICENSE diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/callback.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/callback.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/callback.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/callback.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/callback.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/callback.wat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/callback.wat rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/callback.wat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/callback_chain.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/callback_chain.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/callback_chain.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/callback_chain.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/callback_chain.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/callback_chain.wat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/callback_chain.wat rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/callback_chain.wat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/clone.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/clone.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/clone.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/clone.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/clone.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/clone.wat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/clone.wat rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/clone.wat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/empty_imports.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/empty_imports.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/empty_imports.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/empty_imports.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/empty_imports.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/empty_imports.wat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/empty_imports.wat rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/empty_imports.wat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/global.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/global.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/global.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/global.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/global.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/global.wat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/global.wat rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/global.wat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/globalexportimport-0.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/globalexportimport-0.wat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/globalexportimport-0.wat rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/globalexportimport-0.wat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/globalexportimport-1.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/globalexportimport-1.wat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/globalexportimport-1.wat rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/globalexportimport-1.wat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/globalexportimport.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/globalexportimport.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/globalexportimport.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/globalexportimport.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/hello.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/hello.c similarity index 95% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/hello.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/hello.c index 3ebea87b089..966e141d71e 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/hello.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/hello.c @@ -65,6 +65,12 @@ int main(int argc, const char* argv[]) { } fclose(file); + if (!wasm_module_validate(store, &binary)) { + printf("> Error validate module!\n"); + wasm_byte_vec_delete(&binary); + return 1; + } + // Compile. printf("Compiling module...\n"); own wasm_module_t* module = wasm_module_new(store, &binary); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/hello.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/hello.wat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/hello.wat rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/hello.wat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/hostref.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/hostref.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/hostref.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/hostref.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/hostref.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/hostref.wat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/hostref.wat rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/hostref.wat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/memory.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/memory.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/memory.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/memory.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/memory.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/memory.wat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/memory.wat rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/memory.wat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/multi.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/multi.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/multi.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/multi.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/multi.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/multi.wat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/multi.wat rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/multi.wat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/reflect.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/reflect.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/reflect.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/reflect.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/reflect.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/reflect.wat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/reflect.wat rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/reflect.wat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/serialize.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/serialize.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/serialize.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/serialize.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/serialize.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/serialize.wat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/serialize.wat rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/serialize.wat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/table.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/table.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/table.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/table.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/table.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/table.wat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/table.wat rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/table.wat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/threads.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/threads.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/threads.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/threads.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/threads.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/threads.wat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/threads.wat rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/threads.wat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/trap.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/trap.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/trap.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/trap.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/trap.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/trap.wat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/trap.wat rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/trap.wat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/utils/multi_module_utils.c b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/utils/multi_module_utils.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/wasm-c-api/src/utils/multi_module_utils.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/wasm-c-api/src/utils/multi_module_utils.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/XNNPACK/.gitignore similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/.gitignore rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/XNNPACK/.gitignore diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/XNNPACK/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/XNNPACK/CMakeLists.txt new file mode 100644 index 00000000000..41cdd583fba --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/XNNPACK/CMakeLists.txt @@ -0,0 +1,198 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +cmake_minimum_required (VERSION 3.14) + +project(xnnpack_wasm) + +################ EMCC ################ +include(ExternalProject) + +# grep xnnpack_benchmark -A 1 BUILD.bazel \ +# | grep "name =" \ +# | awk '{print $3}' \ +# | sed -e 's/\"//g; s/,//g; s/^/\"/g; s/$/\"/g' +list(APPEND NATIVE_BENCHMARKS + "qs8_dwconv_bench" + "qs8_f32_vcvt_bench" + "qs8_gemm_bench" + "qs8_requantization_bench" + "qs8_vadd_bench" + "qs8_vaddc_bench" + "qs8_vcvt_bench" + "qs16_qs8_vcvt_bench" + "qs8_vlrelu_bench" + "qs8_vmul_bench" + "qs8_vmulc_bench" + "qu8_f32_vcvt_bench" + "qu8_gemm_bench" + "qu8_requantization_bench" + "qu8_vadd_bench" + "qu8_vaddc_bench" + "qu8_vcvt_bench" + "qu8_vlrelu_bench" + "qu8_vmul_bench" + "qu8_vmulc_bench" + "bf16_gemm_bench" + "f16_f32acc_igemm_bench" + "f16_igemm_bench" + "f16_f32acc_gemm_bench" + "f16_gemm_bench" + "f16_raddstoreexpminusmax_bench" + "f16_spmm_bench" + "f16_vsigmoid_bench" + "f16_vtanh_bench" + "f16_f32_vcvt_bench" + "f32_igemm_bench" + "f32_conv_hwc_bench" + "f16_conv_hwc2chw_bench" + "f16_gavgpool_cw_bench" + "f32_gavgpool_cw_bench" + "f32_conv_hwc2chw_bench" + "f16_dwconv_bench" + "f32_dwconv_bench" + "f32_dwconv2d_chw_bench" + "f16_dwconv2d_chw_bench" + "f32_f16_vcvt_bench" + "xx_transpose_bench" + "x8_transpose_bench" + "x16_transpose_bench" + "x24_transpose_bench" + "x32_transpose_bench" + "x64_transpose_bench" + "f32_bgemm_bench" + "f32_gemm_bench" + "f32_qs8_vcvt_bench" + "f32_qu8_vcvt_bench" + "f32_raddexpminusmax_bench" + "f32_raddextexp_bench" + "f32_raddstoreexpminusmax_bench" + "f32_rmax_bench" + "f32_spmm_bench" + "f32_softmax_bench" + "f16_velu_bench" + "f32_velu_bench" + "f32_vhswish_bench" + "f32_vlrelu_bench" + "f32_vrelu_bench" + "f32_vscaleexpminusmax_bench" + "f32_vscaleextexp_bench" + "f32_vsigmoid_bench" + "f16_vsqrt_bench" + "f32_vsqrt_bench" + "f32_vtanh_bench" + "f32_im2col_gemm_bench" + "rounding_bench" + "s16_rmaxabs_bench" + "s16_window_bench" + "u32_filterbank_accumulate_bench" + "u32_filterbank_subtract_bench" + "u32_vlog_bench" + "u64_u32_vsqrtshift_bench" + "i16_vlshift_bench" + "cs16_vsquareabs_bench" + "cs16_bfly4_bench" + "cs16_fftr_bench" + "x8_lut_bench" + "x32_packw_bench" + "x16_packw_bench" + "abs_bench" + "average_pooling_bench" + "bankers_rounding_bench" + "ceiling_bench" + "channel_shuffle_bench" + "convert_bench" + "convolution_bench" + "deconvolution_bench" + "elu_bench" + "floor_bench" + "global_average_pooling_bench" + "hardswish_bench" + "leaky_relu_bench" + "max_pooling_bench" + "negate_bench" + "prelu_bench" + "sigmoid_bench" + "softmax_bench" + "square_bench" + "square_root_bench" + "tanh_bench" + "truncation_bench" + "f16_dwconv_e2e_bench" + "f16_gemm_e2e_bench" + "f32_dwconv_e2e_bench" + "f32_gemm_e2e_bench" + "qs8_dwconv_e2e_bench" + "qs8_gemm_e2e_bench" + "qu8_gemm_e2e_bench" + "qu8_dwconv_e2e_bench" + "end2end_bench" + "f16_exp_ulp_eval" + "f16_expminus_ulp_eval" + "f16_expm1minus_ulp_eval" + "f16_sigmoid_ulp_eval" + "f16_sqrt_ulp_eval" + "f16_tanh_ulp_eval" + "f32_exp_ulp_eval" + "f32_expminus_ulp_eval" + "f32_expm1minus_ulp_eval" + "f32_extexp_ulp_eval" + "f32_sigmoid_ulp_eval" + "f32_sqrt_ulp_eval" + "f32_tanh_ulp_eval" +) + +# Only Download +ExternalProject_Add(xnnpack-download + PREFIX xnnpack + GIT_REPOSITORY https://github.com/google/XNNPACK.git + GIT_TAG b9d4073a6913891ce9cbd8965c8d506075d2a45a + GIT_PROGRESS ON + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack + UPDATE_COMMAND "" + PATCH_COMMAND git apply ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack.patch + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) + +set(WAMRC "${CMAKE_CURRENT_SOURCE_DIR}/../../../wamr-compiler/build/wamrc") +if(EXISTS ${WAMRC}) + message("-- Will generate .aot") +else() + message("Will generate .wasm") +endif() + +foreach(BENCHMARK IN LISTS NATIVE_BENCHMARKS) + string(CONCAT WASM_BENCHMARK "//:" ${BENCHMARK} "-wasm") + string(CONCAT WASM_OUTPUT ${BENCHMARK} ".wasm") + + add_custom_command( + OUTPUT ${WASM_OUTPUT} + COMMAND bazel --output_user_root=build-user-output build -c opt --config=wasm ${WASM_BENCHMARK} + && ${CMAKE_COMMAND} -E copy_if_different ./bazel-bin/${WASM_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${WASM_OUTPUT} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/xnnpack + DEPENDS xnnpack-download + COMMENT "Generating ${WASM_OUTPUT} ..." + ) + + set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}/${WASM_OUTPUT}) + + if(EXISTS ${WAMRC}) + string(CONCAT AOT_OUTPUT ${BENCHMARK} ".aot") + + add_custom_command( + OUTPUT ${AOT_OUTPUT} + COMMAND ${WAMRC} -o ${AOT_OUTPUT} ${WASM_OUTPUT} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${WASM_OUTPUT} + COMMENT "Generating ${AOT_OUTPUT} ..." + ) + + add_custom_target(${BENCHMARK} ALL DEPENDS ${AOT_OUTPUT}) + else() + add_custom_target(${BENCHMARK} ALL DEPENDS ${WASM_OUTPUT}) + endif() +endforeach() + diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/XNNPACK/README.md similarity index 62% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/XNNPACK/README.md index 7984d9cee58..625ef7f79d0 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/README.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/XNNPACK/README.md @@ -9,17 +9,29 @@ please refer to [installation instructions](../README.md). ## Build XNNPACK -```bash -cd /samples/workload/XNNPACK -mkdir build -cd build +please build wamrc: + +``` bash +cd /wamr-compiler +./build_llvm.sh +mkdir build && cd build cmake .. +make +``` + +And then build xnnpack standalone wasm files + +```bash +$ cd /samples/workload/XNNPACK +$ cmake -S . -B build +$ cmake --build build ``` -The wasm files are generated under folder samples/workload/XNNPACK/xnnpack/bazel-bin. + +Generated .wasm(and .aot) files are under *samples/workload/XNNPACK/build*. ## Run benchmarks -Firstly please build iwasm with simd, libc-emcc and lib-pthread support: +Firstly please build iwasm with simd, libc-emcc and lib-pthread supporting: ``` bash $ cd /product-mini/platforms/linux/ @@ -28,21 +40,10 @@ $ cmake .. -DWAMR_BUILD_LIBC_EMCC=1 -DWAMR_BUILD_LIB_PTHREAD=1 $ make ``` -And please build wamrc: - -``` bash -cd /wamr-compiler -./build_llvm.sh -mkdir build && cd build -cmake .. -make -``` - -Then compile wasm file to aot file and run: +Then run: ``` shell -$ cd /samples/workload/XNNPACK/xnnpack/bazel-bin -$ wamrc -o average_pooling_bench.aot average_pooling_bench.wasm (or other wasm files) -$ iwasm average_pooling_bench.aot +$ cd /samples/workload/XNNPACK/build +$ iwasm average_pooling_bench.aot # (or other aot files) ``` diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/benchmark.patch b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/XNNPACK/benchmark.patch similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/XNNPACK/benchmark.patch rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/XNNPACK/benchmark.patch diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/XNNPACK/xnnpack.patch b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/XNNPACK/xnnpack.patch new file mode 100644 index 00000000000..d7680d3479a --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/XNNPACK/xnnpack.patch @@ -0,0 +1,138 @@ +diff --git a/.bazelrc b/.bazelrc +index fcaff1063..e61d53337 100644 +--- a/.bazelrc ++++ b/.bazelrc +@@ -1,6 +1,7 @@ + # Basic build settings + build --jobs 128 + build --cxxopt='-std=gnu++14' ++build --incompatible_enable_cc_toolchain_resolution + + # Sets the default Apple platform to macOS. + build --apple_platform_type=macos +@@ -55,3 +56,10 @@ build:macos --apple_platform_type=macos + + build:macos_arm64 --config=macos + build:macos_arm64 --cpu=darwin_arm64 ++ ++# Emscripten configs ++build:wasm --copt="-Wno-unused" ++build:wasm --copt="-Wno-unused-function" ++build:wasm --copt="-Wno-unused-but-set-variable" ++build:wasm --cpu=wasm ++build:wasm --features=wasm_simd +diff --git a/WORKSPACE b/WORKSPACE +index 2e568088b..3961371ca 100644 +--- a/WORKSPACE ++++ b/WORKSPACE +@@ -83,7 +83,23 @@ http_archive( + ) + + # Android NDK location and version is auto-detected from $ANDROID_NDK_HOME environment variable +-android_ndk_repository(name = "androidndk") ++# android_ndk_repository(name = "androidndk") + + # Android SDK location and API is auto-detected from $ANDROID_HOME environment variable +-android_sdk_repository(name = "androidsdk") ++# android_sdk_repository(name = "androidsdk") ++ ++http_archive( ++ name = "emsdk", ++ sha256 = "5fa6f5eb45a4d50264610c4c9e1c155535359b63bfaad69b4e5101d16c1e7e32", ++ strip_prefix = "emsdk-a896e3d066448b3530dbcaa48869fafefd738f57/bazel", ++ url = "https://github.com/emscripten-core/emsdk/archive/a896e3d066448b3530dbcaa48869fafefd738f57.tar.gz", ++) ++ ++load("@emsdk//:deps.bzl", emsdk_deps = "deps") ++emsdk_deps() ++ ++load("@emsdk//:emscripten_deps.bzl", emsdk_emscripten_deps = "emscripten_deps") ++emsdk_emscripten_deps(emscripten_version = "3.1.44") ++ ++load("@emsdk//:toolchains.bzl", "register_emscripten_toolchains") ++register_emscripten_toolchains() +diff --git a/bench/utils.cc b/bench/utils.cc +index 3b32503a7..656845336 100644 +--- a/bench/utils.cc ++++ b/bench/utils.cc +@@ -456,3 +456,13 @@ CodeMemoryHelper::~CodeMemoryHelper() { + + } // namespace utils + } // namespace benchmark ++ ++ ++extern "C" ++__attribute__((import_module("env"), import_name("getentropy"))) int import_getentropy(void* buffer, size_t length); ++ ++extern "C" ++int getentropy(void* buffer, size_t length) ++{ ++ return import_getentropy(buffer, length); ++} +diff --git a/build_defs.bzl b/build_defs.bzl +index 01b436eb7..2738fd50a 100644 +--- a/build_defs.bzl ++++ b/build_defs.bzl +@@ -1,6 +1,7 @@ + """Build definitions and rules for XNNPACK.""" + +-load(":emscripten.bzl", "xnnpack_emscripten_benchmark_linkopts", "xnnpack_emscripten_deps", "xnnpack_emscripten_minimal_linkopts", "xnnpack_emscripten_test_linkopts") ++load(":emscripten.bzl", "xnnpack_emscripten_benchmark_linkopts", "xnnpack_emscripten_deps", "xnnpack_emscripten_minimal_linkopts", "xnnpack_emscripten_test_linkopts", "xnnpack_emscripten_standalone_benchmark_linkopts") ++load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary") + + def xnnpack_visibility(): + """Visibility of :XNNPACK target. +@@ -393,7 +394,8 @@ def xnnpack_benchmark(name, srcs, copts = [], deps = [], tags = []): + "//conditions:default": ["-Wno-unused-function"], + }) + copts, + linkopts = select({ +- ":emscripten": xnnpack_emscripten_benchmark_linkopts(), ++ ":emscripten": xnnpack_emscripten_standalone_benchmark_linkopts(), ++ ":emscripten_wasmsimd": xnnpack_emscripten_standalone_benchmark_linkopts(), + ":windows_x86_64_mingw": ["-lshlwapi"], + ":windows_x86_64_msys": ["-lshlwapi"], + "//conditions:default": [], +@@ -405,5 +407,16 @@ def xnnpack_benchmark(name, srcs, copts = [], deps = [], tags = []): + ":emscripten": xnnpack_emscripten_deps(), + "//conditions:default": [], + }), +- tags = tags, ++ tags = tags, ++ ) ++ ++ wasm_cc_binary( ++ name = name + "-wasm", ++ cc_target = ":" + name, ++ threads = "off", ++ simd = True, ++ standalone= True, ++ outputs = [ ++ name + ".wasm", ++ ] + ) +diff --git a/emscripten.bzl b/emscripten.bzl +index f1557a7b1..a3c4f93b9 100644 +--- a/emscripten.bzl ++++ b/emscripten.bzl +@@ -33,6 +33,21 @@ def xnnpack_emscripten_benchmark_linkopts(): + "--pre-js $(location :preamble.js.lds)", + ] + ++def xnnpack_emscripten_standalone_benchmark_linkopts(): ++ return [ ++ "-s ASSERTIONS=1", ++ "-s ERROR_ON_UNDEFINED_SYMBOLS=0", ++ "-s ALLOW_MEMORY_GROWTH=1", ++ "-s TOTAL_MEMORY=536870912", # 512M ++ "-s USE_PTHREADS=0", ++ "-s STANDALONE_WASM=1", ++ "-Wl,--export=__heap_base", ++ "-Wl,--export=__data_end", ++ "-Wl,--export=malloc", ++ "-Wl,--export=free", ++ ] ++ ++ + def xnnpack_emscripten_deps(): + """Emscripten-specific dependencies for unit tests and benchmarks.""" + return [ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/bwa/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/bwa/.gitignore similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/bwa/.gitignore rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/bwa/.gitignore diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/bwa/CMakeLists.bwa_wasm.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/bwa/CMakeLists.bwa_wasm.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/bwa/CMakeLists.bwa_wasm.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/bwa/CMakeLists.bwa_wasm.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/bwa/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/bwa/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/bwa/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/bwa/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/bwa/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/bwa/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/bwa/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/bwa/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/bwa/bwa.patch b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/bwa/bwa.patch similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/bwa/bwa.patch rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/bwa/bwa.patch diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/cmake/FindBinaryen.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/cmake/FindBinaryen.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/cmake/FindBinaryen.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/cmake/FindBinaryen.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/cmake/FindWASISDK.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/cmake/FindWASISDK.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/cmake/FindWASISDK.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/cmake/FindWASISDK.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/include/.gitkeep b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/include/.gitkeep similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/include/.gitkeep rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/include/.gitkeep diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/meshoptimizer/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/meshoptimizer/.gitignore similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/meshoptimizer/.gitignore rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/meshoptimizer/.gitignore diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/meshoptimizer/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/meshoptimizer/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/meshoptimizer/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/meshoptimizer/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/meshoptimizer/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/meshoptimizer/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/meshoptimizer/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/meshoptimizer/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/meshoptimizer/codecbench.patch b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/meshoptimizer/codecbench.patch similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/meshoptimizer/codecbench.patch rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/meshoptimizer/codecbench.patch diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/preparation.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/preparation.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/preparation.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/preparation.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/tensorflow/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/tensorflow/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/tensorflow/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/tensorflow/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/tensorflow/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/tensorflow/build.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/tensorflow/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/tensorflow/build.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/tensorflow/tf_lite.patch b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/tensorflow/tf_lite.patch similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/tensorflow/tf_lite.patch rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/tensorflow/tf_lite.patch diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/wasm-av1/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/wasm-av1/.gitignore similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/wasm-av1/.gitignore rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/wasm-av1/.gitignore diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/wasm-av1/CMakeLists.avx_wasm.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/wasm-av1/CMakeLists.avx_wasm.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/wasm-av1/CMakeLists.avx_wasm.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/wasm-av1/CMakeLists.avx_wasm.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/wasm-av1/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/wasm-av1/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/wasm-av1/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/wasm-av1/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/wasm-av1/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/wasm-av1/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/wasm-av1/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/wasm-av1/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/wasm-av1/av1-clang.patch b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/wasm-av1/av1-clang.patch similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/wasm-av1/av1-clang.patch rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/wasm-av1/av1-clang.patch diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/wasm-av1/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/wasm-av1/build.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/wasm-av1/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/wasm-av1/build.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/wasm-av1/wasm-av1.patch b/lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/wasm-av1/wasm-av1.patch similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/samples/workload/wasm-av1/wasm-av1.patch rename to lib/wasm-micro-runtime-WAMR-1.3.0/samples/workload/wasm-av1/wasm-av1.patch diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/.gitignore similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/.gitignore rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/.gitignore diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/docker-compose.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/docker-compose.yml similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/docker-compose.yml rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/docker-compose.yml diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/Dockerfile b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/Dockerfile similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/Dockerfile rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/Dockerfile diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/db.sqlite3 b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/db.sqlite3 similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/db.sqlite3 rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/db.sqlite3 diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/admin.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/admin.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/admin.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/admin.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/apps.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/apps.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/apps.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/apps.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/migrations/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/migrations/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/migrations/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/migrations/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/models.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/models.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/models.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/models.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/application.html b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/application.html similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/application.html rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/application.html diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/appstore.html b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/appstore.html similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/appstore.html rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/appstore.html diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/empty.html b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/empty.html similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/empty.html rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/empty.html diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/help.html b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/help.html similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/help.html rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/help.html diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/mysite.html b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/mysite.html similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/mysite.html rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/mysite.html diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/tests.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/tests.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/tests.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/tests.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/views.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/views.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/devices/views.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/devices/views.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/manage.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/manage.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/manage.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/manage.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/settings.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/settings.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/settings.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/settings.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/urls.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/urls.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/urls.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/urls.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/wsgi.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/wsgi.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/wsgi.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/mysite/wsgi.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/server/Dockerfile b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/server/Dockerfile similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/server/Dockerfile rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/server/Dockerfile diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/server/wasm_server.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/server/wasm_server.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/server/wasm_server.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/server/wasm_server.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/css/application.css b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/css/application.css similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/css/application.css rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/css/application.css diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/css/appstore.css b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/css/appstore.css similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/css/appstore.css rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/css/appstore.css diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/css/index.css b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/css/index.css similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/css/index.css rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/css/index.css diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/application.js b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/application.js similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/application.js rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/application.js diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/appstore.js b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/appstore.js similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/appstore.js rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/appstore.js diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/index.js b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/index.js similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/index.js rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/js/index.js diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/app(1).png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/app(1).png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/app(1).png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/app(1).png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/application.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/application.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/application.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/application.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/delete.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/delete.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/delete.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/delete.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/download(1).png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/download(1).png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/download(1).png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/download(1).png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/menu.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/menu.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/menu.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/menu.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/milky-way-2695569_1280.jpg b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/milky-way-2695569_1280.jpg similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/milky-way-2695569_1280.jpg rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/milky-way-2695569_1280.jpg diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/net_device.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/net_device.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/net_device.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/net_device.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/software-icon-32081.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/software-icon-32081.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/software-icon-32081.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/software-icon-32081.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/totalblack.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/totalblack.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/totalblack.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/photo/totalblack.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/connection.wasm b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/connection.wasm similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/connection.wasm rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/connection.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_publisher.wasm b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_publisher.wasm similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_publisher.wasm rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_publisher.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_subscriber.wasm b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_subscriber.wasm similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_subscriber.wasm rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_subscriber.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_handler.wasm b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_handler.wasm similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_handler.wasm rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_handler.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_sender.wasm b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_sender.wasm similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_sender.wasm rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_sender.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sensor.wasm b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sensor.wasm similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sensor.wasm rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sensor.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/simple b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/simple similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/simple rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/simple diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/connection.wasm b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/connection.wasm similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/connection.wasm rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/connection.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_publisher.wasm b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_publisher.wasm similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_publisher.wasm rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_publisher.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_subscriber.wasm b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_subscriber.wasm similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_subscriber.wasm rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_subscriber.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_handler.wasm b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_handler.wasm similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_handler.wasm rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_handler.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_sender.wasm b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_sender.wasm similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_sender.wasm rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_sender.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/timer.wasm b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/timer.wasm similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/timer.wasm rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/timer.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/timer.wasm b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/timer.wasm similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/timer.wasm rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/timer.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/ui_app.wasm b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/ui_app.wasm similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/ui_app.wasm rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/ui_app.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/wasm_runtime_wgl b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/wasm_runtime_wgl similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/wasm_runtime_wgl rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/wasm_runtime_wgl diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/binarydump-tool/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/binarydump-tool/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/binarydump-tool/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/binarydump-tool/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/binarydump-tool/binarydump.c b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/binarydump-tool/binarydump.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/binarydump-tool/binarydump.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/binarydump-tool/binarydump.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/framework/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/framework/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/framework/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/framework/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/framework/case_base.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/framework/case_base.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/framework/case_base.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/framework/case_base.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/framework/engine.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/framework/engine.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/framework/engine.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/framework/engine.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/framework/framework.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/framework/framework.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/framework/framework.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/framework/framework.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/framework/suite.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/framework/suite.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/framework/suite.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/framework/suite.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/framework/test_api.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/framework/test_api.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/framework/test_api.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/framework/test_api.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/framework/test_utils.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/framework/test_utils.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/framework/test_utils.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/framework/test_utils.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/harness/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/harness/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/harness/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/harness/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/harness/harness_api.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/harness/harness_api.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/harness/harness_api.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/harness/harness_api.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/host-clients/src/host_app_sample.c b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/host-clients/src/host_app_sample.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/host-clients/src/host_app_sample.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/host-clients/src/host_app_sample.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/host-clients/src/makefile b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/host-clients/src/makefile similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/host-clients/src/makefile rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/host-clients/src/makefile diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/set_dev_env.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/set_dev_env.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/set_dev_env.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/set_dev_env.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/start.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/start.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/start.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/start.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/01-install/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/01-install/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/01-install/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/01-install/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/01-install/case.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/01-install/case.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/01-install/case.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/01-install/case.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/02-request/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/02-request/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/02-request/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/02-request/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/02-request/case.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/02-request/case.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/02-request/case.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/02-request/case.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/03-event/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/03-event/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/03-event/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/03-event/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/03-event/case.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/03-event/case.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/03-event/case.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/03-event/case.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/04-request-internal/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/04-request-internal/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/04-request-internal/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/04-request-internal/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/04-request-internal/case.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/04-request-internal/case.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/04-request-internal/case.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/04-request-internal/case.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/05-event-internal/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/05-event-internal/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/05-event-internal/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/05-event-internal/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/05-event-internal/case.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/05-event-internal/case.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/05-event-internal/case.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/05-event-internal/case.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/06-timer/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/06-timer/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/06-timer/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/06-timer/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/06-timer/case.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/06-timer/case.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/06-timer/case.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/06-timer/case.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/07-sensor/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/07-sensor/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/07-sensor/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/07-sensor/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/07-sensor/case.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/07-sensor/case.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/07-sensor/case.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/07-sensor/case.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/08-on-destroy/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/08-on-destroy/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/08-on-destroy/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/08-on-destroy/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/08-on-destroy/case.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/08-on-destroy/case.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/08-on-destroy/case.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/08-on-destroy/case.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/cases/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/cases/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/suite_setup.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/suite_setup.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/suite_setup.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/suite_setup.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/01_install.c b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/01_install.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/01_install.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/01_install.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/02_request.c b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/02_request.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/02_request.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/02_request.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/03_event.c b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/03_event.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/03_event.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/03_event.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/04_request_internal_req.c b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/04_request_internal_req.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/04_request_internal_req.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/04_request_internal_req.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/04_request_internal_resp.c b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/04_request_internal_resp.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/04_request_internal_resp.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/04_request_internal_resp.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/05_event_internal_provider.c b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/05_event_internal_provider.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/05_event_internal_provider.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/05_event_internal_provider.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/05_event_internal_subscriber.c b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/05_event_internal_subscriber.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/05_event_internal_subscriber.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/05_event_internal_subscriber.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/06_timer.c b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/06_timer.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/06_timer.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/06_timer.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/07_sensor.c b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/07_sensor.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/07_sensor.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/07_sensor.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/08_on_destroy.c b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/08_on_destroy.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/08_on_destroy.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/08_on_destroy.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/build.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/test-app/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/test-app/build.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/tools/product/start.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/tools/product/start.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/tools/product/start.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/tools/product/start.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/tools/product/stop.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/tools/product/stop.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/01-life-cycle/tools/product/stop.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/01-life-cycle/tools/product/stop.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/__init__.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/__init__.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/__init__.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/__init__.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/readme.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/readme.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/component-test/suites/readme.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/component-test/suites/readme.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/external/cJSON/LICENSE b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/external/cJSON/LICENSE similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/external/cJSON/LICENSE rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/external/cJSON/LICENSE diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/external/cJSON/cJSON.c b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/external/cJSON/cJSON.c similarity index 87% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/external/cJSON/cJSON.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/external/cJSON/cJSON.c index 2e35351dbc0..830d2a346c6 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/external/cJSON/cJSON.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/external/cJSON/cJSON.c @@ -1,24 +1,24 @@ /* - Copyright (c) 2009-2017 Dave Gamble and cJSON contributors - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - */ + Copyright (c) 2009-2017 Dave Gamble and cJSON contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ /* cJSON */ /* JSON parser in C. */ @@ -43,6 +43,7 @@ #include #include #include +#include #ifdef ENABLE_LOCALES #include @@ -58,9 +59,33 @@ #include "cJSON.h" /* define our own boolean type */ +#ifdef true +#undef true +#endif #define true ((cJSON_bool)1) + +#ifdef false +#undef false +#endif #define false ((cJSON_bool)0) +/* define isnan and isinf for ANSI C, if in C99 or above, isnan and isinf has + * been defined in math.h */ +#ifndef isinf +#define isinf(d) (isnan((d - d)) && !isnan(d)) +#endif +#ifndef isnan +#define isnan(d) (d != d) +#endif + +#ifndef NAN +#ifdef _WIN32 +#define NAN sqrt(-1.0) +#else +#define NAN 0.0 / 0.0 +#endif +#endif + typedef struct { const unsigned char *json; size_t position; @@ -72,7 +97,7 @@ CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void) return (const char *)(global_error.json + global_error.position); } -CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item) +CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON *const item) { if (!cJSON_IsString(item)) { return NULL; @@ -81,18 +106,27 @@ CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item) return item->valuestring; } +CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON *const item) +{ + if (!cJSON_IsNumber(item)) { + return (double)NAN; + } + + return item->valuedouble; +} + /* This is a safeguard to prevent copy-pasters from using incompatible C and * header files */ #if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) \ - || (CJSON_VERSION_PATCH != 10) + || (CJSON_VERSION_PATCH != 16) #error cJSON.h and cJSON.c have different versions. Make sure that both have the same. #endif CJSON_PUBLIC(const char *) cJSON_Version(void) { static char version[15]; - snprintf(version, sizeof(version), "%i.%i.%i", CJSON_VERSION_MAJOR, - CJSON_VERSION_MINOR, CJSON_VERSION_PATCH); + sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, + CJSON_VERSION_PATCH); return version; } @@ -127,8 +161,8 @@ typedef struct internal_hooks { } internal_hooks; #if defined(_MSC_VER) -/* work around MSVC error C2322: '...' address of dillimport '...' - is not static */ +/* work around MSVC error C2322: '...' address of dllimport '...' is not static + */ static void *CJSON_CDECL internal_malloc(size_t size) { @@ -150,13 +184,11 @@ internal_realloc(void *pointer, size_t size) #define internal_realloc realloc #endif -/* clang-format off */ -static internal_hooks global_hooks = { - internal_malloc, - internal_free, - internal_realloc -}; -/* clang-format on */ +/* strlen of character literals resolved at compile time */ +#define static_strlen(string_literal) (sizeof(string_literal) - sizeof("")) + +static internal_hooks global_hooks = { internal_malloc, internal_free, + internal_realloc }; static unsigned char * cJSON_strdup(const unsigned char *string, const internal_hooks *const hooks) @@ -271,8 +303,8 @@ typedef struct { /* get a pointer to the buffer at the position */ #define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset) -/* Parse the input text to generate a number, and populate the result - into item. */ +/* Parse the input text to generate a number, and populate the result into item. + */ static cJSON_bool parse_number(cJSON *const item, parse_buffer *const input_buffer) { @@ -287,9 +319,8 @@ parse_number(cJSON *const item, parse_buffer *const input_buffer) } /* copy the number into a temporary buffer and replace '.' with the decimal - * point of the current locale (for strtod) - * This also takes care of '\0' not necessarily being available for marking - * the end of the input */ + * point of the current locale (for strtod) This also takes care of '\0' not + * necessarily being available for marking the end of the input */ for (i = 0; (i < (sizeof(number_c_string) - 1)) && can_access_at_index(input_buffer, i); i++) { @@ -363,6 +394,32 @@ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number) return object->valuedouble = number; } +CJSON_PUBLIC(char *) +cJSON_SetValuestring(cJSON *object, const char *valuestring) +{ + char *copy = NULL; + /* if object's type is not cJSON_String or is cJSON_IsReference, it should + * not set valuestring */ + if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference)) { + return NULL; + } + if (strlen(valuestring) <= strlen(object->valuestring)) { + strcpy(object->valuestring, valuestring); + return object->valuestring; + } + copy = + (char *)cJSON_strdup((const unsigned char *)valuestring, &global_hooks); + if (copy == NULL) { + return NULL; + } + if (object->valuestring != NULL) { + cJSON_free(object->valuestring); + } + object->valuestring = copy; + + return copy; +} + typedef struct { unsigned char *buffer; size_t length; @@ -438,9 +495,8 @@ ensure(printbuffer *const p, size_t needed) return NULL; } - if (newbuffer) { - memcpy(newbuffer, p->buffer, p->offset + 1); - } + + memcpy(newbuffer, p->buffer, p->offset + 1); p->hooks.deallocate(p->buffer); } p->length = newsize; @@ -463,6 +519,14 @@ update_offset(printbuffer *const buffer) buffer->offset += strlen((const char *)buffer_pointer); } +/* securely comparison of floating-point variables */ +static cJSON_bool +compare_double(double a, double b) +{ + double maxVal = fabs(a) > fabs(b) ? fabs(a) : fabs(b); + return (fabs(a - b) <= maxVal * DBL_EPSILON); +} + /* Render the number nicely from the given item into a string. */ static cJSON_bool print_number(const cJSON *const item, printbuffer *const output_buffer) @@ -471,35 +535,37 @@ print_number(const cJSON *const item, printbuffer *const output_buffer) double d = item->valuedouble; int length = 0; size_t i = 0; - unsigned char - number_buffer[26]; /* temporary buffer to print the number into */ + unsigned char number_buffer[26] = { + 0 + }; /* temporary buffer to print the number into */ unsigned char decimal_point = get_decimal_point(); - double test; + double test = 0.0; if (output_buffer == NULL) { return false; } /* This checks for NaN and Infinity */ - if ((d * 0) != 0) { - length = snprintf((char *)number_buffer, sizeof(number_buffer), "null"); + if (isnan(d) || isinf(d)) { + length = sprintf((char *)number_buffer, "null"); + } + else if (d == (double)item->valueint) { + length = sprintf((char *)number_buffer, "%d", item->valueint); } else { /* Try 15 decimal places of precision to avoid nonsignificant nonzero * digits */ - length = - snprintf((char *)number_buffer, sizeof(number_buffer), "%1.15g", d); + length = sprintf((char *)number_buffer, "%1.15g", d); /* Check whether the original double can be recovered */ if ((sscanf((char *)number_buffer, "%lg", &test) != 1) - || ((double)test != d)) { + || !compare_double((double)test, d)) { /* If not, print with 17 decimal places of precision */ - length = snprintf((char *)number_buffer, sizeof(number_buffer), - "%1.17g", d); + length = sprintf((char *)number_buffer, "%1.17g", d); } } - /* snprintf failed or buffer overrun occured */ + /* sprintf failed or buffer overrun occurred */ if ((length < 0) || (length > (int)(sizeof(number_buffer) - 1))) { return false; } @@ -709,8 +775,7 @@ parse_string(cJSON *const item, parse_buffer *const input_buffer) if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"')) { - goto fail; - /* string ended unexpectedly */ + goto fail; /* string ended unexpectedly */ } /* This is at most how much we need for the output */ @@ -719,8 +784,7 @@ parse_string(cJSON *const item, parse_buffer *const input_buffer) output = (unsigned char *)input_buffer->hooks.allocate(allocation_length + sizeof("")); if (output == NULL) { - goto fail; - /* allocation failure */ + goto fail; /* allocation failure */ } } @@ -759,7 +823,7 @@ parse_string(cJSON *const item, parse_buffer *const input_buffer) *output_pointer++ = input_pointer[1]; break; - /* UTF-16 literal */ + /* UTF-16 literal */ case 'u': sequence_length = utf16_literal_to_utf8( input_pointer, input_end, &output_pointer); @@ -805,7 +869,7 @@ print_string_ptr(const unsigned char *const input, printbuffer *const output_buffer) { const unsigned char *input_pointer = NULL; - unsigned char *output = NULL, *output_end; + unsigned char *output = NULL; unsigned char *output_pointer = NULL; size_t output_length = 0; /* numbers of additional characters needed for escaping */ @@ -853,7 +917,6 @@ print_string_ptr(const unsigned char *const input, if (output == NULL) { return false; } - output_end = output + output_length + sizeof("\"\""); /* no characters have to be escaped */ if (escape_characters == 0) { @@ -902,9 +965,7 @@ print_string_ptr(const unsigned char *const input, break; default: /* escape and print as unicode codepoint */ - snprintf((char *)output_pointer, - output_end - output_pointer, "u%04x", - *input_pointer); + sprintf((char *)output_pointer, "u%04x", *input_pointer); output_pointer += 4; break; } @@ -945,6 +1006,10 @@ buffer_skip_whitespace(parse_buffer *const buffer) return NULL; } + if (cannot_access_at_index(buffer, 0)) { + return buffer; + } + while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32)) { buffer->offset++; @@ -975,10 +1040,28 @@ skip_utf8_bom(parse_buffer *const buffer) return buffer; } -/* Parse an object - create a new root, and populate. */ CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) +{ + size_t buffer_length; + + if (NULL == value) { + return NULL; + } + + /* Adding null character size due to require_null_terminated. */ + buffer_length = strlen(value) + sizeof(""); + + return cJSON_ParseWithLengthOpts(value, buffer_length, return_parse_end, + require_null_terminated); +} + +/* Parse an object - create a new root, and populate. */ +CJSON_PUBLIC(cJSON *) +cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, + const char **return_parse_end, + cJSON_bool require_null_terminated) { parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } }; cJSON *item = NULL; @@ -987,12 +1070,12 @@ cJSON_ParseWithOpts(const char *value, const char **return_parse_end, global_error.json = NULL; global_error.position = 0; - if (value == NULL) { + if (value == NULL || 0 == buffer_length) { goto fail; } buffer.content = (const unsigned char *)value; - buffer.length = strlen((const char *)value) + sizeof(""); + buffer.length = buffer_length; buffer.offset = 0; buffer.hooks = global_hooks; @@ -1056,7 +1139,13 @@ CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) return cJSON_ParseWithOpts(value, 0, 0); } -#define cjson_min(a, b) ((a < b) ? a : b) +CJSON_PUBLIC(cJSON *) +cJSON_ParseWithLength(const char *value, size_t buffer_length) +{ + return cJSON_ParseWithLengthOpts(value, buffer_length, 0, 0); +} + +#define cjson_min(a, b) (((a) < (b)) ? (a) : (b)) static unsigned char * print(const cJSON *const item, cJSON_bool format, @@ -1113,6 +1202,10 @@ print(const cJSON *const item, cJSON_bool format, hooks->deallocate(buffer->buffer); } + if (printed != NULL) { + hooks->deallocate(printed); + } + return NULL; } @@ -1156,20 +1249,20 @@ cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) } CJSON_PUBLIC(cJSON_bool) -cJSON_PrintPreallocated(cJSON *item, char *buf, const int len, - const cJSON_bool fmt) +cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, + const cJSON_bool format) { printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; - if ((len < 0) || (buf == NULL)) { + if ((length < 0) || (buffer == NULL)) { return false; } - p.buffer = (unsigned char *)buf; - p.length = (size_t)len; + p.buffer = (unsigned char *)buffer; + p.length = (size_t)length; p.offset = 0; p.noalloc = true; - p.format = fmt; + p.format = format; p.hooks = global_hooks; return print_value(item, &p); @@ -1341,8 +1434,7 @@ parse_array(cJSON *const item, parse_buffer *const input_buffer) /* allocate next item */ cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); if (new_item == NULL) { - goto fail; - /* allocation failure */ + goto fail; /* allocation failure */ } /* attach next item to list */ @@ -1361,8 +1453,7 @@ parse_array(cJSON *const item, parse_buffer *const input_buffer) input_buffer->offset++; buffer_skip_whitespace(input_buffer); if (!parse_value(current_item, input_buffer)) { - goto fail; - /* failed to parse value */ + goto fail; /* failed to parse value */ } buffer_skip_whitespace(input_buffer); } while (can_access_at_index(input_buffer, 0) @@ -1370,13 +1461,16 @@ parse_array(cJSON *const item, parse_buffer *const input_buffer) if (cannot_access_at_index(input_buffer, 0) || buffer_at_offset(input_buffer)[0] != ']') { - goto fail; - /* expected end of array */ + goto fail; /* expected end of array */ } success: input_buffer->depth--; + if (head != NULL) { + head->prev = current_item; + } + item->type = cJSON_Array; item->child = head; @@ -1461,16 +1555,14 @@ parse_object(cJSON *const item, parse_buffer *const input_buffer) if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{')) { - goto fail; - /* not an object */ + goto fail; /* not an object */ } input_buffer->offset++; buffer_skip_whitespace(input_buffer); if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}')) { - goto success; - /* empty object */ + goto success; /* empty object */ } /* check if we skipped to the end of the buffer */ @@ -1486,8 +1578,7 @@ parse_object(cJSON *const item, parse_buffer *const input_buffer) /* allocate next item */ cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); if (new_item == NULL) { - goto fail; - /* allocation failure */ + goto fail; /* allocation failure */ } /* attach next item to list */ @@ -1506,8 +1597,7 @@ parse_object(cJSON *const item, parse_buffer *const input_buffer) input_buffer->offset++; buffer_skip_whitespace(input_buffer); if (!parse_string(current_item, input_buffer)) { - goto fail; - /* faile to parse name */ + goto fail; /* failed to parse name */ } buffer_skip_whitespace(input_buffer); @@ -1517,16 +1607,14 @@ parse_object(cJSON *const item, parse_buffer *const input_buffer) if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != ':')) { - goto fail; - /* invalid object */ + goto fail; /* invalid object */ } /* parse the value */ input_buffer->offset++; buffer_skip_whitespace(input_buffer); if (!parse_value(current_item, input_buffer)) { - goto fail; - /* failed to parse value */ + goto fail; /* failed to parse value */ } buffer_skip_whitespace(input_buffer); } while (can_access_at_index(input_buffer, 0) @@ -1534,13 +1622,16 @@ parse_object(cJSON *const item, parse_buffer *const input_buffer) if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '}')) { - goto fail; - /* expected end of object */ + goto fail; /* expected end of object */ } success: input_buffer->depth--; + if (head != NULL) { + head->prev = current_item; + } + item->type = cJSON_Object; item->child = head; @@ -1792,22 +1883,26 @@ add_item_to_array(cJSON *array, cJSON *item) { cJSON *child = NULL; - if ((item == NULL) || (array == NULL)) { + if ((item == NULL) || (array == NULL) || (array == item)) { return false; } child = array->child; - + /* + * To find the last item in array quickly, we use prev in array + */ if (child == NULL) { /* list is empty, start new one */ array->child = item; + item->prev = item; + item->next = NULL; } else { /* append to the end */ - while (child->next) { - child = child->next; + if (child->prev) { + suffix_object(child->prev, item); + array->child->prev = item; } - suffix_object(child, item); } return true; @@ -1847,7 +1942,8 @@ add_item_to_object(cJSON *const object, const char *const string, char *new_key = NULL; int new_type = cJSON_Invalid; - if ((object == NULL) || (string == NULL) || (item == NULL)) { + if ((object == NULL) || (string == NULL) || (item == NULL) + || (object == item)) { return false; } @@ -2028,7 +2124,7 @@ cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item) return NULL; } - if (item->prev != NULL) { + if (item != parent->child) { /* not the first element */ item->prev->next = item->next; } @@ -2041,6 +2137,11 @@ cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item) /* first element */ parent->child = item->next; } + else if (item->next == NULL) { + /* last element */ + parent->child->prev = item->prev; + } + /* make sure the detached item doesn't point anywhere anymore */ item->prev = NULL; item->next = NULL; @@ -2121,7 +2222,8 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, cJSON *replacement) { - if ((parent == NULL) || (replacement == NULL) || (item == NULL)) { + if ((parent == NULL) || (parent->child == NULL) || (replacement == NULL) + || (item == NULL)) { return false; } @@ -2135,12 +2237,24 @@ cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, if (replacement->next != NULL) { replacement->next->prev = replacement; } - if (replacement->prev != NULL) { - replacement->prev->next = replacement; - } if (parent->child == item) { + if (parent->child->prev == parent->child) { + replacement->prev = replacement; + } parent->child = replacement; } + else { /* + * To find the last item in array quickly, we use prev in array. + * We can't modify the last item's next pointer where this item was + * the parent's child + */ + if (replacement->prev != NULL) { + replacement->prev->next = replacement; + } + if (replacement->next == NULL) { + parent->child->prev = replacement; + } + } item->next = NULL; item->prev = NULL; @@ -2149,15 +2263,15 @@ cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, return true; } -CJSON_PUBLIC(void) +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) { if (which < 0) { - return; + return false; } - cJSON_ReplaceItemViaPointer(array, get_array_item(array, (size_t)which), - newitem); + return cJSON_ReplaceItemViaPointer( + array, get_array_item(array, (size_t)which), newitem); } static cJSON_bool @@ -2175,25 +2289,27 @@ replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, } replacement->string = (char *)cJSON_strdup((const unsigned char *)string, &global_hooks); + if (replacement->string == NULL) { + return false; + } + replacement->type &= ~cJSON_StringIsConst; - cJSON_ReplaceItemViaPointer( + return cJSON_ReplaceItemViaPointer( object, get_object_item(object, string, case_sensitive), replacement); - - return true; } -CJSON_PUBLIC(void) +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) { - replace_item_in_object(object, string, newitem, false); + return replace_item_in_object(object, string, newitem, false); } -CJSON_PUBLIC(void) +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem) { - replace_item_in_object(object, string, newitem, true); + return replace_item_in_object(object, string, newitem, true); } /* Create basic types: */ @@ -2227,11 +2343,11 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool b) +CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean) { cJSON *item = cJSON_New_Item(&global_hooks); if (item) { - item->type = b ? cJSON_True : cJSON_False; + item->type = boolean ? cJSON_True : cJSON_False; } return item; @@ -2357,6 +2473,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) } a = cJSON_CreateArray(); + for (i = 0; a && (i < (size_t)count); i++) { n = cJSON_CreateNumber(numbers[i]); if (!n) { @@ -2372,6 +2489,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) p = n; } + if (a && a->child) { + a->child->prev = n; + } + return a; } @@ -2403,6 +2524,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) p = n; } + if (a && a->child) { + a->child->prev = n; + } + return a; } @@ -2434,10 +2559,15 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) p = n; } + if (a && a->child) { + a->child->prev = n; + } + return a; } -CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char **strings, int count) +CJSON_PUBLIC(cJSON *) +cJSON_CreateStringArray(const char *const *strings, int count) { size_t i = 0; cJSON *n = NULL; @@ -2465,6 +2595,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char **strings, int count) p = n; } + if (a && a->child) { + a->child->prev = n; + } + return a; } @@ -2532,6 +2666,9 @@ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) } child = child->next; } + if (newitem && newitem->child) { + newitem->child->prev = newchild; + } return newitem; @@ -2543,55 +2680,93 @@ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) return NULL; } -CJSON_PUBLIC(void) cJSON_Minify(char *json) +static void +skip_oneline_comment(char **input) { - unsigned char *into = (unsigned char *)json; + *input += static_strlen("//"); - if (json == NULL) { - return; + for (; (*input)[0] != '\0'; ++(*input)) { + if ((*input)[0] == '\n') { + *input += static_strlen("\n"); + return; + } } +} - while (*json) { - if (*json == ' ') { - json++; - } - else if (*json == '\t') { - /* Whitespace characters. */ - json++; - } - else if (*json == '\r') { - json++; +static void +skip_multiline_comment(char **input) +{ + *input += static_strlen("/*"); + + for (; (*input)[0] != '\0'; ++(*input)) { + if (((*input)[0] == '*') && ((*input)[1] == '/')) { + *input += static_strlen("*/"); + return; } - else if (*json == '\n') { - json++; + } +} + +static void +minify_string(char **input, char **output) +{ + (*output)[0] = (*input)[0]; + *input += static_strlen("\""); + *output += static_strlen("\""); + + for (; (*input)[0] != '\0'; (void)++(*input), ++(*output)) { + (*output)[0] = (*input)[0]; + + if ((*input)[0] == '\"') { + (*output)[0] = '\"'; + *input += static_strlen("\""); + *output += static_strlen("\""); + return; } - else if ((*json == '/') && (json[1] == '/')) { - /* double-slash comments, to end of line. */ - while (*json && (*json != '\n')) { - json++; - } + else if (((*input)[0] == '\\') && ((*input)[1] == '\"')) { + (*output)[1] = (*input)[1]; + *input += static_strlen("\""); + *output += static_strlen("\""); } - else if ((*json == '/') && (json[1] == '*')) { - /* multiline comments. */ - while (*json && !((*json == '*') && (json[1] == '/'))) { + } +} + +CJSON_PUBLIC(void) cJSON_Minify(char *json) +{ + char *into = json; + + if (json == NULL) { + return; + } + + while (json[0] != '\0') { + switch (json[0]) { + case ' ': + case '\t': + case '\r': + case '\n': json++; - } - json += 2; - } - else if (*json == '\"') { - /* string literals, which are \" sensitive. */ - *into++ = (unsigned char)*json++; - while (*json && (*json != '\"')) { - if (*json == '\\') { - *into++ = (unsigned char)*json++; + break; + + case '/': + if (json[1] == '/') { + skip_oneline_comment(&json); } - *into++ = (unsigned char)*json++; - } - *into++ = (unsigned char)*json++; - } - else { - /* All other characters. */ - *into++ = (unsigned char)*json++; + else if (json[1] == '*') { + skip_multiline_comment(&json); + } + else { + json++; + } + break; + + case '\"': + minify_string(&json, (char **)&into); + break; + + default: + into[0] = json[0]; + json++; + into++; } } @@ -2692,8 +2867,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON *const a, const cJSON *const b, const cJSON_bool case_sensitive) { - if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) - || cJSON_IsInvalid(a)) { + if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF))) { return false; } @@ -2726,7 +2900,7 @@ cJSON_Compare(const cJSON *const a, const cJSON *const b, return true; case cJSON_Number: - if (a->valuedouble == b->valuedouble) { + if (compare_double(a->valuedouble, b->valuedouble)) { return true; } return false; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/external/cJSON/cJSON.h b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/external/cJSON/cJSON.h similarity index 73% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/external/cJSON/cJSON.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/external/cJSON/cJSON.h index d437196a34f..2cafdcf5970 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/external/cJSON/cJSON.h +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/external/cJSON/cJSON.h @@ -1,24 +1,24 @@ /* - Copyright (c) 2009-2017 Dave Gamble and cJSON contributors - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - */ + Copyright (c) 2009-2017 Dave Gamble and cJSON contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ #ifndef cJSON__h #define cJSON__h @@ -35,30 +35,34 @@ extern "C" { #ifdef __WINDOWS__ -/** - * When compiling for windows, we specify a specific calling convention to avoid - * issues where we are being called from a project with a different default - * calling convention. For windows you have 3 define options: - * CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever - * dllexport symbols - * CJSON_EXPORT_SYMBOLS - Define this on library build when you want to - * dllexport symbols (default) - * CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol - * - * For *nix builds that support visibility attribute, you can define similar - * behavior by setting default visibility to hidden by adding - * -fvisibility=hidden (for gcc) - * or - * -xldscope=hidden (for sun cc) - * to CFLAGS, then using the CJSON_API_VISIBILITY flag to "export" the same - * symbols the way CJSON_EXPORT_SYMBOLS does - */ +/* When compiling for windows, we specify a specific calling convention to avoid +issues where we are being called from a project with a different default calling +convention. For windows you have 3 define options: + +CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever +dllexport symbols CJSON_EXPORT_SYMBOLS - Define this on library build when you +want to dllexport symbols (default) CJSON_IMPORT_SYMBOLS - Define this if you +want to dllimport symbol + +For *nix builds that support visibility attribute, you can define similar +behavior by + +setting default visibility to hidden by adding +-fvisibility=hidden (for gcc) +or +-xldscope=hidden (for sun cc) +to CFLAGS + +then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way +CJSON_EXPORT_SYMBOLS does + +*/ #define CJSON_CDECL __cdecl #define CJSON_STDCALL __stdcall /* export symbols by default, this is necessary for copy pasting the C and - header file */ + * header file */ #if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) \ && !defined(CJSON_EXPORT_SYMBOLS) #define CJSON_EXPORT_SYMBOLS @@ -86,7 +90,7 @@ extern "C" { /* project version */ #define CJSON_VERSION_MAJOR 1 #define CJSON_VERSION_MINOR 7 -#define CJSON_VERSION_PATCH 10 +#define CJSON_VERSION_PATCH 16 #include @@ -107,11 +111,11 @@ extern "C" { /* The cJSON structure: */ typedef struct cJSON { /* next/prev allow you to walk array/object chains. Alternatively, use - GetArraySize/GetArrayItem/GetObjectItem */ + * GetArraySize/GetArrayItem/GetObjectItem */ struct cJSON *next; struct cJSON *prev; /* An array or object item will have a child pointer pointing to a chain of - the items in the array/object. */ + * the items in the array/object. */ struct cJSON *child; /* The type of the item, as above. */ @@ -125,7 +129,7 @@ typedef struct cJSON { double valuedouble; /* The item's name string, if this item is the child of, or is in the list - of subitems of an object. */ + * of subitems of an object. */ char *string; } cJSON; @@ -140,7 +144,7 @@ typedef struct cJSON_Hooks { typedef int cJSON_bool; /* Limits how deeply nested arrays/objects can be before cJSON rejects to parse - them. This is to prevent stack overflows. */ + * them. This is to prevent stack overflows. */ #ifndef CJSON_NESTING_LIMIT #define CJSON_NESTING_LIMIT 1000 #endif @@ -159,6 +163,8 @@ CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks *hooks); /* Supply a block of JSON, and this returns a cJSON object you can interrogate. */ CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); +CJSON_PUBLIC(cJSON *) +cJSON_ParseWithLength(const char *value, size_t buffer_length); /* ParseWithOpts allows you to require (and check) that the JSON is null * terminated, and to retrieve the pointer to the final byte parsed. */ /* If you supply a ptr in return_parse_end and parsing fails, then @@ -167,6 +173,10 @@ CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated); +CJSON_PUBLIC(cJSON *) +cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, + const char **return_parse_end, + cJSON_bool require_null_terminated); /* Render a cJSON entity to text for transfer/storage. */ CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item); @@ -185,7 +195,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format); /* Delete a cJSON entity and all subentities. */ -CJSON_PUBLIC(void) cJSON_Delete(cJSON *c); +CJSON_PUBLIC(void) cJSON_Delete(cJSON *item); /* Returns the number of items in an array (or object). */ CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array); @@ -205,8 +215,9 @@ cJSON_HasObjectItem(const cJSON *object, const char *string); * when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void); -/* Check if the item is a string and return its valuestring */ -CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item); +/* Check item type and return its value */ +CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON *const item); +CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON *const item); /* These functions check the type of an item */ CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON *const item); @@ -233,18 +244,21 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void); CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void); /* Create a string where valuestring references a string so - it will not be freed by cJSON_Delete */ + * it will not be freed by cJSON_Delete */ CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string); -/* Create an object/arrray that only references it's elements so - they will not be freed by cJSON_Delete */ +/* Create an object/array that only references it's elements so + * they will not be freed by cJSON_Delete */ CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child); CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child); -/* These utilities create an Array of count items. */ +/* These utilities create an Array of count items. + * The parameter count cannot be greater than the number of elements in the + * number array, otherwise array access will be out of bounds.*/ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count); CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count); CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count); -CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char **strings, int count); +CJSON_PUBLIC(cJSON *) +cJSON_CreateStringArray(const char *const *strings, int count); /* Append item to the specified array/object. */ CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item); @@ -264,7 +278,7 @@ cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); -/* Remove/Detatch items from Arrays/Objects. */ +/* Remove/Detach items from Arrays/Objects. */ CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item); CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which); @@ -286,32 +300,35 @@ cJSON_InsertItemInArray( CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, cJSON *replacement); -CJSON_PUBLIC(void) +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); -CJSON_PUBLIC(void) +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem); -CJSON_PUBLIC(void) +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem); /* Duplicate a cJSON item */ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); /* Duplicate will create a new, identical cJSON item to the one you pass, in new - memory that will need to be released. With recurse!=0, it will duplicate any - children connected to the item. The item->next and ->prev pointers are always - zero on return from Duplicate. */ + * memory that will need to be released. With recurse!=0, it will duplicate any + * children connected to the item. The item->next and ->prev pointers are always + * zero on return from Duplicate. */ /* Recursively compare two cJSON items for equality. If either a or b is NULL or - * invalid, they will be considered unequal. - * case_sensitive determines if object keys are treated case sensitive (1) or - * case insensitive (0) */ + * invalid, they will be considered unequal. case_sensitive determines if object + * keys are treated case sensitive (1) or case insensitive (0) */ CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON *const a, const cJSON *const b, const cJSON_bool case_sensitive); +/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from + * strings. The input pointer json cannot point to a read-only address area, + * such as a string constant, but should point to a readable and writable + * address area. */ CJSON_PUBLIC(void) cJSON_Minify(char *json); /* Helper functions for creating and adding items to an object at the same time. - They return the added item or NULL on failure. */ + * They return the added item or NULL on failure. */ CJSON_PUBLIC(cJSON *) cJSON_AddNullToObject(cJSON *const object, const char *const name); CJSON_PUBLIC(cJSON *) @@ -336,7 +353,7 @@ CJSON_PUBLIC(cJSON *) cJSON_AddArrayToObject(cJSON *const object, const char *const name); /* When assigning an integer value, it needs to be propagated to valuedouble - too. */ + * too. */ #define cJSON_SetIntValue(object, number) \ ((object) ? (object)->valueint = (object)->valuedouble = (number) \ : (number)) @@ -345,6 +362,18 @@ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); #define cJSON_SetNumberValue(object, number) \ ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) \ : (number)) +/* Change the valuestring of a cJSON_String object, only takes effect when type + * of object is cJSON_String */ +CJSON_PUBLIC(char *) +cJSON_SetValuestring(cJSON *object, const char *valuestring); + +/* If the object is not a boolean type this does nothing and returns + * cJSON_Invalid else it returns the new type*/ +#define cJSON_SetBoolValue(object, boolValue) \ + ((object != NULL && ((object)->type & (cJSON_False | cJSON_True))) \ + ? (object)->type = ((object)->type & (~(cJSON_False | cJSON_True))) \ + | ((boolValue) ? cJSON_True : cJSON_False) \ + : cJSON_Invalid) /* Macro for iterating over an array or object */ #define cJSON_ArrayForEach(element, array) \ @@ -352,7 +381,7 @@ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); element = element->next) /* malloc/free objects using the malloc/free functions that have been set with - cJSON_InitHooks */ + * cJSON_InitHooks */ CJSON_PUBLIC(void *) cJSON_malloc(size_t size); CJSON_PUBLIC(void) cJSON_free(void *object); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/external/cJSON/cjson.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/external/cJSON/cjson.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/external/cJSON/cjson.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/external/cJSON/cjson.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/src/host_tool_utils.c b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/src/host_tool_utils.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/src/host_tool_utils.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/src/host_tool_utils.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/src/host_tool_utils.h b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/src/host_tool_utils.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/src/host_tool_utils.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/src/host_tool_utils.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/src/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/src/main.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/src/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/src/main.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/src/transport.c b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/src/transport.c similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/src/transport.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/src/transport.c diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/src/transport.h b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/src/transport.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/host-tool/src/transport.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/host-tool/src/transport.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/pick-up-emscripten-headers/collect_files.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/pick-up-emscripten-headers/collect_files.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/pick-up-emscripten-headers/collect_files.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/pick-up-emscripten-headers/collect_files.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/.gitattributes b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/.gitattributes similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/.gitattributes rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/.gitattributes diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/Config_building_target.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/Config_building_target.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/Config_building_target.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/Config_building_target.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/build_folder.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/build_folder.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/build_folder.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/build_folder.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/build_terminal.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/build_terminal.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/build_terminal.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/build_terminal.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/change_workspace_dialog.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/change_workspace_dialog.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/change_workspace_dialog.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/change_workspace_dialog.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/compilation_config.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/compilation_config.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/compilation_config.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/compilation_config.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/compilation_config_2.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/compilation_config_2.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/compilation_config_2.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/compilation_config_2.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/debug.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/debug.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/debug.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/debug.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/decoration_for_files.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/decoration_for_files.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/decoration_for_files.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/decoration_for_files.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/docker_config.jpg b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/docker_config.jpg similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/docker_config.jpg rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/docker_config.jpg diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/docker_engine_config.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/docker_engine_config.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/docker_engine_config.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/docker_engine_config.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/docker_images.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/docker_images.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/docker_images.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/docker_images.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/install_from_vsix.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/install_from_vsix.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/install_from_vsix.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/install_from_vsix.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/new_project_page.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/new_project_page.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/new_project_page.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/new_project_page.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/open_project_page.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/open_project_page.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/open_project_page.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/open_project_page.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/project_template.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/project_template.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/project_template.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/project_template.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/right_click_menus_1.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/right_click_menus_1.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/right_click_menus_1.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/right_click_menus_1.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/right_click_menus_2.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/right_click_menus_2.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/right_click_menus_2.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/right_click_menus_2.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/run.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/run.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/run.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/run.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/save_configuration.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/save_configuration.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/save_configuration.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/save_configuration.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/set_up_workspace_message.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/set_up_workspace_message.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/set_up_workspace_message.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/set_up_workspace_message.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/wamr_ide_main_menu.png b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/wamr_ide_main_menu.png similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Media/wamr_ide_main_menu.png rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Media/wamr_ide_main_menu.png diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Script/build.bat b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Script/build.bat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Script/build.bat rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Script/build.bat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Script/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Script/build.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/Script/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/Script/build.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.eslintrc.json b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/.eslintrc.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.eslintrc.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/.eslintrc.json diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/.gitignore new file mode 100644 index 00000000000..782f2e467ec --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/.gitignore @@ -0,0 +1,12 @@ +out +dist +node_modules +.vscode-test/ +*.vsix +package-lock.json +.vscode +resource/debug/** +!resource/debug/darwin/.placeholder +!resource/debug/linux/.placeholder +!resource/debug/windows/.placeholder +resource/test/test.wasm \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/.npmrc b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/.npmrc new file mode 100644 index 00000000000..4fd021952d5 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/.npmrc @@ -0,0 +1 @@ +engine-strict=true \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.prettierrc.json b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/.prettierrc.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/.prettierrc.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/.prettierrc.json diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/.vscodeignore b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/.vscodeignore new file mode 100644 index 00000000000..2727ff52a58 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/.vscodeignore @@ -0,0 +1,19 @@ +.gitignore +.yarnrc + +.vscode/** +.vscode-test/** +out/test/** + +**/tsconfig.json +**/.eslintrc.json +**/*.map +**/*.ts + +src + +resource/test +resource/debug/** +!resource/debug/darwin/.placeholder +!resource/debug/linux/.placeholder +!resource/debug/windows/.placeholder \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/CONTRIBUTING.md b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/CONTRIBUTING.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/CONTRIBUTING.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/CONTRIBUTING.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/LICENSE b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/LICENSE similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/LICENSE rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/LICENSE diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/formatters/rust.py b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/formatters/rust.py new file mode 100644 index 00000000000..6fd5f168222 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/formatters/rust.py @@ -0,0 +1,747 @@ +''' +Copyright (c) 2016 Vadim Chugunov +SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +''' + +from __future__ import print_function, division +import sys +import logging +import lldb +import weakref + +if sys.version_info[0] == 2: + # python2-based LLDB accepts utf8-encoded ascii strings only. + def to_lldb_str(s): return s.encode('utf8', 'backslashreplace') if isinstance(s, unicode) else s + range = xrange +else: + to_lldb_str = str + +log = logging.getLogger(__name__) + +module = sys.modules[__name__] +rust_category = None + + +def initialize_category(debugger, internal_dict): + global module, rust_category + + rust_category = debugger.CreateCategory('Rust') + # rust_category.AddLanguage(lldb.eLanguageTypeRust) + rust_category.SetEnabled(True) + + attach_summary_to_type(tuple_summary_provider, r'^\(.*\)$', True) + attach_synthetic_to_type(MsvcTupleSynthProvider, r'^tuple\$?<.+>$', + True) # *-windows-msvc uses this name since 1.47 + + attach_synthetic_to_type(StrSliceSynthProvider, '&str') + attach_synthetic_to_type(StrSliceSynthProvider, 'str*') + attach_synthetic_to_type(StrSliceSynthProvider, 'str') # *-windows-msvc uses this name since 1.5? + + attach_synthetic_to_type(StdStringSynthProvider, '^(collections|alloc)::string::String$', True) + attach_synthetic_to_type(StdVectorSynthProvider, r'^(collections|alloc)::vec::Vec<.+>$', True) + attach_synthetic_to_type(StdVecDequeSynthProvider, + r'^(collections|alloc::collections)::vec_deque::VecDeque<.+>$', True) + + attach_synthetic_to_type(MsvcEnumSynthProvider, r'^enum\$<.+>$', True) + attach_synthetic_to_type(MsvcEnum2SynthProvider, r'^enum2\$<.+>$', True) + + attach_synthetic_to_type(SliceSynthProvider, r'^&(mut *)?\[.*\]$', True) + attach_synthetic_to_type(MsvcSliceSynthProvider, r'^(mut *)?slice\$?<.+>.*$', True) + + attach_synthetic_to_type(StdCStringSynthProvider, '^(std|alloc)::ffi::c_str::CString$', True) + attach_synthetic_to_type(StdCStrSynthProvider, '^&?(std|core)::ffi::c_str::CStr$', True) + + attach_synthetic_to_type(StdOsStringSynthProvider, 'std::ffi::os_str::OsString') + attach_synthetic_to_type(StdOsStrSynthProvider, '^&?std::ffi::os_str::OsStr', True) + + attach_synthetic_to_type(StdPathBufSynthProvider, 'std::path::PathBuf') + attach_synthetic_to_type(StdPathSynthProvider, '^&?std::path::Path', True) + + attach_synthetic_to_type(StdRcSynthProvider, r'^alloc::rc::Rc<.+>$', True) + attach_synthetic_to_type(StdRcSynthProvider, r'^alloc::rc::Weak<.+>$', True) + attach_synthetic_to_type(StdArcSynthProvider, r'^alloc::(sync|arc)::Arc<.+>$', True) + attach_synthetic_to_type(StdArcSynthProvider, r'^alloc::(sync|arc)::Weak<.+>$', True) + attach_synthetic_to_type(StdMutexSynthProvider, r'^std::sync::mutex::Mutex<.+>$', True) + + attach_synthetic_to_type(StdCellSynthProvider, r'^core::cell::Cell<.+>$', True) + attach_synthetic_to_type(StdRefCellSynthProvider, r'^core::cell::RefCell<.+>$', True) + attach_synthetic_to_type(StdRefCellBorrowSynthProvider, r'^core::cell::Ref<.+>$', True) + attach_synthetic_to_type(StdRefCellBorrowSynthProvider, r'^core::cell::RefMut<.+>$', True) + + attach_synthetic_to_type(StdHashMapSynthProvider, r'^std::collections::hash::map::HashMap<.+>$', True) + attach_synthetic_to_type(StdHashSetSynthProvider, r'^std::collections::hash::set::HashSet<.+>$', True) + + attach_synthetic_to_type(GenericEnumSynthProvider, r'^core::option::Option<.+>$', True) + attach_synthetic_to_type(GenericEnumSynthProvider, r'^core::result::Result<.+>$', True) + attach_synthetic_to_type(GenericEnumSynthProvider, r'^alloc::borrow::Cow<.+>$', True) + + if 'rust' in internal_dict.get('source_languages', []): + lldb.SBDebugger.SetInternalVariable('target.process.thread.step-avoid-regexp', + '^ +def read_unique_ptr(valobj): + pointer = valobj.GetChildMemberWithName('pointer') + if pointer.TypeIsPointerType(): # Between 1.33 and 1.63 pointer was just *const T + return pointer + return pointer.GetChildAtIndex(0) + + +def string_from_ptr(pointer, length): + if length <= 0: + return u'' + error = lldb.SBError() + process = pointer.GetProcess() + data = process.ReadMemory(pointer.GetValueAsUnsigned(), length, error) + if error.Success(): + return data.decode('utf8', 'replace') + else: + log.error('ReadMemory error: %s', error.GetCString()) + + +def get_template_params(type_name): + params = [] + level = 0 + start = 0 + for i, c in enumerate(type_name): + if c == '<': + level += 1 + if level == 1: + start = i + 1 + elif c == '>': + level -= 1 + if level == 0: + params.append(type_name[start:i].strip()) + elif c == ',' and level == 1: + params.append(type_name[start:i].strip()) + start = i + 1 + return params + + +def obj_summary(valobj, unavailable='{...}'): + summary = valobj.GetSummary() + if summary is not None: + return summary + summary = valobj.GetValue() + if summary is not None: + return summary + return unavailable + + +def sequence_summary(childern, maxsize=32): + s = '' + for child in childern: + if len(s) > 0: + s += ', ' + s += obj_summary(child) + if len(s) > maxsize: + s += ', ...' + break + return s + + +def tuple_summary(obj, skip_first=0): + fields = [obj_summary(obj.GetChildAtIndex(i)) for i in range(skip_first, obj.GetNumChildren())] + return '(%s)' % ', '.join(fields) + + +# ----- Summaries ----- + +def tuple_summary_provider(valobj, dict={}): + return tuple_summary(valobj) + + +# ----- Synth providers ------ + + +class RustSynthProvider(object): + synth_by_id = weakref.WeakValueDictionary() + next_id = 0 + + def __init__(self, valobj, dict={}): + self.valobj = valobj + self.obj_id = RustSynthProvider.next_id + RustSynthProvider.synth_by_id[self.obj_id] = self + RustSynthProvider.next_id += 1 + + def update(self): + return True + + def has_children(self): + return False + + def num_children(self): + return 0 + + def get_child_at_index(self, index): + return None + + def get_child_index(self, name): + if name == '$$object-id$$': + return self.obj_id + + try: + return self.get_index_of_child(name) + except Exception as e: + log.exception('%s', e) + raise + + def get_summary(self): + return None + + +class ArrayLikeSynthProvider(RustSynthProvider): + '''Base class for providers that represent array-like objects''' + + def update(self): + self.ptr, self.len = self.ptr_and_len(self.valobj) # type: ignore + self.item_type = self.ptr.GetType().GetPointeeType() + self.item_size = self.item_type.GetByteSize() + + def ptr_and_len(self, obj): + pass # abstract + + def num_children(self): + return self.len + + def has_children(self): + return True + + def get_child_at_index(self, index): + try: + if not 0 <= index < self.len: + return None + offset = index * self.item_size + return self.ptr.CreateChildAtOffset('[%s]' % index, offset, self.item_type) + except Exception as e: + log.exception('%s', e) + raise + + def get_index_of_child(self, name): + return int(name.lstrip('[').rstrip(']')) + + def get_summary(self): + return '(%d)' % (self.len,) + + +class StdVectorSynthProvider(ArrayLikeSynthProvider): + def ptr_and_len(self, vec): + return ( + read_unique_ptr(gcm(vec, 'buf', 'ptr')), + gcm(vec, 'len').GetValueAsUnsigned() + ) + + def get_summary(self): + return '(%d) vec![%s]' % (self.len, sequence_summary((self.get_child_at_index(i) for i in range(self.len)))) + + +class StdVecDequeSynthProvider(RustSynthProvider): + def update(self): + self.ptr = read_unique_ptr(gcm(self.valobj, 'buf', 'ptr')) + self.cap = gcm(self.valobj, 'buf', 'cap').GetValueAsUnsigned() + + head = gcm(self.valobj, 'head').GetValueAsUnsigned() + + # rust 1.67 changed from a head, tail implementation to a head, length impl + # https://github.com/rust-lang/rust/pull/102991 + vd_len = gcm(self.valobj, 'len') + if vd_len.IsValid(): + self.len = vd_len.GetValueAsUnsigned() + self.startptr = head + else: + tail = gcm(self.valobj, 'tail').GetValueAsUnsigned() + self.len = head - tail + self.startptr = tail + + self.item_type = self.ptr.GetType().GetPointeeType() + self.item_size = self.item_type.GetByteSize() + + def num_children(self): + return self.len + + def has_children(self): + return True + + def get_child_at_index(self, index): + try: + if not 0 <= index < self.num_children(): + return None + offset = ((self.startptr + index) % self.cap) * self.item_size + return self.ptr.CreateChildAtOffset('[%s]' % index, offset, self.item_type) + except Exception as e: + log.exception('%s', e) + raise + + def get_index_of_child(self, name): + return int(name.lstrip('[').rstrip(']')) + + def get_summary(self): + return '(%d) VecDeque[%s]' % (self.num_children(), sequence_summary((self.get_child_at_index(i) for i in range(self.num_children())))) + +################################################################################################################## + + +class SliceSynthProvider(ArrayLikeSynthProvider): + def ptr_and_len(self, vec): + return ( + gcm(vec, 'data_ptr'), + gcm(vec, 'length').GetValueAsUnsigned() + ) + + def get_summary(self): + return '(%d) &[%s]' % (self.len, sequence_summary((self.get_child_at_index(i) for i in range(self.len)))) + + +class MsvcSliceSynthProvider(SliceSynthProvider): + def get_type_name(self): + tparams = get_template_params(self.valobj.GetTypeName()) + return '&[' + tparams[0] + ']' + + +# Base class for *String providers +class StringLikeSynthProvider(ArrayLikeSynthProvider): + def get_child_at_index(self, index): + ch = ArrayLikeSynthProvider.get_child_at_index(self, index) + ch.SetFormat(lldb.eFormatChar) + return ch + + def get_summary(self): + # Limit string length to 1000 characters to cope with uninitialized values whose + # length field contains garbage. + strval = string_from_ptr(self.ptr, min(self.len, 1000)) + if strval == None: + return None + if self.len > 1000: + strval += u'...' + return u'"%s"' % strval + + +class StrSliceSynthProvider(StringLikeSynthProvider): + def ptr_and_len(self, valobj): + return ( + gcm(valobj, 'data_ptr'), + gcm(valobj, 'length').GetValueAsUnsigned() + ) + + +class StdStringSynthProvider(StringLikeSynthProvider): + def ptr_and_len(self, valobj): + vec = gcm(valobj, 'vec') + return ( + read_unique_ptr(gcm(vec, 'buf', 'ptr')), + gcm(vec, 'len').GetValueAsUnsigned() + ) + + +class StdCStringSynthProvider(StringLikeSynthProvider): + def ptr_and_len(self, valobj): + vec = gcm(valobj, 'inner') + return ( + gcm(vec, 'data_ptr'), + gcm(vec, 'length').GetValueAsUnsigned() - 1 + ) + + +class StdOsStringSynthProvider(StringLikeSynthProvider): + def ptr_and_len(self, valobj): + vec = gcm(valobj, 'inner', 'inner') + tmp = gcm(vec, 'bytes') # Windows OSString has an extra layer + if tmp.IsValid(): + vec = tmp + return ( + read_unique_ptr(gcm(vec, 'buf', 'ptr')), + gcm(vec, 'len').GetValueAsUnsigned() + ) + + +class FFISliceSynthProvider(StringLikeSynthProvider): + def ptr_and_len(self, valobj): + process = valobj.GetProcess() + slice_ptr = valobj.GetLoadAddress() + data_ptr_type = valobj.GetTarget().GetBasicType(lldb.eBasicTypeChar).GetPointerType() + # Unsized slice objects have incomplete debug info, so here we just assume standard slice + # reference layout: [, ] + error = lldb.SBError() + pointer = valobj.CreateValueFromAddress('data', slice_ptr, data_ptr_type) + length = process.ReadPointerFromMemory(slice_ptr + process.GetAddressByteSize(), error) + return pointer, length + + +class StdCStrSynthProvider(FFISliceSynthProvider): + def ptr_and_len(self, valobj): + ptr, len = FFISliceSynthProvider.ptr_and_len(self, valobj) + return (ptr, len-1) # drop terminaing '\0' + + +class StdOsStrSynthProvider(FFISliceSynthProvider): + pass + + +class StdPathBufSynthProvider(StdOsStringSynthProvider): + def ptr_and_len(self, valobj): + return StdOsStringSynthProvider.ptr_and_len(self, gcm(valobj, 'inner')) + + +class StdPathSynthProvider(FFISliceSynthProvider): + pass + +################################################################################################################## + + +class DerefSynthProvider(RustSynthProvider): + deref = lldb.SBValue() + + def has_children(self): + return self.deref.MightHaveChildren() + + def num_children(self): + return self.deref.GetNumChildren() + + def get_child_at_index(self, index): + return self.deref.GetChildAtIndex(index) + + def get_index_of_child(self, name): + return self.deref.GetIndexOfChildWithName(name) + + def get_summary(self): + return obj_summary(self.deref) + +# Base for Rc and Arc + + +class StdRefCountedSynthProvider(DerefSynthProvider): + weak = 0 + strong = 0 + + def get_summary(self): + if self.weak != 0: + s = '(refs:%d,weak:%d) ' % (self.strong, self.weak) + else: + s = '(refs:%d) ' % self.strong + if self.strong > 0: + s += obj_summary(self.deref) + else: + s += '' + return s + + +class StdRcSynthProvider(StdRefCountedSynthProvider): + def update(self): + inner = read_unique_ptr(gcm(self.valobj, 'ptr')) + self.strong = gcm(inner, 'strong', 'value', 'value').GetValueAsUnsigned() + self.weak = gcm(inner, 'weak', 'value', 'value').GetValueAsUnsigned() + if self.strong > 0: + self.deref = gcm(inner, 'value') + self.weak -= 1 # There's an implicit weak reference communally owned by all the strong pointers + else: + self.deref = lldb.SBValue() + self.deref.SetPreferSyntheticValue(True) + + +class StdArcSynthProvider(StdRefCountedSynthProvider): + def update(self): + inner = read_unique_ptr(gcm(self.valobj, 'ptr')) + self.strong = gcm(inner, 'strong', 'v', 'value').GetValueAsUnsigned() + self.weak = gcm(inner, 'weak', 'v', 'value').GetValueAsUnsigned() + if self.strong > 0: + self.deref = gcm(inner, 'data') + self.weak -= 1 # There's an implicit weak reference communally owned by all the strong pointers + else: + self.deref = lldb.SBValue() + self.deref.SetPreferSyntheticValue(True) + + +class StdMutexSynthProvider(DerefSynthProvider): + def update(self): + self.deref = gcm(self.valobj, 'data', 'value') + self.deref.SetPreferSyntheticValue(True) + + +class StdCellSynthProvider(DerefSynthProvider): + def update(self): + self.deref = gcm(self.valobj, 'value', 'value') + self.deref.SetPreferSyntheticValue(True) + + +class StdRefCellSynthProvider(DerefSynthProvider): + def update(self): + self.deref = gcm(self.valobj, 'value', 'value') + self.deref.SetPreferSyntheticValue(True) + + def get_summary(self): + borrow = gcm(self.valobj, 'borrow', 'value', 'value').GetValueAsSigned() + s = '' + if borrow < 0: + s = '(borrowed:mut) ' + elif borrow > 0: + s = '(borrowed:%d) ' % borrow + return s + obj_summary(self.deref) + + +class StdRefCellBorrowSynthProvider(DerefSynthProvider): + def update(self): + self.deref = gcm(self.valobj, 'value', 'pointer').Dereference() + self.deref.SetPreferSyntheticValue(True) + +################################################################################################################## + + +class EnumSynthProvider(RustSynthProvider): + variant = lldb.SBValue() + summary = '' + skip_first = 0 + + def has_children(self): + return self.variant.MightHaveChildren() + + def num_children(self): + return self.variant.GetNumChildren() - self.skip_first + + def get_child_at_index(self, index): + return self.variant.GetChildAtIndex(index + self.skip_first) + + def get_index_of_child(self, name): + return self.variant.GetIndexOfChildWithName(name) - self.skip_first + + def get_summary(self): + return self.summary + + +class GenericEnumSynthProvider(EnumSynthProvider): + def update(self): + dyn_type_name = self.valobj.GetTypeName() + variant_name = dyn_type_name[dyn_type_name.rfind(':')+1:] + self.variant = self.valobj + + if self.variant.IsValid() and self.variant.GetNumChildren() > self.skip_first: + if self.variant.GetChildAtIndex(self.skip_first).GetName() in ['0', '__0']: + self.summary = variant_name + tuple_summary(self.variant) + else: + self.summary = variant_name + '{...}' + else: + self.summary = variant_name + + +class MsvcTupleSynthProvider(RustSynthProvider): + def update(self): + tparams = get_template_params(self.valobj.GetTypeName()) + self.type_name = '(' + ', '.join(tparams) + ')' + + def has_children(self): + return self.valobj.MightHaveChildren() + + def num_children(self): + return self.valobj.GetNumChildren() + + def get_child_at_index(self, index): + child = self.valobj.GetChildAtIndex(index) + return child.CreateChildAtOffset(str(index), 0, child.GetType()) + + def get_index_of_child(self, name): + return str(name) + + def get_summary(self): + return tuple_summary(self.valobj) + + def get_type_name(self): + return self.type_name + + +class MsvcEnumSynthProvider(EnumSynthProvider): + is_tuple_variant = False + + def update(self): + tparams = get_template_params(self.valobj.GetTypeName()) + if len(tparams) == 1: # Regular enum + discr = gcm(self.valobj, 'discriminant') + self.variant = gcm(self.valobj, 'variant' + str(discr.GetValueAsUnsigned())) + variant_name = discr.GetValue() + else: # Niche enum + dataful_min = int(tparams[1]) + dataful_max = int(tparams[2]) + dataful_var = tparams[3] + discr = gcm(self.valobj, 'discriminant') + if dataful_min <= discr.GetValueAsUnsigned() <= dataful_max: + self.variant = gcm(self.valobj, 'dataful_variant') + variant_name = dataful_var + else: + variant_name = discr.GetValue() + + self.type_name = tparams[0] + + if self.variant.IsValid() and self.variant.GetNumChildren() > self.skip_first: + if self.variant.GetChildAtIndex(self.skip_first).GetName() == '__0': + self.is_tuple_variant = True + self.summary = variant_name + tuple_summary(self.variant, skip_first=self.skip_first) + else: + self.summary = variant_name + '{...}' + else: + self.summary = variant_name + + def get_child_at_index(self, index): + child = self.variant.GetChildAtIndex(index + self.skip_first) + if self.is_tuple_variant: + return child.CreateChildAtOffset(str(index), 0, child.GetType()) + else: + return child + + def get_index_of_child(self, name): + if self.is_tuple_variant: + return int(name) + else: + return self.variant.GetIndexOfChildWithName(name) - self.skip_first + + def get_type_name(self): + return self.type_name + + +class MsvcEnum2SynthProvider(EnumSynthProvider): + is_tuple_variant = False + + def update(self): + tparams = get_template_params(self.valobj.GetTypeName()) + self.type_name = tparams[0] + + def get_child_at_index(self, index): + return self.valobj.GetChildAtIndex(index) + + def get_index_of_child(self, name): + return self.valobj.GetChildIndex(name) + + def get_type_name(self): + return self.type_name + + +################################################################################################################## + + +class StdHashMapSynthProvider(RustSynthProvider): + def update(self): + self.initialize_table(gcm(self.valobj, 'base', 'table')) + + def initialize_table(self, table): + assert table.IsValid() + + if table.type.GetNumberOfTemplateArguments() > 0: + item_ty = table.type.GetTemplateArgumentType(0) + else: # we must be on windows-msvc - try to look up item type by name + table_ty_name = table.GetType().GetName() # "hashbrown::raw::RawTable" + item_ty_name = get_template_params(table_ty_name)[0] + item_ty = table.GetTarget().FindTypes(item_ty_name).GetTypeAtIndex(0) + + if item_ty.IsTypedefType(): + item_ty = item_ty.GetTypedefedType() + + inner_table = table.GetChildMemberWithName('table') + if inner_table.IsValid(): + self.initialize_hashbrown_v2(inner_table, item_ty) # 1.52 <= std_version + else: + if not table.GetChildMemberWithName('data'): + self.initialize_hashbrown_v2(table, item_ty) # ? <= std_version < 1.52 + else: + self.initialize_hashbrown_v1(table, item_ty) # 1.36 <= std_version < ? + + def initialize_hashbrown_v2(self, table, item_ty): + self.num_buckets = gcm(table, 'bucket_mask').GetValueAsUnsigned() + 1 + ctrl_ptr = gcm(table, 'ctrl', 'pointer') + ctrl = ctrl_ptr.GetPointeeData(0, self.num_buckets) + # Buckets are located above `ctrl`, in reverse order. + start_addr = ctrl_ptr.GetValueAsUnsigned() - item_ty.GetByteSize() * self.num_buckets + buckets_ty = item_ty.GetArrayType(self.num_buckets) + self.buckets = self.valobj.CreateValueFromAddress('data', start_addr, buckets_ty) + error = lldb.SBError() + self.valid_indices = [] + for i in range(self.num_buckets): + if ctrl.GetUnsignedInt8(error, i) & 0x80 == 0: + self.valid_indices.append(self.num_buckets - 1 - i) + + def initialize_hashbrown_v1(self, table, item_ty): + self.num_buckets = gcm(table, 'bucket_mask').GetValueAsUnsigned() + 1 + ctrl_ptr = gcm(table, 'ctrl', 'pointer') + ctrl = ctrl_ptr.GetPointeeData(0, self.num_buckets) + buckets_ty = item_ty.GetArrayType(self.num_buckets) + self.buckets = gcm(table, 'data', 'pointer').Dereference().Cast(buckets_ty) + error = lldb.SBError() + self.valid_indices = [] + for i in range(self.num_buckets): + if ctrl.GetUnsignedInt8(error, i) & 0x80 == 0: + self.valid_indices.append(i) + + def has_children(self): + return True + + def num_children(self): + return len(self.valid_indices) + + def get_child_at_index(self, index): + bucket_idx = self.valid_indices[index] + item = self.buckets.GetChildAtIndex(bucket_idx) + return item.CreateChildAtOffset('[%d]' % index, 0, item.GetType()) + + def get_index_of_child(self, name): + return int(name.lstrip('[').rstrip(']')) + + def get_summary(self): + return 'size=%d, capacity=%d' % (self.num_children(), self.num_buckets) + + +class StdHashSetSynthProvider(StdHashMapSynthProvider): + def update(self): + table = gcm(self.valobj, 'base', 'map', 'table') # std_version >= 1.48 + if not table.IsValid(): + table = gcm(self.valobj, 'map', 'base', 'table') # std_version < 1.48 + self.initialize_table(table) + + def get_child_at_index(self, index): + bucket_idx = self.valid_indices[index] + item = self.buckets.GetChildAtIndex(bucket_idx).GetChildAtIndex(0) + return item.CreateChildAtOffset('[%d]' % index, 0, item.GetType()) + +################################################################################################################## + + +def __lldb_init_module(debugger_obj, internal_dict): + log.info('Initializing') + initialize_category(debugger_obj, internal_dict) \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/package.json b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/package.json similarity index 96% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/package.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/package.json index dfe37961bd7..d7cc20595f4 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/package.json +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/package.json @@ -6,10 +6,12 @@ }, "displayName": "WAMR-IDE", "description": "An Integrated Development Environment for WASM", - "version": "1.2.1", + "version": "1.2.2", "engines": { - "vscode": "^1.59.0" + "vscode": "^1.59.0", + "node": ">=16.0.0" }, + "engineStrict": true, "categories": [ "Other" ], @@ -235,6 +237,7 @@ "prettier-format-apply": "prettier --config .prettierrc.json 'src/**/*.ts' --write" }, "devDependencies": { + "@types/chai": "^4.3.5", "@types/glob": "^7.1.3", "@types/mocha": "^8.2.2", "@types/node": "14.x", @@ -243,12 +246,14 @@ "@types/yauzl": "^2.10.0", "@typescript-eslint/eslint-plugin": "^4.26.0", "@typescript-eslint/parser": "^4.26.0", + "@vscode/debugprotocol": "^1.61.0", + "@vscode/test-electron": "^2.3.3", + "chai": "^4.3.7", "eslint": "^7.32.0", "glob": "^7.1.7", - "mocha": "^8.4.0", + "mocha": "^10.2.0", "prettier": "2.5.1", - "typescript": "^4.3.2", - "vscode-test": "^1.5.2" + "typescript": "^4.3.2" }, "dependencies": { "@vscode/webview-ui-toolkit": "^0.8.4", diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/boot_debugger_server.bat b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/boot_debugger_server.bat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/boot_debugger_server.bat rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/boot_debugger_server.bat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/boot_debugger_server.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/boot_debugger_server.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/boot_debugger_server.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/boot_debugger_server.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/build.bat b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/build.bat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/build.bat rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/build.bat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/build.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/build.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/destroy.bat b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/destroy.bat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/destroy.bat rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/destroy.bat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/destroy.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/destroy.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/destroy.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/destroy.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/project.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/project.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/project.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/project.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/run.bat b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/run.bat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/run.bat rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/run.bat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/run.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/run.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/scripts/run.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/scripts/run.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/test/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/test/build.sh new file mode 100755 index 00000000000..e175c91066d --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/test/build.sh @@ -0,0 +1,2 @@ +# compile with debug symbols and no optimization +rustc --target wasm32-wasi ./test.rs -g -C opt-level=0 \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/test/test.rs b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/test/test.rs new file mode 100644 index 00000000000..59760f9589c --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/test/test.rs @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +use std::collections::HashMap; +use std::collections::VecDeque; +use std::cell::RefCell; + +fn main() { + let mut vector = Vec::from([1, 2, 3, 4]); + vector.push(12); + + let mut map: HashMap<&str, f64> = HashMap::from([ + ("Mercury", 0.4), + ("Venus", 0.7), + ("Earth", 1.0), + ("Mars", 1.5), + ]); + map.insert("Venus", 2.5); + map.insert("Sun", 312.2); + + let string = "this is a string"; + + let tmp = String::from("hello world"); + let slice = &tmp[1..5]; + + let mut deque = VecDeque::from([1, 2, 3]); + deque.push_back(4); + deque.push_back(5); + + let ref_cell = RefCell::new(5); + + println!("Hello, world!"); // BP_MARKER_1 +} \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/assert.h b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/assert.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/assert.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/assert.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/ctype.h b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/ctype.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/ctype.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/ctype.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/errno.h b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/errno.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/errno.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/errno.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/fcntl.h b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/fcntl.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/fcntl.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/fcntl.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/inttypes.h b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/inttypes.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/inttypes.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/inttypes.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/limits.h b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/limits.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/limits.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/limits.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/pthread.h b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/pthread.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/pthread.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/pthread.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdarg.h b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdarg.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdarg.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdarg.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdbool.h b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdbool.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdbool.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdbool.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdint.h b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdint.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdint.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdint.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdio.h b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdio.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdio.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdio.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdlib.h b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdlib.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdlib.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/stdlib.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/string.h b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/string.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/string.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/string.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/strings.h b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/strings.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/strings.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/wamr-sdk/libc-builtin-sysroot/include/strings.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/webview/css/style.css b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/webview/css/style.css similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/webview/css/style.css rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/webview/css/style.css diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/webview/js/configbuildtarget.js b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/webview/js/configbuildtarget.js similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/webview/js/configbuildtarget.js rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/webview/js/configbuildtarget.js diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/webview/js/newproj.js b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/webview/js/newproj.js similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/webview/js/newproj.js rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/webview/js/newproj.js diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/webview/page/configBuildTarget.html b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/webview/page/configBuildTarget.html similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/webview/page/configBuildTarget.html rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/webview/page/configBuildTarget.html diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/webview/page/newProject.html b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/webview/page/newProject.html similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/resource/webview/page/newProject.html rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/resource/webview/page/newProject.html diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/constants.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/constants.ts similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/constants.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/constants.ts diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/debugConfigurationProvider.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/debugConfigurationProvider.ts similarity index 51% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/debugConfigurationProvider.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/debugConfigurationProvider.ts index e7b42bf031a..657cf59c766 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/debugConfigurationProvider.ts +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/debugConfigurationProvider.ts @@ -6,23 +6,47 @@ import * as vscode from 'vscode'; import * as os from 'os'; +/* see https://github.com/llvm/llvm-project/tree/main/lldb/tools/lldb-vscode#attaching-settings */ +export interface WasmDebugConfig { + type: string, + name: string, + request: string, + program? : string, + pid?: string, + stopOnEntry?: boolean, + waitFor?: boolean, + initCommands?: string[], + preRunCommands?: string[], + stopCommands?: string[], + exitCommands?: string[], + terminateCommands?: string[], + attachCommands?: string[] +} + export class WasmDebugConfigurationProvider implements vscode.DebugConfigurationProvider { - private wasmDebugConfig = { + private wasmDebugConfig: WasmDebugConfig = { type: 'wamr-debug', name: 'Attach', request: 'attach', stopOnEntry: true, - initCommands: os.platform() === 'win32' || os.platform() === 'darwin' ? - /* linux and windows has different debug configuration */ - ['platform select remote-linux'] : - undefined, attachCommands: [ /* default port 1234 */ 'process connect -p wasm connect://127.0.0.1:1234', ] }; + constructor(extensionPath: string) { + this.wasmDebugConfig.initCommands = [ + /* Add rust formatters -> https://lldb.llvm.org/use/variable.html */ + `command script import ${extensionPath}/formatters/rust.py` + ]; + + if (os.platform() === 'win32' || os.platform() === 'darwin') { + this.wasmDebugConfig.initCommands.push('platform select remote-linux'); + } + } + public resolveDebugConfiguration( _: vscode.WorkspaceFolder | undefined, debugConfiguration: vscode.DebugConfiguration, diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/decorationProvider.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/decorationProvider.ts similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/decorationProvider.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/decorationProvider.ts diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/extension.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/extension.ts similarity index 99% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/extension.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/extension.ts index 523b26b831f..419f730c884 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/extension.ts +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/extension.ts @@ -40,7 +40,7 @@ let isWasmProject = false; export async function activate(context: vscode.ExtensionContext) { const extensionPath = context.extensionPath; const osPlatform = os.platform(); - const wamrVersion = getWAMRExtensionVersion(context); + const wamrVersion = getWAMRExtensionVersion(context.extensionPath); const typeMap = new Map(); const scriptMap = new Map(); /* set relative path of build.bat|sh script */ @@ -170,7 +170,7 @@ export async function activate(context: vscode.ExtensionContext) { } /* register debug configuration */ - wasmDebugConfigProvider = new WasmDebugConfigurationProvider(); + wasmDebugConfigProvider = new WasmDebugConfigurationProvider(context.extensionPath); vscode.debug.registerDebugConfigurationProvider( 'wamr-debug', @@ -409,13 +409,13 @@ export async function activate(context: vscode.ExtensionContext) { /* we should check again whether the user installed lldb, as this can be skipped during activation */ try { - if (!isLLDBInstalled(context)) { + if (!isLLDBInstalled(context.extensionPath)) { /**NOTE - if users select to skip install, * we should return rather than continue * the execution */ if ( - (await promptInstallLLDB(context)) === + (await promptInstallLLDB(context.extensionPath)) === SelectionOfPrompt.skip ) { return; @@ -772,8 +772,8 @@ export async function activate(context: vscode.ExtensionContext) { ); try { - if (!isLLDBInstalled(context)) { - await promptInstallLLDB(context); + if (!isLLDBInstalled(context.extensionPath)) { + await promptInstallLLDB(context.extensionPath); } if ( diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/taskProvider.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/taskProvider.ts similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/taskProvider.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/taskProvider.ts diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/test/runTest.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/test/runTest.ts new file mode 100644 index 00000000000..ae81a539b92 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/test/runTest.ts @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +import * as path from 'path'; +import * as os from 'os'; + +import { runTests } from '@vscode/test-electron'; + +async function main() { + try { + // The folder containing the Extension Manifest package.json + // Passed to `--extensionDevelopmentPath` + const extensionDevelopmentPath = path.resolve(__dirname, '../../'); + + // The path to the extension test script + // Passed to --extensionTestsPath + const extensionTestsPath = path.resolve(__dirname, './suite/index'); + + // Download VS Code, unzip it and run the integration test + await runTests({ + extensionDevelopmentPath, + extensionTestsPath, + launchArgs: ['--user-data-dir', `${os.tmpdir()}`] + }); + } catch (err) { + console.error('Failed to run tests'); + process.exit(1); + } +} + +main(); diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/test/suite/extension.test.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/test/suite/extension.test.ts new file mode 100644 index 00000000000..5bd717b28b2 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/test/suite/extension.test.ts @@ -0,0 +1,183 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +import {DebugProtocol} from '@vscode/debugprotocol'; +import {after, before, test, suite} from 'mocha'; +import {assert} from 'chai'; +import * as vscode from 'vscode'; +import * as cp from 'child_process'; +import * as path from "path"; +import * as os from 'os'; +import {WasmDebugConfig, WasmDebugConfigurationProvider} from "../../debugConfigurationProvider"; +import {EXTENSION_PATH, clearAllBp, setBpAtMarker, compileRustToWasm} from "./utils"; +import {downloadLldb, isLLDBInstalled} from '../../utilities/lldbUtilities'; + +suite('Unit Tests', function () { + test('DebugConfigurationProvider init commands', function () { + const testExtensionPath = "/test/path/"; + const provider = new WasmDebugConfigurationProvider(testExtensionPath); + + assert.includeMembers( + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + provider.getDebugConfig().initCommands!, + [`command script import ${testExtensionPath}/formatters/rust.py`], + "Debugger init commands did not contain " + ); + }); + + test('DebugConfigurationProvider resolve configuration', function () { + const testExtensionPath = "/test/path/"; + const provider = new WasmDebugConfigurationProvider(testExtensionPath); + + const actual = provider.resolveDebugConfiguration(undefined, { + type: "wamr-debug", + name: "Attach", + request: "attach", + initCommands: [], + attachCommands: [ + 'process connect -p wasm connect://123.456.789.1:1237', + ] + }); + + assert.deepEqual( + actual, + { + type: "wamr-debug", + name: "Attach", + request: "attach", + stopOnEntry: true, + initCommands: [], + attachCommands: [ + 'process connect -p wasm connect://123.456.789.1:1237', + ] + }, + "Configuration did not match the expected configuration after calling resolveDebugConfiguration()" + ); + }); +}); + +suite('Inegration Tests', function () { + let debuggerProcess: cp.ChildProcessWithoutNullStreams; + const port = 1239; + const downloadTimeout = 60 * 1000; + + before(async function () { + // timeout of 20 seconds + this.timeout(20 * 1000); + // Download LLDB if necessary. Should be available in the CI. Only for local execution. + if (!isLLDBInstalled(EXTENSION_PATH)) { + this.timeout(downloadTimeout); + console.log("Downloading LLDB. This might take a moment..."); + await downloadLldb(EXTENSION_PATH); + assert.isTrue(isLLDBInstalled(EXTENSION_PATH), "LLDB was not installed correctly"); + } + + compileRustToWasm(); + + const platform = os.platform(); + assert.isTrue(platform === "darwin" || platform === "linux", `Tests do not support your platform: ${platform}`); + const iWasmPath = path.resolve(`${EXTENSION_PATH}/../../../product-mini/platforms/${platform}/build/iwasm`); + const testWasmFilePath = `${EXTENSION_PATH}/resource/test/test.wasm`; + + debuggerProcess = cp.spawn( + iWasmPath, + [`-g=127.0.0.1:${port}`, testWasmFilePath], + {} + ); + + debuggerProcess.stderr.on('data', (data) => { + console.log(`Error from debugger process: ${data}`); + }); + }); + + after(async function () { + await vscode.debug.stopDebugging(); + debuggerProcess.kill(); + }); + + test('Rust formatters', async function () { + // timeout of 1 minutes + this.timeout(60 * 1000); + clearAllBp(); + setBpAtMarker(`${EXTENSION_PATH}/resource/test/test.rs`, "BP_MARKER_1"); + + const getVariables = new Promise((resolve, reject) => { + vscode.debug.registerDebugAdapterTrackerFactory("wamr-debug", { + createDebugAdapterTracker: function () { + return { + // The debug adapter has sent a Debug Adapter Protocol message to the editor. + onDidSendMessage: (message: DebugProtocol.ProtocolMessage) => { + if (message.type === "response") { + const m = message as DebugProtocol.Response; + if (m.command === "variables") { + const res = m as DebugProtocol.VariablesResponse; + resolve(res.body.variables); + } + } + }, + onError: (error: Error) => { + reject("An error occurred before vscode reached the breakpoint: " + error); + }, + onExit: (code: number | undefined) => { + reject(`Debugger exited before vscode reached the breakpoint with code: ${code}`); + }, + }; + } + }); + }); + + const config: WasmDebugConfig = { + type: "wamr-debug", + request: "attach", + name: "Attach Debugger", + stopOnEntry: false, + initCommands: [ + `command script import ${EXTENSION_PATH}/formatters/rust.py` + ], + attachCommands: [ + `process connect -p wasm connect://127.0.0.1:${port}` + ] + }; + + if (os.platform() === 'win32' || os.platform() === 'darwin') { + config.initCommands?.push('platform select remote-linux'); + } + + try { + await vscode.debug.startDebugging(undefined, config); + } catch (e) { + assert.fail("Could not connect to debug adapter"); + } + + // wait until vs code has reached breakpoint and has requested the variables. + const variables = await getVariables; + const namesToVariables = variables.reduce((acc: { [name: string]: DebugProtocol.Variable }, c) => { + if (c.evaluateName) { + acc[c.evaluateName] = c; + } + return acc; + }, {}); + + assert.includeMembers(Object.keys(namesToVariables), ["vector", "map", "string", "slice", "deque", "ref_cell"], "The Debugger did not return all expected debugger variables."); + + // Vector + assert.equal(namesToVariables["vector"].value, " (5) vec![1, 2, 3, 4, 12]", "The Vector summary string looks different than expected"); + + // Map + assert.equal(namesToVariables["map"].value, " size=5, capacity=8", "The Map summary string looks different than expected"); + + // String + assert.equal(namesToVariables["string"].value, " \"this is a string\"", "The String summary string looks different than expected"); + + // Slice + assert.equal(namesToVariables["slice"].value, " \"ello\"", "The Slice summary string looks different than expected"); + + // Deque + assert.equal(namesToVariables["deque"].value, " (5) VecDeque[1, 2, 3, 4, 5]", "The Deque summary string looks different than expected"); + + // RefCell + assert.equal(namesToVariables["ref_cell"].value, " 5", "The RefCell summary string looks different than expected"); + }); +}); diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/test/suite/index.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/test/suite/index.ts new file mode 100644 index 00000000000..9b56c6ffe67 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/test/suite/index.ts @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +import * as path from 'path'; +import * as Mocha from 'mocha'; +import * as glob from 'glob'; + +export function run(): Promise { + // Create the mocha test + const mocha = new Mocha({ + ui: 'tdd' + }); + + const testsRoot = path.resolve(__dirname, '..'); + + return new Promise((c, e) => { + glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { + if (err) { + return e(err); + } + + // Add files to the test suite + files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); + + try { + // Run the mocha test + mocha.run(failures => { + if (failures > 0) { + e(new Error(`${failures} tests failed.`)); + } else { + c(); + } + }); + } catch (err) { + console.error(err); + e(err); + } + }); + }); +} diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/test/suite/utils.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/test/suite/utils.ts new file mode 100644 index 00000000000..87cb04b3b1c --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/test/suite/utils.ts @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +import {assert} from 'chai'; +import * as vscode from 'vscode'; +import {Range, SourceBreakpoint} from "vscode"; +import * as fs from "fs"; +import path = require('path'); +import * as cp from 'child_process'; + +export const EXTENSION_PATH = path.resolve(`${__dirname}/../../..`); + +// clears all set breakpoints +export function clearAllBp(): void { + vscode.debug.removeBreakpoints(vscode.debug.breakpoints); +} + +// Inserts a breakpoint in a file at the first occurrence of bpMarker +export function setBpAtMarker(file: string, bpMarker: string): void { + const uri = vscode.Uri.file(file); + const data = fs.readFileSync(uri.path, "utf8"); + const line = data.split("\n").findIndex(line => line.includes(bpMarker)); + assert.notStrictEqual(line, -1, "Could not find breakpoint marker in source file"); + const position = new vscode.Position(line, 0); + const bp = new SourceBreakpoint(new vscode.Location(uri, new Range(position, position)), true); + vscode.debug.addBreakpoints([bp]); +} + +// compiles resources/test/test.rs to test.wasm +export function compileRustToWasm(): void { + const testResourceFolder = `${EXTENSION_PATH}/resource/test`; + // compile with debug symbols and no optimization + const cmd = `rustc --target wasm32-wasi ${testResourceFolder}/test.rs -g -C opt-level=0 -o ${testResourceFolder}/test.wasm`; + + try { + cp.execSync(cmd, {stdio: [null, null, process.stderr]}); + } catch (e) { + assert.fail(`Compilation of example rust file failed with error: ${e}`); + } + assert.isTrue(fs.existsSync(`${testResourceFolder}/test.wasm`), "Could not find wasm file WASM file to run debugger on."); +} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/utilities/directoryUtilities.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/utilities/directoryUtilities.ts similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/utilities/directoryUtilities.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/utilities/directoryUtilities.ts diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/utilities/dockerUtilities.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/utilities/dockerUtilities.ts similarity index 96% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/utilities/dockerUtilities.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/utilities/dockerUtilities.ts index 0a749ba19b0..4c2b40ebcfa 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/utilities/dockerUtilities.ts +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/utilities/dockerUtilities.ts @@ -102,7 +102,7 @@ export async function checkIfDockerImagesExist( ): Promise { try { /* the tag of images is equal to extension's version */ - const imageTag = getWAMRExtensionVersion(context); + const imageTag = getWAMRExtensionVersion(context.extensionPath); await execShell( `docker image inspect wasm-debug-server:${imageTag} wasm-toolchain:${imageTag}` ); @@ -115,7 +115,7 @@ export async function checkIfDockerImagesExist( function getDockerImagesDownloadUrl( context: vscode.ExtensionContext ): string[] { - const wamrVersion = getWAMRExtensionVersion(context); + const wamrVersion = getWAMRExtensionVersion(context.extensionPath); const wamrReleaseUrl = `https://github.com/bytecodealliance/wasm-micro-runtime/releases/download/WAMR`; return [ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/utilities/getUri.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/utilities/getUri.ts similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/utilities/getUri.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/utilities/getUri.ts diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/utilities/lldbUtilities.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/utilities/lldbUtilities.ts similarity index 85% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/utilities/lldbUtilities.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/utilities/lldbUtilities.ts index 9170a75d380..b6553acbc7e 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/utilities/lldbUtilities.ts +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/utilities/lldbUtilities.ts @@ -36,14 +36,14 @@ function getLLDBUnzipFilePath(destinationFolder: string, filename: string) { } export function getWAMRExtensionVersion( - context: vscode.ExtensionContext + extensionPath: string ): string { // eslint-disable-next-line @typescript-eslint/no-var-requires - return require(path.join(context.extensionPath, 'package.json')).version; + return require(path.join(extensionPath, 'package.json')).version; } -function getLLDBDownloadUrl(context: vscode.ExtensionContext): string { - const wamrVersion = getWAMRExtensionVersion(context); +function getLLDBDownloadUrl(extensionPath: string): string { + const wamrVersion = getWAMRExtensionVersion(extensionPath); const lldbOsUrlSuffix = LLDB_OS_DOWNLOAD_URL_SUFFIX_MAP[os.platform()]; if (!lldbOsUrlSuffix) { @@ -53,8 +53,7 @@ function getLLDBDownloadUrl(context: vscode.ExtensionContext): string { return `https://github.com/bytecodealliance/wasm-micro-runtime/releases/download/WAMR-${wamrVersion}/wamr-lldb-${wamrVersion}-${lldbOsUrlSuffix}.zip`; } -export function isLLDBInstalled(context: vscode.ExtensionContext): boolean { - const extensionPath = context.extensionPath; +export function isLLDBInstalled(extensionPath: string): boolean { const lldbOSDir = os.platform(); const lldbBinaryPath = path.join( extensionPath, @@ -67,9 +66,8 @@ export function isLLDBInstalled(context: vscode.ExtensionContext): boolean { } export async function promptInstallLLDB( - context: vscode.ExtensionContext + extensionPath: string ): Promise { - const extensionPath = context.extensionPath; const response = await vscode.window.showWarningMessage( 'No LLDB instance found. Setup now?', @@ -81,7 +79,15 @@ export async function promptInstallLLDB( return response; } - const downloadUrl = getLLDBDownloadUrl(context); + await downloadLldb(extensionPath); + + return SelectionOfPrompt.setUp; +} + +export async function downloadLldb( + extensionPath: string +): Promise { + const downloadUrl = getLLDBDownloadUrl(extensionPath); const destinationDir = os.platform(); if (!downloadUrl) { @@ -115,5 +121,4 @@ export async function promptInstallLLDB( // Remove the bundle.zip fs.unlinkSync(lldbZipPath); - return SelectionOfPrompt.setUp; } diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/view/NewProjectPanel.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/view/NewProjectPanel.ts similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/view/NewProjectPanel.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/view/NewProjectPanel.ts diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/view/TargetConfigPanel.ts b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/view/TargetConfigPanel.ts similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/src/view/TargetConfigPanel.ts rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/src/view/TargetConfigPanel.ts diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/tsconfig.json b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/tsconfig.json similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/VSCode-Extension/tsconfig.json rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/VSCode-Extension/tsconfig.json diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Debug-Server/Docker/Dockerfile b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Debug-Server/Docker/Dockerfile similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Debug-Server/Docker/Dockerfile rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Debug-Server/Docker/Dockerfile diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Debug-Server/Docker/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Debug-Server/Docker/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Debug-Server/Docker/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Debug-Server/Docker/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Debug-Server/Docker/build_docker_image.bat b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Debug-Server/Docker/build_docker_image.bat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Debug-Server/Docker/build_docker_image.bat rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Debug-Server/Docker/build_docker_image.bat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Debug-Server/Docker/build_docker_image.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Debug-Server/Docker/build_docker_image.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Debug-Server/Docker/build_docker_image.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Debug-Server/Docker/build_docker_image.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Debug-Server/Docker/resource/debug.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Debug-Server/Docker/resource/debug.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Debug-Server/Docker/resource/debug.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Debug-Server/Docker/resource/debug.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Debug-Server/Docker/resource/run.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Debug-Server/Docker/resource/run.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Debug-Server/Docker/resource/run.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Debug-Server/Docker/resource/run.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Toolchain/Docker/.dockerignore b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Toolchain/Docker/.dockerignore similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Toolchain/Docker/.dockerignore rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Toolchain/Docker/.dockerignore diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Toolchain/Docker/Dockerfile b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Toolchain/Docker/Dockerfile similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Toolchain/Docker/Dockerfile rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Toolchain/Docker/Dockerfile diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Toolchain/Docker/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Toolchain/Docker/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Toolchain/Docker/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Toolchain/Docker/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Toolchain/Docker/build_docker_image.bat b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Toolchain/Docker/build_docker_image.bat similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Toolchain/Docker/build_docker_image.bat rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Toolchain/Docker/build_docker_image.bat diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Toolchain/Docker/build_docker_image.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Toolchain/Docker/build_docker_image.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Toolchain/Docker/build_docker_image.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Toolchain/Docker/build_docker_image.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Toolchain/Docker/resource/build_wasm.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Toolchain/Docker/resource/build_wasm.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Toolchain/Docker/resource/build_wasm.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Toolchain/Docker/resource/build_wasm.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Toolchain/Docker/resource/wamr_toolchain.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Toolchain/Docker/resource/wamr_toolchain.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/test-tools/wamr-ide/WASM-Toolchain/Docker/resource/wamr_toolchain.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/test-tools/wamr-ide/WASM-Toolchain/Docker/resource/wamr_toolchain.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/README.md new file mode 100644 index 00000000000..2112829e052 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/README.md @@ -0,0 +1,62 @@ +# WAMR test benchmarks + +This folder contains test benchmarks for wamr. + +## Build and Run + +Refer to the `README.md` under each folder for how to build and run the benchmark. + +## Install `llvm-profdata` + +The tool `llvm-profdata` is used when running the `test_pgo.sh` script under the benchmark folder. There are two ways to install it: + +1. Refer to https://apt.llvm.org/, e.g. in Ubuntu 20.04, add lines below to /etc/apt/source.list + +```bash +deb http://apt.llvm.org/focal/ llvm-toolchain-focal main +deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal main +# 15 +deb http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main +deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main +``` + +Then run `sudo apt update`, `sudo apt install llvm`. And after installing: + +```bash +cd /usr/bin +sudo ln -s llvm-profdata-15 llvm-profdata +``` + +2. Build manually + +```bash +git clone --depth 1 --branch release/15.x https://github.com/llvm/llvm-project.git +cd llvm-project +mkdir build && cd build +cmake ../llvm \ + -DCMAKE_BUILD_TYPE:STRING="Release" \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DLLVM_APPEND_VC_REV:BOOL=ON \ + -DLLVM_BUILD_EXAMPLES:BOOL=OFF \ + -DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF \ + -DLLVM_BUILD_TESTS:BOOL=OFF \ + -DLLVM_CCACHE_BUILD:BOOL=ON \ + -DLLVM_ENABLE_BINDINGS:BOOL=OFF \ + -DLLVM_ENABLE_IDE:BOOL=OFF \ + -DLLVM_ENABLE_LIBEDIT=OFF \ + -DLLVM_ENABLE_TERMINFO:BOOL=OFF \ + -DLLVM_ENABLE_ZLIB:BOOL=ON \ + -DLLVM_INCLUDE_BENCHMARKS:BOOL=OFF \ + -DLLVM_INCLUDE_DOCS:BOOL=OFF \ + -DLLVM_INCLUDE_EXAMPLES:BOOL=OFF \ + -DLLVM_INCLUDE_UTILS:BOOL=OFF \ + -DLLVM_INCLUDE_TESTS:BOOL=OFF \ + -DLLVM_BUILD_TESTS:BOOL=OFF \ + -DLLVM_OPTIMIZED_TABLEGEN:BOOL=ON \ + -DLLVM_ENABLE_LIBXML2:BOOL=OFF \ + -DLLVM_TARGETS_TO_BUILD:STRING="X86" \ + -DLLVM_INCLUDE_TOOLS:BOOL=ON \ + -G'Ninja' +ninja -j 8 +# tool `llvm-profdata` is generated under this folder. +``` diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/coremark/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/coremark/README.md similarity index 59% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/coremark/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/coremark/README.md index 1631cc5c00c..4e88069f851 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/coremark/README.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/coremark/README.md @@ -17,3 +17,9 @@ And then run `./build.sh` to build the source code, file `coremark.exe`, `corema # Running Run `./run.sh` to test the benchmark, the native mode, iwasm aot mode and iwasm interpreter mode will be tested respectively. + +Run `./test_pgo.sh` to test the benchmark with AOT static PGO (Profile-Guided Optimization) enabled, please refer [here](../README.md#install-llvm-profdata) to install tool `llvm-profdata` and build `iwasm` with `cmake -DWAMR_BUILD_STATIC_PGO=1`. + +- For Linux, build `iwasm` with `cmake -DWAMR_BUILD_STATIC_PGO=1`, then run `./test_pgo.sh` to test the benchmark with AOT static PGO (Profile-Guided Optimization) enabled. + +- For Linux-sgx, similarly, build `iwasm` with `cmake -DWAMR_BUILD_STATIC_PGO=1`, then `make` in the directory `enclave-sample`. And run `./test_pgo.sh --sgx` to test the benchmark. diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/coremark/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/coremark/build.sh similarity index 84% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/coremark/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/coremark/build.sh index 14c179ce576..ecada10d473 100755 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/coremark/build.sh +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/coremark/build.sh @@ -3,6 +3,8 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +PLATFORM=$(uname -s | tr A-Z a-z) + WAMRC="../../../wamr-compiler/build/wamrc" if [ ! -d coremark ]; then @@ -32,4 +34,9 @@ cd .. echo "Compile coremark.wasm to coremark.aot .." ${WAMRC} -o coremark.aot coremark.wasm +if [[ ${PLATFORM} == "linux" ]]; then + echo "Compile coremark.wasm to coremark_segue.aot .." + ${WAMRC} --enable-segue -o coremark_segue.aot coremark.wasm +fi + echo "Done" diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/coremark/run.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/coremark/run.sh new file mode 100755 index 00000000000..0d308bb68b1 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/coremark/run.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +PLATFORM=$(uname -s | tr A-Z a-z) + +IWASM="../../../product-mini/platforms/${PLATFORM}/build/iwasm" +WAMRC="../../../wamr-compiler/build/wamrc" + +echo "Run coremark with native .." +./coremark.exe + +echo "Run coremark with iwasm aot mode .." +${IWASM} coremark.aot + +if [[ ${PLATFORM} == "linux" ]]; then + echo "Run coremark with iwasm aot-segue mode .." + ${IWASM} coremark_segue.aot +fi + +echo "Run coremark with iwasm interpreter mode .." +${IWASM} coremark.wasm diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/coremark/test_pgo.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/coremark/test_pgo.sh new file mode 100755 index 00000000000..1c631312e87 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/coremark/test_pgo.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +PLATFORM=$(uname -s | tr A-Z a-z) + +if [ "$1" = "--sgx" ] && [ "$PLATFORM" = "linux" ]; then + IWASM="../../../product-mini/platforms/${PLATFORM}-sgx/enclave-sample/iwasm" + WAMRC="../../../wamr-compiler/build/wamrc -sgx" +else + IWASM="../../../product-mini/platforms/${PLATFORM}/build/iwasm" + WAMRC="../../../wamr-compiler/build/wamrc" +fi + +if [ ! -e "coremark.wasm" ]; then + echo "coremark.wasm doesn't exist, please run build.sh first" + exit +fi + +echo "" +echo "Compile coremark.wasm to coremark.aot .." +${WAMRC} -o coremark.aot coremark.wasm + +echo "" +echo "Compile coremark.wasm to coremark_pgo.aot .." +${WAMRC} --enable-llvm-pgo -o coremark_pgo.aot coremark.wasm + +echo "" +echo "Run coremark_pgo.aot to generate the raw profile data .." +${IWASM} --gen-prof-file=coremark.profraw coremark_pgo.aot + +echo "" +echo "Merge the raw profile data to coremark.profdata .." +rm -f coremark.profdata && llvm-profdata merge -output=coremark.profdata coremark.profraw + +echo "" +echo "Compile coremark.wasm to coremark_opt.aot with the profile data .." +${WAMRC} --use-prof-file=coremark.profdata -o coremark_opt.aot coremark.wasm + +echo "" +echo "Run the coremark native" +./coremark.exe + +echo "" +echo "Run the original aot file coremark.aot" +${IWASM} coremark.aot + +echo "" +echo "Run the PGO optimized aot file coremark_opt.aot" +${IWASM} coremark_opt.aot + +# Show the profile data: +# llvm-profdata show --all-functions --detailed-summary --binary-ids --counts \ +# --hot-func-list --memop-sizes --show-prof-sym-list coremark.profraw diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/LICENSE b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/LICENSE new file mode 100644 index 00000000000..9b3a7b2ce9a --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/LICENSE @@ -0,0 +1,7 @@ +Dhrystone +------------------------------------------------------------------------------ +There is no explicit license defined. They were originally +written in ADA by Reinhold P. Weicker and translated to C by Rick Richardson . + +The source obtained from the following site: +https://fossies.org/linux/privat/old/dhrystone-2.1.tar.gz diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/build.sh new file mode 100755 index 00000000000..eea33d58493 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/build.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +PLATFORM=$(uname -s | tr A-Z a-z) + +WAMRC_CMD=$PWD/../../../wamr-compiler/build/wamrc + +echo "===> compile dhrystone src to dhrystone_native" +gcc -O3 -o dhrystone_native src/dhry_1.c src/dhry_2.c -I include + +echo "===> compile dhrystone src to dhrystone.wasm" +/opt/wasi-sdk/bin/clang -O3 \ + -o dhrystone.wasm src/dhry_1.c src/dhry_2.c -I include \ + -Wl,--export=__heap_base -Wl,--export=__data_end + +echo "===> compile dhrystone.wasm to dhrystone.aot" +${WAMRC_CMD} -o dhrystone.aot dhrystone.wasm + +if [[ ${PLATFORM} == "linux" ]]; then + echo "===> compile dhrystone.wasm to dhrystone_segue.aot" + ${WAMRC_CMD} --enable-segue -o dhrystone_segue.aot dhrystone.wasm +fi diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/include/dhry.h b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/include/dhry.h new file mode 100644 index 00000000000..0eb5ec64cfc --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/include/dhry.h @@ -0,0 +1,306 @@ +/* + ************************************************************************** + * DHRYSTONE 2.1 BENCHMARK PC VERSION + ************************************************************************** + * + * "DHRYSTONE" Benchmark Program + * ----------------------------- + * + * Version: C, Version 2.1 + * + * File: dhry.h (part 1 of 3) + * + * Date: May 25, 1988 + * + * Author: Reinhold P. Weicker + * Siemens AG, AUT E 51 + * Postfach 3220 + * 8520 Erlangen + * Germany (West) + * Phone: [+49]-9131-7-20330 + * (8-17 Central European Time) + * Usenet: ..!mcsun!unido!estevax!weicker + * + * Original Version (in Ada) published in + * "Communications of the ACM" vol. 27., no. 10 (Oct. 1984), + * pp. 1013 - 1030, together with the statistics + * on which the distribution of statements etc. is based. + * + * In this C version, the following C library functions are used: + * - strcpy, strcmp (inside the measurement loop) + * - printf, scanf (outside the measurement loop) + * In addition, Berkeley UNIX system calls "times ()" or "time ()" + * are used for execution time measurement. For measurements + * on other systems, these calls have to be changed. + * + * Collection of Results: + * Reinhold Weicker (address see above) and + * + * Rick Richardson + * PC Research. Inc. + * 94 Apple Orchard Drive + * Tinton Falls, NJ 07724 + * Phone: (201) 389-8963 (9-17 EST) + * Usenet: ...!uunet!pcrat!rick + * + * Please send results to Rick Richardson and/or Reinhold Weicker. + * Complete information should be given on hardware and software used. + * Hardware information includes: Machine type, CPU, type and size + * of caches; for microprocessors: clock frequency, memory speed + * (number of wait states). + * Software information includes: Compiler (and runtime library) + * manufacturer and version, compilation switches, OS version. + * The Operating System version may give an indication about the + * compiler; Dhrystone itself performs no OS calls in the measurement + * loop. + * + * The complete output generated by the program should be mailed + * such that at least some checks for correctness can be made. + * + ************************************************************************** + * + * This version has changes made by Roy Longbottom to conform to a common + * format for a series of standard benchmarks for PCs: + * + * Running time greater than 5 seconds due to inaccuracy of the PC clock. + * + * Automatic adjustment of run time, no manually inserted parameters. + * + * Initial display of calibration times to confirm linearity. + * + * Display of results within one screen (or at a slow speed as the test + * progresses) so that it can be seen to have run successfully. + * + * Facilities to type in details of system used etc. + * + * All results and details appended to a results file. + * + * + * Roy Longbottom + * 101323.2241@compuserve.com + * + ************************************************************************** + * + * For details of history, changes, other defines, benchmark construction + * statistics see official versions from ftp.nosc.mil/pub/aburto where + * the latest table of results (dhry.tbl) are available. See also + * netlib@ornl.gov + * + ************************************************************************** + * + * Defines: The following "Defines" are possible: + * -DREG=register (default: Not defined) + * As an approximation to what an average C programmer + * might do, the "register" storage class is applied + * (if enabled by -DREG=register) + * - for local variables, if they are used (dynamically) + * five or more times + * - for parameters if they are used (dynamically) + * six or more times + * Note that an optimal "register" strategy is + * compiler-dependent, and that "register" declarations + * do not necessarily lead to faster execution. + * -DNOSTRUCTASSIGN (default: Not defined) + * Define if the C compiler does not support + * assignment of structures. + * -DNOENUMS (default: Not defined) + * Define if the C compiler does not support + * enumeration types. + *************************************************************************** + * + * Compilation model and measurement (IMPORTANT): + * + * This C version of Dhrystone consists of three files: + * - dhry.h (this file, containing global definitions and comments) + * - dhry_1.c (containing the code corresponding to Ada package Pack_1) + * - dhry_2.c (containing the code corresponding to Ada package Pack_2) + * + * The following "ground rules" apply for measurements: + * - Separate compilation + * - No procedure merging + * - Otherwise, compiler optimizations are allowed but should be indicated + * - Default results are those without register declarations + * See the companion paper "Rationale for Dhrystone Version 2" for a more + * detailed discussion of these ground rules. + * + * For 16-Bit processors (e.g. 80186, 80286), times for all compilation + * models ("small", "medium", "large" etc.) should be given if possible, + * together with a definition of these models for the compiler system used. + * + ************************************************************************** + * Examples of Pentium Results + * + * Dhrystone Benchmark Version 2.1 (Language: C) + * + * Month run 4/1996 + * PC model Escom + * CPU Pentium + * Clock MHz 100 + * Cache 256K + * Options Neptune chipset + * OS/DOS Windows 95 + * Compiler Watcom C/ C++ 10.5 Win386 + * OptLevel -otexan -zp8 -fp5 -5r + * Run by Roy Longbottom + * From UK + * Mail 101323.2241@compuserve.com + * + * Final values (* implementation-dependent): + * + * Int_Glob: O.K. 5 + * Bool_Glob: O.K. 1 + * Ch_1_Glob: O.K. A + * Ch_2_Glob: O.K. B + * Arr_1_Glob[8]: O.K. 7 + * Arr_2_Glob8/7: O.K. 1600010 + * Ptr_Glob-> + * Ptr_Comp: * 98008 + * Discr: O.K. 0 + * Enum_Comp: O.K. 2 + * Int_Comp: O.K. 17 + * Str_Comp: O.K. DHRYSTONE PROGRAM, SOME STRING + * Next_Ptr_Glob-> + * Ptr_Comp: * 98008 same as above + * Discr: O.K. 0 + * Enum_Comp: O.K. 1 + * Int_Comp: O.K. 18 + * Str_Comp: O.K. DHRYSTONE PROGRAM, SOME STRING + * Int_1_Loc: O.K. 5 + * Int_2_Loc: O.K. 13 + * Int_3_Loc: O.K. 7 + * Enum_Loc: O.K. 1 + * Str_1_Loc: O.K. DHRYSTONE PROGRAM, 1'ST STRING + * Str_2_Loc: O.K. DHRYSTONE PROGRAM, 2'ND STRING + * + * Register option Selected. + * + * Microseconds 1 loop: 4.53 + * Dhrystones / second: 220690 + * VAX MIPS rating: 125.61 + * + * + * Dhrystone Benchmark Version 2.1 (Language: C) + * + * Month run 4/1996 + * PC model Escom + * CPU Pentium + * Clock MHz 100 + * Cache 256K + * Options Neptune chipset + * OS/DOS Windows 95 + * Compiler Watcom C/ C++ 10.5 Win386 + * OptLevel No optimisation + * Run by Roy Longbottom + * From UK + * Mail 101323.2241@compuserve.com + * + * Final values (* implementation-dependent): + * + * Int_Glob: O.K. 5 + * Bool_Glob: O.K. 1 + * Ch_1_Glob: O.K. A + * Ch_2_Glob: O.K. B + * Arr_1_Glob[8]: O.K. 7 + * Arr_2_Glob8/7: O.K. 320010 + * Ptr_Glob-> + * Ptr_Comp: * 98004 + * Discr: O.K. 0 + * Enum_Comp: O.K. 2 + * Int_Comp: O.K. 17 + * Str_Comp: O.K. DHRYSTONE PROGRAM, SOME STRING + * Next_Ptr_Glob-> + * Ptr_Comp: * 98004 same as above + * Discr: O.K. 0 + * Enum_Comp: O.K. 1 + * Int_Comp: O.K. 18 + * Str_Comp: O.K. DHRYSTONE PROGRAM, SOME STRING + * Int_1_Loc: O.K. 5 + * Int_2_Loc: O.K. 13 + * Int_3_Loc: O.K. 7 + * Enum_Loc: O.K. 1 + * Str_1_Loc: O.K. DHRYSTONE PROGRAM, 1'ST STRING + * Str_2_Loc: O.K. DHRYSTONE PROGRAM, 2'ND STRING + * + * Register option Not selected. + * + * Microseconds 1 loop: 20.06 + * Dhrystones / second: 49844 + * VAX MIPS rating: 28.37 + * + ************************************************************************** + */ + +/* Compiler and system dependent definitions: */ + +#ifndef TIME +#define TIMES +#endif +/* Use times(2) time function unless */ +/* explicitly defined otherwise */ + +#ifdef TIMES +/* #include + #include */ +/* for "times" */ +#endif + +#define Mic_secs_Per_Second 1000000.0 +/* Berkeley UNIX C returns process times in seconds/HZ */ + +#ifdef NOSTRUCTASSIGN +#define structassign(d, s) memcpy(&(d), &(s), sizeof(d)) +#else +#define structassign(d, s) d = s +#endif + +#ifdef NOENUM +#define Ident_1 0 +#define Ident_2 1 +#define Ident_3 2 +#define Ident_4 3 +#define Ident_5 4 +typedef int Enumeration; +#else +typedef enum { Ident_1, Ident_2, Ident_3, Ident_4, Ident_5 } Enumeration; +#endif +/* for boolean and enumeration types in Ada, Pascal */ + +/* General definitions: */ + +#include +#include + +/* for strcpy, strcmp */ + +#define Null 0 +/* Value of a Null pointer */ +#define true 1 +#define false 0 + +typedef int One_Thirty; +typedef int One_Fifty; +typedef char Capital_Letter; +typedef int Boolean; +typedef char Str_30[31]; +typedef int Arr_1_Dim[50]; +typedef int Arr_2_Dim[50][50]; + +typedef struct record { + struct record *Ptr_Comp; + Enumeration Discr; + union { + struct { + Enumeration Enum_Comp; + int Int_Comp; + char Str_Comp[31]; + } var_1; + struct { + Enumeration E_Comp_2; + char Str_2_Comp[31]; + } var_2; + struct { + char Ch_1_Comp; + char Ch_2_Comp; + } var_3; + } variant; +} Rec_Type, *Rec_Pointer; diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/run.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/run.sh new file mode 100755 index 00000000000..a9ac1d0b509 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/run.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +PLATFORM=$(uname -s | tr A-Z a-z) + +readonly IWASM_CMD="../../../product-mini/platforms/${PLATFORM}/build/iwasm" + +echo "============> run dhrystone native" +./dhrystone_native + +echo "============> run dhrystone.aot" +${IWASM_CMD} dhrystone.aot + +if [[ ${PLATFORM} == "linux" ]]; then + echo "============> run dhrystone_segue.aot" + ${IWASM_CMD} dhrystone_segue.aot +fi diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/src/dhry_1.c b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/src/dhry_1.c new file mode 100644 index 00000000000..92f6e7e8589 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/src/dhry_1.c @@ -0,0 +1,485 @@ +/* + ************************************************************************* + * + * "DHRYSTONE" Benchmark Program + * ----------------------------- + * + * Version: C, Version 2.1 + * + * File: dhry_1.c (part 2 of 3) + * + * Date: May 25, 1988 + * + * Author: Reinhold P. Weicker + * + ************************************************************************* + */ + +#include +#include +#include +#include "dhry.h" + +/* Global Variables: */ + +Rec_Pointer Ptr_Glob, Next_Ptr_Glob; +int Int_Glob; +Boolean Bool_Glob; +char Ch_1_Glob, Ch_2_Glob; +int Arr_1_Glob[50]; +int Arr_2_Glob[50][50]; + +Enumeration +Func_1(Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val); +/* +forward declaration necessary since Enumeration may not simply be int +*/ + +#ifndef ROPT +#define REG +/* REG becomes defined as empty */ +/* i.e. no register variables */ +#else +#define REG register +#endif + +void +Proc_1(REG Rec_Pointer Ptr_Val_Par); +void +Proc_2(One_Fifty *Int_Par_Ref); +void +Proc_3(Rec_Pointer *Ptr_Ref_Par); +void +Proc_4(); +void +Proc_5(); +void +Proc_6(Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par); +void +Proc_7(One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val, + One_Fifty *Int_Par_Ref); +void +Proc_8(Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, + int Int_2_Par_Val); + +Boolean +Func_2(Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref); + +/* variables for time measurement: */ + +#define Too_Small_Time 2 +/* Measurements should last at least 2 seconds */ + +#define BILLION 1000000000L +#define MILLION 1000000 +struct timespec Begin_Time, End_Time; +double User_Time; + +double Microseconds, Dhrystones_Per_Second, Vax_Mips; + +/* end of variables for time measurement */ + +int +main(int argc, char *argv[]) +/*****/ + +/* main program, corresponds to procedures */ +/* Main and Proc_0 in the Ada version */ +{ + One_Fifty Int_1_Loc; + REG One_Fifty Int_2_Loc; + One_Fifty Int_3_Loc; + REG char Ch_Index; + Enumeration Enum_Loc; + Str_30 Str_1_Loc; + Str_30 Str_2_Loc; + REG int Run_Index; + REG int Number_Of_Runs; + int endit, count = 10; + char general[9][80] = { " " }; + + /*********************************************************************** + * Change for compiler and optimisation used * + ***********************************************************************/ + + Next_Ptr_Glob = (Rec_Pointer)malloc(sizeof(Rec_Type)); + Ptr_Glob = (Rec_Pointer)malloc(sizeof(Rec_Type)); + + Ptr_Glob->Ptr_Comp = Next_Ptr_Glob; + Ptr_Glob->Discr = Ident_1; + Ptr_Glob->variant.var_1.Enum_Comp = Ident_3; + Ptr_Glob->variant.var_1.Int_Comp = 40; + strcpy(Ptr_Glob->variant.var_1.Str_Comp, "DHRYSTONE PROGRAM, SOME STRING"); + strcpy(Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING"); + + Arr_2_Glob[8][7] = 10; + /* Was missing in published program. Without this statement, */ + /* Arr_2_Glob [8][7] would have an undefined value. */ + /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */ + /* overflow may occur for this array element. */ + + printf("\n"); + printf("Dhrystone Benchmark, Version 2.1 (Language: C or C++)\n"); + printf("\n"); + + Number_Of_Runs = 5000; + + do { + + Number_Of_Runs = Number_Of_Runs * 2; + count = count - 1; + Arr_2_Glob[8][7] = 10; + + /***************/ + /* Start timer */ + /***************/ + + clock_gettime(CLOCK_MONOTONIC, &Begin_Time); + + for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index) { + + Proc_5(); + Proc_4(); + /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */ + Int_1_Loc = 2; + Int_2_Loc = 3; + strcpy(Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING"); + Enum_Loc = Ident_2; + Bool_Glob = !Func_2(Str_1_Loc, Str_2_Loc); + /* Bool_Glob == 1 */ + while (Int_1_Loc < Int_2_Loc) /* loop body executed once */ + { + Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc; + /* Int_3_Loc == 7 */ + Proc_7(Int_1_Loc, Int_2_Loc, &Int_3_Loc); + /* Int_3_Loc == 7 */ + Int_1_Loc += 1; + } /* while */ + /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */ + Proc_8(Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc); + /* Int_Glob == 5 */ + Proc_1(Ptr_Glob); + for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index) + /* loop body executed twice */ + { + if (Enum_Loc == Func_1(Ch_Index, 'C')) + /* then, not executed */ + { + Proc_6(Ident_1, &Enum_Loc); + strcpy(Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING"); + Int_2_Loc = Run_Index; + Int_Glob = Run_Index; + } + } + /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */ + Int_2_Loc = Int_2_Loc * Int_1_Loc; + Int_1_Loc = Int_2_Loc / Int_3_Loc; + Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc; + /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */ + Proc_2(&Int_1_Loc); + /* Int_1_Loc == 5 */ + + } /* loop "for Run_Index" */ + + /**************/ + /* Stop timer */ + /**************/ + + clock_gettime(CLOCK_MONOTONIC, &End_Time); + + User_Time = (End_Time.tv_sec - Begin_Time.tv_sec) * MILLION + + (End_Time.tv_nsec - Begin_Time.tv_nsec) / 1000; + User_Time = User_Time / MILLION; /* convert to seconds */ + + printf("%ld runs %lf seconds \n", (long)Number_Of_Runs, User_Time); + if (User_Time > 5.0) { + count = 0; + } + else { + if (User_Time < 0.1) { + Number_Of_Runs = Number_Of_Runs * 5; + } + } + } /* calibrate/run do while */ + while (count > 0); + + printf("\n"); + printf("Final values (* implementation-dependent):\n"); + printf("\n"); + printf("Int_Glob: "); + if (Int_Glob == 5) + printf("O.K. "); + else + printf("WRONG "); + printf("%d ", Int_Glob); + + printf("Bool_Glob: "); + if (Bool_Glob == 1) + printf("O.K. "); + else + printf("WRONG "); + printf("%d\n", Bool_Glob); + + printf("Ch_1_Glob: "); + if (Ch_1_Glob == 'A') + printf("O.K. "); + else + printf("WRONG "); + printf("%c ", Ch_1_Glob); + + printf("Ch_2_Glob: "); + if (Ch_2_Glob == 'B') + printf("O.K. "); + else + printf("WRONG "); + printf("%c\n", Ch_2_Glob); + + printf("Arr_1_Glob[8]: "); + if (Arr_1_Glob[8] == 7) + printf("O.K. "); + else + printf("WRONG "); + printf("%d ", Arr_1_Glob[8]); + + printf("Arr_2_Glob8/7: "); + if (Arr_2_Glob[8][7] == Number_Of_Runs + 10) + printf("O.K. "); + else + printf("WRONG "); + printf("%10d\n", Arr_2_Glob[8][7]); + + printf("Ptr_Glob-> "); + printf(" Ptr_Comp: * %p\n", Ptr_Glob->Ptr_Comp); + + printf(" Discr: "); + if (Ptr_Glob->Discr == 0) + printf("O.K. "); + else + printf("WRONG "); + printf("%d ", Ptr_Glob->Discr); + + printf("Enum_Comp: "); + if (Ptr_Glob->variant.var_1.Enum_Comp == 2) + printf("O.K. "); + else + printf("WRONG "); + printf("%d\n", Ptr_Glob->variant.var_1.Enum_Comp); + + printf(" Int_Comp: "); + if (Ptr_Glob->variant.var_1.Int_Comp == 17) + printf("O.K. "); + else + printf("WRONG "); + printf("%d ", Ptr_Glob->variant.var_1.Int_Comp); + + printf("Str_Comp: "); + if (strcmp(Ptr_Glob->variant.var_1.Str_Comp, + "DHRYSTONE PROGRAM, SOME STRING") + == 0) + printf("O.K. "); + else + printf("WRONG "); + printf("%s\n", Ptr_Glob->variant.var_1.Str_Comp); + + printf("Next_Ptr_Glob-> "); + printf(" Ptr_Comp: * %p", Next_Ptr_Glob->Ptr_Comp); + printf(" same as above\n"); + + printf(" Discr: "); + if (Next_Ptr_Glob->Discr == 0) + printf("O.K. "); + else + printf("WRONG "); + printf("%d ", Next_Ptr_Glob->Discr); + + printf("Enum_Comp: "); + if (Next_Ptr_Glob->variant.var_1.Enum_Comp == 1) + printf("O.K. "); + else + printf("WRONG "); + printf("%d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp); + + printf(" Int_Comp: "); + if (Next_Ptr_Glob->variant.var_1.Int_Comp == 18) + printf("O.K. "); + else + printf("WRONG "); + printf("%d ", Next_Ptr_Glob->variant.var_1.Int_Comp); + + printf("Str_Comp: "); + if (strcmp(Next_Ptr_Glob->variant.var_1.Str_Comp, + "DHRYSTONE PROGRAM, SOME STRING") + == 0) + printf("O.K. "); + else + printf("WRONG "); + printf("%s\n", Next_Ptr_Glob->variant.var_1.Str_Comp); + + printf("Int_1_Loc: "); + if (Int_1_Loc == 5) + printf("O.K. "); + else + printf("WRONG "); + printf("%d ", Int_1_Loc); + + printf("Int_2_Loc: "); + if (Int_2_Loc == 13) + printf("O.K. "); + else + printf("WRONG "); + printf("%d\n", Int_2_Loc); + + printf("Int_3_Loc: "); + if (Int_3_Loc == 7) + printf("O.K. "); + else + printf("WRONG "); + printf("%d ", Int_3_Loc); + + printf("Enum_Loc: "); + if (Enum_Loc == 1) + printf("O.K. "); + else + printf("WRONG "); + printf("%d\n", Enum_Loc); + + printf("Str_1_Loc: "); + if (strcmp(Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING") == 0) + printf("O.K. "); + else + printf("WRONG "); + printf("%s\n", Str_1_Loc); + + printf("Str_2_Loc: "); + if (strcmp(Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING") == 0) + printf("O.K. "); + else + printf("WRONG "); + printf("%s\n", Str_2_Loc); + + printf("\n"); + + if (User_Time < Too_Small_Time) { + printf("Measured time too small to obtain meaningful results\n"); + printf("Please increase number of runs\n"); + printf("\n"); + } + else { + Microseconds = User_Time * Mic_secs_Per_Second / (double)Number_Of_Runs; + Dhrystones_Per_Second = (double)Number_Of_Runs / User_Time; + Vax_Mips = Dhrystones_Per_Second / 1757.0; + + printf("Microseconds for one run through Dhrystone: "); + printf("%lf \n", Microseconds); + printf("Dhrystones per Second: "); + printf("%lf \n", Dhrystones_Per_Second); + printf("VAX MIPS rating = "); + printf("%lf \n", Vax_Mips); + printf("\n"); + } + + free(Next_Ptr_Glob); + free(Ptr_Glob); + return 1; +} + +void +Proc_1(REG Rec_Pointer Ptr_Val_Par) +/******************/ + +/* executed once */ +{ + REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp; + /* == Ptr_Glob_Next */ + /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */ + /* corresponds to "rename" in Ada, "with" in Pascal */ + + structassign(*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob); + Ptr_Val_Par->variant.var_1.Int_Comp = 5; + Next_Record->variant.var_1.Int_Comp = Ptr_Val_Par->variant.var_1.Int_Comp; + Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp; + Proc_3(&Next_Record->Ptr_Comp); + /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp + == Ptr_Glob->Ptr_Comp */ + if (Next_Record->Discr == Ident_1) + /* then, executed */ + { + Next_Record->variant.var_1.Int_Comp = 6; + Proc_6(Ptr_Val_Par->variant.var_1.Enum_Comp, + &Next_Record->variant.var_1.Enum_Comp); + Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp; + Proc_7(Next_Record->variant.var_1.Int_Comp, 10, + &Next_Record->variant.var_1.Int_Comp); + } + else { /* not executed */ + structassign(*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp); + } +} /* Proc_1 */ + +void +Proc_2(One_Fifty *Int_Par_Ref) +/******************/ +/* executed once */ +/* *Int_Par_Ref == 1, becomes 4 */ + +{ + One_Fifty Int_Loc; + Enumeration Enum_Loc; + + Int_Loc = *Int_Par_Ref + 10; + do /* executed once */ + if (Ch_1_Glob == 'A') + /* then, executed */ + { + Int_Loc -= 1; + *Int_Par_Ref = Int_Loc - Int_Glob; + Enum_Loc = Ident_1; + } /* if */ + while (Enum_Loc != Ident_1); /* true */ +} /* Proc_2 */ + +void +Proc_3(Rec_Pointer *Ptr_Ref_Par) +/******************/ +/* executed once */ +/* Ptr_Ref_Par becomes Ptr_Glob */ + +{ + if (Ptr_Glob != Null) + /* then, executed */ + *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp; + Proc_7(10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp); +} /* Proc_3 */ + +void +Proc_4() /* without parameters */ +/*******/ +/* executed once */ +{ + Boolean Bool_Loc; + + Bool_Loc = Ch_1_Glob == 'A'; + Bool_Glob = Bool_Loc | Bool_Glob; + Ch_2_Glob = 'B'; +} /* Proc_4 */ + +void +Proc_5() /* without parameters */ +/*******/ +/* executed once */ +{ + Ch_1_Glob = 'A'; + Bool_Glob = false; +} /* Proc_5 */ + +/* Procedure for the assignment of structures, */ +/* if the C compiler doesn't support this feature */ +#ifdef NOSTRUCTASSIGN +memcpy(d, s, l) register char *d; +register char *s; +register int l; +{ + while (l--) + *d++ = *s++; +} +#endif diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/src/dhry_2.c b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/src/dhry_2.c new file mode 100644 index 00000000000..5378799ebe3 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/src/dhry_2.c @@ -0,0 +1,187 @@ +/* + ************************************************************************* + * + * "DHRYSTONE" Benchmark Program + * ----------------------------- + * + * Version: C, Version 2.1 + * + * File: dhry_2.c (part 3 of 3) + * + * Date: May 25, 1988 + * + * Author: Reinhold P. Weicker + * + ************************************************************************* + */ + +#include "dhry.h" + +#ifndef REG +#define REG +/* REG becomes defined as empty */ +/* i.e. no register variables */ +#else +#define REG register +#endif + +extern int Int_Glob; +extern char Ch_1_Glob; + +Boolean +Func_3(Enumeration Enum_Par_Val); + +void +Proc_6(Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par) +/*********************************/ +/* executed once */ +/* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */ + +{ + *Enum_Ref_Par = Enum_Val_Par; + if (!Func_3(Enum_Val_Par)) + /* then, not executed */ + *Enum_Ref_Par = Ident_4; + switch (Enum_Val_Par) { + case Ident_1: + *Enum_Ref_Par = Ident_1; + break; + case Ident_2: + if (Int_Glob > 100) + /* then */ + *Enum_Ref_Par = Ident_1; + else + *Enum_Ref_Par = Ident_4; + break; + case Ident_3: /* executed */ + *Enum_Ref_Par = Ident_2; + break; + case Ident_4: + break; + case Ident_5: + *Enum_Ref_Par = Ident_3; + break; + } /* switch */ +} /* Proc_6 */ + +void +Proc_7(One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val, One_Fifty *Int_Par_Ref) +/**********************************************/ +/* executed three times */ +/* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */ +/* Int_Par_Ref becomes 7 */ +/* second call: Int_1_Par_Val == 10, Int_2_Par_Val == 5, */ +/* Int_Par_Ref becomes 17 */ +/* third call: Int_1_Par_Val == 6, Int_2_Par_Val == 10, */ +/* Int_Par_Ref becomes 18 */ + +{ + One_Fifty Int_Loc; + + Int_Loc = Int_1_Par_Val + 2; + *Int_Par_Ref = Int_2_Par_Val + Int_Loc; +} /* Proc_7 */ + +void +Proc_8(Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, + int Int_2_Par_Val) +/*********************************************************************/ +/* executed once */ +/* Int_Par_Val_1 == 3 */ +/* Int_Par_Val_2 == 7 */ + +{ + REG One_Fifty Int_Index; + REG One_Fifty Int_Loc; + + Int_Loc = Int_1_Par_Val + 5; + Arr_1_Par_Ref[Int_Loc] = Int_2_Par_Val; + Arr_1_Par_Ref[Int_Loc + 1] = Arr_1_Par_Ref[Int_Loc]; + Arr_1_Par_Ref[Int_Loc + 30] = Int_Loc; + for (Int_Index = Int_Loc; Int_Index <= Int_Loc + 1; ++Int_Index) + Arr_2_Par_Ref[Int_Loc][Int_Index] = Int_Loc; + Arr_2_Par_Ref[Int_Loc][Int_Loc - 1] += 1; + Arr_2_Par_Ref[Int_Loc + 20][Int_Loc] = Arr_1_Par_Ref[Int_Loc]; + Int_Glob = 5; +} /* Proc_8 */ + +Enumeration +Func_1(Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val) +/*************************************************/ +/* executed three times */ +/* first call: Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R' */ +/* second call: Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C' */ +/* third call: Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C' */ + +{ + Capital_Letter Ch_1_Loc; + Capital_Letter Ch_2_Loc; + + Ch_1_Loc = Ch_1_Par_Val; + Ch_2_Loc = Ch_1_Loc; + if (Ch_2_Loc != Ch_2_Par_Val) + /* then, executed */ + return (Ident_1); + else /* not executed */ + { + Ch_1_Glob = Ch_1_Loc; + return (Ident_2); + } +} /* Func_1 */ + +Boolean +Func_2(Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref) +/*************************************************/ +/* executed once */ +/* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */ +/* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */ + +{ + REG One_Thirty Int_Loc; + Capital_Letter Ch_Loc; + + Int_Loc = 2; + while (Int_Loc <= 2) /* loop body executed once */ + if (Func_1(Str_1_Par_Ref[Int_Loc], Str_2_Par_Ref[Int_Loc + 1]) + == Ident_1) + /* then, executed */ + { + Ch_Loc = 'A'; + Int_Loc += 1; + } /* if, while */ + if (Ch_Loc >= 'W' && Ch_Loc < 'Z') + /* then, not executed */ + Int_Loc = 7; + if (Ch_Loc == 'R') + /* then, not executed */ + return (true); + else /* executed */ + { + if (strcmp(Str_1_Par_Ref, Str_2_Par_Ref) > 0) + /* then, not executed */ + { + Int_Loc += 7; + Int_Glob = Int_Loc; + return (true); + } + else /* executed */ + return (false); + } /* if Ch_Loc */ +} /* Func_2 */ + +Boolean +Func_3(Enumeration Enum_Par_Val) +/***************************/ +/* executed once */ +/* Enum_Par_Val == Ident_3 */ + +{ + Enumeration Enum_Loc; + + Enum_Loc = Enum_Par_Val; + if (Enum_Loc == Ident_3) + /* then, executed */ + return (true); + else /* not executed */ + return (false); +} /* Func_3 */ diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/test_pgo.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/test_pgo.sh new file mode 100755 index 00000000000..8bca1975722 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/dhrystone/test_pgo.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +PLATFORM=$(uname -s | tr A-Z a-z) + +if [ "$1" = "--sgx" ] && [ "$PLATFORM" = "linux" ]; then + IWASM="../../../product-mini/platforms/${PLATFORM}-sgx/enclave-sample/iwasm" + WAMRC="../../../wamr-compiler/build/wamrc -sgx" +else + IWASM="../../../product-mini/platforms/${PLATFORM}/build/iwasm" + WAMRC="../../../wamr-compiler/build/wamrc" +fi + +if [ ! -e "dhrystone.wasm" ]; then + echo "dhrystone.wasm doesn't exist, please run build.sh first" + exit +fi + +echo "" +echo "Compile dhrystone.wasm to dhrystone.aot .." +${WAMRC} -o dhrystone.aot dhrystone.wasm + +echo "" +echo "Compile dhrystone.wasm to dhrystone_pgo.aot .." +${WAMRC} --enable-llvm-pgo -o dhrystone_pgo.aot dhrystone.wasm + +echo "" +echo "Run dhrystone_pgo.aot to generate the raw profile data .." +${IWASM} --gen-prof-file=dhrystone.profraw dhrystone_pgo.aot + +echo "" +echo "Merge the raw profile data to dhrystone.profdata .." +rm -f dhrystone.profdata && llvm-profdata merge -output=dhrystone.profdata dhrystone.profraw + +echo "" +echo "Compile dhrystone.wasm to dhrystone_opt.aot with the profile data .." +${WAMRC} --use-prof-file=dhrystone.profdata -o dhrystone_opt.aot dhrystone.wasm + +echo "" +echo "Run the dhrystone native" +./dhrystone_native + +echo "" +echo "Run the original aot file dhrystone.aot" +${IWASM} dhrystone.aot + +echo "" +echo "Run the PGO optimized aot file dhrystone_opt.aot" +${IWASM} dhrystone_opt.aot + +# Show the profile data: +# llvm-profdata show --all-functions --detailed-summary --binary-ids --counts \ +# --hot-func-list --memop-sizes --show-prof-sym-list dhrystone.profraw diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/jetstream/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/README.md similarity index 68% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/jetstream/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/README.md index f6c593d1168..1bf438c2b72 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/jetstream/README.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/README.md @@ -27,3 +27,9 @@ And then run `./build.sh` to build the source code, the folder `out` will be cre # Running Run `./run_aot.sh` to test the benchmark, the native mode and iwasm aot mode will be tested for each workload, and the file `report.txt` will be generated. + +Run `./test_pgo.sh` to test the benchmark with AOT static PGO (Profile-Guided Optimization) enabled, please refer [here](../README.md#install-llvm-profdata) to install tool `llvm-profdata` and build `iwasm` with `cmake -DWAMR_BUILD_STATIC_PGO=1`. + +- For Linux, build `iwasm` with `cmake -DWAMR_BUILD_STATIC_PGO=1`, then run `./test_pgo.sh` to test the benchmark with AOT static PGO (Profile-Guided Optimization) enabled. + +- For Linux-sgx, similarly, build `iwasm` with `cmake -DWAMR_BUILD_STATIC_PGO=1`, then `make` in the directory `enclave-sample`. And run `./test_pgo.sh --sgx` to test the benchmark. diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/build.sh new file mode 100755 index 00000000000..ca8401cdab9 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/build.sh @@ -0,0 +1,174 @@ +#!/bin/bash + +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +source /opt/emsdk/emsdk_env.sh + +PLATFORM=$(uname -s | tr A-Z a-z) + +OUT_DIR=$PWD/out +WAMRC_CMD=$PWD/../../../wamr-compiler/build/wamrc + +mkdir -p jetstream +mkdir -p tsf-src +mkdir -p ${OUT_DIR} + +if [[ $1 != "--no-simd" ]];then + NATIVE_SIMD_FLAGS="-msse2 -msse3 -msse4" + WASM_SIMD_FLAGS="-msimd128 -msse2 -msse3 -msse4" +else + NATIVE_SIMD_FLAGS="" + WASM_SIMD_FLAGS="" +fi + +cd jetstream + +echo "Download source files .." +wget -N https://browserbench.org/JetStream/wasm/gcc-loops.cpp +wget -N https://browserbench.org/JetStream/wasm/quicksort.c +wget -N https://browserbench.org/JetStream/wasm/HashSet.cpp +wget -N https://browserbench.org/JetStream/simple/float-mm.c + +if [[ $? != 0 ]]; then + exit +fi + +echo "Patch source files .." +patch -p1 -N < ../jetstream.patch + +echo "Build gcc-loops with g++ .." +g++ -O3 ${NATIVE_SIMD_FLAGS} -o ${OUT_DIR}/gcc-loops_native gcc-loops.cpp + +echo "Build gcc-loops with em++ .." +em++ -O3 -s STANDALONE_WASM=1 ${WASM_SIMD_FLAGS} \ + -s INITIAL_MEMORY=1048576 \ + -s TOTAL_STACK=32768 \ + -s "EXPORTED_FUNCTIONS=['_main']" \ + -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ + -o ${OUT_DIR}/gcc-loops.wasm gcc-loops.cpp + +echo "Compile gcc-loops.wasm to gcc-loops.aot" +${WAMRC_CMD} -o ${OUT_DIR}/gcc-loops.aot ${OUT_DIR}/gcc-loops.wasm + +if [[ ${PLATFORM} == "linux" ]]; then + echo "Compile gcc-loops.wasm to gcc-loops_segue.aot" + ${WAMRC_CMD} --enable-segue -o ${OUT_DIR}/gcc-loops_segue.aot ${OUT_DIR}/gcc-loops.wasm +fi + +echo "Build quicksort with gcc .." +gcc -O3 ${NATIVE_SIMD_FLAGS} -o ${OUT_DIR}/quicksort_native quicksort.c + +echo "Build quicksort with emcc .." +emcc -O3 -s STANDALONE_WASM=1 ${WASM_SIMD_FLAGS} \ + -s INITIAL_MEMORY=1048576 \ + -s TOTAL_STACK=32768 \ + -s "EXPORTED_FUNCTIONS=['_main']" \ + -o ${OUT_DIR}/quicksort.wasm quicksort.c + +echo "Compile quicksort.wasm to quicksort.aot" +${WAMRC_CMD} -o ${OUT_DIR}/quicksort.aot ${OUT_DIR}/quicksort.wasm + +if [[ ${PLATFORM} == "linux" ]]; then + echo "Compile quicksort.wasm to quicksort_segue.aot" + ${WAMRC_CMD} --enable-segue -o ${OUT_DIR}/quicksort_segue.aot ${OUT_DIR}/quicksort.wasm +fi + +echo "Build HashSet with g++ .." +g++ -O3 ${NATIVE_SIMD_FLAGS} -o ${OUT_DIR}/HashSet_native HashSet.cpp \ + -lstdc++ + +echo "Build HashSet with em++ .." +em++ -O3 -s STANDALONE_WASM=1 ${WASM_SIMD_FLAGS} \ + -s INITIAL_MEMORY=1048576 \ + -s TOTAL_STACK=32768 \ + -s "EXPORTED_FUNCTIONS=['_main']" \ + -o ${OUT_DIR}/HashSet.wasm HashSet.cpp + +echo "Compile HashSet.wasm to HashSet.aot" +${WAMRC_CMD} -o ${OUT_DIR}/HashSet.aot ${OUT_DIR}/HashSet.wasm + +if [[ ${PLATFORM} == "linux" ]]; then + echo "Compile HashSet.wasm to HashSet_segue.aot" + ${WAMRC_CMD} --enable-segue -o ${OUT_DIR}/HashSet_segue.aot ${OUT_DIR}/HashSet.wasm +fi + +echo "Build float-mm with gcc .." +gcc -O3 ${NATIVE_SIMD_FLAGS} -o ${OUT_DIR}/float-mm_native float-mm.c + +echo "Build float-mm with emcc .." +emcc -O3 -s STANDALONE_WASM=1 ${WASM_SIMD_FLAGS} \ + -s INITIAL_MEMORY=1048576 \ + -s TOTAL_STACK=32768 \ + -s "EXPORTED_FUNCTIONS=['_main']" \ + -o ${OUT_DIR}/float-mm.wasm float-mm.c + +echo "Compile float-mm.wasm to float-mm.aot" +${WAMRC_CMD} -o ${OUT_DIR}/float-mm.aot ${OUT_DIR}/float-mm.wasm + +if [[ ${PLATFORM} == "linux" ]]; then + echo "Compile float-mm.wasm to float-mm_segue.aot" + ${WAMRC_CMD} --enable-segue -o ${OUT_DIR}/float-mm_segue.aot ${OUT_DIR}/float-mm.wasm +fi + +cd ../tsf-src + +tsf_srcs="tsf_asprintf.c tsf_buffer.c tsf_error.c tsf_reflect.c tsf_st.c \ + tsf_type.c tsf_io.c tsf_native.c tsf_generator.c tsf_st_typetable.c \ + tsf_parser.c tsf_buf_writer.c tsf_buf_reader.c tsf_primitive.c \ + tsf_type_table.c tsf_copier.c tsf_destructor.c tsf_gpc_code_gen.c \ + gpc_code_gen_util.c gpc_threaded.c gpc_intable.c gpc_instruction.c \ + gpc_program.c gpc_proto.c gpc_stack_height.c tsf_serial_in_man.c \ + tsf_serial_out_man.c tsf_type_in_map.c tsf_type_out_map.c \ + tsf_stream_file_input.c tsf_stream_file_output.c tsf_sort.c \ + tsf_version.c tsf_named_type.c tsf_io_utils.c tsf_zip_attr.c \ + tsf_zip_reader.c tsf_zip_writer.c tsf_zip_abstract.c tsf_limits.c \ + tsf_ra_type_man.c tsf_adaptive_reader.c tsf_sha1.c tsf_sha1_writer.c \ + tsf_fsdb.c tsf_fsdb_protocol.c tsf_define_helpers.c tsf_ir.c \ + tsf_ir_different.c tsf_ir_speed.c" + +tsf_files="${tsf_srcs} config.h gpc_worklist.h \ + tsf_config_stub.h tsf.h tsf_internal.h tsf_region.h tsf_types.h \ + gpc.h tsf_atomics.h tsf_define_helpers.h tsf_indent.h tsf_inttypes.h \ + tsf_serial_protocol.h tsf_util.h gpc_int_common.h tsf_build_defines.h \ + tsf_format.h tsf_internal_config.h tsf_ir_different.h tsf_sha1.h \ + tsf_zip_abstract.h gpc_internal.h tsf_config.h tsf_fsdb_protocol.h \ + tsf_internal_config_stub.h tsf_ir.h tsf_st.h \ + gpc_instruction_dispatch.gen gpc_instruction_stack_effects.gen \ + gpc_instruction_to_string.gen gpc_instruction_size.gen \ + gpc_instruction_static_size.gen gpc_interpreter.gen" + +echo "Download tsf source files .." +for t in ${tsf_files} +do + wget -N "https://browserbench.org/JetStream/wasm/TSF/${t}" + if [[ $? != 0 ]]; then + exit + fi +done + +patch -p1 -N < ../tsf.patch + +echo "Build tsf with gcc .." +gcc \ + -o ${OUT_DIR}/tsf_native -O3 ${NATIVE_SIMD_FLAGS} \ + -I. -DTSF_BUILD_SYSTEM=1 \ + ${tsf_srcs} -lm + +echo "Build tsf standalone with wasi-sdk .." +/opt/wasi-sdk/bin/clang -O3 ${WASM_SIMD_FLAGS} -z stack-size=1048576 \ + -Wl,--initial-memory=52428800 \ + -Wl,--export=main \ + -Wl,--export=__heap_base,--export=__data_end \ + -I. -DTSF_BUILD_SYSTEM=1 \ + -Wl,--allow-undefined \ + -o ${OUT_DIR}/tsf.wasm \ + ${tsf_srcs} + +echo "Compile tsf.wasm to tsf.aot" +${WAMRC_CMD} -o ${OUT_DIR}/tsf.aot ${OUT_DIR}/tsf.wasm + +if [[ ${PLATFORM} == "linux" ]]; then + echo "Compile tsf.wasm to tsf_segue.aot" + ${WAMRC_CMD} --enable-segue -o ${OUT_DIR}/tsf_segue.aot ${OUT_DIR}/tsf.wasm +fi diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/jetstream/jetstream.patch b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/jetstream.patch similarity index 69% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/jetstream/jetstream.patch rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/jetstream.patch index 34431de086f..bc680d98a1d 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/jetstream/jetstream.patch +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/jetstream.patch @@ -1,15 +1,18 @@ diff -urN jetstream-org/HashSet.cpp jetstream/HashSet.cpp ---- jetstream-org/HashSet.cpp 2020-10-30 04:12:42.000000000 +0800 -+++ jetstream/HashSet.cpp 2022-01-24 17:11:08.619831711 +0800 -@@ -24,6 +24,7 @@ +--- jetstream-org/HashSet.cpp 2020-10-30 04:12:42.000000000 +0800 ++++ jetstream/HashSet.cpp 2022-01-24 17:11:08.619831711 +0800 +@@ -22,8 +22,10 @@ + + #include #include ++#include #include #include +#include #include - + // Compile with: xcrun clang++ -o HashSet HashSet.cpp -O2 -W -framework Foundation -licucore -std=c++11 -fvisibility=hidden -DNDEBUG=1 -@@ -76,7 +77,7 @@ +@@ -76,7 +78,7 @@ inline ToType bitwise_cast(FromType from) { typename std::remove_const::type to { }; @@ -17,4 +20,4 @@ diff -urN jetstream-org/HashSet.cpp jetstream/HashSet.cpp + memcpy(&to, &from, sizeof(to)); return to; } - + diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/jetstream/run_aot.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/run_aot.sh similarity index 62% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/jetstream/run_aot.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/run_aot.sh index d62a5da900d..85ef3fba5c8 100755 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/jetstream/run_aot.sh +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/run_aot.sh @@ -3,6 +3,8 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +PLATFORM=$(uname -s | tr A-Z a-z) + CUR_DIR=$PWD OUT_DIR=$CUR_DIR/out REPORT=$CUR_DIR/report.txt @@ -13,7 +15,7 @@ IWASM_CMD=$CUR_DIR/../../../product-mini/platforms/${PLATFORM}/build/iwasm BENCH_NAME_MAX_LEN=20 -JETSTREAM_CASES="gcc-loops quicksort HashSet float-mm" +JETSTREAM_CASES="gcc-loops HashSet tsf float-mm quicksort" rm -f $REPORT touch $REPORT @@ -34,7 +36,11 @@ echo "Start to run cases, the result is written to report.txt" #run benchmarks cd $OUT_DIR -echo -en "\t\t\t\t\t native\tiwasm-aot\n" >> $REPORT +if [[ ${PLATFORM} == "linux" ]]; then + echo -en "\t\t\t\t\t native\tiwasm-aot\tiwasm-aot-segue\n" >> $REPORT +else + echo -en "\t\t\t\t\t native\tiwasm-aot\n" >> $REPORT +fi for t in $JETSTREAM_CASES do @@ -46,7 +52,13 @@ do echo "run $t with iwasm aot .." echo -en "\t" >> $REPORT - $TIME -f "real-%e-time" $IWASM_CMD ${t}.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT + $TIME -f "real-%e-time" $IWASM_CMD --dir=. ${t}.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT + + if [[ ${PLATFORM} == "linux" ]]; then + echo "run $t with iwasm aot segue .." + echo -en "\t" >> $REPORT + $TIME -f "real-%e-time" $IWASM_CMD --dir=. ${t}_segue.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT + fi echo -en "\n" >> $REPORT done diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/test_pgo.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/test_pgo.sh new file mode 100755 index 00000000000..a1101821225 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/test_pgo.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +CUR_DIR=$PWD +OUT_DIR=$CUR_DIR/out +REPORT=$CUR_DIR/report.txt +TIME=/usr/bin/time + +PLATFORM=$(uname -s | tr A-Z a-z) +if [ "$1" = "--sgx" ] && [ "$PLATFORM" = "linux" ]; then + IWASM_CMD="$CUR_DIR/../../../product-mini/platforms/${PLATFORM}-sgx/enclave-sample/iwasm" + WAMRC_CMD="$CUR_DIR/../../../wamr-compiler/build/wamrc -sgx" +else + IWASM_CMD="$CUR_DIR/../../../product-mini/platforms/${PLATFORM}/build/iwasm" + WAMRC_CMD="$CUR_DIR/../../../wamr-compiler/build/wamrc" +fi + +BENCH_NAME_MAX_LEN=20 + +JETSTREAM_CASES="gcc-loops HashSet tsf float-mm quicksort" + +rm -f $REPORT +touch $REPORT + +function print_bench_name() +{ + name=$1 + echo -en "$name" >> $REPORT + name_len=${#name} + if [ $name_len -lt $BENCH_NAME_MAX_LEN ] + then + spaces=$(( $BENCH_NAME_MAX_LEN - $name_len )) + for i in $(eval echo "{1..$spaces}"); do echo -n " " >> $REPORT; done + fi +} + +pushd $OUT_DIR > /dev/null 2>&1 +for t in $JETSTREAM_CASES +do + if [ ! -e "${t}.wasm" ]; then + echo "${t}.wasm doesn't exist, please run build.sh first" + exit + fi + + echo "" + echo "Compile ${t}.wasm to ${t}.aot .." + ${WAMRC_CMD} -o ${t}.aot ${t}.wasm + + echo "" + echo "Compile ${t}.wasm to ${t}_pgo.aot .." + ${WAMRC_CMD} --enable-llvm-pgo -o ${t}_pgo.aot ${t}.wasm + + echo "" + echo "Run ${t}_pgo.aot to generate the raw profile data .." + ${IWASM_CMD} --gen-prof-file=${t}.profraw --dir=. ${t}_pgo.aot + + echo "" + echo "Merge the raw profile data to ${t}.profdata .." + rm -f ${t}.profdata && llvm-profdata merge -output=${t}.profdata ${t}.profraw + + echo "" + echo "Compile ${t}.wasm to ${t}_opt.aot with the profile data .." + ${WAMRC_CMD} --use-prof-file=${t}.profdata -o ${t}_opt.aot ${t}.wasm +done +popd > /dev/null 2>&1 + +echo "Start to run cases, the result is written to report.txt" + +#run benchmarks +cd $OUT_DIR +echo -en "\t\t\t\t\t native\tiwasm-aot\tiwasm-aot-pgo\n" >> $REPORT + +for t in $JETSTREAM_CASES +do + print_bench_name $t + + echo "run $t with native .." + echo -en "\t" >> $REPORT + $TIME -f "real-%e-time" ./${t}_native 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT + + echo "run $t with iwasm aot .." + echo -en "\t" >> $REPORT + $TIME -f "real-%e-time" $IWASM_CMD --dir=. ${t}.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT + + echo "run $t with iwasm aot opt .." + echo -en "\t" >> $REPORT + $TIME -f "real-%e-time" $IWASM_CMD --dir=. ${t}_opt.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT + + echo -en "\n" >> $REPORT +done diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/tsf.patch b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/tsf.patch new file mode 100644 index 00000000000..98355b08cfe --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/jetstream/tsf.patch @@ -0,0 +1,36 @@ +diff -urN tsf-src-org/gpc_code_gen_util.c tsf-src/gpc_code_gen_util.c +--- tsf-src-org/gpc_code_gen_util.c 2023-09-21 11:12:40.211166472 +0800 ++++ tsf-src/gpc_code_gen_util.c 2023-09-21 11:09:13.643170967 +0800 +@@ -34,6 +34,8 @@ + #include + #include + ++int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result); ++ + /* code generation debugging */ + + /* NOTE: It is now the case that the count may be incremented multiple times, +diff -urN tsf-src-org/tsf_internal.h tsf-src/tsf_internal.h +--- tsf-src-org/tsf_internal.h 2023-09-21 11:11:50.843167546 +0800 ++++ tsf-src/tsf_internal.h 2023-09-21 11:06:53.031174027 +0800 +@@ -429,6 +429,7 @@ + #endif + tsf_fsdb_connection_t *connection; + #endif ++ uint32_t __padding; + } remote; + } u; + tsf_limits_t *limits; +diff -urN tsf-src-org/tsf_ir_speed.c tsf-src/tsf_ir_speed.c +--- tsf-src-org/tsf_ir_speed.c 2023-09-21 11:12:15.699167005 +0800 ++++ tsf-src/tsf_ir_speed.c 2023-09-21 11:06:53.031174027 +0800 +@@ -63,6 +63,9 @@ + Program_t *program; + unsigned elementIndex; + ++ if (!(programIndex % 100)) ++ printf("##programIndex: %u\n", programIndex); ++ + CS(program = tsf_region_create(sizeof(Program_t))); + + program->globals.len = numDecls + numDefns; diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/libsodium/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/libsodium/README.md similarity index 66% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/libsodium/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/libsodium/README.md index 19500afe615..a21e679c8e9 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/libsodium/README.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/libsodium/README.md @@ -18,6 +18,12 @@ And then run `./build.sh` to build the source code, the libsodium source code wi Run `./run_aot.sh` to test the benchmark, the native mode and iwasm aot mode will be tested respectively. +Run `./test_pgo.sh` to test the benchmark with AOT static PGO (Profile-Guided Optimization) enabled, please refer [here](../README.md#install-llvm-profdata) to install tool `llvm-profdata` and build `iwasm` with `cmake -DWAMR_BUILD_STATIC_PGO=1`. + +- For Linux, build `iwasm` with `cmake -DWAMR_BUILD_STATIC_PGO=1`, then run `./test_pgo.sh` to test the benchmark with AOT static PGO (Profile-Guided Optimization) enabled. + +- For Linux-sgx, similarly, build `iwasm` with `cmake -DWAMR_BUILD_STATIC_PGO=1`, then `make` in the directory `enclave-sample`. And run `./test_pgo.sh --sgx` to test the benchmark. + # Others Refer to [Performance of WebAssembly runtimes in 2023](https://00f.net/2023/01/04/webassembly-benchmark-2023) for more about the performance comparison of wasm runtimes on running the libsodium benchmarks. diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/libsodium/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/libsodium/build.sh similarity index 63% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/libsodium/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/libsodium/build.sh index 1e9cc21a702..c949375b2d7 100755 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/libsodium/build.sh +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/libsodium/build.sh @@ -12,31 +12,43 @@ libsodium_CASES="aead_aes256gcm2 aead_aes256gcm aead_chacha20poly13052 aead_chac pwhash_scrypt_ll pwhash_scrypt randombytes scalarmult2 scalarmult5 \ scalarmult6 scalarmult7 scalarmult8 scalarmult_ed25519 scalarmult_ristretto255 \ scalarmult secretbox2 secretbox7 secretbox8 secretbox_easy2 secretbox_easy \ - secretbox secretstream shorthash sign siphashx24 sodium_core sodium_utils2 \ - sodium_utils3 sodium_utils sodium_version stream2 stream3 stream4 stream verify1 \ - xchacha20" + secretbox secretstream_xchacha20poly1305 shorthash sign siphashx24 sodium_core \ + sodium_utils2 sodium_utils3 sodium_utils sodium_version stream2 stream3 stream4 \ + stream verify1 xchacha20" + +PLATFORM=$(uname -s | tr A-Z a-z) readonly WAMRC_CMD=$PWD/../../../wamr-compiler/build/wamrc readonly OUT_DIR=$PWD/libsodium/zig-out/bin if [ ! -d libsodium ]; then - git clone -b stable https://github.com/jedisct1/libsodium.git + git clone https://github.com/jedisct1/libsodium.git + cd libsodium + git checkout 1.0.19 + cd .. fi cd libsodium echo "Build libsodium native" -zig build -Drelease-fast -Denable_benchmarks=true +zig build -Doptimize=ReleaseFast -Denable_benchmarks=true echo "Build libsodium wasm32-wasi" -zig build -Drelease-fast -Denable_benchmarks=true -Dtarget=wasm32-wasi +zig build -Doptimize=ReleaseFast -Denable_benchmarks=true -Dtarget=wasm32-wasi for case in ${libsodium_CASES} do ${WAMRC_CMD} -o ${OUT_DIR}/${case}.aot ${OUT_DIR}/${case}.wasm - if [ "$?" != 0 ]; then echo -e "Error while compiling ${case}.wasm to ${case}.aot" exit fi + + if [[ ${PLATFORM} == "linux" ]]; then + ${WAMRC_CMD} --enable-segue -o ${OUT_DIR}/${case}_segue.aot ${OUT_DIR}/${case}.wasm + if [ "$?" != 0 ]; then + echo -e "Error while compiling ${case}.wasm to ${case}_segue.aot" + exit + fi + fi done diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/libsodium/run_aot.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/libsodium/run_aot.sh new file mode 100755 index 00000000000..3623deb2caa --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/libsodium/run_aot.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +libsodium_CASES="aead_aes256gcm2 aead_aes256gcm aead_chacha20poly13052 aead_chacha20poly1305 \ + aead_xchacha20poly1305 auth2 auth3 auth5 auth6 auth7 auth box2 box7 box8 \ + box_easy2 box_easy box_seal box_seed box chacha20 codecs core1 core2 core3 \ + core4 core5 core6 core_ed25519 core_ristretto255 ed25519_convert generichash2 \ + generichash3 generichash hash3 hash kdf keygen kx metamorphic misuse \ + onetimeauth2 onetimeauth7 onetimeauth pwhash_argon2id pwhash_argon2i \ + pwhash_scrypt_ll pwhash_scrypt randombytes scalarmult2 scalarmult5 \ + scalarmult6 scalarmult7 scalarmult8 scalarmult_ed25519 scalarmult_ristretto255 \ + scalarmult secretbox2 secretbox7 secretbox8 secretbox_easy2 secretbox_easy \ + secretbox secretstream_xchacha20poly1305 shorthash sign siphashx24 sodium_core \ + sodium_utils2 sodium_utils stream2 stream3 stream4 stream verify1 xchacha20" + +PLATFORM=$(uname -s | tr A-Z a-z) + +readonly OUT_DIR=$PWD/libsodium/zig-out/bin +readonly REPORT=$PWD/report.txt +readonly IWASM_CMD=$PWD/../../../product-mini/platforms/${PLATFORM}/build/iwasm +readonly TIME=/usr/bin/time + +BENCH_NAME_MAX_LEN=20 + +rm -f $REPORT +touch $REPORT + +function print_bench_name() +{ + name=$1 + echo -en "$name" >> $REPORT + name_len=${#name} + if [ $name_len -lt $BENCH_NAME_MAX_LEN ] + then + spaces=$(( $BENCH_NAME_MAX_LEN - $name_len )) + for i in $(eval echo "{1..$spaces}"); do echo -n " " >> $REPORT; done + fi +} + +# run benchmarks +cd $OUT_DIR + +if [[ ${PLATFORM} == "linux" ]]; then + echo -en "\t\t\t\t\t\tnative\tiwasm-aot\tiwasm-aot-segue\n" >> $REPORT +else + echo -en "\t\t\t\t\t\tnative\tiwasm-aot\n" >> $REPORT +fi + +for t in $libsodium_CASES +do + print_bench_name $t + + echo "run $t with native..." + echo -en "\t" >> $REPORT + if [[ $t != "sodium_utils2" ]]; then + ./${t} | awk '{printf "%-10.2f", $0/1000000.0}' >> $REPORT + else + # sodium_utils2 doesn't print the result, + # use time command to get result instead + $TIME -f "real-%e-time" ./${t} 2>&1 | grep "real-.*-time" | + awk -F '-' '{printf "%-10.2f", $2}' >> $REPORT + fi + + echo "run $t with iwasm aot..." + echo -en "\t \t" >> $REPORT + if [[ $t != "sodium_utils2" ]]; then + $IWASM_CMD ${t}.aot | awk '{printf "%-10.2f", $0/1000000.0}' >> $REPORT + else + # sodium_utils2 doesn't print the result, + # use time command to get result instead + $TIME -f "real-%e-time" $IWASM_CMD ${t}.aot 2>&1 | grep "real-.*-time" | + awk -F '-' '{printf "%-10.2f", $2}' >> $REPORT + fi + + if [[ ${PLATFORM} == "linux" ]]; then + echo "run $t with iwasm aot segue..." + echo -en "\t \t" >> $REPORT + if [[ $t != "sodium_utils2" ]]; then + $IWASM_CMD ${t}_segue.aot | awk '{printf "%.2f", $0/1000000.0}' >> $REPORT + else + # sodium_utils2 doesn't print the result, + # use time command to get result instead + $TIME -f "real-%e-time" $IWASM_CMD ${t}_segue.aot 2>&1 | grep "real-.*-time" | + awk -F '-' '{printf "%.2f", $2}' >> $REPORT + fi + fi + + echo -en "\n" >> $REPORT +done + diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/libsodium/test_pgo.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/libsodium/test_pgo.sh new file mode 100755 index 00000000000..3f9ee2eaecf --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/libsodium/test_pgo.sh @@ -0,0 +1,121 @@ +#!/bin/bash + +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +libsodium_CASES="aead_aes256gcm2 aead_aes256gcm aead_chacha20poly13052 aead_chacha20poly1305 \ + aead_xchacha20poly1305 auth2 auth3 auth5 auth6 auth7 auth box2 box7 box8 \ + box_easy2 box_easy box_seal box_seed box chacha20 codecs core1 core2 core3 \ + core4 core5 core6 core_ed25519 core_ristretto255 ed25519_convert generichash2 \ + generichash3 generichash hash3 hash kdf keygen kx metamorphic misuse \ + onetimeauth2 onetimeauth7 onetimeauth pwhash_argon2id pwhash_argon2i \ + pwhash_scrypt_ll pwhash_scrypt randombytes scalarmult2 scalarmult5 \ + scalarmult6 scalarmult7 scalarmult8 scalarmult_ed25519 scalarmult_ristretto255 \ + scalarmult secretbox2 secretbox7 secretbox8 secretbox_easy2 secretbox_easy \ + secretbox secretstream_xchacha20poly1305 shorthash sign siphashx24 sodium_core \ + sodium_utils2 sodium_utils stream2 stream3 stream4 stream verify1 xchacha20" + +PLATFORM=$(uname -s | tr A-Z a-z) + +readonly OUT_DIR=$PWD/libsodium/zig-out/bin +readonly REPORT=$PWD/report.txt +if [ "$1" = "--sgx" ] && [ "$PLATFORM" = "linux" ]; then + readonly IWASM_CMD="$PWD/../../../product-mini/platforms/${PLATFORM}-sgx/enclave-sample/iwasm" + readonly WAMRC_CMD="$PWD/../../../wamr-compiler/build/wamrc -sgx" +else + readonly IWASM_CMD="$PWD/../../../product-mini/platforms/${PLATFORM}/build/iwasm" + readonly WAMRC_CMD="$PWD/../../../wamr-compiler/build/wamrc" +fi +readonly TIME=/usr/bin/time + +BENCH_NAME_MAX_LEN=20 + +rm -f $REPORT +touch $REPORT + +function print_bench_name() +{ + name=$1 + echo -en "$name" >> $REPORT + name_len=${#name} + if [ $name_len -lt $BENCH_NAME_MAX_LEN ] + then + spaces=$(( $BENCH_NAME_MAX_LEN - $name_len )) + for i in $(eval echo "{1..$spaces}"); do echo -n " " >> $REPORT; done + fi +} + +pushd $OUT_DIR > /dev/null 2>&1 +for t in $libsodium_CASES +do + if [ ! -e "${t}.wasm" ]; then + echo "${t}.wasm doesn't exist, please run build.sh first" + exit + fi + + echo "" + echo "Compile ${t}.wasm to ${t}.aot .." + ${WAMRC_CMD} -o ${t}.aot ${t}.wasm + + echo "" + echo "Compile ${t}.wasm to ${t}_pgo.aot .." + ${WAMRC_CMD} --enable-llvm-pgo -o ${t}_pgo.aot ${t}.wasm + + echo "" + echo "Run ${t}_pgo.aot to generate the raw profile data .." + ${IWASM_CMD} --gen-prof-file=${t}.profraw --dir=. ${t}_pgo.aot + + echo "" + echo "Merge the raw profile data to ${t}.profdata .." + rm -f ${t}.profdata && llvm-profdata merge -output=${t}.profdata ${t}.profraw + + echo "" + echo "Compile ${t}.wasm to ${t}_opt.aot with the profile data .." + ${WAMRC_CMD} --use-prof-file=${t}.profdata -o ${t}_opt.aot ${t}.wasm +done + +# run benchmarks +cd $OUT_DIR + +echo -en "\t\t\t\t\t\tnative\tiwasm-aot\tiwasm-aot-pgo\n" >> $REPORT + +for t in $libsodium_CASES +do + print_bench_name $t + + echo "run $t with native..." + echo -en "\t" >> $REPORT + if [[ $t != "sodium_utils2" ]]; then + ./${t} | awk '{printf "%-10.2f", $0/1000000.0}' >> $REPORT + else + # sodium_utils2 doesn't print the result, + # use time command to get result instead + $TIME -f "real-%e-time" ./${t} 2>&1 | grep "real-.*-time" | + awk -F '-' '{printf "%-10.2f", $2}' >> $REPORT + fi + + echo "run $t with iwasm aot..." + echo -en "\t \t" >> $REPORT + if [[ $t != "sodium_utils2" ]]; then + $IWASM_CMD ${t}.aot | awk '{printf "%-10.2f", $0/1000000.0}' >> $REPORT + else + # sodium_utils2 doesn't print the result, + # use time command to get result instead + $TIME -f "real-%e-time" $IWASM_CMD ${t}.aot 2>&1 | grep "real-.*-time" | + awk -F '-' '{printf "%-10.2f", $2}' >> $REPORT + fi + + echo "run $t with iwasm aot opt..." + echo -en "\t \t" >> $REPORT + if [[ $t != "sodium_utils2" ]]; then + $IWASM_CMD ${t}_opt.aot | awk '{printf "%-10.2f", $0/1000000.0}' >> $REPORT + else + # sodium_utils2 doesn't print the result, + # use time command to get result instead + $TIME -f "real-%e-time" $IWASM_CMD ${t}_opt.aot 2>&1 | grep "real-.*-time" | + awk -F '-' '{printf "%-10.2f", $2}' >> $REPORT + fi + + echo -en "\n" >> $REPORT +done + diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/polybench/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/polybench/README.md similarity index 67% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/polybench/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/polybench/README.md index 7808e17d912..d8b3db96197 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/polybench/README.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/polybench/README.md @@ -19,3 +19,9 @@ And then run `./build.sh` to build the source code, the folder `out` will be cre Run `./run_aot.sh` to test the benchmark, the native mode and iwasm aot mode will be tested for each workload, and the file `report.txt` will be generated. Run `./run_interp.sh` to test the benchmark, the native mode and iwasm interpreter mode will be tested for each workload, and the file `report.txt` will be generated. + +Run `./test_pgo.sh` to test the benchmark with AOT static PGO (Profile-Guided Optimization) enabled, please refer [here](../README.md#install-llvm-profdata) to install tool `llvm-profdata` and build `iwasm` with `cmake -DWAMR_BUILD_STATIC_PGO=1`. + +- For Linux, build `iwasm` with `cmake -DWAMR_BUILD_STATIC_PGO=1`, then run `./test_pgo.sh` to test the benchmark with AOT static PGO (Profile-Guided Optimization) enabled. + +- For Linux-sgx, similarly, build `iwasm` with `cmake -DWAMR_BUILD_STATIC_PGO=1`, then `make` in the directory `enclave-sample`. And run `./test_pgo.sh --sgx` to test the benchmark. diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/polybench/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/polybench/build.sh similarity index 82% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/polybench/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/polybench/build.sh index bc7bf4c10e5..3e59a9bc5be 100755 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/polybench/build.sh +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/polybench/build.sh @@ -3,6 +3,8 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +PLATFORM=$(uname -s | tr A-Z a-z) + OUT_DIR=$PWD/out WAMRC_CMD=$PWD/../../../wamr-compiler/build/wamrc POLYBENCH_CASES="datamining linear-algebra medley stencils" @@ -40,6 +42,12 @@ do echo "Compile ${file_name%.*}.wasm into ${file_name%.*}.aot" ${WAMRC_CMD} -o ${OUT_DIR}/${file_name%.*}.aot \ ${OUT_DIR}/${file_name%.*}.wasm + + if [[ ${PLATFORM} == "linux" ]]; then + echo "Compile ${file_name%.*}.wasm into ${file_name%.*}_segue.aot" + ${WAMRC_CMD} --enable-segue -o ${OUT_DIR}/${file_name%.*}_segue.aot \ + ${OUT_DIR}/${file_name%.*}.wasm + fi done done diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/polybench/run_aot.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/polybench/run_aot.sh similarity index 77% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/polybench/run_aot.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/polybench/run_aot.sh index 17cc098ad3f..7eb301b2ba7 100755 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/polybench/run_aot.sh +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/polybench/run_aot.sh @@ -37,7 +37,11 @@ echo "Start to run cases, the result is written to report.txt" #run benchmarks cd $OUT_DIR -echo -en "\t\t\t\t\t native\tiwasm-aot\n" >> $REPORT +if [[ ${PLATFORM} == "linux" ]]; then + echo -en "\t\t\t\t\t native\tiwasm-aot\tiwasm-aot-segue\n" >> $REPORT +else + echo -en "\t\t\t\t\t native\tiwasm-aot\n" >> $REPORT +fi for t in $POLYBENCH_CASES do @@ -51,5 +55,11 @@ do echo -en "\t" >> $REPORT $TIME -f "real-%e-time" $IWASM_CMD ${t}.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT + if [[ ${PLATFORM} == "linux" ]]; then + echo "run $t with iwasm aot segue .." + echo -en "\t" >> $REPORT + $TIME -f "real-%e-time" $IWASM_CMD ${t}_segue.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT + fi + echo -en "\n" >> $REPORT done diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/polybench/run_interp.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/polybench/run_interp.sh similarity index 96% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/polybench/run_interp.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/polybench/run_interp.sh index f6d5c254d31..5dfe760e2ca 100755 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/polybench/run_interp.sh +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/polybench/run_interp.sh @@ -37,7 +37,7 @@ echo "Start to run cases, the result is written to report.txt" #run benchmarks cd $OUT_DIR -echo -en "\t\t\t\t\t native\tiwasm-aot\n" >> $REPORT +echo -en "\t\t\t\t\t native\tiwasm-interp\n" >> $REPORT for t in $POLYBENCH_CASES do diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/polybench/test_pgo.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/polybench/test_pgo.sh new file mode 100755 index 00000000000..6451a5be20f --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/polybench/test_pgo.sh @@ -0,0 +1,95 @@ +#!/bin/bash + +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +CUR_DIR=$PWD +OUT_DIR=$CUR_DIR/out +REPORT=$CUR_DIR/report.txt +TIME=/usr/bin/time + +PLATFORM=$(uname -s | tr A-Z a-z) +if [ "$1" = "--sgx" ] && [ "$PLATFORM" = "linux" ]; then + IWASM_CMD="$CUR_DIR/../../../product-mini/platforms/${PLATFORM}-sgx/enclave-sample/iwasm" + WAMRC_CMD="$CUR_DIR/../../../wamr-compiler/build/wamrc -sgx" +else + IWASM_CMD="$CUR_DIR/../../../product-mini/platforms/${PLATFORM}/build/iwasm" + WAMRC_CMD="$CUR_DIR/../../../wamr-compiler/build/wamrc" +fi + +BENCH_NAME_MAX_LEN=20 + +POLYBENCH_CASES="2mm 3mm adi atax bicg cholesky correlation covariance \ + deriche doitgen durbin fdtd-2d floyd-warshall gemm gemver \ + gesummv gramschmidt heat-3d jacobi-1d jacobi-2d ludcmp lu \ + mvt nussinov seidel-2d symm syr2k syrk trisolv trmm" + +rm -f $REPORT +touch $REPORT + +function print_bench_name() +{ + name=$1 + echo -en "$name" >> $REPORT + name_len=${#name} + if [ $name_len -lt $BENCH_NAME_MAX_LEN ] + then + spaces=$(( $BENCH_NAME_MAX_LEN - $name_len )) + for i in $(eval echo "{1..$spaces}"); do echo -n " " >> $REPORT; done + fi +} + +pushd $OUT_DIR > /dev/null 2>&1 +for t in $POLYBENCH_CASES +do + if [ ! -e "${t}.wasm" ]; then + echo "${t}.wasm doesn't exist, please run build.sh first" + exit + fi + + echo "" + echo "Compile ${t}.wasm to ${t}.aot .." + ${WAMRC_CMD} -o ${t}.aot ${t}.wasm + + echo "" + echo "Compile ${t}.wasm to ${t}_pgo.aot .." + ${WAMRC_CMD} --enable-llvm-pgo -o ${t}_pgo.aot ${t}.wasm + + echo "" + echo "Run ${t}_pgo.aot to generate the raw profile data .." + ${IWASM_CMD} --gen-prof-file=${t}.profraw --dir=. ${t}_pgo.aot + + echo "" + echo "Merge the raw profile data to ${t}.profdata .." + rm -f ${t}.profdata && llvm-profdata merge -output=${t}.profdata ${t}.profraw + + echo "" + echo "Compile ${t}.wasm to ${t}_opt.aot with the profile data .." + ${WAMRC_CMD} --use-prof-file=${t}.profdata -o ${t}_opt.aot ${t}.wasm +done +popd > /dev/null 2>&1 + +echo "Start to run cases, the result is written to report.txt" + +#run benchmarks +cd $OUT_DIR +echo -en "\t\t\t\t\t native\tiwasm-aot\tiwasm-aot-pgo\n" >> $REPORT + +for t in $POLYBENCH_CASES +do + print_bench_name $t + + echo "run $t with native .." + echo -en "\t" >> $REPORT + $TIME -f "real-%e-time" ./${t}_native 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT + + echo "run $t with iwasm aot .." + echo -en "\t" >> $REPORT + $TIME -f "real-%e-time" $IWASM_CMD ${t}.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT + + echo "run $t with iwasm aot opt .." + echo -en "\t" >> $REPORT + $TIME -f "real-%e-time" $IWASM_CMD ${t}_opt.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT + + echo -en "\n" >> $REPORT +done diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/sightglass/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/sightglass/README.md similarity index 64% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/sightglass/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/sightglass/README.md index a446d80ea8f..ff34c7d700b 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/sightglass/README.md +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/sightglass/README.md @@ -19,3 +19,9 @@ And then run `./build.sh` to build the source code, the folder `out` will be cre Run `./run_aot.sh` to test the benchmark, the native mode and iwasm aot mode will be tested for each workload, and the file `report.txt` will be generated. Run `./run_interp.sh` to test the benchmark, the native mode and iwasm interpreter mode will be tested for each workload, and the file `report.txt` will be generated. + +Run `./test_pgo.sh` to test the benchmark with AOT static PGO (Profile-Guided Optimization) enabled, please refer [here](../README.md#install-llvm-profdata) to install tool `llvm-profdata` and build `iwasm` with `cmake -DWAMR_BUILD_STATIC_PGO=1`. + +- For Linux, build `iwasm` with `cmake -DWAMR_BUILD_STATIC_PGO=1`, then run `./test_pgo.sh` to test the benchmark with AOT static PGO (Profile-Guided Optimization) enabled. + +- For Linux-sgx, similarly, build `iwasm` with `cmake -DWAMR_BUILD_STATIC_PGO=1`, then `make` in the directory `enclave-sample`. And run `./test_pgo.sh --sgx` to test the benchmark. diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/sightglass/build.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/sightglass/build.sh similarity index 84% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/sightglass/build.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/sightglass/build.sh index c7192c16f1d..5408822857b 100755 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/sightglass/build.sh +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/sightglass/build.sh @@ -3,6 +3,8 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +PLATFORM=$(uname -s | tr A-Z a-z) + OUT_DIR=$PWD/out WAMRC_CMD=$PWD/../../../wamr-compiler/build/wamrc SHOOTOUT_CASES="base64 fib2 gimli heapsort matrix memmove nestedloop \ @@ -34,9 +36,12 @@ do -Wl,--export=app_main -Wl,--export=_start \ ${bench}.c main/main_${bench}.c main/my_libc.c - echo "Compile ${bench}.wasm into ${bench}.aot" ${WAMRC_CMD} -o ${OUT_DIR}/${bench}.aot ${OUT_DIR}/${bench}.wasm + if [[ ${PLATFORM} == "linux" ]]; then + echo "Compile ${bench}.wasm into ${bench}_segue.aot" + ${WAMRC_CMD} --enable-segue -o ${OUT_DIR}/${bench}_segue.aot ${OUT_DIR}/${bench}.wasm + fi done cd .. diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/sightglass/run_aot.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/sightglass/run_aot.sh similarity index 75% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/sightglass/run_aot.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/sightglass/run_aot.sh index 7a74a7912ea..44945b91bd0 100755 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/sightglass/run_aot.sh +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/sightglass/run_aot.sh @@ -36,7 +36,11 @@ echo "Start to run cases, the result is written to report.txt" #run benchmarks cd $OUT_DIR -echo -en "\t\t\t\t\t native\tiwasm-aot\n" >> $REPORT +if [[ ${PLATFORM} == "linux" ]]; then + echo -en "\t\t\t\t\t native\tiwasm-aot\tiwasm-aot-segue\n" >> $REPORT +else + echo -en "\t\t\t\t\t native\tiwasm-aot\n" >> $REPORT +fi for t in $SHOOTOUT_CASES do @@ -50,5 +54,11 @@ do echo -en "\t" >> $REPORT $TIME -f "real-%e-time" $IWASM_CMD ${t}.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT + if [[ ${PLATFORM} == "linux" ]]; then + echo "run $t with iwasm aot segue .." + echo -en "\t" >> $REPORT + $TIME -f "real-%e-time" $IWASM_CMD ${t}_segue.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT + fi + echo -en "\n" >> $REPORT done diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/sightglass/run_interp.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/sightglass/run_interp.sh similarity index 88% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/sightglass/run_interp.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/sightglass/run_interp.sh index 50e94a5db46..c3dbb302419 100755 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/benchmarks/sightglass/run_interp.sh +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/sightglass/run_interp.sh @@ -46,9 +46,9 @@ do echo -en "\t" >> $REPORT $TIME -f "real-%e-time" ./${t}_native 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT - echo "run $t with iwasm aot .." + echo "run $t with iwasm interp .." echo -en "\t" >> $REPORT - $TIME -f "real-%e-time" $IWASM_CMD ${t}.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT + $TIME -f "real-%e-time" $IWASM_CMD ${t}.wasm 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT echo -en "\n" >> $REPORT done diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/sightglass/test_pgo.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/sightglass/test_pgo.sh new file mode 100755 index 00000000000..4baedf9fd52 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/benchmarks/sightglass/test_pgo.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +CUR_DIR=$PWD +OUT_DIR=$CUR_DIR/out +REPORT=$CUR_DIR/report.txt +TIME=/usr/bin/time + +PLATFORM=$(uname -s | tr A-Z a-z) +if [ "$1" = "--sgx" ] && [ "$PLATFORM" = "linux" ]; then + IWASM_CMD="$CUR_DIR/../../../product-mini/platforms/${PLATFORM}-sgx/enclave-sample/iwasm" + WAMRC_CMD="$CUR_DIR/../../../wamr-compiler/build/wamrc -sgx" +else + IWASM_CMD="$CUR_DIR/../../../product-mini/platforms/${PLATFORM}/build/iwasm" + WAMRC_CMD="$CUR_DIR/../../../wamr-compiler/build/wamrc" +fi + +BENCH_NAME_MAX_LEN=20 + +SHOOTOUT_CASES="base64 fib2 gimli heapsort matrix memmove nestedloop \ + nestedloop2 nestedloop3 random seqhash sieve strchr \ + switch2" + +rm -f $REPORT +touch $REPORT + +function print_bench_name() +{ + name=$1 + echo -en "$name" >> $REPORT + name_len=${#name} + if [ $name_len -lt $BENCH_NAME_MAX_LEN ] + then + spaces=$(( $BENCH_NAME_MAX_LEN - $name_len )) + for i in $(eval echo "{1..$spaces}"); do echo -n " " >> $REPORT; done + fi +} + +pushd $OUT_DIR > /dev/null 2>&1 +for t in $SHOOTOUT_CASES +do + if [ ! -e "${t}.wasm" ]; then + echo "${t}.wasm doesn't exist, please run build.sh first" + exit + fi + + echo "" + echo "Compile ${t}.wasm to ${t}.aot .." + ${WAMRC_CMD} -o ${t}.aot ${t}.wasm + + echo "" + echo "Compile ${t}.wasm to ${t}_pgo.aot .." + ${WAMRC_CMD} --enable-llvm-pgo -o ${t}_pgo.aot ${t}.wasm + + echo "" + echo "Run ${t}_pgo.aot to generate the raw profile data .." + ${IWASM_CMD} --gen-prof-file=${t}.profraw --dir=. ${t}_pgo.aot + + echo "" + echo "Merge the raw profile data to ${t}.profdata .." + rm -f ${t}.profdata && llvm-profdata merge -output=${t}.profdata ${t}.profraw + + echo "" + echo "Compile ${t}.wasm to ${t}_opt.aot with the profile data .." + ${WAMRC_CMD} --use-prof-file=${t}.profdata -o ${t}_opt.aot ${t}.wasm +done +popd > /dev/null 2>&1 + +echo "Start to run cases, the result is written to report.txt" + +#run benchmarks +cd $OUT_DIR +echo -en "\t\t\t\t\t native\tiwasm-aot\tiwasm-aot-pgo\n" >> $REPORT + +for t in $SHOOTOUT_CASES +do + print_bench_name $t + + echo "run $t with native .." + echo -en "\t" >> $REPORT + $TIME -f "real-%e-time" ./${t}_native 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT + + echo "run $t with iwasm aot .." + echo -en "\t" >> $REPORT + $TIME -f "real-%e-time" $IWASM_CMD ${t}.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT + + echo "run $t with iwasm aot opt .." + echo -en "\t" >> $REPORT + $TIME -f "real-%e-time" $IWASM_CMD ${t}_opt.aot 2>&1 | grep "real-.*-time" | awk -F '-' '{ORS=""; print $2}' >> $REPORT + + echo -en "\n" >> $REPORT +done diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/unit/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/unit/CMakeLists.txt new file mode 100644 index 00000000000..a9a7b8776c7 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/unit/CMakeLists.txt @@ -0,0 +1,51 @@ +# Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +cmake_minimum_required (VERSION 3.14) + +project (wamr_unit_tests) + +include (CTest) + +if (NOT DEFINED WAMR_BUILD_INTERP) + # Enable Interpreter by default + set (WAMR_BUILD_INTERP 1) +endif () + +if (NOT DEFINED WAMR_BUILD_PLATFORM) + string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) +endif () + +set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) +include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) +add_library (vmlib ${WAMR_RUNTIME_LIB_SOURCE}) + +include (FetchContent) +FetchContent_Declare ( + googletest + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip +) +# For Windows: Prevent overriding the parent project's compiler/linker settings +set (gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable (googletest) + +include (GoogleTest) + +add_library (wamr_gtest_main main.cpp) +target_link_libraries (wamr_gtest_main PUBLIC gtest vmlib) + +function (create_wamr_unit_test test_name) + set (sources ${ARGN}) + add_executable (${test_name} ${sources}) + target_link_libraries ( + ${test_name} + wamr_gtest_main + vmlib + ${LLVM_AVAILABLE_LIBS} + ) + gtest_discover_tests (${test_name}) + endfunction () + +if (WAMR_BUILD_LIB_WASI_THREADS EQUAL 1) + include (${IWASM_DIR}/libraries/lib-wasi-threads/unit-test/lib_wasi_threads_unit_tests.cmake) +endif () diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/unit/main.cpp b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/unit/main.cpp new file mode 100644 index 00000000000..63695d9ee79 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/unit/main.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ +#include +#include "wasm_runtime_common.h" + +int +main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + + if (!wasm_runtime_init()) { + return -1; + } + + int ret = RUN_ALL_TESTS(); + wasm_runtime_destroy(); + + return ret; +} \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-compiler/.gitignore b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-compiler/.gitignore new file mode 100644 index 00000000000..5425c41bd4f --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-compiler/.gitignore @@ -0,0 +1,2 @@ +*.aot +*.wasm \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-compiler/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-compiler/README.md new file mode 100644 index 00000000000..d48ea982743 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-compiler/README.md @@ -0,0 +1,3 @@ +# WAMR test benchmarks + +This folder contains tests for WAMR AOT compiler and its generated code. diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-compiler/test_shift_negative_constants.wat b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-compiler/test_shift_negative_constants.wat new file mode 100644 index 00000000000..83bc3c44d76 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-compiler/test_shift_negative_constants.wat @@ -0,0 +1,78 @@ +;; Copyright (C) 2023 Amazon Inc. All rights reserved. +;; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +;; +;; Those tests verify if passing constant negative value +;; as a right parameter of the shift operator (along +;; with a constant value of the left operator) causes +;; any problems. See: https://github.com/bytecodealliance/wasm-micro-runtime/pull/2619 +(module + (memory (export "memory") 1 1) + + (func $assert_eq (param i32 i32) + (i32.ne (local.get 0) (local.get 1)) + if + unreachable + end + ) + + (func $i32_shr_u + (call $assert_eq + (i32.shr_u (i32.const -1) (i32.const -5)) + (i32.const 31) + ) + ) + + (func $i32_shr_s + (call $assert_eq + (i32.shr_s (i32.const 32) (i32.const -30)) + (i32.const 8) + ) + ) + + (func $i32_shl + (call $assert_eq + (i32.shl (i32.const -1) (i32.const -30)) + (i32.const -4) + ) + ) + + (func $const_ret (result i32) + i32.const -5 + ) + + ;; *_func_call tests validate the potential LLVM optimizations + ;; where the right parameter of the shift operation is an + ;; indirect constant value. + (func $i32_shr_u_func_call + (call $assert_eq + (i32.shr_u (i32.const -1) (call $const_ret)) + (i32.const 31) + ) + ) + + (func $i32_shr_s_func_call + (call $assert_eq + (i32.shr_s + (i32.const 1073741824) ;; 2^30 + (call $const_ret) + ) + (i32.const 8) + ) + ) + + (func $i32_shl_func_call + (call $assert_eq + (i32.shl (i32.const -1) (call $const_ret)) + (i32.const -134217728) + ) + ) + + (func (export "_start") + call $i32_shr_u + call $i32_shr_s + call $i32_shl + call $i32_shr_u_func_call + call $i32_shr_s_func_call + call $i32_shl_func_call + ) +) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/CHANGES b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/CHANGES similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/CHANGES rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/CHANGES diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/all.py b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/all.py similarity index 82% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/all.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/all.py index 8b26d689225..551a3176c61 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/all.py +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/all.py @@ -6,7 +6,7 @@ import argparse import multiprocessing as mp -import os +import platform import pathlib import subprocess import sys @@ -28,32 +28,45 @@ --aot-compiler wamrc --gc spec/test/core/xxx.wast """ -PLATFORM_NAME = os.uname().sysname.lower() -IWASM_CMD = "../../../product-mini/platforms/" + PLATFORM_NAME + "/build/iwasm" +def exe_file_path(base_path: str) -> str: + if platform.system().lower() == "windows": + base_path += ".exe" + return base_path + +def get_iwasm_cmd(platform: str) -> str: + build_path = "../../../product-mini/platforms/" + platform + "/build/" + exe_name = "iwasm" + + if platform == "windows": + build_path += "RelWithDebInfo/" + + return exe_file_path(build_path + exe_name) + +PLATFORM_NAME = platform.uname().system.lower() +IWASM_CMD = get_iwasm_cmd(PLATFORM_NAME) IWASM_SGX_CMD = "../../../product-mini/platforms/linux-sgx/enclave-sample/iwasm" IWASM_QEMU_CMD = "iwasm" SPEC_TEST_DIR = "spec/test/core" -WAST2WASM_CMD = "./wabt/out/gcc/Release/wat2wasm" +WAST2WASM_CMD = exe_file_path("./wabt/out/gcc/Release/wat2wasm") SPEC_INTERPRETER_CMD = "spec/interpreter/wasm" WAMRC_CMD = "../../../wamr-compiler/build/wamrc" - -class TargetAction(argparse.Action): - TARGET_MAP = { - "ARMV7_VFP": "armv7", - "RISCV32": "riscv32_ilp32", - "RISCV32_ILP32": "riscv32_ilp32", - "RISCV32_ILP32D": "riscv32_ilp32d", - "RISCV64": "riscv64_lp64", - "RISCV64_LP64": "riscv64_lp64", - "RISCV64_LP64D": "riscv64_lp64", - "THUMBV7_VFP": "thumbv7", - "X86_32": "i386", - "X86_64": "x86_64", - } - - def __call__(self, parser, namespace, values, option_string=None): - setattr(namespace, self.dest, self.TARGET_MAP.get(values, "x86_64")) - +AVAILABLE_TARGETS = [ + "I386", + "X86_32", + "X86_64", + "AARCH64", + "AARCH64_VFP", + "ARMV7", + "ARMV7_VFP", + "RISCV32", + "RISCV32_ILP32F", + "RISCV32_ILP32D", + "RISCV64", + "RISCV64_LP64F", + "RISCV64_LP64D", + "THUMBV7", + "THUMBV7_VFP", +] def ignore_the_case( case_name, @@ -65,7 +78,7 @@ def ignore_the_case( simd_flag=False, gc_flag=False, xip_flag=False, - qemu_flag=False + qemu_flag=False, ): if case_name in ["comments", "inline-module", "names"]: return True @@ -73,12 +86,13 @@ def ignore_the_case( if not multi_module_flag and case_name in ["imports", "linking"]: return True - if "i386" == target and case_name in ["float_exprs"]: + # Note: x87 doesn't preserve sNaN and makes some relevant tests fail. + if "i386" == target and case_name in ["float_exprs", "conversions"]: return True if gc_flag: if case_name in ["type-canon", "type-equivalence", "type-rec"]: - return True; + return True if sgx_flag: if case_name in ["conversions", "f32_bitwise", "f64_bitwise"]: @@ -93,9 +107,20 @@ def ignore_the_case( return True if qemu_flag: - if case_name in ["f32_bitwise", "f64_bitwise", "loop", "f64", "f64_cmp", - "conversions", "f32", "f32_cmp", "float_exprs", - "float_misc", "select", "memory_grow"]: + if case_name in [ + "f32_bitwise", + "f64_bitwise", + "loop", + "f64", + "f64_cmp", + "conversions", + "f32", + "f32_cmp", + "float_exprs", + "float_misc", + "select", + "memory_grow", + ]: return True return False @@ -130,27 +155,11 @@ def test_case( verbose_flag=True, gc_flag=False, qemu_flag=False, - qemu_firmware='', - log='', + qemu_firmware="", + log="", + no_pty=False ): - case_path = pathlib.Path(case_path).resolve() - case_name = case_path.stem - - if ignore_the_case( - case_name, - target, - aot_flag, - sgx_flag, - multi_module_flag, - multi_thread_flag, - simd_flag, - gc_flag, - xip_flag, - qemu_flag - ): - return True - - CMD = ["python3", "runtest.py"] + CMD = [sys.executable, "runtest.py"] CMD.append("--wast2wasm") CMD.append(WAST2WASM_CMD if not gc_flag else SPEC_INTERPRETER_CMD) CMD.append("--interpreter") @@ -160,6 +169,8 @@ def test_case( CMD.append(IWASM_QEMU_CMD) else: CMD.append(IWASM_CMD) + if no_pty: + CMD.append("--no-pty") CMD.append("--aot-compiler") CMD.append(WAMRC_CMD) @@ -195,11 +206,15 @@ def test_case( if gc_flag: CMD.append("--gc") - if log != '': + if log != "": CMD.append("--log-dir") CMD.append(log) - CMD.append(case_path) + case_path = pathlib.Path(case_path).resolve() + case_name = case_path.stem + + CMD.append(str(case_path)) + # print(f"============> use {' '.join(CMD)}") print(f"============> run {case_name} ", end="") with subprocess.Popen( CMD, @@ -258,8 +273,9 @@ def test_suite( gc_flag=False, parl_flag=False, qemu_flag=False, - qemu_firmware='', - log='', + qemu_firmware="", + log="", + no_pty=False, ): suite_path = pathlib.Path(SPEC_TEST_DIR).resolve() if not suite_path.exists(): @@ -275,6 +291,26 @@ def test_suite( gc_case_list = sorted(suite_path.glob("gc/*.wast")) case_list.extend(gc_case_list) + # ignore based on command line options + filtered_case_list = [] + for case_path in case_list: + case_name = case_path.stem + if not ignore_the_case( + case_name, + target, + aot_flag, + sgx_flag, + multi_module_flag, + multi_thread_flag, + simd_flag, + gc_flag, + xip_flag, + qemu_flag, + ): + filtered_case_list.append(case_path) + print(f"---> {len(case_list)} --filter--> {len(filtered_case_list)}") + case_list = filtered_case_list + case_count = len(case_list) failed_case = 0 successful_case = 0 @@ -301,6 +337,7 @@ def test_suite( qemu_flag, qemu_firmware, log, + no_pty, ], ) @@ -338,6 +375,7 @@ def test_suite( qemu_flag, qemu_firmware, log, + no_pty, ) successful_case += 1 except Exception as e: @@ -363,8 +401,7 @@ def main(): ) parser.add_argument( "-m", - action=TargetAction, - choices=list(TargetAction.TARGET_MAP.keys()), + choices=AVAILABLE_TARGETS, type=str, dest="target", default="X86_64", @@ -434,7 +471,7 @@ def main(): ) parser.add_argument( "--log", - default='', + default="", dest="log", help="Log directory", ) @@ -459,9 +496,17 @@ def main(): nargs="*", help=f"Specify all wanted cases. If not the script will go through all cases under {SPEC_TEST_DIR}", ) + parser.add_argument('--no-pty', action='store_true', + help="Use direct pipes instead of pseudo-tty") options = parser.parse_args() - print(options) + + # Convert target to lower case for internal use, e.g. X86_64 -> x86_64 + # target is always exist, so no need to check it + options.target = options.target.lower() + + if options.target == "x86_32": + options.target = "i386" if not preflight_check(options.aot_flag): return False @@ -489,6 +534,7 @@ def main(): options.qemu_flag, options.qemu_firmware, options.log, + options.no_pty ) end = time.time_ns() print( @@ -511,7 +557,8 @@ def main(): options.gc_flag, options.qemu_flag, options.qemu_firmware, - options.log + options.log, + options.no_pty, ) else: ret = True diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/all.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/all.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/all.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/all.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/collect_coverage.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/collect_coverage.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/collect_coverage.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/collect_coverage.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/ignore_cases.patch b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/ignore_cases.patch similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/ignore_cases.patch rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/ignore_cases.patch index 1d94d91af98..bfb4383f73a 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/ignore_cases.patch +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/ignore_cases.patch @@ -343,26 +343,6 @@ index adb5cb7..590f626 100644 (func $g (param $x i32) (result i32) (i32.add (local.get $x) (i32.const 1)) ) -diff --git a/test/core/select.wast b/test/core/select.wast -index 046e6fe..b677023 100644 ---- a/test/core/select.wast -+++ b/test/core/select.wast -@@ -324,6 +324,7 @@ - (module (func $arity-0 (select (result) (nop) (nop) (i32.const 1)))) - "invalid result arity" - ) -+(; - (assert_invalid - (module (func $arity-2 (result i32 i32) - (select (result i32 i32) -@@ -334,6 +335,7 @@ - )) - "invalid result arity" - ) -+;) - - - (assert_invalid diff --git a/test/core/table_copy.wast b/test/core/table_copy.wast index 380e84e..f37e745 100644 --- a/test/core/table_copy.wast diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/multi_module_aot_ignore_cases.patch b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/multi_module_aot_ignore_cases.patch new file mode 100644 index 00000000000..4494e08565f --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/multi_module_aot_ignore_cases.patch @@ -0,0 +1,174 @@ +diff --git a/test/core/linking.wast b/test/core/linking.wast +index d0bfb5f..6617945 100644 +--- a/test/core/linking.wast ++++ b/test/core/linking.wast +@@ -35,7 +35,7 @@ + + + ;; Globals +- ++(; + (module $Mg + (global $glob (export "glob") i32 (i32.const 42)) + (func (export "get") (result i32) (global.get $glob)) +@@ -63,7 +63,7 @@ + (export "Mg.get_mut" (func $get_mut)) + (export "Mg.set_mut" (func $set_mut)) + ) +- ++;) + (; + (assert_return (get $Mg "glob") (i32.const 42)) + (assert_return (get $Ng "Mg.glob") (i32.const 42)) +@@ -84,7 +84,7 @@ + (assert_return (invoke $Ng "Mg.get_mut") (i32.const 241)) + ;) + +- ++(; + (assert_unlinkable + (module (import "Mg" "mut_glob" (global i32))) + "incompatible import type" +@@ -166,7 +166,7 @@ + (call_indirect (type 1) (local.get 0)) + ) + ) +- ++;) + (; + (assert_return (invoke $Mt "call" (i32.const 2)) (i32.const 4)) + (assert_return (invoke $Nt "Mt.call" (i32.const 2)) (i32.const 4)) +@@ -191,7 +191,7 @@ + (assert_return (invoke $Nt "call" (i32.const 3)) (i32.const -4)) + (assert_trap (invoke $Nt "call" (i32.const 4)) "indirect call type mismatch") + ;) +- ++(; + (module $Ot + (type (func (result i32))) + +@@ -204,7 +204,7 @@ + (call_indirect (type 0) (local.get 0)) + ) + ) +- ++;) + (; + (assert_return (invoke $Mt "call" (i32.const 3)) (i32.const 4)) + (assert_return (invoke $Nt "Mt.call" (i32.const 3)) (i32.const 4)) +@@ -231,7 +231,7 @@ + + (assert_trap (invoke $Ot "call" (i32.const 20)) "undefined element") + ;) +- ++(; + (module + (table (import "Mt" "tab") 0 funcref) + (elem (i32.const 9) $f) +@@ -266,7 +266,7 @@ + "unknown import" + ) + (assert_trap (invoke $Mt "call" (i32.const 7)) "uninitialized element") +- ++;) + ;; Unlike in the v1 spec, active element segments stored before an + ;; out-of-bounds access persist after the instantiation failure. + (; +@@ -297,7 +297,7 @@ + (assert_return (invoke $Mt "call" (i32.const 7)) (i32.const 0)) + ;) + +- ++(; + (module $Mtable_ex + (table $t1 (export "t-func") 1 funcref) + (table $t2 (export "t-extern") 1 externref) +@@ -308,7 +308,7 @@ + (table (import "Mtable_ex" "t-func") 1 funcref) + (table (import "Mtable_ex" "t-extern") 1 externref) + ) +- ++;) + (; + (assert_unlinkable + (module (table (import "Mtable_ex" "t-func") 1 externref)) +@@ -322,7 +322,7 @@ + + + ;; Memories +- ++(; + (module $Mm + (memory (export "mem") 1 5) + (data (i32.const 10) "\00\01\02\03\04\05\06\07\08\09") +@@ -357,14 +357,14 @@ + (i32.load8_u (local.get 0)) + ) + ) +- ++;) + (; + (assert_return (invoke $Mm "load" (i32.const 12)) (i32.const 0xa7)) + (assert_return (invoke $Nm "Mm.load" (i32.const 12)) (i32.const 0xa7)) + (assert_return (invoke $Nm "load" (i32.const 12)) (i32.const 0xf2)) + (assert_return (invoke $Om "load" (i32.const 12)) (i32.const 0xa7)) + ;) +- ++(; + (module + (memory (import "Mm" "mem") 0) + (data (i32.const 0xffff) "a") +@@ -385,7 +385,7 @@ + (memory.grow (local.get 0)) + ) + ) +- ++;) + (; + (assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 1)) + (assert_return (invoke $Pm "grow" (i32.const 2)) (i32.const 1)) +@@ -396,7 +396,7 @@ + (assert_return (invoke $Pm "grow" (i32.const 1)) (i32.const -1)) + (assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 5)) + ;) +- ++(; + (assert_unlinkable + (module + (func $host (import "spectest" "print")) +@@ -419,11 +419,12 @@ + ) + "out of bounds memory access" + ) ++;) + (; + (assert_return (invoke $Mm "load" (i32.const 0)) (i32.const 97)) + (assert_return (invoke $Mm "load" (i32.const 327670)) (i32.const 0)) + ;) +- ++(; + (assert_trap + (module + (memory (import "Mm" "mem") 1) +@@ -434,10 +435,11 @@ + ) + "out of bounds table access" + ) ++;) + (; + (assert_return (invoke $Mm "load" (i32.const 0)) (i32.const 97)) + ;) +- ++(; + ;; Store is modified if the start function traps. + (module $Ms + (type $t (func (result i32))) +@@ -451,7 +453,7 @@ + ) + ) + (register "Ms" $Ms) +- ++;) + (; + (assert_trap + (module diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/runtest.py b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/runtest.py similarity index 85% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/runtest.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/runtest.py index a1e505bd047..dcc0c3361db 100755 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/runtest.py +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/runtest.py @@ -5,22 +5,21 @@ import argparse import array import atexit -import fcntl import math import os -# Pseudo-TTY and terminal manipulation -import pty import re import shutil import struct import subprocess import sys import tempfile -import termios import time +import threading import traceback from select import select +from queue import Queue from subprocess import PIPE, STDOUT, Popen +from typing import BinaryIO, Optional, Tuple if sys.version_info[0] == 2: IS_PY_3 = False @@ -28,7 +27,9 @@ IS_PY_3 = True test_aot = False -# "x86_64", "i386", "aarch64", "armv7", "thumbv7", "riscv32_ilp32", "riscv32_ilp32d", "riscv32_lp64", "riscv64_lp64d" +# Available targets: +# "aarch64" "aarch64_vfp" "armv7" "armv7_vfp" "thumbv7" "thumbv7_vfp" +# "riscv32" "riscv32_ilp32f" "riscv32_ilp32d" "riscv64" "riscv64_lp64f" "riscv64_lp64d" test_target = "x86_64" debug_file = None @@ -40,6 +41,25 @@ # to save the mapping of module files in /tmp by name temp_module_table = {} +# AOT compilation options mapping +aot_target_options_map = { + "i386": ["--target=i386"], + "x86_32": ["--target=i386"], + "x86_64": ["--target=x86_64", "--cpu=skylake"], + "aarch64": ["--target=aarch64", "--target-abi=eabi", "--cpu=cortex-a53"], + "aarch64_vfp": ["--target=aarch64", "--target-abi=gnueabihf", "--cpu=cortex-a53"], + "armv7": ["--target=armv7", "--target-abi=eabi", "--cpu=cortex-a9", "--cpu-features=-neon"], + "armv7_vfp": ["--target=armv7", "--target-abi=gnueabihf", "--cpu=cortex-a9"], + "thumbv7": ["--target=thumbv7", "--target-abi=eabi", "--cpu=cortex-a9", "--cpu-features=-neon,-vfpv3"], + "thumbv7_vfp": ["--target=thumbv7", "--target-abi=gnueabihf", "--cpu=cortex-a9", "--cpu-features=-neon"], + "riscv32": ["--target=riscv32", "--target-abi=ilp32", "--cpu=generic-rv32", "--cpu-features=+m,+a,+c"], + "riscv32_ilp32f": ["--target=riscv32", "--target-abi=ilp32f", "--cpu=generic-rv32", "--cpu-features=+m,+a,+c,+f"], + "riscv32_ilp32d": ["--target=riscv32", "--target-abi=ilp32d", "--cpu=generic-rv32", "--cpu-features=+m,+a,+c,+f,+d"], + "riscv64": ["--target=riscv64", "--target-abi=lp64", "--cpu=generic-rv64", "--cpu-features=+m,+a,+c"], + "riscv64_lp64f": ["--target=riscv64", "--target-abi=lp64f", "--cpu=generic-rv64", "--cpu-features=+m,+a,+c,+f"], + "riscv64_lp64d": ["--target=riscv64", "--target-abi=lp64d", "--cpu=generic-rv64", "--cpu-features=+m,+a,+c,+f,+d"], +} + def debug(data): if debug_file: debug_file.write(data) @@ -52,6 +72,10 @@ def log(data, end='\n'): print(data, end=end) sys.stdout.flush() +def create_tmp_file(suffix: str) -> str: + with tempfile.NamedTemporaryFile(suffix=suffix, delete=False) as tmp_file: + return tmp_file.name + # TODO: do we need to support '\n' too import platform @@ -62,6 +86,34 @@ def log(data, end='\n'): sep = "\r\n" rundir = None + +class AsyncStreamReader: + def __init__(self, stream: BinaryIO) -> None: + self._queue = Queue() + self._reader_thread = threading.Thread( + daemon=True, + target=AsyncStreamReader._stdout_reader, + args=(self._queue, stream)) + self._reader_thread.start() + + def read(self) -> Optional[bytes]: + return self._queue.get() + + def cleanup(self) -> None: + self._reader_thread.join() + + @staticmethod + def _stdout_reader(queue: Queue, stdout: BinaryIO) -> None: + while True: + try: + queue.put(stdout.read(1)) + except ValueError as e: + if stdout.closed: + queue.put(None) + break + raise e + + class Runner(): def __init__(self, args, no_pty=False): self.no_pty = no_pty @@ -77,11 +129,14 @@ def __init__(self, args, no_pty=False): if no_pty: self.process = Popen(args, bufsize=0, stdin=PIPE, stdout=PIPE, stderr=STDOUT, - preexec_fn=os.setsid, env=env) self.stdin = self.process.stdin self.stdout = self.process.stdout else: + import fcntl + # Pseudo-TTY and terminal manipulation + import pty + import termios # Use tty to setup an interactive environment master, slave = pty.openpty() @@ -101,35 +156,53 @@ def __init__(self, args, no_pty=False): self.stdin = os.fdopen(master, 'r+b', 0) self.stdout = self.stdin + if platform.system().lower() == "windows": + self._stream_reader = AsyncStreamReader(self.stdout) + else: + self._stream_reader = None + self.buf = "" - def read_to_prompt(self, prompts, timeout): - wait_until = time.time() + timeout - while time.time() < wait_until: + def _read_stdout_byte(self) -> Tuple[bool, Optional[bytes]]: + if self._stream_reader: + return True, self._stream_reader.read() + else: + # select doesn't work on file descriptors on Windows. + # however, this method is much faster than using + # queue, so we keep it for non-windows platforms. [outs,_,_] = select([self.stdout], [], [], 1) if self.stdout in outs: - read_byte = self.stdout.read(1) - if not read_byte: - # EOF on macOS ends up here. - break - read_byte = read_byte.decode('utf-8') if IS_PY_3 else read_byte + return True, self.stdout.read(1) + else: + return False, None - debug(read_byte) - if self.no_pty: - self.buf += read_byte.replace('\n', '\r\n') - else: - self.buf += read_byte - self.buf = self.buf.replace('\r\r', '\r') - - # filter the prompts - for prompt in prompts: - pattern = re.compile(prompt) - match = pattern.search(self.buf) - if match: - end = match.end() - buf = self.buf[0:end-len(prompt)] - self.buf = self.buf[end:] - return buf + def read_to_prompt(self, prompts, timeout): + wait_until = time.time() + timeout + while time.time() < wait_until: + has_value, read_byte = self._read_stdout_byte() + if not has_value: + continue + if not read_byte: + # EOF on macOS ends up here. + break + read_byte = read_byte.decode('utf-8') if IS_PY_3 else read_byte + + debug(read_byte) + if self.no_pty: + self.buf += read_byte.replace('\n', '\r\n') + else: + self.buf += read_byte + self.buf = self.buf.replace('\r\r', '\r') + + # filter the prompts + for prompt in prompts: + pattern = re.compile(prompt) + match = pattern.search(self.buf) + if match: + end = match.end() + buf = self.buf[0:end-len(prompt)] + self.buf = self.buf[end:] + return buf return None def writeline(self, str): @@ -140,6 +213,8 @@ def writeline(self, str): self.stdin.write(str_to_write) def cleanup(self): + atexit.unregister(self.cleanup) + if self.process: try: self.writeline("__exit__") @@ -157,6 +232,8 @@ def cleanup(self): self.stdout = None if not IS_PY_3: sys.exc_clear() + if self._stream_reader: + self._stream_reader.cleanup() def assert_prompt(runner, prompts, timeout, is_need_execute_result): # Wait for the initial prompt @@ -400,11 +477,11 @@ def cast_v128_to_i64x2(numbers, type, lane_type): assert(packed) unpacked = struct.unpack("Q Q", packed) - return unpacked, "[{} {}]:{}:v128".format(unpacked[0], unpacked[1], lane_type) - + return unpacked, f"[{unpacked[0]:#x} {unpacked[1]:#x}]:{lane_type}:v128" def parse_simple_const_w_type(number, type): number = number.replace('_', '') + number = re.sub(r"nan\((ind|snan)\)", "nan", number) if type in ["i32", "i64"]: number = int(number, 16) if '0x' in number else int(number) return number, "0x{:x}:{}".format(number, type) \ @@ -412,13 +489,7 @@ def parse_simple_const_w_type(number, type): else "-0x{:x}:{}".format(0 - number, type) elif type in ["f32", "f64"]: if "nan:" in number: - # TODO: how to handle this correctly - if "nan:canonical" in number: - return float.fromhex("0x200000"), "nan:{}".format(type) - elif "nan:arithmetic" in number: - return float.fromhex("-0x200000"), "nan:{}".format(type) - else: - return float('nan'), "nan:{}".format(type) + return float('nan'), "nan:{}".format(type) else: number = float.fromhex(number) if '0x' in number else float(number) return number, "{:.7g}:{}".format(number, type) @@ -542,9 +613,6 @@ def vector_value_comparison(out, expected): if out_type != expected_type: return False - if out_val == expected_val: - return True - out_val = out_val.split(" ") expected_val = expected_val.split(" ") @@ -568,12 +636,14 @@ def vector_value_comparison(out, expected): out_is_nan = [math.isnan(o) for o in out_unpacked] expected_is_nan = [math.isnan(e) for e in expected_unpacked] - if out_is_nan and expected_is_nan: - return True; + if any(out_is_nan): + nan_comparision = [o == e for o, e in zip(out_is_nan, expected_is_nan)] + if all(nan_comparision): + print(f"Pass NaN comparision") + return True - # print("compare {} and {}".format(out_unpacked, expected_unpacked)) + # print(f"compare {out_unpacked} and {expected_unpacked}") result = [o == e for o, e in zip(out_unpacked, expected_unpacked)] - if not all(result): result = [ "{:.7g}".format(o) == "{:.7g}".format(e) @@ -778,7 +848,7 @@ def test_assert_return(r, opts, form): numbers, _ = cast_v128_to_i64x2(splitted[2:], 'v128', splitted[1]) assert(len(numbers) == 2), "has to reform arguments into i64x2" - args.append("{}\{}".format(numbers[0], numbers[1])) + args.append(f"{numbers[0]:#x}\{numbers[1]:#x}") elif "ref.null" == splitted[0]: args.append("null") elif "ref.extern" == splitted[0]: @@ -948,7 +1018,8 @@ def skip_test(form, skip_list): def compile_wast_to_wasm(form, wast_tempfile, wasm_tempfile, opts): log("Writing WAST module to '%s'" % wast_tempfile) - open(wast_tempfile, 'w').write(form) + with open(wast_tempfile, 'w') as file: + file.write(form) log("Compiling WASM to '%s'" % wasm_tempfile) # default arguments @@ -975,27 +1046,8 @@ def compile_wasm_to_aot(wasm_tempfile, aot_tempfile, runner, opts, r, output = ' log("Compiling AOT to '%s'" % aot_tempfile) cmd = [opts.aot_compiler] - if test_target == "x86_64": - cmd.append("--target=x86_64") - cmd.append("--cpu=skylake") - elif test_target == "i386": - cmd.append("--target=i386") - elif test_target == "aarch64": - cmd += ["--target=aarch64", "--cpu=cortex-a57"] - elif test_target == "armv7": - cmd += ["--target=armv7", "--target-abi=gnueabihf"] - elif test_target == "thumbv7": - cmd += ["--target=thumbv7", "--target-abi=gnueabihf", "--cpu=cortex-a9", "--cpu-features=-neon"] - elif test_target == "riscv32_ilp32": - cmd += ["--target=riscv32", "--target-abi=ilp32", "--cpu=generic-rv32", "--cpu-features=+m,+a,+c"] - elif test_target == "riscv32_ilp32d": - cmd += ["--target=riscv32", "--target-abi=ilp32d", "--cpu=generic-rv32", "--cpu-features=+m,+a,+c"] - elif test_target == "riscv64_lp64": - cmd += ["--target=riscv64", "--target-abi=lp64", "--cpu=generic-rv64", "--cpu-features=+m,+a,+c"] - elif test_target == "riscv64_lp64d": - cmd += ["--target=riscv64", "--target-abi=lp64d", "--cpu=generic-rv32", "--cpu-features=+m,+a,+c"] - else: - pass + if test_target in aot_target_options_map: + cmd += aot_target_options_map[test_target] if opts.sgx: cmd.append("-sgx") @@ -1020,6 +1072,17 @@ def compile_wasm_to_aot(wasm_tempfile, aot_tempfile, runner, opts, r, output = ' # exception isn't thrown in several cases cmd.append("--disable-llvm-lto") + # Bounds checks is disabled by default for 64-bit targets, to + # use the hardware based bounds checks. But it is not supported + # in QEMU with NuttX. + # Enable bounds checks explicitly for all targets if running in QEMU. + if opts.qemu: + cmd.append("--bounds-checks=1") + + # RISCV64 requires -mcmodel=medany, which can be set by --size-level=1 + if test_target.startswith("riscv64"): + cmd.append("--size-level=1") + cmd += ["-o", aot_tempfile, wasm_tempfile] log("Running: %s" % " ".join(cmd)) @@ -1044,12 +1107,20 @@ def run_wasm_with_repl(wasm_tempfile, aot_tempfile, opts, r): if opts.qemu_firmware == '': raise Exception("QEMU firmware missing") - if opts.target == "thumbv7": - cmd = ["qemu-system-arm", "-semihosting", "-M", "sabrelite", "-m", "1024", "-smp", "4", "-nographic", "-kernel", opts.qemu_firmware] - elif opts.target == "riscv32_ilp32": - cmd = ["qemu-system-riscv32", "-semihosting", "-M", "virt,aclint=on", "-cpu", "rv32", "-smp", "8", "-nographic", "-bios", "none", "-kernel", opts.qemu_firmware] - elif opts.target == "riscv64_lp64": - cmd = ["qemu-system-riscv64", "-semihosting", "-M", "virt,aclint=on", "-cpu", "rv64", "-smp", "8", "-nographic", "-bios", "none", "-kernel", opts.qemu_firmware] + if opts.target.startswith("aarch64"): + cmd = "qemu-system-aarch64 -cpu cortex-a53 -nographic -machine virt,virtualization=on,gic-version=3 -net none -chardev stdio,id=con,mux=on -serial chardev:con -mon chardev=con,mode=readline -kernel".split() + cmd.append(opts.qemu_firmware) + elif opts.target.startswith("thumbv7"): + cmd = "qemu-system-arm -semihosting -M sabrelite -m 1024 -smp 1 -nographic -kernel".split() + cmd.append(opts.qemu_firmware) + elif opts.target.startswith("riscv32"): + cmd = "qemu-system-riscv32 -semihosting -M virt,aclint=on -cpu rv32 -smp 1 -nographic -bios none -kernel".split() + cmd.append(opts.qemu_firmware) + elif opts.target.startswith("riscv64"): + cmd = "qemu-system-riscv64 -semihosting -M virt,aclint=on -cpu rv64 -smp 1 -nographic -bios none -kernel".split() + cmd.append(opts.qemu_firmware) + else: + raise Exception("Unknwon target for QEMU: %s" % opts.target) else: cmd = cmd_iwasm @@ -1070,13 +1141,10 @@ def run_wasm_with_repl(wasm_tempfile, aot_tempfile, opts, r): def create_tmpfiles(wast_name): tempfiles = [] - (t1fd, wast_tempfile) = tempfile.mkstemp(suffix=".wast") - (t2fd, wasm_tempfile) = tempfile.mkstemp(suffix=".wasm") - tempfiles.append(wast_tempfile) - tempfiles.append(wasm_tempfile) + tempfiles.append(create_tmp_file(".wast")) + tempfiles.append(create_tmp_file(".wasm")) if test_aot: - (t3fd, aot_tempfile) = tempfile.mkstemp(suffix=".aot") - tempfiles.append(aot_tempfile) + tempfiles.append(create_tmp_file(".aot")) # add these temp file to temporal repo, will be deleted when finishing the test temp_file_repo.extend(tempfiles) @@ -1129,7 +1197,7 @@ def test_assert_with_exception(form, wast_tempfile, wasm_tempfile, aot_tempfile, if __name__ == "__main__": opts = parser.parse_args(sys.argv[1:]) - print('Input param :',opts) + # print('Input param :',opts) if opts.aot: test_aot = True # default x86_64 @@ -1145,14 +1213,14 @@ def test_assert_with_exception(form, wast_tempfile, wasm_tempfile, aot_tempfile, else: SKIP_TESTS = C_SKIP_TESTS - (t1fd, wast_tempfile) = tempfile.mkstemp(suffix=".wast") - (t2fd, wasm_tempfile) = tempfile.mkstemp(suffix=".wasm") + wast_tempfile = create_tmp_file(".wast") + wasm_tempfile = create_tmp_file(".wasm") if test_aot: - (t3fd, aot_tempfile) = tempfile.mkstemp(suffix=".aot") + aot_tempfile = create_tmp_file(".aot") ret_code = 0 try: - log("################################################") + log("\n################################################") log("### Testing %s" % opts.test_file.name) log("################################################") forms = read_forms(opts.test_file.read()) @@ -1179,17 +1247,16 @@ def test_assert_with_exception(form, wast_tempfile, wasm_tempfile, aot_tempfile, # workaround: spec test changes error message to "malformed" while iwasm still use "invalid" error_msg = m.group(2).replace("malformed", "invalid") log("Testing(malformed)") - f = open(wasm_tempfile, 'wb') - s = m.group(1) - while s: - res = re.match("[^\"]*\"([^\"]*)\"(.*)", s, re.DOTALL) - if IS_PY_3: - context = res.group(1).replace("\\", "\\x").encode("latin1").decode("unicode-escape").encode("latin1") - f.write(context) - else: - f.write(res.group(1).replace("\\", "\\x").decode("string-escape")) - s = res.group(2) - f.close() + with open(wasm_tempfile, 'wb') as f: + s = m.group(1) + while s: + res = re.match("[^\"]*\"([^\"]*)\"(.*)", s, re.DOTALL) + if IS_PY_3: + context = res.group(1).replace("\\", "\\x").encode("latin1").decode("unicode-escape").encode("latin1") + f.write(context) + else: + f.write(res.group(1).replace("\\", "\\x").decode("string-escape")) + s = res.group(2) # compile wasm to aot if test_aot: @@ -1299,6 +1366,16 @@ def test_assert_with_exception(form, wast_tempfile, wasm_tempfile, aot_tempfile, # add new_module copied from the old into temp_file_repo[] temp_file_repo.append(new_module) + + if test_aot: + new_module_aot = os.path.join(tempfile.gettempdir(), name_new + ".aot") + r = compile_wasm_to_aot(new_module, new_module_aot, True, opts, r) + try: + assert_prompt(r, ['Compile success'], opts.start_timeout, True) + except: + raise Exception("compile wasm to aot failed") + # add aot module into temp_file_repo[] + temp_file_repo.append(new_module_aot) else: # there is no name defined in register cmd raise Exception("can not find module name from the register") @@ -1341,3 +1418,4 @@ def test_assert_with_exception(form, wast_tempfile, wasm_tempfile, aot_tempfile, log("Leaving tempfiles: %s" % ([wast_tempfile, wasm_tempfile])) sys.exit(ret_code) + \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/simd_ignore_cases.patch b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/simd_ignore_cases.patch similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/simd_ignore_cases.patch rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/simd_ignore_cases.patch diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/tail-call/return_call.wast b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/tail-call/return_call.wast similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/tail-call/return_call.wast rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/tail-call/return_call.wast diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/tail-call/return_call_indirect.wast b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/tail-call/return_call_indirect.wast similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/tail-call/return_call_indirect.wast rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/tail-call/return_call_indirect.wast diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/thread_proposal_fix_atomic_case.patch b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/thread_proposal_fix_atomic_case.patch similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/thread_proposal_fix_atomic_case.patch rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/thread_proposal_fix_atomic_case.patch diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/thread_proposal_ignore_cases.patch b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/thread_proposal_ignore_cases.patch similarity index 91% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/thread_proposal_ignore_cases.patch rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/thread_proposal_ignore_cases.patch index 41a0d25b8e4..c411d89c132 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/thread_proposal_ignore_cases.patch +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/spec-test-script/thread_proposal_ignore_cases.patch @@ -1,5 +1,22 @@ +diff --git a/test/core/atomic_wait_notify.wast b/test/core/atomic_wait_notify.wast +index 2e312c3..4f35ac5 100644 +--- a/test/core/atomic_wait_notify.wast ++++ b/test/core/atomic_wait_notify.wast +@@ -70,6 +70,7 @@ + (memory (export "shared") 1 1 shared) + ) + ++(; + (thread $T1 (shared (module $Mem)) + (register "mem" $Mem) + (module +@@ -106,3 +107,4 @@ + + (wait $T1) + (wait $T2) ++;) diff --git a/test/core/binary.wast b/test/core/binary.wast -index b9fa438c..a5711dd3 100644 +index b9fa438..a5711dd 100644 --- a/test/core/binary.wast +++ b/test/core/binary.wast @@ -45,7 +45,7 @@ @@ -163,7 +180,7 @@ index b9fa438c..a5711dd3 100644 ;; 1 elem segment declared, 2 given (assert_malformed diff --git a/test/core/elem.wast b/test/core/elem.wast -index 1ea2b061..8eded377 100644 +index 1ea2b06..8eded37 100644 --- a/test/core/elem.wast +++ b/test/core/elem.wast @@ -12,10 +12,10 @@ @@ -195,7 +212,7 @@ index 1ea2b061..8eded377 100644 (assert_return (invoke $module1 "call-9") (i32.const 70)) +;) diff --git a/test/core/thread.wast b/test/core/thread.wast -index c3456a61..83fc2815 100644 +index c3456a6..83fc281 100644 --- a/test/core/thread.wast +++ b/test/core/thread.wast @@ -2,6 +2,7 @@ diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/test_wamr.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/test_wamr.sh similarity index 85% rename from lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/test_wamr.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/test_wamr.sh index 67868b9c9ed..76b235d499e 100755 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/test_wamr.sh +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/test_wamr.sh @@ -14,8 +14,10 @@ function help() { echo "test_wamr.sh [options]" echo "-c clean previous test results, not start test" - echo "-s {suite_name} test only one suite (spec|wasi_certification)" - echo "-m set compile target of iwasm(x86_64|x86_32|armv7_vfp|thumbv7_vfp|riscv64_lp64d|riscv64_lp64)" + echo "-s {suite_name} test only one suite (spec|wasi_certification|wamr_compiler)" + echo "-m set compile target of iwasm(x86_64|x86_32|armv7|armv7_vfp|thumbv7|thumbv7_vfp|" + echo " riscv32|riscv32_ilp32f|riscv32_ilp32d|riscv64|" + echo " riscv64_lp64f|riscv64_lp64d|aarch64|aarch64_vfp)" echo "-t set compile type of iwasm(classic-interp|fast-interp|jit|aot|fast-jit|multi-tier-jit)" echo "-M enable multi module feature" echo "-p enable multi thread feature" @@ -31,6 +33,8 @@ function help() echo "-Q enable qemu" echo "-F set the firmware path used by qemu" echo "-C enable code coverage collect" + echo "-j set the platform to test" + echo "-T set sanitizer to use in tests(ubsan|tsan|asan)" } OPT_PARSED="" @@ -51,13 +55,22 @@ ENABLE_GC_HEAP_VERIFY=0 #unit test case arrary TEST_CASE_ARR=() SGX_OPT="" -PLATFORM=$(uname -s | tr A-Z a-z) +if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then + PLATFORM=windows + PYTHON_EXE=python +else + PLATFORM=$(uname -s | tr A-Z a-z) + PYTHON_EXE=python3 +fi PARALLELISM=0 ENABLE_QEMU=0 QEMU_FIRMWARE="" -WASI_TESTSUITE_COMMIT="aca78d919355ae00af141e6741a439039615b257" +# prod/testsuite-all branch +WASI_TESTSUITE_COMMIT="ee807fc551978490bf1c277059aabfa1e589a6c2" +TARGET_LIST=("AARCH64" "AARCH64_VFP" "ARMV7" "ARMV7_VFP" "THUMBV7" "THUMBV7_VFP" \ + "RISCV32" "RISCV32_ILP32F" "RISCV32_ILP32D" "RISCV64" "RISCV64_LP64F" "RISCV64_LP64D") -while getopts ":s:cabgvt:m:MCpSXxwPGQF:" opt +while getopts ":s:cabgvt:m:MCpSXxwPGQF:j:T:" opt do OPT_PARSED="TRUE" case $opt in @@ -159,9 +172,18 @@ do echo "QEMU firmware" ${OPTARG} QEMU_FIRMWARE=${OPTARG} ;; + j) + echo "test platform " ${OPTARG} + PLATFORM=${OPTARG} + ;; + T) + echo "sanitizer is " ${OPTARG} + WAMR_BUILD_SANITIZER=${OPTARG} + ;; ?) help - exit 1;; + exit 1 + ;; esac done @@ -303,6 +325,56 @@ function sightglass_test() echo "Finish sightglass benchmark tests" } +function setup_wabt() +{ + if [ ${WABT_BINARY_RELEASE} == "YES" ]; then + echo "download a binary release and install" + local WAT2WASM=${WORK_DIR}/wabt/out/gcc/Release/wat2wasm + if [ ! -f ${WAT2WASM} ]; then + case ${PLATFORM} in + cosmopolitan) + ;; + linux) + WABT_PLATFORM=ubuntu + ;; + darwin) + WABT_PLATFORM=macos-12 + ;; + windows) + WABT_PLATFORM=windows + ;; + *) + echo "wabt platform for ${PLATFORM} in unknown" + exit 1 + ;; + esac + if [ ! -f /tmp/wabt-1.0.31-${WABT_PLATFORM}.tar.gz ]; then + curl -L \ + https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-${WABT_PLATFORM}.tar.gz \ + -o /tmp/wabt-1.0.31-${WABT_PLATFORM}.tar.gz + fi + + cd /tmp \ + && tar zxf wabt-1.0.31-${WABT_PLATFORM}.tar.gz \ + && mkdir -p ${WORK_DIR}/wabt/out/gcc/Release/ \ + && install wabt-1.0.31/bin/wa* ${WORK_DIR}/wabt/out/gcc/Release/ \ + && cd - + fi + else + echo "download source code and compile and install" + if [ ! -d "wabt" ];then + echo "wabt not exist, clone it from github" + git clone --recursive https://github.com/WebAssembly/wabt + fi + echo "upate wabt" + cd wabt + git pull + git reset --hard origin/main + cd .. + make -C wabt gcc-release -j 4 + fi +} + # TODO: with iwasm only function spec_test() { @@ -332,6 +404,9 @@ function spec_test() if [[ ${ENABLE_SIMD} == 1 ]]; then git apply ../../spec-test-script/simd_ignore_cases.patch fi + if [[ ${ENABLE_MULTI_MODULE} == 1 && $1 == 'aot' ]]; then + git apply ../../spec-test-script/multi_module_aot_ignore_cases.patch + fi # udpate thread cases if [ ${ENABLE_MULTI_THREAD} == 1 ]; then @@ -374,47 +449,7 @@ function spec_test() popd echo $(pwd) - if [ ${WABT_BINARY_RELEASE} == "YES" ]; then - echo "download a binary release and install" - local WAT2WASM=${WORK_DIR}/wabt/out/gcc/Release/wat2wasm - if [ ! -f ${WAT2WASM} ]; then - case ${PLATFORM} in - linux) - WABT_PLATFORM=ubuntu - ;; - darwin) - WABT_PLATFORM=macos - ;; - *) - echo "wabt platform for ${PLATFORM} in unknown" - exit 1 - ;; - esac - if [ ! -f /tmp/wabt-1.0.31-${WABT_PLATFORM}.tar.gz ]; then - wget \ - https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-${WABT_PLATFORM}.tar.gz \ - -P /tmp - fi - - cd /tmp \ - && tar zxf wabt-1.0.31-${WABT_PLATFORM}.tar.gz \ - && mkdir -p ${WORK_DIR}/wabt/out/gcc/Release/ \ - && install wabt-1.0.31/bin/wa* ${WORK_DIR}/wabt/out/gcc/Release/ \ - && cd - - fi - else - echo "download source code and compile and install" - if [ ! -d "wabt" ];then - echo "wabt not exist, clone it from github" - git clone --recursive https://github.com/WebAssembly/wabt - fi - echo "upate wabt" - cd wabt - git pull - git reset --hard origin/main - cd .. - make -C wabt gcc-release -j 4 - fi + setup_wabt ln -sf ${WORK_DIR}/../spec-test-script/all.py . ln -sf ${WORK_DIR}/../spec-test-script/runtest.py . @@ -423,14 +458,14 @@ function spec_test() # multi-module only enable in interp mode if [[ 1 == ${ENABLE_MULTI_MODULE} ]]; then - if [[ $1 == 'classic-interp' || $1 == 'fast-interp' ]]; then + if [[ $1 == 'classic-interp' || $1 == 'fast-interp' || $1 == 'aot' ]]; then ARGS_FOR_SPEC_TEST+="-M " fi fi # sgx only enable in interp mode and aot mode if [[ ${SGX_OPT} == "--sgx" ]];then - if [[ $1 == 'classic-interp' || $1 == 'fast-interp' || $1 == 'aot' ]]; then + if [[ $1 == 'classic-interp' || $1 == 'fast-interp' || $1 == 'aot' || $1 == 'fast-jit' ]]; then ARGS_FOR_SPEC_TEST+="-x " fi fi @@ -471,12 +506,16 @@ function spec_test() ARGS_FOR_SPEC_TEST+="--qemu-firmware ${QEMU_FIRMWARE} " fi + if [[ ${PLATFORM} == "windows" ]]; then + ARGS_FOR_SPEC_TEST+="--no-pty " + fi + # set log directory ARGS_FOR_SPEC_TEST+="--log ${REPORT_DIR}" cd ${WORK_DIR} - echo "python3 ./all.py ${ARGS_FOR_SPEC_TEST} | tee -a ${REPORT_DIR}/spec_test_report.txt" - python3 ./all.py ${ARGS_FOR_SPEC_TEST} | tee -a ${REPORT_DIR}/spec_test_report.txt + echo "${PYTHON_EXE} ./all.py ${ARGS_FOR_SPEC_TEST} | tee -a ${REPORT_DIR}/spec_test_report.txt" + ${PYTHON_EXE} ./all.py ${ARGS_FOR_SPEC_TEST} | tee -a ${REPORT_DIR}/spec_test_report.txt if [[ ${PIPESTATUS[0]} -ne 0 ]];then echo -e "\nspec tests FAILED" | tee -a ${REPORT_DIR}/spec_test_report.txt exit 1 @@ -502,20 +541,42 @@ function wasi_test() echo "Finish wasi tests" } +function wamr_compiler_test() +{ + if [[ $1 != "aot" ]]; then + echo "WAMR compiler tests only support AOT mode" + exit 1 + fi + + echo "Now start WAMR compiler tests" + setup_wabt + cd ${WORK_DIR}/../wamr-compiler-test-script + ./run_wamr_compiler_tests.sh ${WORK_DIR}/wabt/out/gcc/Release/wat2wasm $WAMRC_CMD $IWASM_CMD \ + | tee -a ${REPORT_DIR}/wamr_compiler_test_report.txt + + ret=${PIPESTATUS[0]} + + if [[ ${ret} -ne 0 ]];then + echo -e "\nWAMR compiler tests FAILED" | tee -a ${REPORT_DIR}/wamr_compiler_test_report.txt + exit 1 + fi + echo -e "\nFinish WAMR compiler tests" | tee -a ${REPORT_DIR}/wamr_compiler_test_report.txt +} + function wasi_certification_test() { echo "Now start wasi certification tests" cd ${WORK_DIR} if [ ! -d "wasi-testsuite" ]; then - echo "wasi not exist, clone it from github" + echo "wasi-testsuite not exist, clone it from github" git clone -b prod/testsuite-all \ --single-branch https://github.com/WebAssembly/wasi-testsuite.git fi cd wasi-testsuite git reset --hard ${WASI_TESTSUITE_COMMIT} - bash ../../wasi-test-script/run_wasi_tests.sh $1 $TARGET \ + TSAN_OPTIONS=${TSAN_OPTIONS} bash ../../wasi-test-script/run_wasi_tests.sh $1 $TARGET $WASI_TEST_FILTER \ | tee -a ${REPORT_DIR}/wasi_test_report.txt ret=${PIPESTATUS[0]} @@ -628,7 +689,7 @@ function standalone_test() function build_iwasm_with_cfg() { - echo "Build iwasm with compile flags with " $* " for spec test" \ + echo "Build iwasm with compile flags " $* " for spec test" \ | tee -a ${REPORT_DIR}/spec_test_report.txt if [[ ${SGX_OPT} == "--sgx" ]];then @@ -645,20 +706,32 @@ function build_iwasm_with_cfg() && if [ -d build ]; then rm -rf build/*; else mkdir build; fi \ && cd build \ && cmake $* .. \ - && make -j 4 + && cmake --build . -j 4 --config RelWithDebInfo --target iwasm fi if [ "$?" != 0 ];then echo -e "build iwasm failed" exit 1 fi + + if [[ ${PLATFORM} == "cosmopolitan" ]]; then + # convert from APE to ELF so it can be ran easier + # HACK: link to linux so tests work when platform is detected by uname + cp iwasm.com iwasm \ + && ./iwasm --assimilate \ + && rm -rf ../../linux/build \ + && mkdir ../../linux/build \ + && ln -s ../../cosmopolitan/build/iwasm ../../linux/build/iwasm + if [ "$?" != 0 ];then + echo -e "build iwasm failed (cosmopolitan)" + exit 1 + fi + fi } function build_wamrc() { - if [[ $TARGET == "ARMV7_VFP" || $TARGET == "THUMBV7_VFP" - || $TARGET == "RISCV32" || $TARGET == "RISCV32_ILP32" || $TARGET == "RISCV32_ILP32D" - || $TARGET == "RISCV64" || $TARGET == "RISCV64_LP64D" || $TARGET == "RISCV64_LP64" ]];then + if [[ "${TARGET_LIST[*]}" =~ "${TARGET}" ]]; then echo "suppose wamrc is already built" return fi @@ -754,6 +827,34 @@ function trigger() EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_LIB_WASI_THREADS=1" fi + echo "SANITIZER IS" $WAMR_BUILD_SANITIZER + + if [[ "$WAMR_BUILD_SANITIZER" == "ubsan" ]]; then + echo "Setting run with ubsan" + EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SANITIZER=ubsan" + fi + + if [[ "$WAMR_BUILD_SANITIZER" == "asan" ]]; then + echo "Setting run with asan" + EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SANITIZER=asan" + fi + + if [[ "$WAMR_BUILD_SANITIZER" == "tsan" ]]; then + echo "Setting run with tsan" + EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SANITIZER=tsan" + fi + + # Make sure we're using the builtin WASI libc implementation + # if we're running the wasi certification tests. + if [[ $TEST_CASE_ARR ]]; then + for test in "${TEST_CASE_ARR[@]}"; do + if [[ "$test" == "wasi_certification" ]]; then + EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_LIBC_UVWASI=0 -DWAMR_BUILD_LIBC_WASI=1" + break + fi + done + fi + for t in "${TYPE[@]}"; do case $t in "classic-interp") @@ -807,7 +908,7 @@ function trigger() collect_coverage llvm-jit echo "work in orc jit lazy compilation mode" - BUILD_FLAGS="$ORC_EAGER_JIT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS" + BUILD_FLAGS="$ORC_LAZY_JIT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS" build_iwasm_with_cfg $BUILD_FLAGS for suite in "${TEST_CASE_ARR[@]}"; do $suite"_test" jit diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/tsan_suppressions.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/tsan_suppressions.txt new file mode 100644 index 00000000000..d79eafddc56 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/tsan_suppressions.txt @@ -0,0 +1,7 @@ +# Proposing to accept this risk for now. It might be wasi-libc related. +# https://github.com/bytecodealliance/wasm-micro-runtime/pull/1963#issuecomment-1455342931 +race:STORE_U32 + +# Suppressing signal-unsafe inside of a signal for AOT mode +# see https://github.com/bytecodealliance/wasm-micro-runtime/issues/2248#issuecomment-1630189656 +signal:* \ No newline at end of file diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/wamr-compiler-test-script/run_wamr_compiler_tests.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/wamr-compiler-test-script/run_wamr_compiler_tests.sh new file mode 100755 index 00000000000..19c8030d01c --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/wamr-compiler-test-script/run_wamr_compiler_tests.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Copyright (C) 2023 Amazon Inc. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +set -e + +WAT2WASM_CMD=$1 +WAMRC_CMD=$2 +IWASM_CMD=$3 + +for wat_file in ../../wamr-compiler/*.wat; do + wasm_file="${wat_file%.wat}.wasm" + aot_file="${wat_file%.wat}.aot" + + echo "Compiling $wat_file to $wasm_file" + $WAT2WASM_CMD "$wat_file" -o "$wasm_file" + echo "Compiling $wasm_file to $aot_file" + $WAMRC_CMD -o $aot_file $wasm_file + echo "Testing $aot_file" + $IWASM_CMD "$aot_file" +done diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/wasi-test-script/pipe.py b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/wasi-test-script/pipe.py new file mode 100644 index 00000000000..e374087176b --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/wasi-test-script/pipe.py @@ -0,0 +1,19 @@ +#! /usr/bin/env python3 + +# Copyright (C) 2023 YAMAMOTO Takashi +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# This is a copy of https://github.com/yamt/toywasm/blob/master/test/pipe.py + +# keep stdout open until the peer closes it + +import sys +import select + +p = select.poll() +p.register(sys.stdout, select.POLLHUP) +# http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=57369 +while True: + l = p.poll(1) + if l: + break diff --git a/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/wasi-test-script/run_wasi_tests.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/wasi-test-script/run_wasi_tests.sh new file mode 100755 index 00000000000..4cfe6c29be9 --- /dev/null +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/tests/wamr-test-suites/wasi-test-script/run_wasi_tests.sh @@ -0,0 +1,151 @@ +#!/bin/bash + +# +# Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# + +THIS_DIR=$(cd $(dirname $0) && pwd -P) + +readonly MODE=$1 +readonly TARGET=$2 +readonly TEST_FILTER=$3 + +readonly WORK_DIR=$PWD + +if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then + readonly PLATFORM=windows + readonly PYTHON_EXE=python + # see https://github.com/pypa/virtualenv/commit/993ba1316a83b760370f5a3872b3f5ef4dd904c1 + readonly VENV_BIN_DIR=Scripts + readonly IWASM_EXE=$(cygpath -m "${WORK_DIR}/../../../../product-mini/platforms/${PLATFORM}/build/RelWithDebInfo/iwasm.exe") +else + readonly PLATFORM=$(uname -s | tr A-Z a-z) + readonly VENV_BIN_DIR=bin + readonly PYTHON_EXE=python3 + readonly IWASM_EXE="${WORK_DIR}/../../../../product-mini/platforms/${PLATFORM}/build/iwasm" +fi + +readonly WAMR_DIR="${WORK_DIR}/../../../.." +readonly IWASM_CMD="${IWASM_EXE} \ + --allow-resolve=google-public-dns-a.google.com \ + --addr-pool=::1/128,127.0.0.1/32" + +readonly IWASM_CMD_STRESS="${IWASM_CMD} --max-threads=12" +readonly WAMRC_CMD="${WORK_DIR}/../../../../wamr-compiler/build/wamrc" +readonly C_TESTS="tests/c/testsuite/" +readonly RUST_TESTS="tests/rust/testsuite/" +readonly ASSEMBLYSCRIPT_TESTS="tests/assemblyscript/testsuite/" +readonly THREAD_PROPOSAL_TESTS="tests/proposals/wasi-threads/" +readonly THREAD_INTERNAL_TESTS="${WAMR_DIR}/core/iwasm/libraries/lib-wasi-threads/test/" +readonly THREAD_STRESS_TESTS="${WAMR_DIR}/core/iwasm/libraries/lib-wasi-threads/stress-test/" +readonly LIB_SOCKET_TESTS="${WAMR_DIR}/core/iwasm/libraries/lib-socket/test/" + +run_aot_tests () { + local -n tests=$1 + local -n excluded_tests=$2 + + for test_wasm in ${tests[@]}; do + # get the base file name from the filepath + local test_name=${test_wasm##*/} + test_name=${test_name%.wasm} + + for excluded_test in "${excluded_tests[@]}"; do + if [[ $excluded_test == "\"$test_name\"" ]]; then + echo "Skipping test $test_name" + continue 2 + fi + done + + local iwasm="${IWASM_CMD}" + if [[ $test_wasm =~ "stress" ]]; then + iwasm="${IWASM_CMD_STRESS}" + fi + + test_aot="${test_wasm%.wasm}.aot" + test_json="${test_wasm%.wasm}.json" + + if [ -f ${test_wasm} ]; then + expected=$(jq .exit_code ${test_json}) + fi + + echo "Compiling $test_wasm to $test_aot" + ${WAMRC_CMD} --enable-multi-thread ${target_option} \ + -o ${test_aot} ${test_wasm} + + echo "Running $test_aot" + expected=0 + if [ -f ${test_json} ]; then + expected=$(jq .exit_code ${test_json}) + fi + + $PYTHON_EXE ${THIS_DIR}/pipe.py | ${iwasm} $test_aot + ret=${PIPESTATUS[1]} + + echo "expected=$expected, actual=$ret" + if [[ $expected != "" ]] && [[ $expected != $ret ]];then + exit_code=1 + fi + done +} + +if [[ $MODE != "aot" ]];then + $PYTHON_EXE -m venv wasi-env && source wasi-env/${VENV_BIN_DIR}/activate + $PYTHON_EXE -m pip install -r test-runner/requirements.txt + + export TEST_RUNTIME_EXE="${IWASM_CMD}" + + TEST_OPTIONS="-r adapters/wasm-micro-runtime.py \ + -t \ + ${C_TESTS} \ + ${RUST_TESTS} \ + ${ASSEMBLYSCRIPT_TESTS} \ + ${THREAD_PROPOSAL_TESTS} \ + ${THREAD_INTERNAL_TESTS} \ + ${LIB_SOCKET_TESTS}" + + if [ -n "$TEST_FILTER" ]; then + TEST_OPTIONS="${TEST_OPTIONS} --exclude-filter ${TEST_FILTER}" + fi + + $PYTHON_EXE ${THIS_DIR}/pipe.py | TSAN_OPTIONS=${TSAN_OPTIONS} $PYTHON_EXE test-runner/wasi_test_runner.py $TEST_OPTIONS + + ret=${PIPESTATUS[1]} + + TEST_RUNTIME_EXE="${IWASM_CMD_STRESS}" TSAN_OPTIONS=${TSAN_OPTIONS} $PYTHON_EXE test-runner/wasi_test_runner.py \ + -r adapters/wasm-micro-runtime.py \ + -t \ + ${THREAD_STRESS_TESTS} + + if [ "${ret}" -eq 0 ]; then + ret=${PIPESTATUS[0]} + fi + + exit_code=${ret} + + deactivate +else + target_option="" + if [[ $TARGET == "X86_32" ]];then + target_option="--target=i386" + fi + + exit_code=0 + for testsuite in ${THREAD_STRESS_TESTS} ${THREAD_PROPOSAL_TESTS} ${THREAD_INTERNAL_TESTS}; do + tests=$(ls ${testsuite}*.wasm) + tests_array=($tests) + + if [ -n "$TEST_FILTER" ]; then + readarray -t excluded_tests_array < <(jq -c \ + --slurpfile testsuite_manifest $testsuite/manifest.json \ + '.[$testsuite_manifest[0].name] // {} | keys[]' \ + $TEST_FILTER) + else + excluded_tests_array=() + fi + + run_aot_tests tests_array excluded_tests_array + done +fi + +exit ${exit_code} diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-compiler/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-compiler/CMakeLists.txt similarity index 98% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-compiler/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-compiler/CMakeLists.txt index 0ae821af651..5fe8fae16f2 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-compiler/CMakeLists.txt +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-compiler/CMakeLists.txt @@ -21,7 +21,7 @@ else() add_definitions(-DCOMPILING_WASM_RUNTIME_API=1) endif() -set (CMAKE_CXX_STANDARD 14) +set (CMAKE_CXX_STANDARD 17) if (NOT DEFINED WAMR_BUILD_PLATFORM) set (WAMR_BUILD_PLATFORM "linux") @@ -45,6 +45,7 @@ add_definitions(-DWASM_ENABLE_DUMP_CALL_STACK=1) add_definitions(-DWASM_ENABLE_PERF_PROFILING=1) add_definitions(-DWASM_ENABLE_LOAD_CUSTOM_SECTION=1) add_definitions(-DWASM_ENABLE_LIB_WASI_THREADS=1) +add_definitions(-DWASM_ENABLE_MODULE_INST_CONTEXT=1) if (WAMR_BUILD_LLVM_LEGACY_PM EQUAL 1) add_definitions(-DWASM_ENABLE_LLVM_LEGACY_PM=1) @@ -197,6 +198,12 @@ include_directories (${SHARED_DIR}/include enable_language (ASM) +if (NOT MINGW AND NOT MSVC) + set(WAMR_BUILD_LIBC_WASI 1) +else() + set(WAMR_BUILD_LIBC_UVWASI 1) +endif() + include (${SHARED_DIR}/platform/${WAMR_BUILD_PLATFORM}/shared_platform.cmake) include (${SHARED_DIR}/mem-alloc/mem_alloc.cmake) include (${SHARED_DIR}/utils/shared_utils.cmake) diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-compiler/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-compiler/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-compiler/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-compiler/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-compiler/build_llvm.py b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-compiler/build_llvm.py similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-compiler/build_llvm.py rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-compiler/build_llvm.py diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-compiler/build_llvm.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-compiler/build_llvm.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-compiler/build_llvm.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-compiler/build_llvm.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-compiler/build_llvm_arc.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-compiler/build_llvm_arc.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-compiler/build_llvm_arc.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-compiler/build_llvm_arc.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-compiler/build_llvm_xtensa.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-compiler/build_llvm_xtensa.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-compiler/build_llvm_xtensa.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-compiler/build_llvm_xtensa.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-compiler/main.c b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-compiler/main.c similarity index 60% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-compiler/main.c rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-compiler/main.c index bd8691c4b87..0d85b99ce92 100644 --- a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-compiler/main.c +++ b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-compiler/main.c @@ -9,6 +9,100 @@ #include "wasm_export.h" #include "aot_export.h" +#if BH_HAS_DLFCN +#include + +typedef uint32 (*get_native_lib_func)(char **p_module_name, + NativeSymbol **p_native_symbols); + +static uint32 +load_and_register_native_libs(const char **native_lib_list, + uint32 native_lib_count, + void **native_handle_list) +{ + uint32 i, native_handle_count = 0, n_native_symbols; + NativeSymbol *native_symbols; + char *module_name; + void *handle; + + for (i = 0; i < native_lib_count; i++) { + /* open the native library */ + if (!(handle = dlopen(native_lib_list[i], RTLD_NOW | RTLD_GLOBAL)) + && !(handle = dlopen(native_lib_list[i], RTLD_LAZY))) { + LOG_WARNING("warning: failed to load native library %s", + native_lib_list[i]); + continue; + } + + /* lookup get_native_lib func */ + get_native_lib_func get_native_lib = dlsym(handle, "get_native_lib"); + if (!get_native_lib) { + LOG_WARNING("warning: failed to lookup `get_native_lib` function " + "from native lib %s", + native_lib_list[i]); + dlclose(handle); + continue; + } + + n_native_symbols = get_native_lib(&module_name, &native_symbols); + + /* register native symbols */ + if (!(n_native_symbols > 0 && module_name && native_symbols + && wasm_runtime_register_natives(module_name, native_symbols, + n_native_symbols))) { + LOG_WARNING("warning: failed to register native lib %s", + native_lib_list[i]); + dlclose(handle); + continue; + } + + native_handle_list[native_handle_count++] = handle; + } + + return native_handle_count; +} + +static void +unregister_and_unload_native_libs(uint32 native_lib_count, + void **native_handle_list) +{ + uint32 i, n_native_symbols; + NativeSymbol *native_symbols; + char *module_name; + void *handle; + + for (i = 0; i < native_lib_count; i++) { + handle = native_handle_list[i]; + + /* lookup get_native_lib func */ + get_native_lib_func get_native_lib = dlsym(handle, "get_native_lib"); + if (!get_native_lib) { + LOG_WARNING("warning: failed to lookup `get_native_lib` function " + "from native lib %p", + handle); + continue; + } + + n_native_symbols = get_native_lib(&module_name, &native_symbols); + if (n_native_symbols == 0 || module_name == NULL + || native_symbols == NULL) { + LOG_WARNING("warning: get_native_lib returned different values for " + "native lib %p", + handle); + continue; + } + + /* unregister native symbols */ + if (!wasm_runtime_unregister_natives(module_name, native_symbols)) { + LOG_WARNING("warning: failed to unregister native lib %p", handle); + continue; + } + + dlclose(handle); + } +} +#endif + /* clang-format off */ static void print_help() @@ -32,11 +126,14 @@ print_help() printf(" Use --cpu-features=+help to list all the features supported\n"); printf(" --opt-level=n Set the optimization level (0 to 3, default is 3)\n"); printf(" --size-level=n Set the code size level (0 to 3, default is 3)\n"); - printf(" -sgx Generate code for SGX platform (Intel Software Guard Extention)\n"); + printf(" -sgx Generate code for SGX platform (Intel Software Guard Extensions)\n"); printf(" --bounds-checks=1/0 Enable or disable the bounds checks for memory access:\n"); printf(" by default it is disabled in all 64-bit platforms except SGX and\n"); printf(" in these platforms runtime does bounds checks with hardware trap,\n"); printf(" and by default it is enabled in all 32-bit platforms\n"); + printf(" CAVEAT: --bounds-checks=0 enables some optimizations\n"); + printf(" which make the compiled AOT module incompatible\n"); + printf(" with a runtime without the hardware bounds checks.\n"); printf(" --stack-bounds-checks=1/0 Enable or disable the bounds checks for native stack:\n"); printf(" if the option isn't set, the status is same as `--bounds-check`,\n"); printf(" if the option is set:\n"); @@ -62,18 +159,42 @@ print_help() printf(" --enable-dump-call-stack Enable stack trace feature\n"); printf(" --enable-perf-profiling Enable function performance profiling\n"); printf(" --enable-memory-profiling Enable memory usage profiling\n"); - printf(" --enable-indirect-mode Enalbe call function through symbol table but not direct call\n"); + printf(" --xip A shorthand of --enable-indirect-mode --disable-llvm-intrinsics\n"); + printf(" --enable-indirect-mode Enable call function through symbol table but not direct call\n"); printf(" --disable-llvm-intrinsics Disable the LLVM built-in intrinsics\n"); + printf(" --enable-builtin-intrinsics=\n"); + printf(" Enable the specified built-in intrinsics, it will override the default\n"); + printf(" settings. It only takes effect when --disable-llvm-intrinsics is set.\n"); + printf(" Available flags: all, i32.common, i64.common, f32.common, f64.common,\n"); + printf(" i32.clz, i32.ctz, etc, refer to doc/xip.md for full list\n"); + printf(" Use comma to separate, please refer to doc/xip.md for full list.\n"); printf(" --disable-llvm-lto Disable the LLVM link time optimization\n"); + printf(" --enable-llvm-pgo Enable LLVM PGO (Profile-Guided Optimization)\n"); + printf(" --enable-llvm-passes=\n"); + printf(" Enable the specified LLVM passes, using comma to separate\n"); + printf(" --use-prof-file= Use profile file collected by LLVM PGO (Profile-Guided Optimization)\n"); + printf(" --enable-segue[=] Enable using segment register GS as the base address of linear memory,\n"); + printf(" only available on linux/linux-sgx x86-64, which may improve performance,\n"); + printf(" flags can be: i32.load, i64.load, f32.load, f64.load, v128.load,\n"); + printf(" i32.store, i64.store, f32.store, f64.store, v128.store\n"); + printf(" Use comma to separate, e.g. --enable-segue=i32.load,i64.store\n"); + printf(" and --enable-segue means all flags are added.\n"); printf(" --emit-custom-sections=
\n"); printf(" Emit the specified custom sections to AoT file, using comma to separate\n"); printf(" multiple names, e.g.\n"); printf(" --emit-custom-sections=section1,section2,sectionN\n"); +#if BH_HAS_DLFCN + printf(" --native-lib= Register native libraries to the WASM module, which\n"); + printf(" are shared object (.so) files, for example:\n"); + printf(" --native-lib=test1.so --native-lib=test2.so\n"); +#endif printf(" -v=n Set log verbose level (0 to 5, default is 2), larger with more log\n"); printf(" --version Show version information\n"); printf("Examples: wamrc -o test.aot test.wasm\n"); printf(" wamrc --target=i386 -o test.aot test.wasm\n"); printf(" wamrc --target=i386 --format=object -o test.o test.wasm\n"); + printf(" wamrc --target-abi=help\n"); + printf(" wamrc --target=x86_64 --cpu=help\n"); } /* clang-format on */ @@ -84,7 +205,7 @@ print_help() } while (0) /** - * Split a strings into an array of strings + * Split a string into an array of strings * Returns NULL on failure * Memory must be freed by caller * Based on: http://stackoverflow.com/a/11198630/471795 @@ -126,6 +247,63 @@ split_string(char *str, int *count, const char *delimer) return res; } +static uint32 +resolve_segue_flags(char *str_flags) +{ + uint32 segue_flags = 0; + int32 flag_count, i; + char **flag_list; + + flag_list = split_string(str_flags, &flag_count, ","); + if (flag_list) { + for (i = 0; i < flag_count; i++) { + if (!strcmp(flag_list[i], "i32.load")) { + segue_flags |= 1 << 0; + } + else if (!strcmp(flag_list[i], "i64.load")) { + segue_flags |= 1 << 1; + } + else if (!strcmp(flag_list[i], "f32.load")) { + segue_flags |= 1 << 2; + } + else if (!strcmp(flag_list[i], "f64.load")) { + segue_flags |= 1 << 3; + } + else if (!strcmp(flag_list[i], "v128.load")) { + segue_flags |= 1 << 4; + } + else if (!strcmp(flag_list[i], "i32.store")) { + segue_flags |= 1 << 8; + } + else if (!strcmp(flag_list[i], "i64.store")) { + segue_flags |= 1 << 9; + } + else if (!strcmp(flag_list[i], "f32.store")) { + segue_flags |= 1 << 10; + } + else if (!strcmp(flag_list[i], "f64.store")) { + segue_flags |= 1 << 11; + } + else if (!strcmp(flag_list[i], "v128.store")) { + segue_flags |= 1 << 12; + } + else { + /* invalid flag */ + segue_flags = (uint32)-1; + break; + } + } + free(flag_list); + } + return segue_flags; +} + +/* When print help info for target/cpu/target-abi/cpu-features, load this dummy + * wasm file content rather than from an input file, the dummy wasm file content + * is: magic header + version number */ +static unsigned char dummy_wasm_file[8] = { 0x00, 0x61, 0x73, 0x6D, + 0x01, 0x00, 0x00, 0x00 }; + int main(int argc, char *argv[]) { @@ -139,8 +317,14 @@ main(int argc, char *argv[]) AOTCompOption option = { 0 }; char error_buf[128]; int log_verbose_level = 2; - bool sgx_mode = false, size_level_set = false; + bool sgx_mode = false, size_level_set = false, use_dummy_wasm = false; int exit_status = EXIT_FAILURE; +#if BH_HAS_DLFCN + const char *native_lib_list[8] = { NULL }; + uint32 native_lib_count = 0; + void *native_handle_list[8] = { NULL }; + uint32 native_handle_count = 0; +#endif option.opt_level = 3; option.size_level = 3; @@ -166,21 +350,33 @@ main(int argc, char *argv[]) if (argv[0][9] == '\0') PRINT_HELP_AND_EXIT(); option.target_arch = argv[0] + 9; + if (!strcmp(option.target_arch, "help")) { + use_dummy_wasm = true; + } } else if (!strncmp(argv[0], "--target-abi=", 13)) { if (argv[0][13] == '\0') PRINT_HELP_AND_EXIT(); option.target_abi = argv[0] + 13; + if (!strcmp(option.target_abi, "help")) { + use_dummy_wasm = true; + } } else if (!strncmp(argv[0], "--cpu=", 6)) { if (argv[0][6] == '\0') PRINT_HELP_AND_EXIT(); option.target_cpu = argv[0] + 6; + if (!strcmp(option.target_cpu, "help")) { + use_dummy_wasm = true; + } } else if (!strncmp(argv[0], "--cpu-features=", 15)) { if (argv[0][15] == '\0') PRINT_HELP_AND_EXIT(); option.cpu_features = argv[0] + 15; + if (!strcmp(option.cpu_features, "+help")) { + use_dummy_wasm = true; + } } else if (!strncmp(argv[0], "--opt-level=", 12)) { if (argv[0][12] == '\0') @@ -263,15 +459,46 @@ main(int argc, char *argv[]) else if (!strcmp(argv[0], "--enable-memory-profiling")) { option.enable_stack_estimation = true; } + else if (!strcmp(argv[0], "--xip")) { + option.is_indirect_mode = true; + option.disable_llvm_intrinsics = true; + } else if (!strcmp(argv[0], "--enable-indirect-mode")) { option.is_indirect_mode = true; } else if (!strcmp(argv[0], "--disable-llvm-intrinsics")) { option.disable_llvm_intrinsics = true; } + else if (!strncmp(argv[0], "--enable-builtin-intrinsics=", 28)) { + if (argv[0][28] == '\0') + PRINT_HELP_AND_EXIT(); + option.builtin_intrinsics = argv[0] + 28; + } else if (!strcmp(argv[0], "--disable-llvm-lto")) { option.disable_llvm_lto = true; } + else if (!strcmp(argv[0], "--enable-llvm-pgo")) { + option.enable_llvm_pgo = true; + } + else if (!strncmp(argv[0], "--enable-llvm-passes=", 21)) { + if (argv[0][21] == '\0') + PRINT_HELP_AND_EXIT(); + option.llvm_passes = argv[0] + 21; + } + else if (!strncmp(argv[0], "--use-prof-file=", 16)) { + if (argv[0][16] == '\0') + PRINT_HELP_AND_EXIT(); + option.use_prof_file = argv[0] + 16; + } + else if (!strcmp(argv[0], "--enable-segue")) { + /* all flags are enabled */ + option.segue_flags = 0x1F1F; + } + else if (!strncmp(argv[0], "--enable-segue=", 15)) { + option.segue_flags = resolve_segue_flags(argv[0] + 15); + if (option.segue_flags == (uint32)-1) + PRINT_HELP_AND_EXIT(); + } else if (!strncmp(argv[0], "--emit-custom-sections=", 23)) { int len = 0; if (option.custom_sections) { @@ -287,6 +514,18 @@ main(int argc, char *argv[]) option.custom_sections_count = len; } +#if BH_HAS_DLFCN + else if (!strncmp(argv[0], "--native-lib=", 13)) { + if (argv[0][13] == '\0') + PRINT_HELP_AND_EXIT(); + if (native_lib_count >= sizeof(native_lib_list) / sizeof(char *)) { + printf("Only allow max native lib number %d\n", + (int)(sizeof(native_lib_list) / sizeof(char *))); + goto fail0; + } + native_lib_list[native_lib_count++] = argv[0] + 13; + } +#endif else if (!strncmp(argv[0], "--version", 9)) { uint32 major, minor, patch; wasm_runtime_get_version(&major, &minor, &patch); @@ -297,7 +536,7 @@ main(int argc, char *argv[]) PRINT_HELP_AND_EXIT(); } - if (argc == 0 || !out_file_name) + if (!use_dummy_wasm && (argc == 0 || !out_file_name)) PRINT_HELP_AND_EXIT(); if (!size_level_set) { @@ -325,11 +564,13 @@ main(int argc, char *argv[]) option.is_sgx_platform = true; } - wasm_file_name = argv[0]; + if (!use_dummy_wasm) { + wasm_file_name = argv[0]; - if (!strcmp(wasm_file_name, out_file_name)) { - printf("Error: input file and output file are the same"); - return -1; + if (!strcmp(wasm_file_name, out_file_name)) { + printf("Error: input file and output file are the same"); + return -1; + } } memset(&init_args, 0, sizeof(RuntimeInitArgs)); @@ -347,12 +588,25 @@ main(int argc, char *argv[]) bh_log_set_verbose_level(log_verbose_level); +#if BH_HAS_DLFCN + bh_print_time("Begin to load native libs"); + native_handle_count = load_and_register_native_libs( + native_lib_list, native_lib_count, native_handle_list); +#endif + bh_print_time("Begin to load wasm file"); - /* load WASM byte buffer from WASM bin file */ - if (!(wasm_file = - (uint8 *)bh_read_file_to_buffer(wasm_file_name, &wasm_file_size))) - goto fail1; + if (use_dummy_wasm) { + /* load WASM byte buffer from dummy buffer */ + wasm_file_size = sizeof(dummy_wasm_file); + wasm_file = dummy_wasm_file; + } + else { + /* load WASM byte buffer from WASM bin file */ + if (!(wasm_file = (uint8 *)bh_read_file_to_buffer(wasm_file_name, + &wasm_file_size))) + goto fail1; + } if (get_package_type(wasm_file, wasm_file_size) != Wasm_Module_Bytecode) { printf("Invalid file type: expected wasm file but got other\n"); @@ -434,9 +688,14 @@ main(int argc, char *argv[]) fail2: /* free the file buffer */ - wasm_runtime_free(wasm_file); + if (!use_dummy_wasm) { + wasm_runtime_free(wasm_file); + } fail1: +#if BH_HAS_DLFCN + unregister_and_unload_native_libs(native_handle_count, native_handle_list); +#endif /* Destroy runtime environment */ wasm_runtime_destroy(); diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/Kconfig b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/Kconfig similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/Kconfig rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/Kconfig diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/Makefile b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/Makefile similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/Makefile rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/Makefile diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/README.md b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/README.md similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/README.md rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/README.md diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/assert.h b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/assert.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/assert.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/assert.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/ctype.h b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/ctype.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/ctype.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/ctype.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/errno.h b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/errno.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/errno.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/errno.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/fcntl.h b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/fcntl.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/fcntl.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/fcntl.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/inttypes.h b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/inttypes.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/inttypes.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/inttypes.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/limits.h b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/limits.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/limits.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/limits.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/pthread.h b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/pthread.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/pthread.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/pthread.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/semaphore.h b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/semaphore.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/semaphore.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/semaphore.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/stdarg.h b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/stdarg.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/stdarg.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/stdarg.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/stdbool.h b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/stdbool.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/stdbool.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/stdbool.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/stdint.h b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/stdint.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/stdint.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/stdint.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/stdio.h b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/stdio.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/stdio.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/stdio.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/stdlib.h b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/stdlib.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/stdlib.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/stdlib.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/string.h b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/string.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/string.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/string.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/strings.h b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/strings.h similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/include/strings.h rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/include/strings.h diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/share/defined-symbols.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/share/defined-symbols.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/libc-builtin-sysroot/share/defined-symbols.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/libc-builtin-sysroot/share/defined-symbols.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/wamr_toolchain.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/wamr_toolchain.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/wamr_toolchain.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/wamr_toolchain.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/wasi_toolchain.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/wasi_toolchain.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/app/wasi_toolchain.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/app/wasi_toolchain.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/build_sdk.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/build_sdk.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/build_sdk.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/build_sdk.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/menuconfig.sh b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/menuconfig.sh similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/menuconfig.sh rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/menuconfig.sh diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/runtime/CMakeLists.txt b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/runtime/CMakeLists.txt similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/runtime/CMakeLists.txt rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/runtime/CMakeLists.txt diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/wamr_config_default.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/wamr_config_default.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/wamr_config_default.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/wamr_config_default.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/wamr_config_macos_release.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/wamr_config_macos_release.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/wamr_config_macos_release.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/wamr_config_macos_release.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/wamr_config_ubuntu_release.cmake b/lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/wamr_config_ubuntu_release.cmake similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/wamr-sdk/wamr_config_ubuntu_release.cmake rename to lib/wasm-micro-runtime-WAMR-1.3.0/wamr-sdk/wamr_config_ubuntu_release.cmake diff --git a/lib/wasm-micro-runtime-WAMR-1.2.2/zephyr/module.yml b/lib/wasm-micro-runtime-WAMR-1.3.0/zephyr/module.yml similarity index 100% rename from lib/wasm-micro-runtime-WAMR-1.2.2/zephyr/module.yml rename to lib/wasm-micro-runtime-WAMR-1.3.0/zephyr/module.yml diff --git a/src/wamrc/CMakeLists.txt b/src/wamrc/CMakeLists.txt index f8de6449fc8..7b6e7d6ff6d 100644 --- a/src/wamrc/CMakeLists.txt +++ b/src/wamrc/CMakeLists.txt @@ -43,6 +43,35 @@ if (NOT DEFINED WAMR_BUILD_TARGET) endif () endif () +string(TOUPPER ${WAMR_BUILD_TARGET} WAMR_BUILD_TARGET) + +# Add definitions for the build target +if (WAMR_BUILD_TARGET STREQUAL "X86_64") + add_definitions(-DBUILD_TARGET_X86_64) +elseif (WAMR_BUILD_TARGET STREQUAL "AMD_64") + add_definitions(-DBUILD_TARGET_AMD_64) +elseif (WAMR_BUILD_TARGET STREQUAL "X86_32") + add_definitions(-DBUILD_TARGET_X86_32) +elseif (WAMR_BUILD_TARGET MATCHES "AARCH64.*") + add_definitions(-DBUILD_TARGET_AARCH64) + add_definitions(-DBUILD_TARGET="${WAMR_BUILD_TARGET}") +elseif (WAMR_BUILD_TARGET MATCHES "ARM.*") + add_definitions(-DBUILD_TARGET_ARM) + add_definitions(-DBUILD_TARGET="${WAMR_BUILD_TARGET}") +elseif (WAMR_BUILD_TARGET STREQUAL "RISCV64" OR WAMR_BUILD_TARGET STREQUAL "RISCV64_LP64D") + add_definitions(-DBUILD_TARGET_RISCV64_LP64D) +elseif (WAMR_BUILD_TARGET STREQUAL "RISCV64_LP64") + add_definitions(-DBUILD_TARGET_RISCV64_LP64) +elseif (WAMR_BUILD_TARGET STREQUAL "RISCV32" OR WAMR_BUILD_TARGET STREQUAL "RISCV32_ILP32D") + add_definitions(-DBUILD_TARGET_RISCV32_ILP32D) +elseif (WAMR_BUILD_TARGET STREQUAL "RISCV32_ILP32") + add_definitions(-DBUILD_TARGET_RISCV32_ILP32) +else () + message (FATAL_ERROR "-- Build target isn't set") +endif () + +message ("-- Build as target ${WAMR_BUILD_TARGET}") + if (NOT CMAKE_BUILD_TYPE) set (CMAKE_BUILD_TYPE Release) endif () @@ -60,6 +89,9 @@ add_definitions(-DWASM_ENABLE_CUSTOM_NAME_SECTION=1) add_definitions(-DWASM_ENABLE_DUMP_CALL_STACK=1) add_definitions(-DWASM_ENABLE_PERF_PROFILING=1) add_definitions(-DWASM_ENABLE_LOAD_CUSTOM_SECTION=1) +add_definitions(-DWASM_ENABLE_LIB_WASI_THREADS=1) +add_definitions(-DWASM_ENABLE_MODULE_INST_CONTEXT=1) + if (WAMR_BUILD_LLVM_LEGACY_PM EQUAL 1) add_definitions(-DWASM_ENABLE_LLVM_LEGACY_PM=1) endif() @@ -148,10 +180,17 @@ if (LLVM_FOUND) enable_language (ASM) + if (NOT MINGW AND NOT MSVC) + set(WAMR_BUILD_LIBC_WASI 1) + else() + set(WAMR_BUILD_LIBC_UVWASI 1) + endif() + include (${SHARED_DIR}/platform/${WAMR_BUILD_PLATFORM}/shared_platform.cmake) include (${SHARED_DIR}/mem-alloc/mem_alloc.cmake) include (${SHARED_DIR}/utils/shared_utils.cmake) include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) + include (${WAMR_ROOT_DIR}/core/shared/platform/common/libc-util/platform_common_libc_util.cmake) include (${IWASM_DIR}/libraries/thread-mgr/thread_mgr.cmake) include (${IWASM_DIR}/libraries/libc-builtin/libc_builtin.cmake) if (NOT MINGW) @@ -162,6 +201,7 @@ if (LLVM_FOUND) endif() endif() include (${IWASM_DIR}/libraries/lib-pthread/lib_pthread.cmake) + include (${IWASM_DIR}/libraries/lib-wasi-threads/lib_wasi_threads.cmake) include (${IWASM_DIR}/common/iwasm_common.cmake) include (${IWASM_DIR}/interpreter/iwasm_interp.cmake) include (${IWASM_DIR}/aot/iwasm_aot.cmake) @@ -176,11 +216,13 @@ if (LLVM_FOUND) ${LIBC_BUILTIN_SOURCE} ${LIBC_WASI_SOURCE} ${LIB_PTHREAD_SOURCE} + ${LIB_WASI_THREADS_SOURCE} ${IWASM_COMMON_SOURCE} ${IWASM_INTERP_SOURCE} ${IWASM_AOT_SOURCE}) add_library (aotclib-static STATIC ${IWASM_COMPL_SOURCE}) add_executable (flb-wamrc-bin ${WAMR_ROOT_DIR}/wamr-compiler/main.c) + if (NOT MSVC) target_link_libraries (flb-wamrc-bin aotclib-static vmlib-wamrc-static LLVMDemangle ${LLVM_AVAILABLE_LIBS} ${lib_ubsan} -lm -lpthread ${lib_lldb} ${UV_A_LIBS}) diff --git a/src/wasm/CMakeLists.txt b/src/wasm/CMakeLists.txt index b345c4b4510..8b691ac1723 100644 --- a/src/wasm/CMakeLists.txt +++ b/src/wasm/CMakeLists.txt @@ -41,6 +41,35 @@ if (NOT DEFINED WAMR_BUILD_TARGET) endif () endif () +string(TOUPPER ${WAMR_BUILD_TARGET} WAMR_BUILD_TARGET) + +# Add definitions for the build target +if (WAMR_BUILD_TARGET STREQUAL "X86_64") + add_definitions(-DBUILD_TARGET_X86_64) +elseif (WAMR_BUILD_TARGET STREQUAL "AMD_64") + add_definitions(-DBUILD_TARGET_AMD_64) +elseif (WAMR_BUILD_TARGET STREQUAL "X86_32") + add_definitions(-DBUILD_TARGET_X86_32) +elseif (WAMR_BUILD_TARGET MATCHES "AARCH64.*") + add_definitions(-DBUILD_TARGET_AARCH64) + add_definitions(-DBUILD_TARGET="${WAMR_BUILD_TARGET}") +elseif (WAMR_BUILD_TARGET MATCHES "ARM.*") + add_definitions(-DBUILD_TARGET_ARM) + add_definitions(-DBUILD_TARGET="${WAMR_BUILD_TARGET}") +elseif (WAMR_BUILD_TARGET STREQUAL "RISCV64" OR WAMR_BUILD_TARGET STREQUAL "RISCV64_LP64D") + add_definitions(-DBUILD_TARGET_RISCV64_LP64D) +elseif (WAMR_BUILD_TARGET STREQUAL "RISCV64_LP64") + add_definitions(-DBUILD_TARGET_RISCV64_LP64) +elseif (WAMR_BUILD_TARGET STREQUAL "RISCV32" OR WAMR_BUILD_TARGET STREQUAL "RISCV32_ILP32D") + add_definitions(-DBUILD_TARGET_RISCV32_ILP32D) +elseif (WAMR_BUILD_TARGET STREQUAL "RISCV32_ILP32") + add_definitions(-DBUILD_TARGET_RISCV32_ILP32) +else () + message (FATAL_ERROR "-- Build target isn't set") +endif () + +message ("-- Build as target ${WAMR_BUILD_TARGET}") + if (NOT CMAKE_BUILD_TYPE) set (CMAKE_BUILD_TYPE Release) endif () @@ -92,6 +121,9 @@ add_library(vmlib-static STATIC ${WAMR_RUNTIME_LIB_SOURCE}) # Application related include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) +# platform common sources +include (${WAMR_ROOT_DIR}/core/shared/platform/common/libc-util/platform_common_libc_util.cmake) + set(src flb_wasm.c ${UNCOMMON_SHARED_SOURCE}) # link wasm-micro-runtime's uncommon object symbols (for bh_read_file_to_buffer) From 0380d958e27241640b49afe142c5615d39729c27 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Wed, 20 Dec 2023 17:16:00 +0900 Subject: [PATCH 2/2] wasm: Remove forcibly disabling AOT load on Apple Silicon macOS WAMR v1.3.0 can handle AOT on Apple Silicon macOS. Signed-off-by: Hiroshi Hatake --- src/wasm/CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/wasm/CMakeLists.txt b/src/wasm/CMakeLists.txt index 8b691ac1723..a258dc063f5 100644 --- a/src/wasm/CMakeLists.txt +++ b/src/wasm/CMakeLists.txt @@ -20,11 +20,6 @@ endif () if (NOT DEFINED WAMR_BUILD_TARGET) if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)") set (WAMR_BUILD_TARGET "AARCH64") - if (FLB_SYSTEM_MACOS) - message(STATUS "macOS arm64 platform is poor support for AOT loading. Now disabling for it.") - set (WAMR_DISABLE_AOT_LOADING 1) - FLB_DEFINITION(FLB_WAMR_DISABLE_AOT_LOADING) - endif () # For raspbian/buster: armv6l-unknown-linux-gnueabihf elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv6.*|armv7.*)") set (WAMR_BUILD_TARGET "ARM")