Skip to content

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

Draft
radekdoulik wants to merge 3 commits intodotnet:mainfrom
radekdoulik:clr-wasm-reset-portable-entrypoint
Draft

[wasm][coreclr] Improve method portable entrypoints lifecycle#124868
radekdoulik wants to merge 3 commits intodotnet:mainfrom
radekdoulik:clr-wasm-reset-portable-entrypoint

Conversation

@radekdoulik
Copy link
Member

@radekdoulik radekdoulik commented Feb 25, 2026

  • 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 fixes dotnet#123712 and possibly
dotnet#121955
@radekdoulik radekdoulik added this to the Future milestone Feb 25, 2026
Copilot AI review requested due to automatic review settings February 25, 2026 19:05
@radekdoulik radekdoulik added arch-wasm WebAssembly architecture area-VM-coreclr labels Feb 25, 2026
@dotnet-policy-service
Copy link
Contributor

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

@radekdoulik
Copy link
Member Author

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.

Copy link
Contributor

Copilot AI left a comment

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
File Description
src/coreclr/vm/method.hpp Adds declaration for new ResetPortableEntryPoint() method
src/coreclr/vm/method.cpp Implements ResetPortableEntryPoint() and calls it in Reset(), ResetCodeEntryPoint(), and ResetCodeEntryPointForEnC() wherever interpreter code is cleared
src/coreclr/vm/codeversion.cpp Calls ResetPortableEntryPoint() in PublishNativeCodeVersion() when clearing interpreter code
src/coreclr/vm/finalizerthread.cpp Re-enables finalizer execution for browser/WASM (was disabled as workaround for #123712)
src/coreclr/interpreter/compiler.cpp Re-enables access checks in interpreter compiler (was disabled as workaround for #121955)

@radekdoulik
Copy link
Member Author

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.

Copilot AI review requested due to automatic review settings February 25, 2026 21:05
Copy link
Contributor

Copilot AI left a comment

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-VM-coreclr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants