From f7300b56b7ad2f99162e3d47c5b72c6776939047 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 15 Jun 2023 18:48:40 -0700 Subject: [PATCH] Fix redundant MethodInfo lookup in UnixNativeCodeManager Fixes #75807 --- .../Runtime/unix/UnixNativeCodeManager.cpp | 19 +++++++++++++------ .../Runtime/unix/UnixNativeCodeManager.h | 4 ++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp b/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp index 2b46a8e015b46..658919608179a 100644 --- a/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp +++ b/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp @@ -368,15 +368,23 @@ bool UnixNativeCodeManager::UnwindStackFrame(MethodInfo * pMethodInfo, bool UnixNativeCodeManager::IsUnwindable(PTR_VOID pvAddress) { + MethodInfo * pMethodInfo = NULL; + +#if defined(TARGET_ARM64) + MethodInfo methodInfo; + FindMethodInfo(pvAddress, &methodInfo); + pMethodInfo = &methodInfo; +#endif + // VirtualUnwind can't unwind epilogues. - return TrailingEpilogueInstructionsCount(pvAddress) == 0; + return TrailingEpilogueInstructionsCount(pMethodInfo, pvAddress) == 0; } // when stopped in an epilogue, returns the count of remaining stack-consuming instructions // otherwise returns // 0 - not in epilogue, // -1 - unknown. -int UnixNativeCodeManager::TrailingEpilogueInstructionsCount(PTR_VOID pvAddress) +int UnixNativeCodeManager::TrailingEpilogueInstructionsCount(MethodInfo * pMethodInfo, PTR_VOID pvAddress) { #ifdef TARGET_AMD64 @@ -598,9 +606,8 @@ int UnixNativeCodeManager::TrailingEpilogueInstructionsCount(PTR_VOID pvAddress) #define BEGS_BITS 0x14000000 #define BEGS_MASK 0x1C000000 - MethodInfo pMethodInfo; - FindMethodInfo(pvAddress, &pMethodInfo); - UnixNativeMethodInfo* pNativeMethodInfo = (UnixNativeMethodInfo*)&pMethodInfo; + UnixNativeMethodInfo * pNativeMethodInfo = (UnixNativeMethodInfo *)pMethodInfo; + ASSERT(pNativeMethodInfo != NULL); uint32_t* start = (uint32_t*)pNativeMethodInfo->pMethodStartAddress; @@ -699,7 +706,7 @@ bool UnixNativeCodeManager::GetReturnAddressHijackInfo(MethodInfo * pMethodIn GcInfoDecoder decoder(GCInfoToken(p), flags); *pRetValueKind = GetGcRefKind(decoder.GetReturnKind()); - int epilogueInstructions = TrailingEpilogueInstructionsCount((PTR_VOID)pRegisterSet->IP); + int epilogueInstructions = TrailingEpilogueInstructionsCount(pMethodInfo, (PTR_VOID)pRegisterSet->IP); if (epilogueInstructions < 0) { // can't figure, possibly a breakpoint instruction diff --git a/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.h b/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.h index 1b20f85cad79b..5998572edeb98 100644 --- a/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.h +++ b/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.h @@ -59,11 +59,11 @@ class UnixNativeCodeManager : public ICodeManager PInvokeTransitionFrame** ppPreviousTransitionFrame); // out uintptr_t GetConservativeUpperBoundForOutgoingArgs(MethodInfo * pMethodInfo, - REGDISPLAY * pRegisterSet); + REGDISPLAY * pRegisterSet); bool IsUnwindable(PTR_VOID pvAddress); - int TrailingEpilogueInstructionsCount(PTR_VOID pvAddress); + int TrailingEpilogueInstructionsCount(MethodInfo * pMethodInfo, PTR_VOID pvAddress); bool GetReturnAddressHijackInfo(MethodInfo * pMethodInfo, REGDISPLAY * pRegisterSet, // in