2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
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
10 #ifndef HEADER_E_OS2_H
11 # define HEADER_E_OS2_H
13 # include <openssl/opensslconf.h>
19 /******************************************************************************
20 * Detect operating systems. This probably needs completing.
21 * The result is that at least one OPENSSL_SYS_os macro should be defined.
22 * However, if none is defined, Unix is assumed.
25 # define OPENSSL_SYS_UNIX
27 /* --------------------- Microsoft operating systems ---------------------- */
30 * Note that MSDOS actually denotes 32-bit environments running on top of
31 * MS-DOS, such as DJGPP one.
33 # if defined(OPENSSL_SYS_MSDOS)
34 # undef OPENSSL_SYS_UNIX
38 * For 32 bit environment, there seems to be the CygWin environment and then
39 * all the others that try to do the same thing Microsoft does...
42 * UEFI lives here because it might be built with a Microsoft toolchain and
43 * we need to avoid the false positive match on Windows.
45 # if defined(OPENSSL_SYS_UEFI)
46 # undef OPENSSL_SYS_UNIX
47 # elif defined(OPENSSL_SYS_UWIN)
48 # undef OPENSSL_SYS_UNIX
49 # define OPENSSL_SYS_WIN32_UWIN
51 # if defined(__CYGWIN__) || defined(OPENSSL_SYS_CYGWIN)
52 # undef OPENSSL_SYS_UNIX
53 # define OPENSSL_SYS_WIN32_CYGWIN
55 # if defined(_WIN32) || defined(OPENSSL_SYS_WIN32)
56 # undef OPENSSL_SYS_UNIX
57 # if !defined(OPENSSL_SYS_WIN32)
58 # define OPENSSL_SYS_WIN32
61 # if defined(_WIN64) || defined(OPENSSL_SYS_WIN64)
62 # undef OPENSSL_SYS_UNIX
63 # if !defined(OPENSSL_SYS_WIN64)
64 # define OPENSSL_SYS_WIN64
67 # if defined(OPENSSL_SYS_WINNT)
68 # undef OPENSSL_SYS_UNIX
70 # if defined(OPENSSL_SYS_WINCE)
71 # undef OPENSSL_SYS_UNIX
76 /* Anything that tries to look like Microsoft is "Windows" */
77 # if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN64) || defined(OPENSSL_SYS_WINNT) || defined(OPENSSL_SYS_WINCE)
78 # undef OPENSSL_SYS_UNIX
79 # define OPENSSL_SYS_WINDOWS
80 # ifndef OPENSSL_SYS_MSDOS
81 # define OPENSSL_SYS_MSDOS
86 * DLL settings. This part is a bit tough, because it's up to the
87 * application implementor how he or she will link the application, so it
88 * requires some macro to be used.
90 # ifdef OPENSSL_SYS_WINDOWS
91 # ifndef OPENSSL_OPT_WINDLL
92 # if defined(_WINDLL) /* This is used when building OpenSSL to
93 * indicate that DLL linkage should be used */
94 # define OPENSSL_OPT_WINDLL
99 /* ------------------------------- OpenVMS -------------------------------- */
100 # if defined(__VMS) || defined(VMS) || defined(OPENSSL_SYS_VMS)
101 # if !defined(OPENSSL_SYS_VMS)
102 # undef OPENSSL_SYS_UNIX
104 # define OPENSSL_SYS_VMS
106 # define OPENSSL_SYS_VMS_DECC
107 # elif defined(__DECCXX)
108 # define OPENSSL_SYS_VMS_DECC
109 # define OPENSSL_SYS_VMS_DECCXX
111 # define OPENSSL_SYS_VMS_NODECC
115 /* -------------------------------- Unix ---------------------------------- */
116 # ifdef OPENSSL_SYS_UNIX
117 # if defined(linux) || defined(__linux__) && !defined(OPENSSL_SYS_LINUX)
118 # define OPENSSL_SYS_LINUX
120 # if defined(_AIX) && !defined(OPENSSL_SYS_AIX)
121 # define OPENSSL_SYS_AIX
125 /* -------------------------------- VOS ----------------------------------- */
126 # if defined(__VOS__) && !defined(OPENSSL_SYS_VOS)
127 # define OPENSSL_SYS_VOS
129 # define OPENSSL_SYS_VOS_HPPA
132 # define OPENSSL_SYS_VOS_IA32
137 * That's it for OS-specific stuff
138 *****************************************************************************/
140 /* Specials for I/O an exit */
141 # ifdef OPENSSL_SYS_MSDOS
142 # define OPENSSL_UNISTD_IO <io.h>
143 # define OPENSSL_DECLARE_EXIT extern void exit(int);
145 # define OPENSSL_UNISTD_IO OPENSSL_UNISTD
146 # define OPENSSL_DECLARE_EXIT /* declared in unistd.h */
150 * OPENSSL_GLOBAL had some meaning for VAX C, which isn't supported any more.
151 * OPENSSL_EXTERN is normally used to declare a symbol with possible extra
152 * attributes to handle its presence in a shared library.
153 * OPENSSL_EXPORT is used to define a symbol with extra possible attributes
154 * to make it visible in a shared library.
155 * Care needs to be taken when a header file is used both to declare and
156 * define symbols. Basically, for any library that exports some global
157 * variables, the following code must be present in the header file that
158 * declares them, before OPENSSL_EXTERN is used:
160 * #ifdef SOME_BUILD_FLAG_MACRO
161 * # undef OPENSSL_EXTERN
162 * # define OPENSSL_EXTERN OPENSSL_EXPORT
165 * The default is to have OPENSSL_EXPORT, OPENSSL_EXTERN and OPENSSL_GLOBAL
166 * have some generally sensible values.
169 # if defined(OPENSSL_SYS_WINDOWS) && defined(OPENSSL_OPT_WINDLL)
170 # define OPENSSL_EXPORT extern __declspec(dllexport)
171 # define OPENSSL_EXTERN extern __declspec(dllimport)
172 # define OPENSSL_GLOBAL
174 # define OPENSSL_EXPORT extern
175 # define OPENSSL_EXTERN extern
176 # define OPENSSL_GLOBAL
180 * Macros to allow global variables to be reached through function calls when
181 * required (if a shared library version requires it, for example.
182 * The way it's done allows definitions like this:
185 * OPENSSL_IMPLEMENT_GLOBAL(int,foobar,0)
187 * OPENSSL_DECLARE_GLOBAL(int,foobar);
188 * #define foobar OPENSSL_GLOBAL_REF(foobar)
190 # ifdef OPENSSL_EXPORT_VAR_AS_FUNCTION
191 # define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) \
192 type *_shadow_##name(void) \
193 { static type _hide_##name=value; return &_hide_##name; }
194 # define OPENSSL_DECLARE_GLOBAL(type,name) type *_shadow_##name(void)
195 # define OPENSSL_GLOBAL_REF(name) (*(_shadow_##name()))
197 # define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) OPENSSL_GLOBAL type _shadow_##name=value;
198 # define OPENSSL_DECLARE_GLOBAL(type,name) OPENSSL_EXPORT type _shadow_##name
199 # define OPENSSL_GLOBAL_REF(name) _shadow_##name
204 # define ossl_ssize_t __int64
205 # define OSSL_SSIZE_MAX _I64_MAX
207 # define ossl_ssize_t int
208 # define OSSL_SSIZE_MAX INT_MAX
212 # if defined(OPENSSL_SYS_UEFI) && !defined(ssize_t)
213 # define ossl_ssize_t int
214 # define OSSL_SSIZE_MAX INT_MAX
217 # ifndef ossl_ssize_t
218 # define ossl_ssize_t ssize_t
219 # if defined(SSIZE_MAX)
220 # define OSSL_SSIZE_MAX SSIZE_MAX
221 # elif defined(_POSIX_SSIZE_MAX)
222 # define OSSL_SSIZE_MAX _POSIX_SSIZE_MAX
227 # define __owur __attribute__((__warn_unused_result__))
232 /* Standard integer types */
233 # if defined(OPENSSL_SYS_UEFI)
235 typedef UINT8 uint8_t;
236 typedef INT16 int16_t;
237 typedef UINT16 uint16_t;
238 typedef INT32 int32_t;
239 typedef UINT32 uint32_t;
240 typedef INT64 int64_t;
241 typedef UINT64 uint64_t;
242 # define PRIu64 "%Lu"
243 # elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
244 defined(__osf__) || defined(__sgi) || defined(__hpux) || \
245 defined(OPENSSL_SYS_VMS) || defined (__OpenBSD__)
246 # include <inttypes.h>
247 # elif defined(_MSC_VER) && _MSC_VER<=1500
249 * minimally required typdefs for systems not supporting inttypes.h or
250 * stdint.h: currently just older VC++
252 typedef signed char int8_t;
253 typedef unsigned char uint8_t;
254 typedef short int16_t;
255 typedef unsigned short uint16_t;
257 typedef unsigned int uint32_t;
258 typedef __int64 int64_t;
259 typedef unsigned __int64 uint64_t;
265 * We need a format operator for some client tools for uint64_t. If inttypes.h
266 * isn't available or did not define it, just go with hard-coded.
269 # ifdef SIXTY_FOUR_BIT_LONG
272 # define PRIu64 "llu"
276 /* Format specifier for printing size_t */
277 # if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
280 # ifdef THIRTY_TWO_BIT
283 # define OSSLzu PRIu64
287 /* ossl_inline: portable inline definition usable in public headers */
288 # if !defined(inline) && !defined(__cplusplus)
289 # if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
290 /* just use inline */
291 # define ossl_inline inline
292 # elif defined(__GNUC__) && __GNUC__>=2
293 # define ossl_inline __inline__
294 # elif defined(_MSC_VER)
296 * Visual Studio: inline is available in C++ only, however
297 * __inline is available for C, see
298 * http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx
300 # define ossl_inline __inline
305 # define ossl_inline inline
308 # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
309 # define ossl_noreturn _Noreturn
310 # elif defined(__GNUC__) && __GNUC__ >= 2
311 # define ossl_noreturn __attribute__((noreturn))
313 # define ossl_noreturn