static gpointer try_more_restore_tramp = NULL;
static gpointer restore_stack_protection_tramp = NULL;
-static MonoUnhandledExceptionFunc unhandled_exception_hook = NULL;
-static gpointer unhandled_exception_hook_data = NULL;
-
static void try_more_restore (void);
static void restore_stack_protection (void);
static void mono_walk_stack_full (MonoJitStackWalk func, MonoContext *start_ctx, MonoDomain *domain, MonoJitTlsData *jit_tls, MonoLMF *lmf, MonoUnwindOptions unwind_options, gpointer user_data);
static void mono_raise_exception_with_ctx (MonoException *exc, MonoContext *ctx);
static void mono_runtime_walk_stack_with_ctx (MonoJitStackWalk func, MonoContext *start_ctx, MonoUnwindOptions unwind_options, void *user_data);
+static gboolean mono_current_thread_has_handle_block_guard (void);
void
mono_exceptions_init (void)
cbs.mono_raise_exception_with_ctx = mono_raise_exception_with_ctx;
cbs.mono_exception_walk_trace = mono_exception_walk_trace;
cbs.mono_install_handler_block_guard = mono_install_handler_block_guard;
+ cbs.mono_current_thread_has_handle_block_guard = mono_current_thread_has_handle_block_guard;
mono_install_eh_callbacks (&cbs);
}
if (mono_mprotect (tls->stack_ovf_guard_base, tls->stack_ovf_guard_size, MONO_MMAP_NONE)) {
/* mprotect can fail for the main thread stack */
- gpointer gaddr = mono_valloc (tls->stack_ovf_guard_base, tls->stack_ovf_guard_size, MONO_MMAP_NONE|MONO_MMAP_PRIVATE|MONO_MMAP_ANON|MONO_MMAP_FIXED);
+ gpointer gaddr = mono_valloc (tls->stack_ovf_guard_base, tls->stack_ovf_guard_size, MONO_MMAP_NONE|MONO_MMAP_PRIVATE|MONO_MMAP_ANON|MONO_MMAP_FIXED, MONO_MEM_ACCOUNT_EXCEPTIONS);
g_assert (gaddr == tls->stack_ovf_guard_base);
tls->stack_ovf_valloced = TRUE;
}
/* Setup an alternate signal stack */
- tls->signal_stack = mono_valloc (0, MONO_ARCH_SIGNAL_STACK_SIZE, MONO_MMAP_READ|MONO_MMAP_WRITE|MONO_MMAP_PRIVATE|MONO_MMAP_ANON);
+ tls->signal_stack = mono_valloc (0, MONO_ARCH_SIGNAL_STACK_SIZE, MONO_MMAP_READ|MONO_MMAP_WRITE|MONO_MMAP_PRIVATE|MONO_MMAP_ANON, MONO_MEM_ACCOUNT_EXCEPTIONS);
tls->signal_stack_size = MONO_ARCH_SIGNAL_STACK_SIZE;
g_assert (tls->signal_stack);
g_assert (err == 0);
if (tls->signal_stack)
- mono_vfree (tls->signal_stack, MONO_ARCH_SIGNAL_STACK_SIZE);
+ mono_vfree (tls->signal_stack, MONO_ARCH_SIGNAL_STACK_SIZE, MONO_MEM_ACCOUNT_EXCEPTIONS);
if (tls->stack_ovf_valloced)
- mono_vfree (tls->stack_ovf_guard_base, tls->stack_ovf_guard_size);
+ mono_vfree (tls->stack_ovf_guard_base, tls->stack_ovf_guard_size, MONO_MEM_ACCOUNT_EXCEPTIONS);
else
mono_mprotect (tls->stack_ovf_guard_base, tls->stack_ovf_guard_size, MONO_MMAP_READ|MONO_MMAP_WRITE);
}
for (i =0; i < size; ++i) {
mono_runtime_printf_err ("\t%s", names [i]);
}
- free (names);
+ g_free (names);
/* Try to get more meaningful information using gdb */
#endif
GString* text;
char *name;
-#ifndef HOST_WIN32
- char *wapi_desc;
-#endif
GError *error = NULL;
if (!thread)
else
g_string_append (text, "\n\"<unnamed thread>\"");
-#ifndef HOST_WIN32
- wapi_desc = wapi_current_thread_desc ();
- g_string_append_printf (text, " tid=0x%p this=0x%p %s\n", (gpointer)(gsize)thread->tid, thread, wapi_desc);
- free (wapi_desc);
-#endif
+ g_string_append_printf (text, " tid=0x%p this=0x%p ", (gpointer)(gsize)thread->tid, thread);
+ mono_thread_internal_describe (thread, text);
+ g_string_append (text, "\n");
#ifdef MONO_ARCH_HAVE_SIGCTX_TO_MONOCTX
if (start_ctx) {
/*
* Finds the bottom handler block running and install a block guard if needed.
- * FIXME add full-aot support.
*/
gboolean
mono_install_handler_block_guard (MonoThreadUnwindState *ctx)
MonoJitTlsData *jit_tls = (MonoJitTlsData *)ctx->unwind_data [MONO_UNWIND_DATA_JIT_TLS];
gpointer resume_ip;
- /* FIXME */
+#ifndef MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD_AOT
if (mono_aot_only)
return FALSE;
+#endif
/* Guard against a null MonoJitTlsData. This can happens if the thread receives the
* interrupt signal before the JIT has time to initialize its TLS data for the given thread.
return TRUE;
}
+static gboolean
+mono_current_thread_has_handle_block_guard (void)
+{
+ MonoJitTlsData *jit_tls = (MonoJitTlsData *)mono_native_tls_get_value (mono_jit_tls_id);
+ return jit_tls && jit_tls->handler_block_return_address != NULL;
+}
+
#else
gboolean
mono_install_handler_block_guard (MonoThreadUnwindState *ctx)
return FALSE;
}
+static gboolean
+mono_current_thread_has_handle_block_guard (void)
+{
+ return FALSE;
+}
+
#endif
void
#endif
}
-void
-mono_install_unhandled_exception_hook (MonoUnhandledExceptionFunc func, gpointer user_data)
-{
- unhandled_exception_hook = func;
- unhandled_exception_hook_data = user_data;
-}
-
-void
-mono_invoke_unhandled_exception_hook (MonoObject *exc)
-{
- if (unhandled_exception_hook) {
- unhandled_exception_hook (exc, unhandled_exception_hook_data);
- } else {
- MonoError inner_error;
- MonoObject *other = NULL;
- MonoString *str = mono_object_try_to_string (exc, &other, &inner_error);
- char *msg = NULL;
-
- if (str && is_ok (&inner_error)) {
- msg = mono_string_to_utf8_checked (str, &inner_error);
- }
- if (!is_ok (&inner_error)) {
- msg = g_strdup_printf ("Nested exception while formatting original exception");
- mono_error_cleanup (&inner_error);
- } else if (other) {
- char *original_backtrace = mono_exception_get_managed_backtrace ((MonoException*)exc);
- char *nested_backtrace = mono_exception_get_managed_backtrace ((MonoException*)other);
-
- msg = g_strdup_printf ("Nested exception detected.\nOriginal Exception: %s\nNested exception:%s\n",
- original_backtrace, nested_backtrace);
-
- g_free (original_backtrace);
- g_free (nested_backtrace);
- } else {
- msg = g_strdup ("Nested exception trying to figure out what went wrong");
- }
- mono_runtime_printf_err ("[ERROR] FATAL UNHANDLED EXCEPTION: %s", msg);
- g_free (msg);
-#if defined(HOST_IOS)
- g_assertion_message ("Terminating runtime due to unhandled exception");
-#else
- exit (mono_environment_exitcode_get ());
-#endif
- }
-
- g_assert_not_reached ();
-}
-
/*
* mono_restore_context:
*