diff options
| author | cvs2svn <admin@example.com> | 2025-04-14 17:32:06 +0000 |
|---|---|---|
| committer | cvs2svn <admin@example.com> | 2025-04-14 17:32:06 +0000 |
| commit | b1ddde874c215cc8891531ed92876f091b7eb83e (patch) | |
| tree | edb6da6af7e865d488dc1a29309f1e1ec226e603 /src/regress/lib/libc/malloc | |
| parent | f0a36529837a161734c802ae4c42e84e42347be2 (diff) | |
| download | openbsd-tb_20250414.tar.gz openbsd-tb_20250414.tar.bz2 openbsd-tb_20250414.zip | |
This commit was manufactured by cvs2git to create tag 'tb_20250414'.tb_20250414
Diffstat (limited to 'src/regress/lib/libc/malloc')
15 files changed, 0 insertions, 878 deletions
diff --git a/src/regress/lib/libc/malloc/Makefile b/src/regress/lib/libc/malloc/Makefile deleted file mode 100644 index 546d67f6ca..0000000000 --- a/src/regress/lib/libc/malloc/Makefile +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.8 2023/05/08 11:13:30 otto Exp $ | ||
| 2 | |||
| 3 | SUBDIR+= malloc_general malloc0test malloc_errno malloc_ulimit1 malloc_ulimit2 | ||
| 4 | SUBDIR+= malloc_threaderr malloc_errs | ||
| 5 | |||
| 6 | install: | ||
| 7 | |||
| 8 | .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 fc2295c091..0000000000 --- a/src/regress/lib/libc/malloc/malloc0test/Makefile +++ /dev/null | |||
| @@ -1,11 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2017/07/08 00:08:26 bluhm Exp $ | ||
| 2 | |||
| 3 | PROG= malloc0test | ||
| 4 | |||
| 5 | .for m in C D F G J j R S U X << >>> | ||
| 6 | REGRESS_TARGETS += run-regress-${PROG}-${m:S/</-/g:S/>/+/g} | ||
| 7 | run-regress-${PROG}-${m:S/</-/g:S/>/+/g}: ${PROG} | ||
| 8 | MALLOC_OPTIONS='${m}' ./${PROG} | ||
| 9 | .endfor | ||
| 10 | |||
| 11 | .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 1759291f38..0000000000 --- a/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c +++ /dev/null | |||
| @@ -1,49 +0,0 @@ | |||
| 1 | /* $OpenBSD: malloc_errno.c,v 1.5 2019/06/11 22:16:13 bluhm 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 | /* On arm64 with 2G of memory this test hangs while junking. */ | ||
| 11 | char *malloc_options = "jj"; | ||
| 12 | |||
| 13 | static void | ||
| 14 | testerrno(size_t sz) | ||
| 15 | { | ||
| 16 | void *p; | ||
| 17 | |||
| 18 | errno = -1; | ||
| 19 | p = malloc(sz); | ||
| 20 | |||
| 21 | if (p == NULL && errno != ENOMEM) | ||
| 22 | errx(1, "fail: %lx %p %d", (unsigned long)sz, p, errno); | ||
| 23 | |||
| 24 | /* if alloc succeeded, test if errno did not change */ | ||
| 25 | if (p != NULL && errno != -1) | ||
| 26 | errx(1, "fail: %lx %p %d", (unsigned long)sz, p, errno); | ||
| 27 | |||
| 28 | free(p); | ||
| 29 | } | ||
| 30 | |||
| 31 | /* | ||
| 32 | * Provide some (silly) arguments to malloc(), and check if ERRNO is set | ||
| 33 | * correctly. | ||
| 34 | */ | ||
| 35 | int | ||
| 36 | main(int argc, char *argv[]) | ||
| 37 | { | ||
| 38 | size_t i; | ||
| 39 | |||
| 40 | testerrno(1); | ||
| 41 | testerrno(100000); | ||
| 42 | testerrno(-1); | ||
| 43 | testerrno(-1000); | ||
| 44 | testerrno(-10000); | ||
| 45 | testerrno(-10000000); | ||
| 46 | for (i = 0; i < 0x10; i++) | ||
| 47 | testerrno(i * 0x10000000); | ||
| 48 | return 0; | ||
| 49 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_errs/Makefile b/src/regress/lib/libc/malloc/malloc_errs/Makefile deleted file mode 100644 index 150f30e671..0000000000 --- a/src/regress/lib/libc/malloc/malloc_errs/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2023/05/08 11:12:44 otto Exp $ | ||
| 2 | |||
| 3 | PROG= malloc_errs | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_errs/malloc_errs.c b/src/regress/lib/libc/malloc/malloc_errs/malloc_errs.c deleted file mode 100644 index 486c247f0d..0000000000 --- a/src/regress/lib/libc/malloc/malloc_errs/malloc_errs.c +++ /dev/null | |||
| @@ -1,325 +0,0 @@ | |||
| 1 | /* $OpenBSD: malloc_errs.c,v 1.5 2024/04/14 17:47:41 otto Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2023 Otto Moerbeek <otto@drijf.net> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <sys/resource.h> | ||
| 19 | #include <sys/wait.h> | ||
| 20 | #include <err.h> | ||
| 21 | #include <stdlib.h> | ||
| 22 | #include <stdio.h> | ||
| 23 | #include <stdint.h> | ||
| 24 | #include <signal.h> | ||
| 25 | #include <unistd.h> | ||
| 26 | |||
| 27 | /* Test erroneous use of API and heap that malloc should catch */ | ||
| 28 | |||
| 29 | void | ||
| 30 | clearq(void *p) | ||
| 31 | { | ||
| 32 | int i; | ||
| 33 | void *q; | ||
| 34 | |||
| 35 | /* Clear delayed free queue */ | ||
| 36 | for (i = 0; i < 400; i++) { | ||
| 37 | q = malloc(100); | ||
| 38 | free(q); | ||
| 39 | if (p == q) { | ||
| 40 | fprintf(stderr, "Re-use\n"); | ||
| 41 | abort(); | ||
| 42 | } | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | /* test the test setup */ | ||
| 47 | void | ||
| 48 | t0(void) | ||
| 49 | { | ||
| 50 | abort(); | ||
| 51 | } | ||
| 52 | |||
| 53 | /* double free >= page size */ | ||
| 54 | void | ||
| 55 | t1(void) | ||
| 56 | { | ||
| 57 | void *p = malloc(10000); | ||
| 58 | free(p); | ||
| 59 | free(p); | ||
| 60 | } | ||
| 61 | |||
| 62 | /* double free chunks are different, have a delayed free list */ | ||
| 63 | void | ||
| 64 | t2(void) | ||
| 65 | { | ||
| 66 | void *p, *q; | ||
| 67 | int i; | ||
| 68 | |||
| 69 | p = malloc(100); | ||
| 70 | free(p); | ||
| 71 | clearq(p); | ||
| 72 | free(p); | ||
| 73 | } | ||
| 74 | |||
| 75 | /* double free without clearing delayed free list, needs F */ | ||
| 76 | void | ||
| 77 | t3(void) | ||
| 78 | { | ||
| 79 | void *p = malloc(100); | ||
| 80 | free(p); | ||
| 81 | free(p); | ||
| 82 | } | ||
| 83 | |||
| 84 | /* free without prior allocation */ | ||
| 85 | void | ||
| 86 | t4(void) | ||
| 87 | { | ||
| 88 | free((void*)1); | ||
| 89 | } | ||
| 90 | |||
| 91 | /* realloc of bogus pointer */ | ||
| 92 | void | ||
| 93 | t5(void) | ||
| 94 | { | ||
| 95 | realloc((void*)1, 10); | ||
| 96 | } | ||
| 97 | |||
| 98 | /* write after free for chunk */ | ||
| 99 | void | ||
| 100 | t6(void) | ||
| 101 | { | ||
| 102 | char *p = malloc(32); | ||
| 103 | free(p); | ||
| 104 | p[0] = ~p[0]; | ||
| 105 | clearq(NULL); | ||
| 106 | } | ||
| 107 | |||
| 108 | /* write after free large alloction */ | ||
| 109 | void | ||
| 110 | t7(void) | ||
| 111 | { | ||
| 112 | char *p, *q; | ||
| 113 | int i; | ||
| 114 | |||
| 115 | p = malloc(10000); | ||
| 116 | free(p); | ||
| 117 | p[0] = ~p[0]; | ||
| 118 | /* force re-use from the cache */ | ||
| 119 | for (i = 0; i < 100; i++) { | ||
| 120 | q = malloc(10000); | ||
| 121 | free(q); | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | /* write after free for chunk, no clearing of delayed free queue */ | ||
| 126 | void | ||
| 127 | t8(void) | ||
| 128 | { | ||
| 129 | char *p, *q; | ||
| 130 | |||
| 131 | p = malloc(32); | ||
| 132 | q = malloc(32); | ||
| 133 | free(p); | ||
| 134 | p[0] = ~p[0]; | ||
| 135 | free(q); | ||
| 136 | } | ||
| 137 | |||
| 138 | /* canary check */ | ||
| 139 | void | ||
| 140 | t9(void) | ||
| 141 | { | ||
| 142 | char *p = malloc(100); | ||
| 143 | p[100] = 0; | ||
| 144 | free(p); | ||
| 145 | } | ||
| 146 | |||
| 147 | /* t10 is the same as t9 with different flags */ | ||
| 148 | |||
| 149 | /* modified chunk pointer */ | ||
| 150 | void | ||
| 151 | t11(void) | ||
| 152 | { | ||
| 153 | char *p = malloc(100); | ||
| 154 | free(p + 1); | ||
| 155 | } | ||
| 156 | |||
| 157 | /* free chunk pointer */ | ||
| 158 | void | ||
| 159 | t12(void) | ||
| 160 | { | ||
| 161 | char *p = malloc(16); | ||
| 162 | free(p + 16); | ||
| 163 | } | ||
| 164 | |||
| 165 | /* freezero with wrong size */ | ||
| 166 | void | ||
| 167 | t13(void) | ||
| 168 | { | ||
| 169 | char *p = malloc(16); | ||
| 170 | freezero(p, 17); | ||
| 171 | } | ||
| 172 | |||
| 173 | /* freezero with wrong size 2 */ | ||
| 174 | void | ||
| 175 | t14(void) | ||
| 176 | { | ||
| 177 | char *p = malloc(15); | ||
| 178 | freezero(p, 16); | ||
| 179 | } | ||
| 180 | |||
| 181 | /* freezero with wrong size, pages */ | ||
| 182 | void | ||
| 183 | t15(void) | ||
| 184 | { | ||
| 185 | char *p = malloc(getpagesize()); | ||
| 186 | freezero(p, getpagesize() + 1); | ||
| 187 | } | ||
| 188 | |||
| 189 | /* recallocarray with wrong size */ | ||
| 190 | void | ||
| 191 | t16(void) | ||
| 192 | { | ||
| 193 | char *p = recallocarray(NULL, 0, 16, 1); | ||
| 194 | char *q = recallocarray(p, 2, 3, 16); | ||
| 195 | } | ||
| 196 | |||
| 197 | /* recallocarray with wrong size 2 */ | ||
| 198 | void | ||
| 199 | t17(void) | ||
| 200 | { | ||
| 201 | char *p = recallocarray(NULL, 0, 15, 1); | ||
| 202 | char *q = recallocarray(p, 2, 3, 15); | ||
| 203 | } | ||
| 204 | |||
| 205 | /* recallocarray with wrong size, pages */ | ||
| 206 | void | ||
| 207 | t18(void) | ||
| 208 | { | ||
| 209 | char *p = recallocarray(NULL, 0, 1, getpagesize()); | ||
| 210 | char *q = recallocarray(p, 2, 3, getpagesize()); | ||
| 211 | } | ||
| 212 | |||
| 213 | /* recallocarray with wrong size, pages */ | ||
| 214 | void | ||
| 215 | t19(void) | ||
| 216 | { | ||
| 217 | char *p = recallocarray(NULL, 0, 1, 10 * getpagesize()); | ||
| 218 | char *q = recallocarray(p, 1, 2, 4 * getpagesize()); | ||
| 219 | } | ||
| 220 | |||
| 221 | /* canary check pages */ | ||
| 222 | void | ||
| 223 | t20(void) | ||
| 224 | { | ||
| 225 | char *p = malloc(2*getpagesize() - 100); | ||
| 226 | p[2*getpagesize() - 100] = 0; | ||
| 227 | free(p); | ||
| 228 | } | ||
| 229 | |||
| 230 | /* out-of-bound write preceding chunk */ | ||
| 231 | void | ||
| 232 | t22(void) | ||
| 233 | { | ||
| 234 | int i, j; | ||
| 235 | unsigned char *p; | ||
| 236 | while (1) { | ||
| 237 | uintptr_t address; | ||
| 238 | p = malloc(32); | ||
| 239 | address = (uintptr_t)(void *)p; | ||
| 240 | /* we don't want to have a chunk on the last slot of a page */ | ||
| 241 | if (address / getpagesize() == (address + 32) / getpagesize()) | ||
| 242 | break; | ||
| 243 | free(p); | ||
| 244 | } | ||
| 245 | p[32] = 0; | ||
| 246 | for (i = 0; i < 10000; i++) | ||
| 247 | p = malloc(32); | ||
| 248 | } | ||
| 249 | |||
| 250 | struct test { | ||
| 251 | void (*test)(void); | ||
| 252 | const char *flags; | ||
| 253 | }; | ||
| 254 | |||
| 255 | struct test tests[] = { | ||
| 256 | { t0, "" }, | ||
| 257 | { t1, "" }, | ||
| 258 | { t2, "" }, | ||
| 259 | { t3, "F" }, | ||
| 260 | { t4, "" }, | ||
| 261 | { t5, "" }, | ||
| 262 | { t6, "J" }, | ||
| 263 | { t7, "JJ" }, | ||
| 264 | { t8, "FJ" }, | ||
| 265 | { t9, "C" }, | ||
| 266 | { t9, "JC" }, /* t10 re-uses code from t9 */ | ||
| 267 | { t11, "" }, | ||
| 268 | { t12, "" }, | ||
| 269 | { t13, "" }, | ||
| 270 | { t14, "C" }, | ||
| 271 | { t15, "" }, | ||
| 272 | { t16, "" }, | ||
| 273 | { t17, "C" }, | ||
| 274 | { t18, "" }, | ||
| 275 | { t19, "" }, | ||
| 276 | { t20, "C" }, | ||
| 277 | { t8, "FJD" }, /* t21 re-uses code from t8 */ | ||
| 278 | { t22, "J" }, | ||
| 279 | { t22, "JD" }, /* t23 re-uses code from t22 */ | ||
| 280 | }; | ||
| 281 | |||
| 282 | int main(int argc, char *argv[]) | ||
| 283 | { | ||
| 284 | |||
| 285 | const struct rlimit lim = {0, 0}; | ||
| 286 | int i, status; | ||
| 287 | pid_t pid; | ||
| 288 | char num[10]; | ||
| 289 | char options[10]; | ||
| 290 | extern char* malloc_options; | ||
| 291 | |||
| 292 | if (argc == 3) { | ||
| 293 | malloc_options = argv[2]; | ||
| 294 | /* prevent coredumps */ | ||
| 295 | setrlimit(RLIMIT_CORE, &lim); | ||
| 296 | i = atoi(argv[1]); | ||
| 297 | fprintf(stderr, "Test %d\n", i); | ||
| 298 | (*tests[i].test)(); | ||
| 299 | return 0; | ||
| 300 | } | ||
| 301 | |||
| 302 | for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) { | ||
| 303 | pid = fork(); | ||
| 304 | switch (pid) { | ||
| 305 | case 0: | ||
| 306 | snprintf(options, sizeof(options), "us%s", tests[i].flags); | ||
| 307 | snprintf(num, sizeof(num), "%d", i); | ||
| 308 | execl(argv[0], argv[0], num, options, NULL); | ||
| 309 | err(1, "exec"); | ||
| 310 | break; | ||
| 311 | case -1: | ||
| 312 | err(1, "fork"); | ||
| 313 | break; | ||
| 314 | default: | ||
| 315 | if (waitpid(pid, &status, 0) == -1) | ||
| 316 | err(1, "wait"); | ||
| 317 | if (!WIFSIGNALED(status) || | ||
| 318 | WTERMSIG(status) != SIGABRT) | ||
| 319 | errx(1, "Test %d did not abort", i); | ||
| 320 | break; | ||
| 321 | } | ||
| 322 | } | ||
| 323 | return 0; | ||
| 324 | } | ||
| 325 | |||
diff --git a/src/regress/lib/libc/malloc/malloc_general/Makefile b/src/regress/lib/libc/malloc/malloc_general/Makefile deleted file mode 100644 index 367b33b9c5..0000000000 --- a/src/regress/lib/libc/malloc/malloc_general/Makefile +++ /dev/null | |||
| @@ -1,43 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.7 2023/05/09 19:07:37 otto Exp $ | ||
| 2 | |||
| 3 | REGRESS_TARGETS= t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 | ||
| 4 | PROG= malloc_general | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
| 7 | |||
| 8 | t1: malloc_general | ||
| 9 | MALLOC_OPTIONS=su ${.OBJDIR}/malloc_general | ||
| 10 | |||
| 11 | t2: malloc_general | ||
| 12 | MALLOC_OPTIONS=suC ${.OBJDIR}/malloc_general | ||
| 13 | |||
| 14 | t3: malloc_general | ||
| 15 | MALLOC_OPTIONS=suJ ${.OBJDIR}/malloc_general | ||
| 16 | |||
| 17 | t4: malloc_general | ||
| 18 | MALLOC_OPTIONS=suF ${.OBJDIR}/malloc_general | ||
| 19 | |||
| 20 | t5: malloc_general | ||
| 21 | MALLOC_OPTIONS=suG ${.OBJDIR}/malloc_general | ||
| 22 | |||
| 23 | t6: malloc_general | ||
| 24 | MALLOC_OPTIONS=suS ${.OBJDIR}/malloc_general | ||
| 25 | |||
| 26 | t7: malloc_general | ||
| 27 | MALLOC_OPTIONS=suFGJ ${.OBJDIR}/malloc_general | ||
| 28 | |||
| 29 | t8: malloc_general | ||
| 30 | MALLOC_OPTIONS=suCJ ${.OBJDIR}/malloc_general | ||
| 31 | |||
| 32 | t9: malloc_general | ||
| 33 | MALLOC_OPTIONS=suCJJ ${.OBJDIR}/malloc_general | ||
| 34 | |||
| 35 | t10: malloc_general | ||
| 36 | MALLOC_OPTIONS=suJS ${.OBJDIR}/malloc_general | ||
| 37 | |||
| 38 | t11: malloc_general | ||
| 39 | MALLOC_OPTIONS=suFGJJ ${.OBJDIR}/malloc_general | ||
| 40 | |||
| 41 | t12: malloc_general | ||
| 42 | MALLOC_OPTIONS=suFCJJ ${.OBJDIR}/malloc_general | ||
| 43 | |||
diff --git a/src/regress/lib/libc/malloc/malloc_general/malloc_general.c b/src/regress/lib/libc/malloc/malloc_general/malloc_general.c deleted file mode 100644 index b243787bcf..0000000000 --- a/src/regress/lib/libc/malloc/malloc_general/malloc_general.c +++ /dev/null | |||
| @@ -1,123 +0,0 @@ | |||
| 1 | /* $OpenBSD: malloc_general.c,v 1.7 2022/01/09 07:18:50 otto Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2017 Otto Moerbeek <otto@drijf.net> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <err.h> | ||
| 19 | #include <stdio.h> | ||
| 20 | #include <stdlib.h> | ||
| 21 | #include <string.h> | ||
| 22 | |||
| 23 | /* #define VERBOSE */ | ||
| 24 | |||
| 25 | #define N 1000 | ||
| 26 | |||
| 27 | size_t | ||
| 28 | size(void) | ||
| 29 | { | ||
| 30 | int p = arc4random_uniform(17) + 3; | ||
| 31 | return arc4random_uniform(1 << p); | ||
| 32 | } | ||
| 33 | |||
| 34 | struct { void *p; size_t sz; } a[N]; | ||
| 35 | |||
| 36 | void | ||
| 37 | fill(u_char *p, size_t sz) | ||
| 38 | { | ||
| 39 | size_t i; | ||
| 40 | |||
| 41 | for (i = 0; i < sz; i++) | ||
| 42 | p[i] = i % 256; | ||
| 43 | } | ||
| 44 | |||
| 45 | void | ||
| 46 | check(u_char *p, size_t sz) | ||
| 47 | { | ||
| 48 | size_t i; | ||
| 49 | |||
| 50 | for (i = 0; i < sz; i++) | ||
| 51 | if (p[i] != i % 256) | ||
| 52 | errx(1, "check"); | ||
| 53 | } | ||
| 54 | |||
| 55 | int | ||
| 56 | main(int argc, char *argv[]) | ||
| 57 | { | ||
| 58 | int count, p, r, i; | ||
| 59 | void * q; | ||
| 60 | size_t sz; | ||
| 61 | |||
| 62 | for (count = 0; count < 800000; count++) { | ||
| 63 | if (count % 10000 == 0) { | ||
| 64 | printf("."); | ||
| 65 | fflush(stdout); | ||
| 66 | } | ||
| 67 | p = arc4random_uniform(2); | ||
| 68 | i = arc4random_uniform(N); | ||
| 69 | switch (p) { | ||
| 70 | case 0: | ||
| 71 | if (a[i].p) { | ||
| 72 | #ifdef VERBOSE | ||
| 73 | printf("F %p\n", a[i].p); | ||
| 74 | #endif | ||
| 75 | if (a[i].p) | ||
| 76 | check(a[i].p, a[i].sz); | ||
| 77 | free(a[i].p); | ||
| 78 | a[i].p = NULL; | ||
| 79 | } | ||
| 80 | sz = size(); | ||
| 81 | #ifdef VERBOSE | ||
| 82 | printf("M %zu=", sz); | ||
| 83 | #endif | ||
| 84 | r = arc4random_uniform(2); | ||
| 85 | a[i].p = r == 0 ? malloc_conceal(sz) : malloc(sz); | ||
| 86 | a[i].sz = sz; | ||
| 87 | #ifdef VERBOSE | ||
| 88 | printf("%p\n", a[i].p); | ||
| 89 | #endif | ||
| 90 | if (a[i].p) | ||
| 91 | fill(a[i].p, sz); | ||
| 92 | break; | ||
| 93 | case 1: | ||
| 94 | sz = size(); | ||
| 95 | #ifdef VERBOSE | ||
| 96 | printf("R %p %zu=", a[i].p, sz); | ||
| 97 | #endif | ||
| 98 | q = realloc(a[i].p, sz); | ||
| 99 | #ifdef VERBOSE | ||
| 100 | printf("%p\n", q); | ||
| 101 | #endif | ||
| 102 | if (a[i].p && q) | ||
| 103 | check(q, a[i].sz < sz ? a[i].sz : sz); | ||
| 104 | if (q) { | ||
| 105 | a[i].p = q; | ||
| 106 | a[i].sz = sz; | ||
| 107 | fill(a[i].p, sz); | ||
| 108 | } | ||
| 109 | break; | ||
| 110 | } | ||
| 111 | } | ||
| 112 | for (i = 0; i < N; i++) { | ||
| 113 | if (a[i].p) | ||
| 114 | check(a[i].p, a[i].sz); | ||
| 115 | r = arc4random_uniform(2); | ||
| 116 | if (r) | ||
| 117 | free(a[i].p); | ||
| 118 | else | ||
| 119 | freezero(a[i].p, a[i].sz); | ||
| 120 | } | ||
| 121 | printf("\n"); | ||
| 122 | return 0; | ||
| 123 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_threaderr/Makefile b/src/regress/lib/libc/malloc/malloc_threaderr/Makefile deleted file mode 100644 index 2d715af58b..0000000000 --- a/src/regress/lib/libc/malloc/malloc_threaderr/Makefile +++ /dev/null | |||
| @@ -1,13 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2018/01/28 14:55:24 otto Exp $ | ||
| 2 | |||
| 3 | # This test is supposed to print a malloc error and create a core dump | ||
| 4 | |||
| 5 | REGRESS_TARGETS= t1 | ||
| 6 | PROG= malloc_threaderr | ||
| 7 | LDADD+= -pthread | ||
| 8 | DPADD+= ${LIBPTHREAD} | ||
| 9 | |||
| 10 | .include <bsd.regress.mk> | ||
| 11 | |||
| 12 | t1: malloc_threaderr | ||
| 13 | ${.OBJDIR}/malloc_threaderr 2>&1 | fgrep 'in free(): bogus pointer (double free?)' | ||
diff --git a/src/regress/lib/libc/malloc/malloc_threaderr/malloc_threaderr.c b/src/regress/lib/libc/malloc/malloc_threaderr/malloc_threaderr.c deleted file mode 100644 index 3c38604ede..0000000000 --- a/src/regress/lib/libc/malloc/malloc_threaderr/malloc_threaderr.c +++ /dev/null | |||
| @@ -1,72 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2018 Otto Moerbeek <otto@drijf.net> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <err.h> | ||
| 18 | #include <pthread.h> | ||
| 19 | #include <signal.h> | ||
| 20 | #include <stdio.h> | ||
| 21 | #include <stdlib.h> | ||
| 22 | #include <unistd.h> | ||
| 23 | #include <sys/resource.h> | ||
| 24 | |||
| 25 | pthread_cond_t cond; | ||
| 26 | pthread_mutex_t mutex; | ||
| 27 | |||
| 28 | void *p; | ||
| 29 | |||
| 30 | void *m(void *arg) | ||
| 31 | { | ||
| 32 | p = malloc(100000); | ||
| 33 | if (p == NULL) | ||
| 34 | err(1, NULL); | ||
| 35 | return NULL; | ||
| 36 | } | ||
| 37 | |||
| 38 | void *f(void *arg) | ||
| 39 | { | ||
| 40 | free(p); | ||
| 41 | free(p); | ||
| 42 | return NULL; | ||
| 43 | } | ||
| 44 | |||
| 45 | void | ||
| 46 | catch(int x) | ||
| 47 | { | ||
| 48 | _exit(0); | ||
| 49 | } | ||
| 50 | |||
| 51 | int | ||
| 52 | main(void) | ||
| 53 | { | ||
| 54 | const struct rlimit lim = {0, 0}; | ||
| 55 | pthread_t t1, t2; | ||
| 56 | |||
| 57 | /* prevent coredumps */ | ||
| 58 | setrlimit(RLIMIT_CORE, &lim); | ||
| 59 | printf("This test is supposed to print a malloc error\n"); | ||
| 60 | |||
| 61 | signal(SIGABRT, catch); | ||
| 62 | |||
| 63 | if (pthread_create(&t1, NULL, m, NULL)) | ||
| 64 | err(1, "pthread_create"); | ||
| 65 | pthread_join(t1, NULL); | ||
| 66 | |||
| 67 | if (pthread_create(&t2, NULL, f, NULL)) | ||
| 68 | err(1, "pthread_create"); | ||
| 69 | pthread_join(t2, NULL); | ||
| 70 | |||
| 71 | return 1; | ||
| 72 | } | ||
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 799d2b9117..0000000000 --- a/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c +++ /dev/null | |||
| @@ -1,48 +0,0 @@ | |||
| 1 | /* $OpenBSD: malloc_ulimit1.c,v 1.5 2019/06/12 11:31:36 bluhm 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 | /* This test takes forever with junking turned on. */ | ||
| 26 | char *malloc_options = "jj"; | ||
| 27 | |||
| 28 | int | ||
| 29 | main() | ||
| 30 | { | ||
| 31 | struct rlimit lim; | ||
| 32 | size_t sz; | ||
| 33 | int i; | ||
| 34 | void *p; | ||
| 35 | |||
| 36 | if (getrlimit(RLIMIT_DATA, &lim) == -1) | ||
| 37 | err(1, "getrlimit"); | ||
| 38 | |||
| 39 | sz = lim.rlim_cur / FACTOR; | ||
| 40 | |||
| 41 | for (i = STARTI; i >= 0; i--) { | ||
| 42 | size_t len = (sz-i) * FACTOR; | ||
| 43 | p = malloc(len); | ||
| 44 | free(p); | ||
| 45 | free(malloc(4096)); | ||
| 46 | } | ||
| 47 | return (0); | ||
| 48 | } | ||
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 5d9e3774e7..0000000000 --- a/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c +++ /dev/null | |||
| @@ -1,46 +0,0 @@ | |||
| 1 | /* $OpenBSD: malloc_ulimit2.c,v 1.5 2019/06/12 11:31:36 bluhm 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 | /* This test takes forever with junking turned on. */ | ||
| 15 | char *malloc_options = "jj"; | ||
| 16 | |||
| 17 | int | ||
| 18 | main() | ||
| 19 | { | ||
| 20 | struct rlimit lim; | ||
| 21 | size_t sz; | ||
| 22 | int i; | ||
| 23 | void *p; | ||
| 24 | |||
| 25 | if (getrlimit(RLIMIT_DATA, &lim) == -1) | ||
| 26 | err(1, "getrlimit"); | ||
| 27 | |||
| 28 | sz = lim.rlim_cur / FACTOR; | ||
| 29 | |||
| 30 | for (i = 0; ; i++) { | ||
| 31 | size_t len = (sz-i) * FACTOR; | ||
| 32 | p = malloc(len); | ||
| 33 | if (p != NULL) { | ||
| 34 | free(p); | ||
| 35 | break; | ||
| 36 | } | ||
| 37 | } | ||
| 38 | i += 10; | ||
| 39 | for (; i >= 0; i--) { | ||
| 40 | size_t len = (sz-i) * FACTOR; | ||
| 41 | p = malloc(len); | ||
| 42 | free(p); | ||
| 43 | free(malloc(4096)); | ||
| 44 | } | ||
| 45 | return (0); | ||
| 46 | } | ||
