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

Comparing libcoro/coro.c (file contents):
Revision 1.4 by root, Tue Jul 24 19:52:55 2001 UTC vs.
Revision 1.5 by root, Mon Sep 3 02:50:18 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 || CORO_LINUX 35#if CORO_SJLJ || CORO_LOOSE || CORO_LINUX || CORO_IRIX
36
37/* IRIX is decidedly NON-unix */
38#if __sgi
39# define STACK_ADJUST(sp,ss) ((ss) - sizeof (long) + (char *)(sp))
40#else
41# define STACK_ADJUST(sp,ss) (ss)
42#endif
36 43
37#include <signal.h> 44#include <signal.h>
38 45
39static volatile coro_func coro_init_func; 46static volatile coro_func coro_init_func;
40static volatile void *coro_init_arg; 47static volatile void *coro_init_arg;
53 /* the new coro returned. bad. just abort() for now */ 60 /* the new coro returned. bad. just abort() for now */
54 abort (); 61 abort ();
55} 62}
56 63
57# if CORO_SJLJ 64# if CORO_SJLJ
58# define coro_save(ctx) (void)setjmp((ctx)->env)
59 65
60static volatile int trampoline_count; 66static volatile int trampoline_count;
61 67
62/* trampoline signal handler */ 68/* trampoline signal handler */
63static void 69static void
69 trampoline_count++; 75 trampoline_count++;
70} 76}
71 77
72# endif 78# endif
73 79
74#elif CORO_UCONTEXT
75# define coro_save(ctx) getcontext(&((ctx)->uc))
76#endif 80#endif
77 81
78/* initialize a machine state */ 82/* initialize a machine state */
79void coro_create(coro_context *ctx, 83void coro_create(coro_context *ctx,
80 coro_func coro, void *arg, 84 coro_func coro, void *arg,
82{ 86{
83#if CORO_UCONTEXT 87#if CORO_UCONTEXT
84 88
85 getcontext (&(ctx->uc)); 89 getcontext (&(ctx->uc));
86 90
87 ctx->uc.uc_link = 0; 91 ctx->uc.uc_link = 0;
88 ctx->uc.uc_stack.ss_sp = sptr; 92 ctx->uc.uc_stack.ss_sp = STACK_ADJUST(sptr,ssize);
89 ctx->uc.uc_stack.ss_size = (size_t) ssize; 93 ctx->uc.uc_stack.ss_size = (size_t) ssize;
90 ctx->uc.uc_stack.ss_flags = 0; 94 ctx->uc.uc_stack.ss_flags = 0;
91 95
92 makecontext (&(ctx->uc), (void (*)()) coro, 1, arg); 96 makecontext (&(ctx->uc), (void (*)()) coro, 1, arg);
93 97
94#elif CORO_SJLJ || CORO_LOOSE || CORO_LINUX 98#elif CORO_SJLJ || CORO_LOOSE || CORO_LINUX || CORO_IRIX
95 99
96# if CORO_SJLJ 100# if CORO_SJLJ
97 stack_t ostk, nstk; 101 stack_t ostk, nstk;
98 struct sigaction osa, nsa; 102 struct sigaction osa, nsa;
99 sigset_t nsig, osig; 103 sigset_t nsig, osig;
119 123
120 if (sigaction (SIGUSR2, &nsa, &osa)) 124 if (sigaction (SIGUSR2, &nsa, &osa))
121 perror ("sigaction"); 125 perror ("sigaction");
122 126
123 /* set the new stack */ 127 /* set the new stack */
124 nstk.ss_sp = sptr; 128 nstk.ss_sp = STACK_ADJUST(sptr,ssize); /* yes, some platforms (IRIX) get this wrong. */
125 nstk.ss_size = ssize; 129 nstk.ss_size = ssize;
126 nstk.ss_flags = 0; 130 nstk.ss_flags = 0;
127 131
128 if (sigaltstack (&nstk, &ostk) < 0) 132 if (sigaltstack (&nstk, &ostk) < 0)
129 perror ("sigaltstack"); 133 perror ("sigaltstack");
170 ctx->env[0].__jmpbuf[0].__sp = (int *)((char *)sptr + ssize); 174 ctx->env[0].__jmpbuf[0].__sp = (int *)((char *)sptr + ssize);
171#elif defined(__GNU_LIBRARY__) && defined(__i386__) 175#elif defined(__GNU_LIBRARY__) && defined(__i386__)
172 ctx->env[0].__jmpbuf[0].__pc = (char *)coro_init; 176 ctx->env[0].__jmpbuf[0].__pc = (char *)coro_init;
173 ctx->env[0].__jmpbuf[0].__sp = (void *)((char *)sptr + ssize); 177 ctx->env[0].__jmpbuf[0].__sp = (void *)((char *)sptr + ssize);
174#else 178#else
175#error "Unsupported Linux (g)libc version and/or platform" 179#error "linux libc or architecture not supported"
176#endif 180#endif
181
182# elif CORO_IRIX
183
184 setjmp (ctx->env);
185 ctx->env[JB_PC] = (int)coro_init;
186 ctx->env[JB_SP] = (int)((char *)sptr + ssize);
177 187
178# endif 188# endif
179 189
180 coro_transfer ((coro_context *)create_coro, (coro_context *)new_coro); 190 coro_transfer ((coro_context *)create_coro, (coro_context *)new_coro);
181 191

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines