From 6bf19059cbe736f5a23b8bf7451935947bb681a4 Mon Sep 17 00:00:00 2001 From: otto <> Date: Tue, 18 Apr 2006 19:03:30 +0000 Subject: Near ulimit test case 1 --- .../lib/libc/malloc/malloc_ulimit1/Makefile | 5 +++ .../libc/malloc/malloc_ulimit1/malloc_ulimit1.c | 43 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/regress/lib/libc/malloc/malloc_ulimit1/Makefile create mode 100644 src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c (limited to 'src') diff --git a/src/regress/lib/libc/malloc/malloc_ulimit1/Makefile b/src/regress/lib/libc/malloc/malloc_ulimit1/Makefile new file mode 100644 index 0000000000..46ced27a98 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_ulimit1/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2006/04/18 19:03:30 otto Exp $ + +PROG= malloc_ulimit1 + +.include diff --git a/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c b/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c new file mode 100644 index 0000000000..faa98c7bd6 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c @@ -0,0 +1,43 @@ +/* $OpenBSD: malloc_ulimit1.c,v 1.1 2006/04/18 19:03:30 otto Exp $ */ + +/* Public Domain, 2006, Otto Moerbeek */ + +#include +#include +#include +#include +#include +#include + +/* + * This code tries to trigger the case present in -current as of April + * 2006) where the allocation of the region itself succeeds, but the + * page dir entry pages fails. + * This in turn trips a "hole in directories" error. + * Having a large (512M) ulimit -m helps a lot in triggering the + * problem. Note that you may need to run this test multiple times to + * see the error. +*/ + +#define STARTI 1300 +#define FACTOR 1024 + +main() +{ + struct rlimit lim; + size_t sz; + int i; + void *p; + + if (getrlimit(RLIMIT_DATA, &lim) == -1) + err(1, "getrlimit"); + + sz = lim.rlim_cur / FACTOR; + + for (i = STARTI; i >= 0; i--) { + size_t len = (sz-i) * FACTOR; + p = malloc(len); + free(p); + free(malloc(4096)); + } +} -- cgit v1.2.3-55-g6feb