diff options
Diffstat (limited to 'src/regress/lib/libc/malloc')
9 files changed, 0 insertions, 279 deletions
diff --git a/src/regress/lib/libc/malloc/Makefile b/src/regress/lib/libc/malloc/Makefile deleted file mode 100644 index 7c919d1bc2..0000000000 --- a/src/regress/lib/libc/malloc/Makefile +++ /dev/null | |||
| @@ -1,7 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.5 2006/04/18 19:04:39 otto Exp $ | ||
| 2 | |||
| 3 | SUBDIR+= malloc0test malloc_errno malloc_ulimit1 malloc_ulimit2 | ||
| 4 | |||
| 5 | install: | ||
| 6 | |||
| 7 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc0test/Makefile b/src/regress/lib/libc/malloc/malloc0test/Makefile deleted file mode 100644 index 8ed8163a79..0000000000 --- a/src/regress/lib/libc/malloc/malloc0test/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2003/07/15 10:09:37 otto Exp $ | ||
| 2 | |||
| 3 | PROG= malloc0test | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc0test/malloc0test.c b/src/regress/lib/libc/malloc/malloc0test/malloc0test.c deleted file mode 100644 index 06ff0996ee..0000000000 --- a/src/regress/lib/libc/malloc/malloc0test/malloc0test.c +++ /dev/null | |||
| @@ -1,120 +0,0 @@ | |||
| 1 | /* $OpenBSD: malloc0test.c,v 1.5 2008/04/13 00:22:17 djm Exp $ */ | ||
| 2 | /* | ||
| 3 | * Public domain. 2001, Theo de Raadt | ||
| 4 | */ | ||
| 5 | #include <sys/types.h> | ||
| 6 | #include <sys/signal.h> | ||
| 7 | #include <stdio.h> | ||
| 8 | #include <unistd.h> | ||
| 9 | #include <stdlib.h> | ||
| 10 | #include <setjmp.h> | ||
| 11 | #include <limits.h> | ||
| 12 | #include <errno.h> | ||
| 13 | |||
| 14 | volatile sig_atomic_t got; | ||
| 15 | jmp_buf jmp; | ||
| 16 | |||
| 17 | static void | ||
| 18 | catch(int signo) | ||
| 19 | { | ||
| 20 | got++; | ||
| 21 | longjmp(jmp, 1); | ||
| 22 | } | ||
| 23 | |||
| 24 | static int | ||
| 25 | test(char *p, int size) | ||
| 26 | { | ||
| 27 | signal(SIGSEGV, catch); | ||
| 28 | got = 0; | ||
| 29 | if (setjmp(jmp) == 0) | ||
| 30 | *p = 0; | ||
| 31 | if (setjmp(jmp) == 0) | ||
| 32 | *(p+size-1) = 0; | ||
| 33 | return (got); | ||
| 34 | } | ||
| 35 | |||
| 36 | char *prot_table[] = { | ||
| 37 | "unprotected", | ||
| 38 | "fuckup", | ||
| 39 | "protected" | ||
| 40 | }; | ||
| 41 | |||
| 42 | #define SIZE 10 | ||
| 43 | |||
| 44 | /* | ||
| 45 | * Do random memory allocations. | ||
| 46 | * | ||
| 47 | * For each one, ensure that it is at least 16 bytes in size (that | ||
| 48 | * being what our current malloc returns for the minsize of an | ||
| 49 | * object, alignment wise); | ||
| 50 | * | ||
| 51 | * For zero-byte allocations, check that they are still aligned. | ||
| 52 | * | ||
| 53 | * For each object, ensure that they are correctly protected or not | ||
| 54 | * protected. | ||
| 55 | * | ||
| 56 | * Does not regress test malloc + free combinations ... it should. | ||
| 57 | */ | ||
| 58 | int | ||
| 59 | main(int argc, char *argv[]) | ||
| 60 | { | ||
| 61 | caddr_t blob; | ||
| 62 | int size, tsize; | ||
| 63 | int prot; | ||
| 64 | int rval = 0, fuckup = 0; | ||
| 65 | long limit = 200000, count; | ||
| 66 | int ch, silent = 0; | ||
| 67 | char *ep; | ||
| 68 | extern char *__progname; | ||
| 69 | |||
| 70 | while ((ch = getopt(argc, argv, "sn:")) != -1) { | ||
| 71 | switch (ch) { | ||
| 72 | case 's': | ||
| 73 | silent = 1; | ||
| 74 | break; | ||
| 75 | case 'n': | ||
| 76 | errno = 0; | ||
| 77 | limit = strtol(optarg, &ep, 10); | ||
| 78 | if (optarg[0] == '\0' || *ep != '\0' || | ||
| 79 | (errno == ERANGE && | ||
| 80 | (limit == LONG_MAX || limit == LONG_MIN))) | ||
| 81 | goto usage; | ||
| 82 | break; | ||
| 83 | default: | ||
| 84 | usage: | ||
| 85 | fprintf(stderr, "Usage: %s [-s][-n <count>]\n", | ||
| 86 | __progname); | ||
| 87 | exit(1); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | if (limit == 0) | ||
| 92 | limit = LONG_MAX; | ||
| 93 | |||
| 94 | for (count = 0; count < limit; count++) { | ||
| 95 | size = arc4random_uniform(SIZE); | ||
| 96 | blob = malloc(size); | ||
| 97 | if (blob == NULL) { | ||
| 98 | fprintf(stderr, "success: out of memory\n"); | ||
| 99 | exit(rval); | ||
| 100 | } | ||
| 101 | |||
| 102 | tsize = size == 0 ? 16 : size; | ||
| 103 | fuckup = 0; | ||
| 104 | prot = test(blob, tsize); | ||
| 105 | |||
| 106 | if (size == 0 && prot < 2) | ||
| 107 | fuckup = 1; | ||
| 108 | |||
| 109 | if (fuckup) { | ||
| 110 | printf("%8p %6d %20s %10s\n", blob, size, | ||
| 111 | prot_table[prot], fuckup ? "fuckup" : ""); | ||
| 112 | rval = 1; | ||
| 113 | } | ||
| 114 | |||
| 115 | if (!silent && count % 100000 == 0 && count != 0) | ||
| 116 | fprintf(stderr, "count = %ld\n", count); | ||
| 117 | } | ||
| 118 | |||
| 119 | return rval; | ||
| 120 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_errno/Makefile b/src/regress/lib/libc/malloc/malloc_errno/Makefile deleted file mode 100644 index 73ebe37491..0000000000 --- a/src/regress/lib/libc/malloc/malloc_errno/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2003/07/15 10:06:31 otto Exp $ | ||
| 2 | |||
| 3 | PROG= malloc_errno | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c b/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c deleted file mode 100644 index 896ea3c900..0000000000 --- a/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c +++ /dev/null | |||
| @@ -1,46 +0,0 @@ | |||
| 1 | /* $OpenBSD: malloc_errno.c,v 1.4 2003/12/25 18:49:57 miod Exp $ */ | ||
| 2 | /* | ||
| 3 | * Public domain. 2003, Otto Moerbeek | ||
| 4 | */ | ||
| 5 | #include <err.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <stdio.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | |||
| 10 | static void | ||
| 11 | testerrno(size_t sz) | ||
| 12 | { | ||
| 13 | void *p; | ||
| 14 | |||
| 15 | errno = -1; | ||
| 16 | p = malloc(sz); | ||
| 17 | |||
| 18 | if (p == NULL && errno != ENOMEM) | ||
| 19 | errx(1, "fail: %lx %p %d", (unsigned long)sz, p, errno); | ||
| 20 | |||
| 21 | /* if alloc succeeded, test if errno did not change */ | ||
| 22 | if (p != NULL && errno != -1) | ||
| 23 | errx(1, "fail: %lx %p %d", (unsigned long)sz, p, errno); | ||
| 24 | |||
| 25 | free(p); | ||
| 26 | } | ||
| 27 | |||
| 28 | /* | ||
| 29 | * Provide some (silly) arguments to malloc(), and check if ERRNO is set | ||
| 30 | * correctly. | ||
| 31 | */ | ||
| 32 | int | ||
| 33 | main(int argc, char *argv[]) | ||
| 34 | { | ||
| 35 | size_t i; | ||
| 36 | |||
| 37 | testerrno(1); | ||
| 38 | testerrno(100000); | ||
| 39 | testerrno(-1); | ||
| 40 | testerrno(-1000); | ||
| 41 | testerrno(-10000); | ||
| 42 | testerrno(-10000000); | ||
| 43 | for (i = 0; i < 0x10; i++) | ||
| 44 | testerrno(i * 0x10000000); | ||
| 45 | return 0; | ||
| 46 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit1/Makefile b/src/regress/lib/libc/malloc/malloc_ulimit1/Makefile deleted file mode 100644 index 46ced27a98..0000000000 --- a/src/regress/lib/libc/malloc/malloc_ulimit1/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2006/04/18 19:03:30 otto Exp $ | ||
| 2 | |||
| 3 | PROG= malloc_ulimit1 | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c b/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c deleted file mode 100644 index 99e805e8e1..0000000000 --- a/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c +++ /dev/null | |||
| @@ -1,44 +0,0 @@ | |||
| 1 | /* $OpenBSD: malloc_ulimit1.c,v 1.2 2006/05/16 05:47:13 otto Exp $ */ | ||
| 2 | |||
| 3 | /* Public Domain, 2006, Otto Moerbeek <otto@drijf.net> */ | ||
| 4 | |||
| 5 | #include <sys/types.h> | ||
| 6 | #include <sys/time.h> | ||
| 7 | #include <sys/resource.h> | ||
| 8 | #include <err.h> | ||
| 9 | #include <stdlib.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | |||
| 12 | /* | ||
| 13 | * This code tries to trigger the case present in -current as of April | ||
| 14 | * 2006) where the allocation of the region itself succeeds, but the | ||
| 15 | * page dir entry pages fails. | ||
| 16 | * This in turn trips a "hole in directories" error. | ||
| 17 | * Having a large (512M) ulimit -m helps a lot in triggering the | ||
| 18 | * problem. Note that you may need to run this test multiple times to | ||
| 19 | * see the error. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #define STARTI 1300 | ||
| 23 | #define FACTOR 1024 | ||
| 24 | |||
| 25 | main() | ||
| 26 | { | ||
| 27 | struct rlimit lim; | ||
| 28 | size_t sz; | ||
| 29 | int i; | ||
| 30 | void *p; | ||
| 31 | |||
| 32 | if (getrlimit(RLIMIT_DATA, &lim) == -1) | ||
| 33 | err(1, "getrlimit"); | ||
| 34 | |||
| 35 | sz = lim.rlim_cur / FACTOR; | ||
| 36 | |||
| 37 | for (i = STARTI; i >= 0; i--) { | ||
| 38 | size_t len = (sz-i) * FACTOR; | ||
| 39 | p = malloc(len); | ||
| 40 | free(p); | ||
| 41 | free(malloc(4096)); | ||
| 42 | } | ||
| 43 | return (0); | ||
| 44 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit2/Makefile b/src/regress/lib/libc/malloc/malloc_ulimit2/Makefile deleted file mode 100644 index bc83666415..0000000000 --- a/src/regress/lib/libc/malloc/malloc_ulimit2/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2006/04/18 19:04:03 otto Exp $ | ||
| 2 | |||
| 3 | PROG= malloc_ulimit2 | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c b/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c deleted file mode 100644 index ca8e8f438a..0000000000 --- a/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c +++ /dev/null | |||
| @@ -1,42 +0,0 @@ | |||
| 1 | /* $OpenBSD: malloc_ulimit2.c,v 1.2 2006/05/16 05:47:13 otto Exp $ */ | ||
| 2 | |||
| 3 | /* Public Domain, 2006, Otto Moerbeek <otto@drijf.net> */ | ||
| 4 | |||
| 5 | #include <sys/types.h> | ||
| 6 | #include <sys/time.h> | ||
| 7 | #include <sys/resource.h> | ||
| 8 | #include <err.h> | ||
| 9 | #include <stdlib.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | |||
| 12 | #define FACTOR 1024 | ||
| 13 | |||
| 14 | main() | ||
| 15 | { | ||
| 16 | struct rlimit lim; | ||
| 17 | size_t sz; | ||
| 18 | int i; | ||
| 19 | void *p; | ||
| 20 | |||
| 21 | if (getrlimit(RLIMIT_DATA, &lim) == -1) | ||
| 22 | err(1, "getrlimit"); | ||
| 23 | |||
| 24 | sz = lim.rlim_cur / FACTOR; | ||
| 25 | |||
| 26 | for (i = 0; ; i++) { | ||
| 27 | size_t len = (sz-i) * FACTOR; | ||
| 28 | p = malloc(len); | ||
| 29 | if (p != NULL) { | ||
| 30 | free(p); | ||
| 31 | break; | ||
| 32 | } | ||
| 33 | } | ||
| 34 | i += 10; | ||
| 35 | for (; i >= 0; i--) { | ||
| 36 | size_t len = (sz-i) * FACTOR; | ||
| 37 | p = malloc(len); | ||
| 38 | free(p); | ||
| 39 | free(malloc(4096)); | ||
| 40 | } | ||
| 41 | return (0); | ||
| 42 | } | ||
