*
* (C) 2001 Ximian, Inc.
* Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/
#include <config.h>
#include <mono/metadata/threads-types.h>
#include <mono/metadata/debug-helpers.h>
#include <mono/metadata/exception.h>
-#include <mono/metadata/gc-internal.h>
+#include <mono/metadata/gc-internals.h>
#include <mono/metadata/mono-debug.h>
#include <mono/utils/mono-mmap.h>
/* restore_contect (MonoContext *ctx) */
- start = code = mono_global_codeman_reserve (256);
+ start = code = (guint8 *)mono_global_codeman_reserve (256);
amd64_mov_reg_reg (code, AMD64_R11, AMD64_ARG_REG1, 8);
GSList *unwind_ops = NULL;
const guint kMaxCodeSize = NACL_SIZE (128, 256);
- start = code = mono_global_codeman_reserve (kMaxCodeSize);
+ start = code = (guint8 *)mono_global_codeman_reserve (kMaxCodeSize);
/* call_filter (MonoContext *ctx, unsigned long eip) */
code = start;
continue;
#endif
if (AMD64_IS_CALLEE_SAVED_REG (i) && i != AMD64_RBP)
- amd64_mov_reg_membase (code, AMD64_RBX, AMD64_ARG_REG1, gregs_offset + (i * 8), 8);
+ amd64_mov_reg_membase (code, i, AMD64_ARG_REG1, gregs_offset + (i * 8), 8);
}
/* load exc register */
amd64_mov_reg_membase (code, AMD64_RAX, AMD64_ARG_REG1, gregs_offset + (AMD64_RAX * 8), 8);
guint64 dummy5, guint64 dummy6,
MonoContext *mctx, MonoObject *exc, gboolean rethrow)
{
+ MonoError error;
MonoContext ctx;
/* mctx is on the caller's stack */
memcpy (&ctx, mctx, sizeof (MonoContext));
- if (mono_object_isinst (exc, mono_defaults.exception_class)) {
+ if (mono_object_isinst_checked (exc, mono_defaults.exception_class, &error)) {
MonoException *mono_ex = (MonoException*)exc;
if (!rethrow) {
mono_ex->stack_trace = NULL;
mono_ex->trace_ips = NULL;
}
}
+ mono_error_assert_ok (&error);
/* adjust eip so that it point into the call instruction */
ctx.gregs [AMD64_RIP] --;
dummy_stack_space = 0;
#endif
- start = code = mono_global_codeman_reserve (kMaxCodeSize);
+ start = code = (guint8 *)mono_global_codeman_reserve (kMaxCodeSize);
/* The stack is unaligned on entry */
stack_size = ALIGN_TO (sizeof (MonoContext) + 64 + dummy_stack_space, MONO_ARCH_FRAME_ALIGNMENT) + 8;
amd64_lea_membase (code, AMD64_RAX, AMD64_RSP, stack_size + sizeof(mgreg_t));
amd64_mov_membase_reg (code, AMD64_RSP, regs_offset + (AMD64_RSP * sizeof(mgreg_t)), X86_EAX, sizeof(mgreg_t));
/* Save IP */
- if (llvm_abs)
- amd64_alu_reg_reg (code, X86_XOR, AMD64_RAX, AMD64_RAX);
- else
- amd64_mov_reg_membase (code, AMD64_RAX, AMD64_RSP, stack_size, sizeof(mgreg_t));
+ amd64_mov_reg_membase (code, AMD64_RAX, AMD64_RSP, stack_size, sizeof(mgreg_t));
amd64_mov_membase_reg (code, AMD64_RSP, regs_offset + (AMD64_RIP * sizeof(mgreg_t)), AMD64_RAX, sizeof(mgreg_t));
/* Set arg1 == ctx */
amd64_lea_membase (code, AMD64_RAX, AMD64_RSP, ctx_offset);
if (resume_unwind) {
amd64_mov_membase_imm (code, AMD64_RSP, arg_offsets [2], 0, sizeof(mgreg_t));
} else if (corlib) {
- amd64_mov_membase_reg (code, AMD64_RSP, arg_offsets [2], AMD64_ARG_REG2, sizeof(mgreg_t));
if (llvm_abs)
- /*
- * The caller is LLVM code which passes the absolute address not a pc offset,
- * so compensate by passing 0 as 'rip' and passing the negated abs address as
- * the pc offset.
+ /*
+ * The caller doesn't pass in a pc/pc offset, instead we simply use the
+ * caller ip. Negate the pc adjustment done in mono_amd64_throw_corlib_exception ().
*/
- amd64_neg_membase (code, AMD64_RSP, arg_offsets [2]);
+ amd64_mov_membase_imm (code, AMD64_RSP, arg_offsets [2], 1, sizeof(mgreg_t));
+ else
+ amd64_mov_membase_reg (code, AMD64_RSP, arg_offsets [2], AMD64_ARG_REG2, sizeof(mgreg_t));
} else {
amd64_mov_membase_imm (code, AMD64_RSP, arg_offsets [2], rethrow, sizeof(mgreg_t));
}
for (i = 0; i < AMD64_NREG; ++i)
regs [i] = new_ctx->gregs [i];
- mono_unwind_frame (unwind_info, unwind_info_len, ji->code_start,
+ mono_unwind_frame (unwind_info, unwind_info_len, (guint8 *)ji->code_start,
(guint8*)ji->code_start + ji->code_size,
- ip, epilog ? &epilog : NULL, regs, MONO_MAX_IREGS + 1,
+ (guint8 *)ip, epilog ? &epilog : NULL, regs, MONO_MAX_IREGS + 1,
save_locations, MONO_MAX_IREGS, &cfa);
for (i = 0; i < AMD64_NREG; ++i)
memcpy (new_ctx, &ext->ctx, sizeof (MonoContext));
- *lmf = (gpointer)(((guint64)(*lmf)->previous_lmf) & ~7);
+ *lmf = (MonoLMF *)(((guint64)(*lmf)->previous_lmf) & ~7);
frame->type = FRAME_TYPE_DEBUGGER_INVOKE;
rip = *(guint64*)((*lmf)->rsp - sizeof(mgreg_t));
}
- ji = mini_jit_info_table_find (domain, (gpointer)rip, NULL);
+ ji = mini_jit_info_table_find (domain, (char *)rip, NULL);
/*
* FIXME: ji == NULL can happen when a managed-to-native wrapper is interrupted
* in the soft debugger suspend code, since (*lmf)->rsp no longer points to the
}
}
- *lmf = (gpointer)(((guint64)(*lmf)->previous_lmf) & ~7);
+ *lmf = (MonoLMF *)(((guint64)(*lmf)->previous_lmf) & ~7);
return TRUE;
}
static void
handle_signal_exception (gpointer obj)
{
- MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = (MonoJitTlsData *)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_handle_exception (&ctx, (MonoObject *)obj);
mono_restore_context (&ctx);
}
* 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);
+ MonoJitTlsData *jit_tls = (MonoJitTlsData *)mono_native_tls_get_value (mono_jit_tls_id);
/* Pass the ctx parameter in TLS */
mono_sigctx_to_monoctx (sigctx, &jit_tls->ex_ctx);
static void
restore_soft_guard_pages (void)
{
- MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = (MonoJitTlsData *)mono_native_tls_get_value (mono_jit_tls_id);
if (jit_tls->stack_ovf_guard_base)
mono_mprotect (jit_tls->stack_ovf_guard_base, jit_tls->stack_ovf_guard_size, MONO_MMAP_NONE);
}
prepare_for_guard_pages (MonoContext *mctx)
{
gpointer *sp;
- sp = (gpointer)(mctx->gregs [AMD64_RSP]);
+ sp = (gpointer *)(mctx->gregs [AMD64_RSP]);
sp -= 1;
/* the return addr */
sp [0] = (gpointer)(mctx->gregs [AMD64_RIP]);
}
static void
-altstack_handle_and_restore (MonoContext *ctx, gpointer obj, gboolean stack_ovf)
+altstack_handle_and_restore (MonoContext *ctx, MonoObject *obj, gboolean stack_ovf)
{
MonoContext mctx;
{
#if defined(MONO_ARCH_USE_SIGACTION)
MonoException *exc = NULL;
- MonoJitInfo *ji = mini_jit_info_table_find (mono_domain_get (), (gpointer)UCONTEXT_REG_RIP (sigctx), NULL);
+ MonoJitInfo *ji = mini_jit_info_table_find (mono_domain_get (), (char *)UCONTEXT_REG_RIP (sigctx), NULL);
gpointer *sp;
int frame_size;
MonoContext *copied_ctx;
frame_size = sizeof (MonoContext) + sizeof (gpointer) * 4 + 128;
frame_size += 15;
frame_size &= ~15;
- sp = (gpointer)(UCONTEXT_REG_RSP (sigctx) & ~15);
- sp = (gpointer)((char*)sp - frame_size);
+ sp = (gpointer *)(UCONTEXT_REG_RSP (sigctx) & ~15);
+ sp = (gpointer *)((char*)sp - frame_size);
copied_ctx = (MonoContext*)(sp + 4);
/* the arguments must be aligned */
sp [-1] = (gpointer)UCONTEXT_REG_RIP (sigctx);
/* Call this to avoid initialization races */
tramps = mono_amd64_get_exception_trampolines (FALSE);
for (l = tramps; l; l = l->next) {
- MonoTrampInfo *info = l->data;
+ MonoTrampInfo *info = (MonoTrampInfo *)l->data;
mono_register_jit_icall (info->code, g_strdup (info->name), NULL, TRUE);
mono_tramp_info_register (info, NULL);
if (saved)
return (MonoContinuationRestore)saved;
- code = start = mono_global_codeman_reserve (kMaxCodeSize);
+ code = start = (guint8 *)mono_global_codeman_reserve (kMaxCodeSize);
/* the signature is: restore (MonoContinuation *cont, int state, MonoLMF **lmf_addr) */
/* cont is in AMD64_ARG_REG1 ($rcx or $rdi)
* state is in AMD64_ARG_REG2 ($rdx or $rsi)