ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libcoro/conftest.c
Revision: 1.1
Committed: Sun Sep 16 01:34:36 2001 UTC (22 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-1_1, rel-1_0
Log Message:
*** empty log message ***

File Contents

# Content
1 /*
2 * This file was taken from pth-1.40/aclocal.m4
3 * The original copyright is below.
4 *
5 * GNU Pth - The GNU Portable Threads
6 * Copyright (c) 1999-2001 Ralf S. Engelschall <rse@engelschall.com>
7 *
8 * This file is part of GNU Pth, a non-preemptive thread scheduling
9 * library which can be found at http://www.gnu.org/software/pth/.
10 *
11 * This file is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This file is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this file; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * USA, or contact Marc Lehmann <pcg@goof.com>.
25 */
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #if defined(TEST_sigstack) || defined(TEST_sigaltstack)
31 #include <sys/types.h>
32 #include <signal.h>
33 #include <unistd.h>
34 #endif
35 #if defined(TEST_makecontext)
36 #include <ucontext.h>
37 #endif
38 union alltypes {
39 long l;
40 double d;
41 void *vp;
42 void (*fp)(void);
43 char *cp;
44 };
45 static volatile char *handler_addr = (char *)0xDEAD;
46 #if defined(TEST_sigstack) || defined(TEST_sigaltstack)
47 static volatile int handler_done = 0;
48 void handler(int sig)
49 {
50 char garbage[1024];
51 int i;
52 auto int dummy;
53 for (i = 0; i < 1024; i++)
54 garbage[i] = 'X';
55 handler_addr = (char *)&dummy;
56 handler_done = 1;
57 return;
58 }
59 #endif
60 #if defined(TEST_makecontext)
61 static ucontext_t uc_handler;
62 static ucontext_t uc_main;
63 void handler(void)
64 {
65 char garbage[1024];
66 int i;
67 auto int dummy;
68 for (i = 0; i < 1024; i++)
69 garbage[i] = 'X';
70 handler_addr = (char *)&dummy;
71 swapcontext(&uc_handler, &uc_main);
72 return;
73 }
74 #endif
75 int main(int argc, char *argv[])
76 {
77 FILE *f;
78 char *skaddr;
79 char *skbuf;
80 int sksize;
81 char result[1024];
82 int i;
83 sksize = 32768;
84 skbuf = (char *)malloc(sksize*2+2*sizeof(union alltypes));
85 if (skbuf == NULL)
86 exit(1);
87 for (i = 0; i < sksize*2+2*sizeof(union alltypes); i++)
88 skbuf[i] = 'A';
89 skaddr = skbuf+sizeof(union alltypes);
90 #if defined(TEST_sigstack) || defined(TEST_sigaltstack)
91 {
92 struct sigaction sa;
93 #if defined(TEST_sigstack)
94 struct sigstack ss;
95 #elif defined(TEST_sigaltstack) && defined(HAVE_STACK_T)
96 stack_t ss;
97 #else
98 struct sigaltstack ss;
99 #endif
100 #if defined(TEST_sigstack)
101 ss.ss_sp = (void *)(skaddr + sksize);
102 ss.ss_onstack = 0;
103 if (sigstack(&ss, NULL) < 0)
104 exit(1);
105 #elif defined(TEST_sigaltstack)
106 ss.ss_sp = (void *)(skaddr + sksize);
107 ss.ss_size = sksize;
108 ss.ss_flags = 0;
109 if (sigaltstack(&ss, NULL) < 0)
110 exit(1);
111 #endif
112 memset((void *)&sa, 0, sizeof(struct sigaction));
113 sa.sa_handler = handler;
114 sa.sa_flags = SA_ONSTACK;
115 sigemptyset(&sa.sa_mask);
116 sigaction(SIGUSR1, &sa, NULL);
117 kill(getpid(), SIGUSR1);
118 while (!handler_done)
119 /*nop*/;
120 }
121 #endif
122 #if defined(TEST_makecontext)
123 {
124 if (getcontext(&uc_handler) != 0)
125 exit(1);
126 uc_handler.uc_link = NULL;
127 uc_handler.uc_stack.ss_sp = (void *)(skaddr + sksize);
128 uc_handler.uc_stack.ss_size = sksize;
129 uc_handler.uc_stack.ss_flags = 0;
130 makecontext(&uc_handler, handler, 1);
131 swapcontext(&uc_main, &uc_handler);
132 }
133 #endif
134 if (handler_addr == (char *)0xDEAD)
135 exit(1);
136 if (handler_addr < skaddr+sksize) {
137 /* stack was placed into lower area */
138 if (*(skaddr+sksize) != 'A')
139 sprintf(result, "(skaddr)+(sksize)-%d,(sksize)-%d",
140 sizeof(union alltypes), sizeof(union alltypes));
141 else
142 strcpy(result, "(skaddr)+(sksize),(sksize)");
143 }
144 else {
145 /* stack was placed into higher area */
146 if (*(skaddr+sksize*2) != 'A')
147 sprintf(result, "(skaddr),(sksize)-%d", sizeof(union alltypes));
148 else
149 strcpy(result, "(skaddr),(sksize)");
150 }
151 printf("%s\n", result);
152 exit(0);
153 }
154