From 856ba07bd3596b843be58786019ccf7646127f89 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 5 Nov 2014 17:22:36 +0800 Subject: [PATCH 1/2] research st: update public and common. --- trunk/research/st/common.h | 227 ++++++++++++++++++------------------- trunk/research/st/md.h | 58 +++++----- trunk/research/st/public.h | 3 +- 3 files changed, 140 insertions(+), 148 deletions(-) diff --git a/trunk/research/st/common.h b/trunk/research/st/common.h index f22b7cb91..880b4f139 100644 --- a/trunk/research/st/common.h +++ b/trunk/research/st/common.h @@ -50,7 +50,7 @@ /* Enable assertions only if DEBUG is defined */ #ifndef DEBUG -#define NDEBUG + #define NDEBUG #endif #include #define ST_ASSERT(expr) assert(expr) @@ -59,22 +59,21 @@ #define ST_END_MACRO } #ifdef DEBUG -#define ST_HIDDEN /*nothing*/ + #define ST_HIDDEN /*nothing*/ #else -#define ST_HIDDEN static + #define ST_HIDDEN static #endif #include "public.h" #include "md.h" - /***************************************** * Circular linked list definitions */ typedef struct _st_clist { - struct _st_clist *next; - struct _st_clist *prev; + struct _st_clist *next; + struct _st_clist *prev; } _st_clist_t; /* Insert element "_e" into the list, before "_l" */ @@ -137,114 +136,113 @@ typedef struct _st_clist { typedef void (*_st_destructor_t)(void *); - typedef struct _st_stack { - _st_clist_t links; - char *vaddr; /* Base of stack's allocated memory */ - int vaddr_size; /* Size of stack's allocated memory */ - int stk_size; /* Size of usable portion of the stack */ - char *stk_bottom; /* Lowest address of stack's usable portion */ - char *stk_top; /* Highest address of stack's usable portion */ - void *sp; /* Stack pointer from C's point of view */ -#ifdef __ia64__ - void *bsp; /* Register stack backing store pointer */ -#endif + _st_clist_t links; + char *vaddr; /* Base of stack's allocated memory */ + int vaddr_size; /* Size of stack's allocated memory */ + int stk_size; /* Size of usable portion of the stack */ + char *stk_bottom; /* Lowest address of stack's usable portion */ + char *stk_top; /* Highest address of stack's usable portion */ + void *sp; /* Stack pointer from C's point of view */ + #ifdef __ia64__ + void *bsp; /* Register stack backing store pointer */ + #endif } _st_stack_t; typedef struct _st_cond { - _st_clist_t wait_q; /* Condition variable wait queue */ + _st_clist_t wait_q; /* Condition variable wait queue */ } _st_cond_t; typedef struct _st_thread _st_thread_t; struct _st_thread { - int state; /* Thread's state */ - int flags; /* Thread's flags */ - - void *(*start)(void *arg); /* The start function of the thread */ - void *arg; /* Argument of the start function */ - void *retval; /* Return value of the start function */ - - _st_stack_t *stack; /* Info about thread's stack */ - - _st_clist_t links; /* For putting on run/sleep/zombie queue */ - _st_clist_t wait_links; /* For putting on mutex/condvar wait queue */ -#ifdef DEBUG - _st_clist_t tlink; /* For putting on thread queue */ -#endif - - st_utime_t due; /* Wakeup time when thread is sleeping */ - _st_thread_t *left; /* For putting in timeout heap */ - _st_thread_t *right; /* -- see docs/timeout_heap.txt for details */ - int heap_index; - - void **private_data; /* Per thread private data */ - - _st_cond_t *term; /* Termination condition variable for join */ - - jmp_buf context; /* Thread's context */ + int state; /* Thread's state */ + int flags; /* Thread's flags */ + + void *(*start)(void *arg); /* The start function of the thread */ + void *arg; /* Argument of the start function */ + void *retval; /* Return value of the start function */ + + _st_stack_t *stack; /* Info about thread's stack */ + + _st_clist_t links; /* For putting on run/sleep/zombie queue */ + _st_clist_t wait_links; /* For putting on mutex/condvar wait queue */ + #ifdef DEBUG + _st_clist_t tlink; /* For putting on thread queue */ + #endif + + st_utime_t due; /* Wakeup time when thread is sleeping */ + _st_thread_t *left; /* For putting in timeout heap */ + _st_thread_t *right; /* -- see docs/timeout_heap.txt for details */ + int heap_index; + + void **private_data; /* Per thread private data */ + + _st_cond_t *term; /* Termination condition variable for join */ + + jmp_buf context; /* Thread's context */ }; typedef struct _st_mutex { - _st_thread_t *owner; /* Current mutex owner */ - _st_clist_t wait_q; /* Mutex wait queue */ + _st_thread_t *owner; /* Current mutex owner */ + _st_clist_t wait_q; /* Mutex wait queue */ } _st_mutex_t; typedef struct _st_pollq { - _st_clist_t links; /* For putting on io queue */ - _st_thread_t *thread; /* Polling thread */ - struct pollfd *pds; /* Array of poll descriptors */ - int npds; /* Length of the array */ - int on_ioq; /* Is it on ioq? */ + _st_clist_t links; /* For putting on io queue */ + _st_thread_t *thread; /* Polling thread */ + struct pollfd *pds; /* Array of poll descriptors */ + int npds; /* Length of the array */ + int on_ioq; /* Is it on ioq? */ } _st_pollq_t; typedef struct _st_eventsys_ops { - const char *name; /* Name of this event system */ - int val; /* Type of this event system */ - int (*init)(void); /* Initialization */ - void (*dispatch)(void); /* Dispatch function */ - int (*pollset_add)(struct pollfd *, int); /* Add descriptor set */ - void (*pollset_del)(struct pollfd *, int); /* Delete descriptor set */ - int (*fd_new)(int); /* New descriptor allocated */ - int (*fd_close)(int); /* Descriptor closed */ - int (*fd_getlimit)(void); /* Descriptor hard limit */ + const char *name; /* Name of this event system */ + int val; /* Type of this event system */ + int (*init)(void); /* Initialization */ + void (*dispatch)(void); /* Dispatch function */ + int (*pollset_add)(struct pollfd *, int); /* Add descriptor set */ + void (*pollset_del)(struct pollfd *, int); /* Delete descriptor set */ + int (*fd_new)(int); /* New descriptor allocated */ + int (*fd_close)(int); /* Descriptor closed */ + int (*fd_getlimit)(void); /* Descriptor hard limit */ } _st_eventsys_t; typedef struct _st_vp { - _st_thread_t *idle_thread; /* Idle thread for this vp */ - st_utime_t last_clock; /* The last time we went into vp_check_clock() */ - - _st_clist_t run_q; /* run queue for this vp */ - _st_clist_t io_q; /* io queue for this vp */ - _st_clist_t zombie_q; /* zombie queue for this vp */ -#ifdef DEBUG - _st_clist_t thread_q; /* all threads of this vp */ -#endif - int pagesize; - - _st_thread_t *sleep_q; /* sleep queue for this vp */ - int sleepq_size; /* number of threads on sleep queue */ - -#ifdef ST_SWITCH_CB - st_switch_cb_t switch_out_cb; /* called when a thread is switched out */ - st_switch_cb_t switch_in_cb; /* called when a thread is switched in */ -#endif + _st_thread_t *idle_thread; /* Idle thread for this vp */ + st_utime_t last_clock; /* The last time we went into vp_check_clock() */ + + _st_clist_t run_q; /* run queue for this vp */ + _st_clist_t io_q; /* io queue for this vp */ + _st_clist_t zombie_q; /* zombie queue for this vp */ + #ifdef DEBUG + _st_clist_t thread_q; /* all threads of this vp */ + #endif + int pagesize; + + _st_thread_t *sleep_q; /* sleep queue for this vp */ + int sleepq_size; /* number of threads on sleep queue */ + + #ifdef ST_SWITCH_CB + st_switch_cb_t switch_out_cb; /* called when a thread is switched out */ + st_switch_cb_t switch_in_cb; /* called when a thread is switched in */ + #endif } _st_vp_t; typedef struct _st_netfd { - int osfd; /* Underlying OS file descriptor */ - int inuse; /* In-use flag */ - void *private_data; /* Per descriptor private data */ - _st_destructor_t destructor; /* Private data destructor function */ - void *aux_data; /* Auxiliary data for internal use */ - struct _st_netfd *next; /* For putting on the free list */ + int osfd; /* Underlying OS file descriptor */ + int inuse; /* In-use flag */ + void *private_data; /* Per descriptor private data */ + _st_destructor_t destructor; /* Private data destructor function */ + void *aux_data; /* Auxiliary data for internal use */ + struct _st_netfd *next; /* For putting on the free list */ } _st_netfd_t; @@ -265,7 +263,7 @@ extern _st_eventsys_t *_st_eventsys; #define _ST_IOQ (_st_this_vp.io_q) #define _ST_ZOMBIEQ (_st_this_vp.zombie_q) #ifdef DEBUG -#define _ST_THREADQ (_st_this_vp.thread_q) + #define _ST_THREADQ (_st_this_vp.thread_q) #endif #define _ST_PAGE_SIZE (_st_this_vp.pagesize) @@ -293,8 +291,8 @@ extern _st_eventsys_t *_st_eventsys; #define _ST_DEL_ZOMBIEQ(_thr) ST_REMOVE_LINK(&(_thr)->links) #ifdef DEBUG -#define _ST_ADD_THREADQ(_thr) ST_APPEND_LINK(&(_thr)->tlink, &_ST_THREADQ) -#define _ST_DEL_THREADQ(_thr) ST_REMOVE_LINK(&(_thr)->tlink) + #define _ST_ADD_THREADQ(_thr) ST_APPEND_LINK(&(_thr)->tlink, &_ST_THREADQ) + #define _ST_DEL_THREADQ(_thr) ST_REMOVE_LINK(&(_thr)->tlink) #endif @@ -317,13 +315,12 @@ extern _st_eventsys_t *_st_eventsys; #define _ST_FL_INTERRUPT 0x08 #define _ST_FL_TIMEDOUT 0x10 - /***************************************** * Pointer conversion */ #ifndef offsetof -#define offsetof(type, identifier) ((size_t)&(((type *)0)->identifier)) + #define offsetof(type, identifier) ((size_t)&(((type *)0)->identifier)) #endif #define _ST_THREAD_PTR(_qp) \ @@ -339,8 +336,8 @@ extern _st_eventsys_t *_st_eventsys; ((_st_pollq_t *)((char *)(_qp) - offsetof(_st_pollq_t, links))) #ifdef DEBUG -#define _ST_THREAD_THREADQ_PTR(_qp) \ - ((_st_thread_t *)((char *)(_qp) - offsetof(_st_thread_t, tlink))) + #define _ST_THREAD_THREADQ_PTR(_qp) \ + ((_st_thread_t *)((char *)(_qp) - offsetof(_st_thread_t, tlink))) #endif @@ -349,21 +346,21 @@ extern _st_eventsys_t *_st_eventsys; */ #ifndef ST_UTIME_NO_TIMEOUT -#define ST_UTIME_NO_TIMEOUT ((st_utime_t) -1LL) + #define ST_UTIME_NO_TIMEOUT ((st_utime_t) -1LL) #endif #ifndef __ia64__ -#define ST_DEFAULT_STACK_SIZE (64*1024) + #define ST_DEFAULT_STACK_SIZE (64*1024) #else -#define ST_DEFAULT_STACK_SIZE (128*1024) /* Includes register stack size */ + #define ST_DEFAULT_STACK_SIZE (128*1024) /* Includes register stack size */ #endif #ifndef ST_KEYS_MAX -#define ST_KEYS_MAX 16 + #define ST_KEYS_MAX 16 #endif #ifndef ST_MIN_POLLFDS_SIZE -#define ST_MIN_POLLFDS_SIZE 64 + #define ST_MIN_POLLFDS_SIZE 64 #endif @@ -372,28 +369,28 @@ extern _st_eventsys_t *_st_eventsys; */ #ifdef DEBUG -void _st_iterate_threads(void); -#define ST_DEBUG_ITERATE_THREADS() _st_iterate_threads() + void _st_iterate_threads(void); + #define ST_DEBUG_ITERATE_THREADS() _st_iterate_threads() #else -#define ST_DEBUG_ITERATE_THREADS() + #define ST_DEBUG_ITERATE_THREADS() #endif #ifdef ST_SWITCH_CB -#define ST_SWITCH_OUT_CB(_thread) \ - if (_st_this_vp.switch_out_cb != NULL && \ + #define ST_SWITCH_OUT_CB(_thread) \ + if (_st_this_vp.switch_out_cb != NULL && \ + _thread != _st_this_vp.idle_thread && \ + _thread->state != _ST_ST_ZOMBIE) { \ + _st_this_vp.switch_out_cb(); \ + } + #define ST_SWITCH_IN_CB(_thread) \ + if (_st_this_vp.switch_in_cb != NULL && \ _thread != _st_this_vp.idle_thread && \ _thread->state != _ST_ST_ZOMBIE) { \ - _st_this_vp.switch_out_cb(); \ - } -#define ST_SWITCH_IN_CB(_thread) \ - if (_st_this_vp.switch_in_cb != NULL && \ - _thread != _st_this_vp.idle_thread && \ - _thread->state != _ST_ST_ZOMBIE) { \ - _st_this_vp.switch_in_cb(); \ - } + _st_this_vp.switch_in_cb(); \ + } #else -#define ST_SWITCH_OUT_CB(_thread) -#define ST_SWITCH_IN_CB(_thread) + #define ST_SWITCH_OUT_CB(_thread) + #define ST_SWITCH_IN_CB(_thread) #endif /* @@ -424,9 +421,9 @@ void _st_iterate_threads(void); * Initialize the thread context preparing it to execute _main */ #ifdef MD_INIT_CONTEXT -#define _ST_INIT_CONTEXT MD_INIT_CONTEXT + #define _ST_INIT_CONTEXT MD_INIT_CONTEXT #else -#error Unknown OS + #error Unknown OS #endif /* @@ -456,11 +453,9 @@ int st_cond_destroy(_st_cond_t *cvar); int st_cond_timedwait(_st_cond_t *cvar, st_utime_t timeout); int st_cond_signal(_st_cond_t *cvar); ssize_t st_read(_st_netfd_t *fd, void *buf, size_t nbyte, st_utime_t timeout); -ssize_t st_write(_st_netfd_t *fd, const void *buf, size_t nbyte, - st_utime_t timeout); +ssize_t st_write(_st_netfd_t *fd, const void *buf, size_t nbyte, st_utime_t timeout); int st_poll(struct pollfd *pds, int npds, st_utime_t timeout); -_st_thread_t *st_thread_create(void *(*start)(void *arg), void *arg, - int joinable, int stk_size); +_st_thread_t *st_thread_create(void *(*start)(void *arg), void *arg, int joinable, int stk_size); #endif /* !__ST_COMMON_H__ */ diff --git a/trunk/research/st/md.h b/trunk/research/st/md.h index 5bf795f24..61a0fac96 100644 --- a/trunk/research/st/md.h +++ b/trunk/research/st/md.h @@ -43,15 +43,15 @@ #define __ST_MD_H__ #if defined(ETIMEDOUT) && !defined(ETIME) -#define ETIME ETIMEDOUT + #define ETIME ETIMEDOUT #endif #if defined(MAP_ANONYMOUS) && !defined(MAP_ANON) -#define MAP_ANON MAP_ANONYMOUS + #define MAP_ANON MAP_ANONYMOUS #endif #ifndef MAP_FAILED -#define MAP_FAILED -1 + #define MAP_FAILED -1 #endif /***************************************** @@ -59,35 +59,33 @@ */ #if defined (AIX) - -#define MD_STACK_GROWS_DOWN -#define MD_USE_SYSV_ANON_MMAP -#define MD_ACCEPT_NB_INHERITED -#define MD_ALWAYS_UNSERIALIZED_ACCEPT - -#ifndef MD_HAVE_SOCKLEN_T -#define MD_HAVE_SOCKLEN_T -#define socklen_t unsigned long -#endif - -#define MD_SETJMP(env) _setjmp(env) -#define MD_LONGJMP(env, val) _longjmp(env, val) - -#define MD_INIT_CONTEXT(_thread, _sp, _main) \ - ST_BEGIN_MACRO \ - if (MD_SETJMP((_thread)->context)) \ - _main(); \ - (_thread)->context[3] = (long) (_sp); \ - ST_END_MACRO - -#define MD_GET_UTIME() \ - timebasestruct_t rt; \ - (void) read_real_time(&rt, TIMEBASE_SZ); \ - (void) time_base_to_time(&rt, TIMEBASE_SZ); \ - return (rt.tb_high * 1000000LL + rt.tb_low / 1000) + #define MD_STACK_GROWS_DOWN + #define MD_USE_SYSV_ANON_MMAP + #define MD_ACCEPT_NB_INHERITED + #define MD_ALWAYS_UNSERIALIZED_ACCEPT + + #ifndef MD_HAVE_SOCKLEN_T + #define MD_HAVE_SOCKLEN_T + #define socklen_t unsigned long + #endif + + #define MD_SETJMP(env) _setjmp(env) + #define MD_LONGJMP(env, val) _longjmp(env, val) + + #define MD_INIT_CONTEXT(_thread, _sp, _main) \ + ST_BEGIN_MACRO \ + if (MD_SETJMP((_thread)->context)) \ + _main(); \ + (_thread)->context[3] = (long) (_sp); \ + ST_END_MACRO + + #define MD_GET_UTIME() \ + timebasestruct_t rt; \ + (void) read_real_time(&rt, TIMEBASE_SZ); \ + (void) time_base_to_time(&rt, TIMEBASE_SZ); \ + return (rt.tb_high * 1000000LL + rt.tb_low / 1000) #elif defined (CYGWIN) - #define MD_STACK_GROWS_DOWN #define MD_USE_BSD_ANON_MMAP #define MD_ACCEPT_NB_NOT_INHERITED diff --git a/trunk/research/st/public.h b/trunk/research/st/public.h index 8c2ce8b8d..e306e3e8c 100644 --- a/trunk/research/st/public.h +++ b/trunk/research/st/public.h @@ -129,8 +129,7 @@ extern "C" { extern void st_netfd_free(st_netfd_t fd); extern int st_netfd_close(st_netfd_t fd); extern int st_netfd_fileno(st_netfd_t fd); - extern void st_netfd_setspecific(st_netfd_t fd, void *value, - void (*destructor)(void *)); + extern void st_netfd_setspecific(st_netfd_t fd, void *value, void (*destructor)(void *)); extern void *st_netfd_getspecific(st_netfd_t fd); extern int st_netfd_serialize_accept(st_netfd_t fd); extern int st_netfd_poll(st_netfd_t fd, int how, st_utime_t timeout); From 0f293802c80da5d6dab26620a809ca6417d9d501 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 5 Nov 2014 17:42:57 +0800 Subject: [PATCH 2/2] research st: refine the md.h --- trunk/research/st/md.h | 964 ++++++++++++++++++++--------------------- 1 file changed, 471 insertions(+), 493 deletions(-) diff --git a/trunk/research/st/md.h b/trunk/research/st/md.h index 61a0fac96..3b6acc5a5 100644 --- a/trunk/research/st/md.h +++ b/trunk/research/st/md.h @@ -57,7 +57,6 @@ /***************************************** * Platform specifics */ - #if defined (AIX) #define MD_STACK_GROWS_DOWN #define MD_USE_SYSV_ANON_MMAP @@ -86,539 +85,518 @@ return (rt.tb_high * 1000000LL + rt.tb_low / 1000) #elif defined (CYGWIN) -#define MD_STACK_GROWS_DOWN -#define MD_USE_BSD_ANON_MMAP -#define MD_ACCEPT_NB_NOT_INHERITED -#define MD_ALWAYS_UNSERIALIZED_ACCEPT - -#define MD_SETJMP(env) setjmp(env) -#define MD_LONGJMP(env, val) longjmp(env, val) - -#define MD_JB_SP 7 - -#define MD_GET_SP(_t) (_t)->context[MD_JB_SP] + #define MD_STACK_GROWS_DOWN + #define MD_USE_BSD_ANON_MMAP + #define MD_ACCEPT_NB_NOT_INHERITED + #define MD_ALWAYS_UNSERIALIZED_ACCEPT + + #define MD_SETJMP(env) setjmp(env) + #define MD_LONGJMP(env, val) longjmp(env, val) + + #define MD_JB_SP 7 + + #define MD_GET_SP(_t) (_t)->context[MD_JB_SP] -#define MD_INIT_CONTEXT(_thread, _sp, _main) \ - ST_BEGIN_MACRO \ - if (MD_SETJMP((_thread)->context)) \ - _main(); \ - MD_GET_SP(_thread) = (long) (_sp); \ - ST_END_MACRO + #define MD_INIT_CONTEXT(_thread, _sp, _main) \ + ST_BEGIN_MACRO \ + if (MD_SETJMP((_thread)->context)) \ + _main(); \ + MD_GET_SP(_thread) = (long) (_sp); \ + ST_END_MACRO -#define MD_GET_UTIME() \ - struct timeval tv; \ - (void) gettimeofday(&tv, NULL); \ - return (tv.tv_sec * 1000000LL + tv.tv_usec) + #define MD_GET_UTIME() \ + struct timeval tv; \ + (void) gettimeofday(&tv, NULL); \ + return (tv.tv_sec * 1000000LL + tv.tv_usec) #elif defined (DARWIN) + #define MD_STACK_GROWS_DOWN + #define MD_USE_BSD_ANON_MMAP + #define MD_ACCEPT_NB_INHERITED + #define MD_ALWAYS_UNSERIALIZED_ACCEPT + #define MD_HAVE_SOCKLEN_T + + #define MD_SETJMP(env) _setjmp(env) + #define MD_LONGJMP(env, val) _longjmp(env, val) + + #if defined(__ppc__) + #define MD_JB_SP 0 + #elif defined(__i386__) + #define MD_JB_SP 9 + #elif defined(__x86_64__) + #define MD_JB_SP 4 + #else + #error Unknown CPU architecture + #endif -#define MD_STACK_GROWS_DOWN -#define MD_USE_BSD_ANON_MMAP -#define MD_ACCEPT_NB_INHERITED -#define MD_ALWAYS_UNSERIALIZED_ACCEPT -#define MD_HAVE_SOCKLEN_T - -#define MD_SETJMP(env) _setjmp(env) -#define MD_LONGJMP(env, val) _longjmp(env, val) - -#if defined(__ppc__) -#define MD_JB_SP 0 -#elif defined(__i386__) -#define MD_JB_SP 9 -#elif defined(__x86_64__) -#define MD_JB_SP 4 -#else -#error Unknown CPU architecture -#endif - -#define MD_INIT_CONTEXT(_thread, _sp, _main) \ - ST_BEGIN_MACRO \ - if (MD_SETJMP((_thread)->context)) \ - _main(); \ - *((long *)&((_thread)->context[MD_JB_SP])) = (long) (_sp); \ - ST_END_MACRO + #define MD_INIT_CONTEXT(_thread, _sp, _main) \ + ST_BEGIN_MACRO \ + if (MD_SETJMP((_thread)->context)) \ + _main(); \ + *((long *)&((_thread)->context[MD_JB_SP])) = (long) (_sp); \ + ST_END_MACRO -#define MD_GET_UTIME() \ - struct timeval tv; \ - (void) gettimeofday(&tv, NULL); \ - return (tv.tv_sec * 1000000LL + tv.tv_usec) + #define MD_GET_UTIME() \ + struct timeval tv; \ + (void) gettimeofday(&tv, NULL); \ + return (tv.tv_sec * 1000000LL + tv.tv_usec) #elif defined (FREEBSD) + #define MD_STACK_GROWS_DOWN + #define MD_USE_BSD_ANON_MMAP + #define MD_ACCEPT_NB_INHERITED + #define MD_ALWAYS_UNSERIALIZED_ACCEPT + + #define MD_SETJMP(env) _setjmp(env) + #define MD_LONGJMP(env, val) _longjmp(env, val) -#define MD_STACK_GROWS_DOWN -#define MD_USE_BSD_ANON_MMAP -#define MD_ACCEPT_NB_INHERITED -#define MD_ALWAYS_UNSERIALIZED_ACCEPT - -#define MD_SETJMP(env) _setjmp(env) -#define MD_LONGJMP(env, val) _longjmp(env, val) - -#if defined(__i386__) -#define MD_JB_SP 2 -#elif defined(__alpha__) -#define MD_JB_SP 34 -#elif defined(__amd64__) -#define MD_JB_SP 2 -#else -#error Unknown CPU architecture -#endif + #if defined(__i386__) + #define MD_JB_SP 2 + #elif defined(__alpha__) + #define MD_JB_SP 34 + #elif defined(__amd64__) + #define MD_JB_SP 2 + #else + #error Unknown CPU architecture + #endif -#define MD_INIT_CONTEXT(_thread, _sp, _main) \ - ST_BEGIN_MACRO \ - if (MD_SETJMP((_thread)->context)) \ - _main(); \ - (_thread)->context[0]._jb[MD_JB_SP] = (long) (_sp); \ - ST_END_MACRO + #define MD_INIT_CONTEXT(_thread, _sp, _main) \ + ST_BEGIN_MACRO \ + if (MD_SETJMP((_thread)->context)) \ + _main(); \ + (_thread)->context[0]._jb[MD_JB_SP] = (long) (_sp); \ + ST_END_MACRO -#define MD_GET_UTIME() \ - struct timeval tv; \ - (void) gettimeofday(&tv, NULL); \ - return (tv.tv_sec * 1000000LL + tv.tv_usec) + #define MD_GET_UTIME() \ + struct timeval tv; \ + (void) gettimeofday(&tv, NULL); \ + return (tv.tv_sec * 1000000LL + tv.tv_usec) #elif defined (HPUX) - -#define MD_STACK_GROWS_UP -#define MD_USE_BSD_ANON_MMAP -#define MD_ACCEPT_NB_INHERITED -#define MD_ALWAYS_UNSERIALIZED_ACCEPT - -#define MD_SETJMP(env) _setjmp(env) -#define MD_LONGJMP(env, val) _longjmp(env, val) - -#ifndef __LP64__ -/* 32-bit mode (ILP32 data model) */ -#define MD_INIT_CONTEXT(_thread, _sp, _main) \ - ST_BEGIN_MACRO \ - if (MD_SETJMP((_thread)->context)) \ - _main(); \ - ((long *)((_thread)->context))[1] = (long) (_sp); \ - ST_END_MACRO -#else -/* 64-bit mode (LP64 data model) */ -#define MD_STACK_PAD_SIZE 256 -/* Last stack frame must be preserved */ -#define MD_INIT_CONTEXT(_thread, _sp, _main) \ - ST_BEGIN_MACRO \ - if (MD_SETJMP((_thread)->context)) \ - _main(); \ - memcpy((char *)(_sp) - MD_STACK_PAD_SIZE, \ - ((char **)((_thread)->context))[1] - MD_STACK_PAD_SIZE, \ - MD_STACK_PAD_SIZE); \ - ((long *)((_thread)->context))[1] = (long) (_sp); \ - ST_END_MACRO -#endif /* !__LP64__ */ - -#define MD_GET_UTIME() \ - struct timeval tv; \ - (void) gettimeofday(&tv, NULL); \ - return (tv.tv_sec * 1000000LL + tv.tv_usec) + #define MD_STACK_GROWS_UP + #define MD_USE_BSD_ANON_MMAP + #define MD_ACCEPT_NB_INHERITED + #define MD_ALWAYS_UNSERIALIZED_ACCEPT + + #define MD_SETJMP(env) _setjmp(env) + #define MD_LONGJMP(env, val) _longjmp(env, val) + + #ifndef __LP64__ + /* 32-bit mode (ILP32 data model) */ + #define MD_INIT_CONTEXT(_thread, _sp, _main) \ + ST_BEGIN_MACRO \ + if (MD_SETJMP((_thread)->context)) \ + _main(); \ + ((long *)((_thread)->context))[1] = (long) (_sp); \ + ST_END_MACRO + #else + /* 64-bit mode (LP64 data model) */ + #define MD_STACK_PAD_SIZE 256 + /* Last stack frame must be preserved */ + #define MD_INIT_CONTEXT(_thread, _sp, _main) \ + ST_BEGIN_MACRO \ + if (MD_SETJMP((_thread)->context)) \ + _main(); \ + memcpy((char *)(_sp) - MD_STACK_PAD_SIZE, \ + ((char **)((_thread)->context))[1] - MD_STACK_PAD_SIZE, \ + MD_STACK_PAD_SIZE); \ + ((long *)((_thread)->context))[1] = (long) (_sp); \ + ST_END_MACRO + #endif /* !__LP64__ */ + + #define MD_GET_UTIME() \ + struct timeval tv; \ + (void) gettimeofday(&tv, NULL); \ + return (tv.tv_sec * 1000000LL + tv.tv_usec) #elif defined (IRIX) + #include + + #define MD_STACK_GROWS_DOWN + #define MD_USE_SYSV_ANON_MMAP + #define MD_ACCEPT_NB_INHERITED + #define MD_ALWAYS_UNSERIALIZED_ACCEPT + + #define MD_SETJMP(env) setjmp(env) + #define MD_LONGJMP(env, val) longjmp(env, val) -#include - -#define MD_STACK_GROWS_DOWN -#define MD_USE_SYSV_ANON_MMAP -#define MD_ACCEPT_NB_INHERITED -#define MD_ALWAYS_UNSERIALIZED_ACCEPT - -#define MD_SETJMP(env) setjmp(env) -#define MD_LONGJMP(env, val) longjmp(env, val) - -#define MD_INIT_CONTEXT(_thread, _sp, _main) \ - ST_BEGIN_MACRO \ - (void) MD_SETJMP((_thread)->context); \ - (_thread)->context[JB_SP] = (long) (_sp); \ - (_thread)->context[JB_PC] = (long) _main; \ - ST_END_MACRO - -#define MD_GET_UTIME() \ - static int inited = 0; \ - static clockid_t clock_id = CLOCK_SGI_CYCLE; \ - struct timespec ts; \ - if (!inited) { \ - if (syssgi(SGI_CYCLECNTR_SIZE) < 64) \ - clock_id = CLOCK_REALTIME; \ - inited = 1; \ - } \ - (void) clock_gettime(clock_id, &ts); \ - return (ts.tv_sec * 1000000LL + ts.tv_nsec / 1000) + #define MD_INIT_CONTEXT(_thread, _sp, _main) \ + ST_BEGIN_MACRO \ + (void) MD_SETJMP((_thread)->context); \ + (_thread)->context[JB_SP] = (long) (_sp); \ + (_thread)->context[JB_PC] = (long) _main; \ + ST_END_MACRO -/* - * Cap the stack by zeroing out the saved return address register - * value. This allows libexc, used by SpeedShop, to know when to stop - * backtracing since it won't find main, start, or any other known - * stack root function in a state thread's stack. Without this libexc - * traces right off the stack and crashes. - * The function preamble stores ra at 8(sp), this stores zero there. - * N.B. This macro is compiler/ABI dependent. It must change if ANY more - * automatic variables are added to the _st_thread_main() routine, because - * the address where ra is stored will change. - */ -#if !defined(__GNUC__) && defined(_MIPS_SIM) && _MIPS_SIM != _ABIO32 -#define MD_CAP_STACK(var_addr) \ - (((volatile __uint64_t *)(var_addr))[1] = 0) -#endif + #define MD_GET_UTIME() \ + static int inited = 0; \ + static clockid_t clock_id = CLOCK_SGI_CYCLE; \ + struct timespec ts; \ + if (!inited) { \ + if (syssgi(SGI_CYCLECNTR_SIZE) < 64) \ + clock_id = CLOCK_REALTIME; \ + inited = 1; \ + } \ + (void) clock_gettime(clock_id, &ts); \ + return (ts.tv_sec * 1000000LL + ts.tv_nsec / 1000) + + /* + * Cap the stack by zeroing out the saved return address register + * value. This allows libexc, used by SpeedShop, to know when to stop + * backtracing since it won't find main, start, or any other known + * stack root function in a state thread's stack. Without this libexc + * traces right off the stack and crashes. + * The function preamble stores ra at 8(sp), this stores zero there. + * N.B. This macro is compiler/ABI dependent. It must change if ANY more + * automatic variables are added to the _st_thread_main() routine, because + * the address where ra is stored will change. + */ + #if !defined(__GNUC__) && defined(_MIPS_SIM) && _MIPS_SIM != _ABIO32 + #define MD_CAP_STACK(var_addr) \ + (((volatile __uint64_t *)(var_addr))[1] = 0) + #endif #elif defined (LINUX) - -/* - * These are properties of the linux kernel and are the same on every - * flavor and architecture. - */ -#define MD_USE_BSD_ANON_MMAP -#define MD_ACCEPT_NB_NOT_INHERITED -#define MD_ALWAYS_UNSERIALIZED_ACCEPT -/* - * Modern GNU/Linux is Posix.1g compliant. - */ -#define MD_HAVE_SOCKLEN_T - -/* - * All architectures and flavors of linux have the gettimeofday - * function but if you know of a faster way, use it. - */ -#define MD_GET_UTIME() \ - struct timeval tv; \ - (void) gettimeofday(&tv, NULL); \ - return (tv.tv_sec * 1000000LL + tv.tv_usec) - -#if defined(__ia64__) -#define MD_STACK_GROWS_DOWN - -/* - * IA-64 architecture. Besides traditional memory call stack, IA-64 - * uses general register stack. Thus each thread needs a backing store - * for register stack in addition to memory stack. Standard - * setjmp()/longjmp() cannot be used for thread context switching - * because their implementation implicitly assumes that only one - * register stack exists. - */ -#ifdef USE_LIBC_SETJMP -#undef USE_LIBC_SETJMP -#endif -#define MD_USE_BUILTIN_SETJMP - -#define MD_STACK_PAD_SIZE 128 -/* Last register stack frame must be preserved */ -#define MD_INIT_CONTEXT(_thread, _sp, _bsp, _main) \ - ST_BEGIN_MACRO \ - if (MD_SETJMP((_thread)->context)) \ - _main(); \ - memcpy((char *)(_bsp) - MD_STACK_PAD_SIZE, \ - (char *)(_thread)->context[0].__jmpbuf[17] - MD_STACK_PAD_SIZE, \ - MD_STACK_PAD_SIZE); \ - (_thread)->context[0].__jmpbuf[0] = (long) (_sp); \ - (_thread)->context[0].__jmpbuf[17] = (long) (_bsp); \ - ST_END_MACRO - -#elif defined(__mips__) -#define MD_STACK_GROWS_DOWN - -#define MD_INIT_CONTEXT(_thread, _sp, _main) \ - ST_BEGIN_MACRO \ - MD_SETJMP((_thread)->context); \ - _thread->context[0].__jmpbuf[0].__pc = (__ptr_t) _main; \ - _thread->context[0].__jmpbuf[0].__sp = _sp; \ - ST_END_MACRO - -#else /* Not IA-64 or mips */ - -/* - * On linux, there are a few styles of jmpbuf format. These vary based - * on architecture/glibc combination. - * - * Most of the glibc based toggles were lifted from: - * mozilla/nsprpub/pr/include/md/_linux.h - */ - -/* - * Starting with glibc 2.4, JB_SP definitions are not public anymore. - * They, however, can still be found in glibc source tree in - * architecture-specific "jmpbuf-offsets.h" files. - * Most importantly, the content of jmp_buf is mangled by setjmp to make - * it completely opaque (the mangling can be disabled by setting the - * LD_POINTER_GUARD environment variable before application execution). - * Therefore we will use built-in _st_md_cxt_save/_st_md_cxt_restore - * functions as a setjmp/longjmp replacement wherever they are available - * unless USE_LIBC_SETJMP is defined. - */ - -#if defined(__powerpc__) -#define MD_STACK_GROWS_DOWN - -#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) -#ifndef JB_GPR1 -#define JB_GPR1 0 -#endif -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_GPR1] -#else -/* not an error but certainly cause for caution */ -#error "Untested use of old glibc on powerpc" -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__misc[0] -#endif /* glibc 2.1 or later */ - -#elif defined(__alpha) -#define MD_STACK_GROWS_DOWN - -#if defined(__GLIBC__) && __GLIBC__ >= 2 -#ifndef JB_SP -#define JB_SP 8 -#endif -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_SP] -#else -/* not an error but certainly cause for caution */ -#error "Untested use of old glibc on alpha" -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__sp -#endif - -#elif defined(__mc68000__) -#define MD_STACK_GROWS_DOWN - -/* m68k still uses old style sigjmp_buf */ -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__sp - -#elif defined(__sparc__) -#define MD_STACK_GROWS_DOWN - -#if defined(__GLIBC__) && __GLIBC__ >= 2 -#ifndef JB_SP -#define JB_SP 0 -#endif -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_SP] -#else -/* not an error but certainly cause for caution */ -#error "Untested use of old glic on sparc -- also using odd mozilla derived __fp" -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__fp -#endif - -#elif defined(__i386__) -#define MD_STACK_GROWS_DOWN -#define MD_USE_BUILTIN_SETJMP - -#if defined(__GLIBC__) && __GLIBC__ >= 2 -#ifndef JB_SP -#define JB_SP 4 -#endif -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_SP] -#else -/* not an error but certainly cause for caution */ -#error "Untested use of old glibc on i386" -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__sp -#endif - -#elif defined(__amd64__) || defined(__x86_64__) -#define MD_STACK_GROWS_DOWN -#define MD_USE_BUILTIN_SETJMP - -#ifndef JB_RSP -#define JB_RSP 6 -#endif -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_RSP] - -#elif defined(__arm__) -#define MD_STACK_GROWS_DOWN - -#if defined(__GLIBC__) && __GLIBC__ >= 2 -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[20] -#else -#error "ARM/Linux pre-glibc2 not supported yet" -#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ - -#elif defined(__s390__) -#define MD_STACK_GROWS_DOWN - -/* There is no JB_SP in glibc at this time. (glibc 2.2.5) - */ -#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__gregs[9] - -#elif defined(__hppa__) -#define MD_STACK_GROWS_UP - -/* yes, this is gross, unfortunately at the moment (2002/08/01) there is - * a bug in hppa's glibc header definition for JB_SP, so we can't - * use that... - */ -#define MD_GET_SP(_t) (*(long *)(((char *)&(_t)->context[0].__jmpbuf[0]) + 76)) - -#else -#error "Unknown CPU architecture" -#endif /* Cases with common MD_INIT_CONTEXT and different SP locations */ - -#define MD_INIT_CONTEXT(_thread, _sp, _main) \ - ST_BEGIN_MACRO \ - if (MD_SETJMP((_thread)->context)) \ - _main(); \ - MD_GET_SP(_thread) = (long) (_sp); \ - ST_END_MACRO - -#endif /* Cases with different MD_INIT_CONTEXT */ - -#if defined(MD_USE_BUILTIN_SETJMP) && !defined(USE_LIBC_SETJMP) -#define MD_SETJMP(env) _st_md_cxt_save(env) -#define MD_LONGJMP(env, val) _st_md_cxt_restore(env, val) - -extern int _st_md_cxt_save(jmp_buf env); -extern void _st_md_cxt_restore(jmp_buf env, int val); -#else -#define MD_SETJMP(env) setjmp(env) -#define MD_LONGJMP(env, val) longjmp(env, val) -#endif + /* + * These are properties of the linux kernel and are the same on every + * flavor and architecture. + */ + #define MD_USE_BSD_ANON_MMAP + #define MD_ACCEPT_NB_NOT_INHERITED + #define MD_ALWAYS_UNSERIALIZED_ACCEPT + /* + * Modern GNU/Linux is Posix.1g compliant. + */ + #define MD_HAVE_SOCKLEN_T + + /* + * All architectures and flavors of linux have the gettimeofday + * function but if you know of a faster way, use it. + */ + #define MD_GET_UTIME() \ + struct timeval tv; \ + (void) gettimeofday(&tv, NULL); \ + return (tv.tv_sec * 1000000LL + tv.tv_usec) + + #if defined(__ia64__) + #define MD_STACK_GROWS_DOWN + + /* + * IA-64 architecture. Besides traditional memory call stack, IA-64 + * uses general register stack. Thus each thread needs a backing store + * for register stack in addition to memory stack. Standard + * setjmp()/longjmp() cannot be used for thread context switching + * because their implementation implicitly assumes that only one + * register stack exists. + */ + #ifdef USE_LIBC_SETJMP + #undef USE_LIBC_SETJMP + #endif + #define MD_USE_BUILTIN_SETJMP + + #define MD_STACK_PAD_SIZE 128 + /* Last register stack frame must be preserved */ + #define MD_INIT_CONTEXT(_thread, _sp, _bsp, _main) \ + ST_BEGIN_MACRO \ + if (MD_SETJMP((_thread)->context)) \ + _main(); \ + memcpy((char *)(_bsp) - MD_STACK_PAD_SIZE, \ + (char *)(_thread)->context[0].__jmpbuf[17] - MD_STACK_PAD_SIZE, \ + MD_STACK_PAD_SIZE); \ + (_thread)->context[0].__jmpbuf[0] = (long) (_sp); \ + (_thread)->context[0].__jmpbuf[17] = (long) (_bsp); \ + ST_END_MACRO + #elif defined(__mips__) + #define MD_STACK_GROWS_DOWN + + #define MD_INIT_CONTEXT(_thread, _sp, _main) \ + ST_BEGIN_MACRO \ + MD_SETJMP((_thread)->context); \ + _thread->context[0].__jmpbuf[0].__pc = (__ptr_t) _main; \ + _thread->context[0].__jmpbuf[0].__sp = _sp; \ + ST_END_MACRO + #else /* Not IA-64 or mips */ + /* + * On linux, there are a few styles of jmpbuf format. These vary based + * on architecture/glibc combination. + * + * Most of the glibc based toggles were lifted from: + * mozilla/nsprpub/pr/include/md/_linux.h + */ + /* + * Starting with glibc 2.4, JB_SP definitions are not public anymore. + * They, however, can still be found in glibc source tree in + * architecture-specific "jmpbuf-offsets.h" files. + * Most importantly, the content of jmp_buf is mangled by setjmp to make + * it completely opaque (the mangling can be disabled by setting the + * LD_POINTER_GUARD environment variable before application execution). + * Therefore we will use built-in _st_md_cxt_save/_st_md_cxt_restore + * functions as a setjmp/longjmp replacement wherever they are available + * unless USE_LIBC_SETJMP is defined. + */ + #if defined(__powerpc__) + #define MD_STACK_GROWS_DOWN + + #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) + #ifndef JB_GPR1 + #define JB_GPR1 0 + #endif + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_GPR1] + #else + /* not an error but certainly cause for caution */ + #error "Untested use of old glibc on powerpc" + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__misc[0] + #endif /* glibc 2.1 or later */ + #elif defined(__alpha) + #define MD_STACK_GROWS_DOWN + + #if defined(__GLIBC__) && __GLIBC__ >= 2 + #ifndef JB_SP + #define JB_SP 8 + #endif + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_SP] + #else + /* not an error but certainly cause for caution */ + #error "Untested use of old glibc on alpha" + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__sp + #endif + #elif defined(__mc68000__) + #define MD_STACK_GROWS_DOWN + + /* m68k still uses old style sigjmp_buf */ + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__sp + #elif defined(__sparc__) + #define MD_STACK_GROWS_DOWN + + #if defined(__GLIBC__) && __GLIBC__ >= 2 + #ifndef JB_SP + #define JB_SP 0 + #endif + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_SP] + #else + /* not an error but certainly cause for caution */ + #error "Untested use of old glic on sparc -- also using odd mozilla derived __fp" + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__fp + #endif + #elif defined(__i386__) + #define MD_STACK_GROWS_DOWN + #define MD_USE_BUILTIN_SETJMP + + #if defined(__GLIBC__) && __GLIBC__ >= 2 + #ifndef JB_SP + #define JB_SP 4 + #endif + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_SP] + #else + /* not an error but certainly cause for caution */ + #error "Untested use of old glibc on i386" + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__sp + #endif + #elif defined(__amd64__) || defined(__x86_64__) + #define MD_STACK_GROWS_DOWN + #define MD_USE_BUILTIN_SETJMP + + #ifndef JB_RSP + #define JB_RSP 6 + #endif + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_RSP] + #elif defined(__arm__) + #define MD_STACK_GROWS_DOWN + + #if defined(__GLIBC__) && __GLIBC__ >= 2 + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[8] + #else + #error "ARM/Linux pre-glibc2 not supported yet" + #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ + #elif defined(__s390__) + #define MD_STACK_GROWS_DOWN + + /* There is no JB_SP in glibc at this time. (glibc 2.2.5) + */ + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__gregs[9] + #elif defined(__hppa__) + #define MD_STACK_GROWS_UP + + /* yes, this is gross, unfortunately at the moment (2002/08/01) there is + * a bug in hppa's glibc header definition for JB_SP, so we can't + * use that... + */ + #define MD_GET_SP(_t) (*(long *)(((char *)&(_t)->context[0].__jmpbuf[0]) + 76)) + #else + #error "Unknown CPU architecture" + #endif /* Cases with common MD_INIT_CONTEXT and different SP locations */ + + #define MD_INIT_CONTEXT(_thread, _sp, _main) \ + ST_BEGIN_MACRO \ + if (MD_SETJMP((_thread)->context)) \ + _main(); \ + MD_GET_SP(_thread) = (long) (_sp); \ + ST_END_MACRO + #endif /* Cases with different MD_INIT_CONTEXT */ + + #if defined(MD_USE_BUILTIN_SETJMP) && !defined(USE_LIBC_SETJMP) + #define MD_SETJMP(env) _st_md_cxt_save(env) + #define MD_LONGJMP(env, val) _st_md_cxt_restore(env, val) + + extern int _st_md_cxt_save(jmp_buf env); + extern void _st_md_cxt_restore(jmp_buf env, int val); + #else + #define MD_SETJMP(env) setjmp(env) + #define MD_LONGJMP(env, val) longjmp(env, val) + #endif #elif defined (NETBSD) - -#define MD_STACK_GROWS_DOWN -#define MD_USE_BSD_ANON_MMAP -#define MD_ACCEPT_NB_INHERITED -#define MD_ALWAYS_UNSERIALIZED_ACCEPT -#define MD_HAVE_SOCKLEN_T - -#define MD_SETJMP(env) _setjmp(env) -#define MD_LONGJMP(env, val) _longjmp(env, val) - -#if defined(__i386__) -#define MD_JB_SP 2 -#elif defined(__alpha__) -#define MD_JB_SP 34 -#elif defined(__sparc__) -#define MD_JB_SP 0 -#elif defined(__vax__) -#define MD_JB_SP 2 -#else -#error Unknown CPU architecture -#endif - -#define MD_INIT_CONTEXT(_thread, _sp, _main) \ - ST_BEGIN_MACRO \ - if (MD_SETJMP((_thread)->context)) \ - _main(); \ - (_thread)->context[MD_JB_SP] = (long) (_sp); \ - ST_END_MACRO - -#define MD_GET_UTIME() \ - struct timeval tv; \ - (void) gettimeofday(&tv, NULL); \ - return (tv.tv_sec * 1000000LL + tv.tv_usec) + #define MD_STACK_GROWS_DOWN + #define MD_USE_BSD_ANON_MMAP + #define MD_ACCEPT_NB_INHERITED + #define MD_ALWAYS_UNSERIALIZED_ACCEPT + #define MD_HAVE_SOCKLEN_T + + #define MD_SETJMP(env) _setjmp(env) + #define MD_LONGJMP(env, val) _longjmp(env, val) + + #if defined(__i386__) + #define MD_JB_SP 2 + #elif defined(__alpha__) + #define MD_JB_SP 34 + #elif defined(__sparc__) + #define MD_JB_SP 0 + #elif defined(__vax__) + #define MD_JB_SP 2 + #else + #error Unknown CPU architecture + #endif + + #define MD_INIT_CONTEXT(_thread, _sp, _main) \ + ST_BEGIN_MACRO \ + if (MD_SETJMP((_thread)->context)) \ + _main(); \ + (_thread)->context[MD_JB_SP] = (long) (_sp); \ + ST_END_MACRO + + #define MD_GET_UTIME() \ + struct timeval tv; \ + (void) gettimeofday(&tv, NULL); \ + return (tv.tv_sec * 1000000LL + tv.tv_usec) #elif defined (OPENBSD) - -#define MD_STACK_GROWS_DOWN -#define MD_USE_BSD_ANON_MMAP -#define MD_ACCEPT_NB_INHERITED -#define MD_ALWAYS_UNSERIALIZED_ACCEPT - -#define MD_SETJMP(env) _setjmp(env) -#define MD_LONGJMP(env, val) _longjmp(env, val) - -#if defined(__i386__) -#define MD_JB_SP 2 -#elif defined(__alpha__) -#define MD_JB_SP 34 -#elif defined(__sparc__) -#define MD_JB_SP 0 -#elif defined(__amd64__) -#define MD_JB_SP 6 -#else -#error Unknown CPU architecture -#endif - -#define MD_INIT_CONTEXT(_thread, _sp, _main) \ - ST_BEGIN_MACRO \ - if (MD_SETJMP((_thread)->context)) \ - _main(); \ - (_thread)->context[MD_JB_SP] = (long) (_sp); \ - ST_END_MACRO - -#define MD_GET_UTIME() \ - struct timeval tv; \ - (void) gettimeofday(&tv, NULL); \ - return (tv.tv_sec * 1000000LL + tv.tv_usec) + #define MD_STACK_GROWS_DOWN + #define MD_USE_BSD_ANON_MMAP + #define MD_ACCEPT_NB_INHERITED + #define MD_ALWAYS_UNSERIALIZED_ACCEPT + + #define MD_SETJMP(env) _setjmp(env) + #define MD_LONGJMP(env, val) _longjmp(env, val) + + #if defined(__i386__) + #define MD_JB_SP 2 + #elif defined(__alpha__) + #define MD_JB_SP 34 + #elif defined(__sparc__) + #define MD_JB_SP 0 + #elif defined(__amd64__) + #define MD_JB_SP 6 + #else + #error Unknown CPU architecture + #endif + + #define MD_INIT_CONTEXT(_thread, _sp, _main) \ + ST_BEGIN_MACRO \ + if (MD_SETJMP((_thread)->context)) \ + _main(); \ + (_thread)->context[MD_JB_SP] = (long) (_sp); \ + ST_END_MACRO + + #define MD_GET_UTIME() \ + struct timeval tv; \ + (void) gettimeofday(&tv, NULL); \ + return (tv.tv_sec * 1000000LL + tv.tv_usec) #elif defined (OSF1) - -#include - -#define MD_STACK_GROWS_DOWN -#define MD_USE_SYSV_ANON_MMAP -#define MD_ACCEPT_NB_NOT_INHERITED -#define MD_ALWAYS_UNSERIALIZED_ACCEPT - -#define MD_SETJMP(env) _setjmp(env) -#define MD_LONGJMP(env, val) _longjmp(env, val) - -#define MD_INIT_CONTEXT(_thread, _sp, _main) \ - ST_BEGIN_MACRO \ - if (MD_SETJMP((_thread)->context)) \ - _main(); \ - ((struct sigcontext *)((_thread)->context))->sc_sp = (long) (_sp); \ - ST_END_MACRO - -#define MD_GET_UTIME() \ - struct timeval tv; \ - (void) gettimeofday(&tv, NULL); \ - return (tv.tv_sec * 1000000LL + tv.tv_usec) + #include + + #define MD_STACK_GROWS_DOWN + #define MD_USE_SYSV_ANON_MMAP + #define MD_ACCEPT_NB_NOT_INHERITED + #define MD_ALWAYS_UNSERIALIZED_ACCEPT + + #define MD_SETJMP(env) _setjmp(env) + #define MD_LONGJMP(env, val) _longjmp(env, val) + + #define MD_INIT_CONTEXT(_thread, _sp, _main) \ + ST_BEGIN_MACRO \ + if (MD_SETJMP((_thread)->context)) \ + _main(); \ + ((struct sigcontext *)((_thread)->context))->sc_sp = (long) (_sp); \ + ST_END_MACRO + + #define MD_GET_UTIME() \ + struct timeval tv; \ + (void) gettimeofday(&tv, NULL); \ + return (tv.tv_sec * 1000000LL + tv.tv_usec) #elif defined (SOLARIS) - -#include -extern int getpagesize(void); - -#define MD_STACK_GROWS_DOWN -#define MD_USE_SYSV_ANON_MMAP -#define MD_ACCEPT_NB_NOT_INHERITED - -#define MD_SETJMP(env) setjmp(env) -#define MD_LONGJMP(env, val) longjmp(env, val) - -#if defined(sparc) || defined(__sparc) -#ifdef _LP64 -#define MD_STACK_PAD_SIZE 4095 -#endif -#define MD_INIT_CONTEXT(_thread, _sp, _main) \ - ST_BEGIN_MACRO \ - (void) MD_SETJMP((_thread)->context); \ - (_thread)->context[1] = (long) (_sp); \ - (_thread)->context[2] = (long) _main; \ - ST_END_MACRO -#elif defined(i386) || defined(__i386) -#define MD_INIT_CONTEXT(_thread, _sp, _main) \ - ST_BEGIN_MACRO \ - (void) MD_SETJMP((_thread)->context); \ - (_thread)->context[4] = (long) (_sp); \ - (_thread)->context[5] = (long) _main; \ - ST_END_MACRO -#elif defined(__amd64__) -#define MD_INIT_CONTEXT(_thread, _sp, _main) \ - ST_BEGIN_MACRO \ - if (MD_SETJMP((_thread)->context)) \ - _main(); \ - (_thread)->context[6] = (long) (_sp); \ - ST_END_MACRO -#else -#error Unknown CPU architecture -#endif - -#define MD_GET_UTIME() \ - return (gethrtime() / 1000) + #include + extern int getpagesize(void); + + #define MD_STACK_GROWS_DOWN + #define MD_USE_SYSV_ANON_MMAP + #define MD_ACCEPT_NB_NOT_INHERITED + + #define MD_SETJMP(env) setjmp(env) + #define MD_LONGJMP(env, val) longjmp(env, val) + + #if defined(sparc) || defined(__sparc) + #ifdef _LP64 + #define MD_STACK_PAD_SIZE 4095 + #endif + #define MD_INIT_CONTEXT(_thread, _sp, _main) \ + ST_BEGIN_MACRO \ + (void) MD_SETJMP((_thread)->context); \ + (_thread)->context[1] = (long) (_sp); \ + (_thread)->context[2] = (long) _main; \ + ST_END_MACRO + #elif defined(i386) || defined(__i386) + #define MD_INIT_CONTEXT(_thread, _sp, _main) \ + ST_BEGIN_MACRO \ + (void) MD_SETJMP((_thread)->context); \ + (_thread)->context[4] = (long) (_sp); \ + (_thread)->context[5] = (long) _main; \ + ST_END_MACRO + #elif defined(__amd64__) + #define MD_INIT_CONTEXT(_thread, _sp, _main) \ + ST_BEGIN_MACRO \ + if (MD_SETJMP((_thread)->context)) \ + _main(); \ + (_thread)->context[6] = (long) (_sp); \ + ST_END_MACRO + #else + #error Unknown CPU architecture + #endif + + #define MD_GET_UTIME() \ + return (gethrtime() / 1000) #else -#error Unknown OS + #error Unknown OS #endif /* OS */ +/***************************************** + * Other defines + */ #if !defined(MD_HAVE_POLL) && !defined(MD_DONT_HAVE_POLL) -#define MD_HAVE_POLL + #define MD_HAVE_POLL #endif #ifndef MD_STACK_PAD_SIZE -#define MD_STACK_PAD_SIZE 128 + #define MD_STACK_PAD_SIZE 128 #endif #if !defined(MD_HAVE_SOCKLEN_T) && !defined(socklen_t) -#define socklen_t int + #define socklen_t int #endif #ifndef MD_CAP_STACK -#define MD_CAP_STACK(var_addr) + #define MD_CAP_STACK(var_addr) #endif #endif /* !__ST_MD_H__ */