Skip to content

[wasm][coreclr] Improve method portable entrypoints lifecycle - #124868

Merged
radekdoulik merged 8 commits into
dotnet:mainfrom
radekdoulik:clr-wasm-reset-portable-entrypoint
Mar 3, 2026
Merged

[wasm][coreclr] Improve method portable entrypoints lifecycle#124868
radekdoulik merged 8 commits into
dotnet:mainfrom
radekdoulik:clr-wasm-reset-portable-entrypoint

Conversation

@radekdoulik

@radekdoulikradekdoulik commented Feb 25, 2026

Copy link
Copy Markdown
Member
  • Reset the portable entrypoint in places where we clear the interpreter code pointer. To avoid having stale portable entrypoint set to a method without interpreter code pointer.

  • Re-enable running of finalizers

This was happening when dynamic method was finalized and added back to free list. Later when Reset() was called on that method, the portable entrypoint had still data from previous cycle, with dangling pointer to the interpreter code.

I also added call to reset portable entry point in other places, where we clear the interpreter code pointer to avoid similar issues.

Fixes#123712

Reset the portable entrypoint in places where we clear the interpreter
code pointer
Re-enable running of finalizers
Re-enable access checks in the interpreter compiler
This fixesdotnet#123712 and possibly
dotnet#121955
@radekdoulikradekdoulik added this to the Future milestone Feb 25, 2026
CopilotAI review requested due to automatic review settings February 25, 2026 19:05
@radekdoulikradekdoulik added arch-wasm WebAssembly architecture area-VM-coreclr labels Feb 25, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

@radekdoulik

Copy link
Copy Markdown
MemberAuthor

The library test I was using to reproduce locally was running fine with re-enabled access checks. Let see whether it will survive CI as well.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes memory corruption issues in the WASM CoreCLR build by properly managing the portable entrypoint lifecycle. When interpreter code pointers are cleared (e.g., during dynamic method finalization), the portable entrypoint structure can retain stale data with dangling pointers. The fix introduces a ResetPortableEntryPoint() method that clears the portable entrypoint whenever interpreter code is cleared, preventing memory corruption.

Changes:

  • Added ResetPortableEntryPoint() method to reset portable entrypoints alongside interpreter code clearing
  • Re-enabled finalizers for browser/WASM builds (previously disabled due to #123712)
  • Re-enabled access checks in the interpreter compiler (previously disabled due to #121955)

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
FileDescription
src/coreclr/vm/method.hppAdds declaration for new ResetPortableEntryPoint() method
src/coreclr/vm/method.cppImplements ResetPortableEntryPoint() and calls it in Reset(), ResetCodeEntryPoint(), and ResetCodeEntryPointForEnC() wherever interpreter code is cleared
src/coreclr/vm/codeversion.cppCalls ResetPortableEntryPoint() in PublishNativeCodeVersion() when clearing interpreter code
src/coreclr/vm/finalizerthread.cppRe-enables finalizer execution for browser/WASM (was disabled as workaround for #123712)
src/coreclr/interpreter/compiler.cppRe-enables access checks in interpreter compiler (was disabled as workaround for #121955)

Comment threadsrc/coreclr/vm/method.cpp Outdated
Comment threadsrc/coreclr/vm/method.cpp Outdated
@radekdoulik

Copy link
Copy Markdown
MemberAuthor

OK, no free lunch :-)

[20:11:21] info: System.MethodAccessException : Attempt by method 'System.Runtime.InteropServices.JavaScript.JSMarshalerArgument.ToJS(System.Threading.Tasks.Task`1<!!0>, ArgumentToJSCallback`1<!!0>)' to access method 'System.Delegate.DelegateConstruct(System.Object, IntPtr)' failed.

radekdoulikand others added 2 commits February 25, 2026 22:04
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
CopilotAI review requested due to automatic review settings February 25, 2026 21:05

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Comment threadsrc/coreclr/vm/method.cpp Outdated
CopilotAI review requested due to automatic review settings March 2, 2026 11:32

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Comment threadsrc/coreclr/vm/method.cpp Outdated
Comment threadsrc/coreclr/vm/method.cpp Outdated
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
CopilotAI review requested due to automatic review settings March 3, 2026 08:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment threadsrc/coreclr/vm/finalizerthread.cpp
Comment threadsrc/coreclr/vm/codeversion.cpp
@radekdoulik
radekdoulik merged commit a964328 into dotnet:mainMar 3, 2026
107 of 109 checks passed
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Apr 3, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasmWebAssembly architecturearea-VM-coreclr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[browser][coreCLR] GC/Finalizer is corrupting memory

4 participants

@radekdoulik@jkotas@AaronRobinsonMSFT