summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordhartmei <>2002-07-29 19:51:41 +0000
committerdhartmei <>2002-07-29 19:51:41 +0000
commit6f9ce38a0a9c5edc0d3984f9c1878e6f227fd210 (patch)
tree15553b4c82f60ec75d853da70ce8e83d81a865c5 /src
parent25bbc9a70b23853a4437755a23e8343266347817 (diff)
downloadopenbsd-6f9ce38a0a9c5edc0d3984f9c1878e6f227fd210.tar.gz
openbsd-6f9ce38a0a9c5edc0d3984f9c1878e6f227fd210.tar.bz2
openbsd-6f9ce38a0a9c5edc0d3984f9c1878e6f227fd210.zip
Try to modify __atexit directly and see if our function gets called.
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libc/atexit/Makefile12
-rw-r--r--src/regress/lib/libc/atexit/atexit_test.c131
-rw-r--r--src/regress/lib/libc/atexit/invalid.ok4
-rw-r--r--src/regress/lib/libc/atexit/valid.ok5
4 files changed, 152 insertions, 0 deletions
diff --git a/src/regress/lib/libc/atexit/Makefile b/src/regress/lib/libc/atexit/Makefile
new file mode 100644
index 0000000000..800c1b5ed6
--- /dev/null
+++ b/src/regress/lib/libc/atexit/Makefile
@@ -0,0 +1,12 @@
1# $OpenBSD: Makefile,v 1.1 2002/07/29 19:51:41 dhartmei Exp $
2
3NOMAN=
4PROG=atexit_test
5
6regress: ${PROG}
7 ./${PROG} -valid 2>${.OBJDIR}/valid.out
8 cmp -s ${.OBJDIR}/valid.out ${.CURDIR}/valid.ok
9 ./${PROG} -invalid 2>${.OBJDIR}/invalid.out
10 cmp -s ${.OBJDIR}/invalid.out ${.CURDIR}/invalid.ok
11
12.include <bsd.regress.mk>
diff --git a/src/regress/lib/libc/atexit/atexit_test.c b/src/regress/lib/libc/atexit/atexit_test.c
new file mode 100644
index 0000000000..fcfe95cb02
--- /dev/null
+++ b/src/regress/lib/libc/atexit/atexit_test.c
@@ -0,0 +1,131 @@
1/* $OpenBSD: atexit_test.c,v 1.1 2002/07/29 19:51:41 dhartmei 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 <signal.h>
40#include "/usr/src/lib/libc/stdlib/atexit.h"
41
42extern struct atexit *__atexit;
43extern void (*__cleanup)();
44
45void handle_first();
46void handle_middle();
47void handle_last();
48void handle_invalid();
49void handle_cleanup();
50void handle_signal(int);
51
52static int counter;
53
54int
55main(int argc, char *argv[])
56{
57 int i;
58
59 if (argc != 2 || (strcmp(argv[1], "-valid") &&
60 strcmp(argv[1], "-invalid"))) {
61 fprintf(stderr, "%s -valid/-invalid\n", argv[0]);
62 return (1);
63 }
64 fprintf(stderr, "main()\n");
65 if (atexit(handle_last)) {
66 perror("atexit(handle_last) failed");
67 return (1);
68 }
69 for (i = 0; i < 65535; ++i) {
70 if (atexit(handle_middle)) {
71 perror("atexit(handle_middle) failed");
72 return (1);
73 }
74 }
75 if (atexit(handle_first)) {
76 perror("atexit(handle_first) failed");
77 return (1);
78 }
79 /* this is supposed to segfault */
80 if (strcmp(argv[1], "-valid")) {
81 signal(SIGSEGV, handle_signal);
82 __atexit->fns[0] = handle_invalid;
83 }
84 __cleanup = handle_cleanup;
85 counter = 0;
86 fprintf(stderr, "main() returns\n");
87 return (0);
88}
89
90void
91handle_first()
92{
93 fprintf(stderr, "handle_first() counter == %i\n", counter);
94}
95
96void
97handle_middle()
98{
99 counter++;
100}
101
102void
103handle_last()
104{
105 fprintf(stderr, "handle_last() counter == %i\n", counter);
106}
107
108void
109handle_cleanup()
110{
111 fprintf(stderr, "handle_cleanup()\n");
112}
113
114void
115handle_invalid()
116{
117 fprintf(stderr, "handle_invalid() THIS SHOULD HAVE SEGFAULTED INSTEAD!\n");
118}
119
120void
121handle_signal(int sigraised)
122{
123 switch (sigraised) {
124 case SIGSEGV:
125 fprintf(stderr, "SIGSEGV\n");
126 exit(0);
127 default:
128 fprintf(stderr, "unexpected signal caught\n");
129 exit(1);
130 }
131}
diff --git a/src/regress/lib/libc/atexit/invalid.ok b/src/regress/lib/libc/atexit/invalid.ok
new file mode 100644
index 0000000000..98cbf8c1de
--- /dev/null
+++ b/src/regress/lib/libc/atexit/invalid.ok
@@ -0,0 +1,4 @@
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
new file mode 100644
index 0000000000..6509e827a7
--- /dev/null
+++ b/src/regress/lib/libc/atexit/valid.ok
@@ -0,0 +1,5 @@
1main()
2main() returns
3handle_first() counter == 0
4handle_last() counter == 65535
5handle_cleanup()