From ca47362a921ba3ce58b2ae75b319d06b74feef1e Mon Sep 17 00:00:00 2001 From: Calvin Date: Thu, 22 Feb 2018 22:49:12 -0400 Subject: [PATCH] Fix mono_arch_setup_async_callback and add mono_arch_setup_resume_sighandler_ctx on PPC (#7159) * Fix *setup_async_callback and add *resume_sighandler_ctx on PPC mono_arch_setup_async_callback didn't work on systems that use function pointers. For consistency with other backends with exception support, also add mono_arch_setup_resume_sighandler_ctx, which we can use to support mono_arch_setup_async_callback, like those other backends. Also enable async callbacks on AIX, then enable *resume_sighandler_ctx on PPC Linux (untested) and AIX. With this, I can now ^C in the REPL with AIX and have it work; whereas before it bombed out, with or without async callbacks enabled or disabled. * Don't configure func descriptors twice, set args reg with user data * No sense configuring configuring function descriptors if the restore sigcontext call already set them up. (If Mac OS supports is verified and added to the ifdef maze, it'd be safe to remove this whole ifdef, and let the call in `exceptions-ppc` handle it all, as all supported OSes would have that call...) * Set user_data in an arguments register, like what amd64 and z do. These don't seem to cause any regressions, like the first patch. * Remove unnecessary case for PPC * mono_ppc_set_func_into_sigctx is unused now, remove it * Everyone has MONO_ARCH_HAVE_SETUP_RESUME_FROM_SIGNAL_HANDLER_CTX on PPC now * Everyone has MONO_ARCH_HAVE_SIGCTX_TO_MONOCTX on PPC too --- mono/mini/debugger-agent.c | 4 ---- mono/mini/exceptions-ppc.c | 30 +++++++++++++----------------- mono/mini/mini-ppc.h | 9 ++++----- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index 06f0259eaf9..0113fbcde38 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -5166,10 +5166,6 @@ resume_from_signal_handler (void *sigctx, void *func) MONO_CONTEXT_SET_IP (&ctx, func); #endif mono_monoctx_to_sigctx (&ctx, sigctx); - -#ifdef PPC_USES_FUNCTION_DESCRIPTOR - mono_ppc_set_func_into_sigctx (sigctx, func); -#endif } void diff --git a/mono/mini/exceptions-ppc.c b/mono/mini/exceptions-ppc.c index 4101eaf3e99..3483ba835d8 100644 --- a/mono/mini/exceptions-ppc.c +++ b/mono/mini/exceptions-ppc.c @@ -618,22 +618,6 @@ mono_arch_ip_from_context (void *sigctx) #endif } -void -mono_ppc_set_func_into_sigctx (void *sigctx, void *func) -{ -#ifdef MONO_CROSS_COMPILE - g_assert_not_reached (); -#elif defined(PPC_USES_FUNCTION_DESCRIPTOR) - /* Have to set both the ip and the TOC reg */ - os_ucontext *uc = sigctx; - - UCONTEXT_REG_NIP(uc) = ((gsize*)func) [0]; - UCONTEXT_REG_Rn (uc, 2) = ((gsize*)func)[1]; -#else - g_assert_not_reached (); -#endif -} - static void altstack_handle_and_restore (void *sigctx, gpointer obj) { @@ -808,9 +792,21 @@ void mono_arch_setup_async_callback (MonoContext *ctx, void (*async_cb)(void *fun), gpointer user_data) { uintptr_t sp = (uintptr_t) MONO_CONTEXT_GET_SP(ctx); + ctx->regs [PPC_FIRST_ARG_REG] = user_data; sp -= PPC_MINIMAL_STACK_SIZE; *(unsigned long *)sp = MONO_CONTEXT_GET_SP(ctx); MONO_CONTEXT_SET_BP(ctx, sp); - MONO_CONTEXT_SET_IP(ctx, (unsigned long) async_cb); + mono_arch_setup_resume_sighandler_ctx(ctx, (unsigned long) async_cb); } +void +mono_arch_setup_resume_sighandler_ctx (MonoContext *ctx, gpointer func) +{ +#ifdef PPC_USES_FUNCTION_DESCRIPTOR + MonoPPCFunctionDescriptor *handler_ftnptr = (MonoPPCFunctionDescriptor*)func; + MONO_CONTEXT_SET_IP(ctx, (gulong)handler_ftnptr->code); + ctx->regs[2] = (gulong)handler_ftnptr->toc; +#else + MONO_CONTEXT_SET_IP(ctx, (unsigned long) func); +#endif +} diff --git a/mono/mini/mini-ppc.h b/mono/mini/mini-ppc.h index eb8a7600a60..f19fa11ddab 100644 --- a/mono/mini/mini-ppc.h +++ b/mono/mini/mini-ppc.h @@ -161,12 +161,11 @@ typedef struct MonoCompileArch { #define PPC_PASS_SMALL_FLOAT_STRUCTS_IN_FR_REGS 0 #define PPC_RETURN_SMALL_FLOAT_STRUCTS_IN_FR_REGS 0 #define PPC_RETURN_SMALL_STRUCTS_IN_REGS 0 -//#define MONO_ARCH_HAVE_SETUP_ASYNC_CALLBACK 1 +#define MONO_ARCH_HAVE_SETUP_ASYNC_CALLBACK 1 #define PPC_MINIMAL_PARAM_AREA_SIZE 64 #define PPC_LAST_FPARG_REG ppc_f13 #define PPC_PASS_STRUCTS_BY_VALUE 1 #define PPC_THREAD_PTR_REG ppc_r13 -#define MONO_ARCH_HAVE_SIGCTX_TO_MONOCTX 1 #define PPC_FIRST_ARG_REG ppc_r3 #define PPC_LAST_ARG_REG ppc_r10 #define PPC_FIRST_FPARG_REG ppc_f1 @@ -217,7 +216,6 @@ typedef struct MonoCompileArch { #define PPC_RETURN_SMALL_STRUCTS_IN_REGS 0 #define PPC_THREAD_PTR_REG ppc_r2 #endif -#define MONO_ARCH_HAVE_SIGCTX_TO_MONOCTX 1 #define PPC_FIRST_ARG_REG ppc_r3 #define PPC_LAST_ARG_REG ppc_r10 #define PPC_FIRST_FPARG_REG ppc_f1 @@ -235,6 +233,9 @@ typedef struct MonoCompileArch { #define MONO_ARCH_VTABLE_REG ppc_r11 #define MONO_ARCH_RGCTX_REG MONO_ARCH_IMT_REG +#define MONO_ARCH_HAVE_SIGCTX_TO_MONOCTX 1 +#define MONO_ARCH_HAVE_SETUP_RESUME_FROM_SIGNAL_HANDLER_CTX 1 + #define MONO_ARCH_NO_IOV_CHECK 1 #define MONO_ARCH_HAVE_DECOMPOSE_OPTS 1 #define MONO_ARCH_HAVE_DECOMPOSE_LONG_OPTS 1 @@ -379,8 +380,6 @@ gboolean mono_ppc_is_direct_call_sequence (guint32 *code); void mono_ppc_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr); -void mono_ppc_set_func_into_sigctx (void *sigctx, void *func); - // Debugging macros for ELF ABI v2 #ifdef DEBUG_ELFABIV2 -- 2.11.4.GIT