Skip to content

Commit f09d2e8

Browse files
Disable GS cookie checks for LightUnwind (#109530)
LightUnwind does not track sufficient context to compute GS cookie address Fixes #109242 Co-authored-by: Jan Kotas <[email protected]>
1 parent e13eb14 commit f09d2e8

File tree

6 files changed

+46
-0
lines changed

6 files changed

+46
-0
lines changed

src/coreclr/inc/eetwain.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ virtual GenericParamContextType GetParamContextType(PREGDISPLAY pContext,
273273
*/
274274
virtual void * GetGSCookieAddr(PREGDISPLAY pContext,
275275
EECodeInfo * pCodeInfo,
276+
unsigned flags,
276277
CodeManState * pState) = 0;
277278

278279
#ifndef USE_GC_INFO_DECODER
@@ -541,6 +542,7 @@ PTR_VOID GetExactGenericsToken(SIZE_T baseStackSlot,
541542
virtual
542543
void * GetGSCookieAddr(PREGDISPLAY pContext,
543544
EECodeInfo * pCodeInfo,
545+
unsigned flags,
544546
CodeManState * pState);
545547

546548

src/coreclr/vm/eetwain.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,6 +1952,7 @@ PTR_VOID EECodeManager::GetExactGenericsToken(SIZE_T baseStackSlot,
19521952

19531953
void * EECodeManager::GetGSCookieAddr(PREGDISPLAY pContext,
19541954
EECodeInfo * pCodeInfo,
1955+
unsigned flags,
19551956
CodeManState * pState)
19561957
{
19571958
CONTRACTL {
@@ -1969,6 +1970,14 @@ void * EECodeManager::GetGSCookieAddr(PREGDISPLAY pContext,
19691970
}
19701971
#endif
19711972

1973+
#ifdef HAS_LIGHTUNWIND
1974+
// LightUnwind does not track sufficient context to compute GS cookie address
1975+
if (flags & LightUnwind)
1976+
{
1977+
return NULL;
1978+
}
1979+
#endif
1980+
19721981
#ifndef USE_GC_INFO_DECODER
19731982
_ASSERTE(sizeof(CodeManStateBuf) <= sizeof(pState->stateBuf));
19741983

src/coreclr/vm/exceptionhandling.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,6 +2054,7 @@ CLRUnwindStatus ExceptionTracker::ProcessOSExceptionNotification(
20542054
{
20552055
pGSCookie = (GSCookie*)cfThisFrame.GetCodeManager()->GetGSCookieAddr(cfThisFrame.pRD,
20562056
&cfThisFrame.codeInfo,
2057+
0 /* CodeManFlags */,
20572058
&cfThisFrame.codeManState);
20582059
if (pGSCookie)
20592060
{

src/coreclr/vm/stackwalk.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,6 +3185,7 @@ void StackFrameIterator::PreProcessingForManagedFrames(void)
31853185
m_pCachedGSCookie = (GSCookie*)m_crawl.GetCodeManager()->GetGSCookieAddr(
31863186
m_crawl.pRD,
31873187
&m_crawl.codeInfo,
3188+
m_codeManFlags,
31883189
&m_crawl.codeManState);
31893190
#endif // !DACCESS_COMPILE
31903191

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
using System;
4+
using System.Reflection;
5+
using Xunit;
6+
7+
public class Test109242
8+
{
9+
[Fact]
10+
public static void TestEntryPoint()
11+
{
12+
unsafe
13+
{
14+
void* p = stackalloc byte[Random.Shared.Next(100)];
15+
GC.KeepAlive(((IntPtr)p).ToString());
16+
}
17+
18+
Assembly.Load("System.Runtime");
19+
}
20+
}
21+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<CLRTestPriority>1</CLRTestPriority>
4+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<Compile Include="test109242.cs" />
8+
</ItemGroup>
9+
<ItemGroup>
10+
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
11+
</ItemGroup>
12+
</Project>

0 commit comments

Comments
 (0)