X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fregression%2Fflockfile-list.c;h=a269cb86eb5817696469e208c824bb2377b788fe;hb=7b91cea54a5f5e4e58a9064795c467eaf573e544;hp=09f18ffc059a9da2ca7f973095310ee1f277f774;hpb=4b0ca742d7f3ecbe397d5a05655538bd33567938;p=libc-test 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