From c71e49d86911a923ae2e6068bfb11b41471939f5 Mon Sep 17 00:00:00 2001 From: liiir1985 Date: Wed, 25 May 2022 21:05:59 +0800 Subject: [PATCH] Fixed #692 --- ILRuntime/Runtime/Intepreter/ILIntepreter.cs | 11 +++++++++-- .../Intepreter/RegisterVM/ILIntepreter.Register.cs | 7 +++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ILRuntime/Runtime/Intepreter/ILIntepreter.cs b/ILRuntime/Runtime/Intepreter/ILIntepreter.cs index 998b7df5..a284e0e9 100644 --- a/ILRuntime/Runtime/Intepreter/ILIntepreter.cs +++ b/ILRuntime/Runtime/Intepreter/ILIntepreter.cs @@ -1948,6 +1948,13 @@ public object Run(ILMethod method, object instance, object[] p) } else { + intVal = (int)(ip - ptr); + var eh = FindExceptionHandlerByBranchTarget(intVal, finallyEndAddress, ehs); + if (eh != null) + { + ip = ptr + eh.HandlerStart; + continue; + } ip = ptr + finallyEndAddress; finallyEndAddress = 0; continue; @@ -4648,8 +4655,8 @@ ExceptionHandler FindExceptionHandlerByBranchTarget(int addr, int branchTarget, var e = ehs[i]; if (addr >= e.TryStart && addr <= e.TryEnd && (branchTarget < e.TryStart || branchTarget > e.TryEnd) && e.HandlerType == ExceptionHandlerType.Finally) { - eh = e; - break; + if (eh == null || e.TryStart > eh.TryStart) + eh = e; } } return eh; diff --git a/ILRuntime/Runtime/Intepreter/RegisterVM/ILIntepreter.Register.cs b/ILRuntime/Runtime/Intepreter/RegisterVM/ILIntepreter.Register.cs index 85886e92..a544b235 100644 --- a/ILRuntime/Runtime/Intepreter/RegisterVM/ILIntepreter.Register.cs +++ b/ILRuntime/Runtime/Intepreter/RegisterVM/ILIntepreter.Register.cs @@ -2776,6 +2776,13 @@ public unsafe partial class ILIntepreter } else { + intVal = (int)(ip - ptr); + var eh = FindExceptionHandlerByBranchTarget(intVal, finallyEndAddress, ehs); + if (eh != null) + { + ip = ptr + eh.HandlerStart; + continue; + } ip = ptr + finallyEndAddress; finallyEndAddress = 0; continue;