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

Comparing libcoro/coro.c (file contents):
Revision 1.9 by root, Tue Nov 6 20:34:11 2001 UTC vs.
Revision 1.17 by root, Tue Aug 30 21:32:17 2005 UTC

1/* 1/*
2 * Copyright (c) 2001 Marc Alexander Lehmann <pcg@goof.com> 2 * Copyright (c) 2001-2005 Marc Alexander Lehmann <schmorp@schmorp.de>
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without modifica- 4 * Redistribution and use in source and binary forms, with or without modifica-
5 * tion, are permitted provided that the following conditions are met: 5 * tion, are permitted provided that the following conditions are met:
6 * 6 *
7 * 1. Redistributions of source code must retain the above copyright notice, 7 * 1. Redistributions of source code must retain the above copyright notice,
44# define STACK_ADJUST_PTR(sp,ss) (sp) 44# define STACK_ADJUST_PTR(sp,ss) (sp)
45# define STACK_ADJUST_SIZE(sp,ss) (ss) 45# define STACK_ADJUST_SIZE(sp,ss) (ss)
46# endif 46# endif
47#endif 47#endif
48 48
49#if CORO_SJLJ || CORO_LOOSE || CORO_LINUX || CORO_IRIX 49#if CORO_SJLJ || CORO_LOSER || CORO_LINUX || CORO_IRIX
50 50
51#include <stdlib.h>
52
53#if CORO_SJLJ
54# include <stdio.h>
51#include <signal.h> 55# include <signal.h>
56# include <unistd.h>
57#endif
52 58
53static volatile coro_func coro_init_func; 59static volatile coro_func coro_init_func;
54static volatile void *coro_init_arg; 60static volatile void *coro_init_arg;
55static volatile coro_context *new_coro, *create_coro; 61static volatile coro_context *new_coro, *create_coro;
56 62
72 78
73static volatile int trampoline_count; 79static volatile int trampoline_count;
74 80
75/* trampoline signal handler */ 81/* trampoline signal handler */
76static void 82static void
77trampoline(int sig) 83trampoline (int sig)
78{ 84{
79 if (setjmp (((coro_context *)new_coro)->env)) 85 if (setjmp (((coro_context *)new_coro)->env))
80 coro_init (); /* start it */ 86 coro_init (); /* start it */
81 else 87 else
82 trampoline_count++; 88 trampoline_count++;
100 ctx->uc.uc_stack.ss_size = (size_t) STACK_ADJUST_SIZE (sptr,ssize); 106 ctx->uc.uc_stack.ss_size = (size_t) STACK_ADJUST_SIZE (sptr,ssize);
101 ctx->uc.uc_stack.ss_flags = 0; 107 ctx->uc.uc_stack.ss_flags = 0;
102 108
103 makecontext (&(ctx->uc), (void (*)()) coro, 1, arg); 109 makecontext (&(ctx->uc), (void (*)()) coro, 1, arg);
104 110
105#elif CORO_SJLJ || CORO_LOOSE || CORO_LINUX || CORO_IRIX 111#elif CORO_SJLJ || CORO_LOSER || CORO_LINUX || CORO_IRIX
106 112
107# if CORO_SJLJ 113# if CORO_SJLJ
108 stack_t ostk, nstk; 114 stack_t ostk, nstk;
109 struct sigaction osa, nsa; 115 struct sigaction osa, nsa;
110 sigset_t nsig, osig; 116 sigset_t nsig, osig;
160 166
161 sigaction (SIGUSR1, &osa, 0); 167 sigaction (SIGUSR1, &osa, 0);
162 168
163 sigprocmask (SIG_SETMASK, &osig, 0); 169 sigprocmask (SIG_SETMASK, &osig, 0);
164 170
165# elif CORO_LOOSE 171# elif CORO_LOSER
166 172
167 setjmp (ctx->env); 173 setjmp (ctx->env);
168 ctx->env[7] = (int)((char *)sptr + ssize); 174 ctx->env[7] = (long)((char *)sptr + ssize);
169 ctx->env[8] = (int)coro_init; 175 ctx->env[8] = (long)coro_init;
170 176
171# elif CORO_LINUX 177# elif CORO_LINUX
172 178
173 setjmp (ctx->env); 179 setjmp (ctx->env);
174#if defined(__GLIBC__) && defined(__GLIBC_MINOR__) \ 180#if defined(__GLIBC__) && defined(__GLIBC_MINOR__) \
175 && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined(JB_PC) && defined(JB_SP) 181 && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined(JB_PC) && defined(JB_SP)
176 ctx->env[0].__jmpbuf[JB_PC] = (int)coro_init; 182 ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init;
177 ctx->env[0].__jmpbuf[JB_SP] = (int)STACK_ADJUST_PTR (sptr,ssize); 183 ctx->env[0].__jmpbuf[JB_SP] = (long)STACK_ADJUST_PTR (sptr,ssize);
178#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) \ 184#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) \
179 && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined(__mc68000__) 185 && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined(__mc68000__)
180 ctx->env[0].__jmpbuf[0].__aregs[0] = (long int)coro_init; 186 ctx->env[0].__jmpbuf[0].__aregs[0] = (long int)coro_init;
181 ctx->env[0].__jmpbuf[0].__sp = (int *)((char *)sptr + ssize); 187 ctx->env[0].__jmpbuf[0].__sp = (int *)((char *)sptr + ssize);
182#elif defined(__GNU_LIBRARY__) && defined(__i386__) 188#elif defined(__GNU_LIBRARY__) && defined(__i386__)
183 ctx->env[0].__jmpbuf[0].__pc = (char *)coro_init; 189 ctx->env[0].__jmpbuf[0].__pc = (char *)coro_init;
184 ctx->env[0].__jmpbuf[0].__sp = (void *)((char *)sptr + ssize); 190 ctx->env[0].__jmpbuf[0].__sp = (void *)((char *)sptr + ssize);
191#elif defined(__GNU_LIBRARY__) && defined(__amd64__)
192 ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init;
193 ctx->env[0].__jmpbuf[JB_RSP] = (long)((char *)sptr + ssize);
185#else 194#else
186#error "linux libc or architecture not supported" 195#error "linux libc or architecture not supported"
187#endif 196#endif
188 197
189# elif CORO_IRIX 198# elif CORO_IRIX

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines