#include <glib.h>
#include <signal.h>
#include <string.h>
+#ifdef HAVE_ASM_SIGCONTEXT_H
+#include <asm/sigcontext.h>
+#endif /* def HAVE_ASM_SIGCONTEXT_H */
+#ifdef HAVE_UCONTEXT_H
#include <ucontext.h>
+#endif /* def HAVE_UCONTEXT_H */
#include <mono/arch/arm/arm-codegen.h>
#include <mono/metadata/appdomain.h>
* The first argument in r0 is the pointer to the context.
*/
gpointer
-mono_arch_get_restore_context_full (guint32 *code_size, MonoJumpInfo **ji, gboolean aot)
+mono_arch_get_restore_context (MonoTrampInfo **info, gboolean aot)
{
guint8 *code;
guint8 *start;
int ctx_reg;
-
- *ji = NULL;
+ MonoJumpInfo *ji = NULL;
+ GSList *unwind_ops = NULL;
start = code = mono_global_codeman_reserve (128);
mono_arch_flush_icache (start, code - start);
- *code_size = code - start;
+ if (info)
+ *info = mono_tramp_info_create (g_strdup_printf ("restore_context"), start, code - start, ji, unwind_ops);
return start;
}
* @exc object in this case).
*/
gpointer
-mono_arch_get_call_filter_full (guint32 *code_size, MonoJumpInfo **ji, gboolean aot)
+mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot)
{
guint8 *code;
guint8* start;
int ctx_reg;
-
- *ji = NULL;
+ MonoJumpInfo *ji = NULL;
+ GSList *unwind_ops = NULL;
/* call_filter (MonoContext *ctx, unsigned long eip, gpointer exc) */
start = code = mono_global_codeman_reserve (320);
mono_arch_flush_icache (start, code - start);
- *code_size = code - start;
+ if (info)
+ *info = mono_tramp_info_create (g_strdup_printf ("call_filter"), start, code - start, ji, unwind_ops);
return start;
}
*
*/
static gpointer
-mono_arch_get_throw_exception_generic (int size, int by_token, gboolean rethrow, guint32 *code_size, MonoJumpInfo **ji, gboolean aot)
+mono_arch_get_throw_exception_generic (int size, gboolean corlib, gboolean rethrow, MonoTrampInfo **info, gboolean aot)
{
guint8 *start;
guint8 *code;
-
- *ji = NULL;
+ MonoJumpInfo *ji = NULL;
+ GSList *unwind_ops = NULL;
code = start = mono_global_codeman_reserve (size);
/* caller sp */
ARM_ADD_REG_IMM8 (code, ARMREG_R2, ARMREG_SP, 10 * 4); /* 10 saved regs */
/* exc is already in place in r0 */
- if (by_token) {
+ if (corlib) {
/* The caller ip is already in R1 */
} else {
ARM_MOV_REG_REG (code, ARMREG_R1, ARMREG_LR); /* caller ip */
ARM_ORR_REG_IMM8 (code, ARMREG_R1, ARMREG_R1, rethrow);
if (aot) {
- *ji = mono_patch_info_list_prepend (*ji, code - start, MONO_PATCH_INFO_JIT_ICALL_ADDR, by_token ? "mono_arm_throw_exception_by_token" : "mono_arm_throw_exception");
+ ji = mono_patch_info_list_prepend (ji, code - start, MONO_PATCH_INFO_JIT_ICALL_ADDR, corlib ? "mono_arm_throw_exception_by_token" : "mono_arm_throw_exception");
ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 0);
ARM_B (code, 0);
*(gpointer*)(gpointer)code = NULL;
code += 4;
ARM_LDR_REG_REG (code, ARMREG_IP, ARMREG_PC, ARMREG_IP);
} else {
- code = mono_arm_emit_load_imm (code, ARMREG_IP, GPOINTER_TO_UINT (by_token ? (gpointer)mono_arm_throw_exception_by_token : (gpointer)mono_arm_throw_exception));
+ code = mono_arm_emit_load_imm (code, ARMREG_IP, GPOINTER_TO_UINT (corlib ? (gpointer)mono_arm_throw_exception_by_token : (gpointer)mono_arm_throw_exception));
}
ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_PC);
ARM_MOV_REG_REG (code, ARMREG_PC, ARMREG_IP);
g_assert ((code - start) < size);
mono_arch_flush_icache (start, code - start);
- *code_size = code - start;
+ if (info)
+ *info = mono_tramp_info_create (g_strdup_printf (corlib ? "throw_corlib_exception" : (rethrow ? "rethrow_exception" : "throw_exception")), start, code - start, ji, unwind_ops);
return start;
}
*
*/
gpointer
-mono_arch_get_rethrow_exception_full (guint32 *code_size, MonoJumpInfo **ji, gboolean aot)
+mono_arch_get_rethrow_exception (MonoTrampInfo **info, gboolean aot)
{
- return mono_arch_get_throw_exception_generic (132, FALSE, TRUE, code_size, ji, aot);
+ return mono_arch_get_throw_exception_generic (132, FALSE, TRUE, info, aot);
}
/**
*
*/
gpointer
-mono_arch_get_throw_exception_full (guint32 *code_size, MonoJumpInfo **ji, gboolean aot)
+mono_arch_get_throw_exception (MonoTrampInfo **info, gboolean aot)
{
- return mono_arch_get_throw_exception_generic (132, FALSE, FALSE, code_size, ji, aot);
-}
-
-gpointer
-mono_arch_get_throw_exception_by_name_full (guint32 *code_size, MonoJumpInfo **ji, gboolean aot)
-{
- guint8* start;
- guint8 *code;
-
- *ji = NULL;
-
- start = code = mono_global_codeman_reserve (64);
-
- /* Not used on ARM */
- ARM_DBRK (code);
-
- *code_size = code - start;
-
- return start;
+ return mono_arch_get_throw_exception_generic (132, FALSE, FALSE, info, aot);
}
/**
* On ARM, the ip is passed instead of an offset.
*/
gpointer
-mono_arch_get_throw_corlib_exception_full (guint32 *code_size, MonoJumpInfo **ji, gboolean aot)
+mono_arch_get_throw_corlib_exception (MonoTrampInfo **info, gboolean aot)
{
- return mono_arch_get_throw_exception_generic (168, TRUE, FALSE, code_size, ji, aot);
+ return mono_arch_get_throw_exception_generic (168, TRUE, FALSE, info, aot);
}
/*
#endif
}
+/*
+ * handle_exception:
+ *
+ * Called by resuming from a signal handler.
+ */
+static void
+handle_signal_exception (gpointer obj, gboolean test_only)
+{
+ MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoContext ctx;
+ static void (*restore_context) (MonoContext *);
+
+ if (!restore_context)
+ restore_context = mono_get_restore_context ();
+
+ memcpy (&ctx, &jit_tls->ex_ctx, sizeof (MonoContext));
+
+ mono_handle_exception (&ctx, obj, MONO_CONTEXT_GET_IP (&ctx), test_only);
+
+ restore_context (&ctx);
+}
+
/*
* This is the function called from the signal handler
*/
gboolean
mono_arch_handle_exception (void *ctx, gpointer obj, gboolean test_only)
{
+#if defined(MONO_CROSS_COMPILE)
+ g_assert_not_reached ();
+#elif defined(MONO_ARCH_USE_SIGACTION)
+ my_ucontext *sigctx = ctx;
+ /*
+ * Handling the exception in the signal handler is problematic, since the original
+ * 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 = TlsGetValue (mono_jit_tls_id);
+ guint64 sp = UCONTEXT_REG_SP (sigctx);
+
+ /* Pass the ctx parameter in TLS */
+ mono_arch_sigctx_to_monoctx (sigctx, &jit_tls->ex_ctx);
+ /* The others in registers */
+ UCONTEXT_REG_R0 (sigctx) = (gsize)obj;
+ UCONTEXT_REG_R1 (sigctx) = test_only;
+
+ /* Allocate a stack frame */
+ sp -= 16;
+ UCONTEXT_REG_SP (sigctx) = sp;
+
+ UCONTEXT_REG_PC (sigctx) = (gsize)handle_signal_exception;
+
+ return TRUE;
+#else
MonoContext mctx;
gboolean result;
*/
mono_arch_monoctx_to_sigctx (&mctx, ctx);
return result;
+#endif
}
gpointer