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 | |
53 | static volatile coro_func coro_init_func; |
59 | static volatile coro_func coro_init_func; |
54 | static volatile void *coro_init_arg; |
60 | static volatile void *coro_init_arg; |
55 | static volatile coro_context *new_coro, *create_coro; |
61 | static volatile coro_context *new_coro, *create_coro; |
56 | |
62 | |
… | |
… | |
72 | |
78 | |
73 | static volatile int trampoline_count; |
79 | static volatile int trampoline_count; |
74 | |
80 | |
75 | /* trampoline signal handler */ |
81 | /* trampoline signal handler */ |
76 | static void |
82 | static void |
77 | trampoline(int sig) |
83 | trampoline (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] = (long)((char *)sptr + ssize); |
174 | ctx->env[7] = (long)((char *)sptr + ssize); |
169 | ctx->env[8] = (long)coro_init; |
175 | ctx->env[8] = (long)coro_init; |
170 | |
176 | |