e_os2.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. * Definitions of OPENSSL_GLOBAL and OPENSSL_EXTERN, to define and declare
  134. * certain global symbols that, with some compilers under VMS, have to be
  135. * defined and declared explicitly with globaldef and globalref.
  136. * Definitions of OPENSSL_EXPORT and OPENSSL_IMPORT, to define and declare
  137. * DLL exports and imports for compilers under Win32. These are a little
  138. * more complicated to use. Basically, for any library that exports some
  139. * global variables, the following code must be present in the header file
  140. * that 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, OPENSSL_EXTERN and OPENSSL_GLOBAL
  148. * have some generally sensible values.
  149. */
  150. # if defined(OPENSSL_SYS_VMS_NODECC)
  151. # define OPENSSL_EXPORT globalref
  152. # define OPENSSL_EXTERN globalref
  153. # define OPENSSL_GLOBAL globaldef
  154. # elif defined(OPENSSL_SYS_WINDOWS) && defined(OPENSSL_OPT_WINDLL)
  155. # define OPENSSL_EXPORT extern __declspec(dllexport)
  156. # define OPENSSL_EXTERN extern __declspec(dllimport)
  157. # define OPENSSL_GLOBAL
  158. # else
  159. # define OPENSSL_EXPORT extern
  160. # define OPENSSL_EXTERN extern
  161. # define OPENSSL_GLOBAL
  162. # endif
  163. /*-
  164. * Macros to allow global variables to be reached through function calls when
  165. * required (if a shared library version requires it, for example.
  166. * The way it's done allows definitions like this:
  167. *
  168. * // in foobar.c
  169. * OPENSSL_IMPLEMENT_GLOBAL(int,foobar,0)
  170. * // in foobar.h
  171. * OPENSSL_DECLARE_GLOBAL(int,foobar);
  172. * #define foobar OPENSSL_GLOBAL_REF(foobar)
  173. */
  174. # ifdef OPENSSL_EXPORT_VAR_AS_FUNCTION
  175. # define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) \
  176. type *_shadow_##name(void) \
  177. { static type _hide_##name=value; return &_hide_##name; }
  178. # define OPENSSL_DECLARE_GLOBAL(type,name) type *_shadow_##name(void)
  179. # define OPENSSL_GLOBAL_REF(name) (*(_shadow_##name()))
  180. # else
  181. # define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) OPENSSL_GLOBAL type _shadow_##name=value;
  182. # define OPENSSL_DECLARE_GLOBAL(type,name) OPENSSL_EXPORT type _shadow_##name
  183. # define OPENSSL_GLOBAL_REF(name) _shadow_##name
  184. # endif
  185. # ifdef _WIN32
  186. # ifdef _WIN64
  187. # define ossl_ssize_t __int64
  188. # define OSSL_SSIZE_MAX _I64_MAX
  189. # else
  190. # define ossl_ssize_t int
  191. # define OSSL_SSIZE_MAX INT_MAX
  192. # endif
  193. # endif
  194. # if defined(OPENSSL_SYS_UEFI) && !defined(ossl_ssize_t)
  195. # define ossl_ssize_t INTN
  196. # define OSSL_SSIZE_MAX MAX_INTN
  197. # endif
  198. # ifndef ossl_ssize_t
  199. # define ossl_ssize_t ssize_t
  200. # if defined(SSIZE_MAX)
  201. # define OSSL_SSIZE_MAX SSIZE_MAX
  202. # elif defined(_POSIX_SSIZE_MAX)
  203. # define OSSL_SSIZE_MAX _POSIX_SSIZE_MAX
  204. # endif
  205. # endif
  206. # ifdef DEBUG_UNUSED
  207. # define __owur __attribute__((__warn_unused_result__))
  208. # else
  209. # define __owur
  210. # endif
  211. /* Standard integer types */
  212. # if defined(OPENSSL_SYS_UEFI)
  213. typedef INT8 int8_t;
  214. typedef UINT8 uint8_t;
  215. typedef INT16 int16_t;
  216. typedef UINT16 uint16_t;
  217. typedef INT32 int32_t;
  218. typedef UINT32 uint32_t;
  219. typedef INT64 int64_t;
  220. typedef UINT64 uint64_t;
  221. # elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
  222. defined(__osf__) || defined(__sgi) || defined(__hpux) || \
  223. defined(OPENSSL_SYS_VMS) || defined (__OpenBSD__)
  224. # include <inttypes.h>
  225. # elif defined(_MSC_VER) && _MSC_VER<=1500
  226. /*
  227. * minimally required typdefs for systems not supporting inttypes.h or
  228. * stdint.h: currently just older VC++
  229. */
  230. typedef signed char int8_t;
  231. typedef unsigned char uint8_t;
  232. typedef short int16_t;
  233. typedef unsigned short uint16_t;
  234. typedef int int32_t;
  235. typedef unsigned int uint32_t;
  236. typedef __int64 int64_t;
  237. typedef unsigned __int64 uint64_t;
  238. # else
  239. # include <stdint.h>
  240. # endif
  241. /* ossl_inline: portable inline definition usable in public headers */
  242. # if !defined(inline) && !defined(__cplusplus)
  243. # if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
  244. /* just use inline */
  245. # define ossl_inline inline
  246. # elif defined(__GNUC__) && __GNUC__>=2
  247. # define ossl_inline __inline__
  248. # elif defined(_MSC_VER)
  249. /*
  250. * Visual Studio: inline is available in C++ only, however
  251. * __inline is available for C, see
  252. * http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx
  253. */
  254. # define ossl_inline __inline
  255. # else
  256. # define ossl_inline
  257. # endif
  258. # else
  259. # define ossl_inline inline
  260. # endif
  261. # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
  262. # define ossl_noreturn _Noreturn
  263. # elif defined(__GNUC__) && __GNUC__ >= 2
  264. # define ossl_noreturn __attribute__((noreturn))
  265. # else
  266. # define ossl_noreturn
  267. # endif
  268. #ifdef __cplusplus
  269. }
  270. #endif
  271. #endif