X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2Fexceptions-amd64.c;h=06c0fd710fc830a14454225d2867b41b8823f999;hb=3d1752383d7da3afc8633187d41265ebe8d1bc6e;hp=4f7e336e6d2ee53f4ef524810ac7d667809d8723;hpb=b26f7890202f367223a1cb48625aee8b43f1b45f;p=mono.git diff --git a/mono/mini/exceptions-amd64.c b/mono/mini/exceptions-amd64.c index 4f7e336e6d2..06c0fd710fc 100644 --- a/mono/mini/exceptions-amd64.c +++ b/mono/mini/exceptions-amd64.c @@ -6,6 +6,7 @@ * * (C) 2001 Ximian, Inc. * Copyright 2011 Xamarin, Inc (http://www.xamarin.com) + * Licensed under the MIT license. See LICENSE file in the project root for full license information. */ #include @@ -28,7 +29,7 @@ #include #include #include -#include +#include #include #include @@ -167,7 +168,7 @@ mono_arch_get_restore_context (MonoTrampInfo **info, gboolean aot) /* restore_contect (MonoContext *ctx) */ - start = code = mono_global_codeman_reserve (256); + start = code = (guint8 *)mono_global_codeman_reserve (256); amd64_mov_reg_reg (code, AMD64_R11, AMD64_ARG_REG1, 8); @@ -226,7 +227,7 @@ mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot) GSList *unwind_ops = NULL; const guint kMaxCodeSize = NACL_SIZE (128, 256); - start = code = mono_global_codeman_reserve (kMaxCodeSize); + start = code = (guint8 *)mono_global_codeman_reserve (kMaxCodeSize); /* call_filter (MonoContext *ctx, unsigned long eip) */ code = start; @@ -262,7 +263,7 @@ mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot) continue; #endif if (AMD64_IS_CALLEE_SAVED_REG (i) && i != AMD64_RBP) - amd64_mov_reg_membase (code, AMD64_RBX, AMD64_ARG_REG1, gregs_offset + (i * 8), 8); + amd64_mov_reg_membase (code, i, AMD64_ARG_REG1, gregs_offset + (i * 8), 8); } /* load exc register */ amd64_mov_reg_membase (code, AMD64_RAX, AMD64_ARG_REG1, gregs_offset + (AMD64_RAX * 8), 8); @@ -306,18 +307,20 @@ mono_amd64_throw_exception (guint64 dummy1, guint64 dummy2, guint64 dummy3, guin guint64 dummy5, guint64 dummy6, MonoContext *mctx, MonoObject *exc, gboolean rethrow) { + MonoError error; MonoContext ctx; /* mctx is on the caller's stack */ memcpy (&ctx, mctx, sizeof (MonoContext)); - if (mono_object_isinst (exc, mono_defaults.exception_class)) { + if (mono_object_isinst_checked (exc, mono_defaults.exception_class, &error)) { MonoException *mono_ex = (MonoException*)exc; if (!rethrow) { mono_ex->stack_trace = NULL; mono_ex->trace_ips = NULL; } } + mono_error_assert_ok (&error); /* adjust eip so that it point into the call instruction */ ctx.gregs [AMD64_RIP] --; @@ -381,7 +384,7 @@ get_throw_trampoline (MonoTrampInfo **info, gboolean rethrow, gboolean corlib, g dummy_stack_space = 0; #endif - start = code = mono_global_codeman_reserve (kMaxCodeSize); + start = code = (guint8 *)mono_global_codeman_reserve (kMaxCodeSize); /* The stack is unaligned on entry */ stack_size = ALIGN_TO (sizeof (MonoContext) + 64 + dummy_stack_space, MONO_ARCH_FRAME_ALIGNMENT) + 8; @@ -415,10 +418,7 @@ get_throw_trampoline (MonoTrampInfo **info, gboolean rethrow, gboolean corlib, g amd64_lea_membase (code, AMD64_RAX, AMD64_RSP, stack_size + sizeof(mgreg_t)); amd64_mov_membase_reg (code, AMD64_RSP, regs_offset + (AMD64_RSP * sizeof(mgreg_t)), X86_EAX, sizeof(mgreg_t)); /* Save IP */ - if (llvm_abs) - amd64_alu_reg_reg (code, X86_XOR, AMD64_RAX, AMD64_RAX); - else - amd64_mov_reg_membase (code, AMD64_RAX, AMD64_RSP, stack_size, sizeof(mgreg_t)); + amd64_mov_reg_membase (code, AMD64_RAX, AMD64_RSP, stack_size, sizeof(mgreg_t)); amd64_mov_membase_reg (code, AMD64_RSP, regs_offset + (AMD64_RIP * sizeof(mgreg_t)), AMD64_RAX, sizeof(mgreg_t)); /* Set arg1 == ctx */ amd64_lea_membase (code, AMD64_RAX, AMD64_RSP, ctx_offset); @@ -432,14 +432,14 @@ get_throw_trampoline (MonoTrampInfo **info, gboolean rethrow, gboolean corlib, g if (resume_unwind) { amd64_mov_membase_imm (code, AMD64_RSP, arg_offsets [2], 0, sizeof(mgreg_t)); } else if (corlib) { - amd64_mov_membase_reg (code, AMD64_RSP, arg_offsets [2], AMD64_ARG_REG2, sizeof(mgreg_t)); if (llvm_abs) - /* - * The caller is LLVM code which passes the absolute address not a pc offset, - * so compensate by passing 0 as 'rip' and passing the negated abs address as - * the pc offset. + /* + * The caller doesn't pass in a pc/pc offset, instead we simply use the + * caller ip. Negate the pc adjustment done in mono_amd64_throw_corlib_exception (). */ - amd64_neg_membase (code, AMD64_RSP, arg_offsets [2]); + amd64_mov_membase_imm (code, AMD64_RSP, arg_offsets [2], 1, sizeof(mgreg_t)); + else + amd64_mov_membase_reg (code, AMD64_RSP, arg_offsets [2], AMD64_ARG_REG2, sizeof(mgreg_t)); } else { amd64_mov_membase_imm (code, AMD64_RSP, arg_offsets [2], rethrow, sizeof(mgreg_t)); } @@ -561,9 +561,9 @@ mono_arch_unwind_frame (MonoDomain *domain, MonoJitTlsData *jit_tls, for (i = 0; i < AMD64_NREG; ++i) regs [i] = new_ctx->gregs [i]; - mono_unwind_frame (unwind_info, unwind_info_len, ji->code_start, + mono_unwind_frame (unwind_info, unwind_info_len, (guint8 *)ji->code_start, (guint8*)ji->code_start + ji->code_size, - ip, epilog ? &epilog : NULL, regs, MONO_MAX_IREGS + 1, + (guint8 *)ip, epilog ? &epilog : NULL, regs, MONO_MAX_IREGS + 1, save_locations, MONO_MAX_IREGS, &cfa); for (i = 0; i < AMD64_NREG; ++i) @@ -590,7 +590,7 @@ mono_arch_unwind_frame (MonoDomain *domain, MonoJitTlsData *jit_tls, memcpy (new_ctx, &ext->ctx, sizeof (MonoContext)); - *lmf = (gpointer)(((guint64)(*lmf)->previous_lmf) & ~7); + *lmf = (MonoLMF *)(((guint64)(*lmf)->previous_lmf) & ~7); frame->type = FRAME_TYPE_DEBUGGER_INVOKE; @@ -615,7 +615,7 @@ mono_arch_unwind_frame (MonoDomain *domain, MonoJitTlsData *jit_tls, rip = *(guint64*)((*lmf)->rsp - sizeof(mgreg_t)); } - ji = mini_jit_info_table_find (domain, (gpointer)rip, NULL); + ji = mini_jit_info_table_find (domain, (char *)rip, NULL); /* * FIXME: ji == NULL can happen when a managed-to-native wrapper is interrupted * in the soft debugger suspend code, since (*lmf)->rsp no longer points to the @@ -652,7 +652,7 @@ mono_arch_unwind_frame (MonoDomain *domain, MonoJitTlsData *jit_tls, } } - *lmf = (gpointer)(((guint64)(*lmf)->previous_lmf) & ~7); + *lmf = (MonoLMF *)(((guint64)(*lmf)->previous_lmf) & ~7); return TRUE; } @@ -668,12 +668,12 @@ mono_arch_unwind_frame (MonoDomain *domain, MonoJitTlsData *jit_tls, static void handle_signal_exception (gpointer obj) { - MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id); + MonoJitTlsData *jit_tls = (MonoJitTlsData *)mono_native_tls_get_value (mono_jit_tls_id); MonoContext ctx; memcpy (&ctx, &jit_tls->ex_ctx, sizeof (MonoContext)); - mono_handle_exception (&ctx, obj); + mono_handle_exception (&ctx, (MonoObject *)obj); mono_restore_context (&ctx); } @@ -715,7 +715,7 @@ mono_arch_handle_exception (void *sigctx, gpointer obj) * signal is disabled, and we could run arbitrary code though the debugger. So * resume into the normal stack and do most work there if possible. */ - MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id); + MonoJitTlsData *jit_tls = (MonoJitTlsData *)mono_native_tls_get_value (mono_jit_tls_id); /* Pass the ctx parameter in TLS */ mono_sigctx_to_monoctx (sigctx, &jit_tls->ex_ctx); @@ -756,7 +756,7 @@ mono_arch_ip_from_context (void *sigctx) static void restore_soft_guard_pages (void) { - MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id); + MonoJitTlsData *jit_tls = (MonoJitTlsData *)mono_native_tls_get_value (mono_jit_tls_id); if (jit_tls->stack_ovf_guard_base) mono_mprotect (jit_tls->stack_ovf_guard_base, jit_tls->stack_ovf_guard_size, MONO_MMAP_NONE); } @@ -771,7 +771,7 @@ static void prepare_for_guard_pages (MonoContext *mctx) { gpointer *sp; - sp = (gpointer)(mctx->gregs [AMD64_RSP]); + sp = (gpointer *)(mctx->gregs [AMD64_RSP]); sp -= 1; /* the return addr */ sp [0] = (gpointer)(mctx->gregs [AMD64_RIP]); @@ -780,7 +780,7 @@ prepare_for_guard_pages (MonoContext *mctx) } static void -altstack_handle_and_restore (MonoContext *ctx, gpointer obj, gboolean stack_ovf) +altstack_handle_and_restore (MonoContext *ctx, MonoObject *obj, gboolean stack_ovf) { MonoContext mctx; @@ -797,7 +797,7 @@ mono_arch_handle_altstack_exception (void *sigctx, MONO_SIG_HANDLER_INFO_TYPE *s { #if defined(MONO_ARCH_USE_SIGACTION) MonoException *exc = NULL; - MonoJitInfo *ji = mini_jit_info_table_find (mono_domain_get (), (gpointer)UCONTEXT_REG_RIP (sigctx), NULL); + MonoJitInfo *ji = mini_jit_info_table_find (mono_domain_get (), (char *)UCONTEXT_REG_RIP (sigctx), NULL); gpointer *sp; int frame_size; MonoContext *copied_ctx; @@ -818,8 +818,8 @@ mono_arch_handle_altstack_exception (void *sigctx, MONO_SIG_HANDLER_INFO_TYPE *s frame_size = sizeof (MonoContext) + sizeof (gpointer) * 4 + 128; frame_size += 15; frame_size &= ~15; - sp = (gpointer)(UCONTEXT_REG_RSP (sigctx) & ~15); - sp = (gpointer)((char*)sp - frame_size); + sp = (gpointer *)(UCONTEXT_REG_RSP (sigctx) & ~15); + sp = (gpointer *)((char*)sp - frame_size); copied_ctx = (MonoContext*)(sp + 4); /* the arguments must be aligned */ sp [-1] = (gpointer)UCONTEXT_REG_RIP (sigctx); @@ -882,7 +882,7 @@ mono_arch_exceptions_init (void) /* Call this to avoid initialization races */ tramps = mono_amd64_get_exception_trampolines (FALSE); for (l = tramps; l; l = l->next) { - MonoTrampInfo *info = l->data; + MonoTrampInfo *info = (MonoTrampInfo *)l->data; mono_register_jit_icall (info->code, g_strdup (info->name), NULL, TRUE); mono_tramp_info_register (info, NULL); @@ -1145,7 +1145,7 @@ mono_tasklets_arch_restore (void) if (saved) return (MonoContinuationRestore)saved; - code = start = mono_global_codeman_reserve (kMaxCodeSize); + code = start = (guint8 *)mono_global_codeman_reserve (kMaxCodeSize); /* the signature is: restore (MonoContinuation *cont, int state, MonoLMF **lmf_addr) */ /* cont is in AMD64_ARG_REG1 ($rcx or $rdi) * state is in AMD64_ARG_REG2 ($rdx or $rsi)