2
0

md.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * The contents of this file are subject to the Mozilla Public
  3. * License Version 1.1 (the "License"); you may not use this file
  4. * except in compliance with the License. You may obtain a copy of
  5. * the License at http://www.mozilla.org/MPL/
  6. *
  7. * Software distributed under the License is distributed on an "AS
  8. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9. * implied. See the License for the specific language governing
  10. * rights and limitations under the License.
  11. *
  12. * The Original Code is the Netscape Portable Runtime library.
  13. *
  14. * The Initial Developer of the Original Code is Netscape
  15. * Communications Corporation. Portions created by Netscape are
  16. * Copyright (C) 1994-2000 Netscape Communications Corporation. All
  17. * Rights Reserved.
  18. *
  19. * Contributor(s): Silicon Graphics, Inc.
  20. *
  21. * Portions created by SGI are Copyright (C) 2000-2001 Silicon
  22. * Graphics, Inc. All Rights Reserved.
  23. *
  24. * Alternatively, the contents of this file may be used under the
  25. * terms of the GNU General Public License Version 2 or later (the
  26. * "GPL"), in which case the provisions of the GPL are applicable
  27. * instead of those above. If you wish to allow use of your
  28. * version of this file only under the terms of the GPL and not to
  29. * allow others to use your version of this file under the MPL,
  30. * indicate your decision by deleting the provisions above and
  31. * replace them with the notice and other provisions required by
  32. * the GPL. If you do not delete the provisions above, a recipient
  33. * may use your version of this file under either the MPL or the
  34. * GPL.
  35. */
  36. /*
  37. * This file is derived directly from Netscape Communications Corporation,
  38. * and consists of extensive modifications made during the year(s) 1999-2000.
  39. */
  40. #ifndef __ST_MD_H__
  41. #define __ST_MD_H__
  42. #if defined(ETIMEDOUT) && !defined(ETIME)
  43. #define ETIME ETIMEDOUT
  44. #endif
  45. #if defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
  46. #define MAP_ANON MAP_ANONYMOUS
  47. #endif
  48. #ifndef MAP_FAILED
  49. #define MAP_FAILED -1
  50. #endif
  51. /*****************************************
  52. * Platform specifics
  53. */
  54. #if defined (LINUX)
  55. /* linux ok, defined bellow */
  56. #elif defined (AIX)
  57. #error "AIX not supported"
  58. #elif defined (CYGWIN)
  59. #error "CYGWIN not supported"
  60. #elif defined (DARWIN)
  61. #error "DARWIN not supported"
  62. #elif defined (FREEBSD)
  63. #error "FREEBSD not supported"
  64. #elif defined (HPUX)
  65. #error "HPUX not supported"
  66. #elif defined (IRIX)
  67. #error "IRIX not supported"
  68. #elif defined (NETBSD)
  69. #error "NETBSD not supported"
  70. #elif defined (OPENBSD)
  71. #error "OPENBSD not supported"
  72. #elif defined (OSF1)
  73. #error "OSF1 not supported"
  74. #elif defined (SOLARIS)
  75. #error "SOLARIS not supported"
  76. #else
  77. #error "Unknown OS"
  78. #endif /* OS */
  79. /* linux only, defined bellow */
  80. /*
  81. * These are properties of the linux kernel and are the same on every
  82. * flavor and architecture.
  83. */
  84. #define MD_USE_BSD_ANON_MMAP
  85. #define MD_ACCEPT_NB_NOT_INHERITED
  86. #define MD_ALWAYS_UNSERIALIZED_ACCEPT
  87. /*
  88. * Modern GNU/Linux is Posix.1g compliant.
  89. */
  90. #define MD_HAVE_SOCKLEN_T
  91. /*
  92. * All architectures and flavors of linux have the gettimeofday
  93. * function but if you know of a faster way, use it.
  94. */
  95. #define MD_GET_UTIME() \
  96. struct timeval tv; \
  97. (void) gettimeofday(&tv, NULL); \
  98. return (tv.tv_sec * 1000000LL + tv.tv_usec)
  99. #if defined(__mips__)
  100. #define MD_STACK_GROWS_DOWN
  101. #else /* Not or mips */
  102. /*
  103. * On linux, there are a few styles of jmpbuf format. These vary based
  104. * on architecture/glibc combination.
  105. *
  106. * Most of the glibc based toggles were lifted from:
  107. * mozilla/nsprpub/pr/include/md/_linux.h
  108. */
  109. /*
  110. * Starting with glibc 2.4, JB_SP definitions are not public anymore.
  111. * They, however, can still be found in glibc source tree in
  112. * architecture-specific "jmpbuf-offsets.h" files.
  113. * Most importantly, the content of jmp_buf is mangled by setjmp to make
  114. * it completely opaque (the mangling can be disabled by setting the
  115. * LD_POINTER_GUARD environment variable before application execution).
  116. * Therefore we will use built-in _st_md_cxt_save/_st_md_cxt_restore
  117. * functions as a setjmp/longjmp replacement wherever they are available
  118. * unless USE_LIBC_SETJMP is defined.
  119. */
  120. #if defined(__i386__)
  121. #define MD_STACK_GROWS_DOWN
  122. #define MD_USE_BUILTIN_SETJMP
  123. #if defined(__GLIBC__) && __GLIBC__ >= 2
  124. #ifndef JB_SP
  125. #define JB_SP 4
  126. #endif
  127. #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_SP]
  128. #else
  129. /* not an error but certainly cause for caution */
  130. #error "Untested use of old glibc on i386"
  131. #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__sp
  132. #endif
  133. #elif defined(__amd64__) || defined(__x86_64__)
  134. #define MD_STACK_GROWS_DOWN
  135. #define MD_USE_BUILTIN_SETJMP
  136. #ifndef JB_RSP
  137. #define JB_RSP 6
  138. #endif
  139. #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_RSP]
  140. #elif defined(__arm__)
  141. #define MD_STACK_GROWS_DOWN
  142. #if defined(__GLIBC__) && __GLIBC__ >= 2
  143. #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[8]
  144. #else
  145. #error "ARM/Linux pre-glibc2 not supported yet"
  146. #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
  147. #else
  148. #error "Unknown CPU architecture"
  149. #endif /* Cases with common MD_INIT_CONTEXT and different SP locations */
  150. #endif /* Cases with different MD_INIT_CONTEXT */
  151. #if defined(MD_USE_BUILTIN_SETJMP) && !defined(USE_LIBC_SETJMP)
  152. /* i386/x86_64 */
  153. #define MD_SETJMP(env) _st_md_cxt_save(env)
  154. #define MD_LONGJMP(env, val) _st_md_cxt_restore(env, val)
  155. extern int _st_md_cxt_save(jmp_buf env);
  156. extern void _st_md_cxt_restore(jmp_buf env, int val);
  157. #else
  158. /* arm/mips */
  159. #define MD_SETJMP(env) setjmp(env)
  160. #define MD_LONGJMP(env, val) longjmp(env, val)
  161. #endif
  162. /*****************************************
  163. * Other defines
  164. */
  165. #ifndef MD_STACK_PAD_SIZE
  166. #define MD_STACK_PAD_SIZE 128
  167. #endif
  168. #if !defined(MD_HAVE_SOCKLEN_T) && !defined(socklen_t)
  169. #define socklen_t int
  170. #endif
  171. #ifndef MD_CAP_STACK
  172. #define MD_CAP_STACK(var_addr)
  173. #endif
  174. #endif /* !__ST_MD_H__ */