X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2Fexceptions-ppc.c;h=6c3878e97b8e4df6102126330851adae5cea167f;hb=dbfee6a3404e684b1ce811ca3bdea45b01bb98b0;hp=0ffcf23a17d2f8f75c7ae9d0e74bffce4c41a993;hpb=f3e4623ee9709a580dbc8d4112fb9558f2c557c3;p=mono.git diff --git a/mono/mini/exceptions-ppc.c b/mono/mini/exceptions-ppc.c index 0ffcf23a17d..6c3878e97b8 100644 --- a/mono/mini/exceptions-ppc.c +++ b/mono/mini/exceptions-ppc.c @@ -220,7 +220,7 @@ mono_arch_get_restore_context (MonoTrampInfo **info, gboolean aot) mono_arch_flush_icache (start, code - start); if (info) - *info = mono_tramp_info_create (g_strdup_printf ("restore_context"), start, code - start, ji, unwind_ops); + *info = mono_tramp_info_create ("restore_context", start, code - start, ji, unwind_ops); return start; } @@ -308,7 +308,7 @@ mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot) mono_arch_flush_icache (start, code - start); if (info) - *info = mono_tramp_info_create (g_strdup_printf ("call_filter"), start, code - start, ji, unwind_ops); + *info = mono_tramp_info_create ("call_filter", start, code - start, ji, unwind_ops); return start; } @@ -316,12 +316,8 @@ mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot) void mono_ppc_throw_exception (MonoObject *exc, unsigned long eip, unsigned long esp, mgreg_t *int_regs, gdouble *fp_regs, gboolean rethrow) { - static void (*restore_context) (MonoContext *); MonoContext ctx; - if (!restore_context) - restore_context = mono_get_restore_context (); - /* adjust eip so that it point into the call instruction */ eip -= 4; @@ -338,8 +334,8 @@ mono_ppc_throw_exception (MonoObject *exc, unsigned long eip, unsigned long esp, if (!rethrow) mono_ex->stack_trace = NULL; } - mono_handle_exception (&ctx, exc, (gpointer)eip, FALSE); - restore_context (&ctx); + mono_handle_exception (&ctx, exc); + mono_restore_context (&ctx); g_assert_not_reached (); } @@ -440,7 +436,7 @@ mono_arch_get_throw_exception_generic (int size, MonoTrampInfo **info, int corli mono_arch_flush_icache (start, code - start); if (info) - *info = mono_tramp_info_create (g_strdup_printf (corlib ? "throw_corlib_exception" : (rethrow ? "rethrow_exception" : "throw_exception")), start, code - start, ji, unwind_ops); + *info = mono_tramp_info_create (corlib ? "throw_corlib_exception" : (rethrow ? "rethrow_exception" : "throw_exception"), start, code - start, ji, unwind_ops); return start; } @@ -504,14 +500,15 @@ mono_arch_get_throw_corlib_exception (MonoTrampInfo **info, gboolean aot) } /* - * mono_arch_find_jit_info_ext: + * mono_arch_find_jit_info: * * See exceptions-amd64.c for docs. */ gboolean -mono_arch_find_jit_info_ext (MonoDomain *domain, MonoJitTlsData *jit_tls, +mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls, MonoJitInfo *ji, MonoContext *ctx, - MonoContext *new_ctx, MonoLMF **lmf, + MonoContext *new_ctx, MonoLMF **lmf, + mgreg_t **save_locations, StackFrameInfo *frame) { gpointer ip = MONO_CONTEXT_GET_IP (ctx); @@ -519,7 +516,6 @@ mono_arch_find_jit_info_ext (MonoDomain *domain, MonoJitTlsData *jit_tls, memset (frame, 0, sizeof (StackFrameInfo)); frame->ji = ji; - frame->managed = FALSE; *new_ctx = *ctx; setup_context (new_ctx); @@ -533,17 +529,11 @@ mono_arch_find_jit_info_ext (MonoDomain *domain, MonoJitTlsData *jit_tls, frame->type = FRAME_TYPE_MANAGED; - if (!ji->method->wrapper_type || ji->method->wrapper_type == MONO_WRAPPER_DYNAMIC_METHOD) - frame->managed = TRUE; - - 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); sframe = (MonoPPCStackFrame*)MONO_CONTEXT_GET_SP (ctx); MONO_CONTEXT_SET_BP (new_ctx, sframe->sp); - if (ji->method->save_lmf) { + if (jinfo_get_method (ji)->save_lmf) { /* sframe->sp points just past the end of the LMF */ guint8 *lmf_addr = (guint8*)sframe->sp - sizeof (MonoLMF); memcpy (&new_ctx->fregs, lmf_addr + G_STRUCT_OFFSET (MonoLMF, fregs), sizeof (double) * MONO_SAVED_FREGS); @@ -560,7 +550,8 @@ mono_arch_find_jit_info_ext (MonoDomain *domain, MonoJitTlsData *jit_tls, mono_unwind_frame (unwind_info, unwind_info_len, ji->code_start, (guint8*)ji->code_start + ji->code_size, - ip, regs, ppc_lr + 1, &cfa); + ip, NULL, regs, ppc_lr + 1, + save_locations, MONO_MAX_IREGS, &cfa); /* we substract 4, so that the IP points into the call instruction */ MONO_CONTEXT_SET_IP (new_ctx, regs [ppc_lr] - 4); @@ -570,11 +561,6 @@ mono_arch_find_jit_info_ext (MonoDomain *domain, MonoJitTlsData *jit_tls, new_ctx->regs [i] = regs [ppc_r13 + i]; } - if (*lmf && (MONO_CONTEXT_GET_SP (ctx) >= (gpointer)(*lmf)->ebp)) { - /* remove any unused lmf */ - *lmf = (*lmf)->previous_lmf; - } - return TRUE; } else if (*lmf) { @@ -669,15 +655,13 @@ mono_ppc_set_func_into_sigctx (void *sigctx, void *func) } static void -altstack_handle_and_restore (void *sigctx, gpointer obj, gboolean test_only) +altstack_handle_and_restore (void *sigctx, gpointer obj) { - void (*restore_context) (MonoContext *); MonoContext mctx; - restore_context = mono_get_restore_context (); mono_arch_sigctx_to_monoctx (sigctx, &mctx); - mono_handle_exception (&mctx, obj, (gpointer)mctx.sc_ir, test_only); - restore_context (&mctx); + mono_handle_exception (&mctx, obj); + mono_restore_context (&mctx); } void @@ -697,8 +681,8 @@ mono_arch_handle_altstack_exception (void *sigctx, gpointer fault_addr, gboolean const char *method; /* we don't do much now, but we can warn the user with a useful message */ fprintf (stderr, "Stack overflow: IP: %p, SP: %p\n", mono_arch_ip_from_context (sigctx), (gpointer)UCONTEXT_REG_Rn(uc, 1)); - if (ji && ji->method) - method = mono_method_full_name (ji->method, TRUE); + if (ji && jinfo_get_method (ji)) + method = mono_method_full_name (jinfo_get_method (ji), TRUE); else method = "Unmanaged"; fprintf (stderr, "At %s\n", method); @@ -746,25 +730,84 @@ mono_arch_handle_altstack_exception (void *sigctx, gpointer fault_addr, gboolean #endif /* !MONO_CROSS_COMPILE */ } +/* + * handle_exception: + * + * Called by resuming from a signal handler. + */ +static void +handle_signal_exception (gpointer obj) +{ + MonoJitTlsData *jit_tls = 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_restore_context (&ctx); +} + +static void +setup_ucontext_return (void *uc, gpointer func) +{ +#if !defined(MONO_CROSS_COMPILE) + UCONTEXT_REG_LNK(uc) = UCONTEXT_REG_NIP(uc); +#ifdef PPC_USES_FUNCTION_DESCRIPTOR + { + MonoPPCFunctionDescriptor *handler_ftnptr = (MonoPPCFunctionDescriptor*)func; + + UCONTEXT_REG_NIP(uc) = (gulong)handler_ftnptr->code; + UCONTEXT_REG_Rn(uc, 2) = (gulong)handler_ftnptr->toc; + } +#else + UCONTEXT_REG_NIP(uc) = (unsigned long)func; +#endif +#endif +} + gboolean -mono_arch_handle_exception (void *ctx, gpointer obj, gboolean test_only) +mono_arch_handle_exception (void *ctx, gpointer obj) { +#if defined(MONO_ARCH_USE_SIGACTION) && defined(UCONTEXT_REG_Rn) + /* + * Handling the exception in the signal handler is problematic, since the original + * 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); + mgreg_t sp; + void *sigctx = ctx; + int frame_size; + void *uc = sigctx; + + /* Pass the ctx parameter in TLS */ + mono_arch_sigctx_to_monoctx (sigctx, &jit_tls->ex_ctx); + /* The others in registers */ + UCONTEXT_REG_Rn (sigctx, PPC_FIRST_ARG_REG) = (gsize)obj; + + /* Allocate a stack frame below the red zone */ + /* Similar to mono_arch_handle_altstack_exception () */ + frame_size = 224; + frame_size += 15; + frame_size &= ~15; + sp = (mgreg_t)(UCONTEXT_REG_Rn(uc, 1) & ~15); + sp = (mgreg_t)(sp - frame_size); + UCONTEXT_REG_Rn(uc, 1) = (mgreg_t)sp; + setup_ucontext_return (uc, handle_signal_exception); + + return TRUE; +#else MonoContext mctx; gboolean result; mono_arch_sigctx_to_monoctx (ctx, &mctx); - result = mono_handle_exception (&mctx, obj, (gpointer)mctx.sc_ir, test_only); + result = mono_handle_exception (&mctx, obj); /* restore the context so that returning from the signal handler will invoke * the catch clause */ mono_arch_monoctx_to_sigctx (&mctx, ctx); return result; +#endif } - -gboolean -mono_arch_has_unwind_info (gconstpointer addr) -{ - return FALSE; -} -