1 /* Test 9 setjmp with register variables. Author: Ceriel Jacobs */
13 _PROTOTYPE(int main
, (int argc
, char *argv
[]));
14 _PROTOTYPE(void test9a
, (void));
15 _PROTOTYPE(void test9b
, (void));
16 _PROTOTYPE(void test9c
, (void));
17 _PROTOTYPE(void test9d
, (void));
18 _PROTOTYPE(void test9e
, (void));
19 _PROTOTYPE(void test9f
, (void));
20 _PROTOTYPE(char *addr
, (void));
21 _PROTOTYPE(void garbage
, (void));
22 _PROTOTYPE(void level1
, (void));
23 _PROTOTYPE(void level2
, (void));
24 _PROTOTYPE(void dolev
, (void));
25 _PROTOTYPE(void catch, (int s
));
26 _PROTOTYPE(void hard
, (void));
36 if (argc
== 2) m
= atoi(argv
[1]);
37 for (j
= 0; j
< 100; j
++) {
38 if (m
& 00001) test9a();
39 if (m
& 00002) test9b();
40 if (m
& 00004) test9c();
41 if (m
& 00010) test9d();
42 if (m
& 00020) test9e();
43 if (m
& 00040) test9f();
47 if (setjmp(envm
) == 0) {
54 printf("WARNING: The setjmp/longjmp of this machine restore register variables\n\
55 to the value they had at the time of the Setjmp\n");
57 printf("Aha, I just found one last error\n");
62 return(-1); /* impossible */
110 if (p
!= &buf
[100]) e(1);
115 register char *p
, *q
;
121 if (p
!= &buf
[100]) e(1);
122 if (q
!= &buf
[200]) e(2);
127 register char *p
, *q
, *r
;
134 if (p
!= &buf
[100]) e(1);
135 if (q
!= &buf
[200]) e(2);
136 if (r
!= &buf
[300]) e(3);
141 /* return address of local variable.
142 This way we can check that the stack is not polluted.
155 register char *p
, *q
, *r
;
164 switch (setjmp(env
)) {
169 * to defeat the smartness of the GNU C optimizer we pretend we
170 * use 'a'. Otherwise the optimizer will not detect the looping
171 * effectuated by setjmp/longjmp, so that it thinks it can get
172 * rid of the assignment to 'a'.
182 if (p
!= &buf
[300]) e(14);
183 if (q
!= &buf
[400]) e(15);
184 if (r
!= &buf
[500]) e(16);
186 if (a
!= tmpa
) e(17);
193 if (p
!= &buf
[300]) e(24);
194 if (q
!= &buf
[400]) e(25);
195 if (r
!= &buf
[500]) e(26);
197 if (a
!= tmpa
) e(27);
204 if (p
!= &buf
[300]) e(34);
205 if (q
!= &buf
[400]) e(35);
206 if (r
!= &buf
[500]) e(36);
208 if (a
!= tmpa
) e(37);
214 if (p
!= &buf
[300]) e(44);
215 if (q
!= &buf
[400]) e(45);
216 if (r
!= &buf
[500]) e(46);
218 if (a
!= tmpa
) e(47);
270 signal(SIGHUP
, catch);
271 for (p
= buf
; p
<= &buf
[511]; p
++) *p
= 025;
272 kill(getpid(), SIGHUP
);