Skip to content

Commit e2419de

Browse files
authored
[interp] Add missing exception checkpoints (mono#6917)
On interp we can't async abort since we cannot unwind from an ip in the interp, so the interpreter does explicit checks as part of branch instructions. Note this can lead to increased stack usage when compiling with -O0.
1 parent cf64447 commit e2419de

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

mono/mini/interp/interp.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,13 +2794,9 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
27942794
g_warning ("ret.vt: more values on stack: %d", sp-frame->stack);
27952795
goto exit_frame;
27962796
MINT_IN_CASE(MINT_BR_S)
2797-
/* Checkpoint to be able to handle aborts */
2798-
EXCEPTION_CHECKPOINT;
27992797
ip += (short) *(ip + 1);
28002798
MINT_IN_BREAK;
28012799
MINT_IN_CASE(MINT_BR)
2802-
/* Checkpoint to be able to handle aborts */
2803-
EXCEPTION_CHECKPOINT;
28042800
ip += (gint32) READ32(ip + 1);
28052801
MINT_IN_BREAK;
28062802
#define ZEROP_S(datamem, op) \
@@ -3650,6 +3646,11 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, guint16 *st
36503646

36513647
THROW_EX ((MonoException *)sp->data.p, ip);
36523648
MINT_IN_BREAK;
3649+
MINT_IN_CASE(MINT_CHECKPOINT)
3650+
/* Do synchronous checking of abort requests */
3651+
EXCEPTION_CHECKPOINT;
3652+
++ip;
3653+
MINT_IN_BREAK;
36533654
MINT_IN_CASE(MINT_LDFLDA_UNSAFE)
36543655
o = sp [-1].data.p;
36553656
sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);

mono/mini/interp/mintops.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ OPDEF(MINT_THROW, "throw", 1, MintOpNoArgs)
179179
OPDEF(MINT_RETHROW, "rethrow", 2, MintOpUShortInt)
180180
OPDEF(MINT_ENDFINALLY, "endfinally", 2, MintOpNoArgs)
181181

182+
OPDEF(MINT_CHECKPOINT, "checkpoint", 1, MintOpNoArgs)
183+
182184
OPDEF(MINT_BRFALSE_I4, "brfalse.i4", 3, MintOpBranch)
183185
OPDEF(MINT_BRFALSE_I8, "brfalse.i8", 3, MintOpBranch)
184186
OPDEF(MINT_BRFALSE_R8, "brfalse.r8", 3, MintOpBranch)

mono/mini/interp/transform.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ handle_branch (TransformData *td, int short_op, int long_op, int offset)
313313
int target = td->ip + offset - td->il_code;
314314
if (target < 0 || target >= td->code_size)
315315
g_assert_not_reached ();
316+
/* Add exception checkpoint for backward branches */
317+
if (offset < 0)
318+
ADD_CODE(td, MINT_CHECKPOINT);
316319
if (offset > 0 && td->stack_height [target] < 0) {
317320
td->stack_height [target] = td->sp - td->stack;
318321
if (td->stack_height [target] > 0)

mono/tests/Makefile.am

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,6 @@ INTERP_DISABLED_TESTS = \
10211021
$(if $(CI),$(CI_DISABLED_TESTS)) \
10221022
$(if $(CI_PR),$(CI_PR_DISABLED_TESTS)) \
10231023
appdomain-unload.exe \
1024-
async-exc-compilation.exe \
10251024
async-with-cb-throws.exe \
10261025
block_guard_restore_aligment_on_exit.exe \
10271026
bug-335131.2.exe \

0 commit comments

Comments
 (0)