ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libcoro/coro.c
(Generate patch)

Comparing libcoro/coro.c (file contents):
Revision 1.22 by root, Sat Nov 25 00:27:00 2006 UTC vs.
Revision 1.26 by root, Fri Apr 27 19:35:28 2007 UTC

65 65
66static volatile coro_func coro_init_func; 66static volatile coro_func coro_init_func;
67static volatile void *coro_init_arg; 67static volatile void *coro_init_arg;
68static volatile coro_context *new_coro, *create_coro; 68static volatile coro_context *new_coro, *create_coro;
69 69
70/* what we really want to detect here is wether we use a new-enough version of GAS */
71/* instead, check for gcc 3 and ELF and hope for the best */
72#if __GNUC__ >= 3 && __ELF__
73# define HAVE_CFI 1
74#endif
75
70static void 76static void
71coro_init (void) 77coro_init (void)
72{ 78{
73 volatile coro_func func = coro_init_func; 79 volatile coro_func func = coro_init_func;
74 volatile void *arg = coro_init_arg; 80 volatile void *arg = coro_init_arg;
88/* trampoline signal handler */ 94/* trampoline signal handler */
89static void 95static void
90trampoline (int sig) 96trampoline (int sig)
91{ 97{
92 if (setjmp (((coro_context *)new_coro)->env)) 98 if (setjmp (((coro_context *)new_coro)->env))
99 {
100#if HAVE_CFI
101 asm (".cfi_startproc");
102#endif
93 coro_init (); /* start it */ 103 coro_init (); /* start it */
104#if HAVE_CFI
105 asm (".cfi_endproc");
106#endif
107 }
94 else 108 else
95 trampoline_count++; 109 trampoline_count++;
96} 110}
97 111
98# endif 112# endif
99 113
100#endif 114#endif
101 115
102/* initialize a machine state */ 116/* initialize a machine state */
103void coro_create(coro_context *ctx, 117void coro_create (coro_context *ctx,
104 coro_func coro, void *arg, 118 coro_func coro, void *arg,
105 void *sptr, long ssize) 119 void *sptr, long ssize)
106{ 120{
107#if CORO_UCONTEXT 121#if CORO_UCONTEXT
108 122
109 getcontext (&(ctx->uc)); 123 getcontext (&(ctx->uc));
110 124
140 nsa.sa_handler = trampoline; 154 nsa.sa_handler = trampoline;
141 sigemptyset (&nsa.sa_mask); 155 sigemptyset (&nsa.sa_mask);
142 nsa.sa_flags = SA_ONSTACK; 156 nsa.sa_flags = SA_ONSTACK;
143 157
144 if (sigaction (SIGUSR2, &nsa, &osa)) 158 if (sigaction (SIGUSR2, &nsa, &osa))
159 {
145 perror ("sigaction"); 160 perror ("sigaction");
161 abort ();
162 }
146 163
147 /* set the new stack */ 164 /* set the new stack */
148 nstk.ss_sp = STACK_ADJUST_PTR (sptr,ssize); /* yes, some platforms (IRIX) get this wrong. */ 165 nstk.ss_sp = STACK_ADJUST_PTR (sptr,ssize); /* yes, some platforms (IRIX) get this wrong. */
149 nstk.ss_size = STACK_ADJUST_SIZE (sptr,ssize); 166 nstk.ss_size = STACK_ADJUST_SIZE (sptr,ssize);
150 nstk.ss_flags = 0; 167 nstk.ss_flags = 0;
151 168
152 if (sigaltstack (&nstk, &ostk) < 0) 169 if (sigaltstack (&nstk, &ostk) < 0)
170 {
153 perror ("sigaltstack"); 171 perror ("sigaltstack");
172 abort ();
173 }
154 174
155 trampoline_count = 0; 175 trampoline_count = 0;
156 kill (getpid (), SIGUSR2); 176 kill (getpid (), SIGUSR2);
157 sigfillset (&nsig); sigdelset (&nsig, SIGUSR2); 177 sigfillset (&nsig); sigdelset (&nsig, SIGUSR2);
158 178
195#endif 215#endif
196 216
197# elif CORO_LINUX 217# elif CORO_LINUX
198 218
199 _setjmp (ctx->env); 219 _setjmp (ctx->env);
200#if defined(__GLIBC__) && defined(__GLIBC_MINOR__) \
201 && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined(JB_PC) && defined(JB_SP) 220#if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined (JB_PC) && defined (JB_SP)
202 ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init; 221 ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init;
203 ctx->env[0].__jmpbuf[JB_SP] = (long)STACK_ADJUST_PTR (sptr,ssize); 222 ctx->env[0].__jmpbuf[JB_SP] = (long)STACK_ADJUST_PTR (sptr, ssize);
204#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) \
205 && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined(__mc68000__) 223#elif __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined (__mc68000__)
206 ctx->env[0].__jmpbuf[0].__aregs[0] = (long int)coro_init; 224 ctx->env[0].__jmpbuf[0].__aregs[0] = (long int)coro_init;
207 ctx->env[0].__jmpbuf[0].__sp = (int *)((char *)sptr + ssize); 225 ctx->env[0].__jmpbuf[0].__sp = (int *)((char *)sptr + ssize);
208#elif defined(__GNU_LIBRARY__) && defined(__i386__) 226#elif defined (__GNU_LIBRARY__) && defined (__i386__)
209 ctx->env[0].__jmpbuf[0].__pc = (char *)coro_init; 227 ctx->env[0].__jmpbuf[0].__pc = (char *)coro_init;
210 ctx->env[0].__jmpbuf[0].__sp = (void *)((char *)sptr + ssize); 228 ctx->env[0].__jmpbuf[0].__sp = (void *)((char *)sptr + ssize);
211#elif defined(__GNU_LIBRARY__) && defined(__amd64__) 229#elif defined (__GNU_LIBRARY__) && defined (__amd64__)
212 ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init; 230 ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init;
213 ctx->env[0].__jmpbuf[JB_RSP] = (long)STACK_ADJUST_PTR (sptr,ssize); 231 ctx->env[0].__jmpbuf[JB_RSP] = (long)STACK_ADJUST_PTR (sptr, ssize);
214#else 232#else
215#error "linux libc or architecture not supported" 233#error "linux libc or architecture not supported"
216#endif 234#endif
217 235
218# elif CORO_IRIX 236# elif CORO_IRIX
219 237
220 setjmp (ctx->env); 238 setjmp (ctx->env);
221 ctx->env[JB_PC] = (__uint64_t)coro_init; 239 ctx->env[JB_PC] = (__uint64_t)coro_init;
222 ctx->env[JB_SP] = (__uint64_t)STACK_ADJUST_PTR (sptr,ssize); 240 ctx->env[JB_SP] = (__uint64_t)STACK_ADJUST_PTR (sptr, ssize);
223 241
224# endif 242# endif
225 243
226 coro_transfer ((coro_context *)create_coro, (coro_context *)new_coro); 244 coro_transfer ((coro_context *)create_coro, (coro_context *)new_coro);
227 245

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines