X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2Fexceptions-amd64.c;h=b81a7dca3a3fa8eced768d1e8f6c1e7b5504d004;hb=8f09dad4353bb75afebf96ad58d08f7e7f3bf56d;hp=91c0a8996b706a4c33dec81aab8080e21f0f636d;hpb=79e0856ffda4c2566314ba31677fe55f2d7f53f2;p=mono.git diff --git a/mono/mini/exceptions-amd64.c b/mono/mini/exceptions-amd64.c index 91c0a8996b7..b81a7dca3a3 100644 --- a/mono/mini/exceptions-amd64.c +++ b/mono/mini/exceptions-amd64.c @@ -37,7 +37,6 @@ #include "mini.h" #include "mini-amd64.h" #include "tasklets.h" -#include "debug-mini.h" #define ALIGN_TO(val,align) (((val) + ((align) - 1)) & ~((align) - 1)) @@ -47,13 +46,13 @@ static MonoW32ExceptionHandler ill_handler; static MonoW32ExceptionHandler segv_handler; LPTOP_LEVEL_EXCEPTION_FILTER mono_old_win_toplevel_exception_filter; -guint64 mono_win_vectored_exception_handle; +void *mono_win_vectored_exception_handle; extern gboolean mono_win_chained_exception_needs_run; #define W32_SEH_HANDLE_EX(_ex) \ if (_ex##_handler) _ex##_handler(0, ep, sctx) -LONG CALLBACK seh_unhandled_exception_filter(EXCEPTION_POINTERS* ep) +static LONG CALLBACK seh_unhandled_exception_filter(EXCEPTION_POINTERS* ep) { #ifndef MONO_CROSS_COMPILE if (mono_old_win_toplevel_exception_filter) { @@ -70,7 +69,7 @@ LONG CALLBACK seh_unhandled_exception_filter(EXCEPTION_POINTERS* ep) * Unhandled Exception Filter * Top-level per-process exception handler. */ -LONG CALLBACK seh_vectored_exception_handler(EXCEPTION_POINTERS* ep) +static LONG CALLBACK seh_vectored_exception_handler(EXCEPTION_POINTERS* ep) { EXCEPTION_RECORD* er; CONTEXT* ctx; @@ -161,10 +160,10 @@ void win32_seh_init() void win32_seh_cleanup() { - if (mono_old_win_toplevel_exception_filter) SetUnhandledExceptionFilter(mono_old_win_toplevel_exception_filter); - guint32 ret = 0; + if (mono_old_win_toplevel_exception_filter) SetUnhandledExceptionFilter(mono_old_win_toplevel_exception_filter); + ret = RemoveVectoredExceptionHandler (mono_win_vectored_exception_handle); g_assert (ret); } @@ -369,22 +368,6 @@ mono_amd64_throw_exception (guint64 dummy1, guint64 dummy2, guint64 dummy3, guin mono_ex->stack_trace = NULL; } - if (mono_debug_using_mono_debugger ()) { - guint8 buf [16]; - - mono_breakpoint_clean_code (NULL, (gpointer)rip, 8, buf, sizeof (buf)); - - if (buf [3] == 0xe8) { - MonoContext ctx_cp = ctx; - ctx_cp.rip = rip - 5; - - if (mono_debugger_handle_exception (&ctx_cp, exc)) { - mono_restore_context (&ctx_cp); - g_assert_not_reached (); - } - } - } - /* adjust eip so that it point into the call instruction */ ctx.rip -= 1; @@ -610,13 +593,15 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls, frame->type = FRAME_TYPE_MANAGED; - if (ji->from_aot) - unwind_info = mono_aot_get_unwind_info (ji, &unwind_info_len); - else - unwind_info = mono_get_cached_unwind_info (ji->used_regs, &unwind_info_len); + unwind_info = mono_jinfo_get_unwind_info (ji, &unwind_info_len); frame->unwind_info = unwind_info; frame->unwind_info_len = unwind_info_len; + + /* + printf ("%s %p %p\n", ji->d.method->name, ji->code_start, ip); + mono_print_unwind_info (unwind_info, unwind_info_len); + */ regs [AMD64_RAX] = new_ctx->rax; regs [AMD64_RBX] = new_ctx->rbx; @@ -659,7 +644,7 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls, if (*lmf && ((*lmf) != jit_tls->first_lmf) && (MONO_CONTEXT_GET_SP (ctx) >= (gpointer)(*lmf)->rsp)) { /* remove any unused lmf */ - *lmf = (gpointer)(((guint64)(*lmf)->previous_lmf) & ~3); + *lmf = (gpointer)(((guint64)(*lmf)->previous_lmf) & ~7); } #ifndef MONO_AMD64_NO_PUSHES @@ -683,7 +668,7 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls, memcpy (new_ctx, &ext->ctx, sizeof (MonoContext)); - *lmf = (gpointer)(((guint64)(*lmf)->previous_lmf) & ~3); + *lmf = (gpointer)(((guint64)(*lmf)->previous_lmf) & ~7); frame->type = FRAME_TYPE_DEBUGGER_INVOKE; @@ -724,17 +709,36 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls, new_ctx->rbp = (*lmf)->rbp; new_ctx->rsp = (*lmf)->rsp; - new_ctx->rbx = (*lmf)->rbx; - new_ctx->r12 = (*lmf)->r12; - new_ctx->r13 = (*lmf)->r13; - new_ctx->r14 = (*lmf)->r14; - new_ctx->r15 = (*lmf)->r15; + if (((guint64)(*lmf)->previous_lmf) & 4) { + MonoLMFTramp *ext = (MonoLMFTramp*)(*lmf); + + /* Trampoline frame */ + new_ctx->rbx = ext->regs [AMD64_RBX]; + new_ctx->r12 = ext->regs [AMD64_R12]; + new_ctx->r13 = ext->regs [AMD64_R13]; + new_ctx->r14 = ext->regs [AMD64_R14]; + new_ctx->r15 = ext->regs [AMD64_R15]; #ifdef TARGET_WIN32 - new_ctx->rdi = (*lmf)->rdi; - new_ctx->rsi = (*lmf)->rsi; + new_ctx->rdi = ext->regs [AMD64_RDI]; + new_ctx->rsi = ext->regs [AMD64_RSI]; #endif + } else { + /* + * The registers saved in the LMF will be restored using the normal unwind info, + * when the wrapper frame is processed. + */ + new_ctx->rbx = 0; + new_ctx->r12 = 0; + new_ctx->r13 = 0; + new_ctx->r14 = 0; + new_ctx->r15 = 0; +#ifdef TARGET_WIN32 + new_ctx->rdi = 0; + new_ctx->rsi = 0; +#endif + } - *lmf = (gpointer)(((guint64)(*lmf)->previous_lmf) & ~3); + *lmf = (gpointer)(((guint64)(*lmf)->previous_lmf) & ~7); return TRUE; } @@ -755,9 +759,6 @@ handle_signal_exception (gpointer obj) memcpy (&ctx, &jit_tls->ex_ctx, sizeof (MonoContext)); - if (mono_debugger_handle_exception (&ctx, (MonoObject *)obj)) - return; - mono_handle_exception (&ctx, obj); mono_restore_context (&ctx); @@ -775,8 +776,10 @@ mono_arch_setup_async_callback (MonoContext *ctx, void (*async_cb)(void *fun), g /* The stack should be unaligned */ if ((sp % 16) == 0) sp -= 8; +#ifdef __linux__ /* Preserve the call chain to prevent crashes in the libgcc unwinder (#15969) */ *(guint64*)sp = ctx->rip; +#endif ctx->rsp = sp; ctx->rip = (guint64)async_cb; } @@ -813,9 +816,6 @@ mono_arch_handle_exception (void *sigctx, gpointer obj) mono_arch_sigctx_to_monoctx (sigctx, &mctx); - if (mono_debugger_handle_exception (&mctx, (MonoObject *)obj)) - return TRUE; - mono_handle_exception (&mctx, obj); mono_arch_monoctx_to_sigctx (&mctx, sigctx); @@ -882,12 +882,6 @@ altstack_handle_and_restore (void *sigctx, gpointer obj, gboolean stack_ovf) mono_arch_sigctx_to_monoctx (sigctx, &mctx); - if (mono_debugger_handle_exception (&mctx, (MonoObject *)obj)) { - if (stack_ovf) - prepare_for_guard_pages (&mctx); - mono_restore_context (&mctx); - } - mono_handle_exception (&mctx, obj); if (stack_ovf) prepare_for_guard_pages (&mctx); @@ -1347,7 +1341,7 @@ mono_arch_unwindinfo_get_size (gpointer monoui) (sizeof (UNWIND_CODE) * (MONO_MAX_UNWIND_CODES - unwindinfo->unwindInfo.CountOfCodes)); } -PRUNTIME_FUNCTION +static PRUNTIME_FUNCTION MONO_GET_RUNTIME_FUNCTION_CALLBACK ( DWORD64 ControlPc, IN PVOID Context ) { MonoJitInfo *ji;