[wasm][coreclr] Improve method portable entrypoints lifecycle#124868
[wasm][coreclr] Improve method portable entrypoints lifecycle#124868radekdoulik wants to merge 3 commits intodotnet:mainfrom
Conversation
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
|
Tagging subscribers to this area: @agocke |
|
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. |
There was a problem hiding this comment.
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) |
|
OK, no free lunch :-) |
Co-authored-by: Copilot <[email protected]> Co-authored-by: Aaron R Robinson <[email protected]>
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