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

Comparing cvsroot/libcoro/coro.c (file contents):
Revision 1.20 by root, Thu Oct 26 05:20:47 2006 UTC vs.
Revision 1.23 by root, Thu Nov 30 18:21:14 2006 UTC

98# endif 98# endif
99 99
100#endif 100#endif
101 101
102/* initialize a machine state */ 102/* initialize a machine state */
103void coro_create(coro_context *ctx, 103void coro_create (coro_context *ctx,
104 coro_func coro, void *arg, 104 coro_func coro, void *arg,
105 void *sptr, long ssize) 105 void *sptr, long ssize)
106{ 106{
107#if CORO_UCONTEXT 107#if CORO_UCONTEXT
108 108
109 getcontext (&(ctx->uc)); 109 getcontext (&(ctx->uc));
110 110
140 nsa.sa_handler = trampoline; 140 nsa.sa_handler = trampoline;
141 sigemptyset (&nsa.sa_mask); 141 sigemptyset (&nsa.sa_mask);
142 nsa.sa_flags = SA_ONSTACK; 142 nsa.sa_flags = SA_ONSTACK;
143 143
144 if (sigaction (SIGUSR2, &nsa, &osa)) 144 if (sigaction (SIGUSR2, &nsa, &osa))
145 {
145 perror ("sigaction"); 146 perror ("sigaction");
147 abort ();
148 }
146 149
147 /* set the new stack */ 150 /* set the new stack */
148 nstk.ss_sp = STACK_ADJUST_PTR (sptr,ssize); /* yes, some platforms (IRIX) get this wrong. */ 151 nstk.ss_sp = STACK_ADJUST_PTR (sptr,ssize); /* yes, some platforms (IRIX) get this wrong. */
149 nstk.ss_size = STACK_ADJUST_SIZE (sptr,ssize); 152 nstk.ss_size = STACK_ADJUST_SIZE (sptr,ssize);
150 nstk.ss_flags = 0; 153 nstk.ss_flags = 0;
151 154
152 if (sigaltstack (&nstk, &ostk) < 0) 155 if (sigaltstack (&nstk, &ostk) < 0)
156 {
153 perror ("sigaltstack"); 157 perror ("sigaltstack");
158 abort ();
159 }
154 160
155 trampoline_count = 0; 161 trampoline_count = 0;
156 kill (getpid (), SIGUSR2); 162 kill (getpid (), SIGUSR2);
157 sigfillset (&nsig); sigdelset (&nsig, SIGUSR2); 163 sigfillset (&nsig); sigdelset (&nsig, SIGUSR2);
158 164
176 sigprocmask (SIG_SETMASK, &osig, 0); 182 sigprocmask (SIG_SETMASK, &osig, 0);
177 183
178# elif CORO_LOSER 184# elif CORO_LOSER
179 185
180 setjmp (ctx->env); 186 setjmp (ctx->env);
187#if __CYGWIN__
181 ctx->env[7] = (long)((char *)sptr + ssize); 188 ctx->env[7] = (long)((char *)sptr + ssize);
182 ctx->env[8] = (long)coro_init; 189 ctx->env[8] = (long)coro_init;
190#elif defined(_M_IX86)
191 ((_JUMP_BUFFER *)&ctx->env)->Eip = (long)coro_init;
192 ((_JUMP_BUFFER *)&ctx->env)->Esp = (long)STACK_ADJUST_PTR (sptr,ssize);
193#elif defined(_M_AMD64)
194 ((_JUMP_BUFFER *)&ctx->env)->Rip = (__int64)coro_init;
195 ((_JUMP_BUFFER *)&ctx->env)->Rsp = (__int64)STACK_ADJUST_PTR (sptr,ssize);
196#elif defined(_M_IA64)
197 ((_JUMP_BUFFER *)&ctx->env)->StIIP = (__int64)coro_init;
198 ((_JUMP_BUFFER *)&ctx->env)->IntSp = (__int64)STACK_ADJUST_PTR (sptr,ssize);
199#else
200#error "microsoft libc or architecture not supported"
201#endif
183 202
184# elif CORO_LINUX 203# elif CORO_LINUX
185 204
186 setjmp (ctx->env); 205 _setjmp (ctx->env);
187#if defined(__GLIBC__) && defined(__GLIBC_MINOR__) \ 206#if defined(__GLIBC__) && defined(__GLIBC_MINOR__) \
188 && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined(JB_PC) && defined(JB_SP) 207 && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined(JB_PC) && defined(JB_SP)
189 ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init; 208 ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init;
190 ctx->env[0].__jmpbuf[JB_SP] = (long)STACK_ADJUST_PTR (sptr,ssize); 209 ctx->env[0].__jmpbuf[JB_SP] = (long)STACK_ADJUST_PTR (sptr,ssize);
191#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) \ 210#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) \

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines