[Mono-dev] [PATCH] altstack for osx
Paolo Molaro
lupus at ximian.com
Thu Jul 1 09:12:50 EDT 2010
On 06/23/10 Geoff Norton wrote:
> Attached is a patch which enables sigaltstack for OSX (x86 and amd64).
>
> The configure.in check passes on amd64 and fails on x86 for some reason (the signal isn't delivered to the child ?)
> but the support appears to work correctly on both.
> --- a/mono/mini/exceptions-amd64.c
> +++ b/mono/mini/exceptions-amd64.c
> @@ -723,7 +723,6 @@ handle_signal_exception (gpointer obj, gboolean test_only)
> gboolean
> mono_arch_handle_exception (void *sigctx, gpointer obj, gboolean test_only)
> {
> -#if defined(MONO_ARCH_USE_SIGACTION) && defined(UCONTEXT_GREGS)
> /*
> * 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
> @@ -748,29 +747,8 @@ mono_arch_handle_exception (void *sigctx, gpointer obj, gboolean test_only)
> UCONTEXT_REG_RIP (sigctx) = (guint64)handle_signal_exception;
>
> return TRUE;
> -#else
> - MonoContext mctx;
> -
> - mono_arch_sigctx_to_monoctx (sigctx, &mctx);
> -
> - if (mono_debugger_handle_exception (&mctx, (MonoObject *)obj))
> - return TRUE;
> -
> - mono_handle_exception (&mctx, obj, MONO_CONTEXT_GET_IP (&mctx), test_only);
> -
> - mono_arch_monoctx_to_sigctx (&mctx, sigctx);
> -
> - return TRUE;
> -#endif
I would leave the alternate code in, it may be needed for other ports.
> diff --git a/mono/mini/mini-exceptions.c b/mono/mini/mini-exceptions.c
> index 5a73ac9..3881b7e 100644
> --- a/mono/mini/mini-exceptions.c
> +++ b/mono/mini/mini-exceptions.c
> @@ -1594,13 +1594,23 @@ mono_handle_exception (MonoContext *ctx, gpointer obj, gpointer original_ip, gbo
> #error "Can't use sigaltstack without sigaction"
> #endif
>
> +/*
> + * Handling a ovf on osx requires a lot more stack space than on linux because
> + * we might end up in CoreFoundation getting the locale
You might want to adjust also the minimum thread stack size to account
for this (adding a check in metadata/threads.c). Bonus points for also
fixing the race with the mono_threads_set_default_stacksize() calls in
threadpool.c (maybe adding a stack size argument to
mono_thread_create_internal() in a separate patch).
> @@ -1682,13 +1699,19 @@ static gboolean
> try_restore_stack_protection (MonoJitTlsData *jit_tls, int extra_bytes)
> {
> gint32 unprotect_size = jit_tls->stack_ovf_guard_size;
> + /* OSX requires a ton of stack space when we're handling an overflow exception, because
> + * we might call into corefoundation to get the locale and other such things
> + * as such we'll just give the entire page back to the system
> + */
In this case some of the more complex stack overflow scenarios won't be
handled. We unprotect a page at a time to have a chance of handling
an additional overflow during finally or catch handlers.
Anyway, the patch is ok to commit.
Thanks!
lupus
--
-----------------------------------------------------------------
lupus at debian.org debian/rules
lupus at ximian.com Monkeys do it better
More information about the Mono-devel-list
mailing list