summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/malloc
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2019-11-19 19:57:05 +0000
committercvs2svn <admin@example.com>2019-11-19 19:57:05 +0000
commite9f9eb6198f1757b7c0dfef043fadf1fa8243022 (patch)
treeb5a648f6ccaf6c1cd9915ddb45503d1fccfeba0e /src/regress/lib/libc/malloc
parentab72e3a6f7e8d5c71bbba034410468781d5923b6 (diff)
downloadopenbsd-bluhm_20191119.tar.gz
openbsd-bluhm_20191119.tar.bz2
openbsd-bluhm_20191119.zip
This commit was manufactured by cvs2git to create tag 'bluhm_20191119'.bluhm_20191119
Diffstat (limited to 'src/regress/lib/libc/malloc')
-rw-r--r--src/regress/lib/libc/malloc/Makefile8
-rw-r--r--src/regress/lib/libc/malloc/malloc0test/Makefile11
-rw-r--r--src/regress/lib/libc/malloc/malloc0test/malloc0test.c120
-rw-r--r--src/regress/lib/libc/malloc/malloc_errno/Makefile5
-rw-r--r--src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c49
-rw-r--r--src/regress/lib/libc/malloc/malloc_general/Makefile27
-rw-r--r--src/regress/lib/libc/malloc/malloc_general/malloc_general.c123
-rw-r--r--src/regress/lib/libc/malloc/malloc_threaderr/Makefile13
-rw-r--r--src/regress/lib/libc/malloc/malloc_threaderr/malloc_threaderr.c58
-rw-r--r--src/regress/lib/libc/malloc/malloc_ulimit1/Makefile5
-rw-r--r--src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c48
-rw-r--r--src/regress/lib/libc/malloc/malloc_ulimit2/Makefile5
-rw-r--r--src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c46
13 files changed, 0 insertions, 518 deletions
diff --git a/src/regress/lib/libc/malloc/Makefile b/src/regress/lib/libc/malloc/Makefile
deleted file mode 100644
index 7eb84f6a6c..0000000000
--- a/src/regress/lib/libc/malloc/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
1# $OpenBSD: Makefile,v 1.7 2018/01/28 13:42:17 otto Exp $
2
3SUBDIR+= malloc_general malloc0test malloc_errno malloc_ulimit1 malloc_ulimit2
4SUBDIR+= malloc_threaderr
5
6install:
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
3PROG= malloc0test
4
5.for m in C D F G J j R S U X << >>>
6REGRESS_TARGETS += run-regress-${PROG}-${m:S/</-/g:S/>/+/g}
7run-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
14volatile sig_atomic_t got;
15jmp_buf jmp;
16
17static void
18catch(int signo)
19{
20 got++;
21 longjmp(jmp, 1);
22}
23
24static int
25test(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
36char *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 */
58int
59main(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:
84usage:
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
3PROG= 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. */
11char *malloc_options = "jj";
12
13static void
14testerrno(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 */
35int
36main(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_general/Makefile b/src/regress/lib/libc/malloc/malloc_general/Makefile
deleted file mode 100644
index ddc3220854..0000000000
--- a/src/regress/lib/libc/malloc/malloc_general/Makefile
+++ /dev/null
@@ -1,27 +0,0 @@
1# $OpenBSD: Makefile,v 1.4 2019/06/04 05:30:39 otto Exp $
2
3REGRESS_TARGETS= t1 t2 t3 t4 t5 t6 t7
4PROG= malloc_general
5
6.include <bsd.regress.mk>
7
8t1: malloc_general
9 MALLOC_OPTIONS=cfgju ${.OBJDIR}/malloc_general
10
11t2: malloc_general
12 MALLOC_OPTIONS=cfgjuC ${.OBJDIR}//malloc_general
13
14t3: malloc_general
15 MALLOC_OPTIONS=cfgjuJ ${.OBJDIR}//malloc_general
16
17t4: malloc_general
18 MALLOC_OPTIONS=cfgjuF ${.OBJDIR}//malloc_general
19
20t5: malloc_general
21 MALLOC_OPTIONS=cfgjuG ${.OBJDIR}//malloc_general
22
23t6: malloc_general
24 MALLOC_OPTIONS=cfgjuS ${.OBJDIR}//malloc_general
25
26t7: malloc_general
27 MALLOC_OPTIONS=cfgjuFGJ ${.OBJDIR}//malloc_general
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 7dbaf5d8aa..0000000000
--- a/src/regress/lib/libc/malloc/malloc_general/malloc_general.c
+++ /dev/null
@@ -1,123 +0,0 @@
1/* $OpenBSD */
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
27size_t
28size(void)
29{
30 int p = arc4random_uniform(13) + 3;
31 return arc4random_uniform(1 << p);
32}
33
34struct { void *p; size_t sz; } a[N];
35
36void
37fill(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
45void
46check(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
55int
56main(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
5REGRESS_TARGETS= t1
6PROG= malloc_threaderr
7LDADD+= -pthread
8DPADD+= ${LIBPTHREAD}
9
10.include <bsd.regress.mk>
11
12t1: 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 f34f37fc93..0000000000
--- a/src/regress/lib/libc/malloc/malloc_threaderr/malloc_threaderr.c
+++ /dev/null
@@ -1,58 +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 <stdio.h>
19#include <stdlib.h>
20#include <pthread.h>
21
22pthread_cond_t cond;
23pthread_mutex_t mutex;
24
25void *p;
26
27void *m(void *arg)
28{
29 p = malloc(100000);
30 if (p == NULL)
31 err(1, NULL);
32 return NULL;
33}
34
35void *f(void *arg)
36{
37 free(p);
38 free(p);
39 return NULL;
40}
41
42int
43main(void)
44{
45 pthread_t t1, t2;
46
47 printf("This test is supposed to print a malloc error and create a core dump\n");
48
49 if (pthread_create(&t1, NULL, m, NULL))
50 err(1, "pthread_create");
51 pthread_join(t1, NULL);
52
53 if (pthread_create(&t2, NULL, f, NULL))
54 err(1, "pthread_create");
55 pthread_join(t2, NULL);
56
57 return 0;
58}
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
3PROG= 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. */
26char *malloc_options = "jj";
27
28int
29main()
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
3PROG= 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. */
15char *malloc_options = "jj";
16
17int
18main()
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}