Skip to content

Commit

Permalink
Disable GS cookie checks for LightUnwind (#109530)
Browse files Browse the repository at this point in the history
LightUnwind does not track sufficient context to compute GS cookie address

Fixes #109242

Co-authored-by: Jan Kotas <[email protected]>
  • Loading branch information
github-actions[bot] and jkotas authored Jan 9, 2025
1 parent e13eb14 commit f09d2e8
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/coreclr/inc/eetwain.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -541,6 +542,7 @@ PTR_VOID GetExactGenericsToken(SIZE_T baseStackSlot,
virtual
void * GetGSCookieAddr(PREGDISPLAY pContext,
EECodeInfo * pCodeInfo,
unsigned flags,
CodeManState * pState);


Expand Down
9 changes: 9 additions & 0 deletions src/coreclr/vm/eetwain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,7 @@ PTR_VOID EECodeManager::GetExactGenericsToken(SIZE_T baseStackSlot,

void * EECodeManager::GetGSCookieAddr(PREGDISPLAY pContext,
EECodeInfo * pCodeInfo,
unsigned flags,
CodeManState * pState)
{
CONTRACTL {
Expand All @@ -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));

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/vm/exceptionhandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2054,6 +2054,7 @@ CLRUnwindStatus ExceptionTracker::ProcessOSExceptionNotification(
{
pGSCookie = (GSCookie*)cfThisFrame.GetCodeManager()->GetGSCookieAddr(cfThisFrame.pRD,
&cfThisFrame.codeInfo,
0 /* CodeManFlags */,
&cfThisFrame.codeManState);
if (pGSCookie)
{
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/vm/stackwalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3185,6 +3185,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

Expand Down
21 changes: 21 additions & 0 deletions src/tests/Regressions/coreclr/GitHub_109242/test109242.cs
Original file line number Diff line number Diff line change
@@ -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");
}
}

12 changes: 12 additions & 0 deletions src/tests/Regressions/coreclr/GitHub_109242/test109242.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<CLRTestPriority>1</CLRTestPriority>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="test109242.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
</ItemGroup>
</Project>

0 comments on commit f09d2e8

Please sign in to comment.