From 4b6b0dddcdc5834093f085b51c64aee01bf0c998 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Mon, 27 Jul 2026 15:56:56 -0700 Subject: [PATCH 1/3] Fix missed case of COOP to PREEMPT transition Fixes #131435 --- src/coreclr/vm/interpexec.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/interpexec.cpp b/src/coreclr/vm/interpexec.cpp index c6b267c184db0d..427be0b810885b 100644 --- a/src/coreclr/vm/interpexec.cpp +++ b/src/coreclr/vm/interpexec.cpp @@ -463,6 +463,20 @@ void InvokeUnmanagedMethod(MethodDesc *targetMethod, int8_t *pArgs, int8_t *pRet InvokeManagedMethod(targetMethod, pArgs, pRet, callTarget, NULL); } +static NOINLINE CallStubHeader* InvokeDelegateInvokeMethodHelper(MethodDesc *pMDDelegateInvoke) +{ + CONTRACTL + { + THROWS; + MODE_ANY; + PRECONDITION(CheckPointer(pMDDelegateInvoke)); + } + CONTRACTL_END + + GCX_PREEMP(); + return UpdateCallStubForMethod(pMDDelegateInvoke, (PCODE)pMDDelegateInvoke->GetMultiCallableAddrOfCode(CORINFO_ACCESS_ANY)); +} + void InvokeDelegateInvokeMethod(MethodDesc *pMDDelegateInvoke, int8_t *pArgs, int8_t *pRet, PCODE target, Object** pContinuationRet) { CONTRACTL @@ -478,7 +492,7 @@ void InvokeDelegateInvokeMethod(MethodDesc *pMDDelegateInvoke, int8_t *pArgs, in CallStubHeader *stubHeaderTemplate = pMDDelegateInvoke->GetCalliCookie(); if (stubHeaderTemplate == NULL) { - stubHeaderTemplate = UpdateCallStubForMethod(pMDDelegateInvoke, (PCODE)pMDDelegateInvoke->GetMultiCallableAddrOfCode(CORINFO_ACCESS_ANY)); + stubHeaderTemplate = InvokeDelegateInvokeMethodHelper(pMDDelegateInvoke); } // CallStubHeaders encode their destination addresses in the Routines array, so they need to be From 63f6b12392c3609db24df932ebe712a2ac93fef0 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Mon, 27 Jul 2026 16:11:40 -0700 Subject: [PATCH 2/3] Fix additional case found by copilot --- src/coreclr/vm/interpexec.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/interpexec.cpp b/src/coreclr/vm/interpexec.cpp index 427be0b810885b..f82ce1c7a94e66 100644 --- a/src/coreclr/vm/interpexec.cpp +++ b/src/coreclr/vm/interpexec.cpp @@ -411,6 +411,20 @@ MethodDesc* GetTargetPInvokeMethodDesc(PCODE target) return NULL; } +static NOINLINE CallStubHeader *InvokeManagedMethodHelper(MethodDesc *pMD, PCODE target) +{ + CONTRACTL + { + THROWS; + MODE_ANY; + PRECONDITION(CheckPointer(pMD)); + } + CONTRACTL_END + + GCX_PREEMP(); + return UpdateCallStubForMethod(pMD, target == (PCODE)NULL ? pMD->GetMultiCallableAddrOfCode(CORINFO_ACCESS_ANY) : target); +} + void InvokeManagedMethod(MethodDesc *pMD, int8_t *pArgs, int8_t *pRet, PCODE target, Object** pContinuationRet) { CONTRACTL @@ -426,7 +440,7 @@ void InvokeManagedMethod(MethodDesc *pMD, int8_t *pArgs, int8_t *pRet, PCODE tar CallStubHeader *pHeader = pMD->GetCalliCookie(); if (pHeader == NULL) { - pHeader = UpdateCallStubForMethod(pMD, target == (PCODE)NULL ? pMD->GetMultiCallableAddrOfCode(CORINFO_ACCESS_ANY) : target); + pHeader = InvokeManagedMethodHelper(pMD, target); } if (target != (PCODE)NULL) From 4980541363324dfe4a782fe5ca818839a1f9502b Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Mon, 27 Jul 2026 16:12:27 -0700 Subject: [PATCH 3/3] Fix formatting nit --- src/coreclr/vm/interpexec.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/vm/interpexec.cpp b/src/coreclr/vm/interpexec.cpp index f82ce1c7a94e66..f4f9f1da00bde0 100644 --- a/src/coreclr/vm/interpexec.cpp +++ b/src/coreclr/vm/interpexec.cpp @@ -477,7 +477,7 @@ void InvokeUnmanagedMethod(MethodDesc *targetMethod, int8_t *pArgs, int8_t *pRet InvokeManagedMethod(targetMethod, pArgs, pRet, callTarget, NULL); } -static NOINLINE CallStubHeader* InvokeDelegateInvokeMethodHelper(MethodDesc *pMDDelegateInvoke) +static NOINLINE CallStubHeader *InvokeDelegateInvokeMethodHelper(MethodDesc *pMDDelegateInvoke) { CONTRACTL {