Skip to content

Commit 2ce87ce

Browse files
committed
Remove HAVE_WORKING_SIGALTSTACK
Not enabled in dotnet/runtime since the beginning. It was also making crashes harder to investigate because we wouldn't get "normal" stack traces that GDB could understand.
1 parent e7d9b70 commit 2ce87ce

24 files changed

Lines changed: 3 additions & 716 deletions

src/mono/cmake/config.h.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,6 @@
536536
and to 0 if you don't. */
537537
#cmakedefine HAVE_DECL_PTHREAD_MUTEXATTR_SETPROTOCOL 1
538538

539-
/* Have a working sigaltstack */
540-
#cmakedefine HAVE_WORKING_SIGALTSTACK 1
541-
542539
/* Define to 1 if you have the `shm_open' function. */
543540
#cmakedefine HAVE_SHM_OPEN 1
544541

src/mono/mono.proj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@
378378
<_MonoCMakeArgs Include="-DENABLE_MINIMAL=jit,logging,shared_perfcounters" />
379379
<_MonoCMakeArgs Include="-DENABLE_VISIBILITY_HIDDEN=1"/>
380380
<_MonoCMakeArgs Include="-DENABLE_LAZY_GC_THREAD_CREATION=1"/>
381-
<_MonoCMakeArgs Include="-DENABLE_SIGALTSTACK=0"/>
382381
<_MonoCMakeArgs Include="-DENABLE_ICALL_EXPORT=1"/>
383382
<_MonoCFLAGS Include="-Werror=partial-availability" />
384383
<_MonoCFLAGS Condition="'$(TargetstvOS)' == 'true'" Include="-fno-gnu-inline-asm" />
@@ -406,7 +405,6 @@
406405
<_MonoCMakeArgs Condition="'$(Platform)' == 'x86'" Include="-DANDROID_ABI=x86" />
407406
<_MonoCMakeArgs Condition="'$(Platform)' == 'x64'" Include="-DANDROID_ABI=x86_64" />
408407
<_MonoCMakeArgs Include="-DENABLE_MINIMAL=ssa,logging" />
409-
<_MonoCMakeArgs Include="-DENABLE_SIGALTSTACK=1"/>
410408

411409
<_MonoCFLAGS Condition="'$(Platform)' == 'arm'" Include="-march=armv7-a" />
412410
<_MonoCFLAGS Condition="'$(Platform)' == 'arm'" Include="-mtune=cortex-a8" />

src/mono/mono/component/debugger-agent.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4316,7 +4316,6 @@ resume_from_signal_handler (void *sigctx, void *func)
43164316
MonoContext ctx;
43174317

43184318
/* Save the original context in TLS */
4319-
// FIXME: This might not work on an altstack ?
43204319
tls = (DebuggerTlsData *)mono_native_tls_get_value (debugger_tls_id);
43214320
if (!tls)
43224321
PRINT_ERROR_MSG ("Thread %p is not attached to the JIT.\n", (gpointer) (gsize) mono_native_thread_id_get ());

src/mono/mono/metadata/boehm-gc.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,18 +1204,6 @@ mono_gc_get_vtable_bits (MonoClass *klass)
12041204
return 0;
12051205
}
12061206

1207-
/*
1208-
* mono_gc_register_altstack:
1209-
*
1210-
* Register the dimensions of the normal stack and altstack with the collector.
1211-
* Currently, STACK/STACK_SIZE is only used when the thread is suspended while it is on an altstack.
1212-
*/
1213-
void
1214-
mono_gc_register_altstack (gpointer stack, gint32 stack_size, gpointer altstack, gint32 altstack_size)
1215-
{
1216-
GC_register_altstack (stack, stack_size, altstack, altstack_size);
1217-
}
1218-
12191207
int
12201208
mono_gc_get_los_limit (void)
12211209
{

src/mono/mono/metadata/gc-internals.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,6 @@ MonoVTable *mono_gc_get_vtable (MonoObject *obj);
406406

407407
guint mono_gc_get_vtable_bits (MonoClass *klass);
408408

409-
void mono_gc_register_altstack (gpointer stack, gint32 stack_size, gpointer altstack, gint32 altstack_size);
410-
411409
gboolean mono_gc_is_critical_method (MonoMethod *method);
412410

413411
G_EXTERN_C // due to THREAD_INFO_TYPE varying

src/mono/mono/metadata/null-gc.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,6 @@ mono_gc_get_vtable_bits (MonoClass *klass)
606606
return 0;
607607
}
608608

609-
void
610-
mono_gc_register_altstack (gpointer stack, gint32 stack_size, gpointer altstack, gint32 altstack_size)
611-
{
612-
}
613-
614609
gboolean
615610
mono_gc_is_null (void)
616611
{

src/mono/mono/metadata/sgen-mono.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,12 +2861,6 @@ mono_gc_invoke_with_gc_lock (MonoGCLockedCallbackFunc func, void *data)
28612861
return result;
28622862
}
28632863

2864-
void
2865-
mono_gc_register_altstack (gpointer stack, gint32 stack_size, gpointer altstack, gint32 altstack_size)
2866-
{
2867-
// FIXME:
2868-
}
2869-
28702864
guint8*
28712865
mono_gc_get_card_table (int *shift_bits, gpointer *mask)
28722866
{

src/mono/mono/mini/driver.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,11 +1694,7 @@ mono_get_version_info (void)
16941694
g_string_append_printf (output, "\tTLS: \n");
16951695
#endif /* MONO_KEYWORD_THREAD */
16961696

1697-
#ifdef MONO_ARCH_SIGSEGV_ON_ALTSTACK
1698-
g_string_append_printf (output, "\tSIGSEGV: altstack\n");
1699-
#else
17001697
g_string_append_printf (output, "\tSIGSEGV: normal\n");
1701-
#endif
17021698

17031699
g_string_append_printf (output, "\tArchitecture: %s\n", MONO_ARCHITECTURE);
17041700
g_string_append_printf (output, "\tDisabled: %s\n", DISABLED_FEATURES);

src/mono/mono/mini/exceptions-amd64.c

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -829,110 +829,6 @@ mono_arch_ip_from_context (void *sigctx)
829829
#endif
830830
}
831831

832-
static MonoObject*
833-
restore_soft_guard_pages (void)
834-
{
835-
MonoJitTlsData *jit_tls = mono_tls_get_jit_tls ();
836-
if (jit_tls->stack_ovf_guard_base)
837-
mono_mprotect (jit_tls->stack_ovf_guard_base, jit_tls->stack_ovf_guard_size, MONO_MMAP_NONE);
838-
839-
if (jit_tls->stack_ovf_pending) {
840-
jit_tls->stack_ovf_pending = 0;
841-
return (MonoObject *)mini_get_stack_overflow_ex ();
842-
}
843-
844-
return NULL;
845-
}
846-
847-
/*
848-
* this function modifies mctx so that when it is restored, it
849-
* won't execcute starting at mctx.eip, but in a function that
850-
* will restore the protection on the soft-guard pages and return back to
851-
* continue at mctx.eip.
852-
*/
853-
static void
854-
prepare_for_guard_pages (MonoContext *mctx)
855-
{
856-
gpointer *sp;
857-
sp = (gpointer *)(mctx->gregs [AMD64_RSP]);
858-
sp -= 1;
859-
/* the return addr */
860-
sp [0] = (gpointer)(mctx->gregs [AMD64_RIP]);
861-
mctx->gregs [AMD64_RIP] = (guint64)restore_soft_guard_pages;
862-
mctx->gregs [AMD64_RSP] = (guint64)sp;
863-
}
864-
865-
static void
866-
altstack_handle_and_restore (MonoContext *ctx, MonoObject *obj, guint32 flags)
867-
{
868-
MonoContext mctx;
869-
MonoJitInfo *ji = mini_jit_info_table_find (MONO_CONTEXT_GET_IP (ctx));
870-
gboolean stack_ovf = (flags & 1) != 0;
871-
gboolean nullref = (flags & 2) != 0;
872-
873-
if (!ji || (!stack_ovf && !nullref)) {
874-
mono_handle_native_crash (mono_get_signame (SIGSEGV), ctx, NULL);
875-
// if couldn't dump or if mono_handle_native_crash returns, abort
876-
abort ();
877-
}
878-
879-
mctx = *ctx;
880-
881-
mono_handle_exception (&mctx, obj);
882-
if (stack_ovf) {
883-
MonoJitTlsData *jit_tls = mono_tls_get_jit_tls ();
884-
jit_tls->stack_ovf_pending = 1;
885-
prepare_for_guard_pages (&mctx);
886-
}
887-
mono_restore_context (&mctx);
888-
}
889-
890-
void
891-
mono_arch_handle_altstack_exception (void *sigctx, MONO_SIG_HANDLER_INFO_TYPE *siginfo, gpointer fault_addr, gboolean stack_ovf)
892-
{
893-
#if defined(MONO_ARCH_USE_SIGACTION)
894-
MonoException *exc = NULL;
895-
gpointer *sp;
896-
MonoJitTlsData *jit_tls = NULL;
897-
MonoContext *copied_ctx = NULL;
898-
gboolean nullref = TRUE;
899-
900-
jit_tls = mono_tls_get_jit_tls ();
901-
g_assert (jit_tls);
902-
903-
/* use TLS as temporary storage as we want to avoid
904-
* (1) stack allocation on the application stack
905-
* (2) calling malloc, because it is not async-safe
906-
* (3) using a global storage, because this function is not reentrant
907-
*
908-
* tls->orig_ex_ctx is used by the stack walker, which shouldn't be running at this point.
909-
*/
910-
copied_ctx = &jit_tls->orig_ex_ctx;
911-
912-
if (!mono_is_addr_implicit_null_check (fault_addr))
913-
nullref = FALSE;
914-
915-
if (stack_ovf)
916-
exc = mini_get_stack_overflow_ex ();
917-
918-
/* setup the call frame on the application stack so that control is
919-
* returned there and exception handling can continue. we want the call
920-
* frame to be minimal as possible, for example no argument passing that
921-
* requires allocation on the stack, as this wouldn't be encoded in unwind
922-
* information for the caller frame.
923-
*/
924-
sp = (gpointer *) ALIGN_DOWN_TO (UCONTEXT_REG_RSP (sigctx), 16);
925-
sp [-1] = (gpointer)UCONTEXT_REG_RIP (sigctx);
926-
mono_sigctx_to_monoctx (sigctx, copied_ctx);
927-
/* at the return from the signal handler execution starts in altstack_handle_and_restore() */
928-
UCONTEXT_REG_RIP (sigctx) = (unsigned long)altstack_handle_and_restore;
929-
UCONTEXT_REG_RSP (sigctx) = (unsigned long)(sp - 1);
930-
UCONTEXT_REG_RDI (sigctx) = (unsigned long)(copied_ctx);
931-
UCONTEXT_REG_RSI (sigctx) = (guint64)exc;
932-
UCONTEXT_REG_RDX (sigctx) = (stack_ovf ? 1 : 0) | (nullref ? 2 : 0);
933-
#endif
934-
}
935-
936832
#ifndef DISABLE_JIT
937833
GSList*
938834
mono_amd64_get_exception_trampolines (gboolean aot)

src/mono/mono/mini/exceptions-ppc.c

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -641,81 +641,6 @@ mono_arch_ip_from_context (void *sigctx)
641641
#endif
642642
}
643643

644-
static void
645-
altstack_handle_and_restore (MonoContext *mctx, gpointer obj)
646-
{
647-
mono_handle_exception (mctx, obj);
648-
mono_restore_context (mctx);
649-
}
650-
651-
void
652-
mono_arch_handle_altstack_exception (void *sigctx, MONO_SIG_HANDLER_INFO_TYPE *siginfo, gpointer fault_addr, gboolean stack_ovf)
653-
{
654-
#ifdef MONO_CROSS_COMPILE
655-
g_assert_not_reached ();
656-
#else
657-
#ifdef MONO_ARCH_USE_SIGACTION
658-
os_ucontext *uc = (os_ucontext*)sigctx;
659-
MonoContext *uc_copy;
660-
MonoJitInfo *ji = mini_jit_info_table_find (mono_arch_ip_from_context (sigctx));
661-
gpointer *sp;
662-
int frame_size;
663-
664-
if (stack_ovf) {
665-
const char *method;
666-
/* we don't do much now, but we can warn the user with a useful message */
667-
fprintf (stderr, "Stack overflow: IP: %p, SP: %p\n", mono_arch_ip_from_context (sigctx), (gpointer)UCONTEXT_REG_Rn(uc, 1));
668-
if (ji && !ji->is_trampoline && jinfo_get_method (ji))
669-
method = mono_method_full_name (jinfo_get_method (ji), TRUE);
670-
else
671-
method = "Unmanaged";
672-
fprintf (stderr, "At %s\n", method);
673-
abort ();
674-
}
675-
if (!ji)
676-
mono_handle_native_crash (mono_get_signame (SIGSEGV), (MonoContext*)sigctx, siginfo);
677-
/* setup a call frame on the real stack so that control is returned there
678-
* and exception handling can continue.
679-
* The frame looks like:
680-
* ucontext struct
681-
* ...
682-
* 224 is the size of the red zone
683-
*/
684-
frame_size = sizeof (MonoContext) + sizeof (gpointer) * 16 + 224;
685-
frame_size += 15;
686-
frame_size &= ~15;
687-
sp = (void**)(UCONTEXT_REG_Rn(uc, 1) & ~15);
688-
sp = (void**)((char*)sp - frame_size);
689-
/* may need to adjust pointers in the new struct copy, depending on the OS */
690-
uc_copy = (MonoContext*)(sp + 16);
691-
mono_sigctx_to_monoctx (uc, uc_copy);
692-
g_assert (mono_arch_ip_from_context (uc) == MONO_CONTEXT_GET_IP (uc_copy));
693-
/* at the return form the signal handler execution starts in altstack_handle_and_restore() */
694-
UCONTEXT_REG_LNK(uc) = UCONTEXT_REG_NIP(uc);
695-
#ifdef PPC_USES_FUNCTION_DESCRIPTOR
696-
{
697-
MonoPPCFunctionDescriptor *handler_ftnptr = (MonoPPCFunctionDescriptor*)altstack_handle_and_restore;
698-
699-
UCONTEXT_REG_NIP(uc) = (gulong)handler_ftnptr->code;
700-
UCONTEXT_REG_Rn(uc, 2) = (gulong)handler_ftnptr->toc;
701-
}
702-
#else
703-
UCONTEXT_REG_NIP(uc) = (unsigned long)altstack_handle_and_restore;
704-
#if _CALL_ELF == 2
705-
/* ELF v2 ABI calling convention requires to put the target address into
706-
* r12 if we use the global entry point of a function. */
707-
UCONTEXT_REG_Rn(uc, 12) = (unsigned long) altstack_handle_and_restore;
708-
#endif
709-
#endif
710-
UCONTEXT_REG_Rn(uc, 1) = (unsigned long)sp;
711-
UCONTEXT_REG_Rn(uc, PPC_FIRST_ARG_REG) = (unsigned long)uc_copy;
712-
UCONTEXT_REG_Rn(uc, PPC_FIRST_ARG_REG + 1) = 0;
713-
UCONTEXT_REG_Rn(uc, PPC_FIRST_ARG_REG + 2) = 0;
714-
#endif
715-
716-
#endif /* !MONO_CROSS_COMPILE */
717-
}
718-
719644
/*
720645
* handle_exception:
721646
*
@@ -778,7 +703,6 @@ mono_arch_handle_exception (void *ctx, gpointer obj)
778703
UCONTEXT_REG_Rn (sigctx, PPC_FIRST_ARG_REG) = (gsize)obj;
779704

780705
/* Allocate a stack frame below the red zone */
781-
/* Similar to mono_arch_handle_altstack_exception () */
782706
frame_size = 224;
783707
frame_size += 15;
784708
frame_size &= ~15;

0 commit comments

Comments
 (0)