2 * Copyright 1995-2020 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
14 # include <openssl/opensslconf.h>
16 # include <openssl/e_os2.h>
17 # include <openssl/crypto.h>
18 # include "internal/nelem.h"
21 * <openssl/e_os2.h> contains what we can justify to make visible to the
22 * outside; this file e_os.h is not part of the exported interface.
27 * set this to a comma-separated list of 'random' device files to try out. By
28 * default, we will try to read at least one of these files
30 # define DEVRANDOM "/dev/urandom", "/dev/random", "/dev/hwrng", "/dev/srandom"
31 # if defined(__linux) && !defined(__ANDROID__)
33 * Linux kernels 4.8 and later changes how their random device works and there
34 * is no reliable way to tell that /dev/urandom has been seeded -- getentropy(2)
35 * should be used instead.
37 # ifndef DEVRANDOM_SAFE_KERNEL
38 # define DEVRANDOM_SAFE_KERNEL 4, 8
41 * Some operating systems do not permit select(2) on their random devices,
42 * defining this to zero will force the use of read(2) to extract one byte
45 # ifndef DEVRANDM_WAIT_USE_SELECT
46 # define DEVRANDM_WAIT_USE_SELECT 1
49 * Define the shared memory identifier used to indicate if the operating
50 * system has properly seeded the DEVRANDOM source.
52 # ifndef OPENSSL_RAND_SEED_DEVRANDOM_SHM_ID
53 # define OPENSSL_RAND_SEED_DEVRANDOM_SHM_ID 114
58 # if !defined(OPENSSL_NO_EGD) && !defined(DEVRANDOM_EGD)
60 * set this to a comma-separated list of 'egd' sockets to try out. These
61 * sockets will be tried in the order listed in case accessing the device
62 * files listed in DEVRANDOM did not return enough randomness.
64 # define DEVRANDOM_EGD "/var/run/egd-pool", "/dev/egd-pool", "/etc/egd-pool", "/etc/entropy"
67 # if defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI)
72 # define get_last_sys_error() errno
73 # define clear_sys_error() errno=0
74 # define set_sys_error(e) errno=(e)
76 /********************************************************************
78 ********************************************************************/
79 # if defined(OPENSSL_SYS_WIN32) && !defined(WIN32)
82 # if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS)
85 # if defined(OPENSSL_SYS_MSDOS) && !defined(MSDOS)
90 # undef get_last_sys_error
91 # undef clear_sys_error
93 # define get_last_sys_error() GetLastError()
94 # define clear_sys_error() SetLastError(0)
95 # define set_sys_error(e) SetLastError(e)
97 # define WIN_CONSOLE_BUG
102 # if (defined(WINDOWS) || defined(MSDOS))
106 # include <sys/stat.h>
107 # define _setmode setmode
108 # define _O_TEXT O_TEXT
109 # define _O_BINARY O_BINARY
110 # define HAS_LFN_SUPPORT(name) (pathconf((name), _PC_NAME_MAX) > 12)
111 # undef DEVRANDOM_EGD /* Neither MS-DOS nor FreeDOS provide 'egd' sockets. */
113 # define DEVRANDOM "/dev/urandom\x24"
114 # endif /* __DJGPP__ */
117 # define S_IFDIR _S_IFDIR
121 # define S_IFMT _S_IFMT
124 # if !defined(WINNT) && !defined(__DJGPP__)
129 # if !defined(_WIN32_WCE) && !defined(_WIN32_WINNT)
131 * Defining _WIN32_WINNT here in e_os.h implies certain "discipline."
132 * Most notably we ought to check for availability of each specific
133 * routine that was introduced after denoted _WIN32_WINNT with
134 * GetProcAddress(). Normally newer functions are masked with higher
135 * _WIN32_WINNT in SDK headers. So that if you wish to use them in
136 * some module, you'd need to override _WIN32_WINNT definition in
137 * the target module in order to "reach for" prototypes, but replace
138 * calls to new functions with indirect calls. Alternatively it
139 * might be possible to achieve the goal by /DELAYLOAD-ing .DLLs
140 * and check for current OS version instead.
142 # define _WIN32_WINNT 0x0501
144 # if defined(_WIN32_WINNT) || defined(_WIN32_WCE)
146 * Just like defining _WIN32_WINNT including winsock2.h implies
147 * certain "discipline" for maintaining [broad] binary compatibility.
148 * As long as structures are invariant among Winsock versions,
149 * it's sufficient to check for specific Winsock2 API availability
150 * at run-time [DSO_global_lookup is recommended]...
152 # include <winsock2.h>
153 # include <ws2tcpip.h>
154 /* yes, they have to be #included prior to <windows.h> */
156 # include <windows.h>
160 # if defined(_WIN32_WCE) && !defined(EACCES)
165 # define strlen(s) _strlen31(s)
166 /* cut strings to 2GB */
167 static __inline unsigned int _strlen31(const char *str)
169 unsigned int len = 0;
170 while (*str && len < 0x80000000U)
172 return len & 0x7FFFFFFF;
176 # if defined(_MSC_VER) && !defined(_WIN32_WCE) && !defined(_DLL) && defined(stdin)
177 # if _MSC_VER>=1300 && _MSC_VER<1600
182 # define stdin (&__iob_func()[0])
183 # define stdout (&__iob_func()[1])
184 # define stderr (&__iob_func()[2])
185 # elif _MSC_VER<1300 && defined(I_CAN_LIVE_WITH_LNK4049)
190 * pre-1300 has __p__iob(), but it's available only in msvcrt.lib,
191 * or in other words with /MD. Declaring implicit import, i.e. with
192 * _imp_ prefix, works correctly with all compiler options, but
193 * without /MD results in LINK warning LNK4049: 'locally defined
194 * symbol "__iob" imported'.
196 extern FILE *_imp___iob;
197 # define stdin (&_imp___iob[0])
198 # define stdout (&_imp___iob[1])
199 # define stderr (&_imp___iob[2])
206 # ifdef OPENSSL_SYS_WINCE
207 # define OPENSSL_NO_POSIX_IO
210 # define EXIT(n) exit(n)
211 # define LIST_SEPARATOR_CHAR ';'
218 # ifdef OPENSSL_SYS_WINCE
219 # define DEFAULT_HOME ""
221 # define DEFAULT_HOME "C:"
224 /* Avoid Visual Studio 13 GetVersion deprecated problems */
225 # if defined(_MSC_VER) && _MSC_VER>=1800
226 # define check_winnt() (1)
227 # define check_win_minplat(x) (1)
229 # define check_winnt() (GetVersion() < 0x80000000)
230 # define check_win_minplat(x) (LOBYTE(LOWORD(GetVersion())) >= (x))
233 # else /* The non-microsoft world */
235 # if defined(OPENSSL_SYS_VXWORKS)
236 # include <sys/times.h>
238 # include <sys/time.h>
241 # ifdef OPENSSL_SYS_VMS
244 * some programs don't include stdlib, so exit() and others give implicit
251 # include <unixlib.h>
253 # define LIST_SEPARATOR_CHAR ','
254 /* We don't have any well-defined random devices on VMS, yet... */
257 We need to do this since VMS has the following coding on status codes:
259 Bits 0-2: status type: 0 = warning, 1 = success, 2 = error, 3 = info ...
260 The important thing to know is that odd numbers are considered
261 good, while even ones are considered errors.
262 Bits 3-15: actual status number
263 Bits 16-27: facility number. 0 is considered "unknown"
264 Bits 28-31: control bits. If bit 28 is set, the shell won't try to
265 output the message (which, for random codes, just looks ugly)
267 So, what we do here is to change 0 to 1 to get the default success status,
268 and everything else is shifted up to fit into the status number field, and
269 the status is tagged as an error, which is what is wanted here.
271 Finally, we add the VMS C facility code 0x35a000, because there are some
272 programs, such as Perl, that will reinterpret the code back to something
273 POSIX. 'man perlvms' explains it further.
275 NOTE: the perlvms manual wants to turn all codes 2 to 255 into success
276 codes (status type = 1). I couldn't disagree more. Fortunately, the
277 status type doesn't seem to bother Perl.
280 # define EXIT(n) exit((n) ? (((n) << 3) | 2 | 0x10000000 | 0x35a000) : 1)
282 # define DEFAULT_HOME "SYS$LOGIN:"
286 # ifdef OPENSSL_UNISTD
287 # include OPENSSL_UNISTD
291 # include <sys/types.h>
292 # ifdef OPENSSL_SYS_WIN32_CYGWIN
297 # define LIST_SEPARATOR_CHAR ':'
298 # define EXIT(n) exit(n)
303 /***********************************************/
305 # if defined(OPENSSL_SYS_WINDOWS)
306 # define strcasecmp _stricmp
307 # define strncasecmp _strnicmp
308 # if (_MSC_VER >= 1310) && !defined(_WIN32_WCE)
310 # define fdopen _fdopen
311 # define close _close
313 # define strdup _strdup
315 # define unlink _unlink
316 # define fileno _fileno
319 # include <strings.h>
323 # if defined(OPENSSL_SYS_VXWORKS)
325 # include <tickLib.h>
327 # include <vxWorks.h>
328 # include <sockLib.h>
329 # include <taskLib.h>
331 # define TTY_STRUCT int
332 # define sleep(a) taskDelay((a) * sysClkRateGet())
335 * NOTE: these are implemented by helpers in database app! if the database is
336 * not linked, we need to implement them elsewhere
338 struct hostent *gethostbyname(const char *name);
339 struct hostent *gethostbyaddr(const char *addr, int length, int type);
340 struct servent *getservbyname(const char *name, const char *proto);
345 # ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
346 # define CRYPTO_memcmp memcmp
349 /* unistd.h defines _POSIX_VERSION */
350 # if !defined(OPENSSL_NO_SECURE_MEMORY) && defined(OPENSSL_SYS_UNIX) \
351 && ( (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) \
352 || defined(__sun) || defined(__hpux) || defined(__sgi) \
353 || defined(__osf__) )
354 # define OPENSSL_SECURE_MEMORY /* secure memory is implemented */