*managed = FALSE;
if (ji != NULL) {
- int offset;
+ int i;
+ gssize regs [MONO_MAX_IREGS + 1];
+ guint8 *cfa;
+ guint32 unwind_info_len;
+ guint8 *unwind_info;
*new_ctx = *ctx;
if (!ji->method->wrapper_type)
*managed = TRUE;
- /*
- * Some managed methods like pinvoke wrappers might have save_lmf set.
- * In this case, register save/restore code is not generated by the
- * JIT, so we have to restore callee saved registers from the lmf.
- */
- if (ji->method->save_lmf) {
- /*
- * We only need to do this if the exception was raised in managed
- * code, since otherwise the lmf was already popped of the stack.
- */
- if (*lmf && (MONO_CONTEXT_GET_BP (ctx) >= (gpointer)(*lmf)->ebp)) {
- memcpy (&new_ctx->regs [0], &(*lmf)->iregs [4], sizeof (gulong) * MONO_SAVED_GREGS);
- }
- /* This is the sp for the parent frame */
- new_ctx->esp = (*lmf)->iregs [12];
- new_ctx->eip = (*lmf)->iregs [13];
- new_ctx->ebp = new_ctx->esp;
- } else {
- int i;
- char* sp;
- offset = ji->used_regs >> 16;
- offset <<= 2;
- /* the saved regs are at sp + offset */
- /* restore caller saved registers */
- sp = (char*)ctx->ebp;
- sp += offset;
- for (i = 4; i < 16; ++i) {
- if (ji->used_regs & (1 << i)) {
- new_ctx->regs [i - 4] = *(gulong*)sp;
- sp += sizeof (gulong);
- }
- }
- /* IP and LR */
- new_ctx->esp = *(gulong*)sp;
- sp += sizeof (gulong);
- new_ctx->eip = *(gulong*)sp;
- sp += sizeof (gulong);
- new_ctx->ebp = new_ctx->regs [ARMREG_R11 - 4];
- /*
- * FIXME this doesn't really do what is supposed to. MonoContext::regs map r4-r11, r12(ip), r14(lr)
- * This code is storing in MonoContext::fregs [0].
- */
- /* Needed by get_exception_catch_class () */
- new_ctx->regs [ARMREG_R11] = new_ctx->ebp;
- }
+ unwind_info = mono_get_cached_unwind_info (ji->used_regs, &unwind_info_len);
+
+ /* Beautiful numbers */
+ for (i = 4; i < 12; ++i)
+ regs [i] = new_ctx->regs [i - 4];
+ regs [ARMREG_IP] = new_ctx->regs [8];
+ regs [ARMREG_LR] = new_ctx->regs [9];
+ regs [ARMREG_SP] = new_ctx->esp;
+
+ mono_unwind_frame (unwind_info, unwind_info_len, -4, ji->code_start,
+ (guint8*)ji->code_start + ji->code_size,
+ ip, regs, MONO_MAX_IREGS, &cfa);
+
+ for (i = 4; i < 12; ++i)
+ new_ctx->regs [i - 4] = regs [i];
+ new_ctx->regs [8] = regs [ARMREG_IP];
+ new_ctx->regs [9] = regs [ARMREG_LR];
+ new_ctx->eip = regs [ARMREG_LR];
+ new_ctx->esp = (gsize)cfa;
+ new_ctx->ebp = new_ctx->esp;
+
+ /* Needed by get_exception_catch_class () */
+ // FIXME: Is this neded ?
+ new_ctx->regs [ARMREG_R11] = new_ctx->esp;
if (*lmf && (MONO_CONTEXT_GET_BP (ctx) >= (gpointer)(*lmf)->ebp)) {
/* remove any unused lmf */