e_os2.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * Copyright 1995-2016 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. # undef OPENSSL_SYS_UNIX
  45. # define OPENSSL_SYS_WIN32_CYGWIN
  46. # else
  47. # if defined(_WIN32) || defined(OPENSSL_SYS_WIN32)
  48. # undef OPENSSL_SYS_UNIX
  49. # if !defined(OPENSSL_SYS_WIN32)
  50. # define OPENSSL_SYS_WIN32
  51. # endif
  52. # endif
  53. # if defined(_WIN64) || defined(OPENSSL_SYS_WIN64)
  54. # undef OPENSSL_SYS_UNIX
  55. # if !defined(OPENSSL_SYS_WIN64)
  56. # define OPENSSL_SYS_WIN64
  57. # endif
  58. # endif
  59. # if defined(OPENSSL_SYS_WINNT)
  60. # undef OPENSSL_SYS_UNIX
  61. # endif
  62. # if defined(OPENSSL_SYS_WINCE)
  63. # undef OPENSSL_SYS_UNIX
  64. # endif
  65. # endif
  66. # endif
  67. /* Anything that tries to look like Microsoft is "Windows" */
  68. # if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN64) || defined(OPENSSL_SYS_WINNT) || defined(OPENSSL_SYS_WINCE)
  69. # undef OPENSSL_SYS_UNIX
  70. # define OPENSSL_SYS_WINDOWS
  71. # ifndef OPENSSL_SYS_MSDOS
  72. # define OPENSSL_SYS_MSDOS
  73. # endif
  74. # endif
  75. /*
  76. * DLL settings. This part is a bit tough, because it's up to the
  77. * application implementor how he or she will link the application, so it
  78. * requires some macro to be used.
  79. */
  80. # ifdef OPENSSL_SYS_WINDOWS
  81. # ifndef OPENSSL_OPT_WINDLL
  82. # if defined(_WINDLL) /* This is used when building OpenSSL to
  83. * indicate that DLL linkage should be used */
  84. # define OPENSSL_OPT_WINDLL
  85. # endif
  86. # endif
  87. # endif
  88. /* ------------------------------- OpenVMS -------------------------------- */
  89. # if defined(__VMS) || defined(VMS) || defined(OPENSSL_SYS_VMS)
  90. # if !defined(OPENSSL_SYS_VMS)
  91. # undef OPENSSL_SYS_UNIX
  92. # endif
  93. # define OPENSSL_SYS_VMS
  94. # if defined(__DECC)
  95. # define OPENSSL_SYS_VMS_DECC
  96. # elif defined(__DECCXX)
  97. # define OPENSSL_SYS_VMS_DECC
  98. # define OPENSSL_SYS_VMS_DECCXX
  99. # else
  100. # define OPENSSL_SYS_VMS_NODECC
  101. # endif
  102. # endif
  103. /* -------------------------------- Unix ---------------------------------- */
  104. # ifdef OPENSSL_SYS_UNIX
  105. # if defined(linux) || defined(__linux__) && !defined(OPENSSL_SYS_LINUX)
  106. # define OPENSSL_SYS_LINUX
  107. # endif
  108. # if defined(_AIX) && !defined(OPENSSL_SYS_AIX)
  109. # define OPENSSL_SYS_AIX
  110. # endif
  111. # endif
  112. /* -------------------------------- VOS ----------------------------------- */
  113. # if defined(__VOS__) && !defined(OPENSSL_SYS_VOS)
  114. # define OPENSSL_SYS_VOS
  115. # ifdef __HPPA__
  116. # define OPENSSL_SYS_VOS_HPPA
  117. # endif
  118. # ifdef __IA32__
  119. # define OPENSSL_SYS_VOS_IA32
  120. # endif
  121. # endif
  122. /**
  123. * That's it for OS-specific stuff
  124. *****************************************************************************/
  125. /* Specials for I/O an exit */
  126. # ifdef OPENSSL_SYS_MSDOS
  127. # define OPENSSL_UNISTD_IO <io.h>
  128. # define OPENSSL_DECLARE_EXIT extern void exit(int);
  129. # else
  130. # define OPENSSL_UNISTD_IO OPENSSL_UNISTD
  131. # define OPENSSL_DECLARE_EXIT /* declared in unistd.h */
  132. # endif
  133. /*-
  134. * Definitions of OPENSSL_GLOBAL and OPENSSL_EXTERN, to define and declare
  135. * certain global symbols that, with some compilers under VMS, have to be
  136. * defined and declared explicitly with globaldef and globalref.
  137. * Definitions of OPENSSL_EXPORT and OPENSSL_IMPORT, to define and declare
  138. * DLL exports and imports for compilers under Win32. These are a little
  139. * more complicated to use. Basically, for any library that exports some
  140. * global variables, the following code must be present in the header file
  141. * that declares them, before OPENSSL_EXTERN is used:
  142. *
  143. * #ifdef SOME_BUILD_FLAG_MACRO
  144. * # undef OPENSSL_EXTERN
  145. * # define OPENSSL_EXTERN OPENSSL_EXPORT
  146. * #endif
  147. *
  148. * The default is to have OPENSSL_EXPORT, OPENSSL_EXTERN and OPENSSL_GLOBAL
  149. * have some generally sensible values.
  150. */
  151. # if defined(OPENSSL_SYS_VMS_NODECC)
  152. # define OPENSSL_EXPORT globalref
  153. # define OPENSSL_EXTERN globalref
  154. # define OPENSSL_GLOBAL globaldef
  155. # elif defined(OPENSSL_SYS_WINDOWS) && defined(OPENSSL_OPT_WINDLL)
  156. # define OPENSSL_EXPORT extern __declspec(dllexport)
  157. # define OPENSSL_EXTERN extern __declspec(dllimport)
  158. # define OPENSSL_GLOBAL
  159. # else
  160. # define OPENSSL_EXPORT extern
  161. # define OPENSSL_EXTERN extern
  162. # define OPENSSL_GLOBAL
  163. # endif
  164. /*-
  165. * Macros to allow global variables to be reached through function calls when
  166. * required (if a shared library version requires it, for example.
  167. * The way it's done allows definitions like this:
  168. *
  169. * // in foobar.c
  170. * OPENSSL_IMPLEMENT_GLOBAL(int,foobar,0)
  171. * // in foobar.h
  172. * OPENSSL_DECLARE_GLOBAL(int,foobar);
  173. * #define foobar OPENSSL_GLOBAL_REF(foobar)
  174. */
  175. # ifdef OPENSSL_EXPORT_VAR_AS_FUNCTION
  176. # define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) \
  177. type *_shadow_##name(void) \
  178. { static type _hide_##name=value; return &_hide_##name; }
  179. # define OPENSSL_DECLARE_GLOBAL(type,name) type *_shadow_##name(void)
  180. # define OPENSSL_GLOBAL_REF(name) (*(_shadow_##name()))
  181. # else
  182. # define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) OPENSSL_GLOBAL type _shadow_##name=value;
  183. # define OPENSSL_DECLARE_GLOBAL(type,name) OPENSSL_EXPORT type _shadow_##name
  184. # define OPENSSL_GLOBAL_REF(name) _shadow_##name
  185. # endif
  186. # ifdef _WIN32
  187. # ifdef _WIN64
  188. # define ossl_ssize_t __int64
  189. # define OSSL_SSIZE_MAX _I64_MAX
  190. # else
  191. # define ossl_ssize_t int
  192. # define OSSL_SSIZE_MAX INT_MAX
  193. # endif
  194. # endif
  195. # if defined(OPENSSL_SYS_UEFI) && !defined(ossl_ssize_t)
  196. # define ossl_ssize_t INTN
  197. # define OSSL_SSIZE_MAX MAX_INTN
  198. # endif
  199. # ifndef ossl_ssize_t
  200. # define ossl_ssize_t ssize_t
  201. # if defined(SSIZE_MAX)
  202. # define OSSL_SSIZE_MAX SSIZE_MAX
  203. # elif defined(_POSIX_SSIZE_MAX)
  204. # define OSSL_SSIZE_MAX _POSIX_SSIZE_MAX
  205. # endif
  206. # endif
  207. # ifdef DEBUG_UNUSED
  208. # define __owur __attribute__((__warn_unused_result__))
  209. # else
  210. # define __owur
  211. # endif
  212. /* Standard integer types */
  213. # if defined(OPENSSL_SYS_UEFI)
  214. typedef INT8 int8_t;
  215. typedef UINT8 uint8_t;
  216. typedef INT16 int16_t;
  217. typedef UINT16 uint16_t;
  218. typedef INT32 int32_t;
  219. typedef UINT32 uint32_t;
  220. typedef INT64 int64_t;
  221. typedef UINT64 uint64_t;
  222. # elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
  223. defined(__osf__) || defined(__sgi) || defined(__hpux) || \
  224. defined(OPENSSL_SYS_VMS) || defined (__OpenBSD__)
  225. # include <inttypes.h>
  226. # elif defined(_MSC_VER) && _MSC_VER<=1500
  227. /*
  228. * minimally required typdefs for systems not supporting inttypes.h or
  229. * stdint.h: currently just older VC++
  230. */
  231. typedef signed char int8_t;
  232. typedef unsigned char uint8_t;
  233. typedef short int16_t;
  234. typedef unsigned short uint16_t;
  235. typedef int int32_t;
  236. typedef unsigned int uint32_t;
  237. typedef __int64 int64_t;
  238. typedef unsigned __int64 uint64_t;
  239. # else
  240. # include <stdint.h>
  241. # endif
  242. /* ossl_inline: portable inline definition usable in public headers */
  243. # if !defined(inline) && !defined(__cplusplus)
  244. # if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
  245. /* just use inline */
  246. # define ossl_inline inline
  247. # elif defined(__GNUC__) && __GNUC__>=2
  248. # define ossl_inline __inline__
  249. # elif defined(_MSC_VER)
  250. /*
  251. * Visual Studio: inline is available in C++ only, however
  252. * __inline is available for C, see
  253. * http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx
  254. */
  255. # define ossl_inline __inline
  256. # else
  257. # define ossl_inline
  258. # endif
  259. # else
  260. # define ossl_inline inline
  261. # endif
  262. # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
  263. # define ossl_noreturn _Noreturn
  264. # elif defined(__GNUC__) && __GNUC__ >= 2
  265. # define ossl_noreturn __attribute__((noreturn))
  266. # else
  267. # define ossl_noreturn
  268. # endif
  269. #ifdef __cplusplus
  270. }
  271. #endif
  272. #endif