Author: Remi Meier <meier...@student.ethz.ch>
Branch: 
Changeset: r326:18b8edd35778
Date: 2013-07-01 11:18 +0200
http://bitbucket.org/pypy/stmgc/changeset/18b8edd35778/

Log:    fix uninitialized shadowstack problem during major collection

diff --git a/c4/et.c b/c4/et.c
--- a/c4/et.c
+++ b/c4/et.c
@@ -1504,7 +1504,6 @@
       revision_t i;
       struct tx_descriptor *d = stm_malloc(sizeof(struct tx_descriptor));
       memset(d, 0, sizeof(struct tx_descriptor));
-      stmgcpage_acquire_global_lock();
 
       struct tx_public_descriptor *pd;
       i = descriptor_array_free_list;
@@ -1554,7 +1553,6 @@
                (long)d->public_descriptor_index, (long)pthread_self()));
 
       stmgcpage_init_tls();
-      stmgcpage_release_global_lock();
       return 1;
     }
   else
@@ -1567,7 +1565,6 @@
     struct tx_descriptor *d = thread_descriptor;
     assert(d != NULL);
     assert(d->active == 0);
-    stmgcpage_acquire_global_lock();
 
     /* our nursery is empty at this point.  The list 'stolen_objects'
        should have been emptied at the previous minor collection and
@@ -1585,7 +1582,6 @@
     if (d->tx_prev != NULL) d->tx_prev->tx_next = d->tx_next;
     if (d->tx_next != NULL) d->tx_next->tx_prev = d->tx_prev;
     if (d == stm_tx_head) stm_tx_head = d->tx_next;
-    stmgcpage_release_global_lock();
 
     thread_descriptor = NULL;
 
diff --git a/c4/gcpage.c b/c4/gcpage.c
--- a/c4/gcpage.c
+++ b/c4/gcpage.c
@@ -625,6 +625,7 @@
         if (d != saved) {
             /* Hack: temporarily pretend that we "are" the other thread...
              */
+            assert(d->shadowstack_end_ref && *d->shadowstack_end_ref);
             thread_descriptor = d;
             stm_private_rev_num = *d->private_revision_ref;
             stm_read_barrier_cache = *d->read_barrier_cache_ref;
diff --git a/c4/nursery.c b/c4/nursery.c
--- a/c4/nursery.c
+++ b/c4/nursery.c
@@ -198,7 +198,8 @@
         return (revision_t)p;
     }
     
-
+    /* XXX: think about if p->h_original needs a volatile read
+       and if we need a memory fence (smp_wmb())... */
     
     spinlock_acquire(d->public_descriptor->collection_lock, 'I');
     /* old objects must have an h_original xOR be
diff --git a/c4/stmsync.c b/c4/stmsync.c
--- a/c4/stmsync.c
+++ b/c4/stmsync.c
@@ -79,12 +79,14 @@
 
 void stm_initialize(void)
 {
+    stmgcpage_acquire_global_lock();
     int r = DescriptorInit();
     if (r != 1)
         stm_fatalerror("stm_initialize: DescriptorInit failure\n");
     stmgc_init_nursery();
     init_shadowstack();
     //stmgcpage_init_tls();
+    stmgcpage_release_global_lock();
     BeginInevitableTransaction();
 }
 
@@ -92,10 +94,12 @@
 {
     stmgc_minor_collect();   /* force everything out of the nursery */
     CommitTransaction();
+    stmgcpage_acquire_global_lock();
     //stmgcpage_done_tls();
     done_shadowstack();
     stmgc_done_nursery();
     DescriptorDone();
+    stmgcpage_release_global_lock();
 }
 
 /************************************************************/
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to