Skip to content

Conversation

@AaronRobinsonMSFT
Copy link
Member

Contributes to #123864

Convert 7 VM-to-managed calls in appdomain.cpp from MethodDescCallSite
to the more efficient UnmanagedCallersOnlyCaller pattern:

- OnAssemblyLoad
- OnTypeResolve
- OnResourceResolve
- OnAssemblyResolve
- Resolve
- ResolveSatelliteAssembly
- ResolveUsingResolvingEvent

Changes:
- Add UCO wrapper methods in AssemblyLoadContext.cs with object* parameters
- Add metasig signatures for the new UCO methods
- Update corelib.h method definitions to use new signatures
- Update appdomain.cpp to use UnmanagedCallersOnlyCaller
- Remove obsolete methods from AssemblyLoadContext.CoreCLR.cs
- Update TypeNameResolver.CoreCLR.cs to use OnTypeResolveCore

Contributes to dotnet#123864
@dotnet-policy-service
Copy link
Contributor

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

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 converts assembly loading callbacks in appdomain.cpp from the older MethodDescCallSite / CallDescrWorker infrastructure to the more efficient UnmanagedCallersOnly pattern, contributing to the broader effort tracked in issue #123864. This change improves VM-to-managed call performance by using the reverse P/Invoke infrastructure.

Changes:

  • Added seven [UnmanagedCallersOnly] wrapper methods in AssemblyLoadContext.cs for assembly loading callbacks
  • Updated native code to use UnmanagedCallersOnlyCaller instead of MethodDescCallSite for invoking managed methods
  • Updated method signatures in corelib.h and added new metadata signatures in metasig.h to support the new calling convention

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/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs Added seven UnmanagedCallersOnly wrapper methods (OnAssemblyLoad, OnTypeResolve, OnResourceResolve, OnAssemblyResolve, Resolve, ResolveSatelliteAssembly, ResolveUsingEvent) with exception handling via out-parameters
src/coreclr/vm/metasig.h Added three new UCO method signatures for assembly loading callbacks with pointer parameters and exception handling
src/coreclr/vm/corelib.h Updated seven method definitions to reference the new UCO signatures and corrected method name (ResolveUsingResolvingEvent → ResolveUsingEvent)
src/coreclr/vm/appdomain.cpp Converted seven call sites from MethodDescCallSite to UnmanagedCallersOnlyCaller, updated argument passing to use pointers, and simplified code by removing ARG_SLOT array construction
src/coreclr/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs Removed two wrapper methods (ResolveSatelliteAssembly, ResolveUsingResolvingEvent) now replaced by UnmanagedCallersOnly wrappers in the main file

@jkotas
Copy link
Member

jkotas commented Feb 3, 2026

I assume this will need the wasm callhelpers update too.

Copilot AI review requested due to automatic review settings February 4, 2026 00:06
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 6 out of 6 changed files in this pull request and generated 3 comments.

{
try
{
*ppResult = OnTypeResolve(*pAssembly, new string(typeName));
Copy link
Member

Choose a reason for hiding this comment

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

new string(sbyte*) uses CP_ACP on Windows. I do not think you want that here. This should use Utf8StringMarshaller.ConvertToManaged or something like that.

Also, I would use byte* for the typeName. byte* is typically used for UTF8 throughout the BCL.

Copilot AI review requested due to automatic review settings February 4, 2026 04:20
@AaronRobinsonMSFT
Copy link
Member Author

I've got a type load level issue here.

Looking for any advice from @jkotas or @davidwrighton.

Assert failure(PID 34248 [0x000085c8], Thread: 34708 [0x8794]): CONTRACT VIOLATION by SigPointer::GetTypeHandleThrowing at "D:\a\_work\1\s\src\coreclr\vm\siginfo.cpp":1124

A function tried to load a type past the current level limit.

                        CONTRACT in SigPointer::GetTypeHandleThrowing at "D:\a\_work\1\s\src\coreclr\vm\siginfo.cpp":1124
                        CONTRACT in ZapSig::DecodeType at "D:\a\_work\1\s\src\coreclr\vm\zapsig.cpp":715
                        CONTRACT in LoadDynamicInfoEntry at "D:\a\_work\1\s\src\coreclr\vm\jitinterface.cpp":13866
                        CONTRACT in Module::FixupNativeEntry at "D:\a\_work\1\s\src\coreclr\vm\ceeload.cpp":3636
                        CONTRACT in Module::FixupDelayListAux at "D:\a\_work\1\s\src\coreclr\vm\ceeload.inl":379
                        CONTRACT in ReadyToRunInfo::GetEntryPoint at "D:\a\_work\1\s\src\coreclr\vm\readytoruninfo.cpp":1178
                        CONTRACT in MethodDesc::GetPrecompiledR2RCode at "D:\a\_work\1\s\src\coreclr\vm\prestub.cpp":472
                        CONTRACT in MethodDesc::GetPrecompiledCode at "D:\a\_work\1\s\src\coreclr\vm\prestub.cpp":417
                        CONTRACT in MethodDesc::PrepareILBasedCode at "D:\a\_work\1\s\src\coreclr\vm\prestub.cpp":340
                        CONTRACT in MethodDesc::PrepareCode at "D:\a\_work\1\s\src\coreclr\vm\prestub.cpp":310
                        CONTRACT in CodeVersionManager::PublishVersionableCodeIfNecessary at "D:\a\_work\1\s\src\coreclr\vm\codeversion.cpp":1717
                        CONTRACT in MethodDesc::DoPrestub at "D:\a\_work\1\s\src\coreclr\vm\prestub.cpp":2125
                        GCX_PREEMP in UnmanagedCallersOnlyCaller::InvokeThrowing at "D:\a\_work\1\s\src\coreclr\vm\callhelpers.h":720
                        CONTRACT in UnmanagedCallersOnlyCaller::InvokeThrowing at "D:\a\_work\1\s\src\coreclr\vm\callhelpers.h":710
                        GCX_COOP in RuntimeInvokeHostAssemblyResolver at "D:\a\_work\1\s\src\coreclr\vm\appdomain.cpp":4082
                        CONTRACT in RuntimeInvokeHostAssemblyResolver at "D:\a\_work\1\s\src\coreclr\vm\appdomain.cpp":4077
                        CONTRACT in AssemblySpec::Bind at "D:\a\_work\1\s\src\coreclr\vm\coreassemblyspec.cpp":40
                        GCX_PREEMP in AppDomain::BindAssemblySpec at "D:\a\_work\1\s\src\coreclr\vm\appdomain.cpp":3129
                        CONTRACT in PEAssembly::LoadAssembly at "D:\a\_work\1\s\src\coreclr\vm\peassembly.cpp":484
                        CONTRACT in Module::LoadAssemblyImpl at "D:\a\_work\1\s\src\coreclr\vm\ceeload.cpp":2457
                        ...
VIOLATED-->  OVERRIDE_TYPE_LOAD_LEVEL_LIMIT in ClassLoader::CreateTypeHandleForTypeDefThrowing at "D:\a\_work\1\s\src\coreclr\vm\methodtablebuilder.cpp":12850

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 6 out of 6 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

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants