Skip to content

Commit 79b1cd2

Browse files
committed
Disable GS checks in Reverse P/Invoke stubs to avoid missing these copies.
1 parent e9bb29e commit 79b1cd2

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/coreclr/vm/jitinterface.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3743,8 +3743,18 @@ uint32_t CEEInfo::getClassAttribsInternal (CORINFO_CLASS_HANDLE clsHnd)
37433743
if (pMT->IsByRefLike())
37443744
ret |= CORINFO_FLG_BYREF_LIKE;
37453745

3746-
if (pClass->IsUnsafeValueClass())
3746+
// In Reverse P/Invoke stubs, we are generating the code
3747+
// and we are not generating the code patterns that the GS checks
3748+
// are meant to catch.
3749+
// As a result, we can skip setting this flag.
3750+
// We do this as the GS checks (emitted when this flag is set)
3751+
// can break C++/CLI's copy-constructor semantics by missing copies.
3752+
if (pClass->IsUnsafeValueClass()
3753+
&& !(m_pMethodBeingCompiled->IsILStub()
3754+
&& dac_cast<PTR_DynamicMethodDesc>(m_pMethodBeingCompiled)->GetILStubType() == DynamicMethodDesc::StubNativeToCLRInterop))
3755+
{
37473756
ret |= CORINFO_FLG_UNSAFE_VALUECLASS;
3757+
}
37483758
}
37493759
if (pClass->HasExplicitFieldOffsetLayout() && pClass->HasOverlaidField())
37503760
ret |= CORINFO_FLG_OVERLAPPING_FIELDS;

0 commit comments

Comments
 (0)