winlin

Merge branch 'srs.master'

@@ -57,528 +57,220 @@ @@ -57,528 +57,220 @@
57 /***************************************** 57 /*****************************************
58 * Platform specifics 58 * Platform specifics
59 */ 59 */
60 -#if defined (AIX)  
61 - #define MD_STACK_GROWS_DOWN  
62 - #define MD_USE_SYSV_ANON_MMAP  
63 - #define MD_ACCEPT_NB_INHERITED  
64 - #define MD_ALWAYS_UNSERIALIZED_ACCEPT  
65 -  
66 - #ifndef MD_HAVE_SOCKLEN_T  
67 - #define MD_HAVE_SOCKLEN_T  
68 - #define socklen_t unsigned long  
69 - #endif  
70 -  
71 - #define MD_SETJMP(env) _setjmp(env)  
72 - #define MD_LONGJMP(env, val) _longjmp(env, val)  
73 -  
74 - #define MD_INIT_CONTEXT(_thread, _sp, _main) \  
75 - ST_BEGIN_MACRO \  
76 - if (MD_SETJMP((_thread)->context)) \  
77 - _main(); \  
78 - (_thread)->context[3] = (long) (_sp); \  
79 - ST_END_MACRO  
80 -  
81 - #define MD_GET_UTIME() \  
82 - timebasestruct_t rt; \  
83 - (void) read_real_time(&rt, TIMEBASE_SZ); \  
84 - (void) time_base_to_time(&rt, TIMEBASE_SZ); \  
85 - return (rt.tb_high * 1000000LL + rt.tb_low / 1000)  
86 - 60 +#if defined (LINUX)
  61 + /* linux ok, defined bellow */
  62 +#elif defined (AIX)
  63 + #error "AIX not supported"
87 #elif defined (CYGWIN) 64 #elif defined (CYGWIN)
88 - #define MD_STACK_GROWS_DOWN  
89 - #define MD_USE_BSD_ANON_MMAP  
90 - #define MD_ACCEPT_NB_NOT_INHERITED  
91 - #define MD_ALWAYS_UNSERIALIZED_ACCEPT  
92 -  
93 - #define MD_SETJMP(env) setjmp(env)  
94 - #define MD_LONGJMP(env, val) longjmp(env, val)  
95 -  
96 - #define MD_JB_SP 7  
97 -  
98 - #define MD_GET_SP(_t) (_t)->context[MD_JB_SP]  
99 -  
100 - #define MD_INIT_CONTEXT(_thread, _sp, _main) \  
101 - ST_BEGIN_MACRO \  
102 - if (MD_SETJMP((_thread)->context)) \  
103 - _main(); \  
104 - MD_GET_SP(_thread) = (long) (_sp); \  
105 - ST_END_MACRO  
106 -  
107 - #define MD_GET_UTIME() \  
108 - struct timeval tv; \  
109 - (void) gettimeofday(&tv, NULL); \  
110 - return (tv.tv_sec * 1000000LL + tv.tv_usec)  
111 - 65 + #error "CYGWIN not supported"
112 #elif defined (DARWIN) 66 #elif defined (DARWIN)
113 - #define MD_STACK_GROWS_DOWN  
114 - #define MD_USE_BSD_ANON_MMAP  
115 - #define MD_ACCEPT_NB_INHERITED  
116 - #define MD_ALWAYS_UNSERIALIZED_ACCEPT  
117 - #define MD_HAVE_SOCKLEN_T  
118 -  
119 - #define MD_SETJMP(env) _setjmp(env)  
120 - #define MD_LONGJMP(env, val) _longjmp(env, val)  
121 -  
122 - #if defined(__ppc__)  
123 - #define MD_JB_SP 0  
124 - #elif defined(__i386__)  
125 - #define MD_JB_SP 9  
126 - #elif defined(__x86_64__)  
127 - #define MD_JB_SP 4  
128 - #else  
129 - #error Unknown CPU architecture  
130 - #endif 67 + #error "DARWIN not supported"
  68 +#elif defined (FREEBSD)
  69 + #error "FREEBSD not supported"
  70 +#elif defined (HPUX)
  71 + #error "HPUX not supported"
  72 +#elif defined (IRIX)
  73 + #error "IRIX not supported"
  74 +#elif defined (NETBSD)
  75 + #error "NETBSD not supported"
  76 +#elif defined (OPENBSD)
  77 + #error "OPENBSD not supported"
  78 +#elif defined (OSF1)
  79 + #error "OSF1 not supported"
  80 +#elif defined (SOLARIS)
  81 + #error "SOLARIS not supported"
  82 +#else
  83 + #error "Unknown OS"
  84 +#endif /* OS */
131 85
132 - #define MD_INIT_CONTEXT(_thread, _sp, _main) \  
133 - ST_BEGIN_MACRO \  
134 - if (MD_SETJMP((_thread)->context)) \  
135 - _main(); \  
136 - *((long *)&((_thread)->context[MD_JB_SP])) = (long) (_sp); \  
137 - ST_END_MACRO 86 +/* linux only, defined bellow */
  87 +/*
  88 + * These are properties of the linux kernel and are the same on every
  89 + * flavor and architecture.
  90 + */
  91 +#define MD_USE_BSD_ANON_MMAP
  92 +#define MD_ACCEPT_NB_NOT_INHERITED
  93 +#define MD_ALWAYS_UNSERIALIZED_ACCEPT
  94 +/*
  95 + * Modern GNU/Linux is Posix.1g compliant.
  96 + */
  97 +#define MD_HAVE_SOCKLEN_T
138 98
139 - #define MD_GET_UTIME() \  
140 - struct timeval tv; \  
141 - (void) gettimeofday(&tv, NULL); \  
142 - return (tv.tv_sec * 1000000LL + tv.tv_usec) 99 +/*
  100 + * All architectures and flavors of linux have the gettimeofday
  101 + * function but if you know of a faster way, use it.
  102 + */
  103 +#define MD_GET_UTIME() \
  104 + struct timeval tv; \
  105 + (void) gettimeofday(&tv, NULL); \
  106 + return (tv.tv_sec * 1000000LL + tv.tv_usec)
143 107
144 -#elif defined (FREEBSD) 108 +#if defined(__ia64__)
145 #define MD_STACK_GROWS_DOWN 109 #define MD_STACK_GROWS_DOWN
146 - #define MD_USE_BSD_ANON_MMAP  
147 - #define MD_ACCEPT_NB_INHERITED  
148 - #define MD_ALWAYS_UNSERIALIZED_ACCEPT  
149 110
150 - #define MD_SETJMP(env) _setjmp(env)  
151 - #define MD_LONGJMP(env, val) _longjmp(env, val)  
152 -  
153 - #if defined(__i386__)  
154 - #define MD_JB_SP 2  
155 - #elif defined(__alpha__)  
156 - #define MD_JB_SP 34  
157 - #elif defined(__amd64__)  
158 - #define MD_JB_SP 2  
159 - #else  
160 - #error Unknown CPU architecture 111 + /*
  112 + * IA-64 architecture. Besides traditional memory call stack, IA-64
  113 + * uses general register stack. Thus each thread needs a backing store
  114 + * for register stack in addition to memory stack. Standard
  115 + * setjmp()/longjmp() cannot be used for thread context switching
  116 + * because their implementation implicitly assumes that only one
  117 + * register stack exists.
  118 + */
  119 + #ifdef USE_LIBC_SETJMP
  120 + #undef USE_LIBC_SETJMP
161 #endif 121 #endif
  122 + #define MD_USE_BUILTIN_SETJMP
162 123
163 - #define MD_INIT_CONTEXT(_thread, _sp, _main) \  
164 - ST_BEGIN_MACRO \  
165 - if (MD_SETJMP((_thread)->context)) \  
166 - _main(); \  
167 - (_thread)->context[0]._jb[MD_JB_SP] = (long) (_sp); \ 124 + #define MD_STACK_PAD_SIZE 128
  125 + /* Last register stack frame must be preserved */
  126 + #define MD_INIT_CONTEXT(_thread, _sp, _bsp, _main) \
  127 + ST_BEGIN_MACRO \
  128 + if (MD_SETJMP((_thread)->context)) \
  129 + _main(); \
  130 + memcpy((char *)(_bsp) - MD_STACK_PAD_SIZE, \
  131 + (char *)(_thread)->context[0].__jmpbuf[17] - MD_STACK_PAD_SIZE, \
  132 + MD_STACK_PAD_SIZE); \
  133 + (_thread)->context[0].__jmpbuf[0] = (long) (_sp); \
  134 + (_thread)->context[0].__jmpbuf[17] = (long) (_bsp); \
168 ST_END_MACRO 135 ST_END_MACRO
169 -  
170 - #define MD_GET_UTIME() \  
171 - struct timeval tv; \  
172 - (void) gettimeofday(&tv, NULL); \  
173 - return (tv.tv_sec * 1000000LL + tv.tv_usec)  
174 -  
175 -#elif defined (HPUX)  
176 - #define MD_STACK_GROWS_UP  
177 - #define MD_USE_BSD_ANON_MMAP  
178 - #define MD_ACCEPT_NB_INHERITED  
179 - #define MD_ALWAYS_UNSERIALIZED_ACCEPT  
180 -  
181 - #define MD_SETJMP(env) _setjmp(env)  
182 - #define MD_LONGJMP(env, val) _longjmp(env, val)  
183 -  
184 - #ifndef __LP64__  
185 - /* 32-bit mode (ILP32 data model) */  
186 - #define MD_INIT_CONTEXT(_thread, _sp, _main) \  
187 - ST_BEGIN_MACRO \  
188 - if (MD_SETJMP((_thread)->context)) \  
189 - _main(); \  
190 - ((long *)((_thread)->context))[1] = (long) (_sp); \  
191 - ST_END_MACRO  
192 - #else  
193 - /* 64-bit mode (LP64 data model) */  
194 - #define MD_STACK_PAD_SIZE 256  
195 - /* Last stack frame must be preserved */  
196 - #define MD_INIT_CONTEXT(_thread, _sp, _main) \  
197 - ST_BEGIN_MACRO \  
198 - if (MD_SETJMP((_thread)->context)) \  
199 - _main(); \  
200 - memcpy((char *)(_sp) - MD_STACK_PAD_SIZE, \  
201 - ((char **)((_thread)->context))[1] - MD_STACK_PAD_SIZE, \  
202 - MD_STACK_PAD_SIZE); \  
203 - ((long *)((_thread)->context))[1] = (long) (_sp); \  
204 - ST_END_MACRO  
205 - #endif /* !__LP64__ */  
206 -  
207 - #define MD_GET_UTIME() \  
208 - struct timeval tv; \  
209 - (void) gettimeofday(&tv, NULL); \  
210 - return (tv.tv_sec * 1000000LL + tv.tv_usec)  
211 -  
212 -#elif defined (IRIX)  
213 - #include <sys/syssgi.h>  
214 - 136 +#elif defined(__mips__)
215 #define MD_STACK_GROWS_DOWN 137 #define MD_STACK_GROWS_DOWN
216 - #define MD_USE_SYSV_ANON_MMAP  
217 - #define MD_ACCEPT_NB_INHERITED  
218 - #define MD_ALWAYS_UNSERIALIZED_ACCEPT  
219 138
220 - #define MD_SETJMP(env) setjmp(env)  
221 - #define MD_LONGJMP(env, val) longjmp(env, val)  
222 -  
223 - #define MD_INIT_CONTEXT(_thread, _sp, _main) \  
224 - ST_BEGIN_MACRO \  
225 - (void) MD_SETJMP((_thread)->context); \  
226 - (_thread)->context[JB_SP] = (long) (_sp); \  
227 - (_thread)->context[JB_PC] = (long) _main; \ 139 + #define MD_INIT_CONTEXT(_thread, _sp, _main) \
  140 + ST_BEGIN_MACRO \
  141 + MD_SETJMP((_thread)->context); \
  142 + _thread->context[0].__jmpbuf[0].__pc = (__ptr_t) _main; \
  143 + _thread->context[0].__jmpbuf[0].__sp = _sp; \
228 ST_END_MACRO 144 ST_END_MACRO
229 -  
230 - #define MD_GET_UTIME() \  
231 - static int inited = 0; \  
232 - static clockid_t clock_id = CLOCK_SGI_CYCLE; \  
233 - struct timespec ts; \  
234 - if (!inited) { \  
235 - if (syssgi(SGI_CYCLECNTR_SIZE) < 64) \  
236 - clock_id = CLOCK_REALTIME; \  
237 - inited = 1; \  
238 - } \  
239 - (void) clock_gettime(clock_id, &ts); \  
240 - return (ts.tv_sec * 1000000LL + ts.tv_nsec / 1000)  
241 - 145 +#else /* Not IA-64 or mips */
242 /* 146 /*
243 - * Cap the stack by zeroing out the saved return address register  
244 - * value. This allows libexc, used by SpeedShop, to know when to stop  
245 - * backtracing since it won't find main, start, or any other known  
246 - * stack root function in a state thread's stack. Without this libexc  
247 - * traces right off the stack and crashes.  
248 - * The function preamble stores ra at 8(sp), this stores zero there.  
249 - * N.B. This macro is compiler/ABI dependent. It must change if ANY more  
250 - * automatic variables are added to the _st_thread_main() routine, because  
251 - * the address where ra is stored will change. 147 + * On linux, there are a few styles of jmpbuf format. These vary based
  148 + * on architecture/glibc combination.
  149 + *
  150 + * Most of the glibc based toggles were lifted from:
  151 + * mozilla/nsprpub/pr/include/md/_linux.h
252 */ 152 */
253 - #if !defined(__GNUC__) && defined(_MIPS_SIM) && _MIPS_SIM != _ABIO32  
254 - #define MD_CAP_STACK(var_addr) \  
255 - (((volatile __uint64_t *)(var_addr))[1] = 0)  
256 - #endif  
257 -  
258 -#elif defined (LINUX)  
259 /* 153 /*
260 - * These are properties of the linux kernel and are the same on every  
261 - * flavor and architecture. 154 + * Starting with glibc 2.4, JB_SP definitions are not public anymore.
  155 + * They, however, can still be found in glibc source tree in
  156 + * architecture-specific "jmpbuf-offsets.h" files.
  157 + * Most importantly, the content of jmp_buf is mangled by setjmp to make
  158 + * it completely opaque (the mangling can be disabled by setting the
  159 + * LD_POINTER_GUARD environment variable before application execution).
  160 + * Therefore we will use built-in _st_md_cxt_save/_st_md_cxt_restore
  161 + * functions as a setjmp/longjmp replacement wherever they are available
  162 + * unless USE_LIBC_SETJMP is defined.
262 */ 163 */
263 - #define MD_USE_BSD_ANON_MMAP  
264 - #define MD_ACCEPT_NB_NOT_INHERITED  
265 - #define MD_ALWAYS_UNSERIALIZED_ACCEPT  
266 - /*  
267 - * Modern GNU/Linux is Posix.1g compliant.  
268 - */  
269 - #define MD_HAVE_SOCKLEN_T 164 + #if defined(__powerpc__)
  165 + #define MD_STACK_GROWS_DOWN
270 166
271 - /*  
272 - * All architectures and flavors of linux have the gettimeofday  
273 - * function but if you know of a faster way, use it.  
274 - */  
275 - #define MD_GET_UTIME() \  
276 - struct timeval tv; \  
277 - (void) gettimeofday(&tv, NULL); \  
278 - return (tv.tv_sec * 1000000LL + tv.tv_usec)  
279 -  
280 - #if defined(__ia64__) 167 + #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
  168 + #ifndef JB_GPR1
  169 + #define JB_GPR1 0
  170 + #endif
  171 + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_GPR1]
  172 + #else
  173 + /* not an error but certainly cause for caution */
  174 + #error "Untested use of old glibc on powerpc"
  175 + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__misc[0]
  176 + #endif /* glibc 2.1 or later */
  177 + #elif defined(__alpha)
281 #define MD_STACK_GROWS_DOWN 178 #define MD_STACK_GROWS_DOWN
282 -  
283 - /*  
284 - * IA-64 architecture. Besides traditional memory call stack, IA-64  
285 - * uses general register stack. Thus each thread needs a backing store  
286 - * for register stack in addition to memory stack. Standard  
287 - * setjmp()/longjmp() cannot be used for thread context switching  
288 - * because their implementation implicitly assumes that only one  
289 - * register stack exists.  
290 - */  
291 - #ifdef USE_LIBC_SETJMP  
292 - #undef USE_LIBC_SETJMP  
293 - #endif  
294 - #define MD_USE_BUILTIN_SETJMP  
295 179
296 - #define MD_STACK_PAD_SIZE 128  
297 - /* Last register stack frame must be preserved */  
298 - #define MD_INIT_CONTEXT(_thread, _sp, _bsp, _main) \  
299 - ST_BEGIN_MACRO \  
300 - if (MD_SETJMP((_thread)->context)) \  
301 - _main(); \  
302 - memcpy((char *)(_bsp) - MD_STACK_PAD_SIZE, \  
303 - (char *)(_thread)->context[0].__jmpbuf[17] - MD_STACK_PAD_SIZE, \  
304 - MD_STACK_PAD_SIZE); \  
305 - (_thread)->context[0].__jmpbuf[0] = (long) (_sp); \  
306 - (_thread)->context[0].__jmpbuf[17] = (long) (_bsp); \  
307 - ST_END_MACRO  
308 - #elif defined(__mips__) 180 + #if defined(__GLIBC__) && __GLIBC__ >= 2
  181 + #ifndef JB_SP
  182 + #define JB_SP 8
  183 + #endif
  184 + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_SP]
  185 + #else
  186 + /* not an error but certainly cause for caution */
  187 + #error "Untested use of old glibc on alpha"
  188 + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__sp
  189 + #endif
  190 + #elif defined(__mc68000__)
309 #define MD_STACK_GROWS_DOWN 191 #define MD_STACK_GROWS_DOWN
310 192
311 - #define MD_INIT_CONTEXT(_thread, _sp, _main) \  
312 - ST_BEGIN_MACRO \  
313 - MD_SETJMP((_thread)->context); \  
314 - _thread->context[0].__jmpbuf[0].__pc = (__ptr_t) _main; \  
315 - _thread->context[0].__jmpbuf[0].__sp = _sp; \  
316 - ST_END_MACRO  
317 - #else /* Not IA-64 or mips */  
318 - /*  
319 - * On linux, there are a few styles of jmpbuf format. These vary based  
320 - * on architecture/glibc combination.  
321 - *  
322 - * Most of the glibc based toggles were lifted from:  
323 - * mozilla/nsprpub/pr/include/md/_linux.h  
324 - */  
325 - /*  
326 - * Starting with glibc 2.4, JB_SP definitions are not public anymore.  
327 - * They, however, can still be found in glibc source tree in  
328 - * architecture-specific "jmpbuf-offsets.h" files.  
329 - * Most importantly, the content of jmp_buf is mangled by setjmp to make  
330 - * it completely opaque (the mangling can be disabled by setting the  
331 - * LD_POINTER_GUARD environment variable before application execution).  
332 - * Therefore we will use built-in _st_md_cxt_save/_st_md_cxt_restore  
333 - * functions as a setjmp/longjmp replacement wherever they are available  
334 - * unless USE_LIBC_SETJMP is defined.  
335 - */  
336 - #if defined(__powerpc__)  
337 - #define MD_STACK_GROWS_DOWN  
338 -  
339 - #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)  
340 - #ifndef JB_GPR1  
341 - #define JB_GPR1 0  
342 - #endif  
343 - #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_GPR1]  
344 - #else  
345 - /* not an error but certainly cause for caution */  
346 - #error "Untested use of old glibc on powerpc"  
347 - #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__misc[0]  
348 - #endif /* glibc 2.1 or later */  
349 - #elif defined(__alpha)  
350 - #define MD_STACK_GROWS_DOWN 193 + /* m68k still uses old style sigjmp_buf */
  194 + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__sp
  195 + #elif defined(__sparc__)
  196 + #define MD_STACK_GROWS_DOWN
  197 +
  198 + #if defined(__GLIBC__) && __GLIBC__ >= 2
  199 + #ifndef JB_SP
  200 + #define JB_SP 0
  201 + #endif
  202 + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_SP]
  203 + #else
  204 + /* not an error but certainly cause for caution */
  205 + #error "Untested use of old glic on sparc -- also using odd mozilla derived __fp"
  206 + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__fp
  207 + #endif
  208 + #elif defined(__i386__)
  209 + #define MD_STACK_GROWS_DOWN
  210 + #define MD_USE_BUILTIN_SETJMP
351 211
352 - #if defined(__GLIBC__) && __GLIBC__ >= 2  
353 - #ifndef JB_SP  
354 - #define JB_SP 8  
355 - #endif  
356 - #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_SP]  
357 - #else  
358 - /* not an error but certainly cause for caution */  
359 - #error "Untested use of old glibc on alpha"  
360 - #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__sp 212 + #if defined(__GLIBC__) && __GLIBC__ >= 2
  213 + #ifndef JB_SP
  214 + #define JB_SP 4
361 #endif 215 #endif
362 - #elif defined(__mc68000__)  
363 - #define MD_STACK_GROWS_DOWN  
364 -  
365 - /* m68k still uses old style sigjmp_buf */ 216 + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_SP]
  217 + #else
  218 + /* not an error but certainly cause for caution */
  219 + #error "Untested use of old glibc on i386"
366 #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__sp 220 #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__sp
367 - #elif defined(__sparc__)  
368 - #define MD_STACK_GROWS_DOWN 221 + #endif
  222 + #elif defined(__amd64__) || defined(__x86_64__)
  223 + #define MD_STACK_GROWS_DOWN
  224 + #define MD_USE_BUILTIN_SETJMP
369 225
370 - #if defined(__GLIBC__) && __GLIBC__ >= 2  
371 - #ifndef JB_SP  
372 - #define JB_SP 0  
373 - #endif  
374 - #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_SP]  
375 - #else  
376 - /* not an error but certainly cause for caution */  
377 - #error "Untested use of old glic on sparc -- also using odd mozilla derived __fp"  
378 - #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__fp  
379 - #endif  
380 - #elif defined(__i386__)  
381 - #define MD_STACK_GROWS_DOWN  
382 - #define MD_USE_BUILTIN_SETJMP  
383 -  
384 - #if defined(__GLIBC__) && __GLIBC__ >= 2  
385 - #ifndef JB_SP  
386 - #define JB_SP 4  
387 - #endif  
388 - #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_SP]  
389 - #else  
390 - /* not an error but certainly cause for caution */  
391 - #error "Untested use of old glibc on i386"  
392 - #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__sp  
393 - #endif  
394 - #elif defined(__amd64__) || defined(__x86_64__)  
395 - #define MD_STACK_GROWS_DOWN  
396 - #define MD_USE_BUILTIN_SETJMP  
397 -  
398 - #ifndef JB_RSP  
399 - #define JB_RSP 6  
400 - #endif  
401 - #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_RSP]  
402 - #elif defined(__arm__)  
403 - #define MD_STACK_GROWS_DOWN  
404 -  
405 - #if defined(__GLIBC__) && __GLIBC__ >= 2  
406 - #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[8]  
407 - #else  
408 - #error "ARM/Linux pre-glibc2 not supported yet"  
409 - #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */  
410 - #elif defined(__s390__)  
411 - #define MD_STACK_GROWS_DOWN  
412 -  
413 - /* There is no JB_SP in glibc at this time. (glibc 2.2.5)  
414 - */  
415 - #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__gregs[9]  
416 - #elif defined(__hppa__)  
417 - #define MD_STACK_GROWS_UP  
418 -  
419 - /* yes, this is gross, unfortunately at the moment (2002/08/01) there is  
420 - * a bug in hppa's glibc header definition for JB_SP, so we can't  
421 - * use that...  
422 - */  
423 - #define MD_GET_SP(_t) (*(long *)(((char *)&(_t)->context[0].__jmpbuf[0]) + 76)) 226 + #ifndef JB_RSP
  227 + #define JB_RSP 6
  228 + #endif
  229 + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_RSP]
  230 + #elif defined(__arm__)
  231 + #define MD_STACK_GROWS_DOWN
  232 +
  233 + #if defined(__GLIBC__) && __GLIBC__ >= 2
  234 + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[8]
424 #else 235 #else
425 - #error "Unknown CPU architecture"  
426 - #endif /* Cases with common MD_INIT_CONTEXT and different SP locations */ 236 + #error "ARM/Linux pre-glibc2 not supported yet"
  237 + #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
  238 + #elif defined(__s390__)
  239 + #define MD_STACK_GROWS_DOWN
427 240
428 - #define MD_INIT_CONTEXT(_thread, _sp, _main) \  
429 - ST_BEGIN_MACRO \  
430 - if (MD_SETJMP((_thread)->context)) \  
431 - _main(); \  
432 - MD_GET_SP(_thread) = (long) (_sp); \  
433 - ST_END_MACRO  
434 - #endif /* Cases with different MD_INIT_CONTEXT */  
435 -  
436 - #if defined(MD_USE_BUILTIN_SETJMP) && !defined(USE_LIBC_SETJMP)  
437 - #define MD_SETJMP(env) _st_md_cxt_save(env)  
438 - #define MD_LONGJMP(env, val) _st_md_cxt_restore(env, val) 241 + /* There is no JB_SP in glibc at this time. (glibc 2.2.5)
  242 + */
  243 + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__gregs[9]
  244 + #elif defined(__hppa__)
  245 + #define MD_STACK_GROWS_UP
439 246
440 - extern int _st_md_cxt_save(jmp_buf env);  
441 - extern void _st_md_cxt_restore(jmp_buf env, int val);  
442 - #else  
443 - #define MD_SETJMP(env) setjmp(env)  
444 - #define MD_LONGJMP(env, val) longjmp(env, val)  
445 - #endif  
446 -  
447 -#elif defined (NETBSD)  
448 - #define MD_STACK_GROWS_DOWN  
449 - #define MD_USE_BSD_ANON_MMAP  
450 - #define MD_ACCEPT_NB_INHERITED  
451 - #define MD_ALWAYS_UNSERIALIZED_ACCEPT  
452 - #define MD_HAVE_SOCKLEN_T  
453 -  
454 - #define MD_SETJMP(env) _setjmp(env)  
455 - #define MD_LONGJMP(env, val) _longjmp(env, val)  
456 -  
457 - #if defined(__i386__)  
458 - #define MD_JB_SP 2  
459 - #elif defined(__alpha__)  
460 - #define MD_JB_SP 34  
461 - #elif defined(__sparc__)  
462 - #define MD_JB_SP 0  
463 - #elif defined(__vax__)  
464 - #define MD_JB_SP 2  
465 - #else  
466 - #error Unknown CPU architecture  
467 - #endif  
468 -  
469 - #define MD_INIT_CONTEXT(_thread, _sp, _main) \  
470 - ST_BEGIN_MACRO \  
471 - if (MD_SETJMP((_thread)->context)) \  
472 - _main(); \  
473 - (_thread)->context[MD_JB_SP] = (long) (_sp); \  
474 - ST_END_MACRO  
475 -  
476 - #define MD_GET_UTIME() \  
477 - struct timeval tv; \  
478 - (void) gettimeofday(&tv, NULL); \  
479 - return (tv.tv_sec * 1000000LL + tv.tv_usec)  
480 -  
481 -#elif defined (OPENBSD)  
482 - #define MD_STACK_GROWS_DOWN  
483 - #define MD_USE_BSD_ANON_MMAP  
484 - #define MD_ACCEPT_NB_INHERITED  
485 - #define MD_ALWAYS_UNSERIALIZED_ACCEPT  
486 -  
487 - #define MD_SETJMP(env) _setjmp(env)  
488 - #define MD_LONGJMP(env, val) _longjmp(env, val)  
489 -  
490 - #if defined(__i386__)  
491 - #define MD_JB_SP 2  
492 - #elif defined(__alpha__)  
493 - #define MD_JB_SP 34  
494 - #elif defined(__sparc__)  
495 - #define MD_JB_SP 0  
496 - #elif defined(__amd64__)  
497 - #define MD_JB_SP 6 247 + /* yes, this is gross, unfortunately at the moment (2002/08/01) there is
  248 + * a bug in hppa's glibc header definition for JB_SP, so we can't
  249 + * use that...
  250 + */
  251 + #define MD_GET_SP(_t) (*(long *)(((char *)&(_t)->context[0].__jmpbuf[0]) + 76))
498 #else 252 #else
499 - #error Unknown CPU architecture  
500 - #endif  
501 -  
502 - #define MD_INIT_CONTEXT(_thread, _sp, _main) \  
503 - ST_BEGIN_MACRO \  
504 - if (MD_SETJMP((_thread)->context)) \  
505 - _main(); \  
506 - (_thread)->context[MD_JB_SP] = (long) (_sp); \  
507 - ST_END_MACRO  
508 -  
509 - #define MD_GET_UTIME() \  
510 - struct timeval tv; \  
511 - (void) gettimeofday(&tv, NULL); \  
512 - return (tv.tv_sec * 1000000LL + tv.tv_usec)  
513 -  
514 -#elif defined (OSF1)  
515 - #include <signal.h>  
516 -  
517 - #define MD_STACK_GROWS_DOWN  
518 - #define MD_USE_SYSV_ANON_MMAP  
519 - #define MD_ACCEPT_NB_NOT_INHERITED  
520 - #define MD_ALWAYS_UNSERIALIZED_ACCEPT 253 + #error "Unknown CPU architecture"
  254 + #endif /* Cases with common MD_INIT_CONTEXT and different SP locations */
521 255
522 - #define MD_SETJMP(env) _setjmp(env)  
523 - #define MD_LONGJMP(env, val) _longjmp(env, val)  
524 -  
525 - #define MD_INIT_CONTEXT(_thread, _sp, _main) \  
526 - ST_BEGIN_MACRO \  
527 - if (MD_SETJMP((_thread)->context)) \  
528 - _main(); \  
529 - ((struct sigcontext *)((_thread)->context))->sc_sp = (long) (_sp); \ 256 + #define MD_INIT_CONTEXT(_thread, _sp, _main) \
  257 + ST_BEGIN_MACRO \
  258 + if (MD_SETJMP((_thread)->context)) \
  259 + _main(); \
  260 + MD_GET_SP(_thread) = (long) (_sp); \
530 ST_END_MACRO 261 ST_END_MACRO
531 -  
532 - #define MD_GET_UTIME() \  
533 - struct timeval tv; \  
534 - (void) gettimeofday(&tv, NULL); \  
535 - return (tv.tv_sec * 1000000LL + tv.tv_usec) 262 +#endif /* Cases with different MD_INIT_CONTEXT */
536 263
537 -#elif defined (SOLARIS)  
538 - #include <sys/filio.h>  
539 - extern int getpagesize(void);  
540 -  
541 - #define MD_STACK_GROWS_DOWN  
542 - #define MD_USE_SYSV_ANON_MMAP  
543 - #define MD_ACCEPT_NB_NOT_INHERITED 264 +#if defined(MD_USE_BUILTIN_SETJMP) && !defined(USE_LIBC_SETJMP)
  265 + #define MD_SETJMP(env) _st_md_cxt_save(env)
  266 + #define MD_LONGJMP(env, val) _st_md_cxt_restore(env, val)
544 267
  268 + extern int _st_md_cxt_save(jmp_buf env);
  269 + extern void _st_md_cxt_restore(jmp_buf env, int val);
  270 +#else
545 #define MD_SETJMP(env) setjmp(env) 271 #define MD_SETJMP(env) setjmp(env)
546 #define MD_LONGJMP(env, val) longjmp(env, val) 272 #define MD_LONGJMP(env, val) longjmp(env, val)
547 -  
548 - #if defined(sparc) || defined(__sparc)  
549 - #ifdef _LP64  
550 - #define MD_STACK_PAD_SIZE 4095  
551 - #endif  
552 - #define MD_INIT_CONTEXT(_thread, _sp, _main) \  
553 - ST_BEGIN_MACRO \  
554 - (void) MD_SETJMP((_thread)->context); \  
555 - (_thread)->context[1] = (long) (_sp); \  
556 - (_thread)->context[2] = (long) _main; \  
557 - ST_END_MACRO  
558 - #elif defined(i386) || defined(__i386)  
559 - #define MD_INIT_CONTEXT(_thread, _sp, _main) \  
560 - ST_BEGIN_MACRO \  
561 - (void) MD_SETJMP((_thread)->context); \  
562 - (_thread)->context[4] = (long) (_sp); \  
563 - (_thread)->context[5] = (long) _main; \  
564 - ST_END_MACRO  
565 - #elif defined(__amd64__)  
566 - #define MD_INIT_CONTEXT(_thread, _sp, _main) \  
567 - ST_BEGIN_MACRO \  
568 - if (MD_SETJMP((_thread)->context)) \  
569 - _main(); \  
570 - (_thread)->context[6] = (long) (_sp); \  
571 - ST_END_MACRO  
572 - #else  
573 - #error Unknown CPU architecture  
574 - #endif  
575 -  
576 - #define MD_GET_UTIME() \  
577 - return (gethrtime() / 1000)  
578 -  
579 -#else  
580 - #error Unknown OS  
581 -#endif /* OS */ 273 +#endif
582 274
583 /***************************************** 275 /*****************************************
584 * Other defines 276 * Other defines