mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 11:51:57 +00:00
commit f4872e528cad07f8ea683cc8cb26e34111bad1b5 Author: winlin <winlin@vip.126.com> Date: Fri Feb 26 09:13:21 2021 +0800 ST: For #2188: Remove sendmmsg from ST. commit aaeb8919bd4a026268e0600398cb1e9ad477663f Author: winlin <winlin@vip.126.com> Date: Thu Mar 11 08:09:54 2021 +0800 ST: Refine utest script. commit d1ac9da53060b6bfa82b5d041da4c2ad9bd6b90a Author: winlin <winlin@vip.126.com> Date: Wed Mar 3 11:02:25 2021 +0800 ST: Support fast utest and coverage commit 8400115b83c022e33f59422dbf6d85ee46fb9edb Author: winlin <winlin@vip.126.com> Date: Fri Feb 26 07:02:19 2021 +0800 ST: Always use unserialized accept for linux or darwin commit c3686f2bca80d2c139239b08975575b1bb981ffa Author: winlin <winlin@vip.126.com> Date: Fri Feb 26 06:54:05 2021 +0800 ST: Refine ARFLAGS by disable the verbose log commit aaa5c4f863eba278c4ed2b29a46297fb01a4ed63 Author: winlin <winlin@vip.126.com> Date: Thu Feb 25 08:58:46 2021 +0800 ST: Stack always grows from top to down. commit dddd466e5c2e418c6f4896cd8bf701130052b3d9 Author: winlin <winlin@vip.126.com> Date: Thu Feb 25 08:51:31 2021 +0800 ST: Ignore process fork, for single process only commit 7906cb5f6e78c916cb8b8d9522275bfc086bb6a3 Author: winlin <winlin@vip.126.com> Date: Thu Feb 25 08:50:59 2021 +0800 ST: Fix build warnings commit d94921b84a3b6cf88ace2c766cc2bfedb9c0602e Author: winlin <winlin@vip.126.com> Date: Thu Feb 25 07:27:45 2021 +0800 ST: Remove select and poll support, only epoll and kqueue commit 76d202514615f78d1a8f2b15778f3dac5abf4abb Author: winlin <winlin@vip.126.com> Date: Thu Feb 25 07:10:47 2021 +0800 ST: Remove multiple OS support, except Linux and Darwin. commit 13c4ba345c61170e86dde486a174378ca235f442 Author: winlin <winlin@vip.126.com> Date: Thu Feb 25 06:59:35 2021 +0800 ST: Remove __ia64__ CPU support commit 46c06e4a11879cfeb828382e44f11287782ce4b5 Author: winlin <winlin@vip.126.com> Date: Wed Feb 24 11:37:27 2021 +0800 ST: Remove unused files for ST
232 lines
8 KiB
C
232 lines
8 KiB
C
/*
|
|
* The contents of this file are subject to the Mozilla Public
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
* except in compliance with the License. You may obtain a copy of
|
|
* the License at http://www.mozilla.org/MPL/
|
|
*
|
|
* Software distributed under the License is distributed on an "AS
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
* implied. See the License for the specific language governing
|
|
* rights and limitations under the License.
|
|
*
|
|
* The Original Code is the Netscape Portable Runtime library.
|
|
*
|
|
* The Initial Developer of the Original Code is Netscape
|
|
* Communications Corporation. Portions created by Netscape are
|
|
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
|
|
* Rights Reserved.
|
|
*
|
|
* Contributor(s): Silicon Graphics, Inc.
|
|
*
|
|
* Portions created by SGI are Copyright (C) 2000-2001 Silicon
|
|
* Graphics, Inc. All Rights Reserved.
|
|
*
|
|
* Alternatively, the contents of this file may be used under the
|
|
* terms of the GNU General Public License Version 2 or later (the
|
|
* "GPL"), in which case the provisions of the GPL are applicable
|
|
* instead of those above. If you wish to allow use of your
|
|
* version of this file only under the terms of the GPL and not to
|
|
* allow others to use your version of this file under the MPL,
|
|
* indicate your decision by deleting the provisions above and
|
|
* replace them with the notice and other provisions required by
|
|
* the GPL. If you do not delete the provisions above, a recipient
|
|
* may use your version of this file under either the MPL or the
|
|
* GPL.
|
|
*/
|
|
|
|
/*
|
|
* This file is derived directly from Netscape Communications Corporation,
|
|
* and consists of extensive modifications made during the year(s) 1999-2000.
|
|
*/
|
|
|
|
#ifndef __ST_MD_H__
|
|
#define __ST_MD_H__
|
|
|
|
#if defined(ETIMEDOUT) && !defined(ETIME)
|
|
#define ETIME ETIMEDOUT
|
|
#endif
|
|
|
|
#if defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
|
|
#define MAP_ANON MAP_ANONYMOUS
|
|
#endif
|
|
|
|
#ifndef MAP_FAILED
|
|
#define MAP_FAILED -1
|
|
#endif
|
|
|
|
/*****************************************
|
|
* Platform specifics
|
|
*/
|
|
|
|
#if defined (DARWIN)
|
|
|
|
#define MD_USE_BSD_ANON_MMAP
|
|
#define MD_ACCEPT_NB_INHERITED
|
|
#define MD_HAVE_SOCKLEN_T
|
|
|
|
#define MD_USE_BUILTIN_SETJMP
|
|
|
|
#if defined(__amd64__) || defined(__x86_64__)
|
|
#define JB_SP 12
|
|
#define MD_GET_SP(_t) *((long *)&((_t)->context[JB_SP]))
|
|
#else
|
|
#error Unknown CPU architecture
|
|
#endif
|
|
|
|
#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
|
|
|
|
#if defined(MD_USE_BUILTIN_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);
|
|
#endif
|
|
|
|
#define MD_GET_UTIME() \
|
|
struct timeval tv; \
|
|
(void) gettimeofday(&tv, NULL); \
|
|
return (tv.tv_sec * 1000000LL + tv.tv_usec)
|
|
|
|
#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
|
|
/*
|
|
* 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(__mips__)
|
|
#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 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(__i386__)
|
|
#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_USE_BUILTIN_SETJMP
|
|
|
|
#ifndef JB_RSP
|
|
#define JB_RSP 6
|
|
#endif
|
|
#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_RSP]
|
|
|
|
#elif defined(__aarch64__)
|
|
/* https://github.com/ossrs/state-threads/issues/9 */
|
|
#define MD_USE_BUILTIN_SETJMP
|
|
#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[13]
|
|
|
|
#elif defined(__arm__)
|
|
/* https://github.com/ossrs/state-threads/issues/1#issuecomment-244648573 */
|
|
#define MD_USE_BUILTIN_SETJMP
|
|
|
|
/* force to use glibc solution, hack the guard jmpbuf from michaeltalyansky */
|
|
#ifdef USE_LIBC_SETJMP
|
|
#undef MD_USE_BUILTIN_SETJMP
|
|
#endif
|
|
|
|
#if defined(__GLIBC__) && __GLIBC__ >= 2
|
|
/* Merge from https://github.com/michaeltalyansky/state-threads/commit/56554a5c425aee8e7a73782eae23d74d83c4120a */
|
|
#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[8]
|
|
#else
|
|
#error "ARM/Linux pre-glibc2 not supported yet"
|
|
#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
|
|
|
|
#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
|
|
|
|
#else
|
|
#error Unknown OS
|
|
#endif /* OS */
|
|
|
|
#ifndef MD_STACK_PAD_SIZE
|
|
#define MD_STACK_PAD_SIZE 128
|
|
#endif
|
|
|
|
#if !defined(MD_HAVE_SOCKLEN_T) && !defined(socklen_t)
|
|
#define socklen_t int
|
|
#endif
|
|
|
|
#ifndef MD_CAP_STACK
|
|
#define MD_CAP_STACK(var_addr)
|
|
#endif
|
|
|
|
#endif /* !__ST_MD_H__ */
|
|
|