diff --git a/src/regression/flockfile-list.c b/src/regression/flockfile-list.c index 09f18ff..a269cb8 100644 --- a/src/regression/flockfile-list.c +++ b/src/regression/flockfile-list.c @@ -6,6 +6,84 @@ #include #include "test.h" +#define t_fatal(...) (t_error(__VA_ARGS__), _Exit(t_status)) +#define length(a) (sizeof(a)/sizeof*(a)) + +// interpose malloc functions +// freed memory is not reused, it is checked for clobber. + +static unsigned char buf[1<<20]; +static size_t pos; +static struct { + size_t pos; + size_t n; + int freed; +} alloc[100]; +static int idx; + +void *malloc(size_t n) +{ + if (n == 0) n++; + if (n > sizeof buf - pos) + t_fatal("test buffer is small, pos: %zu, need: %zu\n", pos, n); + if (idx >= length(alloc)) + t_fatal("test buffer is small, idx: %d\n", idx); + void *p = buf + pos; + alloc[idx].pos = pos; + alloc[idx].n = n; + pos += n; + idx++; + return p; +} + +void *calloc(size_t n, size_t m) +{ + return memset(malloc(n*m), 0, n*m); +} + +void *aligned_alloc(size_t a, size_t n) +{ + t_fatal("aligned_alloc is unsupported\n"); +} + +static int findidx(void *p) +{ + size_t pos = (unsigned char *)p - buf; + for (int i=0; i