Skip to content

WASM: add webassembly-micro-runtime port#120

Open
R4ken wants to merge 1 commit into
masterfrom
jrak/wamr
Open

WASM: add webassembly-micro-runtime port#120
R4ken wants to merge 1 commit into
masterfrom
jrak/wamr

Conversation

@R4ken

@R4ken R4ken commented Sep 30, 2025

Copy link
Copy Markdown

Add add webassembly-micro-runtime port

JIRA: RTOS-1087

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: ia32-generic-qemu armv7a9-zynq700-qemu riscv64-generic-qemu aarch64a53-zynqmp-qemu

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @R4ken, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new port for the WebAssembly Micro Runtime (WAMR) to the Phoenix-RTOS ecosystem. It establishes a foundational layer that allows WebAssembly modules to run on Phoenix-RTOS, complete with custom platform adaptations for file system access, threading primitives, and mathematical functions. The integration supports multiple architectures and includes configurations for resource-constrained environments, paving the way for deploying WebAssembly applications on the RTOS.

Highlights

  • WebAssembly Micro Runtime (WAMR) Port: Introduces WAMR version 2.4.2, enabling WebAssembly execution on Phoenix-RTOS, expanding the system's application capabilities.
  • Phoenix-RTOS Platform Integration: Implements a custom platform layer for WAMR, adapting its build system and core functionalities to align with Phoenix-RTOS specifics, ensuring seamless operation within the RTOS environment.
  • Cross-Architecture Support: Configures WAMR for various target architectures including ARMv7m, ARM, AARCH64, and RISCV64, broadening the range of devices that can run WebAssembly modules.
  • Custom System Call and Library Adaptations: Patches WAMR's POSIX-like interfaces for file system operations, threading primitives (semaphores, rwlocks), clock resolution, and mathematical functions to ensure compatibility with Phoenix-RTOS's unique environment.
  • Native Library Integration: Provides mechanisms and example code for linking native C functions directly into WASM modules, allowing WebAssembly applications to interact with host-specific functionalities.
  • Build System Enhancements: Modifies the main build.sh script to include WAMR and sets up a dedicated build script for WAMR with specific flags for Phoenix-RTOS, including configurations optimized for low-memory environments.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Comment thread wamr/native_libs_example/example/example.c
Comment thread wamr/native_libs_example/example/example.c
Comment thread wamr/native_libs_example/example/example.c
Comment thread wamr/native_libs_example/example/example.c
Comment thread wamr/patches/2.4.2/main.patch Outdated
Comment thread wamr/patches/2.4.2/posix_file.patch Outdated
Comment thread wamr/patches/2.4.2/posix_file.patch Outdated
Comment thread wamr/patches/2.4.2/posix_file.patch Outdated
Comment thread wamr/patches/2.4.2/posix_file.patch Outdated
Comment thread wamr/patches/2.4.2/posix_file.patch Outdated
Comment thread wamr/patches/2.4.2/posix_file.patch Outdated
Comment thread wamr/patches/2.4.2/posix_file.patch Outdated
Comment thread wamr/patches/2.4.2/posix_file.patch Outdated
Comment thread wamr/patches/2.4.2/posix_file.patch Outdated
@R4ken
R4ken marked this pull request as draft September 30, 2025 08:16

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a port for the WebAssembly Micro Runtime (WAMR) to Phoenix-RTOS, which is a significant new feature. The changes include a build script, patches to adapt WAMR to the Phoenix-RTOS environment, and example files. The patches correctly disable features not supported on Phoenix-RTOS, such as AOT/JIT and dynamic linking, and provide workarounds for missing system calls and library functions. However, the review has identified several issues, including a critical compilation error, potential memory leaks, incorrect logic in file operations, and leftover debug code. These issues should be addressed to ensure the stability and correctness of the port.

Comment thread wamr/patches/2.4.2/posix_thread.patch Outdated
Comment thread wamr/native_libs_example/example/example.c
Comment thread wamr/patches/math.patch Outdated
Comment thread wamr/patches/posix_file.patch
Comment thread wamr/patches/2.4.2/posix_file.patch Outdated
Comment thread wamr/build.sh Outdated
Comment thread wamr/patches/2.4.2/main.patch Outdated
Comment thread wamr/patches/2.4.2/posix_file.patch Outdated
Comment thread wamr/patches/2.4.2/posix_thread.patch Outdated
@github-actions

github-actions Bot commented Sep 30, 2025

Copy link
Copy Markdown

Unit Test Results

10 585 tests  ±0   9 915 ✅ ±0   55m 39s ⏱️ +37s
   649 suites ±0     670 💤 ±0 
     1 files   ±0       0 ❌ ±0 

Results for commit 4f5ccbf. ± Comparison against base commit 4bd9ec8.

♻️ This comment has been updated with latest results.

Comment thread wamr/build.sh Outdated
fi

mkdir -p "${PRODUCT_MINI_DIR}"
(cd "${PRODUCT_MINI_DIR}" && cmake ${WAMR_FLAGS} .. && make)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double quotes preserve indentation between flags which breaks passing them to cmake

Comment thread wamr/patches/main.patch
@R4ken
R4ken marked this pull request as ready for review September 30, 2025 14:18
@oI0ck oI0ck self-assigned this Nov 25, 2025
@oI0ck

oI0ck commented Nov 25, 2025

Copy link
Copy Markdown
Member

Ported runtime seems to run well, though I have some nitpicks.

Patching core/shared/platform/linux and then copying it as core/shared/platform/phoenix is a bit hacky.

Also, instead of patching core/platform/common/posix, I'd be better to implement those interfaces in Phoenix platform directory. That way the implementation should be easier to upstream later on, and, basing of what Zephyr did, it shouldn't be that much work either (~1k LoC in their directory).

@oI0ck

oI0ck commented Nov 26, 2025

Copy link
Copy Markdown
Member

Actually, since we are planning on adding missing POSIX features, we can probably leave this patchset as it is.
When they'll be ready, we can use common/posix without substantially changing them with patches.

oI0ck
oI0ck previously approved these changes Nov 26, 2025

@oI0ck oI0ck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request is a bit hacky, due to Phoenix not being fully POSIX compilant.
The patchset should probably be reworked before upstreaming in the future, however, it makes little sense to change it now, before we implement missing POSIX features.

Porting this runtime was a considerable undertaking, thank you for your work.

Comment thread wamr/patches/2.4.2/platform_internal.patch Outdated
@oI0ck

oI0ck commented Nov 26, 2025

Copy link
Copy Markdown
Member

Merge after phoenix-rtos/libphoenix#433

@oI0ck
oI0ck requested a review from Darchiv November 26, 2025 13:50
@oI0ck
oI0ck requested review from a team and adamgreloch March 26, 2026 15:36

@adamgreloch adamgreloch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One (debatable) nit, otherwise LGTM from port.def.sh perspective

Comment thread wamr/port.def.sh Outdated
Comment thread wamr/port.def.sh Outdated
@oI0ck
oI0ck force-pushed the jrak/wamr branch 2 times, most recently from 6db7bf0 to 51f87c3 Compare March 30, 2026 16:57
@oI0ck
oI0ck requested a review from adamgreloch March 30, 2026 17:09
Comment thread wamr/port.def.sh Outdated
@oI0ck
oI0ck force-pushed the jrak/wamr branch 2 times, most recently from 5655e18 to 09b8d51 Compare May 26, 2026 13:47
@oI0ck
oI0ck requested a review from adamgreloch May 26, 2026 14:32
adamgreloch
adamgreloch previously approved these changes May 27, 2026

@adamgreloch adamgreloch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM port def-wise. I acknowledge the limitation of supports field, I hope we resolve this once the release process is dealt with.

Comment thread wamr/port.def.sh Outdated
case "${TARGET_FAMILY}" in
arm*)
CMAKE_FLAGS="${CMAKE_FLAGS} -DWAMR_BUILD_TARGET=THUMB -DWAMR_BUILD_INVOKE_NATIVE_GENERAL=1"
if [[ "${TARGET_FAMILY}" =~ "armv7m" || "${TARGET_FAMILY}" =~ "armv7m" ]]; then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both conditions are the same

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ouch, missed that, sorry)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, this used to be v7 and v8. Corrected

Comment thread wamr/patches/wasm_memory.patch Outdated
Comment on lines +19 to +20
- os_munmap(new_mem, new_size);
+ os_munmap(new_mem, new_size);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change? (Whitespace added)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discarded this hunk from the patch

@adamgreloch

Copy link
Copy Markdown
Member

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request ports WAMR (WebAssembly Micro Runtime) to the Phoenix operating system by introducing platform-specific patches for math, file, thread, and clock APIs, alongside a port definition script. The code review highlights several critical issues, including multiple potential deadlocks due to missing mutex unlocks on error paths in the custom rwlock implementation, numerous NULL pointer dereferences from unchecked path resolutions, memory and resource leaks, uninitialized memory usage, and minor redundancies in the port script.

Comment thread wamr/patches/posix_thread.patch Outdated
Comment thread wamr/patches/posix_file.patch
Comment thread wamr/patches/posix_thread.patch Outdated
Comment thread wamr/patches/posix_file.patch
Comment thread wamr/patches/posix_file.patch Outdated
Comment thread wamr/patches/posix_file.patch
Comment thread wamr/patches/posix_thread.patch Outdated
Comment thread wamr/port.def.sh Outdated
Comment thread wamr/port.def.sh Outdated
Comment thread wamr/patches/math.patch Outdated
@oI0ck
oI0ck force-pushed the jrak/wamr branch 2 times, most recently from 8d05a5a to f92fab9 Compare May 29, 2026 16:00
@oI0ck

oI0ck commented May 29, 2026

Copy link
Copy Markdown
Member

I fixed the more blatant memory issues and leaks. I'm not sure what is up here with the resolve_fd_path() layer at a glance. Will look at it on Monday.

Add add webassembly-micro-runtime port

JIRA: RTOS-1087
Co-authored-by: Michal Lach <michal.lach@phoenix-rtos.com>
@oI0ck
oI0ck requested a review from Darchiv June 1, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants