winlin

Merge branch 'srs.master'

@@ -50,7 +50,7 @@ @@ -50,7 +50,7 @@
50 50
51 /* Enable assertions only if DEBUG is defined */ 51 /* Enable assertions only if DEBUG is defined */
52 #ifndef DEBUG 52 #ifndef DEBUG
53 -#define NDEBUG 53 + #define NDEBUG
54 #endif 54 #endif
55 #include <assert.h> 55 #include <assert.h>
56 #define ST_ASSERT(expr) assert(expr) 56 #define ST_ASSERT(expr) assert(expr)
@@ -59,22 +59,21 @@ @@ -59,22 +59,21 @@
59 #define ST_END_MACRO } 59 #define ST_END_MACRO }
60 60
61 #ifdef DEBUG 61 #ifdef DEBUG
62 -#define ST_HIDDEN /*nothing*/ 62 + #define ST_HIDDEN /*nothing*/
63 #else 63 #else
64 -#define ST_HIDDEN static 64 + #define ST_HIDDEN static
65 #endif 65 #endif
66 66
67 #include "public.h" 67 #include "public.h"
68 #include "md.h" 68 #include "md.h"
69 69
70 -  
71 /***************************************** 70 /*****************************************
72 * Circular linked list definitions 71 * Circular linked list definitions
73 */ 72 */
74 73
75 typedef struct _st_clist { 74 typedef struct _st_clist {
76 - struct _st_clist *next;  
77 - struct _st_clist *prev; 75 + struct _st_clist *next;
  76 + struct _st_clist *prev;
78 } _st_clist_t; 77 } _st_clist_t;
79 78
80 /* Insert element "_e" into the list, before "_l" */ 79 /* Insert element "_e" into the list, before "_l" */
@@ -137,114 +136,113 @@ typedef struct _st_clist { @@ -137,114 +136,113 @@ typedef struct _st_clist {
137 136
138 typedef void (*_st_destructor_t)(void *); 137 typedef void (*_st_destructor_t)(void *);
139 138
140 -  
141 typedef struct _st_stack { 139 typedef struct _st_stack {
142 - _st_clist_t links;  
143 - char *vaddr; /* Base of stack's allocated memory */  
144 - int vaddr_size; /* Size of stack's allocated memory */  
145 - int stk_size; /* Size of usable portion of the stack */  
146 - char *stk_bottom; /* Lowest address of stack's usable portion */  
147 - char *stk_top; /* Highest address of stack's usable portion */  
148 - void *sp; /* Stack pointer from C's point of view */  
149 -#ifdef __ia64__  
150 - void *bsp; /* Register stack backing store pointer */  
151 -#endif 140 + _st_clist_t links;
  141 + char *vaddr; /* Base of stack's allocated memory */
  142 + int vaddr_size; /* Size of stack's allocated memory */
  143 + int stk_size; /* Size of usable portion of the stack */
  144 + char *stk_bottom; /* Lowest address of stack's usable portion */
  145 + char *stk_top; /* Highest address of stack's usable portion */
  146 + void *sp; /* Stack pointer from C's point of view */
  147 + #ifdef __ia64__
  148 + void *bsp; /* Register stack backing store pointer */
  149 + #endif
152 } _st_stack_t; 150 } _st_stack_t;
153 151
154 152
155 typedef struct _st_cond { 153 typedef struct _st_cond {
156 - _st_clist_t wait_q; /* Condition variable wait queue */ 154 + _st_clist_t wait_q; /* Condition variable wait queue */
157 } _st_cond_t; 155 } _st_cond_t;
158 156
159 157
160 typedef struct _st_thread _st_thread_t; 158 typedef struct _st_thread _st_thread_t;
161 159
162 struct _st_thread { 160 struct _st_thread {
163 - int state; /* Thread's state */  
164 - int flags; /* Thread's flags */  
165 -  
166 - void *(*start)(void *arg); /* The start function of the thread */  
167 - void *arg; /* Argument of the start function */  
168 - void *retval; /* Return value of the start function */  
169 -  
170 - _st_stack_t *stack; /* Info about thread's stack */  
171 -  
172 - _st_clist_t links; /* For putting on run/sleep/zombie queue */  
173 - _st_clist_t wait_links; /* For putting on mutex/condvar wait queue */  
174 -#ifdef DEBUG  
175 - _st_clist_t tlink; /* For putting on thread queue */  
176 -#endif  
177 -  
178 - st_utime_t due; /* Wakeup time when thread is sleeping */  
179 - _st_thread_t *left; /* For putting in timeout heap */  
180 - _st_thread_t *right; /* -- see docs/timeout_heap.txt for details */  
181 - int heap_index;  
182 -  
183 - void **private_data; /* Per thread private data */  
184 -  
185 - _st_cond_t *term; /* Termination condition variable for join */  
186 -  
187 - jmp_buf context; /* Thread's context */ 161 + int state; /* Thread's state */
  162 + int flags; /* Thread's flags */
  163 +
  164 + void *(*start)(void *arg); /* The start function of the thread */
  165 + void *arg; /* Argument of the start function */
  166 + void *retval; /* Return value of the start function */
  167 +
  168 + _st_stack_t *stack; /* Info about thread's stack */
  169 +
  170 + _st_clist_t links; /* For putting on run/sleep/zombie queue */
  171 + _st_clist_t wait_links; /* For putting on mutex/condvar wait queue */
  172 + #ifdef DEBUG
  173 + _st_clist_t tlink; /* For putting on thread queue */
  174 + #endif
  175 +
  176 + st_utime_t due; /* Wakeup time when thread is sleeping */
  177 + _st_thread_t *left; /* For putting in timeout heap */
  178 + _st_thread_t *right; /* -- see docs/timeout_heap.txt for details */
  179 + int heap_index;
  180 +
  181 + void **private_data; /* Per thread private data */
  182 +
  183 + _st_cond_t *term; /* Termination condition variable for join */
  184 +
  185 + jmp_buf context; /* Thread's context */
188 }; 186 };
189 187
190 188
191 typedef struct _st_mutex { 189 typedef struct _st_mutex {
192 - _st_thread_t *owner; /* Current mutex owner */  
193 - _st_clist_t wait_q; /* Mutex wait queue */ 190 + _st_thread_t *owner; /* Current mutex owner */
  191 + _st_clist_t wait_q; /* Mutex wait queue */
194 } _st_mutex_t; 192 } _st_mutex_t;
195 193
196 194
197 typedef struct _st_pollq { 195 typedef struct _st_pollq {
198 - _st_clist_t links; /* For putting on io queue */  
199 - _st_thread_t *thread; /* Polling thread */  
200 - struct pollfd *pds; /* Array of poll descriptors */  
201 - int npds; /* Length of the array */  
202 - int on_ioq; /* Is it on ioq? */ 196 + _st_clist_t links; /* For putting on io queue */
  197 + _st_thread_t *thread; /* Polling thread */
  198 + struct pollfd *pds; /* Array of poll descriptors */
  199 + int npds; /* Length of the array */
  200 + int on_ioq; /* Is it on ioq? */
203 } _st_pollq_t; 201 } _st_pollq_t;
204 202
205 203
206 typedef struct _st_eventsys_ops { 204 typedef struct _st_eventsys_ops {
207 - const char *name; /* Name of this event system */  
208 - int val; /* Type of this event system */  
209 - int (*init)(void); /* Initialization */  
210 - void (*dispatch)(void); /* Dispatch function */  
211 - int (*pollset_add)(struct pollfd *, int); /* Add descriptor set */  
212 - void (*pollset_del)(struct pollfd *, int); /* Delete descriptor set */  
213 - int (*fd_new)(int); /* New descriptor allocated */  
214 - int (*fd_close)(int); /* Descriptor closed */  
215 - int (*fd_getlimit)(void); /* Descriptor hard limit */ 205 + const char *name; /* Name of this event system */
  206 + int val; /* Type of this event system */
  207 + int (*init)(void); /* Initialization */
  208 + void (*dispatch)(void); /* Dispatch function */
  209 + int (*pollset_add)(struct pollfd *, int); /* Add descriptor set */
  210 + void (*pollset_del)(struct pollfd *, int); /* Delete descriptor set */
  211 + int (*fd_new)(int); /* New descriptor allocated */
  212 + int (*fd_close)(int); /* Descriptor closed */
  213 + int (*fd_getlimit)(void); /* Descriptor hard limit */
216 } _st_eventsys_t; 214 } _st_eventsys_t;
217 215
218 216
219 typedef struct _st_vp { 217 typedef struct _st_vp {
220 - _st_thread_t *idle_thread; /* Idle thread for this vp */  
221 - st_utime_t last_clock; /* The last time we went into vp_check_clock() */  
222 -  
223 - _st_clist_t run_q; /* run queue for this vp */  
224 - _st_clist_t io_q; /* io queue for this vp */  
225 - _st_clist_t zombie_q; /* zombie queue for this vp */  
226 -#ifdef DEBUG  
227 - _st_clist_t thread_q; /* all threads of this vp */  
228 -#endif  
229 - int pagesize;  
230 -  
231 - _st_thread_t *sleep_q; /* sleep queue for this vp */  
232 - int sleepq_size; /* number of threads on sleep queue */  
233 -  
234 -#ifdef ST_SWITCH_CB  
235 - st_switch_cb_t switch_out_cb; /* called when a thread is switched out */  
236 - st_switch_cb_t switch_in_cb; /* called when a thread is switched in */  
237 -#endif 218 + _st_thread_t *idle_thread; /* Idle thread for this vp */
  219 + st_utime_t last_clock; /* The last time we went into vp_check_clock() */
  220 +
  221 + _st_clist_t run_q; /* run queue for this vp */
  222 + _st_clist_t io_q; /* io queue for this vp */
  223 + _st_clist_t zombie_q; /* zombie queue for this vp */
  224 + #ifdef DEBUG
  225 + _st_clist_t thread_q; /* all threads of this vp */
  226 + #endif
  227 + int pagesize;
  228 +
  229 + _st_thread_t *sleep_q; /* sleep queue for this vp */
  230 + int sleepq_size; /* number of threads on sleep queue */
  231 +
  232 + #ifdef ST_SWITCH_CB
  233 + st_switch_cb_t switch_out_cb; /* called when a thread is switched out */
  234 + st_switch_cb_t switch_in_cb; /* called when a thread is switched in */
  235 + #endif
238 } _st_vp_t; 236 } _st_vp_t;
239 237
240 238
241 typedef struct _st_netfd { 239 typedef struct _st_netfd {
242 - int osfd; /* Underlying OS file descriptor */  
243 - int inuse; /* In-use flag */  
244 - void *private_data; /* Per descriptor private data */  
245 - _st_destructor_t destructor; /* Private data destructor function */  
246 - void *aux_data; /* Auxiliary data for internal use */  
247 - struct _st_netfd *next; /* For putting on the free list */ 240 + int osfd; /* Underlying OS file descriptor */
  241 + int inuse; /* In-use flag */
  242 + void *private_data; /* Per descriptor private data */
  243 + _st_destructor_t destructor; /* Private data destructor function */
  244 + void *aux_data; /* Auxiliary data for internal use */
  245 + struct _st_netfd *next; /* For putting on the free list */
248 } _st_netfd_t; 246 } _st_netfd_t;
249 247
250 248
@@ -265,7 +263,7 @@ extern _st_eventsys_t *_st_eventsys; @@ -265,7 +263,7 @@ extern _st_eventsys_t *_st_eventsys;
265 #define _ST_IOQ (_st_this_vp.io_q) 263 #define _ST_IOQ (_st_this_vp.io_q)
266 #define _ST_ZOMBIEQ (_st_this_vp.zombie_q) 264 #define _ST_ZOMBIEQ (_st_this_vp.zombie_q)
267 #ifdef DEBUG 265 #ifdef DEBUG
268 -#define _ST_THREADQ (_st_this_vp.thread_q) 266 + #define _ST_THREADQ (_st_this_vp.thread_q)
269 #endif 267 #endif
270 268
271 #define _ST_PAGE_SIZE (_st_this_vp.pagesize) 269 #define _ST_PAGE_SIZE (_st_this_vp.pagesize)
@@ -293,8 +291,8 @@ extern _st_eventsys_t *_st_eventsys; @@ -293,8 +291,8 @@ extern _st_eventsys_t *_st_eventsys;
293 #define _ST_DEL_ZOMBIEQ(_thr) ST_REMOVE_LINK(&(_thr)->links) 291 #define _ST_DEL_ZOMBIEQ(_thr) ST_REMOVE_LINK(&(_thr)->links)
294 292
295 #ifdef DEBUG 293 #ifdef DEBUG
296 -#define _ST_ADD_THREADQ(_thr) ST_APPEND_LINK(&(_thr)->tlink, &_ST_THREADQ)  
297 -#define _ST_DEL_THREADQ(_thr) ST_REMOVE_LINK(&(_thr)->tlink) 294 + #define _ST_ADD_THREADQ(_thr) ST_APPEND_LINK(&(_thr)->tlink, &_ST_THREADQ)
  295 + #define _ST_DEL_THREADQ(_thr) ST_REMOVE_LINK(&(_thr)->tlink)
298 #endif 296 #endif
299 297
300 298
@@ -317,13 +315,12 @@ extern _st_eventsys_t *_st_eventsys; @@ -317,13 +315,12 @@ extern _st_eventsys_t *_st_eventsys;
317 #define _ST_FL_INTERRUPT 0x08 315 #define _ST_FL_INTERRUPT 0x08
318 #define _ST_FL_TIMEDOUT 0x10 316 #define _ST_FL_TIMEDOUT 0x10
319 317
320 -  
321 /***************************************** 318 /*****************************************
322 * Pointer conversion 319 * Pointer conversion
323 */ 320 */
324 321
325 #ifndef offsetof 322 #ifndef offsetof
326 -#define offsetof(type, identifier) ((size_t)&(((type *)0)->identifier)) 323 + #define offsetof(type, identifier) ((size_t)&(((type *)0)->identifier))
327 #endif 324 #endif
328 325
329 #define _ST_THREAD_PTR(_qp) \ 326 #define _ST_THREAD_PTR(_qp) \
@@ -339,8 +336,8 @@ extern _st_eventsys_t *_st_eventsys; @@ -339,8 +336,8 @@ extern _st_eventsys_t *_st_eventsys;
339 ((_st_pollq_t *)((char *)(_qp) - offsetof(_st_pollq_t, links))) 336 ((_st_pollq_t *)((char *)(_qp) - offsetof(_st_pollq_t, links)))
340 337
341 #ifdef DEBUG 338 #ifdef DEBUG
342 -#define _ST_THREAD_THREADQ_PTR(_qp) \  
343 - ((_st_thread_t *)((char *)(_qp) - offsetof(_st_thread_t, tlink))) 339 + #define _ST_THREAD_THREADQ_PTR(_qp) \
  340 + ((_st_thread_t *)((char *)(_qp) - offsetof(_st_thread_t, tlink)))
344 #endif 341 #endif
345 342
346 343
@@ -349,21 +346,21 @@ extern _st_eventsys_t *_st_eventsys; @@ -349,21 +346,21 @@ extern _st_eventsys_t *_st_eventsys;
349 */ 346 */
350 347
351 #ifndef ST_UTIME_NO_TIMEOUT 348 #ifndef ST_UTIME_NO_TIMEOUT
352 -#define ST_UTIME_NO_TIMEOUT ((st_utime_t) -1LL) 349 + #define ST_UTIME_NO_TIMEOUT ((st_utime_t) -1LL)
353 #endif 350 #endif
354 351
355 #ifndef __ia64__ 352 #ifndef __ia64__
356 -#define ST_DEFAULT_STACK_SIZE (64*1024) 353 + #define ST_DEFAULT_STACK_SIZE (64*1024)
357 #else 354 #else
358 -#define ST_DEFAULT_STACK_SIZE (128*1024) /* Includes register stack size */ 355 + #define ST_DEFAULT_STACK_SIZE (128*1024) /* Includes register stack size */
359 #endif 356 #endif
360 357
361 #ifndef ST_KEYS_MAX 358 #ifndef ST_KEYS_MAX
362 -#define ST_KEYS_MAX 16 359 + #define ST_KEYS_MAX 16
363 #endif 360 #endif
364 361
365 #ifndef ST_MIN_POLLFDS_SIZE 362 #ifndef ST_MIN_POLLFDS_SIZE
366 -#define ST_MIN_POLLFDS_SIZE 64 363 + #define ST_MIN_POLLFDS_SIZE 64
367 #endif 364 #endif
368 365
369 366
@@ -372,28 +369,28 @@ extern _st_eventsys_t *_st_eventsys; @@ -372,28 +369,28 @@ extern _st_eventsys_t *_st_eventsys;
372 */ 369 */
373 370
374 #ifdef DEBUG 371 #ifdef DEBUG
375 -void _st_iterate_threads(void);  
376 -#define ST_DEBUG_ITERATE_THREADS() _st_iterate_threads() 372 + void _st_iterate_threads(void);
  373 + #define ST_DEBUG_ITERATE_THREADS() _st_iterate_threads()
377 #else 374 #else
378 -#define ST_DEBUG_ITERATE_THREADS() 375 + #define ST_DEBUG_ITERATE_THREADS()
379 #endif 376 #endif
380 377
381 #ifdef ST_SWITCH_CB 378 #ifdef ST_SWITCH_CB
382 -#define ST_SWITCH_OUT_CB(_thread) \  
383 - if (_st_this_vp.switch_out_cb != NULL && \ 379 + #define ST_SWITCH_OUT_CB(_thread) \
  380 + if (_st_this_vp.switch_out_cb != NULL && \
  381 + _thread != _st_this_vp.idle_thread && \
  382 + _thread->state != _ST_ST_ZOMBIE) { \
  383 + _st_this_vp.switch_out_cb(); \
  384 + }
  385 + #define ST_SWITCH_IN_CB(_thread) \
  386 + if (_st_this_vp.switch_in_cb != NULL && \
384 _thread != _st_this_vp.idle_thread && \ 387 _thread != _st_this_vp.idle_thread && \
385 _thread->state != _ST_ST_ZOMBIE) { \ 388 _thread->state != _ST_ST_ZOMBIE) { \
386 - _st_this_vp.switch_out_cb(); \  
387 - }  
388 -#define ST_SWITCH_IN_CB(_thread) \  
389 - if (_st_this_vp.switch_in_cb != NULL && \  
390 - _thread != _st_this_vp.idle_thread && \  
391 - _thread->state != _ST_ST_ZOMBIE) { \  
392 - _st_this_vp.switch_in_cb(); \  
393 - } 389 + _st_this_vp.switch_in_cb(); \
  390 + }
394 #else 391 #else
395 -#define ST_SWITCH_OUT_CB(_thread)  
396 -#define ST_SWITCH_IN_CB(_thread) 392 + #define ST_SWITCH_OUT_CB(_thread)
  393 + #define ST_SWITCH_IN_CB(_thread)
397 #endif 394 #endif
398 395
399 /* 396 /*
@@ -424,9 +421,9 @@ void _st_iterate_threads(void); @@ -424,9 +421,9 @@ void _st_iterate_threads(void);
424 * Initialize the thread context preparing it to execute _main 421 * Initialize the thread context preparing it to execute _main
425 */ 422 */
426 #ifdef MD_INIT_CONTEXT 423 #ifdef MD_INIT_CONTEXT
427 -#define _ST_INIT_CONTEXT MD_INIT_CONTEXT 424 + #define _ST_INIT_CONTEXT MD_INIT_CONTEXT
428 #else 425 #else
429 -#error Unknown OS 426 + #error Unknown OS
430 #endif 427 #endif
431 428
432 /* 429 /*
@@ -456,11 +453,9 @@ int st_cond_destroy(_st_cond_t *cvar); @@ -456,11 +453,9 @@ int st_cond_destroy(_st_cond_t *cvar);
456 int st_cond_timedwait(_st_cond_t *cvar, st_utime_t timeout); 453 int st_cond_timedwait(_st_cond_t *cvar, st_utime_t timeout);
457 int st_cond_signal(_st_cond_t *cvar); 454 int st_cond_signal(_st_cond_t *cvar);
458 ssize_t st_read(_st_netfd_t *fd, void *buf, size_t nbyte, st_utime_t timeout); 455 ssize_t st_read(_st_netfd_t *fd, void *buf, size_t nbyte, st_utime_t timeout);
459 -ssize_t st_write(_st_netfd_t *fd, const void *buf, size_t nbyte,  
460 - st_utime_t timeout); 456 +ssize_t st_write(_st_netfd_t *fd, const void *buf, size_t nbyte, st_utime_t timeout);
461 int st_poll(struct pollfd *pds, int npds, st_utime_t timeout); 457 int st_poll(struct pollfd *pds, int npds, st_utime_t timeout);
462 -_st_thread_t *st_thread_create(void *(*start)(void *arg), void *arg,  
463 - int joinable, int stk_size); 458 +_st_thread_t *st_thread_create(void *(*start)(void *arg), void *arg, int joinable, int stk_size);
464 459
465 #endif /* !__ST_COMMON_H__ */ 460 #endif /* !__ST_COMMON_H__ */
466 461
@@ -43,584 +43,560 @@ @@ -43,584 +43,560 @@
43 #define __ST_MD_H__ 43 #define __ST_MD_H__
44 44
45 #if defined(ETIMEDOUT) && !defined(ETIME) 45 #if defined(ETIMEDOUT) && !defined(ETIME)
46 -#define ETIME ETIMEDOUT 46 + #define ETIME ETIMEDOUT
47 #endif 47 #endif
48 48
49 #if defined(MAP_ANONYMOUS) && !defined(MAP_ANON) 49 #if defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
50 -#define MAP_ANON MAP_ANONYMOUS 50 + #define MAP_ANON MAP_ANONYMOUS
51 #endif 51 #endif
52 52
53 #ifndef MAP_FAILED 53 #ifndef MAP_FAILED
54 -#define MAP_FAILED -1 54 + #define MAP_FAILED -1
55 #endif 55 #endif
56 56
57 /***************************************** 57 /*****************************************
58 * Platform specifics 58 * Platform specifics
59 */ 59 */
60 -  
61 #if defined (AIX) 60 #if defined (AIX)
62 -  
63 -#define MD_STACK_GROWS_DOWN  
64 -#define MD_USE_SYSV_ANON_MMAP  
65 -#define MD_ACCEPT_NB_INHERITED  
66 -#define MD_ALWAYS_UNSERIALIZED_ACCEPT  
67 -  
68 -#ifndef MD_HAVE_SOCKLEN_T  
69 -#define MD_HAVE_SOCKLEN_T  
70 -#define socklen_t unsigned long  
71 -#endif  
72 -  
73 -#define MD_SETJMP(env) _setjmp(env)  
74 -#define MD_LONGJMP(env, val) _longjmp(env, val)  
75 -  
76 -#define MD_INIT_CONTEXT(_thread, _sp, _main) \  
77 - ST_BEGIN_MACRO \  
78 - if (MD_SETJMP((_thread)->context)) \  
79 - _main(); \  
80 - (_thread)->context[3] = (long) (_sp); \  
81 - ST_END_MACRO  
82 -  
83 -#define MD_GET_UTIME() \  
84 - timebasestruct_t rt; \  
85 - (void) read_real_time(&rt, TIMEBASE_SZ); \  
86 - (void) time_base_to_time(&rt, TIMEBASE_SZ); \  
87 - return (rt.tb_high * 1000000LL + rt.tb_low / 1000) 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)
88 86
89 #elif defined (CYGWIN) 87 #elif defined (CYGWIN)
90 -  
91 -#define MD_STACK_GROWS_DOWN  
92 -#define MD_USE_BSD_ANON_MMAP  
93 -#define MD_ACCEPT_NB_NOT_INHERITED  
94 -#define MD_ALWAYS_UNSERIALIZED_ACCEPT  
95 -  
96 -#define MD_SETJMP(env) setjmp(env)  
97 -#define MD_LONGJMP(env, val) longjmp(env, val)  
98 -  
99 -#define MD_JB_SP 7  
100 -  
101 -#define MD_GET_SP(_t) (_t)->context[MD_JB_SP]  
102 -  
103 -#define MD_INIT_CONTEXT(_thread, _sp, _main) \  
104 - ST_BEGIN_MACRO \  
105 - if (MD_SETJMP((_thread)->context)) \  
106 - _main(); \  
107 - MD_GET_SP(_thread) = (long) (_sp); \  
108 - ST_END_MACRO  
109 -  
110 -#define MD_GET_UTIME() \  
111 - struct timeval tv; \  
112 - (void) gettimeofday(&tv, NULL); \  
113 - return (tv.tv_sec * 1000000LL + tv.tv_usec) 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)
114 111
115 #elif defined (DARWIN) 112 #elif defined (DARWIN)
116 -  
117 -#define MD_STACK_GROWS_DOWN  
118 -#define MD_USE_BSD_ANON_MMAP  
119 -#define MD_ACCEPT_NB_INHERITED  
120 -#define MD_ALWAYS_UNSERIALIZED_ACCEPT  
121 -#define MD_HAVE_SOCKLEN_T  
122 -  
123 -#define MD_SETJMP(env) _setjmp(env)  
124 -#define MD_LONGJMP(env, val) _longjmp(env, val)  
125 -  
126 -#if defined(__ppc__)  
127 -#define MD_JB_SP 0  
128 -#elif defined(__i386__)  
129 -#define MD_JB_SP 9  
130 -#elif defined(__x86_64__)  
131 -#define MD_JB_SP 4  
132 -#else  
133 -#error Unknown CPU architecture  
134 -#endif  
135 -  
136 -#define MD_INIT_CONTEXT(_thread, _sp, _main) \  
137 - ST_BEGIN_MACRO \  
138 - if (MD_SETJMP((_thread)->context)) \  
139 - _main(); \  
140 - *((long *)&((_thread)->context[MD_JB_SP])) = (long) (_sp); \  
141 - ST_END_MACRO  
142 -  
143 -#define MD_GET_UTIME() \  
144 - struct timeval tv; \  
145 - (void) gettimeofday(&tv, NULL); \  
146 - return (tv.tv_sec * 1000000LL + tv.tv_usec) 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
  131 +
  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
  138 +
  139 + #define MD_GET_UTIME() \
  140 + struct timeval tv; \
  141 + (void) gettimeofday(&tv, NULL); \
  142 + return (tv.tv_sec * 1000000LL + tv.tv_usec)
147 143
148 #elif defined (FREEBSD) 144 #elif defined (FREEBSD)
149 -  
150 -#define MD_STACK_GROWS_DOWN  
151 -#define MD_USE_BSD_ANON_MMAP  
152 -#define MD_ACCEPT_NB_INHERITED  
153 -#define MD_ALWAYS_UNSERIALIZED_ACCEPT  
154 -  
155 -#define MD_SETJMP(env) _setjmp(env)  
156 -#define MD_LONGJMP(env, val) _longjmp(env, val)  
157 -  
158 -#if defined(__i386__)  
159 -#define MD_JB_SP 2  
160 -#elif defined(__alpha__)  
161 -#define MD_JB_SP 34  
162 -#elif defined(__amd64__)  
163 -#define MD_JB_SP 2  
164 -#else  
165 -#error Unknown CPU architecture  
166 -#endif  
167 -  
168 -#define MD_INIT_CONTEXT(_thread, _sp, _main) \  
169 - ST_BEGIN_MACRO \  
170 - if (MD_SETJMP((_thread)->context)) \  
171 - _main(); \  
172 - (_thread)->context[0]._jb[MD_JB_SP] = (long) (_sp); \  
173 - ST_END_MACRO  
174 -  
175 -#define MD_GET_UTIME() \  
176 - struct timeval tv; \  
177 - (void) gettimeofday(&tv, NULL); \  
178 - return (tv.tv_sec * 1000000LL + tv.tv_usec) 145 + #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 +
  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
  161 + #endif
  162 +
  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); \
  168 + 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)
179 174
180 #elif defined (HPUX) 175 #elif defined (HPUX)
181 -  
182 -#define MD_STACK_GROWS_UP  
183 -#define MD_USE_BSD_ANON_MMAP  
184 -#define MD_ACCEPT_NB_INHERITED  
185 -#define MD_ALWAYS_UNSERIALIZED_ACCEPT  
186 -  
187 -#define MD_SETJMP(env) _setjmp(env)  
188 -#define MD_LONGJMP(env, val) _longjmp(env, val)  
189 -  
190 -#ifndef __LP64__  
191 -/* 32-bit mode (ILP32 data model) */  
192 -#define MD_INIT_CONTEXT(_thread, _sp, _main) \  
193 - ST_BEGIN_MACRO \  
194 - if (MD_SETJMP((_thread)->context)) \  
195 - _main(); \  
196 - ((long *)((_thread)->context))[1] = (long) (_sp); \  
197 - ST_END_MACRO  
198 -#else  
199 -/* 64-bit mode (LP64 data model) */  
200 -#define MD_STACK_PAD_SIZE 256  
201 -/* Last stack frame must be preserved */  
202 -#define MD_INIT_CONTEXT(_thread, _sp, _main) \  
203 - ST_BEGIN_MACRO \  
204 - if (MD_SETJMP((_thread)->context)) \  
205 - _main(); \  
206 - memcpy((char *)(_sp) - MD_STACK_PAD_SIZE, \  
207 - ((char **)((_thread)->context))[1] - MD_STACK_PAD_SIZE, \  
208 - MD_STACK_PAD_SIZE); \  
209 - ((long *)((_thread)->context))[1] = (long) (_sp); \  
210 - ST_END_MACRO  
211 -#endif /* !__LP64__ */  
212 -  
213 -#define MD_GET_UTIME() \  
214 - struct timeval tv; \  
215 - (void) gettimeofday(&tv, NULL); \  
216 - return (tv.tv_sec * 1000000LL + tv.tv_usec) 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)
217 211
218 #elif defined (IRIX) 212 #elif defined (IRIX)
219 -  
220 -#include <sys/syssgi.h>  
221 -  
222 -#define MD_STACK_GROWS_DOWN  
223 -#define MD_USE_SYSV_ANON_MMAP  
224 -#define MD_ACCEPT_NB_INHERITED  
225 -#define MD_ALWAYS_UNSERIALIZED_ACCEPT  
226 -  
227 -#define MD_SETJMP(env) setjmp(env)  
228 -#define MD_LONGJMP(env, val) longjmp(env, val)  
229 -  
230 -#define MD_INIT_CONTEXT(_thread, _sp, _main) \  
231 - ST_BEGIN_MACRO \  
232 - (void) MD_SETJMP((_thread)->context); \  
233 - (_thread)->context[JB_SP] = (long) (_sp); \  
234 - (_thread)->context[JB_PC] = (long) _main; \  
235 - ST_END_MACRO  
236 -  
237 -#define MD_GET_UTIME() \  
238 - static int inited = 0; \  
239 - static clockid_t clock_id = CLOCK_SGI_CYCLE; \  
240 - struct timespec ts; \  
241 - if (!inited) { \  
242 - if (syssgi(SGI_CYCLECNTR_SIZE) < 64) \  
243 - clock_id = CLOCK_REALTIME; \  
244 - inited = 1; \  
245 - } \  
246 - (void) clock_gettime(clock_id, &ts); \  
247 - return (ts.tv_sec * 1000000LL + ts.tv_nsec / 1000)  
248 -  
249 -/*  
250 - * Cap the stack by zeroing out the saved return address register  
251 - * value. This allows libexc, used by SpeedShop, to know when to stop  
252 - * backtracing since it won't find main, start, or any other known  
253 - * stack root function in a state thread's stack. Without this libexc  
254 - * traces right off the stack and crashes.  
255 - * The function preamble stores ra at 8(sp), this stores zero there.  
256 - * N.B. This macro is compiler/ABI dependent. It must change if ANY more  
257 - * automatic variables are added to the _st_thread_main() routine, because  
258 - * the address where ra is stored will change.  
259 - */  
260 -#if !defined(__GNUC__) && defined(_MIPS_SIM) && _MIPS_SIM != _ABIO32  
261 -#define MD_CAP_STACK(var_addr) \  
262 - (((volatile __uint64_t *)(var_addr))[1] = 0)  
263 -#endif 213 + #include <sys/syssgi.h>
  214 +
  215 + #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 +
  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; \
  228 + 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 +
  242 + /*
  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.
  252 + */
  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
264 257
265 #elif defined (LINUX) 258 #elif defined (LINUX)
266 -  
267 -/*  
268 - * These are properties of the linux kernel and are the same on every  
269 - * flavor and architecture.  
270 - */  
271 -#define MD_USE_BSD_ANON_MMAP  
272 -#define MD_ACCEPT_NB_NOT_INHERITED  
273 -#define MD_ALWAYS_UNSERIALIZED_ACCEPT  
274 -/*  
275 - * Modern GNU/Linux is Posix.1g compliant.  
276 - */  
277 -#define MD_HAVE_SOCKLEN_T  
278 -  
279 -/*  
280 - * All architectures and flavors of linux have the gettimeofday  
281 - * function but if you know of a faster way, use it.  
282 - */  
283 -#define MD_GET_UTIME() \  
284 - struct timeval tv; \  
285 - (void) gettimeofday(&tv, NULL); \  
286 - return (tv.tv_sec * 1000000LL + tv.tv_usec)  
287 -  
288 -#if defined(__ia64__)  
289 -#define MD_STACK_GROWS_DOWN  
290 -  
291 -/*  
292 - * IA-64 architecture. Besides traditional memory call stack, IA-64  
293 - * uses general register stack. Thus each thread needs a backing store  
294 - * for register stack in addition to memory stack. Standard  
295 - * setjmp()/longjmp() cannot be used for thread context switching  
296 - * because their implementation implicitly assumes that only one  
297 - * register stack exists.  
298 - */  
299 -#ifdef USE_LIBC_SETJMP  
300 -#undef USE_LIBC_SETJMP  
301 -#endif  
302 -#define MD_USE_BUILTIN_SETJMP  
303 -  
304 -#define MD_STACK_PAD_SIZE 128  
305 -/* Last register stack frame must be preserved */  
306 -#define MD_INIT_CONTEXT(_thread, _sp, _bsp, _main) \  
307 - ST_BEGIN_MACRO \  
308 - if (MD_SETJMP((_thread)->context)) \  
309 - _main(); \  
310 - memcpy((char *)(_bsp) - MD_STACK_PAD_SIZE, \  
311 - (char *)(_thread)->context[0].__jmpbuf[17] - MD_STACK_PAD_SIZE, \  
312 - MD_STACK_PAD_SIZE); \  
313 - (_thread)->context[0].__jmpbuf[0] = (long) (_sp); \  
314 - (_thread)->context[0].__jmpbuf[17] = (long) (_bsp); \  
315 - ST_END_MACRO  
316 -  
317 -#elif defined(__mips__)  
318 -#define MD_STACK_GROWS_DOWN  
319 -  
320 -#define MD_INIT_CONTEXT(_thread, _sp, _main) \  
321 - ST_BEGIN_MACRO \  
322 - MD_SETJMP((_thread)->context); \  
323 - _thread->context[0].__jmpbuf[0].__pc = (__ptr_t) _main; \  
324 - _thread->context[0].__jmpbuf[0].__sp = _sp; \  
325 - ST_END_MACRO  
326 -  
327 -#else /* Not IA-64 or mips */  
328 -  
329 -/*  
330 - * On linux, there are a few styles of jmpbuf format. These vary based  
331 - * on architecture/glibc combination.  
332 - *  
333 - * Most of the glibc based toggles were lifted from:  
334 - * mozilla/nsprpub/pr/include/md/_linux.h  
335 - */  
336 -  
337 -/*  
338 - * Starting with glibc 2.4, JB_SP definitions are not public anymore.  
339 - * They, however, can still be found in glibc source tree in  
340 - * architecture-specific "jmpbuf-offsets.h" files.  
341 - * Most importantly, the content of jmp_buf is mangled by setjmp to make  
342 - * it completely opaque (the mangling can be disabled by setting the  
343 - * LD_POINTER_GUARD environment variable before application execution).  
344 - * Therefore we will use built-in _st_md_cxt_save/_st_md_cxt_restore  
345 - * functions as a setjmp/longjmp replacement wherever they are available  
346 - * unless USE_LIBC_SETJMP is defined.  
347 - */  
348 -  
349 -#if defined(__powerpc__)  
350 -#define MD_STACK_GROWS_DOWN  
351 -  
352 -#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)  
353 -#ifndef JB_GPR1  
354 -#define JB_GPR1 0  
355 -#endif  
356 -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_GPR1]  
357 -#else  
358 -/* not an error but certainly cause for caution */  
359 -#error "Untested use of old glibc on powerpc"  
360 -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__misc[0]  
361 -#endif /* glibc 2.1 or later */  
362 -  
363 -#elif defined(__alpha)  
364 -#define MD_STACK_GROWS_DOWN  
365 -  
366 -#if defined(__GLIBC__) && __GLIBC__ >= 2  
367 -#ifndef JB_SP  
368 -#define JB_SP 8  
369 -#endif  
370 -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_SP]  
371 -#else  
372 -/* not an error but certainly cause for caution */  
373 -#error "Untested use of old glibc on alpha"  
374 -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__sp  
375 -#endif  
376 -  
377 -#elif defined(__mc68000__)  
378 -#define MD_STACK_GROWS_DOWN  
379 -  
380 -/* m68k still uses old style sigjmp_buf */  
381 -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__sp  
382 -  
383 -#elif defined(__sparc__)  
384 -#define MD_STACK_GROWS_DOWN  
385 -  
386 -#if defined(__GLIBC__) && __GLIBC__ >= 2  
387 -#ifndef JB_SP  
388 -#define JB_SP 0  
389 -#endif  
390 -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_SP]  
391 -#else  
392 -/* not an error but certainly cause for caution */  
393 -#error "Untested use of old glic on sparc -- also using odd mozilla derived __fp"  
394 -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__fp  
395 -#endif  
396 -  
397 -#elif defined(__i386__)  
398 -#define MD_STACK_GROWS_DOWN  
399 -#define MD_USE_BUILTIN_SETJMP  
400 -  
401 -#if defined(__GLIBC__) && __GLIBC__ >= 2  
402 -#ifndef JB_SP  
403 -#define JB_SP 4  
404 -#endif  
405 -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_SP]  
406 -#else  
407 -/* not an error but certainly cause for caution */  
408 -#error "Untested use of old glibc on i386"  
409 -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__sp  
410 -#endif  
411 -  
412 -#elif defined(__amd64__) || defined(__x86_64__)  
413 -#define MD_STACK_GROWS_DOWN  
414 -#define MD_USE_BUILTIN_SETJMP  
415 -  
416 -#ifndef JB_RSP  
417 -#define JB_RSP 6  
418 -#endif  
419 -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_RSP]  
420 -  
421 -#elif defined(__arm__)  
422 -#define MD_STACK_GROWS_DOWN  
423 -  
424 -#if defined(__GLIBC__) && __GLIBC__ >= 2  
425 -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[20]  
426 -#else  
427 -#error "ARM/Linux pre-glibc2 not supported yet"  
428 -#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */  
429 -  
430 -#elif defined(__s390__)  
431 -#define MD_STACK_GROWS_DOWN  
432 -  
433 -/* There is no JB_SP in glibc at this time. (glibc 2.2.5)  
434 - */  
435 -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__gregs[9]  
436 -  
437 -#elif defined(__hppa__)  
438 -#define MD_STACK_GROWS_UP  
439 -  
440 -/* yes, this is gross, unfortunately at the moment (2002/08/01) there is  
441 - * a bug in hppa's glibc header definition for JB_SP, so we can't  
442 - * use that...  
443 - */  
444 -#define MD_GET_SP(_t) (*(long *)(((char *)&(_t)->context[0].__jmpbuf[0]) + 76))  
445 -  
446 -#else  
447 -#error "Unknown CPU architecture"  
448 -#endif /* Cases with common MD_INIT_CONTEXT and different SP locations */  
449 -  
450 -#define MD_INIT_CONTEXT(_thread, _sp, _main) \  
451 - ST_BEGIN_MACRO \  
452 - if (MD_SETJMP((_thread)->context)) \  
453 - _main(); \  
454 - MD_GET_SP(_thread) = (long) (_sp); \  
455 - ST_END_MACRO  
456 -  
457 -#endif /* Cases with different MD_INIT_CONTEXT */  
458 -  
459 -#if defined(MD_USE_BUILTIN_SETJMP) && !defined(USE_LIBC_SETJMP)  
460 -#define MD_SETJMP(env) _st_md_cxt_save(env)  
461 -#define MD_LONGJMP(env, val) _st_md_cxt_restore(env, val)  
462 -  
463 -extern int _st_md_cxt_save(jmp_buf env);  
464 -extern void _st_md_cxt_restore(jmp_buf env, int val);  
465 -#else  
466 -#define MD_SETJMP(env) setjmp(env)  
467 -#define MD_LONGJMP(env, val) longjmp(env, val)  
468 -#endif 259 + /*
  260 + * These are properties of the linux kernel and are the same on every
  261 + * flavor and architecture.
  262 + */
  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
  270 +
  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__)
  281 + #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 +
  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__)
  309 + #define MD_STACK_GROWS_DOWN
  310 +
  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
  351 +
  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
  361 + #endif
  362 + #elif defined(__mc68000__)
  363 + #define MD_STACK_GROWS_DOWN
  364 +
  365 + /* m68k still uses old style sigjmp_buf */
  366 + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__sp
  367 + #elif defined(__sparc__)
  368 + #define MD_STACK_GROWS_DOWN
  369 +
  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))
  424 + #else
  425 + #error "Unknown CPU architecture"
  426 + #endif /* Cases with common MD_INIT_CONTEXT and different SP locations */
  427 +
  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)
  439 +
  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
469 446
470 #elif defined (NETBSD) 447 #elif defined (NETBSD)
471 -  
472 -#define MD_STACK_GROWS_DOWN  
473 -#define MD_USE_BSD_ANON_MMAP  
474 -#define MD_ACCEPT_NB_INHERITED  
475 -#define MD_ALWAYS_UNSERIALIZED_ACCEPT  
476 -#define MD_HAVE_SOCKLEN_T  
477 -  
478 -#define MD_SETJMP(env) _setjmp(env)  
479 -#define MD_LONGJMP(env, val) _longjmp(env, val)  
480 -  
481 -#if defined(__i386__)  
482 -#define MD_JB_SP 2  
483 -#elif defined(__alpha__)  
484 -#define MD_JB_SP 34  
485 -#elif defined(__sparc__)  
486 -#define MD_JB_SP 0  
487 -#elif defined(__vax__)  
488 -#define MD_JB_SP 2  
489 -#else  
490 -#error Unknown CPU architecture  
491 -#endif  
492 -  
493 -#define MD_INIT_CONTEXT(_thread, _sp, _main) \  
494 - ST_BEGIN_MACRO \  
495 - if (MD_SETJMP((_thread)->context)) \  
496 - _main(); \  
497 - (_thread)->context[MD_JB_SP] = (long) (_sp); \  
498 - ST_END_MACRO  
499 -  
500 -#define MD_GET_UTIME() \  
501 - struct timeval tv; \  
502 - (void) gettimeofday(&tv, NULL); \  
503 - return (tv.tv_sec * 1000000LL + tv.tv_usec) 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)
504 480
505 #elif defined (OPENBSD) 481 #elif defined (OPENBSD)
506 -  
507 -#define MD_STACK_GROWS_DOWN  
508 -#define MD_USE_BSD_ANON_MMAP  
509 -#define MD_ACCEPT_NB_INHERITED  
510 -#define MD_ALWAYS_UNSERIALIZED_ACCEPT  
511 -  
512 -#define MD_SETJMP(env) _setjmp(env)  
513 -#define MD_LONGJMP(env, val) _longjmp(env, val)  
514 -  
515 -#if defined(__i386__)  
516 -#define MD_JB_SP 2  
517 -#elif defined(__alpha__)  
518 -#define MD_JB_SP 34  
519 -#elif defined(__sparc__)  
520 -#define MD_JB_SP 0  
521 -#elif defined(__amd64__)  
522 -#define MD_JB_SP 6  
523 -#else  
524 -#error Unknown CPU architecture  
525 -#endif  
526 -  
527 -#define MD_INIT_CONTEXT(_thread, _sp, _main) \  
528 - ST_BEGIN_MACRO \  
529 - if (MD_SETJMP((_thread)->context)) \  
530 - _main(); \  
531 - (_thread)->context[MD_JB_SP] = (long) (_sp); \  
532 - ST_END_MACRO  
533 -  
534 -#define MD_GET_UTIME() \  
535 - struct timeval tv; \  
536 - (void) gettimeofday(&tv, NULL); \  
537 - return (tv.tv_sec * 1000000LL + tv.tv_usec) 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
  498 + #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)
538 513
539 #elif defined (OSF1) 514 #elif defined (OSF1)
540 -  
541 -#include <signal.h>  
542 -  
543 -#define MD_STACK_GROWS_DOWN  
544 -#define MD_USE_SYSV_ANON_MMAP  
545 -#define MD_ACCEPT_NB_NOT_INHERITED  
546 -#define MD_ALWAYS_UNSERIALIZED_ACCEPT  
547 -  
548 -#define MD_SETJMP(env) _setjmp(env)  
549 -#define MD_LONGJMP(env, val) _longjmp(env, val)  
550 -  
551 -#define MD_INIT_CONTEXT(_thread, _sp, _main) \  
552 - ST_BEGIN_MACRO \  
553 - if (MD_SETJMP((_thread)->context)) \  
554 - _main(); \  
555 - ((struct sigcontext *)((_thread)->context))->sc_sp = (long) (_sp); \  
556 - ST_END_MACRO  
557 -  
558 -#define MD_GET_UTIME() \  
559 - struct timeval tv; \  
560 - (void) gettimeofday(&tv, NULL); \  
561 - return (tv.tv_sec * 1000000LL + tv.tv_usec) 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
  521 +
  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); \
  530 + 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)
562 536
563 #elif defined (SOLARIS) 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
  544 +
  545 + #define MD_SETJMP(env) setjmp(env)
  546 + #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)
564 578
565 -#include <sys/filio.h>  
566 -extern int getpagesize(void);  
567 -  
568 -#define MD_STACK_GROWS_DOWN  
569 -#define MD_USE_SYSV_ANON_MMAP  
570 -#define MD_ACCEPT_NB_NOT_INHERITED  
571 -  
572 -#define MD_SETJMP(env) setjmp(env)  
573 -#define MD_LONGJMP(env, val) longjmp(env, val)  
574 -  
575 -#if defined(sparc) || defined(__sparc)  
576 -#ifdef _LP64  
577 -#define MD_STACK_PAD_SIZE 4095  
578 -#endif  
579 -#define MD_INIT_CONTEXT(_thread, _sp, _main) \  
580 - ST_BEGIN_MACRO \  
581 - (void) MD_SETJMP((_thread)->context); \  
582 - (_thread)->context[1] = (long) (_sp); \  
583 - (_thread)->context[2] = (long) _main; \  
584 - ST_END_MACRO  
585 -#elif defined(i386) || defined(__i386)  
586 -#define MD_INIT_CONTEXT(_thread, _sp, _main) \  
587 - ST_BEGIN_MACRO \  
588 - (void) MD_SETJMP((_thread)->context); \  
589 - (_thread)->context[4] = (long) (_sp); \  
590 - (_thread)->context[5] = (long) _main; \  
591 - ST_END_MACRO  
592 -#elif defined(__amd64__)  
593 -#define MD_INIT_CONTEXT(_thread, _sp, _main) \  
594 - ST_BEGIN_MACRO \  
595 - if (MD_SETJMP((_thread)->context)) \  
596 - _main(); \  
597 - (_thread)->context[6] = (long) (_sp); \  
598 - ST_END_MACRO  
599 #else 579 #else
600 -#error Unknown CPU architecture  
601 -#endif  
602 -  
603 -#define MD_GET_UTIME() \  
604 - return (gethrtime() / 1000)  
605 -  
606 -#else  
607 -#error Unknown OS 580 + #error Unknown OS
608 #endif /* OS */ 581 #endif /* OS */
609 582
  583 +/*****************************************
  584 + * Other defines
  585 + */
610 #if !defined(MD_HAVE_POLL) && !defined(MD_DONT_HAVE_POLL) 586 #if !defined(MD_HAVE_POLL) && !defined(MD_DONT_HAVE_POLL)
611 -#define MD_HAVE_POLL 587 + #define MD_HAVE_POLL
612 #endif 588 #endif
613 589
614 #ifndef MD_STACK_PAD_SIZE 590 #ifndef MD_STACK_PAD_SIZE
615 -#define MD_STACK_PAD_SIZE 128 591 + #define MD_STACK_PAD_SIZE 128
616 #endif 592 #endif
617 593
618 #if !defined(MD_HAVE_SOCKLEN_T) && !defined(socklen_t) 594 #if !defined(MD_HAVE_SOCKLEN_T) && !defined(socklen_t)
619 -#define socklen_t int 595 + #define socklen_t int
620 #endif 596 #endif
621 597
622 #ifndef MD_CAP_STACK 598 #ifndef MD_CAP_STACK
623 -#define MD_CAP_STACK(var_addr) 599 + #define MD_CAP_STACK(var_addr)
624 #endif 600 #endif
625 601
626 #endif /* !__ST_MD_H__ */ 602 #endif /* !__ST_MD_H__ */
@@ -129,8 +129,7 @@ extern "C" { @@ -129,8 +129,7 @@ extern "C" {
129 extern void st_netfd_free(st_netfd_t fd); 129 extern void st_netfd_free(st_netfd_t fd);
130 extern int st_netfd_close(st_netfd_t fd); 130 extern int st_netfd_close(st_netfd_t fd);
131 extern int st_netfd_fileno(st_netfd_t fd); 131 extern int st_netfd_fileno(st_netfd_t fd);
132 - extern void st_netfd_setspecific(st_netfd_t fd, void *value,  
133 - void (*destructor)(void *)); 132 + extern void st_netfd_setspecific(st_netfd_t fd, void *value, void (*destructor)(void *));
134 extern void *st_netfd_getspecific(st_netfd_t fd); 133 extern void *st_netfd_getspecific(st_netfd_t fd);
135 extern int st_netfd_serialize_accept(st_netfd_t fd); 134 extern int st_netfd_serialize_accept(st_netfd_t fd);
136 extern int st_netfd_poll(st_netfd_t fd, int how, st_utime_t timeout); 135 extern int st_netfd_poll(st_netfd_t fd, int how, st_utime_t timeout);