[pypy-commit] pypy stmgc-c7: import stmgc/0492e398156b
arigo
noreply at buildbot.pypy.org
Thu Apr 10 12:36:58 CEST 2014
Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c7
Changeset: r70535:3b8d9d990e35
Date: 2014-04-09 13:06 +0200
http://bitbucket.org/pypy/pypy/changeset/3b8d9d990e35/
Log: import stmgc/0492e398156b
diff --git a/rpython/translator/stm/src_stm/revision b/rpython/translator/stm/src_stm/revision
--- a/rpython/translator/stm/src_stm/revision
+++ b/rpython/translator/stm/src_stm/revision
@@ -1,1 +1,1 @@
-859b241ec058
+0492e398156b
diff --git a/rpython/translator/stm/src_stm/stm/setup.c b/rpython/translator/stm/src_stm/stm/setup.c
--- a/rpython/translator/stm/src_stm/stm/setup.c
+++ b/rpython/translator/stm/src_stm/stm/setup.c
@@ -10,7 +10,7 @@
PROT_READ | PROT_WRITE,
MAP_PAGES_FLAGS, -1, 0);
if (result == MAP_FAILED)
- stm_fatalerror("%s failed: %m\n", reason);
+ stm_fatalerror("%s failed: %m", reason);
return result;
}
@@ -132,17 +132,37 @@
teardown_pages();
}
+static void _shadowstack_trap_page(char *start, int prot)
+{
+ size_t bsize = STM_SHADOW_STACK_DEPTH * sizeof(struct stm_shadowentry_s);
+ char *end = start + bsize + 4095;
+ end -= (((uintptr_t)end) & 4095);
+ mprotect(end, 4096, prot);
+}
+
static void _init_shadow_stack(stm_thread_local_t *tl)
{
- struct stm_shadowentry_s *s = (struct stm_shadowentry_s *)
- malloc(STM_SHADOW_STACK_DEPTH * sizeof(struct stm_shadowentry_s));
- assert(s);
+ size_t bsize = STM_SHADOW_STACK_DEPTH * sizeof(struct stm_shadowentry_s);
+ char *start = malloc(bsize + 8192); /* for the trap page, plus rounding */
+ if (!start)
+ stm_fatalerror("can't allocate shadow stack");
+
+ /* set up a trap page: if the shadowstack overflows, it will
+ crash in a clean segfault */
+ _shadowstack_trap_page(start, PROT_NONE);
+
+ struct stm_shadowentry_s *s = (struct stm_shadowentry_s *)start;
tl->shadowstack = s;
tl->shadowstack_base = s;
}
static void _done_shadow_stack(stm_thread_local_t *tl)
{
+ assert(tl->shadowstack >= tl->shadowstack_base);
+
+ char *start = (char *)tl->shadowstack_base;
+ _shadowstack_trap_page(start, PROT_READ | PROT_WRITE);
+
free(tl->shadowstack_base);
tl->shadowstack = NULL;
tl->shadowstack_base = NULL;
diff --git a/rpython/translator/stm/src_stm/stm/weakref.c b/rpython/translator/stm/src_stm/stm/weakref.c
--- a/rpython/translator/stm/src_stm/stm/weakref.c
+++ b/rpython/translator/stm/src_stm/stm/weakref.c
@@ -35,7 +35,7 @@
stm_char *point_to_loc = (stm_char*)WEAKREF_PTR(weakref, size);
long i;
- for (i = 1; i <= NB_SEGMENTS; i++) {
+ for (i = 0; i <= NB_SEGMENTS; i++) {
char *base = get_segment_base(i);
object_t ** ref_loc = (object_t **)REAL_ADDRESS(base, point_to_loc);
*ref_loc = value;
@@ -58,11 +58,14 @@
a young outside nursery object. */
assert(_is_in_nursery(item));
object_t *TLPREFIX *pforwarded_array = (object_t *TLPREFIX *)item;
+ ssize_t size = 16;
- /* the following checks are done like in nursery.c: */
- if (!(item->stm_flags & GCFLAG_HAS_SHADOW)
- || (pforwarded_array[0] != GCWORD_MOVED)) {
- /* weakref dies */
+ /* check if the weakref object was moved out of the nursery */
+ if (pforwarded_array[0] != GCWORD_MOVED) {
+ /* no: weakref dies */
+#ifndef NDEBUG
+ *WEAKREF_PTR(item, size) = (object_t *)-99;
+#endif
continue;
}
@@ -70,15 +73,13 @@
assert(!_is_young(item));
- ssize_t size = 16;
object_t *pointing_to = *WEAKREF_PTR(item, size);
assert(pointing_to != NULL);
if (_is_in_nursery(pointing_to)) {
object_t *TLPREFIX *pforwarded_array = (object_t *TLPREFIX *)pointing_to;
- /* the following checks are done like in nursery.c: */
- if (!(pointing_to->stm_flags & GCFLAG_HAS_SHADOW)
- || (pforwarded_array[0] != GCWORD_MOVED)) {
+ /* check if the target was moved out of the nursery */
+ if (pforwarded_array[0] != GCWORD_MOVED) {
/* pointing_to dies */
_set_weakref_in_all_segments(item, NULL);
continue; /* no need to remember in old_weakrefs */
@@ -97,7 +98,9 @@
_set_weakref_in_all_segments(item, NULL);
continue; /* no need to remember in old_weakrefs */
}
- /* pointing_to was already old */
+ /* pointing_to is either a surviving young object outside
+ the nursery, or it was already old; in both cases keeping
+ the currently stored pointer is what we need */
}
LIST_APPEND(STM_PSEGMENT->old_weakrefs, item);
}));
@@ -129,7 +132,7 @@
stm_char *wr = (stm_char *)WEAKREF_PTR(weakref, size);
char *real_wr = REAL_ADDRESS(pseg->pub.segment_base, wr);
object_t *pointing_to = *(object_t **)real_wr;
- assert(pointing_to != NULL);
+ assert((uintptr_t)pointing_to >= NURSERY_END);
if (!mark_visited_test(pointing_to)) {
//assert(flag_page_private[(uintptr_t)weakref / 4096UL] != PRIVATE_PAGE);
_set_weakref_in_all_segments(weakref, NULL);
More information about the pypy-commit
mailing list