This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libgo patch committed: Better error message if malloc gets SIGSEGV


Previously, if a SIGSEGV occurred during an malloc, perhaps due to a
corrupt heap, this would start a panic as usual, and the panic would
itself allocate memory, potentially leading to another SIGSEGV, and then
to a "malloc/free - deadlock" message.  That is not very useful.  This
patch checks for whether a signal occurs during memory allocation.  If
it does, we just abort the program immediately, as a panic is unlikely
to succeed.  Committed to mainline.

Ian

diff -r a3f3fa2f104e libgo/runtime/go-signal.c
--- a/libgo/runtime/go-signal.c	Mon Dec 13 21:12:33 2010 -0800
+++ b/libgo/runtime/go-signal.c	Mon Dec 13 21:16:34 2010 -0800
@@ -133,6 +133,12 @@
     {
       sigset_t clear;
 
+      if (__sync_bool_compare_and_swap (&m->mallocing, 1, 1))
+	{
+	  fprintf (stderr, "caught signal while mallocing: %s\n", msg);
+	  __go_assert (0);
+	}
+
       /* The signal handler blocked signals; unblock them.  */
       i = sigfillset (&clear);
       __go_assert (i == 0);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]