diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2005-01-06 10:14:21 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2005-01-06 10:14:21 +0000 |
commit | 17a16bc41b8a66ef0a71488f80fb4eeddd2b30a0 (patch) | |
tree | dc782b4a1de75ea22c66aa7dd4bea71c5cb79717 /regress/sys/uvm/mmap_size | |
parent | 56ed4d90af133f6a29f8b2897df8524025b37f40 (diff) |
sanity checks on size arg to mmap.
Diffstat (limited to 'regress/sys/uvm/mmap_size')
-rw-r--r-- | regress/sys/uvm/mmap_size/Makefile | 4 | ||||
-rw-r--r-- | regress/sys/uvm/mmap_size/mmap_size.c | 45 |
2 files changed, 49 insertions, 0 deletions
diff --git a/regress/sys/uvm/mmap_size/Makefile b/regress/sys/uvm/mmap_size/Makefile new file mode 100644 index 00000000000..2c5d809d386 --- /dev/null +++ b/regress/sys/uvm/mmap_size/Makefile @@ -0,0 +1,4 @@ +# $OpenBSD: Makefile,v 1.1 2005/01/06 10:14:20 otto Exp $ +PROG=mmap_size + +.include <bsd.regress.mk> diff --git a/regress/sys/uvm/mmap_size/mmap_size.c b/regress/sys/uvm/mmap_size/mmap_size.c new file mode 100644 index 00000000000..5bd9b0980f2 --- /dev/null +++ b/regress/sys/uvm/mmap_size/mmap_size.c @@ -0,0 +1,45 @@ +/* $OpenBSD: mmap_size.c,v 1.1 2005/01/06 10:14:20 otto Exp $ */ + +/* + * Public domain. 2005, Otto Moerbeek <otto@drijf.net> + */ + +#include <sys/types.h> +#include <sys/mman.h> +#include <err.h> +#include <limits.h> +#include <stdlib.h> +#include <stdio.h> + +void +f(size_t sz) +{ + char *p; + p = mmap(NULL, sz, PROT_READ|PROT_WRITE, + MAP_ANON|MAP_PRIVATE, -1, (off_t)0); + + if (p == MAP_FAILED) + return; + + if (sz > 0) { + p[0] = 0; + p[sz / 2] = 0; + p[sz - 1] = 0; + } + munmap(p, sz); +} + +int +main() +{ + size_t i; + + for (i = 0; i < 0x2000; i += 0x100) { + f(i); + f(-i); + f(SIZE_T_MAX/2 - 0x1000); + } + return (0); +} + + |