2 * Copyright 1995-2018 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 # define OPENSSL_SYS_WIN32_CYGWIN
54 # if defined(_WIN32) || defined(OPENSSL_SYS_WIN32)
55 # undef OPENSSL_SYS_UNIX
56 # if !defined(OPENSSL_SYS_WIN32)
57 # define OPENSSL_SYS_WIN32
60 # if defined(_WIN64) || defined(OPENSSL_SYS_WIN64)
61 # undef OPENSSL_SYS_UNIX
62 # if !defined(OPENSSL_SYS_WIN64)
63 # define OPENSSL_SYS_WIN64
66 # if defined(OPENSSL_SYS_WINNT)
67 # undef OPENSSL_SYS_UNIX
69 # if defined(OPENSSL_SYS_WINCE)
70 # undef OPENSSL_SYS_UNIX
75 /* Anything that tries to look like Microsoft is "Windows" */
76 # if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN64) || defined(OPENSSL_SYS_WINNT) || defined(OPENSSL_SYS_WINCE)
77 # undef OPENSSL_SYS_UNIX
78 # define OPENSSL_SYS_WINDOWS
79 # ifndef OPENSSL_SYS_MSDOS
80 # define OPENSSL_SYS_MSDOS
85 * DLL settings. This part is a bit tough, because it's up to the
86 * application implementor how he or she will link the application, so it
87 * requires some macro to be used.
89 # ifdef OPENSSL_SYS_WINDOWS
90 # ifndef OPENSSL_OPT_WINDLL
91 # if defined(_WINDLL) /* This is used when building OpenSSL to
92 * indicate that DLL linkage should be used */
93 # define OPENSSL_OPT_WINDLL
98 /* ------------------------------- OpenVMS -------------------------------- */
99 # if defined(__VMS) || defined(VMS) || defined(OPENSSL_SYS_VMS)
100 # if !defined(OPENSSL_SYS_VMS)
101 # undef OPENSSL_SYS_UNIX
103 # define OPENSSL_SYS_VMS
105 # define OPENSSL_SYS_VMS_DECC
106 # elif defined(__DECCXX)
107 # define OPENSSL_SYS_VMS_DECC
108 # define OPENSSL_SYS_VMS_DECCXX
110 # define OPENSSL_SYS_VMS_NODECC
114 /* -------------------------------- Unix ---------------------------------- */
115 # ifdef OPENSSL_SYS_UNIX
116 # if defined(linux) || defined(__linux__) && !defined(OPENSSL_SYS_LINUX)
117 # define OPENSSL_SYS_LINUX
119 # if defined(_AIX) && !defined(OPENSSL_SYS_AIX)
120 # define OPENSSL_SYS_AIX
124 /* -------------------------------- VOS ----------------------------------- */
125 # if defined(__VOS__) && !defined(OPENSSL_SYS_VOS)
126 # define OPENSSL_SYS_VOS
128 # define OPENSSL_SYS_VOS_HPPA
131 # define OPENSSL_SYS_VOS_IA32
136 * That's it for OS-specific stuff
137 *****************************************************************************/
139 /* Specials for I/O an exit */
140 # ifdef OPENSSL_SYS_MSDOS
141 # define OPENSSL_UNISTD_IO <io.h>
142 # define OPENSSL_DECLARE_EXIT extern void exit(int);
144 # define OPENSSL_UNISTD_IO OPENSSL_UNISTD
145 # define OPENSSL_DECLARE_EXIT /* declared in unistd.h */
149 * Definitions of OPENSSL_GLOBAL and OPENSSL_EXTERN, to define and declare
150 * certain global symbols that, with some compilers under VMS, have to be
151 * defined and declared explicitly with globaldef and globalref.
152 * Definitions of OPENSSL_EXPORT and OPENSSL_IMPORT, to define and declare
153 * DLL exports and imports for compilers under Win32. These are a little
154 * more complicated to use. Basically, for any library that exports some
155 * global variables, the following code must be present in the header file
156 * that declares them, before OPENSSL_EXTERN is used:
158 * #ifdef SOME_BUILD_FLAG_MACRO
159 * # undef OPENSSL_EXTERN
160 * # define OPENSSL_EXTERN OPENSSL_EXPORT
163 * The default is to have OPENSSL_EXPORT, OPENSSL_EXTERN and OPENSSL_GLOBAL
164 * have some generally sensible values.
167 # if defined(OPENSSL_SYS_VMS_NODECC)
168 # define OPENSSL_EXPORT globalref
169 # define OPENSSL_EXTERN globalref
170 # define OPENSSL_GLOBAL globaldef
171 # elif defined(OPENSSL_SYS_WINDOWS) && defined(OPENSSL_OPT_WINDLL)
172 # define OPENSSL_EXPORT extern __declspec(dllexport)
173 # define OPENSSL_EXTERN extern __declspec(dllimport)
174 # define OPENSSL_GLOBAL
176 # define OPENSSL_EXPORT extern
177 # define OPENSSL_EXTERN extern
178 # define OPENSSL_GLOBAL
182 * Macros to allow global variables to be reached through function calls when
183 * required (if a shared library version requires it, for example.
184 * The way it's done allows definitions like this:
187 * OPENSSL_IMPLEMENT_GLOBAL(int,foobar,0)
189 * OPENSSL_DECLARE_GLOBAL(int,foobar);
190 * #define foobar OPENSSL_GLOBAL_REF(foobar)
192 # ifdef OPENSSL_EXPORT_VAR_AS_FUNCTION
193 # define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) \
194 type *_shadow_##name(void) \
195 { static type _hide_##name=value; return &_hide_##name; }
196 # define OPENSSL_DECLARE_GLOBAL(type,name) type *_shadow_##name(void)
197 # define OPENSSL_GLOBAL_REF(name) (*(_shadow_##name()))
199 # define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) OPENSSL_GLOBAL type _shadow_##name=value;
200 # define OPENSSL_DECLARE_GLOBAL(type,name) OPENSSL_EXPORT type _shadow_##name
201 # define OPENSSL_GLOBAL_REF(name) _shadow_##name
206 # define ossl_ssize_t __int64
207 # define OSSL_SSIZE_MAX _I64_MAX
209 # define ossl_ssize_t int
210 # define OSSL_SSIZE_MAX INT_MAX
214 # if defined(OPENSSL_SYS_UEFI) && !defined(ossl_ssize_t)
215 # define ossl_ssize_t INTN
216 # define OSSL_SSIZE_MAX MAX_INTN
219 # ifndef ossl_ssize_t
220 # define ossl_ssize_t ssize_t
221 # if defined(SSIZE_MAX)
222 # define OSSL_SSIZE_MAX SSIZE_MAX
223 # elif defined(_POSIX_SSIZE_MAX)
224 # define OSSL_SSIZE_MAX _POSIX_SSIZE_MAX
229 # define __owur __attribute__((__warn_unused_result__))
234 /* Standard integer types */
235 # if defined(OPENSSL_SYS_UEFI)
237 typedef UINT8 uint8_t;
238 typedef INT16 int16_t;
239 typedef UINT16 uint16_t;
240 typedef INT32 int32_t;
241 typedef UINT32 uint32_t;
242 typedef INT64 int64_t;
243 typedef UINT64 uint64_t;
244 # elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
245 defined(__osf__) || defined(__sgi) || defined(__hpux) || \
246 defined(OPENSSL_SYS_VMS) || defined (__OpenBSD__)
247 # include <inttypes.h>
248 # elif defined(_MSC_VER) && _MSC_VER<=1500
250 * minimally required typdefs for systems not supporting inttypes.h or
251 * stdint.h: currently just older VC++
253 typedef signed char int8_t;
254 typedef unsigned char uint8_t;
255 typedef short int16_t;
256 typedef unsigned short uint16_t;
258 typedef unsigned int uint32_t;
259 typedef __int64 int64_t;
260 typedef unsigned __int64 uint64_t;
265 /* ossl_inline: portable inline definition usable in public headers */
266 # if !defined(inline) && !defined(__cplusplus)
267 # if defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
268 /* just use inline */
269 # define ossl_inline inline
270 # elif defined(__GNUC__) && __GNUC__>=2
271 # define ossl_inline __inline__
272 # elif defined(_MSC_VER)
274 * Visual Studio: inline is available in C++ only, however
275 * __inline is available for C, see
276 * http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx
278 # define ossl_inline __inline
283 # define ossl_inline inline
286 # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
287 # define ossl_noreturn _Noreturn
288 # elif defined(__GNUC__) && __GNUC__ >= 2
289 # define ossl_noreturn __attribute__((noreturn))
291 # define ossl_noreturn