[runtime] Rewrite MonoContext code to work via libunwind.
authorJoão Matos <joao@tritao.eu>
Fri, 24 Jul 2015 18:56:05 +0000 (19:56 +0100)
committerJoão Matos <joao@tritao.eu>
Fri, 24 Jul 2015 18:58:59 +0000 (19:58 +0100)
The latest Xcode 7 beta 4 SDK disallows usage of getcontext and friends.

mono/utils/mono-context.h

index 55d75bda44d0f86406a776f5127c9c856d5054ec..33a821a198a9bd57851f752fb29a49cd3619b75d 100644 (file)
@@ -18,7 +18,7 @@
 #endif
 
 #ifdef HOST_WATCHOS
-#include <ucontext.h>
+#include <libunwind.h>
 #endif
 
 /*
@@ -254,18 +254,27 @@ typedef struct {
 
 #if defined(HOST_WATCHOS)
 
-#define MONO_CONTEXT_GET_CURRENT(ctx) do {                                                     \
-       ucontext_t uctx;                                                                                                \
-       struct __darwin_mcontext32 *mctx;                                                               \
-       getcontext(&uctx);                                                                                              \
-       mctx = uctx.uc_mcontext;                                                                                \
-       memcpy(ctx.regs, mctx->__ss.__r, 13 * sizeof(__uint32_t));              \
-       ctx.regs[ARMREG_SP] = mctx->__ss.__sp;                                                  \
-       ctx.regs[ARMREG_LR] = mctx->__ss.__lr;                                                  \
-       ctx.regs[ARMREG_PC] = mctx->__ss.__pc;                                                  \
-       ctx.pc = mctx->__ss.__pc;                                                                               \
-       memcpy(ctx.fregs, mctx->__fs.__r, 16 * sizeof(__uint32_t));             \
-       ctx.cpsr = mctx->__ss.__cpsr;                                                                   \
+#define MONO_CONTEXT_GET_CURRENT(ctx) do { \
+       unw_context_t uctx; \
+       unw_cursor_t c; \
+       unw_word_t data; \
+       g_assert (unw_getcontext (&uctx) == 0); \
+       g_assert (unw_init_local (&c, &uctx) == 0); \
+       for (int reg = 0; reg < 13; ++reg) { \
+               unw_get_reg (&c, (unw_regnum_t) UNW_ARM_R0 + reg, &data); \
+               ctx.regs[reg] = data; \
+       } \
+       unw_get_reg (&c, UNW_ARM_SP, &data); \
+       ctx.regs[ARMREG_SP] = data; \
+       unw_get_reg (&c, UNW_ARM_LR, &data); \
+       ctx.regs[ARMREG_LR] = data; \
+       unw_get_reg (&c, UNW_ARM_IP, &data); \
+       ctx.regs[ARMREG_PC] = data; \
+       ctx.pc = ctx.regs[ARMREG_PC]; \
+       for (int reg = 0; reg < 16; ++reg) { \
+               unw_get_reg (&c, (unw_regnum_t) UNW_ARM_D0 + reg, &data); \
+               ctx.fregs[reg] = data; \
+       } \
 } while (0);
 
 #else