diff --git a/src/coreclr/inc/eetwain.h b/src/coreclr/inc/eetwain.h index c7b1be02e5c638..4ee7b9a7b84b6e 100644 --- a/src/coreclr/inc/eetwain.h +++ b/src/coreclr/inc/eetwain.h @@ -273,6 +273,7 @@ virtual GenericParamContextType GetParamContextType(PREGDISPLAY pContext, */ virtual void * GetGSCookieAddr(PREGDISPLAY pContext, EECodeInfo * pCodeInfo, + unsigned flags, CodeManState * pState) = 0; #ifndef USE_GC_INFO_DECODER @@ -541,6 +542,7 @@ PTR_VOID GetExactGenericsToken(SIZE_T baseStackSlot, virtual void * GetGSCookieAddr(PREGDISPLAY pContext, EECodeInfo * pCodeInfo, + unsigned flags, CodeManState * pState); diff --git a/src/coreclr/vm/eetwain.cpp b/src/coreclr/vm/eetwain.cpp index 5746c44de4a770..618077b1b105c7 100644 --- a/src/coreclr/vm/eetwain.cpp +++ b/src/coreclr/vm/eetwain.cpp @@ -1952,6 +1952,7 @@ PTR_VOID EECodeManager::GetExactGenericsToken(SIZE_T baseStackSlot, void * EECodeManager::GetGSCookieAddr(PREGDISPLAY pContext, EECodeInfo * pCodeInfo, + unsigned flags, CodeManState * pState) { CONTRACTL { @@ -1969,6 +1970,14 @@ void * EECodeManager::GetGSCookieAddr(PREGDISPLAY pContext, } #endif +#ifdef HAS_LIGHTUNWIND + // LightUnwind does not track sufficient context to compute GS cookie address + if (flags & LightUnwind) + { + return NULL; + } +#endif + #ifndef USE_GC_INFO_DECODER _ASSERTE(sizeof(CodeManStateBuf) <= sizeof(pState->stateBuf)); diff --git a/src/coreclr/vm/exceptionhandling.cpp b/src/coreclr/vm/exceptionhandling.cpp index 62a536442f492e..15c12548f03813 100644 --- a/src/coreclr/vm/exceptionhandling.cpp +++ b/src/coreclr/vm/exceptionhandling.cpp @@ -2054,6 +2054,7 @@ CLRUnwindStatus ExceptionTracker::ProcessOSExceptionNotification( { pGSCookie = (GSCookie*)cfThisFrame.GetCodeManager()->GetGSCookieAddr(cfThisFrame.pRD, &cfThisFrame.codeInfo, + 0 /* CodeManFlags */, &cfThisFrame.codeManState); if (pGSCookie) { diff --git a/src/coreclr/vm/stackwalk.cpp b/src/coreclr/vm/stackwalk.cpp index 8a0d2e4eb8e634..70ae26185edf82 100644 --- a/src/coreclr/vm/stackwalk.cpp +++ b/src/coreclr/vm/stackwalk.cpp @@ -3152,6 +3152,7 @@ void StackFrameIterator::PreProcessingForManagedFrames(void) m_pCachedGSCookie = (GSCookie*)m_crawl.GetCodeManager()->GetGSCookieAddr( m_crawl.pRD, &m_crawl.codeInfo, + m_codeManFlags, &m_crawl.codeManState); #endif // !DACCESS_COMPILE diff --git a/src/tests/Regressions/coreclr/GitHub_109242/test109242.cs b/src/tests/Regressions/coreclr/GitHub_109242/test109242.cs new file mode 100644 index 00000000000000..080744316bdd73 --- /dev/null +++ b/src/tests/Regressions/coreclr/GitHub_109242/test109242.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +using System; +using System.Reflection; +using Xunit; + +public class Test109242 +{ + [Fact] + public static void TestEntryPoint() + { + unsafe + { + void* p = stackalloc byte[Random.Shared.Next(100)]; + GC.KeepAlive(((IntPtr)p).ToString()); + } + + Assembly.Load("System.Runtime"); + } +} + diff --git a/src/tests/Regressions/coreclr/GitHub_109242/test109242.csproj b/src/tests/Regressions/coreclr/GitHub_109242/test109242.csproj new file mode 100644 index 00000000000000..4eace003accf0b --- /dev/null +++ b/src/tests/Regressions/coreclr/GitHub_109242/test109242.csproj @@ -0,0 +1,11 @@ + + + 1 + + + + + + + +