Skip to content

Replace MethodDescCallSite with UnmanagedCallersOnly for Priority 1 c…#124303

Merged
AaronRobinsonMSFT merged 15 commits intodotnet:mainfrom
AaronRobinsonMSFT:remove_mdcs_2
Feb 15, 2026
Merged

Replace MethodDescCallSite with UnmanagedCallersOnly for Priority 1 c…#124303
AaronRobinsonMSFT merged 15 commits intodotnet:mainfrom
AaronRobinsonMSFT:remove_mdcs_2

Conversation

@AaronRobinsonMSFT
Copy link
Member

…all sites

Convert the following MethodDescCallSite/CallDescrWorker calls to use UnmanagedCallersOnlyCaller with [UnmanagedCallersOnly] managed wrappers:

  • EventSource.InitializeDefaultEventSources (corhost.cpp)
  • StartupHookProvider.CallStartupHook (ds-rt-coreclr.h)
  • LoaderAllocator constructor (loaderallocator.cpp)
  • ColorMarshaler.ConvertToManaged/ConvertToNative (interoputil.cpp)
  • CultureInfo get/set CurrentCulture/CurrentUICulture (threads.cpp)
  • CultureInfo(int) constructor (interoputil.cpp)
  • Resolver.GetJitContext/GetCodeInfo/GetLocalsSignature/GetStringLiteral (dynamicmethod.cpp)

Contributes to #123864

…all sites

Convert the following MethodDescCallSite/CallDescrWorker calls to use
UnmanagedCallersOnlyCaller with [UnmanagedCallersOnly] managed wrappers:

- EventSource.InitializeDefaultEventSources (corhost.cpp)
- StartupHookProvider.CallStartupHook (ds-rt-coreclr.h)
- LoaderAllocator constructor (loaderallocator.cpp)
- ColorMarshaler.ConvertToManaged/ConvertToNative (interoputil.cpp)
- CultureInfo get/set CurrentCulture/CurrentUICulture (threads.cpp)
- CultureInfo(int) constructor (interoputil.cpp)
- Resolver.GetJitContext/GetCodeInfo/GetLocalsSignature/GetStringLiteral (dynamicmethod.cpp)

Contributes to dotnet#123864
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 PR converts several MethodDescCallSite/CallDescrWorker invocations to use the more efficient UnmanagedCallersOnly pattern with UnmanagedCallersOnlyCaller. This work is part of a broader effort (#123864) to modernize VM-to-managed code calling conventions by replacing the expensive CallDescrWorker mechanism with reverse P/Invoke infrastructure.

Changes:

  • Added [UnmanagedCallersOnly] wrapper methods in managed code for EventSource initialization, startup hooks, culture info operations, color marshaling, dynamic method resolution, and loader allocator creation
  • Updated native code to use UnmanagedCallersOnlyCaller template class instead of MethodDescCallSite, with appropriate GC protection for object references
  • Added metadata signatures in metasig.h and method definitions in corelib.h to support the new calling convention

Reviewed changes

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

Show a summary per file
File Description
src/libraries/System.Private.CoreLib/src/System/StartupHookProvider.cs Added UnmanagedCallersOnly wrapper for CallStartupHook method
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs Added UnmanagedCallersOnly wrappers for CurrentCulture/CurrentUICulture getters/setters and CultureInfo constructor
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs Added UnmanagedCallersOnly wrapper for InitializeDefaultEventSources
src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs Added UnmanagedCallersOnly wrappers for ColorMarshaler conversion methods
src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs Added UnmanagedCallersOnly wrappers for Resolver methods (GetJitContext, GetCodeInfo, GetLocalsSignature, GetStringLiteral)
src/coreclr/System.Private.CoreLib/src/System/Reflection/LoaderAllocator.cs Added UnmanagedCallersOnly factory method Create to replace constructor invocation pattern
src/coreclr/vm/threads.cpp Converted GetCulture/SetCulture to use UnmanagedCallersOnlyCaller with proper GC protection
src/coreclr/vm/loaderallocator.cpp Simplified LoaderAllocator initialization to use factory method pattern
src/coreclr/vm/interoputil.cpp Converted GetCultureInfoForLCID and color conversion methods to use UnmanagedCallersOnlyCaller
src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h Converted startup hook application to use UnmanagedCallersOnlyCaller
src/coreclr/vm/dynamicmethod.cpp Converted dynamic method resolver calls to use UnmanagedCallersOnlyCaller with proper GC protection for multi-field structures
src/coreclr/vm/corhost.cpp Converted event source initialization to use UnmanagedCallersOnlyCaller
src/coreclr/vm/metasig.h Added 10 new signature definitions for UnmanagedCallersOnly methods
src/coreclr/vm/corelib.h Updated method definitions to reference new UnmanagedCallersOnly entry points with _UCO suffixes or CREATE for factory methods

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

Copilot AI review requested due to automatic review settings February 12, 2026 18:12
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 19 out of 19 changed files in this pull request and generated 10 comments.

Copilot AI review requested due to automatic review settings February 13, 2026 04:27
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 21 out of 21 changed files in this pull request and generated no new comments.

@AaronRobinsonMSFT
Copy link
Member Author

@radekdoulik This is still failing with a signature mismatch. I'll try generating the data on linux.

[19:03:56] info: could not load /runArgs.json: 404. Ignoring
[19:03:56] info: Incoming arguments: --setenv=XHARNESS_LOG_TEST_START=true --run WasmTestRunner.dll System.Threading.Tasks.Tests.dll -notrait category=IgnoreForCI -notrait category=OuterLoop -notrait category=failing -verbosity Info
[19:03:56] info: Application arguments: --run WasmTestRunner.dll System.Threading.Tasks.Tests.dll -notrait category=IgnoreForCI -notrait category=OuterLoop -notrait category=failing -verbosity Info
[19:03:57] info: Initializing dotnet version 11.0.0 commit hash d3677f434f01c8d7ee16f0fa050d12a9e06295a5
[19:03:58] info: Using threadless Xunit runner
[19:03:58] info: Discovering: System.Threading.Tasks.Tests.dll (method display = ClassAndMethod, method display options = None)
[19:03:58] info: DOTNET: function signature mismatch
                 RuntimeError: function signature mismatch
                     at http://127.0.0.1:45567/_framework/dotnet.native.wu7tkr52qx.wasm:wasm-function[7275]:0x30ddb1
                     at http://127.0.0.1:45567/_framework/dotnet.native.wu7tkr52qx.wasm:wasm-function[1904]:0xb1946
                     at http://127.0.0.1:45567/_framework/dotnet.native.wu7tkr52qx.wasm:wasm-function[5924]:0x282bea
                     at http://127.0.0.1:45567/_framework/dotnet.native.wu7tkr52qx.wasm:wasm-function[6598]:0x2d15e3
                     at http://127.0.0.1:45567/_framework/dotnet.native.wu7tkr52qx.wasm:wasm-function[6599]:0x2d2231
                     at http://127.0.0.1:45567/_framework/dotnet.native.wu7tkr52qx.wasm:wasm-function[2606]:0x1193a7
                     at http://127.0.0.1:45567/_framework/dotnet.native.wu7tkr52qx.wasm:wasm-function[663]:0x33721
                     at http://127.0.0.1:45567/_framework/dotnet.native.wu7tkr52qx.wasm:wasm-function[2622]:0x121ca4
                     at http://127.0.0.1:45567/_framework/dotnet.native.wu7tkr52qx.wasm:wasm-function[4026]:0x1dc286
                     at http://127.0.0.1:45567/_framework/dotnet.native.wu7tkr52qx.wasm:wasm-function[255]:0x133e9
                     at http://127.0.0.1:45567/_framework/dotnet.native.wu7tkr52qx.wasm:wasm-function[3231]:0x160029
                     at _SystemJS_ExecuteBackgroundJobCallback (http://127.0.0.1:45567/_framework/dotnet.native.f8bal4x16h.js:8:125777)
                     at SystemJS_ScheduleBackgroundJobTick (http://127.0.0.1:45567/_framework/dotnet.native.f8bal4x16h.js:8:94806)
                     at callUserCallback (http://127.0.0.1:45567/_framework/dotnet.native.f8bal4x16h.js:8:122785)
                     at http://127.0.0.1:45567/_framework/dotnet.native.f8bal4x16h.js:8:122996

@AaronRobinsonMSFT
Copy link
Member Author

@radekdoulik Looks like problem with overloads. I'd forgotten about that. I added a check for UnmanagedCallersOnly in the look up logic. It should substantially reduce the occurrance of this issue.

Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

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

LGTM, thank you. I haven't tried to verify the sanity of the ‎src/coreclr/vm/wasm/callhelpers-reverse.cpp changes, I assume this is generated, right?

@AaronRobinsonMSFT
Copy link
Member Author

LGTM, thank you. I haven't tried to verify the sanity of the ‎src/coreclr/vm/wasm/callhelpers-reverse.cpp changes, I assume this is generated, right?

Yep, all generated. Hoping we can get that into a better pipeline or get crossgen up soon. It is a bit cumbersome at present. The instructions are solid though. Thanks @radekdoulik !

Copilot AI review requested due to automatic review settings February 13, 2026 22:47
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 24 out of 25 changed files in this pull request and generated no new comments.

@AaronRobinsonMSFT AaronRobinsonMSFT merged commit 3ea3efc into dotnet:main Feb 15, 2026
167 checks passed
@AaronRobinsonMSFT AaronRobinsonMSFT deleted the remove_mdcs_2 branch February 15, 2026 04:44
@github-project-automation github-project-automation bot moved this to Done in AppModel Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants