From df7f4749377ca5d25567d2cf0c404615c2d0faba Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Mon, 24 Jul 2017 23:42:45 +0300 Subject: [PATCH] [runtime] Remove handler block trampoline code --- mono/metadata/object-offsets.h | 1 - mono/mini/aot-compiler.c | 9 -- mono/mini/mini-amd64.c | 20 ----- mono/mini/mini-amd64.h | 5 -- mono/mini/mini-arm.c | 21 ----- mono/mini/mini-arm.h | 7 -- mono/mini/mini-arm64.c | 20 ----- mono/mini/mini-arm64.h | 6 -- mono/mini/mini-exceptions.c | 5 -- mono/mini/mini-ppc.c | 12 --- mono/mini/mini-ppc.h | 4 - mono/mini/mini-s390x.c | 33 ------- mono/mini/mini-s390x.h | 1 - mono/mini/mini-trampolines.c | 73 +--------------- mono/mini/mini-x86.c | 23 ----- mono/mini/mini-x86.h | 1 - mono/mini/mini.h | 12 +-- mono/mini/tramp-amd64.c | 153 +++++++-------------------------- mono/mini/tramp-arm.c | 70 --------------- mono/mini/tramp-arm64.c | 62 ------------- mono/mini/tramp-s390x.c | 64 +------------- mono/mini/tramp-x86.c | 70 +-------------- 22 files changed, 35 insertions(+), 637 deletions(-) diff --git a/mono/metadata/object-offsets.h b/mono/metadata/object-offsets.h index 375831531f6..9f2fa37e04e 100644 --- a/mono/metadata/object-offsets.h +++ b/mono/metadata/object-offsets.h @@ -158,7 +158,6 @@ DECL_OFFSET(MonoMethodRuntimeGenericContext, class_vtable) DECL_OFFSET(MonoJitTlsData, lmf) DECL_OFFSET(MonoJitTlsData, class_cast_from) DECL_OFFSET(MonoJitTlsData, class_cast_to) -DECL_OFFSET(MonoJitTlsData, handler_block_return_address) DECL_OFFSET(MonoJitTlsData, restore_stack_prot) DECL_OFFSET(MonoGSharedVtMethodRuntimeInfo, locals_size) diff --git a/mono/mini/aot-compiler.c b/mono/mini/aot-compiler.c index b9c86a44c89..c2dd1b28eeb 100644 --- a/mono/mini/aot-compiler.c +++ b/mono/mini/aot-compiler.c @@ -6741,10 +6741,6 @@ emit_trampolines (MonoAotCompile *acfg) #ifdef DISABLE_REMOTING if (tramp_type == MONO_TRAMPOLINE_GENERIC_VIRTUAL_REMOTING) continue; -#endif -#ifndef MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD - if (tramp_type == MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD) - continue; #endif mono_arch_create_generic_trampoline ((MonoTrampolineType)tramp_type, &info, acfg->aot_opts.use_trampolines_page? 2: TRUE); emit_trampoline (acfg, acfg->got_offset, info); @@ -6825,11 +6821,6 @@ emit_trampolines (MonoAotCompile *acfg) } } -#ifdef MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD_AOT - mono_arch_create_handler_block_trampoline (&info, TRUE); - emit_trampoline (acfg, acfg->got_offset, info); -#endif - if (mono_aot_mode_is_interp (&acfg->aot_opts)) { mono_arch_get_enter_icall_trampoline (&info); emit_trampoline (acfg, acfg->got_offset, info); diff --git a/mono/mini/mini-amd64.c b/mono/mini/mini-amd64.c index bab77635fde..5a376b89450 100644 --- a/mono/mini/mini-amd64.c +++ b/mono/mini/mini-amd64.c @@ -1168,7 +1168,6 @@ mono_arch_init (void) mono_aot_register_jit_icall ("mono_amd64_throw_corlib_exception", mono_amd64_throw_corlib_exception); mono_aot_register_jit_icall ("mono_amd64_resume_unwind", mono_amd64_resume_unwind); mono_aot_register_jit_icall ("mono_amd64_get_original_ip", mono_amd64_get_original_ip); - mono_aot_register_jit_icall ("mono_amd64_handler_block_trampoline_helper", mono_amd64_handler_block_trampoline_helper); #if defined(MONO_ARCH_GSHAREDVT_SUPPORTED) mono_aot_register_jit_icall ("mono_amd64_start_gsharedvt_call", mono_amd64_start_gsharedvt_call); @@ -8132,25 +8131,6 @@ mono_arch_context_set_int_reg (MonoContext *ctx, int reg, mgreg_t val) ctx->gregs [reg] = val; } -gpointer -mono_arch_install_handler_block_guard (MonoJitInfo *ji, MonoJitExceptionInfo *clause, MonoContext *ctx, gpointer new_value) -{ - gpointer *sp, old_value; - char *bp; - - /*Load the spvar*/ - bp = (char *)MONO_CONTEXT_GET_BP (ctx); - sp = (gpointer *)*(gpointer*)(bp + clause->exvar_offset); - - old_value = *sp; - if (old_value < ji->code_start || (char*)old_value > ((char*)ji->code_start + ji->code_size)) - return old_value; - - *sp = new_value; - - return old_value; -} - /* * mono_arch_emit_load_aotconst: * diff --git a/mono/mini/mini-amd64.h b/mono/mini/mini-amd64.h index d568af78db8..b6885020606 100644 --- a/mono/mini/mini-amd64.h +++ b/mono/mini/mini-amd64.h @@ -431,8 +431,6 @@ typedef struct { #define MONO_ARCH_DYN_CALL_PARAM_AREA (DYN_CALL_STACK_ARGS * 8) #define MONO_ARCH_LLVM_SUPPORTED 1 -#define MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD 1 -#define MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD_AOT 1 #define MONO_ARCH_HAVE_CARD_TABLE_WBARRIER 1 #define MONO_ARCH_HAVE_SETUP_RESUME_FROM_SIGNAL_HANDLER_CTX 1 #define MONO_ARCH_GC_MAPS_SUPPORTED 1 @@ -503,9 +501,6 @@ mono_amd64_get_exception_trampolines (gboolean aot); int mono_amd64_get_tls_gs_offset (void) MONO_LLVM_INTERNAL; -gpointer -mono_amd64_handler_block_trampoline_helper (void); - #if defined(TARGET_WIN32) && !defined(DISABLE_JIT) #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) diff --git a/mono/mini/mini-arm.c b/mono/mini/mini-arm.c index 9703c1e09de..e61e7b00c71 100644 --- a/mono/mini/mini-arm.c +++ b/mono/mini/mini-arm.c @@ -799,7 +799,6 @@ mono_arch_init (void) mono_aot_register_jit_icall ("mono_arm_start_gsharedvt_call", mono_arm_start_gsharedvt_call); #endif mono_aot_register_jit_icall ("mono_arm_unaligned_stack", mono_arm_unaligned_stack); - mono_aot_register_jit_icall ("mono_arm_handler_block_trampoline_helper", mono_arm_handler_block_trampoline_helper); #if defined(__ARM_EABI__) eabi_supported = TRUE; #endif @@ -7082,26 +7081,6 @@ mono_arch_get_trampolines (gboolean aot) return mono_arm_get_exception_trampolines (aot); } -gpointer -mono_arch_install_handler_block_guard (MonoJitInfo *ji, MonoJitExceptionInfo *clause, MonoContext *ctx, gpointer new_value) -{ - gpointer *lr_loc; - char *old_value; - char *bp; - - /*Load the spvar*/ - bp = MONO_CONTEXT_GET_BP (ctx); - lr_loc = (gpointer*)(bp + clause->exvar_offset); - - old_value = *lr_loc; - if ((char*)old_value < (char*)ji->code_start || (char*)old_value > ((char*)ji->code_start + ji->code_size)) - return old_value; - - *lr_loc = new_value; - - return old_value; -} - #if defined(MONO_ARCH_SOFT_DEBUG_SUPPORTED) /* * mono_arch_set_breakpoint: diff --git a/mono/mini/mini-arm.h b/mono/mini/mini-arm.h index 2e8914c395c..633c16f306b 100644 --- a/mono/mini/mini-arm.h +++ b/mono/mini/mini-arm.h @@ -340,10 +340,6 @@ typedef struct MonoCompileArch { #define MONO_ARCH_GC_MAPS_SUPPORTED 1 #define MONO_ARCH_HAVE_SETUP_ASYNC_CALLBACK 1 #define MONO_ARCH_HAVE_CONTEXT_SET_INT_REG 1 -#define MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD 1 -#ifndef TARGET_IOS -#define MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD_AOT 1 -#endif #define MONO_ARCH_HAVE_SETUP_RESUME_FROM_SIGNAL_HANDLER_CTX 1 #define MONO_ARCH_GSHAREDVT_SUPPORTED 1 #define MONO_ARCH_HAVE_GENERAL_RGCTX_LAZY_FETCH_TRAMPOLINE 1 @@ -414,9 +410,6 @@ mono_arm_is_hard_float (void); void mono_arm_unaligned_stack (MonoMethod *method); -gpointer -mono_arm_handler_block_trampoline_helper (gpointer *ptr); - /* MonoJumpInfo **ji */ guint8* mono_arm_emit_aotconst (gpointer ji, guint8 *code, guint8 *buf, int dreg, int patch_type, gconstpointer data); diff --git a/mono/mini/mini-arm64.c b/mono/mini/mini-arm64.c index 7a189792a2c..aacdd599afc 100644 --- a/mono/mini/mini-arm64.c +++ b/mono/mini/mini-arm64.c @@ -234,7 +234,6 @@ mono_arch_init (void) { mono_aot_register_jit_icall ("mono_arm_throw_exception", mono_arm_throw_exception); mono_aot_register_jit_icall ("mono_arm_resume_unwind", mono_arm_resume_unwind); - mono_aot_register_jit_icall ("mono_arm_handler_block_trampoline_helper", mono_arm_handler_block_trampoline_helper); if (!mono_aot_only) bp_trampoline = mini_get_breakpoint_trampoline (); @@ -5241,22 +5240,3 @@ mono_arch_get_call_info (MonoMemPool *mp, MonoMethodSignature *sig) return get_call_info (mp, sig); } -gpointer -mono_arch_install_handler_block_guard (MonoJitInfo *ji, MonoJitExceptionInfo *clause, MonoContext *ctx, gpointer new_value) -{ - gpointer *lr_loc; - char *old_value; - char *bp; - - /*Load the spvar*/ - bp = MONO_CONTEXT_GET_BP (ctx); - lr_loc = (gpointer*)(bp + clause->exvar_offset); - - old_value = *lr_loc; - if ((char*)old_value < (char*)ji->code_start || (char*)old_value > ((char*)ji->code_start + ji->code_size)) - return old_value; - - *lr_loc = new_value; - - return old_value; -} diff --git a/mono/mini/mini-arm64.h b/mono/mini/mini-arm64.h index c7cd1fb1262..6268a1064de 100644 --- a/mono/mini/mini-arm64.h +++ b/mono/mini/mini-arm64.h @@ -154,11 +154,7 @@ typedef struct { #define MONO_ARCH_HAVE_OP_GENERIC_CLASS_INIT 1 #define MONO_ARCH_HAVE_OPCODE_NEEDS_EMULATION 1 #define MONO_ARCH_HAVE_DECOMPOSE_LONG_OPTS 1 -#define MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD 1 #define MONO_ARCH_HAVE_INIT_LMF_EXT 1 -#ifndef TARGET_IOS -#define MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD_AOT 1 -#endif #ifdef TARGET_IOS @@ -260,8 +256,6 @@ GSList* mono_arm_get_exception_trampolines (gboolean aot); void mono_arm_resume_unwind (gpointer arg, mgreg_t pc, mgreg_t *int_regs, gdouble *fp_regs, gboolean corlib, gboolean rethrow); -gpointer mono_arm_handler_block_trampoline_helper (gpointer *ptr); - CallInfo* mono_arch_get_call_info (MonoMemPool *mp, MonoMethodSignature *sig); #endif /* __MONO_MINI_ARM64_H__ */ diff --git a/mono/mini/mini-exceptions.c b/mono/mini/mini-exceptions.c index d73c4c8e462..c8a71c69378 100644 --- a/mono/mini/mini-exceptions.c +++ b/mono/mini/mini-exceptions.c @@ -2963,11 +2963,6 @@ mono_install_handler_block_guard (MonoThreadUnwindState *ctx) FindHandlerBlockData data = { 0 }; MonoJitTlsData *jit_tls = (MonoJitTlsData *)ctx->unwind_data [MONO_UNWIND_DATA_JIT_TLS]; -#ifndef MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD_AOT - if (mono_aot_only) - return FALSE; -#endif - /* Guard against a null MonoJitTlsData. This can happens if the thread receives the * interrupt signal before the JIT has time to initialize its TLS data for the given thread. */ diff --git a/mono/mini/mini-ppc.c b/mono/mini/mini-ppc.c index f36a3fd528a..59fa9edc03e 100644 --- a/mono/mini/mini-ppc.c +++ b/mono/mini/mini-ppc.c @@ -6017,15 +6017,3 @@ mono_arch_opcode_supported (int opcode) } } - -#if 0 -// FIXME: To get the test case finally_block_ending_in_dead_bb to work properly we need to define the following -// (in mini-ppc.h) and then implement the fuction mono_arch_create_handler_block_trampoline. -// #define MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD 1 - -gpointer -mono_arch_create_handler_block_trampoline (void) -{ - . . . -} -#endif diff --git a/mono/mini/mini-ppc.h b/mono/mini/mini-ppc.h index 718bb98d6fa..3f241f6db31 100644 --- a/mono/mini/mini-ppc.h +++ b/mono/mini/mini-ppc.h @@ -160,10 +160,6 @@ typedef struct MonoCompileArch { #define MONO_ARCH_HAVE_DECOMPOSE_VTYPE_OPTS 1 #define MONO_ARCH_RETURN_CAN_USE_MULTIPLE_REGISTERS 1 -// FIXME: To get the test case finally_block_ending_in_dead_bb to work properly define the following -// and then implement the fuction mono_arch_create_handler_block_trampoline. -// #define MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD 1 - // Define "DEBUG_ELFABIV2" to allow for debugging output for ELF ABI v2 function call and return codegen // #define DEBUG_ELFABIV2 diff --git a/mono/mini/mini-s390x.c b/mono/mini/mini-s390x.c index bab41317cc6..7f726bfaadb 100644 --- a/mono/mini/mini-s390x.c +++ b/mono/mini/mini-s390x.c @@ -6413,39 +6413,6 @@ mono_arch_get_this_arg_from_call (mgreg_t *regs, guint8 *code) /*========================= End of Function ========================*/ -/*------------------------------------------------------------------*/ -/* */ -/* Name - mono_arch_install_handler_block_guard */ -/* */ -/* Function - */ -/* */ -/*------------------------------------------------------------------*/ - -gpointer -mono_arch_install_handler_block_guard (MonoJitInfo *ji, MonoJitExceptionInfo *clause, - MonoContext *ctx, gpointer new_value) -{ - int offset; - gpointer *sp, old_value; - char *bp; - - offset = clause->exvar_offset; - - /*Load the spvar*/ - bp = MONO_CONTEXT_GET_BP (ctx); - sp = *(gpointer*)(bp + offset); - - old_value = *sp; - if (old_value < ji->code_start || (char*)old_value > ((char*)ji->code_start + ji->code_size)) - return old_value; - - *sp = new_value; - - return old_value; -} - -/*========================= End of Function ========================*/ - /*------------------------------------------------------------------*/ /* */ /* Name - get_delegate_invoke_impl. */ diff --git a/mono/mini/mini-s390x.h b/mono/mini/mini-s390x.h index 9747be08ce7..01dcfd997a9 100644 --- a/mono/mini/mini-s390x.h +++ b/mono/mini/mini-s390x.h @@ -61,7 +61,6 @@ typedef struct #define MONO_ARCH_GC_MAPS_SUPPORTED 1 #define MONO_ARCH_GSHARED_SUPPORTED 1 #define MONO_ARCH_MONITOR_ENTER_ADJUSTMENT 1 -#define MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD 1 #define MONO_ARCH_HAVE_INVALIDATE_METHOD 1 #define MONO_ARCH_HAVE_OP_GENERIC_CLASS_INIT 1 #define MONO_ARCH_HAVE_SETUP_ASYNC_CALLBACK 1 diff --git a/mono/mini/mini-trampolines.c b/mono/mini/mini-trampolines.c index 3ef30208cf7..c78abccad63 100644 --- a/mono/mini/mini-trampolines.c +++ b/mono/mini/mini-trampolines.c @@ -1273,68 +1273,6 @@ mono_delegate_trampoline (mgreg_t *regs, guint8 *code, gpointer *arg, guint8* tr return code; } -#ifdef MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD -static gpointer -mono_handler_block_guard_trampoline (mgreg_t *regs, guint8 *code, gpointer *tramp_info, guint8* tramp) -{ - MONO_REQ_GC_UNSAFE_MODE; - - MonoContext ctx; - MonoException *exc; - MonoJitTlsData *jit_tls = (MonoJitTlsData *)mono_tls_get_jit_tls (); - gpointer resume_ip = jit_tls->handler_block_return_address; - - memcpy (&ctx, &jit_tls->handler_block_context, sizeof (MonoContext)); - MONO_CONTEXT_SET_IP (&ctx, jit_tls->handler_block_return_address); - - jit_tls->handler_block_return_address = NULL; - jit_tls->handler_block = NULL; - - if (!resume_ip) /*this should not happen, but we should avoid crashing */ - exc = mono_get_exception_execution_engine ("Invalid internal state, resuming abort after handler block but no resume ip found"); - else - exc = mono_thread_resume_interruption (TRUE); - - if (exc) { - mono_handle_exception (&ctx, (MonoObject *)exc); - mono_restore_context (&ctx); - } - - return resume_ip; -} - -gpointer -mono_create_handler_block_trampoline (void) -{ - static gpointer code; - - if (code) - return code; - - if (mono_aot_only) { - gpointer tmp = mono_aot_get_trampoline ("handler_block_trampoline"); - g_assert (tmp); - mono_memory_barrier (); - code = tmp; - return code; - } - - mono_trampolines_lock (); - if (!code) { - MonoTrampInfo *info; - gpointer tmp; - - tmp = mono_arch_create_handler_block_trampoline (&info, FALSE); - mono_tramp_info_register (info, NULL); - mono_memory_barrier (); - code = tmp; - } - mono_trampolines_unlock (); - - return code; -} -#endif - /* * mono_get_trampoline_func: * @@ -1366,10 +1304,6 @@ mono_get_trampoline_func (MonoTrampolineType tramp_type) #endif case MONO_TRAMPOLINE_VCALL: return mono_vcall_trampoline; -#ifdef MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD - case MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD: - return mono_handler_block_guard_trampoline; -#endif default: g_assert_not_reached (); return NULL; @@ -1409,10 +1343,6 @@ mono_trampolines_init (void) mono_trampoline_code [MONO_TRAMPOLINE_GENERIC_VIRTUAL_REMOTING] = create_trampoline_code (MONO_TRAMPOLINE_GENERIC_VIRTUAL_REMOTING); #endif mono_trampoline_code [MONO_TRAMPOLINE_VCALL] = create_trampoline_code (MONO_TRAMPOLINE_VCALL); -#ifdef MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD - mono_trampoline_code [MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD] = create_trampoline_code (MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD); - mono_create_handler_block_trampoline (); -#endif mono_counters_register ("Calls to trampolines", MONO_COUNTER_JIT | MONO_COUNTER_INT, &trampoline_calls); mono_counters_register ("JIT trampolines", MONO_COUNTER_JIT | MONO_COUNTER_INT, &jit_trampolines); @@ -1740,8 +1670,7 @@ static const char*tramp_names [MONO_TRAMPOLINE_NUM] = { "delegate", "restore_stack_prot", "generic_virtual_remoting", - "vcall", - "handler_block_guard" + "vcall" }; /* diff --git a/mono/mini/mini-x86.c b/mono/mini/mini-x86.c index ad1637319c8..54966b1dc8f 100644 --- a/mono/mini/mini-x86.c +++ b/mono/mini/mini-x86.c @@ -6294,29 +6294,6 @@ mono_arch_decompose_long_opts (MonoCompile *cfg, MonoInst *long_ins) #endif /* MONO_ARCH_SIMD_INTRINSICS */ } -/*MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD*/ -gpointer -mono_arch_install_handler_block_guard (MonoJitInfo *ji, MonoJitExceptionInfo *clause, MonoContext *ctx, gpointer new_value) -{ - int offset; - gpointer *sp, old_value; - char *bp; - - offset = clause->exvar_offset; - - /*Load the spvar*/ - bp = MONO_CONTEXT_GET_BP (ctx); - sp = *(gpointer*)(bp + offset); - - old_value = *sp; - if (old_value < ji->code_start || (char*)old_value > ((char*)ji->code_start + ji->code_size)) - return old_value; - - *sp = new_value; - - return old_value; -} - /* * mono_aot_emit_load_got_addr: * diff --git a/mono/mini/mini-x86.h b/mono/mini/mini-x86.h index a3d0a600003..180e6cc967c 100644 --- a/mono/mini/mini-x86.h +++ b/mono/mini/mini-x86.h @@ -224,7 +224,6 @@ typedef struct { #define MONO_ARCH_SOFT_DEBUG_SUPPORTED 1 #define MONO_ARCH_HAVE_EXCEPTIONS_INIT 1 -#define MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD 1 #define MONO_ARCH_HAVE_CARD_TABLE_WBARRIER 1 #define MONO_ARCH_HAVE_SETUP_RESUME_FROM_SIGNAL_HANDLER_CTX 1 diff --git a/mono/mini/mini.h b/mono/mini/mini.h index 348c4a5e958..a8bd6f70221 100644 --- a/mono/mini/mini.h +++ b/mono/mini/mini.h @@ -1170,10 +1170,6 @@ typedef struct { MonoContext ex_ctx; ResumeState resume_state; - /*Variabled use to implement handler blocks (finally/catch/etc) guards during interruption*/ - /* handler block return address */ - gpointer handler_block_return_address; - /* handler block been guarded. It's safe to store this even for dynamic methods since there is an activation on stack making sure it will remain alive.*/ MonoJitExceptionInfo *handler_block; @@ -1489,7 +1485,6 @@ typedef enum { MONO_TRAMPOLINE_RESTORE_STACK_PROT, MONO_TRAMPOLINE_GENERIC_VIRTUAL_REMOTING, MONO_TRAMPOLINE_VCALL, - MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD, MONO_TRAMPOLINE_NUM } MonoTrampolineType; @@ -1500,7 +1495,7 @@ typedef enum { /* These trampolines receive an argument directly in a register */ #define MONO_TRAMPOLINE_TYPE_HAS_ARG(t) \ - ((t) == MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD) + (FALSE) /* optimization flags */ #define OPTFLAG(id,shift,name,descr) MONO_OPT_ ## id = 1 << shift, @@ -2864,11 +2859,6 @@ guint32 mono_arch_get_plt_info_offset (guint8 *plt_entry, mgreg_t *reg GSList *mono_arch_get_trampolines (gboolean aot); gpointer mono_arch_get_enter_icall_trampoline (MonoTrampInfo **info); -/* Handle block guard */ -gpointer mono_arch_install_handler_block_guard (MonoJitInfo *ji, MonoJitExceptionInfo *clause, MonoContext *ctx, gpointer new_value); -gpointer mono_arch_create_handler_block_trampoline (MonoTrampInfo **info, gboolean aot); -gpointer mono_create_handler_block_trampoline (void); - /*New interruption machinery */ void mono_setup_async_callback (MonoContext *ctx, void (*async_cb)(void *fun), gpointer user_data); diff --git a/mono/mini/tramp-amd64.c b/mono/mini/tramp-amd64.c index cf519e1c929..53e3bc2e834 100644 --- a/mono/mini/tramp-amd64.c +++ b/mono/mini/tramp-amd64.c @@ -239,7 +239,7 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf MonoJumpInfo *ji = NULL; const guint kMaxCodeSize = 630; - if (tramp_type == MONO_TRAMPOLINE_JUMP || tramp_type == MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD) + if (tramp_type == MONO_TRAMPOLINE_JUMP) has_caller = FALSE; else has_caller = TRUE; @@ -379,43 +379,38 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf mono_amd64_patch (br [0], code); //amd64_breakpoint (code); - if (tramp_type != MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD) { - /* Obtain the trampoline argument which is encoded in the instruction stream */ - if (aot) { - /* Load the GOT offset */ - amd64_mov_reg_membase (code, AMD64_R11, AMD64_RBP, tramp_offset, sizeof(gpointer)); - /* - * r11 points to a call *(%rip) instruction, load the - * pc-relative offset from the instruction itself. - */ - amd64_mov_reg_membase (code, AMD64_RAX, AMD64_R11, 3, 4); - /* 7 is the length of the call, 8 is the offset to the next got slot */ - amd64_alu_reg_imm_size (code, X86_ADD, AMD64_RAX, 7 + sizeof (gpointer), sizeof(gpointer)); - /* Compute the address of the GOT slot */ - amd64_alu_reg_reg_size (code, X86_ADD, AMD64_R11, AMD64_RAX, sizeof(gpointer)); - /* Load the value */ - amd64_mov_reg_membase (code, AMD64_R11, AMD64_R11, 0, sizeof(gpointer)); - } else { - amd64_mov_reg_membase (code, AMD64_R11, AMD64_RBP, tramp_offset, sizeof(gpointer)); - amd64_mov_reg_membase (code, AMD64_RAX, AMD64_R11, 5, 1); - amd64_widen_reg (code, AMD64_RAX, AMD64_RAX, TRUE, FALSE); - amd64_alu_reg_imm_size (code, X86_CMP, AMD64_RAX, 4, 1); - br [0] = code; - x86_branch8 (code, X86_CC_NE, 6, FALSE); - /* 32 bit immediate */ - amd64_mov_reg_membase (code, AMD64_R11, AMD64_R11, 6, 4); - br [1] = code; - x86_jump8 (code, 10); - /* 64 bit immediate */ - mono_amd64_patch (br [0], code); - amd64_mov_reg_membase (code, AMD64_R11, AMD64_R11, 6, 8); - mono_amd64_patch (br [1], code); - } - amd64_mov_membase_reg (code, AMD64_RBP, arg_offset, AMD64_R11, sizeof(gpointer)); + /* Obtain the trampoline argument which is encoded in the instruction stream */ + if (aot) { + /* Load the GOT offset */ + amd64_mov_reg_membase (code, AMD64_R11, AMD64_RBP, tramp_offset, sizeof(gpointer)); + /* + * r11 points to a call *(%rip) instruction, load the + * pc-relative offset from the instruction itself. + */ + amd64_mov_reg_membase (code, AMD64_RAX, AMD64_R11, 3, 4); + /* 7 is the length of the call, 8 is the offset to the next got slot */ + amd64_alu_reg_imm_size (code, X86_ADD, AMD64_RAX, 7 + sizeof (gpointer), sizeof(gpointer)); + /* Compute the address of the GOT slot */ + amd64_alu_reg_reg_size (code, X86_ADD, AMD64_R11, AMD64_RAX, sizeof(gpointer)); + /* Load the value */ + amd64_mov_reg_membase (code, AMD64_R11, AMD64_R11, 0, sizeof(gpointer)); } else { - amd64_mov_reg_membase (code, AMD64_R11, AMD64_RBP, saved_regs_offset + (MONO_AMD64_ARG_REG1 * sizeof(mgreg_t)), sizeof(mgreg_t)); - amd64_mov_membase_reg (code, AMD64_RBP, arg_offset, AMD64_R11, sizeof(gpointer)); + amd64_mov_reg_membase (code, AMD64_R11, AMD64_RBP, tramp_offset, sizeof(gpointer)); + amd64_mov_reg_membase (code, AMD64_RAX, AMD64_R11, 5, 1); + amd64_widen_reg (code, AMD64_RAX, AMD64_RAX, TRUE, FALSE); + amd64_alu_reg_imm_size (code, X86_CMP, AMD64_RAX, 4, 1); + br [0] = code; + x86_branch8 (code, X86_CC_NE, 6, FALSE); + /* 32 bit immediate */ + amd64_mov_reg_membase (code, AMD64_R11, AMD64_R11, 6, 4); + br [1] = code; + x86_jump8 (code, 10); + /* 64 bit immediate */ + mono_amd64_patch (br [0], code); + amd64_mov_reg_membase (code, AMD64_R11, AMD64_R11, 6, 8); + mono_amd64_patch (br [1], code); } + amd64_mov_membase_reg (code, AMD64_RBP, arg_offset, AMD64_R11, sizeof(gpointer)); /* Save LMF begin */ @@ -786,85 +781,6 @@ mono_arch_invalidate_method (MonoJitInfo *ji, void *func, gpointer func_arg) } #endif /* !DISABLE_JIT */ -gpointer -mono_amd64_handler_block_trampoline_helper (void) -{ - MonoJitTlsData *jit_tls = (MonoJitTlsData *)mono_tls_get_jit_tls (); - return jit_tls->handler_block_return_address; -} - -#ifndef DISABLE_JIT -gpointer -mono_arch_create_handler_block_trampoline (MonoTrampInfo **info, gboolean aot) -{ - guint8 *code, *buf; - int tramp_size = 64; - MonoJumpInfo *ji = NULL; - GSList *unwind_ops; - - code = buf = (guint8 *)mono_global_codeman_reserve (tramp_size + MONO_TRAMPOLINE_UNWINDINFO_SIZE(0)); - - unwind_ops = mono_arch_get_cie_program (); - - /* - * This trampoline restore the call chain of the handler block then jumps into the code that deals with it. - * We get here from the ret emitted by CEE_ENDFINALLY. - * The stack is misaligned. - */ - /* Align the stack before the call to mono_amd64_handler_block_trampoline_helper() */ -#ifdef TARGET_WIN32 - /* Also make room for the "register parameter stack area" as specified by the Windows x64 ABI (4 64-bit registers) */ - amd64_alu_reg_imm (code, X86_SUB, AMD64_RSP, 8 + 4 * 8); -#else - amd64_alu_reg_imm (code, X86_SUB, AMD64_RSP, 8); -#endif - if (aot) { - code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "mono_amd64_handler_block_trampoline_helper"); - amd64_call_reg (code, AMD64_R11); - } else { - amd64_mov_reg_imm (code, AMD64_RAX, mono_amd64_handler_block_trampoline_helper); - amd64_call_reg (code, AMD64_RAX); - } - /* Undo stack alignment */ -#ifdef TARGET_WIN32 - amd64_alu_reg_imm (code, X86_ADD, AMD64_RSP, 8 + 4 * 8); -#else - amd64_alu_reg_imm (code, X86_ADD, AMD64_RSP, 8); -#endif - /* Save the result to the stack */ - amd64_push_reg (code, AMD64_RAX); -#ifdef TARGET_WIN32 - /* Make room for the "register parameter stack area" as specified by the Windows x64 ABI (4 64-bit registers) */ - amd64_alu_reg_imm (code, X86_SUB, AMD64_RSP, 4 * 8); -#endif - if (aot) { - char *name = g_strdup_printf ("trampoline_func_%d", MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD); - code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, name); - amd64_mov_reg_reg (code, AMD64_RAX, AMD64_R11, 8); - } else { - amd64_mov_reg_imm (code, AMD64_RAX, mono_get_trampoline_func (MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD)); - } - /* The stack is aligned */ - amd64_call_reg (code, AMD64_RAX); -#ifdef TARGET_WIN32 - amd64_alu_reg_imm (code, X86_ADD, AMD64_RSP, 4 * 8); -#endif - /* Load return address */ - amd64_pop_reg (code, AMD64_RAX); - /* The stack is misaligned, thats what the code we branch to expects */ - amd64_jump_reg (code, AMD64_RAX); - - mono_arch_flush_icache (buf, code - buf); - MONO_PROFILER_RAISE (jit_code_buffer, (buf, code - buf, MONO_PROFILER_CODE_BUFFER_HELPER, NULL)); - g_assert (code - buf <= tramp_size); - g_assert_checked (mono_arch_unwindinfo_validate_size (unwind_ops, MONO_TRAMPOLINE_UNWINDINFO_SIZE(0))); - - *info = mono_tramp_info_create ("handler_block_trampoline", buf, code - buf, ji, unwind_ops); - - return buf; -} -#endif /* !DISABLE_JIT */ - /* * mono_arch_get_call_target: * @@ -1207,13 +1123,6 @@ mono_arch_create_general_rgctx_lazy_fetch_trampoline (MonoTrampInfo **info, gboo return NULL; } -gpointer -mono_arch_create_handler_block_trampoline (MonoTrampInfo **info, gboolean aot) -{ - g_assert_not_reached (); - return NULL; -} - void mono_arch_invalidate_method (MonoJitInfo *ji, void *func, gpointer func_arg) { diff --git a/mono/mini/tramp-arm.c b/mono/mini/tramp-arm.c index 935a2ee6882..bf2c9c91447 100644 --- a/mono/mini/tramp-arm.c +++ b/mono/mini/tramp-arm.c @@ -89,13 +89,6 @@ mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *a *(guint8**)jump_entry = addr; } -gpointer -mono_arm_handler_block_trampoline_helper (gpointer *ptr) -{ - MonoJitTlsData *jit_tls = mono_tls_get_jit_tls (); - return jit_tls->handler_block_return_address; -} - #ifndef DISABLE_JIT #define arm_is_imm12(v) ((int)(v) > -4096 && (int)(v) < 4096) @@ -692,62 +685,6 @@ mono_arch_create_general_rgctx_lazy_fetch_trampoline (MonoTrampInfo **info, gboo return buf; } -gpointer -mono_arch_create_handler_block_trampoline (MonoTrampInfo **info, gboolean aot) -{ - guint8 *tramp; - guint8 *code, *buf; - int tramp_size = 64; - MonoJumpInfo *ji = NULL; - GSList *unwind_ops = NULL; - - code = buf = mono_global_codeman_reserve (tramp_size); - - unwind_ops = mono_arch_get_cie_program (); - - tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD, NULL, NULL); - - /* - This trampoline restore the call chain of the handler block then jumps into the code that deals with it. - */ - - /* - * We are in a method frame after the call emitted by OP_CALL_HANDLER. - */ - /* Obtain jit_tls->handler_block_return_address */ - if (aot) { - code = mono_arm_emit_aotconst (&ji, code, buf, ARMREG_R0, MONO_PATCH_INFO_JIT_ICALL_ADDR, "mono_arm_handler_block_trampoline_helper"); - } else { - ARM_LDR_IMM (code, ARMREG_R0, ARMREG_PC, 0); - ARM_B (code, 0); - *(gpointer*)code = mono_arm_handler_block_trampoline_helper; - code += 4; - } - ARM_BLX_REG (code, ARMREG_R0); - /* Set it as the return address so the trampoline will return to it */ - ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_R0); - - /* Call the trampoline */ - if (aot) { - char *name = g_strdup_printf ("trampoline_func_%d", MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD); - code = mono_arm_emit_aotconst (&ji, code, buf, ARMREG_R0, MONO_PATCH_INFO_JIT_ICALL_ADDR, name); - code = emit_bx (code, ARMREG_R0); - } else { - ARM_LDR_IMM (code, ARMREG_R0, ARMREG_PC, 0); - code = emit_bx (code, ARMREG_R0); - *(gpointer*)code = tramp; - code += 4; - } - - mono_arch_flush_icache (buf, code - buf); - MONO_PROFILER_RAISE (jit_code_buffer, (buf, code - buf, MONO_PROFILER_CODE_BUFFER_HELPER, NULL)); - g_assert (code - buf <= tramp_size); - - *info = mono_tramp_info_create ("handler_block_trampoline", buf, code - buf, ji, unwind_ops); - - return buf; -} - guint8* mono_arch_create_sdb_trampoline (gboolean single_step, MonoTrampInfo **info, gboolean aot) { @@ -1028,13 +965,6 @@ mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info return NULL; } -gpointer -mono_arch_create_handler_block_trampoline (MonoTrampInfo **info, gboolean aot) -{ - g_assert_not_reached (); - return NULL; -} - guint8* mono_arch_create_sdb_trampoline (gboolean single_step, MonoTrampInfo **info, gboolean aot) { diff --git a/mono/mini/tramp-arm64.c b/mono/mini/tramp-arm64.c index be10117bbe7..a09fed858fe 100644 --- a/mono/mini/tramp-arm64.c +++ b/mono/mini/tramp-arm64.c @@ -97,13 +97,6 @@ mono_arch_get_plt_info_offset (guint8 *plt_entry, mgreg_t *regs, guint8 *code) return ((guint32*)plt_entry) [4]; } -gpointer -mono_arm_handler_block_trampoline_helper (gpointer *ptr) -{ - MonoJitTlsData *jit_tls = mono_tls_get_jit_tls (); - return jit_tls->handler_block_return_address; -} - #ifndef DISABLE_JIT guchar* @@ -519,54 +512,6 @@ mono_arch_create_general_rgctx_lazy_fetch_trampoline (MonoTrampInfo **info, gboo return buf; } -gpointer -mono_arch_create_handler_block_trampoline (MonoTrampInfo **info, gboolean aot) -{ - guint8 *tramp; - guint8 *code, *buf; - int tramp_size = 64; - MonoJumpInfo *ji = NULL; - GSList *unwind_ops = NULL; - - code = buf = mono_global_codeman_reserve (tramp_size); - - unwind_ops = NULL; - - /* - This trampoline restore the call chain of the handler block then jumps into the code that deals with it. - */ - - /* - * We are in a method frame after the call emitted by OP_CALL_HANDLER. - */ - /* Call a helper to obtain jit_tls->handler_block_return_address */ - if (aot) - code = mono_arm_emit_aotconst (&ji, code, buf, ARMREG_IP0, MONO_PATCH_INFO_JIT_ICALL_ADDR, "mono_arm_handler_block_trampoline_helper"); - else - code = mono_arm_emit_imm64 (code, ARMREG_IP0, (guint64)mono_arm_handler_block_trampoline_helper); - arm_blrx (code, ARMREG_IP0); - /* Set it as the return address so the trampoline will return to it */ - arm_movx (code, ARMREG_LR, ARMREG_R0); - - /* Call the C trampoline function */ - if (aot) { - char *name = g_strdup_printf ("trampoline_func_%d", MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD); - code = mono_arm_emit_aotconst (&ji, code, buf, ARMREG_IP0, MONO_PATCH_INFO_JIT_ICALL_ADDR, name); - } else { - tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD, NULL, NULL); - code = mono_arm_emit_imm64 (code, ARMREG_IP0, (guint64)tramp); - } - arm_brx (code, ARMREG_IP0); - - mono_arch_flush_icache (buf, code - buf); - MONO_PROFILER_RAISE (jit_code_buffer, (buf, code - buf, MONO_PROFILER_CODE_BUFFER_HELPER, NULL)); - g_assert (code - buf <= tramp_size); - - *info = mono_tramp_info_create ("handler_block_trampoline", buf, code - buf, ji, unwind_ops); - - return buf; -} - /* * mono_arch_create_sdb_trampoline: * @@ -836,13 +781,6 @@ mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_ty return NULL; } -gpointer -mono_arch_create_handler_block_trampoline (MonoTrampInfo **info, gboolean aot) -{ - g_assert_not_reached (); - return NULL; -} - gpointer mono_arch_get_unbox_trampoline (MonoMethod *m, gpointer addr) { diff --git a/mono/mini/tramp-s390x.c b/mono/mini/tramp-s390x.c index b0333d3cf18..91aed0b96e2 100644 --- a/mono/mini/tramp-s390x.c +++ b/mono/mini/tramp-s390x.c @@ -190,8 +190,7 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf code = buf = mono_global_codeman_reserve(512); - if ((tramp_type == MONO_TRAMPOLINE_JUMP) || - (tramp_type == MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD)) + if (tramp_type == MONO_TRAMPOLINE_JUMP) has_caller = 0; else has_caller = 1; @@ -587,64 +586,3 @@ mono_arch_get_static_rgctx_trampoline (gpointer arg, } /*========================= End of Function ========================*/ - -/*------------------------------------------------------------------*/ -/* */ -/* Name - handler_block_trampoline_helper */ -/* */ -/* Function - */ -/* */ -/*------------------------------------------------------------------*/ - -static void -handler_block_trampoline_helper (gpointer *ptr) -{ - MonoJitTlsData *jit_tls = mono_tls_get_jit_tls (); - *ptr = jit_tls->handler_block_return_address; -} - -/*========================= End of Function ========================*/ - -/*------------------------------------------------------------------*/ -/* */ -/* Name - mono_arch_create_handler_block_trampoline */ -/* */ -/* Function - */ -/* */ -/*------------------------------------------------------------------*/ - -gpointer -mono_arch_create_handler_block_trampoline (MonoTrampInfo **info, gboolean aot) -{ - guint8 *tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD); - guint8 *code, *buf; - int tramp_size = 64; - MonoJumpInfo *ji = NULL; - GSList *unwind_ops = NULL; - - g_assert (!aot); - - code = buf = mono_global_codeman_reserve (tramp_size); - - /* - * This trampoline restore the call chain of the handler block - * then jumps into the code that deals with it. - */ - - /* - * Slow path uses a C helper - */ - S390_SET (code, s390_r2, tramp); - S390_SET (code, s390_r1, handler_block_trampoline_helper); - s390_br (code, s390_r1); - - mono_arch_flush_icache (buf, code - buf); - MONO_PROFILER_RAISE (jit_code_buffer, (buf, code - buf, MONO_PROFILER_CODE_BUFFER_HELPER, NULL)); - g_assert (code - buf <= tramp_size); - - *info = mono_tramp_info_create ("handler_block_trampoline", buf, code - buf, ji, unwind_ops); - - return buf; -} - -/*========================= End of Function ========================*/ diff --git a/mono/mini/tramp-x86.c b/mono/mini/tramp-x86.c index 6d2ba621ea9..bced9017f43 100644 --- a/mono/mini/tramp-x86.c +++ b/mono/mini/tramp-x86.c @@ -414,16 +414,7 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf mono_add_unwind_op_def_cfa_offset (unwind_ops, code, buf, cfa_offset); x86_ret (code); } else { - /* The trampoline argument is at the top of the stack, and it contains the address we need to branch to */ - if (tramp_type == MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD) { - x86_pop_reg (code, X86_EAX); - cfa_offset -= sizeof (mgreg_t); - mono_add_unwind_op_def_cfa_offset (unwind_ops, code, buf, cfa_offset); - x86_alu_reg_imm (code, X86_ADD, X86_ESP, 0x8); - x86_jump_reg (code, X86_EAX); - } else { - x86_ret (code); - } + x86_ret (code); } g_assert ((code - buf) <= 256); @@ -608,65 +599,6 @@ mono_arch_invalidate_method (MonoJitInfo *ji, void *func, gpointer func_arg) x86_call_code (code, (guint8*)func); } -static gpointer -handler_block_trampoline_helper (void) -{ - MonoJitTlsData *jit_tls = mono_tls_get_jit_tls (); - return jit_tls->handler_block_return_address; -} - -gpointer -mono_arch_create_handler_block_trampoline (MonoTrampInfo **info, gboolean aot) -{ - guint8 *tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD); - guint8 *code, *buf; - int tramp_size = 64; - MonoJumpInfo *ji = NULL; - int cfa_offset; - GSList *unwind_ops = NULL; - - g_assert (!aot); - - code = buf = mono_global_codeman_reserve (tramp_size); - - unwind_ops = mono_arch_get_cie_program (); - cfa_offset = sizeof (mgreg_t); - /* - This trampoline restore the call chain of the handler block then jumps into the code that deals with it. - */ - - /* - * We are in a method frame after the call emitted by OP_CALL_HANDLER. - */ - - /*Slow path uses a c helper*/ - x86_call_code (code, handler_block_trampoline_helper); - /* Simulate a call */ - /*Fix stack alignment*/ - x86_alu_reg_imm (code, X86_SUB, X86_ESP, 0x4); - cfa_offset += sizeof (mgreg_t); - mono_add_unwind_op_def_cfa_offset (unwind_ops, code, buf, cfa_offset); - - /* This is the address the trampoline will return to */ - x86_push_reg (code, X86_EAX); - cfa_offset += sizeof (mgreg_t); - mono_add_unwind_op_def_cfa_offset (unwind_ops, code, buf, cfa_offset); - - /* Dummy trampoline argument, since we call the generic trampoline directly */ - x86_push_imm (code, 0); - cfa_offset += sizeof (mgreg_t); - mono_add_unwind_op_def_cfa_offset (unwind_ops, code, buf, cfa_offset); - x86_jump_code (code, tramp); - - mono_arch_flush_icache (buf, code - buf); - MONO_PROFILER_RAISE (jit_code_buffer, (buf, code - buf, MONO_PROFILER_CODE_BUFFER_HELPER, NULL)); - g_assert (code - buf <= tramp_size); - - *info = mono_tramp_info_create ("handler_block_trampoline", buf, code - buf, ji, unwind_ops); - - return buf; -} - guint8* mono_arch_get_call_target (guint8 *code) { -- 2.25.1