Skip to content

Instantly share code, notes, and snippets.

@NattyNarwhal
Last active February 20, 2018 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NattyNarwhal/1de3685ca4a9d39350ac7ab8b6073c80 to your computer and use it in GitHub Desktop.
Save NattyNarwhal/1de3685ca4a9d39350ac7ab8b6073c80 to your computer and use it in GitHub Desktop.
broken async callback setup patch
diff --git a/mono/mini/exceptions-ppc.c b/mono/mini/exceptions-ppc.c
index 4101eaf..df5fdbd 100644
--- a/mono/mini/exceptions-ppc.c
+++ b/mono/mini/exceptions-ppc.c
@@ -811,6 +811,28 @@ mono_arch_setup_async_callback (MonoContext *ctx, void (*async_cb)(void *fun), g
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)
+{
+ os_ucontext uctx;
+ mono_monoctx_to_sigctx (&uctx, ctx);
+#ifdef PPC_USES_FUNCTION_DESCRIPTOR
+ {
+ MonoPPCFunctionDescriptor *handler_ftnptr = (MonoPPCFunctionDescriptor*)func;
+
+ UCONTEXT_REG_NIP(ctx) = (gulong)handler_ftnptr->code;
+ UCONTEXT_REG_Rn(ctx, 2) = (gulong)handler_ftnptr->toc;
+ }
+#else
+ UCONTEXT_REG_NIP(ctx) = (unsigned long)func;
+#if _CALL_ELF == 2
+ /* ELF v2 ABI calling convention requires to put the target address into
+ * r12 if we use the global entry point of a function. */
+ UCONTEXT_REG_Rn(ctx, 12) = (unsigned long) func;
+#endif
+#endif
+ mono_monoctx_to_sigctx (ctx, &uctx);
+}
diff --git a/mono/mini/mini-ppc.h b/mono/mini/mini-ppc.h
index 167f6ed..8208701 100644
--- a/mono/mini/mini-ppc.h
+++ b/mono/mini/mini-ppc.h
@@ -166,7 +166,7 @@ typedef struct MonoCompileArch {
#define PPC_RETURN_SMALL_STRUCTS_IN_REGS 0
#define MONO_ARCH_HAVE_DECOMPOSE_VTYPE_OPTS 0
#define MONO_ARCH_RETURN_CAN_USE_MULTIPLE_REGISTERS 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
@NattyNarwhal
Copy link
Author

omitted from this patch is printfs; often around sleep code. it seems this part of the code actually works, but then it exposes a threadpool issue: https://linx.li/8dau1af2.txt

I thought it was sleep, but it might be an issue with threadpool worker parking; to see for yourself, try uncommenting some stuff in threadpool-workers-default and mono-threads-debug, setting log level debug, and then run an infinite loop in the REPL & ^C it. the thing gets caught on worker_thread sleeping and looping because of what I assume are stuck parked workers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment