Convert exception-related MethodDescCallSite calls to UnmanagedCallersOnly#124834
Open
AaronRobinsonMSFT wants to merge 1 commit intodotnet:mainfrom
Open
Convert exception-related MethodDescCallSite calls to UnmanagedCallersOnly#124834AaronRobinsonMSFT wants to merge 1 commit intodotnet:mainfrom
AaronRobinsonMSFT wants to merge 1 commit intodotnet:mainfrom
Conversation
…sOnly Replace MethodDescCallSite/CallDescrWorker calls with more efficient UnmanagedCallersOnly reverse P/Invoke calls in exception handling code paths (priority 2 from dotnet#123864): - GetExceptionMessage: Object.ToString via UCO - ExceptionPreserveStackTrace: InternalPreserveStackTrace via UCO - WrapNonCompliantException: RuntimeWrappedException ctor via UCO - CreateTypeInitializationExceptionObject: TypeInitializationException via UCO - GetResourceStringFromManaged: Environment.GetResourceStringLocal via UCO - GetEventArgsForNotification: FirstChanceExceptionEventArgs ctor via UCO Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @agocke |
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request converts six exception-related MethodDescCallSite call sites in excep.cpp to use the more efficient UnmanagedCallersOnly reverse P/Invoke pattern, following the established approach from priority 1 and 2 tasks in issue #123864.
Changes:
- Replaces
MethodDescCallSite/CallDescrWorkerwithUnmanagedCallersOnlyCaller::InvokeThrowingfor six exception-handling methods - Adds six new UnmanagedCallersOnly wrapper methods in managed code (Object.CoreCLR.cs, Exception.CoreCLR.cs, Environment.CoreCLR.cs)
- Updates metasig.h with six new method signatures and corelib.h with updated DEFINE_METHOD entries, removing obsolete constructor definitions
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/vm/metasig.h | Adds 6 new metasig definitions for UnmanagedCallersOnly wrappers (PtrObj_PtrStr, PtrObj_PtrObj, PtrStr_PtrStr, PtrException_PtrException, PtrChar_PtrException_PtrObj, PtrException_PtrObj, all with PtrException_RetVoid suffix) |
| src/coreclr/vm/corelib.h | Updates DEFINE_METHOD entries for the 6 converted methods and removes 3 obsolete constructor entries (TYPE_INIT_EXCEPTION.STR_EX_CTOR, RUNTIME_WRAPPED_EXCEPTION.OBJ_CTOR, FIRSTCHANCE_EVENTARGS.CTOR) |
| src/coreclr/vm/excep.cpp | Converts 6 call sites to use UnmanagedCallersOnlyCaller: GetExceptionMessage, ExceptionPreserveStackTrace, WrapNonCompliantException, CreateTypeInitializationExceptionObject, GetResourceStringFromManaged, GetEventArgsForNotification |
| src/coreclr/System.Private.CoreLib/src/System/Object.CoreCLR.cs | Adds GetToString UnmanagedCallersOnly wrapper with Exception* out-parameter |
| src/coreclr/System.Private.CoreLib/src/System/Exception.CoreCLR.cs | Adds 4 UnmanagedCallersOnly wrappers: InternalPreserveStackTrace, CreateRuntimeWrappedException, CreateTypeInitializationException, CreateFirstChanceExceptionEventArgs |
| src/coreclr/System.Private.CoreLib/src/System/Environment.CoreCLR.cs | Converts GetResourceStringLocal to UnmanagedCallersOnly pattern with string* in/out parameters |
jkotas
reviewed
Feb 25, 2026
jkotas
reviewed
Feb 25, 2026
jkotas
reviewed
Feb 25, 2026
jkotas
reviewed
Feb 25, 2026
jkotas
reviewed
Feb 25, 2026
jkotas
reviewed
Feb 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace
MethodDescCallSite/CallDescrWorkercalls with more efficientUnmanagedCallersOnlyreverse P/Invoke calls in exception handling code paths (priority 2 from #123864).Changes
Convert the following call sites in
excep.cppto useUnmanagedCallersOnlyCaller:GetExceptionMessage:Object.ToStringvia UCO (METHOD__OBJECT__GET_TO_STRING)ExceptionPreserveStackTrace:InternalPreserveStackTracevia UCOWrapNonCompliantException:RuntimeWrappedExceptionconstruction via UCOCreateTypeInitializationExceptionObject:TypeInitializationExceptionconstruction via UCOGetResourceStringFromManaged:Environment.GetResourceStringLocalvia UCOGetEventArgsForNotification:FirstChanceExceptionEventArgsconstruction via UCOPattern
Each conversion follows the established pattern:
[UnmanagedCallersOnly]static wrapper in managed code withException*out-parametermetasig.handDEFINE_METHODincorelib.hMethodDescCallSite+ARG_SLOTwithUnmanagedCallersOnlyCaller::InvokeThrowingDEFINE_METHODentries for old constructorsAll GC references passed to
InvokeThrowingare in GCPROTECT'd locations.