e_os2.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*
  2. * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef HEADER_E_OS2_H
  10. # define HEADER_E_OS2_H
  11. # include <openssl/opensslconf.h>
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. /******************************************************************************
  16. * Detect operating systems. This probably needs completing.
  17. * The result is that at least one OPENSSL_SYS_os macro should be defined.
  18. * However, if none is defined, Unix is assumed.
  19. **/
  20. # define OPENSSL_SYS_UNIX
  21. /* --------------------- Microsoft operating systems ---------------------- */
  22. /*
  23. * Note that MSDOS actually denotes 32-bit environments running on top of
  24. * MS-DOS, such as DJGPP one.
  25. */
  26. # if defined(OPENSSL_SYS_MSDOS)
  27. # undef OPENSSL_SYS_UNIX
  28. # endif
  29. /*
  30. * For 32 bit environment, there seems to be the CygWin environment and then
  31. * all the others that try to do the same thing Microsoft does...
  32. */
  33. /*
  34. * UEFI lives here because it might be built with a Microsoft toolchain and
  35. * we need to avoid the false positive match on Windows.
  36. */
  37. # if defined(OPENSSL_SYS_UEFI)
  38. # undef OPENSSL_SYS_UNIX
  39. # elif defined(OPENSSL_SYS_UWIN)
  40. # undef OPENSSL_SYS_UNIX
  41. # define OPENSSL_SYS_WIN32_UWIN
  42. # else
  43. # if defined(__CYGWIN__) || defined(OPENSSL_SYS_CYGWIN)
  44. # define OPENSSL_SYS_WIN32_CYGWIN
  45. # else
  46. # if defined(_WIN32) || defined(OPENSSL_SYS_WIN32)
  47. # undef OPENSSL_SYS_UNIX
  48. # if !defined(OPENSSL_SYS_WIN32)
  49. # define OPENSSL_SYS_WIN32
  50. # endif
  51. # endif
  52. # if defined(_WIN64) || defined(OPENSSL_SYS_WIN64)
  53. # undef OPENSSL_SYS_UNIX
  54. # if !defined(OPENSSL_SYS_WIN64)
  55. # define OPENSSL_SYS_WIN64
  56. # endif
  57. # endif
  58. # if defined(OPENSSL_SYS_WINNT)
  59. # undef OPENSSL_SYS_UNIX
  60. # endif
  61. # if defined(OPENSSL_SYS_WINCE)
  62. # undef OPENSSL_SYS_UNIX
  63. # endif
  64. # endif
  65. # endif
  66. /* Anything that tries to look like Microsoft is "Windows" */
  67. # if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN64) || defined(OPENSSL_SYS_WINNT) || defined(OPENSSL_SYS_WINCE)
  68. # undef OPENSSL_SYS_UNIX
  69. # define OPENSSL_SYS_WINDOWS
  70. # ifndef OPENSSL_SYS_MSDOS
  71. # define OPENSSL_SYS_MSDOS
  72. # endif
  73. # endif
  74. /*
  75. * DLL settings. This part is a bit tough, because it's up to the
  76. * application implementor how he or she will link the application, so it
  77. * requires some macro to be used.
  78. */
  79. # ifdef OPENSSL_SYS_WINDOWS
  80. # ifndef OPENSSL_OPT_WINDLL
  81. # if defined(_WINDLL) /* This is used when building OpenSSL to
  82. * indicate that DLL linkage should be used */
  83. # define OPENSSL_OPT_WINDLL
  84. # endif
  85. # endif
  86. # endif
  87. /* ------------------------------- OpenVMS -------------------------------- */
  88. # if defined(__VMS) || defined(VMS) || defined(OPENSSL_SYS_VMS)
  89. # if !defined(OPENSSL_SYS_VMS)
  90. # undef OPENSSL_SYS_UNIX
  91. # endif
  92. # define OPENSSL_SYS_VMS
  93. # if defined(__DECC)
  94. # define OPENSSL_SYS_VMS_DECC
  95. # elif defined(__DECCXX)
  96. # define OPENSSL_SYS_VMS_DECC
  97. # define OPENSSL_SYS_VMS_DECCXX
  98. # else
  99. # define OPENSSL_SYS_VMS_NODECC
  100. # endif
  101. # endif
  102. /* -------------------------------- Unix ---------------------------------- */
  103. # ifdef OPENSSL_SYS_UNIX
  104. # if defined(linux) || defined(__linux__) && !defined(OPENSSL_SYS_LINUX)
  105. # define OPENSSL_SYS_LINUX
  106. # endif
  107. # if defined(_AIX) && !defined(OPENSSL_SYS_AIX)
  108. # define OPENSSL_SYS_AIX
  109. # endif
  110. # endif
  111. /* -------------------------------- VOS ----------------------------------- */
  112. # if defined(__VOS__) && !defined(OPENSSL_SYS_VOS)
  113. # define OPENSSL_SYS_VOS
  114. # ifdef __HPPA__
  115. # define OPENSSL_SYS_VOS_HPPA
  116. # endif
  117. # ifdef __IA32__
  118. # define OPENSSL_SYS_VOS_IA32
  119. # endif
  120. # endif
  121. /**
  122. * That's it for OS-specific stuff
  123. *****************************************************************************/
  124. /* Specials for I/O an exit */
  125. # ifdef OPENSSL_SYS_MSDOS
  126. # define OPENSSL_UNISTD_IO <io.h>
  127. # define OPENSSL_DECLARE_EXIT extern void exit(int);
  128. # else
  129. # define OPENSSL_UNISTD_IO OPENSSL_UNISTD
  130. # define OPENSSL_DECLARE_EXIT /* declared in unistd.h */
  131. # endif
  132. /*-
  133. * OPENSSL_EXTERN is normally used to declare a symbol with possible extra
  134. * attributes to handle its presence in a shared library.
  135. * OPENSSL_EXPORT is used to define a symbol with extra possible attributes
  136. * to make it visible in a shared library.
  137. * Care needs to be taken when a header file is used both to declare and
  138. * define symbols. Basically, for any library that exports some global
  139. * variables, the following code must be present in the header file that
  140. * declares them, before OPENSSL_EXTERN is used:
  141. *
  142. * #ifdef SOME_BUILD_FLAG_MACRO
  143. * # undef OPENSSL_EXTERN
  144. * # define OPENSSL_EXTERN OPENSSL_EXPORT
  145. * #endif
  146. *
  147. * The default is to have OPENSSL_EXPORT and OPENSSL_EXTERN
  148. * have some generally sensible values.
  149. */
  150. # if defined(OPENSSL_SYS_WINDOWS) && defined(OPENSSL_OPT_WINDLL)
  151. # define OPENSSL_EXPORT extern __declspec(dllexport)
  152. # define OPENSSL_EXTERN extern __declspec(dllimport)
  153. # else
  154. # define OPENSSL_EXPORT extern
  155. # define OPENSSL_EXTERN extern
  156. # endif
  157. /*-
  158. * Macros to allow global variables to be reached through function calls when
  159. * required (if a shared library version requires it, for example.
  160. * The way it's done allows definitions like this:
  161. *
  162. * // in foobar.c
  163. * OPENSSL_IMPLEMENT_GLOBAL(int,foobar,0)
  164. * // in foobar.h
  165. * OPENSSL_DECLARE_GLOBAL(int,foobar);
  166. * #define foobar OPENSSL_GLOBAL_REF(foobar)
  167. */
  168. # ifdef OPENSSL_EXPORT_VAR_AS_FUNCTION
  169. # define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) \
  170. type *_shadow_##name(void) \
  171. { static type _hide_##name=value; return &_hide_##name; }
  172. # define OPENSSL_DECLARE_GLOBAL(type,name) type *_shadow_##name(void)
  173. # define OPENSSL_GLOBAL_REF(name) (*(_shadow_##name()))
  174. # else
  175. # define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) type _shadow_##name=value;
  176. # define OPENSSL_DECLARE_GLOBAL(type,name) OPENSSL_EXPORT type _shadow_##name
  177. # define OPENSSL_GLOBAL_REF(name) _shadow_##name
  178. # endif
  179. # ifdef _WIN32
  180. # ifdef _WIN64
  181. # define ossl_ssize_t __int64
  182. # define OSSL_SSIZE_MAX _I64_MAX
  183. # else
  184. # define ossl_ssize_t int
  185. # define OSSL_SSIZE_MAX INT_MAX
  186. # endif
  187. # endif
  188. # if defined(OPENSSL_SYS_UEFI) && !defined(ossl_ssize_t)
  189. # define ossl_ssize_t INTN
  190. # define OSSL_SSIZE_MAX MAX_INTN
  191. # endif
  192. # ifndef ossl_ssize_t
  193. # define ossl_ssize_t ssize_t
  194. # if defined(SSIZE_MAX)
  195. # define OSSL_SSIZE_MAX SSIZE_MAX
  196. # elif defined(_POSIX_SSIZE_MAX)
  197. # define OSSL_SSIZE_MAX _POSIX_SSIZE_MAX
  198. # endif
  199. # endif
  200. # ifdef DEBUG_UNUSED
  201. # define __owur __attribute__((__warn_unused_result__))
  202. # else
  203. # define __owur
  204. # endif
  205. /* Standard integer types */
  206. # if defined(OPENSSL_SYS_UEFI)
  207. typedef INT8 int8_t;
  208. typedef UINT8 uint8_t;
  209. typedef INT16 int16_t;
  210. typedef UINT16 uint16_t;
  211. typedef INT32 int32_t;
  212. typedef UINT32 uint32_t;
  213. typedef INT64 int64_t;
  214. typedef UINT64 uint64_t;
  215. # elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
  216. defined(__osf__) || defined(__sgi) || defined(__hpux) || \
  217. defined(OPENSSL_SYS_VMS) || defined (__OpenBSD__)
  218. # include <inttypes.h>
  219. # elif defined(_MSC_VER) && _MSC_VER<=1500
  220. /*
  221. * minimally required typdefs for systems not supporting inttypes.h or
  222. * stdint.h: currently just older VC++
  223. */
  224. typedef signed char int8_t;
  225. typedef unsigned char uint8_t;
  226. typedef short int16_t;
  227. typedef unsigned short uint16_t;
  228. typedef int int32_t;
  229. typedef unsigned int uint32_t;
  230. typedef __int64 int64_t;
  231. typedef unsigned __int64 uint64_t;
  232. # else
  233. # include <stdint.h>
  234. # endif
  235. /* ossl_inline: portable inline definition usable in public headers */
  236. # if !defined(inline) && !defined(__cplusplus)
  237. # if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
  238. /* just use inline */
  239. # define ossl_inline inline
  240. # elif defined(__GNUC__) && __GNUC__>=2
  241. # define ossl_inline __inline__
  242. # elif defined(_MSC_VER)
  243. /*
  244. * Visual Studio: inline is available in C++ only, however
  245. * __inline is available for C, see
  246. * http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx
  247. */
  248. # define ossl_inline __inline
  249. # else
  250. # define ossl_inline
  251. # endif
  252. # else
  253. # define ossl_inline inline
  254. # endif
  255. # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
  256. # define ossl_noreturn _Noreturn
  257. # elif defined(__GNUC__) && __GNUC__ >= 2
  258. # define ossl_noreturn __attribute__((noreturn))
  259. # else
  260. # define ossl_noreturn
  261. # endif
  262. #ifdef __cplusplus
  263. }
  264. #endif
  265. #endif