X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2Fexceptions-amd64.c;h=cab03fc0f2eae39d21165e0a02250a666d7cbd79;hb=3e69ff3ae72acec33c471236da49ed6c78b26dc4;hp=1a34f6e2f5234cc335c40a7558e315ce8dabb897;hpb=3360de9221d7e4012822eb572abb41339c707645;p=mono.git diff --git a/mono/mini/exceptions-amd64.c b/mono/mini/exceptions-amd64.c index 1a34f6e2f52..cab03fc0f2e 100644 --- a/mono/mini/exceptions-amd64.c +++ b/mono/mini/exceptions-amd64.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -167,7 +167,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 +226,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 +262,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 +306,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 +383,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 +417,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 +431,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)); } @@ -540,7 +539,10 @@ mono_arch_unwind_frame (MonoDomain *domain, MonoJitTlsData *jit_tls, guint8 *unwind_info; guint8 *epilog = NULL; - frame->type = FRAME_TYPE_MANAGED; + if (ji->is_trampoline) + frame->type = FRAME_TYPE_TRAMPOLINE; + else + frame->type = FRAME_TYPE_MANAGED; unwind_info = mono_jinfo_get_unwind_info (ji, &unwind_info_len); @@ -558,9 +560,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) @@ -587,7 +589,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; @@ -612,7 +614,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 @@ -649,7 +651,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; } @@ -665,12 +667,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); } @@ -712,7 +714,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); @@ -753,7 +755,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); } @@ -768,7 +770,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]); @@ -777,7 +779,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; @@ -794,7 +796,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; @@ -815,8 +817,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); @@ -879,10 +881,10 @@ 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); + mono_tramp_info_register (info, NULL); } g_slist_free (tramps); } @@ -1142,7 +1144,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)