[MLton-commit] r7397

Matthew Fluet fluet at mlton.org
Tue Jan 19 10:58:48 PST 2010


Fix signal handling regressions on Mac OS X >= 10.5.

Contrary to the documentation, the alternate signal stack is not
inherited by a forked process.
----------------------------------------------------------------------

U   mlton/trunk/runtime/basis/Posix/Process/fork.c
U   mlton/trunk/runtime/gc/signals.c
U   mlton/trunk/runtime/gc/signals.h

----------------------------------------------------------------------

Modified: mlton/trunk/runtime/basis/Posix/Process/fork.c
===================================================================
--- mlton/trunk/runtime/basis/Posix/Process/fork.c	2010-01-19 18:58:33 UTC (rev 7396)
+++ mlton/trunk/runtime/basis/Posix/Process/fork.c	2010-01-19 18:58:43 UTC (rev 7397)
@@ -1,5 +1,17 @@
 #include "platform.h"
 
+extern struct GC_state gcState;
+
 C_Errno_t(C_PId_t) Posix_Process_fork (void) {
-  return fork ();
+  pid_t pid = fork ();
+#if (defined (__Darwin__))
+  /* Contrary to the documentation, a forked process does not inherit
+   * the alternate signal stack; re-install the alternate signal
+   * stack.
+   */
+  if (pid == 0) {
+    GC_initSignalStack(&gcState);
+  }
+#endif
+  return pid;
 }

Modified: mlton/trunk/runtime/gc/signals.c
===================================================================
--- mlton/trunk/runtime/gc/signals.c	2010-01-19 18:58:33 UTC (rev 7396)
+++ mlton/trunk/runtime/gc/signals.c	2010-01-19 18:58:43 UTC (rev 7397)
@@ -1,4 +1,5 @@
-/* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 2010 Matthew Fluet.
+ * Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -14,14 +15,23 @@
 #else
 
 void initSignalStack (GC_state s) {
+  static bool init = FALSE;
   static stack_t altstack;
-  size_t ss_size = align (SIGSTKSZ, s->sysvals.pageSize);
-  size_t psize = s->sysvals.pageSize;
-  void *ss_sp = GC_mmapAnon_safe_protect (NULL, 2 * ss_size, psize, psize);
-  altstack.ss_sp = (void*)((pointer)ss_sp + ss_size);
-  altstack.ss_size = ss_size;
-  altstack.ss_flags = 0;
+
+  if (! init) {
+    init = TRUE;
+    size_t ss_size = align (SIGSTKSZ, s->sysvals.pageSize);
+    size_t psize = s->sysvals.pageSize;
+    void *ss_sp = GC_mmapAnon_safe_protect (NULL, 2 * ss_size, psize, psize);
+    altstack.ss_sp = (void*)((pointer)ss_sp + ss_size);
+    altstack.ss_size = ss_size;
+    altstack.ss_flags = 0;
+  }
   sigaltstack (&altstack, NULL);
 }
 
 #endif
+
+void GC_initSignalStack (GC_state s) {
+  initSignalStack (s);
+}

Modified: mlton/trunk/runtime/gc/signals.h
===================================================================
--- mlton/trunk/runtime/gc/signals.h	2010-01-19 18:58:33 UTC (rev 7396)
+++ mlton/trunk/runtime/gc/signals.h	2010-01-19 18:58:43 UTC (rev 7397)
@@ -1,4 +1,5 @@
-/* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
+/* Copyright (C) 2010 Matthew Fluet.
+ * Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
  *    Jagannathan, and Stephen Weeks.
  * Copyright (C) 1997-2000 NEC Research Institute.
  *
@@ -34,3 +35,5 @@
 static void initSignalStack (GC_state s);
 
 #endif /* (defined (MLTON_GC_INTERNAL_FUNCS)) */
+
+void GC_initSignalStack (GC_state s);




More information about the MLton-commit mailing list