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

Commit 22c5cb0

Browse files
jkotasstephentoub
authored andcommitted
Fix override detection to work reliably for JITed mscorlib
1 parent 9c2ebf0 commit 22c5cb0

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

src/vm/comutilnative.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3164,6 +3164,31 @@ static MethodTable * g_pStreamMT;
31643164
static WORD g_slotBeginRead, g_slotEndRead;
31653165
static WORD g_slotBeginWrite, g_slotEndWrite;
31663166

3167+
static bool HasOverriddenStreamMethod(MethodTable * pMT, WORD slot)
3168+
{
3169+
CONTRACTL{
3170+
NOTHROW;
3171+
GC_NOTRIGGER;
3172+
MODE_ANY;
3173+
SO_TOLERANT;
3174+
} CONTRACTL_END;
3175+
3176+
PCODE actual = pMT->GetRestoredSlot(slot);
3177+
PCODE base = g_pStreamMT->GetRestoredSlot(slot);
3178+
if (actual == base)
3179+
return false;
3180+
3181+
if (!g_pStreamMT->IsZapped())
3182+
{
3183+
// If mscorlib is JITed, the slots can be patched and thus we need to compare the actual MethodDescs
3184+
// to detect match reliably
3185+
if (MethodTable::GetMethodDescForSlotAddress(actual) == MethodTable::GetMethodDescForSlotAddress(base))
3186+
return false;
3187+
}
3188+
3189+
return true;
3190+
}
3191+
31673192
FCIMPL1(FC_BOOL_RET, StreamNative::HasOverriddenBeginEndRead, Object *stream)
31683193
{
31693194
FCALL_CONTRACT;
@@ -3182,10 +3207,7 @@ FCIMPL1(FC_BOOL_RET, StreamNative::HasOverriddenBeginEndRead, Object *stream)
31823207

31833208
MethodTable * pMT = stream->GetMethodTable();
31843209

3185-
FC_RETURN_BOOL(
3186-
pMT->GetRestoredSlot(g_slotBeginRead) != g_pStreamMT->GetRestoredSlot(g_slotBeginRead) ||
3187-
pMT->GetRestoredSlot(g_slotEndRead) != g_pStreamMT->GetRestoredSlot(g_slotEndRead)
3188-
);
3210+
FC_RETURN_BOOL(HasOverriddenStreamMethod(pMT, g_slotBeginRead) || HasOverriddenStreamMethod(pMT, g_slotEndRead));
31893211
}
31903212
FCIMPLEND
31913213

@@ -3207,9 +3229,6 @@ FCIMPL1(FC_BOOL_RET, StreamNative::HasOverriddenBeginEndWrite, Object *stream)
32073229

32083230
MethodTable * pMT = stream->GetMethodTable();
32093231

3210-
FC_RETURN_BOOL(
3211-
pMT->GetRestoredSlot(g_slotBeginWrite) != g_pStreamMT->GetRestoredSlot(g_slotBeginWrite) ||
3212-
pMT->GetRestoredSlot(g_slotEndWrite) != g_pStreamMT->GetRestoredSlot(g_slotEndWrite)
3213-
);
3232+
FC_RETURN_BOOL(HasOverriddenStreamMethod(pMT, g_slotBeginWrite) || HasOverriddenStreamMethod(pMT, g_slotEndWrite));
32143233
}
32153234
FCIMPLEND

0 commit comments

Comments
 (0)