aboutsummaryrefslogtreecommitdiffstats
path: root/cheney_c89.c
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2024-07-14 01:20:50 -0400
committerGravatar Peter McGoron 2024-07-14 01:20:50 -0400
commit2effa0f98cac2a2845aba5e303e977170f72a8d8 (patch)
treed2140f61b4d3a0460bf92909946fd5e4516c2de0 /cheney_c89.c
parentimport flatrate lisp, rename to Universal Service LISP (diff)
cheney_c89: valgrind
Diffstat (limited to 'cheney_c89.c')
-rw-r--r--cheney_c89.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/cheney_c89.c b/cheney_c89.c
index d1b499d..b94fd55 100644
--- a/cheney_c89.c
+++ b/cheney_c89.c
@@ -16,6 +16,16 @@
*/
#include <stdio.h>
+#ifdef UNS_VALGRIND
+# include <valgrind/valgrind.h>
+# define REDZONE 16
+#else
+# define REDZONE 0
+# define VALGRIND_CREATE_MEMPOOL(pool, rzB, is_zeroed) (void)0
+# define VALGRIND_DESTROY_MEMPOOL(pool) (void)0
+# define VALGRIND_MEMPOOL_ALLOC(pool, ptr, siz) (void)0
+#endif
+
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
@@ -186,7 +196,7 @@ static void hdr_write_direct(struct hdr *hdr, unsigned char *p)
*/
static int enough_space(struct ctx *ctx, uns_sword bytes)
{
- return ctx->tospace_end - ctx->tospace_alloc >= bytes + HDR_LEN;
+ return ctx->tospace_end - ctx->tospace_alloc >= bytes + HDR_LEN + REDZONE;
}
/** Allocate region without bounds checking.
@@ -215,8 +225,10 @@ static void *raw_alloc(struct ctx *ctx, uns_sword len, int is_record)
assert(enough_space(ctx, len));
p = ctx->tospace_alloc;
+ VALGRIND_MEMPOOL_ALLOC(ctx->tospace, p, len);
+
hdr_write_direct(&hdr, p);
- ctx->tospace_alloc += len;
+ ctx->tospace_alloc += len + REDZONE;
return p + HDR_LEN;
}
@@ -342,7 +354,7 @@ static void relocate_everything(Uns_GC gc)
if (hdr.typ == RECORD)
scan_record(ctx, scanptr, (size_t)hdr.len/sizeof(void*));
- scanptr += hdr.len;
+ scanptr += hdr.len + REDZONE;
}
}
@@ -363,6 +375,7 @@ int uns_cheney_c89_collect(Uns_GC gc)
*/
assert(newlen >= fromspace_lim - fromspace);
ctx->tospace = malloc(newlen);
+ VALGRIND_CREATE_MEMPOOL(ctx->tospace, REDZONE, 0);
if (!ctx->tospace) {
ctx->tospace = fromspace;
return 1;
@@ -374,6 +387,7 @@ int uns_cheney_c89_collect(Uns_GC gc)
relocate_everything(gc);
+ VALGRIND_DESTROY_MEMPOOL(fromspace);
free(fromspace);
ctx->stats.usage_after = ctx->tospace_alloc - ctx->tospace;
@@ -446,6 +460,7 @@ int uns_cheney_c89_init(Uns_GC gc, size_t heap_size)
uns_deinit(gc);
ctx->tospace_alloc = ctx->tospace = malloc(heap_size);
+ VALGRIND_CREATE_MEMPOOL(ctx->tospace, REDZONE, 0);
if (!ctx->tospace) {
free(ctx);
return 0;