summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/atexit
diff options
context:
space:
mode:
Diffstat (limited to 'src/regress/lib/libc/atexit')
-rw-r--r--src/regress/lib/libc/atexit/Makefile16
-rw-r--r--src/regress/lib/libc/atexit/atexit_test.c152
-rw-r--r--src/regress/lib/libc/atexit/invalid.ok4
-rw-r--r--src/regress/lib/libc/atexit/valid.ok5
4 files changed, 0 insertions, 177 deletions
diff --git a/src/regress/lib/libc/atexit/Makefile b/src/regress/lib/libc/atexit/Makefile
deleted file mode 100644
index eb8c55e91e..0000000000
--- a/src/regress/lib/libc/atexit/Makefile
+++ /dev/null
@@ -1,16 +0,0 @@
1# $OpenBSD: Makefile,v 1.7 2017/07/27 15:08:37 bluhm Exp $
2
3PROG = atexit_test
4CPPFLAGS = -I${.CURDIR}/../../../../lib/libc
5CLEANFILES = invalid.out valid.out
6LDADD = -static
7
8run-regress-${PROG}: ${PROG}
9 ./${PROG} -valid 2>${.OBJDIR}/valid.out
10 cmp -s ${.OBJDIR}/valid.out ${.CURDIR}/valid.ok
11 ./${PROG} -invalid-atexit 2>${.OBJDIR}/invalid.out
12 cmp -s ${.OBJDIR}/invalid.out ${.CURDIR}/invalid.ok
13 ./${PROG} -invalid-cleanup 2>${.OBJDIR}/invalid.out
14 cmp -s ${.OBJDIR}/invalid.out ${.CURDIR}/invalid.ok
15
16.include <bsd.regress.mk>
diff --git a/src/regress/lib/libc/atexit/atexit_test.c b/src/regress/lib/libc/atexit/atexit_test.c
deleted file mode 100644
index f00a81a6c9..0000000000
--- a/src/regress/lib/libc/atexit/atexit_test.c
+++ /dev/null
@@ -1,152 +0,0 @@
1/* $OpenBSD: atexit_test.c,v 1.10 2024/03/05 19:27:47 miod Exp $ */
2
3/*
4 * Copyright (c) 2002 Daniel Hartmeier
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * Effort sponsored in part by the Defense Advanced Research Projects
32 * Agency (DARPA) and Air Force Research Laboratory, Air Force
33 * Materiel Command, USAF, under agreement number F30602-01-2-0537.
34 *
35 */
36
37#include <stdio.h>
38#include <stdlib.h>
39#include <string.h>
40#include <signal.h>
41#include <unistd.h>
42
43/*
44 * XXX Provide a prototype for aligned_alloc on pre-C11 compilers to prevent
45 * inclusion of hidden/stdlib.h below to cause a missing prototype error.
46 */
47#if (__ISO_C_VISIBLE - 0) < 2011
48void *aligned_alloc(size_t, size_t);
49#endif
50
51#include "include/namespace.h"
52#include "hidden/stdlib.h"
53#include "stdlib/atexit.h"
54
55void handle_first(void);
56void handle_middle(void);
57void handle_last(void);
58void handle_invalid(void *);
59void handle_cleanup(void);
60void handle_signal(int);
61
62static int counter;
63
64int
65main(int argc, char *argv[])
66{
67 int i;
68
69 if (argc != 2 || (strcmp(argv[1], "-valid") &&
70 strcmp(argv[1], "-invalid-atexit") &&
71 strcmp(argv[1], "-invalid-cleanup"))) {
72 fprintf(stderr, "%s -valid/-invalid-atexit/-invalid-cleanup\n",
73 argv[0]);
74 return (1);
75 }
76 fprintf(stderr, "main()\n");
77 if (atexit(handle_last)) {
78 perror("atexit(handle_last) failed");
79 return (1);
80 }
81 for (i = 0; i < 65535; ++i) {
82 if (atexit(handle_middle)) {
83 perror("atexit(handle_middle) failed");
84 return (1);
85 }
86 }
87 if (atexit(handle_first)) {
88 perror("atexit(handle_first) failed");
89 return (1);
90 }
91 /* this is supposed to segfault */
92 if (!strcmp(argv[1], "-invalid-atexit")) {
93 signal(SIGSEGV, handle_signal);
94 __atexit->fns[0].fn_ptr = handle_invalid;
95 } else if (!strcmp(argv[1], "-invalid-cleanup")) {
96 struct atexit *p = __atexit;
97
98 signal(SIGSEGV, handle_signal);
99 while (p != NULL && p->next != NULL)
100 p = p->next;
101 if (p == NULL)
102 fprintf(stderr, "p == NULL, no page found\n");
103 p->fns[0].fn_ptr = handle_invalid;
104 }
105 __atexit_register_cleanup(handle_cleanup);
106 counter = 0;
107 fprintf(stderr, "main() returns\n");
108 return (0);
109}
110
111void
112handle_first(void)
113{
114 fprintf(stderr, "handle_first() counter == %i\n", counter);
115}
116
117void
118handle_middle(void)
119{
120 counter++;
121}
122
123void
124handle_last(void)
125{
126 fprintf(stderr, "handle_last() counter == %i\n", counter);
127}
128
129void
130handle_cleanup(void)
131{
132 fprintf(stderr, "handle_cleanup()\n");
133}
134
135void
136handle_invalid(void *arg)
137{
138 fprintf(stderr, "handle_invalid() THIS SHOULD HAVE SEGFAULTED INSTEAD!\n");
139}
140
141void
142handle_signal(int sigraised)
143{
144 switch (sigraised) {
145 case SIGSEGV:
146 dprintf(STDERR_FILENO, "SIGSEGV\n");
147 exit(0);
148 default:
149 dprintf(STDERR_FILENO, "unexpected signal caught\n");
150 exit(1);
151 }
152}
diff --git a/src/regress/lib/libc/atexit/invalid.ok b/src/regress/lib/libc/atexit/invalid.ok
deleted file mode 100644
index 98cbf8c1de..0000000000
--- a/src/regress/lib/libc/atexit/invalid.ok
+++ /dev/null
@@ -1,4 +0,0 @@
1main()
2SIGSEGV
3handle_first() counter == 0
4handle_last() counter == 65535
diff --git a/src/regress/lib/libc/atexit/valid.ok b/src/regress/lib/libc/atexit/valid.ok
deleted file mode 100644
index 6509e827a7..0000000000
--- a/src/regress/lib/libc/atexit/valid.ok
+++ /dev/null
@@ -1,5 +0,0 @@
1main()
2main() returns
3handle_first() counter == 0
4handle_last() counter == 65535
5handle_cleanup()