Repository navigation
Fix up FCalls on native AOT/WASM - #135764
Merged
MichalStrehovsky merged 5 commits intoOct 15, 2026
Merged
Conversation
Co-authored-by: Copilot <[email protected]> Copilot-Session: c78266f3-08e3-4918-b2e5-9fe0ddf2ca17
Contributor
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
jkotas
reviewed
Oct 14, 2026
jkotas
reviewed
Oct 14, 2026
This was referenced Oct 14, 2026
Closed
Use the RAW FCall naming, including CoreCLR-style non-Wasm fallbacks, and compile the existing naked Wasm barriers for NativeAOT instead of allowing C++ barriers to access an unpublished native stack. Co-authored-by: Copilot <[email protected]> Copilot-Session: c78266f3-08e3-4918-b2e5-9fe0ddf2ca17
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Native-ABI exports receive an incompatible managed stack-pointer argument through the new FCall wrappers.
2 open findings
What changed in this PR
Updates NativeAOT/Wasm call boundaries to prevent native stack allocations from overlapping live managed frames, supporting WASI startup.
Changes:
- Adds FCall stack-pointer publication and restoration wrappers.
- Updates P/Invoke boundaries and allocator forwarding.
- Integrates Wasm write barriers while preserving their native ABI.
Validation was not rerun during this review.
| File | Description |
|---|---|
| src/coreclr/runtime/wasm/writebarriers.cpp | Adds NativeAOT-compatible includes and declarations. |
| src/coreclr/nativeaot/Runtime/thread.cpp | Updates portable P/Invoke names and Wasm stack boundaries. |
| src/coreclr/nativeaot/Runtime/portable.cpp | Adds pointer-array allocation and direct implementation forwarding. |
| src/coreclr/nativeaot/Runtime/CommonMacros.h | Introduces Wasm FCall wrappers and raw native declarations. |
| src/coreclr/nativeaot/Runtime/CMakeLists.txt | Includes Wasm write barriers in NativeAOT builds. |
🧠 Review effort: Balanced
jkotas
reviewed
Oct 14, 2026
Remove the obsolete ARM64 exclusion from portable write barriers. Co-authored-by: Copilot <[email protected]> Copilot-Session: c78266f3-08e3-4918-b2e5-9fe0ddf2ca17
Co-authored-by: Copilot <[email protected]> Copilot-Session: c78266f3-08e3-4918-b2e5-9fe0ddf2ca17
Co-authored-by: Copilot <[email protected]> Copilot-Session: c78266f3-08e3-4918-b2e5-9fe0ddf2ca17
jkotas
approved these changes
Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Part of a series of pull requests that enable compiling, linking, and running a
Console.WriteLinehello world on WASI/native AOT.Summary
Match the Wasm managed/native ABI and publish the managed stack pointer before clang-generated native code can allocate a linear-memory stack frame.
Port CoreCLR's naked FCall save/publish/call/restore wrappers, including their comments, with NativeAOT declarations/linkage and no portable-entrypoint context argument. Cover the floating-point/int64 variants and preserve the native ABI of write barriers.
Add portable pointer-array allocation and forward allocator-to-allocator calls directly to
_IMPL, avoiding wrapper reentry above a live native frame. Fix the portable P/Invoke helper names and mirror CoreCLR's special begin/return boundaries: begin leaves SP published for the native target; debug return checks synchronization. Reverse-P/Invoke helpers inherit the FCall wrappers.This fixes startup corruption caused by native allocation overlapping live managed frames. It does not implement Wasm GC stack scanning.
Validation
.\build.cmd clr.nativeaotruntime -rc Checked -os wasi -arch wasm- passed.verify-stack-boundaries.ps1and its-RuntimeConfiguration Releasevariant - passed, covering ordinary/suppressed P/Invokes, nested unmanaged-callable callbacks, and dynamiclocalloc.These results are from the combined local bringup tree, including prerequisite NativeAOT/Wasm enablement, not a fresh build of this isolated main-based branch. The probe scripts are local fixtures, not tests added by this PR. No GC-pressure/root-survival claim is made.
Note
This PR description was generated by GitHub Copilot.