Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit fcfec0e

Browse files
committed
Introduce new UsesStackCrawlMarkAttribute to indicate a method uses StackCrawlMark
1 parent 89bf443 commit fcfec0e

File tree

6 files changed

+44
-12
lines changed

6 files changed

+44
-12
lines changed

src/mscorlib/mscorlib.shared.sources.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<CompilerServicesSources Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\YieldAwaitable.cs" />
6565
<CompilerServicesSources Condition="'$(FeatureCominterop)' == 'true'" Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\IDispatchConstantAttribute.cs" />
6666
<CompilerServicesSources Condition="'$(FeatureCoreClr)'!='true'" Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\IUnknownConstantAttribute.cs" />
67+
<CompilerServicesSources Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\UsesStackCrawlMarkAttribute.cs" />
6768
</ItemGroup>
6869
<ItemGroup>
6970
<ReliabilitySources Include="$(BclSourcesRoot)\System\Runtime\Reliability\CriticalFinalizerObject.cs" />
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
// See the LICENSE file in the project root for more information.
4+
5+
namespace System.Runtime.CompilerServices
6+
{
7+
// Indicates to the runtime that this method contains a StackCrawlMark
8+
// local variable. This prevents inlining of both caller and callee.
9+
10+
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method)]
11+
internal sealed class UsesStackCrawlMarkAttribute : Attribute
12+
{
13+
public UsesStackCrawlMarkAttribute() { }
14+
}
15+
}

src/vm/classnames.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@
153153

154154
#define g_CompilerServicesTypeDependencyAttribute "System.Runtime.CompilerServices.TypeDependencyAttribute"
155155

156+
#define g_UsesStackCrawlMarkAttribute "System.Threading.UsesStackCrawlMarkAttribute"
157+
156158
#define g_SecurityCriticalAttribute "System.Security.SecurityCriticalAttribute"
157159
#define g_SecurityTransparentAttribute "System.Security.SecurityTransparentAttribute"
158160
#ifndef FEATURE_CORECLR

src/vm/jitinterface.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6652,12 +6652,8 @@ DWORD CEEInfo::getMethodAttribsInternal (CORINFO_METHOD_HANDLE ftn)
66526652
result |= CORINFO_FLG_DONT_INLINE;
66536653

66546654
if (pMD->IsIL() && (IsMdRequireSecObject(attribs) ||
6655-
(pMD->GetModule()->IsSystem() && IsMiNoInlining(pMD->GetImplAttrs()))))
6655+
(pMD->GetModule()->IsSystem() && pMD->HasUsesStackCrawlMarkAttribute())))
66566656
{
6657-
// Assume all methods marked as NoInline inside mscorlib are
6658-
// marked that way because they use StackCrawlMark to identify
6659-
// the caller (not just the security info).
6660-
// See comments in canInline or canTailCall
66616657
result |= CORINFO_FLG_DONT_INLINE_CALLER;
66626658
}
66636659
}
@@ -7373,7 +7369,7 @@ CorInfoInline CEEInfo::canInline (CORINFO_METHOD_HANDLE hCaller,
73737369
// caller. Boundary methods are:
73747370
//
73757371
// 1) A method that calls anything that creates a StackCrawlMark to look for its caller. In this code
7376-
// this is approximated as "in mscorlib and is marked as NoInlining".
7372+
// this is determined by "in mscorlib and is marked as [UsesStackCrawlMark]".
73777373
// 2) A method that calls a method which calls Demand. These methods must be marked as
73787374
// IsMdRequireSecObject.
73797375
// 3) Calls anything that is virtual. This is because the virtual method could be #1 or #2.
@@ -8145,11 +8141,10 @@ bool CEEInfo::canTailCall (CORINFO_METHOD_HANDLE hCaller,
81458141
}
81468142

81478143
// Methods with StackCrawlMark depend on finding their caller on the stack.
8148-
// If we tail call one of these guys, they get confused. For lack of
8149-
// a better way of identifying them, we look for methods marked as NoInlining
8150-
// inside mscorlib (StackCrawlMark is private), and assume it is one of these
8151-
// methods. We have an assert in canInline that ensures all StackCrawlMark
8152-
// methods are appropriately marked.
8144+
// If we tail call one of these guys, they get confused. To identify them,
8145+
// we look for methods marked as [UsesStackCrawlMark] inside mscorlib.
8146+
// We have an assert in canInline that ensures all StackCrawlMark methods
8147+
// are appropriately marked.
81538148
//
81548149
// NOTE that this is *NOT* a security issue because we check to ensure that
81558150
// the callee has the *SAME* security properties as the caller, it just might
@@ -8158,7 +8153,7 @@ bool CEEInfo::canTailCall (CORINFO_METHOD_HANDLE hCaller,
81588153
// typenames.
81598154
if ((pExactCallee != NULL) && pExactCallee->GetModule()->IsSystem() && pExactCallee->IsIL())
81608155
{
8161-
if (IsMiNoInlining(pExactCallee->GetImplAttrs()))
8156+
if (pExactCallee->HasUsesStackCrawlMarkAttribute())
81628157
{
81638158
result = false;
81648159
szFailReason = "Callee might have a StackCrawlMark.LookForMyCaller";

src/vm/method.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5403,6 +5403,24 @@ BOOL MethodDesc::HasNativeCallableAttribute()
54035403
return FALSE;
54045404
}
54055405

5406+
BOOL MethodDesc::HasUsesStackCrawlMarkAttribute()
5407+
{
5408+
CONTRACTL
5409+
{
5410+
THROWS;
5411+
GC_NOTRIGGER;
5412+
FORBID_FAULT;
5413+
}
5414+
CONTRACTL_END;
5415+
5416+
HRESULT hr = GetMDImport()->GetCustomAttributeByName(GetMemberDef(),
5417+
g_UsesStackCrawlMarkAttribute,
5418+
nullptr,
5419+
nullptr);
5420+
5421+
return hr == S_OK;
5422+
}
5423+
54065424
//*******************************************************************************
54075425
BOOL MethodDesc::HasSuppressUnmanagedCodeAccessAttr()
54085426
{

src/vm/method.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ class MethodDesc
671671
void ComputeSuppressUnmanagedCodeAccessAttr(IMDInternalImport *pImport);
672672
BOOL HasSuppressUnmanagedCodeAccessAttr();
673673
BOOL HasNativeCallableAttribute();
674+
BOOL HasUsesStackCrawlMarkAttribute();
674675

675676
#ifdef FEATURE_COMINTEROP
676677
inline DWORD IsComPlusCall()

0 commit comments

Comments
 (0)