[arm64] Fix finally abort
authorVlad Brezae <brezaevlad@gmail.com>
Wed, 21 Dec 2016 01:29:49 +0000 (03:29 +0200)
committerVlad Brezae <brezaevlad@gmail.com>
Wed, 21 Dec 2016 01:40:16 +0000 (03:40 +0200)
A try finally set looks like :

try:
   ...
   call finally
E: exit try_block

finally:
   ...
   call E

If we get aborted in the finally block, instead of calling to E, we call to a handler block trampoline which will throw the exception using a context that has the ip at E (since we need to execute the finally block first). We need to make sure that E is not logically part of the try block, otherwise we will end up calling the finally block again when unwinding the stack.

mono/mini/mini-arm64.c

index 31b07e6faff2214f08dc0937648fabe8bf373099..200036dddd50f7a5c22bdd7e8181fca577fab4d6 100644 (file)
@@ -4300,6 +4300,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
                        mono_add_patch_info_rel (cfg, offset, MONO_PATCH_INFO_BB, ins->inst_target_bb, MONO_R_ARM64_BL);
                        arm_bl (code, 0);
                        cfg->thunk_area += THUNK_SIZE;
+                       mono_cfg_add_try_hole (cfg, ins->inst_eh_block, code, bb);
                        break;
                case OP_START_HANDLER: {
                        MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);