diff options
author | dhartmei <> | 2002-07-29 19:51:41 +0000 |
---|---|---|
committer | dhartmei <> | 2002-07-29 19:51:41 +0000 |
commit | 6f9ce38a0a9c5edc0d3984f9c1878e6f227fd210 (patch) | |
tree | 15553b4c82f60ec75d853da70ce8e83d81a865c5 /src | |
parent | 25bbc9a70b23853a4437755a23e8343266347817 (diff) | |
download | openbsd-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/Makefile | 12 | ||||
-rw-r--r-- | src/regress/lib/libc/atexit/atexit_test.c | 131 | ||||
-rw-r--r-- | src/regress/lib/libc/atexit/invalid.ok | 4 | ||||
-rw-r--r-- | src/regress/lib/libc/atexit/valid.ok | 5 |
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 | |||
3 | NOMAN= | ||
4 | PROG=atexit_test | ||
5 | |||
6 | regress: ${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 | |||
42 | extern struct atexit *__atexit; | ||
43 | extern void (*__cleanup)(); | ||
44 | |||
45 | void handle_first(); | ||
46 | void handle_middle(); | ||
47 | void handle_last(); | ||
48 | void handle_invalid(); | ||
49 | void handle_cleanup(); | ||
50 | void handle_signal(int); | ||
51 | |||
52 | static int counter; | ||
53 | |||
54 | int | ||
55 | main(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 | |||
90 | void | ||
91 | handle_first() | ||
92 | { | ||
93 | fprintf(stderr, "handle_first() counter == %i\n", counter); | ||
94 | } | ||
95 | |||
96 | void | ||
97 | handle_middle() | ||
98 | { | ||
99 | counter++; | ||
100 | } | ||
101 | |||
102 | void | ||
103 | handle_last() | ||
104 | { | ||
105 | fprintf(stderr, "handle_last() counter == %i\n", counter); | ||
106 | } | ||
107 | |||
108 | void | ||
109 | handle_cleanup() | ||
110 | { | ||
111 | fprintf(stderr, "handle_cleanup()\n"); | ||
112 | } | ||
113 | |||
114 | void | ||
115 | handle_invalid() | ||
116 | { | ||
117 | fprintf(stderr, "handle_invalid() THIS SHOULD HAVE SEGFAULTED INSTEAD!\n"); | ||
118 | } | ||
119 | |||
120 | void | ||
121 | handle_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 @@ | |||
1 | main() | ||
2 | SIGSEGV | ||
3 | handle_first() counter == 0 | ||
4 | handle_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 @@ | |||
1 | main() | ||
2 | main() returns | ||
3 | handle_first() counter == 0 | ||
4 | handle_last() counter == 65535 | ||
5 | handle_cleanup() | ||