[commit: ghc] ghc-7.8: rts/Capability.c: fix crash in -threaded mode on UNREG build (645d1ec)

git at git.haskell.org git at git.haskell.org
Mon Feb 17 10:26:23 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-7.8
Link       : http://ghc.haskell.org/trac/ghc/changeset/645d1ec0a67a05aae75cc4d53e1fbc9664481589/ghc

>---------------------------------------------------------------

commit 645d1ec0a67a05aae75cc4d53e1fbc9664481589
Author: Sergei Trofimovich <slyfox at gentoo.org>
Date:   Thu Feb 13 07:26:05 2014 -0600

    rts/Capability.c: fix crash in -threaded mode on UNREG build
    
    UNREG mode has quite nasty invariant to maintain:
        capabilities[0] == &MainCapability
    
    and it's a non-heap memory, while other
    capabilities are dynamically allocated.
    
    Issue #8748
    
    Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org>
    Signed-off-by: Austin Seipp <austin at well-typed.com>
    (cherry picked from commit ebace6969f0ec85b1caa0fea265a5f9990a23b2e)


>---------------------------------------------------------------

645d1ec0a67a05aae75cc4d53e1fbc9664481589
 rts/Capability.c |   22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/rts/Capability.c b/rts/Capability.c
index 5988d42..16b71b7 100644
--- a/rts/Capability.c
+++ b/rts/Capability.c
@@ -357,15 +357,18 @@ moreCapabilities (nat from USED_IF_THREADS, nat to USED_IF_THREADS)
         // BaseReg (eg. unregisterised), so in this case
 	// capabilities[0] must coincide with &MainCapability.
         capabilities[0] = &MainCapability;
+        initCapability(&MainCapability, 0);
     }
-
-    for (i = 0; i < to; i++) {
-        if (i < from) {
-            capabilities[i] = old_capabilities[i];
-        } else {
-            capabilities[i] = stgMallocBytes(sizeof(Capability),
-                                             "moreCapabilities");
-            initCapability(capabilities[i], i);
+    else
+    {
+        for (i = 0; i < to; i++) {
+            if (i < from) {
+                capabilities[i] = old_capabilities[i];
+            } else {
+                capabilities[i] = stgMallocBytes(sizeof(Capability),
+                                                 "moreCapabilities");
+                initCapability(capabilities[i], i);
+            }
         }
     }
 
@@ -983,7 +986,8 @@ freeCapabilities (void)
     nat i;
     for (i=0; i < n_capabilities; i++) {
         freeCapability(capabilities[i]);
-        stgFree(capabilities[i]);
+        if (capabilities[i] != &MainCapability)
+            stgFree(capabilities[i]);
     }
 #else
     freeCapability(&MainCapability);



More information about the ghc-commits mailing list