Skip to content

Commit 13f9524

Browse files
[release/10.0-rc1] JIT: fix issue with EH clause class types for fault/filters from C++/CLI (#118905)
* JIT: fix issue with EH clause class types for fault/filters from C++/CLI C++/CLI appears to leave the CORINFO_EH_CLAUSE ClassToken/FilterOffset union set to some nonzero value for fault/filter clauses. The JIT currently just passes this value along to the runtime. If a method with such a nonzero field is inlined into a dynamic method, this trips up a check in the runtime where a nonzero entry for such a field is interpreted as a class handle, even for fault/filter clauses where it should be ignored. Tolerate this by zeroing the field in the JIT. Note this could not have happened in pre .NET10 as methods with EH could not be inlined, so a dynamic method would never see such an EH clause, and in non-dynamic methods this field is ignored for faults and filters. Fixes #118837. * review feedback * zero eh table on alloc/realloc --------- Co-authored-by: Andy Ayers <[email protected]>
1 parent e2b61c7 commit 13f9524

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

src/coreclr/jit/fgbasic.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3741,31 +3741,32 @@ void Compiler::fgFindBasicBlocks()
37413741
}
37423742
else
37433743
{
3744-
HBtab->ebdTyp = clause.ClassToken;
3745-
3746-
/* Set bbCatchTyp as appropriate */
3747-
3744+
// Set ebdTyp and bbCatchTyp as appropriate
3745+
//
37483746
if (clause.Flags & CORINFO_EH_CLAUSE_FINALLY)
37493747
{
37503748
hndBegBB->bbCatchTyp = BBCT_FINALLY;
3749+
HBtab->ebdTyp = 0;
37513750
}
37523751
else
37533752
{
37543753
if (clause.Flags & CORINFO_EH_CLAUSE_FAULT)
37553754
{
37563755
hndBegBB->bbCatchTyp = BBCT_FAULT;
3756+
HBtab->ebdTyp = 0;
37573757
}
37583758
else
37593759
{
3760-
hndBegBB->bbCatchTyp = clause.ClassToken;
3761-
37623760
// These values should be non-zero value that will
37633761
// not collide with real tokens for bbCatchTyp
37643762
if (clause.ClassToken == 0)
37653763
{
37663764
BADCODE("Exception catch type is Null");
37673765
}
37683766

3767+
hndBegBB->bbCatchTyp = clause.ClassToken;
3768+
HBtab->ebdTyp = clause.ClassToken;
3769+
37693770
noway_assert(clause.ClassToken != BBCT_FAULT);
37703771
noway_assert(clause.ClassToken != BBCT_FINALLY);
37713772
noway_assert(clause.ClassToken != BBCT_FILTER);

src/coreclr/jit/jiteh.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,8 @@ void Compiler::fgAllocEHTable()
15221522

15231523
compHndBBtab = new (this, CMK_BasicBlock) EHblkDsc[compHndBBtabAllocCount];
15241524

1525+
memset(compHndBBtab, 0, compHndBBtabAllocCount * sizeof(*compHndBBtab));
1526+
15251527
compHndBBtabCount = info.compXcptnsCount;
15261528
}
15271529

@@ -1883,6 +1885,10 @@ EHblkDsc* Compiler::fgTryAddEHTableEntries(unsigned XTnum, unsigned count, bool
18831885

18841886
EHblkDsc* newTable = new (this, CMK_BasicBlock) EHblkDsc[compHndBBtabAllocCount];
18851887

1888+
// Zero the storage
1889+
1890+
memset(newTable, 0, compHndBBtabAllocCount * sizeof(*compHndBBtab));
1891+
18861892
// Move over the stuff before the new entries
18871893

18881894
memcpy_s(newTable, compHndBBtabAllocCount * sizeof(*compHndBBtab), compHndBBtab, XTnum * sizeof(*compHndBBtab));

src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,8 +3117,8 @@ private void setEHcount(uint cEH)
31173117

31183118
private void setEHinfo(uint EHnumber, ref CORINFO_EH_CLAUSE clause)
31193119
{
3120-
// Filters don't have class token in the clause.ClassTokenOrOffset
3121-
if ((clause.Flags & CORINFO_EH_CLAUSE_FLAGS.CORINFO_EH_CLAUSE_FILTER) == 0)
3120+
// Filters, finallys, and faults don't have class token in the clause.ClassTokenOrOffset
3121+
if ((clause.Flags & (CORINFO_EH_CLAUSE_FLAGS.CORINFO_EH_CLAUSE_FILTER | CORINFO_EH_CLAUSE_FLAGS.CORINFO_EH_CLAUSE_FINALLY | CORINFO_EH_CLAUSE_FLAGS.CORINFO_EH_CLAUSE_FAULT)) == 0)
31223122
{
31233123
if (clause.ClassTokenOrOffset != 0)
31243124
{

src/coreclr/vm/jitinterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12734,7 +12734,7 @@ void CEECodeGenInfo::setEHinfoWorker(
1273412734
LOG((LF_EH, LL_INFO1000000, " FilterOffset : 0x%08lx -> 0x%08lx\n", clause->FilterOffset, pEHClause->FilterOffset));
1273512735

1273612736
if (IsDynamicScope(m_MethodInfo.scope) &&
12737-
((pEHClause->Flags & COR_ILEXCEPTION_CLAUSE_FILTER) == 0) &&
12737+
((pEHClause->Flags & (COR_ILEXCEPTION_CLAUSE_FILTER | COR_ILEXCEPTION_CLAUSE_FINALLY | COR_ILEXCEPTION_CLAUSE_FAULT)) == 0) &&
1273812738
(clause->ClassToken != mdTokenNil))
1273912739
{
1274012740
ResolvedToken resolved{};

0 commit comments

Comments
 (0)