[pypy-commit] stmgc default: Restore the setting of PROT_NONE pages after a fork()

arigo noreply at buildbot.pypy.org
Mon Mar 24 15:14:45 CET 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r1086:62382817df4c
Date: 2014-03-24 15:14 +0100
http://bitbucket.org/pypy/stmgc/changeset/62382817df4c/

Log:	Restore the setting of PROT_NONE pages after a fork()

diff --git a/c7/stm/forksupport.c b/c7/stm/forksupport.c
--- a/c7/stm/forksupport.c
+++ b/c7/stm/forksupport.c
@@ -12,6 +12,7 @@
 static bool fork_was_in_transaction;
 
 static char *setup_mmap(char *reason);            /* forward, in setup.c */
+static void setup_protection_settings(void);      /* forward, in setup.c */
 static pthread_t *_get_cpth(stm_thread_local_t *);/* forward, in setup.c */
 
 
@@ -226,6 +227,10 @@
     }
     assert(stm_all_thread_locals == fork_this_tl);
 
+    /* Restore the base setting of PROT_NONE pages.
+     */
+    setup_protection_settings();
+
     /* Make all pages shared again.
      */
     uintptr_t pagenum, endpagenum;
diff --git a/c7/stm/setup.c b/c7/stm/setup.c
--- a/c7/stm/setup.c
+++ b/c7/stm/setup.c
@@ -14,6 +14,30 @@
     return result;
 }
 
+static void setup_protection_settings(void)
+{
+    /* The segment 0 is not used to run transactions, but contains the
+       shared copy of the pages.  We mprotect all pages before so that
+       accesses fail, up to and including the pages corresponding to the
+       nurseries of the other segments. */
+    mprotect(stm_object_pages, END_NURSERY_PAGE * 4096UL, PROT_NONE);
+
+    long i;
+    for (i = 1; i <= NB_SEGMENTS; i++) {
+        char *segment_base = get_segment_base(i);
+
+        /* In each segment, the first page is where TLPREFIX'ed
+           NULL accesses land.  We mprotect it so that accesses fail. */
+        mprotect(segment_base, 4096, PROT_NONE);
+
+        /* Pages in range(2, FIRST_READMARKER_PAGE) are never used */
+        if (FIRST_READMARKER_PAGE > 2)
+            mprotect(segment_base + 8192,
+                     (FIRST_READMARKER_PAGE - 2) * 4096UL,
+                     PROT_NONE);
+    }
+}
+
 void stm_setup(void)
 {
     /* Check that some values are acceptable */
@@ -32,33 +56,18 @@
     assert(_STM_FAST_ALLOC <= NB_NURSERY_PAGES * 4096);
 
     stm_object_pages = setup_mmap("initial stm_object_pages mmap()");
-
-    /* The segment 0 is not used to run transactions, but contains the
-       shared copy of the pages.  We mprotect all pages before so that
-       accesses fail, up to and including the pages corresponding to the
-       nurseries of the other segments. */
-    mprotect(stm_object_pages, END_NURSERY_PAGE * 4096UL, PROT_NONE);
+    setup_protection_settings();
 
     long i;
     for (i = 1; i <= NB_SEGMENTS; i++) {
         char *segment_base = get_segment_base(i);
 
-        /* In each segment, the first page is where TLPREFIX'ed
-           NULL accesses land.  We mprotect it so that accesses fail. */
-        mprotect(segment_base, 4096, PROT_NONE);
-
         /* Fill the TLS page (page 1) with 0xDC, for debugging */
         memset(REAL_ADDRESS(segment_base, 4096), 0xDC, 4096);
         /* Make a "hole" at STM_PSEGMENT (which includes STM_SEGMENT) */
         memset(REAL_ADDRESS(segment_base, STM_PSEGMENT), 0,
                sizeof(*STM_PSEGMENT));
 
-        /* Pages in range(2, FIRST_READMARKER_PAGE) are never used */
-        if (FIRST_READMARKER_PAGE > 2)
-            mprotect(segment_base + 8192,
-                     (FIRST_READMARKER_PAGE - 2) * 4096UL,
-                     PROT_NONE);
-
         /* Initialize STM_PSEGMENT */
         struct stm_priv_segment_info_s *pr = get_priv_segment(i);
         assert(1 <= i && i < 255);   /* 255 is WL_VISITED in gcpage.c */


More information about the pypy-commit mailing list