Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2014-11-06 15:54:24 +0800
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
1e51462677e9403bdb32148288b87ee46c7656e4
1e514626
2 parents
76d5914d
0f41e0d2
Merge branch 'srs.master'
显示空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
36 行增加
和
344 行删除
trunk/research/st/md.h
trunk/research/st/md.h
查看文件 @
1e51462
...
...
@@ -57,227 +57,55 @@
/*****************************************
* Platform specifics
*/
#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)
#if defined (LINUX)
/* linux ok, defined bellow */
#elif defined (AIX)
#error "AIX not supported"
#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_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)
#error "CYGWIN not supported"
#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_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)
#error "DARWIN not supported"
#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)
#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_GET_UTIME() \
struct timeval tv; \
(void) gettimeofday(&tv, NULL); \
return (tv.tv_sec * 1000000LL + tv.tv_usec)
#error "FREEBSD not supported"
#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)
#error "HPUX not supported"
#elif defined (IRIX)
#include <sys/syssgi.h>
#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)
/*
* 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
#error "IRIX not supported"
#elif defined (NETBSD)
#error "NETBSD not supported"
#elif defined (OPENBSD)
#error "OPENBSD not supported"
#elif defined (OSF1)
#error "OSF1 not supported"
#elif defined (SOLARIS)
#error "SOLARIS not supported"
#else
#error "Unknown OS"
#endif
/* OS */
#elif defined (LINUX)
/*
/* linux only, defined bellow */
/*
* 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
/*
#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
#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() \
#define MD_GET_UTIME() \
struct timeval tv; \
(void) gettimeofday(&tv, NULL); \
return (tv.tv_sec * 1000000LL + tv.tv_usec)
#if defined(__ia64__)
#if defined(__ia64__)
#define MD_STACK_GROWS_DOWN
/*
...
...
@@ -305,7 +133,7 @@
(_thread)->context[0].__jmpbuf[0] = (long) (_sp); \
(_thread)->context[0].__jmpbuf[17] = (long) (_bsp); \
ST_END_MACRO
#elif defined(__mips__)
#elif defined(__mips__)
#define MD_STACK_GROWS_DOWN
#define MD_INIT_CONTEXT(_thread, _sp, _main) \
...
...
@@ -314,7 +142,7 @@
_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 */
#else
/* Not IA-64 or mips */
/*
* On linux, there are a few styles of jmpbuf format. These vary based
* on architecture/glibc combination.
...
...
@@ -431,154 +259,18 @@
_main(); \
MD_GET_SP(_thread) = (long) (_sp); \
ST_END_MACRO
#endif
/* Cases with different MD_INIT_CONTEXT */
#endif
/* Cases with different MD_INIT_CONTEXT */
#if defined(MD_USE_BUILTIN_SETJMP) && !defined(USE_LIBC_SETJMP)
#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)
#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)
#elif defined (OSF1)
#include <signal.h>
#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 <sys/filio.h>
extern
int
getpagesize
(
void
);
#define MD_STACK_GROWS_DOWN
#define MD_USE_SYSV_ANON_MMAP
#define MD_ACCEPT_NB_NOT_INHERITED
#else
#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
#endif
/* OS */
#endif
/*****************************************
* Other defines
...
...
请
注册
或
登录
后发表评论