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

Comparing libcoro/coro.c (file contents):
Revision 1.2 by root, Mon Jul 23 22:09:39 2001 UTC vs.
Revision 1.4 by root, Tue Jul 24 19:52:55 2001 UTC

30 * go to Ralf S. Engelschall <rse@engelschall.com>. 30 * go to Ralf S. Engelschall <rse@engelschall.com>.
31 */ 31 */
32 32
33#include "coro.h" 33#include "coro.h"
34 34
35#if CORO_LOOSE || CORO_SJLJ 35#if CORO_LOOSE || CORO_SJLJ || CORO_LINUX
36 36
37#include <signal.h> 37#include <signal.h>
38 38
39static volatile coro_func coro_init_func; 39static volatile coro_func coro_init_func;
40static volatile void *coro_init_arg; 40static volatile void *coro_init_arg;
46 volatile coro_func func = coro_init_func; 46 volatile coro_func func = coro_init_func;
47 volatile void *arg = coro_init_arg; 47 volatile void *arg = coro_init_arg;
48 48
49 coro_transfer ((coro_context *)new_coro, (coro_context *)create_coro); 49 coro_transfer ((coro_context *)new_coro, (coro_context *)create_coro);
50 50
51 func (arg); 51 func ((void *)arg);
52 52
53 /* the new coro returned. bad. just abort() for now */ 53 /* the new coro returned. bad. just abort() for now */
54 abort (); 54 abort ();
55} 55}
56 56
61 61
62/* trampoline signal handler */ 62/* trampoline signal handler */
63static void 63static void
64trampoline(int sig) 64trampoline(int sig)
65{ 65{
66 if (setjmp (&(((coro_context *)new_coro)->env))) 66 if (setjmp (((coro_context *)new_coro)->env))
67 coro_init (); /* start it */ 67 coro_init (); /* start it */
68 else 68 else
69 trampoline_count++; 69 trampoline_count++;
70} 70}
71 71
89 ctx->uc.uc_stack.ss_size = (size_t) ssize; 89 ctx->uc.uc_stack.ss_size = (size_t) ssize;
90 ctx->uc.uc_stack.ss_flags = 0; 90 ctx->uc.uc_stack.ss_flags = 0;
91 91
92 makecontext (&(ctx->uc), (void (*)()) coro, 1, arg); 92 makecontext (&(ctx->uc), (void (*)()) coro, 1, arg);
93 93
94#elif CORO_SJLJ || CORO_LOOSE 94#elif CORO_SJLJ || CORO_LOOSE || CORO_LINUX
95 95
96# if CORO_SJLJ 96# if CORO_SJLJ
97 stack_t ostk, nstk; 97 stack_t ostk, nstk;
98 struct sigaction osa, nsa; 98 struct sigaction osa, nsa;
99 sigset_t nsig, osig; 99 sigset_t nsig, osig;
149 149
150 sigaction (SIGUSR1, &osa, 0); 150 sigaction (SIGUSR1, &osa, 0);
151 151
152 sigprocmask (SIG_SETMASK, &osig, 0); 152 sigprocmask (SIG_SETMASK, &osig, 0);
153 153
154# elif MS_LOOSE 154# elif CORO_LOOSE
155 155
156 coro_save (ctx); 156 setjmp (ctx->env);
157 ctx->env[7] = (int)((char *)sptr + ssize); 157 ctx->env[7] = (int)((char *)sptr + ssize);
158 ctx->env[8] = (int)coro; 158 ctx->env[8] = (int)coro_init;
159
160# elif CORO_LINUX
161
162 setjmp (ctx->env);
163#if defined(__GLIBC__) && defined(__GLIBC_MINOR__) \
164 && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined(JB_PC) && defined(JB_SP)
165 ctx->env[0].__jmpbuf[JB_PC] = (int)coro_init;
166 ctx->env[0].__jmpbuf[JB_SP] = (int)((char *)sptr + ssize);
167#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) \
168 && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined(__mc68000__)
169 ctx->env[0].__jmpbuf[0].__aregs[0] = (long int)coro_init;
170 ctx->env[0].__jmpbuf[0].__sp = (int *)((char *)sptr + ssize);
171#elif defined(__GNU_LIBRARY__) && defined(__i386__)
172 ctx->env[0].__jmpbuf[0].__pc = (char *)coro_init;
173 ctx->env[0].__jmpbuf[0].__sp = (void *)((char *)sptr + ssize);
174#else
175#error "Unsupported Linux (g)libc version and/or platform"
176#endif
159 177
160# endif 178# endif
161 179
162 coro_transfer ((coro_context *)create_coro, (coro_context *)new_coro); 180 coro_transfer ((coro_context *)create_coro, (coro_context *)new_coro);
163 181

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines