Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r971:58c5e282befd
Date: 2014-03-11 08:44 +0100
http://bitbucket.org/pypy/stmgc/changeset/58c5e282befd/

Log:    Clear bytes of raw memory on abort

diff --git a/c7/stm/core.c b/c7/stm/core.c
--- a/c7/stm/core.c
+++ b/c7/stm/core.c
@@ -498,6 +498,11 @@
 
     stm_jmpbuf_t *jmpbuf_ptr = STM_SEGMENT->jmpbuf_ptr;
 
+    /* clear memory registered on the thread-local */
+    stm_thread_local_t *tl = STM_SEGMENT->running_thread;
+    if (tl->mem_clear_on_abort)
+        memset(tl->mem_clear_on_abort, 0, tl->mem_bytes_to_clear_on_abort);
+
     if (STM_SEGMENT->nursery_end == NSE_SIGABORT)
         STM_SEGMENT->nursery_end = NURSERY_END;   /* done aborting */
 
diff --git a/c7/stmgc.h b/c7/stmgc.h
--- a/c7/stmgc.h
+++ b/c7/stmgc.h
@@ -53,6 +53,10 @@
     object_t **shadowstack, **shadowstack_base;
     /* a generic optional thread-local object */
     object_t *thread_local_obj;
+    /* in case this thread runs a transaction that aborts,
+       the following raw region of memory is cleared. */
+    char *mem_clear_on_abort;
+    size_t mem_bytes_to_clear_on_abort;
     /* the next fields are handled automatically by the library */
     int associated_segment_num;
     struct stm_thread_local_s *prev, *next;
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -15,6 +15,8 @@
 typedef struct {
     object_t **shadowstack, **shadowstack_base;
     object_t *thread_local_obj;
+    char *mem_clear_on_abort;
+    size_t mem_bytes_to_clear_on_abort;
     int associated_segment_num;
     ...;
 } stm_thread_local_t;
@@ -405,6 +407,9 @@
             lib.stm_unregister_thread_local(tl)
         lib.stm_teardown()
 
+    def get_stm_thread_local(self):
+        return self.tls[self.current_thread]
+
     def start_transaction(self):
         tl = self.tls[self.current_thread]
         assert not lib._stm_in_transaction(tl)
diff --git a/c7/test/test_extra.py b/c7/test/test_extra.py
new file mode 100644
--- /dev/null
+++ b/c7/test/test_extra.py
@@ -0,0 +1,19 @@
+from support import *
+import py
+
+class TestExtra(BaseTest):
+
+    def test_clear_on_abort(self):
+        p = ffi.new("char[]", "hello")
+        tl = self.get_stm_thread_local()
+        tl.mem_clear_on_abort = p
+        tl.mem_bytes_to_clear_on_abort = 2
+        #
+        self.start_transaction()
+        assert ffi.string(p) == "hello"
+        self.abort_transaction()
+        assert p[0] == '\0'
+        assert p[1] == '\0'
+        assert p[2] == 'l'
+        assert p[3] == 'l'
+        assert p[4] == 'o'
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to