From 145fb86fd3759c16f437e768dd4d20394e1cd87e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 26 Jan 2026 21:04:50 +0000 Subject: [PATCH 1/4] Initial plan From 14fc63e73d2464f835190242bf0722cc4dd6fc86 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 26 Jan 2026 21:16:20 +0000 Subject: [PATCH 2/4] Fix TraceDestination types to have valid PCODE address Modified InitForMulticastDelegateHelper() and InitForExternalMethodFixup() to accept a PCODE addr parameter instead of setting address to NULL. This fixes the invariant that GetAddress() works for non-TRACE_UNJITTED_METHOD types. Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com> --- src/coreclr/vm/stubmgr.cpp | 4 ++-- src/coreclr/vm/stubmgr.h | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/coreclr/vm/stubmgr.cpp b/src/coreclr/vm/stubmgr.cpp index cbae7c8a2f2045..5beeec127ec9bf 100644 --- a/src/coreclr/vm/stubmgr.cpp +++ b/src/coreclr/vm/stubmgr.cpp @@ -1566,7 +1566,7 @@ BOOL RangeSectionStubManager::DoTraceStub(PCODE stubStartAddress, TraceDestinati #ifdef DACCESS_COMPILE DacNotImpl(); #else - trace->InitForExternalMethodFixup(); + trace->InitForExternalMethodFixup(stubStartAddress); #endif return TRUE; @@ -1679,7 +1679,7 @@ BOOL ILStubManager::DoTraceStub(PCODE stubStartAddress, MethodDesc* pStubMD = ExecutionManager::GetCodeMethodDesc(stubStartAddress); if (pStubMD != NULL && pStubMD->AsDynamicMethodDesc()->IsMulticastStub()) { - trace->InitForMulticastDelegateHelper(); + trace->InitForMulticastDelegateHelper(stubStartAddress); } else { diff --git a/src/coreclr/vm/stubmgr.h b/src/coreclr/vm/stubmgr.h index 47eb5d2f8aa20b..e281e7c584971e 100644 --- a/src/coreclr/vm/stubmgr.h +++ b/src/coreclr/vm/stubmgr.h @@ -150,17 +150,17 @@ class TraceDestination } - void InitForMulticastDelegateHelper() + void InitForMulticastDelegateHelper(PCODE addr) { this->type = TRACE_MULTICAST_DELEGATE_HELPER; - this->address = (PCODE)NULL; + this->address = addr; this->stubManager = NULL; } - void InitForExternalMethodFixup() + void InitForExternalMethodFixup(PCODE addr) { this->type = TRACE_EXTERNAL_METHOD_FIXUP; - this->address = (PCODE)NULL; + this->address = addr; this->stubManager = NULL; } From 0eec95b4ce54d41c78979944d98f90cc007d08e5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Jan 2026 16:06:39 +0000 Subject: [PATCH 3/4] Fix AV in IsTailCall by checking for NULL trace address Reverted changes to stubmgr.h and stubmgr.cpp since NULL addresses are by-design for TRACE_MULTICAST_DELEGATE_HELPER and TRACE_EXTERNAL_METHOD_FIXUP. Instead, fixed the AV bug in IsTailCall (controller.cpp) by checking if trace.GetAddress() returns NULL before calling GetNativeCodeMethodDesc. Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com> --- src/coreclr/debug/ee/controller.cpp | 13 +++++++++---- src/coreclr/vm/stubmgr.cpp | 4 ++-- src/coreclr/vm/stubmgr.h | 8 ++++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/coreclr/debug/ee/controller.cpp b/src/coreclr/debug/ee/controller.cpp index 14b14ff97e7b90..7e4d809702c2c4 100644 --- a/src/coreclr/debug/ee/controller.cpp +++ b/src/coreclr/debug/ee/controller.cpp @@ -5831,10 +5831,15 @@ static bool IsTailCall(const BYTE * ip, ControllerStackInfo* info, TailCallFunct return false; } - MethodDesc* pTargetMD = - trace.GetTraceType() == TRACE_UNJITTED_METHOD - ? trace.GetMethodDesc() - : g_pEEInterface->GetNativeCodeMethodDesc(trace.GetAddress()); + MethodDesc* pTargetMD = NULL; + if (trace.GetTraceType() == TRACE_UNJITTED_METHOD) + { + pTargetMD = trace.GetMethodDesc(); + } + else if (trace.GetAddress() != NULL) + { + pTargetMD = g_pEEInterface->GetNativeCodeMethodDesc(trace.GetAddress()); + } if (type == TailCallFunctionType::StoreTailCallArgs) { diff --git a/src/coreclr/vm/stubmgr.cpp b/src/coreclr/vm/stubmgr.cpp index 5beeec127ec9bf..cbae7c8a2f2045 100644 --- a/src/coreclr/vm/stubmgr.cpp +++ b/src/coreclr/vm/stubmgr.cpp @@ -1566,7 +1566,7 @@ BOOL RangeSectionStubManager::DoTraceStub(PCODE stubStartAddress, TraceDestinati #ifdef DACCESS_COMPILE DacNotImpl(); #else - trace->InitForExternalMethodFixup(stubStartAddress); + trace->InitForExternalMethodFixup(); #endif return TRUE; @@ -1679,7 +1679,7 @@ BOOL ILStubManager::DoTraceStub(PCODE stubStartAddress, MethodDesc* pStubMD = ExecutionManager::GetCodeMethodDesc(stubStartAddress); if (pStubMD != NULL && pStubMD->AsDynamicMethodDesc()->IsMulticastStub()) { - trace->InitForMulticastDelegateHelper(stubStartAddress); + trace->InitForMulticastDelegateHelper(); } else { diff --git a/src/coreclr/vm/stubmgr.h b/src/coreclr/vm/stubmgr.h index e281e7c584971e..47eb5d2f8aa20b 100644 --- a/src/coreclr/vm/stubmgr.h +++ b/src/coreclr/vm/stubmgr.h @@ -150,17 +150,17 @@ class TraceDestination } - void InitForMulticastDelegateHelper(PCODE addr) + void InitForMulticastDelegateHelper() { this->type = TRACE_MULTICAST_DELEGATE_HELPER; - this->address = addr; + this->address = (PCODE)NULL; this->stubManager = NULL; } - void InitForExternalMethodFixup(PCODE addr) + void InitForExternalMethodFixup() { this->type = TRACE_EXTERNAL_METHOD_FIXUP; - this->address = addr; + this->address = (PCODE)NULL; this->stubManager = NULL; } From 99584e4a0d5bf6b1265172516569804e4f9c61ef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Jan 2026 16:54:02 +0000 Subject: [PATCH 4/4] Fix build error: use (PCODE)NULL for PCODE comparison PCODE is unsigned long and cannot be compared directly to NULL (std::nullptr_t). Updated the comparison to use (PCODE)NULL to match existing patterns in the codebase. Co-authored-by: max-charlamb <44248479+max-charlamb@users.noreply.github.com> --- src/coreclr/debug/ee/controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/debug/ee/controller.cpp b/src/coreclr/debug/ee/controller.cpp index 7e4d809702c2c4..d40de63bd9e512 100644 --- a/src/coreclr/debug/ee/controller.cpp +++ b/src/coreclr/debug/ee/controller.cpp @@ -5836,7 +5836,7 @@ static bool IsTailCall(const BYTE * ip, ControllerStackInfo* info, TailCallFunct { pTargetMD = trace.GetMethodDesc(); } - else if (trace.GetAddress() != NULL) + else if (trace.GetAddress() != (PCODE)NULL) { pTargetMD = g_pEEInterface->GetNativeCodeMethodDesc(trace.GetAddress()); }