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
11 # define HEADER_E_OS_H
13 # include <openssl/opensslconf.h>
15 # include <openssl/e_os2.h>
16 # include <openssl/crypto.h>
18 * <openssl/e_os2.h> contains what we can justify to make visible to the
19 * outside; this file e_os.h is not part of the exported interface.
26 /* Used to checking reference counts, most while doing perl5 stuff :-) */
27 # if defined(OPENSSL_NO_STDIO)
28 # if defined(REF_PRINT)
29 # error "REF_PRINT requires stdio"
34 * Format specifier for printing size_t. Original conundrum was to
35 * get it working with -Wformat [-Werror], which can be considered
36 * overzelaous, especially in multi-platform context, but it's
40 # define OSSLzu "I64u" /* One would expect _WIN{64|32} cases after
41 * __STDC_VERSION__, but there are corner
42 * cases of MinGW compilers that link with
43 * non-compliant MSVCRT.DLL... */
44 # elif defined(_WIN32)
47 # define OSSLzu "u" /* VMS suffers from similar problem as MinGW,
48 * i.e. C RTL falling behind compiler. Recall
49 * that sizeof(size_t)==4 even in LP64 case. */
50 # elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
52 # elif defined(__SIZEOF_SIZE_T__) && __SIZEOF_SIZE_T__==4
53 # define OSSLzu "u" /* 'lu' should have worked, but when generating
54 * 32-bit code gcc still complains :-( */
56 # define OSSLzu "lu" /* To see that is works recall what does L
57 * stand for in ILP32 and LP64 */
60 # if !defined(NDEBUG) && !defined(OPENSSL_NO_STDIO)
61 # define REF_ASSERT_ISNT(test) \
62 (void)((test) ? (OPENSSL_die("refcount error", __FILE__, __LINE__), 1) : 0)
64 # define REF_ASSERT_ISNT(i)
67 # define REF_PRINT_COUNT(a, b) \
68 fprintf(stderr, "%p:%4d:%s\n", b, b->references, a)
70 # define REF_PRINT_COUNT(a, b)
73 # define osslargused(x) (void)x
74 # define OPENSSL_CONF "openssl.cnf"
78 * set this to a comma-separated list of 'random' device files to try out. By
79 * default, we will try to read at least one of these files
81 # define DEVRANDOM "/dev/urandom","/dev/random","/dev/srandom"
83 # if !defined(OPENSSL_NO_EGD) && !defined(DEVRANDOM_EGD)
85 * set this to a comma-separated list of 'egd' sockets to try out. These
86 * sockets will be tried in the order listed in case accessing the device
87 * files listed in DEVRANDOM did not return enough randomness.
89 # define DEVRANDOM_EGD "/var/run/egd-pool","/dev/egd-pool","/etc/egd-pool","/etc/entropy"
92 # if defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI)
93 # define NO_SYS_PARAM_H
98 /********************************************************************
100 ********************************************************************/
101 # if defined(OPENSSL_SYS_WIN32) && !defined(WIN32)
104 # if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS)
107 # if defined(OPENSSL_SYS_MSDOS) && !defined(MSDOS)
111 # if (defined(MSDOS) || defined(OPENSSL_SYS_UEFI)) && !defined(GETPID_IS_MEANINGLESS)
112 # define GETPID_IS_MEANINGLESS
117 # define get_last_sys_error() GetLastError()
118 # define clear_sys_error() SetLastError(0)
120 # define WIN_CONSOLE_BUG
123 # define get_last_sys_error() errno
124 # define clear_sys_error() errno=0
127 # if defined(WINDOWS)
128 # define get_last_socket_error() WSAGetLastError()
129 # define clear_socket_error() WSASetLastError(0)
130 # define readsocket(s,b,n) recv((s),(b),(n),0)
131 # define writesocket(s,b,n) send((s),(b),(n),0)
132 # elif defined(__DJGPP__)
134 # define WATT32_NO_OLDIES
135 # define get_last_socket_error() errno
136 # define clear_socket_error() errno=0
137 # define closesocket(s) close_s(s)
138 # define readsocket(s,b,n) read_s(s,b,n)
139 # define writesocket(s,b,n) send(s,b,n,0)
140 # elif defined(OPENSSL_SYS_VMS)
141 # define get_last_socket_error() errno
142 # define clear_socket_error() errno=0
143 # define ioctlsocket(a,b,c) ioctl(a,b,c)
144 # define closesocket(s) close(s)
145 # define readsocket(s,b,n) recv((s),(b),(n),0)
146 # define writesocket(s,b,n) send((s),(b),(n),0)
147 # elif defined(OPENSSL_SYS_VXWORKS)
148 # define get_last_socket_error() errno
149 # define clear_socket_error() errno=0
150 # define ioctlsocket(a,b,c) ioctl((a),(b),(int)(c))
151 # define closesocket(s) close(s)
152 # define readsocket(s,b,n) read((s),(b),(n))
153 # define writesocket(s,b,n) write((s),(char *)(b),(n))
155 # define get_last_socket_error() errno
156 # define clear_socket_error() errno=0
157 # define ioctlsocket(a,b,c) ioctl(a,b,c)
158 # define closesocket(s) close(s)
159 # define readsocket(s,b,n) read((s),(b),(n))
160 # define writesocket(s,b,n) write((s),(b),(n))
163 # if (defined(WINDOWS) || defined(MSDOS))
167 # include <sys/stat.h>
168 # include <sys/socket.h>
172 # define _setmode setmode
173 # define _O_TEXT O_TEXT
174 # define _O_BINARY O_BINARY
175 # define HAS_LFN_SUPPORT(name) (pathconf((name), _PC_NAME_MAX) > 12)
176 # undef DEVRANDOM_EGD /* Neither MS-DOS nor FreeDOS provide 'egd' sockets. */
178 # define DEVRANDOM "/dev/urandom\x24"
179 # endif /* __DJGPP__ */
182 # define S_IFDIR _S_IFDIR
186 # define S_IFMT _S_IFMT
189 # if !defined(WINNT) && !defined(__DJGPP__)
195 # if !defined(_WIN32_WCE) && !defined(_WIN32_WINNT)
197 * Defining _WIN32_WINNT here in e_os.h implies certain "discipline."
198 * Most notably we ought to check for availability of each specific
199 * routine that was introduced after denoted _WIN32_WINNT with
200 * GetProcAddress(). Normally newer functions are masked with higher
201 * _WIN32_WINNT in SDK headers. So that if you wish to use them in
202 * some module, you'd need to override _WIN32_WINNT definition in
203 * the target module in order to "reach for" prototypes, but replace
204 * calls to new functions with indirect calls. Alternatively it
205 * might be possible to achieve the goal by /DELAYLOAD-ing .DLLs
206 * and check for current OS version instead.
208 # define _WIN32_WINNT 0x0501
210 # if defined(_WIN32_WINNT) || defined(_WIN32_WCE)
212 * Just like defining _WIN32_WINNT including winsock2.h implies
213 * certain "discipline" for maintaining [broad] binary compatibility.
214 * As long as structures are invariant among Winsock versions,
215 * it's sufficient to check for specific Winsock2 API availability
216 * at run-time [DSO_global_lookup is recommended]...
218 # include <winsock2.h>
219 # include <ws2tcpip.h>
220 /* yes, they have to be #included prior to <windows.h> */
222 # include <windows.h>
226 # if defined(_WIN32_WCE) && !defined(EACCES)
231 # define strlen(s) _strlen31(s)
232 /* cut strings to 2GB */
233 static __inline unsigned int _strlen31(const char *str)
235 unsigned int len = 0;
236 while (*str && len < 0x80000000U)
238 return len & 0x7FFFFFFF;
242 # if defined(_MSC_VER) && _MSC_VER<=1200 && defined(_MT) && defined(isspace)
243 /* compensate for bug in VC6 ctype.h */
250 # if defined(_MSC_VER) && !defined(_WIN32_WCE) && !defined(_DLL) && defined(stdin)
251 # if _MSC_VER>=1300 && _MSC_VER<1600
256 # define stdin (&__iob_func()[0])
257 # define stdout (&__iob_func()[1])
258 # define stderr (&__iob_func()[2])
259 # elif _MSC_VER<1300 && defined(I_CAN_LIVE_WITH_LNK4049)
264 * pre-1300 has __p__iob(), but it's available only in msvcrt.lib,
265 * or in other words with /MD. Declaring implicit import, i.e. with
266 * _imp_ prefix, works correctly with all compiler options, but
267 * without /MD results in LINK warning LNK4049: 'locally defined
268 * symbol "__iob" imported'.
270 extern FILE *_imp___iob;
271 # define stdin (&_imp___iob[0])
272 # define stdout (&_imp___iob[1])
273 # define stderr (&_imp___iob[2])
280 # ifdef OPENSSL_SYS_WINCE
281 # define OPENSSL_NO_POSIX_IO
284 # define EXIT(n) exit(n)
285 # define LIST_SEPARATOR_CHAR ';'
295 # ifdef OPENSSL_SYS_WINCE
296 # define DEFAULT_HOME ""
298 # define DEFAULT_HOME "C:"
301 /* Avoid Visual Studio 13 GetVersion deprecated problems */
302 # if defined(_MSC_VER) && _MSC_VER>=1800
303 # define check_winnt() (1)
304 # define check_win_minplat(x) (1)
306 # define check_winnt() (GetVersion() < 0x80000000)
307 # define check_win_minplat(x) (LOBYTE(LOWORD(GetVersion())) >= (x))
310 # else /* The non-microsoft world */
312 # ifdef OPENSSL_SYS_VMS
315 * some programs don't include stdlib, so exit() and others give implicit
322 # include <unixlib.h>
324 # define LIST_SEPARATOR_CHAR ','
325 /* We don't have any well-defined random devices on VMS, yet... */
328 We need to do this since VMS has the following coding on status codes:
330 Bits 0-2: status type: 0 = warning, 1 = success, 2 = error, 3 = info ...
331 The important thing to know is that odd numbers are considered
332 good, while even ones are considered errors.
333 Bits 3-15: actual status number
334 Bits 16-27: facility number. 0 is considered "unknown"
335 Bits 28-31: control bits. If bit 28 is set, the shell won't try to
336 output the message (which, for random codes, just looks ugly)
338 So, what we do here is to change 0 to 1 to get the default success status,
339 and everything else is shifted up to fit into the status number field, and
340 the status is tagged as an error, which is what is wanted here.
342 Finally, we add the VMS C facility code 0x35a000, because there are some
343 programs, such as Perl, that will reinterpret the code back to something
344 POSIXly. 'man perlvms' explains it further.
346 NOTE: the perlvms manual wants to turn all codes 2 to 255 into success
347 codes (status type = 1). I couldn't disagree more. Fortunately, the
348 status type doesn't seem to bother Perl.
351 # define EXIT(n) exit((n) ? (((n) << 3) | 2 | 0x10000000 | 0x35a000) : 1)
353 # define NO_SYS_PARAM_H
356 # define DEFAULT_HOME "SYS$LOGIN:"
360 # ifdef OPENSSL_UNISTD
361 # include OPENSSL_UNISTD
365 # ifndef NO_SYS_TYPES_H
366 # include <sys/types.h>
368 # ifdef OPENSSL_SYS_WIN32_CYGWIN
373 # define LIST_SEPARATOR_CHAR ':'
374 # define EXIT(n) exit(n)
382 # ifdef OPENSSL_NO_SOCK
383 # elif defined(WINDOWS) || defined(MSDOS)
385 # if !defined(__DJGPP__)
386 # if defined(_WIN32_WCE) && _WIN32_WCE<410
387 # define getservbyname _masked_declaration_getservbyname
389 # if !defined(IPPROTO_IP)
390 /* winsock[2].h was included already? */
391 # include <winsock.h>
393 # ifdef getservbyname
394 # undef getservbyname
395 /* this is used to be wcecompat/include/winsock_extras.h */
396 struct servent *PASCAL getservbyname(const char *, const char *);
401 * Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because
402 * the value constitutes an index in per-process table of limited size
403 * and not a real pointer. And we also depend on fact that all processors
404 * Windows run on happen to be two's-complement, which allows to
405 * interchange INVALID_SOCKET and -1.
407 # define socket(d,t,p) ((int)socket(d,t,p))
408 # define accept(s,f,l) ((int)accept(s,f,l))
415 # ifndef NO_SYS_PARAM_H
416 # include <sys/param.h>
418 # ifdef OPENSSL_SYS_VXWORKS
423 # if defined(OPENSSL_SYS_VMS_NODECC)
428 # include <sys/socket.h>
430 # ifdef OPENSSL_SYS_VXWORKS
431 # include <streams/un.h>
435 # ifndef UNIX_PATH_MAX
436 # define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
440 # include <sys/filio.h> /* FIONBIO in some SVR4, e.g. unixware, solaris */
442 # include <netinet/in.h>
443 # include <arpa/inet.h>
444 # include <netinet/tcp.h>
447 # ifdef OPENSSL_SYS_AIX
448 # include <sys/select.h>
452 # include <sys/select.h>
456 # include <sys/ioctl.h>
458 /* ioctl is only in VMS > 7.0 and when socketshr is not used */
459 # if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000)
460 # include <sys/ioctl.h>
466 # if defined(TCPIP_TYPE_SOCKETSHR)
467 # include <socketshr.h>
471 # ifndef INVALID_SOCKET
472 # define INVALID_SOCKET (-1)
473 # endif /* INVALID_SOCKET */
477 * Some IPv6 implementations are broken, disable them in known bad versions.
479 # if !defined(OPENSSL_USE_IPV6)
480 # if defined(AF_INET6) && !defined(NETWARE_CLIB)
481 # define OPENSSL_USE_IPV6 1
483 # define OPENSSL_USE_IPV6 0
489 # ifndef OPENSSL_EXIT
490 # if defined(MONOLITH) && !defined(OPENSSL_C)
491 # define OPENSSL_EXIT(n) return(n)
493 # define OPENSSL_EXIT(n) do { EXIT(n); return(n); } while(0)
497 /***********************************************/
499 # if defined(OPENSSL_SYS_WINDOWS)
500 # define strcasecmp _stricmp
501 # define strncasecmp _strnicmp
502 # if (_MSC_VER >= 1310)
504 # define fdopen _fdopen
505 # define close _close
507 # define strdup _strdup
509 # define unlink _unlink
512 # include <strings.h>
516 # if defined(OPENSSL_SYS_VXWORKS)
518 # include <tickLib.h>
521 # define TTY_STRUCT int
523 # define sleep(a) taskDelay((a) * sysClkRateGet())
525 # include <vxWorks.h>
526 # include <sockLib.h>
527 # include <taskLib.h>
529 # define getpid taskIdSelf
532 * NOTE: these are implemented by helpers in database app! if the database is
533 * not linked, we need to implement them elswhere
535 struct hostent *gethostbyname(const char *name);
536 struct hostent *gethostbyaddr(const char *addr, int length, int type);
537 struct servent *getservbyname(const char *name, const char *proto);
542 #define OSSL_NELEM(x) (sizeof(x)/sizeof((x)[0]))
544 #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
545 # define CRYPTO_memcmp memcmp