[MLton-commit] r6978

Wesley Terpstra wesley at mlton.org
Wed Nov 5 07:26:40 PST 2008


Ensure that the current thread's stack is traceable by the collector.
It (might be) possible to pass an object to MLton.size that can reach the
current thread. If we don't have a valid return address and an up-to-date
used value for the stack, the collector will segfault tracing the stack.


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

U   mlton/trunk/mlton/backend/ssa-to-rssa.fun
U   mlton/trunk/runtime/gc/size.c

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

Modified: mlton/trunk/mlton/backend/ssa-to-rssa.fun
===================================================================
--- mlton/trunk/mlton/backend/ssa-to-rssa.fun	2008-11-04 19:20:08 UTC (rev 6977)
+++ mlton/trunk/mlton/backend/ssa-to-rssa.fun	2008-11-05 15:26:39 UTC (rev 6978)
@@ -250,11 +250,14 @@
             convention = Cdecl,
             ensuresBytesFree = false,
             mayGC = false,
-            maySwitchThreads = false,
+            maySwitchThreads = true, (* Ensure the stack has a return address
+                                      * this guards against the GC possibly
+                                      * tracing the current thread's stack.
+                                      *)
             modifiesFrontier = false,
             prototype = (Vector.new2 (CType.gcState, CType.cpointer),
                          SOME (CType.csize ())),
-            readsStackTop = false,
+            readsStackTop = true,
             return = Type.csize (),
             symbolScope = Private,
             target = Direct "GC_size",

Modified: mlton/trunk/runtime/gc/size.c
===================================================================
--- mlton/trunk/runtime/gc/size.c	2008-11-04 19:20:08 UTC (rev 6977)
+++ mlton/trunk/runtime/gc/size.c	2008-11-05 15:26:39 UTC (rev 6978)
@@ -8,12 +8,15 @@
 
 size_t GC_size (GC_state s, pointer root) {
   size_t res;
-
+  
+  enter(s); /* write a valid stack header in case it is reached */
   if (DEBUG_SIZE)
     fprintf (stderr, "GC_size marking\n");
   res = dfsMarkByMode (s, root, MARK_MODE, FALSE, FALSE);
   if (DEBUG_SIZE)
     fprintf (stderr, "GC_size unmarking\n");
   dfsMarkByMode (s, root, UNMARK_MODE, FALSE, FALSE);
+  leave(s);
+  
   return res;
 }




More information about the MLton-commit mailing list