Skip to content

[mono] Preserve arguments across AOT exception filters - #136852

Merged
pavelsavara merged 1 commit into
dotnet:mainfrom
pavelsavara:browser-mono-aot-filter-arguments
Nov 3, 2026
Merged

pavelsavara merged 1 commit into
dotnet:mainfrom
pavelsavara:browser-mono-aot-filter-arguments

Conversation

@pavelsavara

Copy link
Copy Markdown
Member

Summary

Fix argument corruption after exception filters in Mono AOT code.

interp_run_clause_with_il_state used the first argument slot as the filter-result buffer. MINT_ENDFILTER wrote the filter result there, and argument writeback copied it into the suspended AOT frame before the catch ran. This made an integer argument become 1 and corrupted string references.

Give filter evaluation a separate result slot, following the normal interpreter filter path. Catch/finally return storage and legitimate argument/local writeback remain unchanged.

Add the eight reported scenarios to the existing System.Runtime.Tests exception suite, plus two cases ensuring argument mutations survive both accepted and rejected filters.

Testing

Mono/browser-wasm Debug runtime and libraries; Release test app; Chrome with a matching ChromeDriver. $root is the checkout path. The local runs used the cached Emscripten SDK via EMSDK_PATH and cached Chrome via CHROME_PATH_FOR_TESTS.

Runtime/libraries/packs build: passed, 0 warnings and 0 errors.

.\build.cmd -bl -os browser -subset mono+libs+packs -c Debug /p:RuntimeFlavor=Mono /p:EnableHotReloadInRuntimeConfigDevFile=false

Chrome AOT exception suite: passed, 18/18 tests. Before the fix, the same suite ran 18 tests with 7 failures: the five original failing scenarios and both argument-mutation cases.

.\dotnet.cmd build -bl /p:TargetOS=browser /p:TargetArchitecture=wasm /p:RuntimeFlavor=Mono /p:Configuration=Release /p:RuntimeConfiguration=Debug /p:RuntimeConfig=Debug /p:LibrariesConfiguration=Debug /p:TasksConfiguration=Debug "/p:WasmTestRunnerDir=$root\artifacts\bin\WasmTestRunner\Debug\net12.0-browser\" /t:Test /p:RunAOTCompilation=true /p:Scenario=WasmTestOnChrome /p:InstallChromeForTests=false /p:EnableHotReloadInRuntimeConfigDevFile=false /p:XUnitClassName=System.Tests.ExceptionTests .\src\libraries\System.Runtime\tests\System.Runtime.Tests\System.Runtime.Tests.csproj

Chrome interpreter exception suite: passed, 20/20 tests. Cleaned this test project's browser-wasm bin/obj directories before switching AOT off to avoid reusing IL-stripped staging. Two existing target-site tests have Mono-AOT exclusions and therefore run only in the interpreter configuration.

.\dotnet.cmd build -bl /p:TargetOS=browser /p:TargetArchitecture=wasm /p:RuntimeFlavor=Mono /p:Configuration=Release /p:RuntimeConfiguration=Debug /p:RuntimeConfig=Debug /p:LibrariesConfiguration=Debug /p:TasksConfiguration=Debug "/p:WasmTestRunnerDir=$root\artifacts\bin\WasmTestRunner\Debug\net12.0-browser\" /t:Test /p:RunAOTCompilation=false /p:Scenario=WasmTestOnChrome /p:InstallChromeForTests=false /p:EnableHotReloadInRuntimeConfigDevFile=false /p:XUnitClassName=System.Tests.ExceptionTests .\src\libraries\System.Runtime\tests\System.Runtime.Tests\System.Runtime.Tests.csproj

The original eight-case probe also passes all cases under both AOT and the interpreter. Other target platforms were not tested locally.

Resolves #136780

Note

This change and PR description were prepared with GitHub Copilot.

Keep the filter result in a separate interpreter stack value instead of
overwriting the first argument before copying arguments back to AOT state.
Leave catch and finally return storage unchanged.

Adopt the eight reported scenarios into the existing exception suite and
cover argument mutations in both accepted and rejected filters.

Fixes dotnet#136780

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @akoeplinger, @matouskozak, @simonrozsival
See info in area-owners.md if you want to be subscribed.

@pavelsavara pavelsavara added this to the 12.0.0 milestone Nov 2, 2026
@pavelsavara pavelsavara added area-Codegen-AOT-mono arch-wasm WebAssembly architecture os-browser Browser variant of arch-wasm and removed area-Infrastructure-mono labels Nov 2, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

@pavelsavara

Copy link
Copy Markdown
Member Author

/azp run runtime-extra-platforms

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@pavelsavara

Copy link
Copy Markdown
Member Author

/ba-g unrelated CI failures

@pavelsavara
pavelsavara merged commit 76e0443 into dotnet:main Nov 3, 2026
177 of 183 checks passed
@pavelsavara
pavelsavara deleted the browser-mono-aot-filter-arguments branch November 3, 2026 16:38
@pavelsavara

Copy link
Copy Markdown
Member Author

/backport to release/11.0

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

@pavelsavara backporting to release/11.0 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git cherry-pick 76e0443e3d4e50f09b831b95c8d32046176c1990

Auto-merging src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExceptionTests.cs
CONFLICT (content): Merge conflict in src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExceptionTests.cs
error: could not apply 76e0443e3d4... [mono] Preserve arguments across AOT exception filters (#136852)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"


$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: [mono] Preserve arguments across AOT exception filters
Using index info to reconstruct a base tree...
M	src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExceptionTests.cs
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExceptionTests.cs
CONFLICT (content): Merge conflict in src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExceptionTests.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 [mono] Preserve arguments across AOT exception filters
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — dbe1078c Deployed Nov 2, 2026 by pavelsavara via conclusion #11579
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-Codegen-AOT-mono os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[wasm][mono][AOT] After an exception filter catches, the method's arguments read wrong (string empty, int 1)

3 participants