diff options
author | marc <> | 2001-12-17 02:36:00 +0000 |
---|---|---|
committer | marc <> | 2001-12-17 02:36:00 +0000 |
commit | 501b069937cce03a23cfe88e87a3f96f0a5a0869 (patch) | |
tree | 9cca214def0c5443e5dd34faff684d3c65ee428f | |
parent | 5350d20c661ce6484258b9c95d65c215de6bae48 (diff) | |
download | openbsd-501b069937cce03a23cfe88e87a3f96f0a5a0869.tar.gz openbsd-501b069937cce03a23cfe88e87a3f96f0a5a0869.tar.bz2 openbsd-501b069937cce03a23cfe88e87a3f96f0a5a0869.zip |
sigreturn test program
-rw-r--r-- | src/regress/lib/libc/sigreturn/Makefile | 16 | ||||
-rw-r--r-- | src/regress/lib/libc/sigreturn/sigret.c | 168 |
2 files changed, 184 insertions, 0 deletions
diff --git a/src/regress/lib/libc/sigreturn/Makefile b/src/regress/lib/libc/sigreturn/Makefile new file mode 100644 index 0000000000..6a40c40fe0 --- /dev/null +++ b/src/regress/lib/libc/sigreturn/Makefile | |||
@@ -0,0 +1,16 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2001/12/17 02:36:00 marc Exp $ | ||
2 | |||
3 | PROG= sigret | ||
4 | SRCS= sigret.c | ||
5 | NOMAN= noman | ||
6 | |||
7 | DEBUG+= -ggdb | ||
8 | |||
9 | .PATH: ${.CURDIR}/../sigret | ||
10 | |||
11 | install: | ||
12 | |||
13 | regress: ${PROG} | ||
14 | ./${PROG} | ||
15 | |||
16 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/sigreturn/sigret.c b/src/regress/lib/libc/sigreturn/sigret.c new file mode 100644 index 0000000000..bd661a3649 --- /dev/null +++ b/src/regress/lib/libc/sigreturn/sigret.c | |||
@@ -0,0 +1,168 @@ | |||
1 | /* | ||
2 | * Playing games with sigreturn. Check if calling sigreturn from a | ||
3 | * signal handler screws anything up. | ||
4 | * | ||
5 | * Run with: | ||
6 | * -a: use an alternate signal stack | ||
7 | * | ||
8 | * -b: call sigreturn from outside of a signal handler | ||
9 | * An error is OK | ||
10 | * | ||
11 | * -c: clobber the sigcontext before calling sigreturn | ||
12 | * the program should die | ||
13 | * | ||
14 | * -f: don't use sigreturn -- fall through the signal handler | ||
15 | * -c, and -i options ignored when used | ||
16 | * | ||
17 | * -i: call sigreturn from a function called by the signal handler | ||
18 | * | ||
19 | * Program should not exit until killed. | ||
20 | */ | ||
21 | |||
22 | #include <sys/time.h> | ||
23 | |||
24 | #include <err.h> | ||
25 | #include <signal.h> | ||
26 | #include <stdarg.h> | ||
27 | #include <stdio.h> | ||
28 | #include <stdlib.h> | ||
29 | #include <string.h> | ||
30 | #include <unistd.h> | ||
31 | |||
32 | int altstack; | ||
33 | int badcall; | ||
34 | int clobbercall; | ||
35 | int fallthru; | ||
36 | int indirect; | ||
37 | |||
38 | volatile int count; | ||
39 | struct sigcontext gscp; | ||
40 | int gscp_loaded; | ||
41 | |||
42 | static void | ||
43 | usage(const char * err, ...) | ||
44 | { | ||
45 | extern const char * __progname; | ||
46 | |||
47 | if (err) { | ||
48 | va_list ap; | ||
49 | va_start(ap, err); | ||
50 | vwarnx(err, ap); | ||
51 | va_end(ap); | ||
52 | } | ||
53 | fprintf(stderr, "usage: %s [-abcfi]\n", __progname); | ||
54 | exit(1); | ||
55 | } | ||
56 | |||
57 | void | ||
58 | indirect_return(struct sigcontext * scp) | ||
59 | { | ||
60 | sigreturn(scp); | ||
61 | } | ||
62 | |||
63 | void | ||
64 | sig_handler(int sig, siginfo_t *blah, void *x) | ||
65 | { | ||
66 | struct sigcontext * scp = x; | ||
67 | |||
68 | count++; | ||
69 | |||
70 | if (!fallthru) { | ||
71 | if (clobbercall) | ||
72 | memset(scp, 0, sizeof *scp); | ||
73 | if (indirect) | ||
74 | indirect_return(scp); | ||
75 | else if (badcall) { | ||
76 | gscp = *scp; | ||
77 | gscp_loaded = 1; | ||
78 | } else | ||
79 | sigreturn(scp); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | void | ||
84 | test2(char *fmt) | ||
85 | { | ||
86 | char *ofmt = fmt; | ||
87 | |||
88 | if (gscp_loaded) { | ||
89 | gscp_loaded = 0; | ||
90 | sigreturn(&gscp); | ||
91 | } | ||
92 | |||
93 | for (; *fmt; fmt++) | ||
94 | switch (*fmt) { | ||
95 | case 'i': | ||
96 | case 'c': | ||
97 | case 'l': | ||
98 | case 'p': | ||
99 | break; | ||
100 | default: | ||
101 | fprintf(stderr, | ||
102 | "unexpected character 0x%02x `%c' in %s: count %d\n", | ||
103 | *fmt, *fmt, ofmt, count); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | int | ||
108 | main(int argc, char * argv[]) | ||
109 | { | ||
110 | extern char *optarg; | ||
111 | extern int optind; | ||
112 | |||
113 | int opt; | ||
114 | |||
115 | struct sigaction act; | ||
116 | struct sigaltstack ss; | ||
117 | |||
118 | while ((opt = getopt(argc, argv, "abcfi")) != -1) { | ||
119 | switch (opt) { | ||
120 | case 'a': | ||
121 | /* use sigaltstack */ | ||
122 | altstack = 1; | ||
123 | break; | ||
124 | case 'b': | ||
125 | /* call outside of sig_handler */ | ||
126 | badcall = 1; | ||
127 | break; | ||
128 | case 'c': | ||
129 | /* force error by munging sigcontext */ | ||
130 | clobbercall = 1; | ||
131 | break; | ||
132 | case 'f': | ||
133 | /* don't use sigreturn */ | ||
134 | fallthru = 1; | ||
135 | break; | ||
136 | case 'i': | ||
137 | /* call sigreturn indirectly */ | ||
138 | indirect = 1; | ||
139 | break; | ||
140 | } | ||
141 | } | ||
142 | |||
143 | /* make sure there is no other cruft left on the command line */ | ||
144 | if (optind != argc) | ||
145 | usage("unknown arguement -- %s", argv[ optind ]); | ||
146 | |||
147 | if (altstack) { | ||
148 | if ((ss.ss_sp = malloc(SIGSTKSZ)) == NULL) | ||
149 | errx(1, "ss_sp malloc"); | ||
150 | |||
151 | ss.ss_size = SIGSTKSZ; | ||
152 | ss.ss_flags = 0; | ||
153 | if (sigaltstack(&ss,0) == -1) | ||
154 | err(1, "sigaltstack"); | ||
155 | } | ||
156 | |||
157 | sigfillset(&act.sa_mask); | ||
158 | act.sa_sigaction = sig_handler; | ||
159 | act.sa_flags = SA_RESTART; | ||
160 | if (altstack) | ||
161 | act.sa_flags |= SA_ONSTACK; | ||
162 | sigaction(SIGALRM, &act, NULL); | ||
163 | |||
164 | ualarm(10000, 10000); | ||
165 | |||
166 | while (1) | ||
167 | test2("iclp"); | ||
168 | } | ||