[pypy-commit] stmgc default: Add a failing test for the preservation of the shadowstack

arigo noreply at buildbot.pypy.org
Tue Aug 12 14:54:53 CEST 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r1296:93f047b33b57
Date: 2014-08-12 14:54 +0200
http://bitbucket.org/pypy/stmgc/changeset/93f047b33b57/

Log:	Add a failing test for the preservation of the shadowstack

diff --git a/c7/test/test_rewind.c b/c7/test/test_rewind.c
--- a/c7/test/test_rewind.c
+++ b/c7/test/test_rewind.c
@@ -220,6 +220,49 @@
 
 /************************************************************/
 
+typedef struct { char foo; } object_t;
+struct stm_shadowentry_s { object_t *ss; };
+typedef struct {
+    struct stm_shadowentry_s *shadowstack;
+    struct stm_shadowentry_s _inline[99];
+} stm_thread_local_t;
+#define STM_PUSH_ROOT(tl, p)   ((tl).shadowstack++->ss = (object_t *)(p))
+#define STM_POP_ROOT(tl, p)    ((p) = (typeof(p))((--(tl).shadowstack)->ss))
+void stm_register_thread_local(stm_thread_local_t *tl) {
+    tl->shadowstack = tl->_inline;
+}
+void stm_unregister_thread_local(stm_thread_local_t *tl) { }
+static stm_thread_local_t tl;
+
+
+void testTL1(void)
+{
+    object_t *a1, *a2;
+    stm_register_thread_local(&tl);
+
+    rewind_jmp_buf buf;
+    rewind_jmp_enterframe(&gthread, &buf);
+
+    a1 = a2 = (object_t *)123456;
+    STM_PUSH_ROOT(tl, a1);
+
+    if (rewind_jmp_setjmp(&gthread) == 0) {
+        /* first path */
+        STM_POP_ROOT(tl, a2);
+        assert(a1 == a2);
+        STM_PUSH_ROOT(tl, NULL);
+        rewind_jmp_longjmp(&gthread);
+    }
+    /* second path */
+    STM_POP_ROOT(tl, a2);
+    assert(a1 == a2);
+
+    rewind_jmp_leaveframe(&gthread, &buf);
+    stm_unregister_thread_local(&tl);
+}
+
+/************************************************************/
+
 int rj_malloc_count = 0;
 
 void *rj_malloc(size_t size)
@@ -248,6 +291,7 @@
     else if (!strcmp(argv[1], "4"))  test4();
     else if (!strcmp(argv[1], "5"))  test5();
     else if (!strcmp(argv[1], "6"))  test6();
+    else if (!strcmp(argv[1], "TL1")) testTL1();
     else
         assert(!"bad argv[1]");
     assert(rj_malloc_count == 0);
diff --git a/c7/test/test_rewind.py b/c7/test/test_rewind.py
--- a/c7/test/test_rewind.py
+++ b/c7/test/test_rewind.py
@@ -1,17 +1,17 @@
 import os
 
 def run_test(opt):
-    err = os.system("clang -g -O%d -Werror -DRJBUF_CUSTOM_MALLOC -I../stm"
-                    " -o test_rewind_O%d test_rewind.c ../stm/rewind_setjmp.c"
+    err = os.system("clang -g -O%s -Werror -DRJBUF_CUSTOM_MALLOC -I../stm"
+                    " -o test_rewind_O%s test_rewind.c ../stm/rewind_setjmp.c"
                     % (opt, opt))
     if err != 0:
         raise OSError("clang failed on test_rewind.c")
-    for testnum in [1, 2, 3, 4, 5, 6]:
-        print '=== O%d: RUNNING TEST %d ===' % (opt, testnum)
-        err = os.system("./test_rewind_O%d %d" % (opt, testnum))
+    for testnum in [1, 2, 3, 4, 5, 6, "TL1"]:
+        print '=== O%s: RUNNING TEST %s ===' % (opt, testnum)
+        err = os.system("./test_rewind_O%s %s" % (opt, testnum))
         if err != 0:
-            raise OSError("'test_rewind_O%d %d' failed" % (opt, testnum))
-    os.unlink("./test_rewind_O%d" % (opt,))
+            raise OSError("'test_rewind_O%s %s' failed" % (opt, testnum))
+    os.unlink("./test_rewind_O%s" % (opt,))
 
 def test_O0(): run_test(0)
 def test_O1(): run_test(1)


More information about the pypy-commit mailing list