Repository navigation
[release/10.0] Fix sporadic AccessViolation in compressed single-file apps on Apple Silicon - #132710
Conversation
…Silicon (dotnet#127355) On macOS Apple Silicon (observed on macOS 15), compressed self-contained single-file apps intermittently hit `AccessViolationException` crashes. With the repro provided in the issue, the failure rate was roughly 75% in a local run. `FlatImageLayout::LoadImageByCopyingParts` allocates the image region with `MEM_RESERVE_EXECUTABLE` (which maps to `MAP_JIT` on macOS) as `PAGE_READWRITE`, copies in all section bytes, then promotes executable sections to `PAGE_EXECUTE_READWRITE` via a second `mprotect`. On Apple Silicon, this `RW → RWX` transition on MAP_JIT memory has been observed to intermittently succeed at the API level but leave pages non-executable at the kernel level, producing the sporadic AVs. On Apple Silicon (`HOST_OSX && HOST_ARM64`), avoid the unreliable transition: reserve the whole image region as `PAGE_NOACCESS` up front, then commit each section directly with its final runtime protection (`PAGE_EXECUTE_READWRITE` for exec, `PAGE_READWRITE` otherwise), copying executable content under `PAL_JitWriteProtect`. The `PROT_NONE → RWX` direction via a fresh commit is reliable; the problematic `RW → RWX` transition no longer occurs. Read-only sections are still downgraded from `PAGE_READWRITE` to `PAGE_READONLY` after the copy, which is a W-removing transition and is not implicated in the original bug. The non-Apple-Silicon code path is unchanged. New test: `AppHost.Bundle.Tests.AppLaunch.SelfContained_Compressed_SpawnsChildren` (OSX-only). Adds a `launch_self` option to the `HelloWorld` test asset that spawns 5 copies of itself in parallel, and asserts the parent runs to completion. Local validation on Apple Silicon: - Without fix: parent crash with `AccessViolationException` in ~74% of trials at N=5 children (rises to ~98% at N≥12). - With fix: 0 failures across 50+ trials at N=5. --------- Co-authored-by: Copilot <[email protected]> (cherry picked from commit 0f01d22)
|
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. |
There was a problem hiding this comment.
Pull request overview
Backports the Apple Silicon fix for compressed single-file app crashes and adds regression coverage.
Changes:
- Adjusts Apple Silicon image allocation and protection handling.
- Adds concurrent child-process launch coverage.
- Adds compressed single-file regression testing.
Show a summary per file
| File | Summary | Review |
|---|---|---|
src/installer/tests/Assets/Projects/HelloWorld/Program.cs |
Adds concurrent child-process launching. | Check child exit codes and fail on non-zero results. |
src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs |
Adds compressed single-file launch coverage. | No additional comments. |
src/coreclr/vm/peimagelayout.cpp |
Updates Apple Silicon image allocation and protections. | No additional comments. |
Review details
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Suppressed comments (2)
src/coreclr/vm/peimagelayout.cpp:843
- The old Apple Silicon branch in this function selected
PAGE_EXECUTE_READWRITEfor executable sections (rather thanPAGE_EXECUTE_READ), so this comment describes the wrong protection transition. Please name the actualPAGE_READWRITE→PAGE_EXECUTE_READWRITEtransition; that distinction is central to the rationale for this workaround.
// On Apple Silicon, allocating the image region as plain PAGE_READWRITE and then promoting
// executable sections to PAGE_EXECUTE_READ via mprotect has been observed to
// intermittently leave pages non-executable at the kernel level. This manifests as sporadic
src/installer/tests/AppHost.Bundle.Tests/AppLaunch.cs:118
- This condition restricts the test to macOS, but not to Apple Silicon. The product change is compiled only under
HOST_OSX && HOST_ARM64(lines 840-957), so an Intel macOS run can pass without exercising the fix. Add an ARM64 condition so this regression test cannot provide false coverage on an x64 runner.
[PlatformSpecific(TestPlatforms.OSX)]
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
|
Not sure why that one leg is marked as a failure. The log (https://helixr1107v0xdeko0k025g8.blob.core.windows.net/dotnet-runtime-refs-pull-132710-merge-2729b6f1283e47118d/AppHost.Bundle.Tests.Attempt.3/1/console.3d6650c7.log?helixlogtype=result) indicates success: |
|
Appears to be an infra hiccup that ended up failing the entire leg even though it passed. |
|
/ba-g flaky infra. |
Both found during the 2026-09 backlog sweep, both verified against the source of truth rather than against the text that made the claim. 1. release.yml said the macOS single-file AccessViolation fix was "NOT backported to release/10.0", so a reader concluded only a move to .NET 11 could re-enable compression. It HAS been backported: dotnet/runtime#132710 merged into release/10.0 on 2026-08-26, milestone 10.0.13 (verified against dotnet/runtime). It has not shipped - dotnet/core publishes up to 10.0.11 - so the workaround stays, but the gate is now a dated servicing release rather than a major-version migration. The re-enable condition now names 10.0.13, records that there is no pin to unwind, and points at #444. 2. docs/plans/21-run-fault-triage.md told its reader to send the design out as a draft PR "per #106". #106 predates Charter and recorded the older habit. A design of record is reviewed in Charter; a PR is a code-review vehicle, and opening one for prose spends a 3-OS matrix putting a green tick on something it certifies nothing about. Left alone, the next agent reads that header and opens the PR. No behaviour change: one YAML comment and one markdown blockquote. release.yml still parses. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_018ygCiteWCFHAavpb4vMtXF
Backport of #127355 to release/10.0
/cc @dotnet/appmodel @AaronRobinsonMSFT
Customer Impact
When running compressed single-file applications on macOS, users would hit intermittent crashes with an access violation.
Issues: #112167, #123324, #132627
On macOS, when loading compressed images from single-file, the runtime allocates the image region with
MAP_JITasPAGE_READWRITE, copies in all section bytes, then promotes executable sections toPAGE_EXECUTE_READWRITEvia a secondmprotect. On Apple Silicon, thisRW → RWXtransition onMAP_JITmemory has been observed to intermittently succeed at the API level but leave pages non-executable at the kernel level, producing the sporadic AVs.This change (only on maOS arm64) reserve the whole image region as
PAGE_NOACCESSup front, then commit each section directly with its final runtime protection.Regression
Testing
Automated test added.
Risk
Low. Fix has been in main for 3 months. The non-Apple Silicon path is unchanged by the fix.