On Monday 09 July 2007 02:49:03 Nuno 'smash' Carvalho wrote:

> I saw your sentinel patch but didn't apply it yet.

> Is this related to you sentnel patch? I can re-test this after appling it.

Here's a better version.  I suspect it's not very portable.  It probably needs 
to fix up page alignment, and it's definitely not quite POSIX kosher.

It does create some interesting aborts though.

-- c

=== include/parrot/pobj.h
==================================================================
--- include/parrot/pobj.h	(revision 4598)
+++ include/parrot/pobj.h	(local)
@@ -47,6 +47,7 @@
 
 /* plain Buffer is the smallest Parrot Obj */
 typedef struct Buffer {
+    char sentinel[4200];
     pobj_t obj;
 } Buffer;
 
@@ -124,6 +125,7 @@
 } parrot_string_representation_t;
 
 struct parrot_string_t {
+    char sentinel[4200];
     pobj_t obj;
     UINTVAL bufused;
     char *strstart;
@@ -134,11 +136,17 @@
     UINTVAL hashval; /* cached hash value computation; not yet used */
 };
 
+static void make_sentinel(PObj *o)
+{
+    /* Make the memory unwritable. */
+    mprotect(o->sentinel, 4096, PROT_READ);
+}
 
 /* put data into the PMC_EXT structure */
 #define PMC_DATA_IN_EXT 1
 
 struct PMC {
+    char sentinel[4200];
     pobj_t obj;
     VTABLE *vtable;
     PMC *real_self;
=== include/parrot/stacks.h
==================================================================
--- include/parrot/stacks.h	(revision 4598)
+++ include/parrot/stacks.h	(local)
@@ -25,6 +25,7 @@
 } Stack_Entry_t;
 
 typedef struct Stack_Chunk {
+    char sentinel[4200];
     pobj_t obj;
     int size;
     const char * name;
=== src/gc/smallobject.c
==================================================================
--- src/gc/smallobject.c	(revision 4598)
+++ src/gc/smallobject.c	(local)
@@ -151,6 +151,7 @@
 gc_ms_add_free_object(SHIM_INTERP, Small_Object_Pool *pool /*NN*/,
                       void *to_add /*NN*/)
 {
+    mprotect(((PObj *)to_add)->sentinel, 4, PROT_WRITE);
     *(void **)to_add = pool->free_list;
     pool->free_list  = to_add;
 }
=== src/headers.c
==================================================================
--- src/headers.c	(revision 4598)
+++ src/headers.c	(local)
@@ -89,6 +89,8 @@
     if (pool->object_size  - GC_HEADER_SIZE > sizeof (PObj))
         memset(buffer + 1, 0,
                 pool->object_size - sizeof (PObj) - GC_HEADER_SIZE);
+
+    make_sentinel((PObj *)buffer);
     return buffer;
 }
 
@@ -247,6 +249,7 @@
             ? interp->arena_base->constant_pmc_pool
             : interp->arena_base->pmc_pool;
     PMC * const pmc = (PMC *)pool->get_free_object(interp, pool);
+    make_sentinel((PObj *)pmc);
 
     /* clear flags, set is_PMC_FLAG */
     if (flags & PObj_is_PMC_EXT_FLAG) {
@@ -356,6 +359,7 @@
         flags | PObj_is_string_FLAG | PObj_is_COWable_FLAG | PObj_live_FLAG;
 
     string->strstart        = NULL;
+    make_sentinel((PObj *)string);
 
     return string;
 }
=== src/pmc.c
==================================================================
--- src/pmc.c	(revision 4598)
+++ src/pmc.c	(local)
@@ -199,6 +199,7 @@
             pmc->real_self = pmc;
             VTABLE_set_pointer(interp, pmc, pmc);
         }
+        make_sentinel((PObj *)pmc);
         return pmc;
     }
     if (vtable->flags & VTABLE_IS_CONST_PMC_FLAG) {
@@ -245,6 +246,7 @@
         fprintf(stderr, "\t=> new %p type %d\n", pmc, (int)base_type);
     }
 #endif
+    make_sentinel((PObj *)pmc);
     return pmc;
 }
 
=== src/stack_common.c
==================================================================
--- src/stack_common.c	(revision 4598)
+++ src/stack_common.c	(local)
@@ -79,7 +79,8 @@
     Stack_Chunk_t * const new_chunk = (Stack_Chunk_t *)pool->get_free_object(interp, pool);
 
     PObj_bufstart(new_chunk) = NULL;
-    PObj_buflen(new_chunk) = 0;
+    PObj_buflen(new_chunk)   = 0;
+    make_sentinel((PObj *)new_chunk);
 
     new_chunk->size = chunk->size;
     new_chunk->name = chunk->name;
=== src/string.c
==================================================================
--- src/string.c	(revision 4598)
+++ src/string.c	(local)
@@ -91,6 +91,7 @@
          * also be sure not to allocate from the constant pool
          */
         PObj_flags_CLEARALL(&for_alloc);
+        make_sentinel((PObj *)&for_alloc);
         Parrot_allocate_string(interp, &for_alloc, PObj_buflen(s));
 
         /* now copy memory over */
@@ -130,8 +131,10 @@
 
     if (PObj_constant_TEST(s)) {
         d = new_string_header(interp, PObj_get_FLAGS(s) & ~PObj_constant_FLAG);
+        mprotect(d->sentinel, 4096, PROT_WRITE);
         PObj_COW_SET(s);
         STRUCT_COPY(d,s);
+        mprotect(d->sentinel, 4096, PROT_READ);
         /* we can't move the memory, because constants aren't
          * scanned in compact_pool, therefore the other end
          * would point to garbage.
@@ -142,7 +145,9 @@
     else {
         d = new_string_header(interp, PObj_get_FLAGS(s));
         PObj_COW_SET(s);
+        mprotect(d->sentinel, 4096, PROT_WRITE);
         STRUCT_COPY(d,s);
+        mprotect(d->sentinel, 4096, PROT_READ);
         PObj_sysmem_CLEAR(d);
 #if 0
         /* XXX FIXME hack to avoid cross-interpreter issue until it

Reply via email to