8 #if !defined(__OpenBSD__)
9 # if defined(__APPLE__)
10 # define _XOPEN_SOURCE /* for Snow Leopard */
12 # include <ucontext.h>
14 #include <sys/utsname.h>
18 #if defined(__APPLE__)
20 * OS X before 10.5 (Leopard) does not provide
21 * swapcontext nor makecontext, so we have to use our own.
22 * In theory, Leopard does provide them, but when we use
23 * them, they seg fault. Maybe we're using them wrong.
24 * So just use our own versions, even on Leopard.
26 # define mcontext libthread_mcontext
27 # define mcontext_t libthread_mcontext_t
28 # define ucontext libthread_ucontext
29 # define ucontext_t libthread_ucontext_t
30 # define swapcontext libthread_swapcontext
31 # define makecontext libthread_makecontext
32 # if defined(__i386__)
33 # include "386-ucontext.h"
34 # elif defined(__x86_64__)
35 # include "x86_64-ucontext.h"
36 # elif defined(__ppc__) || defined(__power__)
37 # include "power-ucontext.h"
39 # error "unknown architecture"
43 #if defined(__OpenBSD__)
44 # define mcontext libthread_mcontext
45 # define mcontext_t libthread_mcontext_t
46 # define ucontext libthread_ucontext
47 # define ucontext_t libthread_ucontext_t
49 # include "386-ucontext.h"
50 # elif defined __amd64__
51 # include "x86_64-ucontext.h"
53 # include "power-ucontext.h"
55 extern pid_t rfork_thread(int, void*, int(*)(void*), void*);
59 int mygetmcontext(ulong*);
60 void mysetmcontext(const ulong*);
61 #define setcontext(u) mysetmcontext(&(u)->uc_mcontext.arm_r0)
62 #define getcontext(u) mygetmcontext(&(u)->uc_mcontext.arm_r0)
66 typedef struct Context Context;
67 typedef struct Execjob Execjob;
68 typedef struct Proc Proc;
69 typedef struct _Procrendez _Procrendez;
71 typedef struct Jmp Jmp;
87 * On Snow Leopard, etc., the context routines exist,
88 * so we use them, but apparently they write past the
89 * end of the ucontext_t. Sigh. We put some extra
90 * scratch space here for them.
112 void (*startfn)(void*);
129 #ifdef PLAN9PORT_USING_PTHREADS
136 extern void _procsleep(_Procrendez*);
137 extern void _procwakeup(_Procrendez*);
138 extern void _procwakeupandunlock(_Procrendez*);
145 #ifdef PLAN9PORT_USING_PTHREADS
154 _Threadlist runqueue;
155 _Threadlist idlequeue;
156 _Threadlist allthreads;
160 Context schedcontext;
166 #define proc() _threadproc()
168 extern Proc *_threadprocs;
169 extern Lock _threadprocslock;
170 extern Proc *_threadexecproc;
171 extern Channel *_threadexecchan;
172 extern QLock _threadexeclock;
173 extern Channel *_dowaitchan;
175 extern void _procstart(Proc*, void (*fn)(Proc*));
176 extern _Thread *_threadcreate(Proc*, void(*fn)(void*), void*, uint);
177 extern void _procexit(void);
178 extern Proc *_threadproc(void);
179 extern void _threadsetproc(Proc*);
180 extern int _threadlock(Lock*, int, ulong);
181 extern void _threadunlock(Lock*, ulong);
182 extern void _pthreadinit(void);
183 extern int _threadspawn(int*, char*, char**, char*);
184 extern int _runthreadspawn(int*, char*, char**, char*);
185 extern void _threadsetupdaemonize(void);
186 extern void _threaddodaemonize(char*);
187 extern void _threadpexit(void);
188 extern void _threaddaemonize(void);
189 extern void *_threadstkalloc(int);
190 extern void _threadstkfree(void*, int);
192 #define USPALIGN(ucp, align) \
193 (void*)((((uintptr)(ucp)->uc_stack.ss_sp+(ucp)->uc_stack.ss_size)-(align))&~((align)-1))