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>
17 * <openssl/e_os2.h> contains what we can justify to make visible to the
18 * outside; this file e_os.h is not part of the exported interface.
25 /* Used to checking reference counts, most while doing perl5 stuff :-) */
26 # if defined(OPENSSL_NO_STDIO)
27 # if defined(REF_PRINT)
28 # error "REF_PRINT requires stdio"
33 * Format specifier for printing size_t. Original conundrum was to
34 * get it working with -Wformat [-Werror], which can be considered
35 * overzelaous, especially in multi-platform context, but it's
39 # define OSSLzu "I64u" /* One would expect _WIN{64|32} cases after
40 * __STDC_VERSION__, but there are corner
41 * cases of MinGW compilers that link with
42 * non-compliant MSVCRT.DLL... */
43 # elif defined(_WIN32)
46 # define OSSLzu "u" /* VMS suffers from similar problem as MinGW,
47 * i.e. C RTL falling behind compiler. Recall
48 * that sizeof(size_t)==4 even in LP64 case. */
49 # elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
51 # elif defined(__SIZEOF_SIZE_T__) && __SIZEOF_SIZE_T__==4
52 # define OSSLzu "u" /* 'lu' should have worked, but when generating
53 * 32-bit code gcc still complains :-( */
55 # define OSSLzu "lu" /* To see that is works recall what does L
56 * stand for in ILP32 and LP64 */
59 # if !defined(NDEBUG) && !defined(OPENSSL_NO_STDIO)
60 # define REF_ASSERT_ISNT(test) \
61 (void)((test) ? (OPENSSL_die("refcount error", __FILE__, __LINE__), 1) : 0)
63 # define REF_ASSERT_ISNT(i)
66 # define REF_PRINT_COUNT(a, b) \
67 fprintf(stderr, "%p:%4d:%s\n", b, b->references, a)
69 # define REF_PRINT_COUNT(a, b)
72 # define osslargused(x) (void)x
73 # define OPENSSL_CONF "openssl.cnf"
77 * set this to a comma-separated list of 'random' device files to try out. My
78 * default, we will try to read at least one of these files
80 # define DEVRANDOM "/dev/urandom","/dev/random","/dev/srandom"
82 # if !defined(OPENSSL_NO_EGD) && !defined(DEVRANDOM_EGD)
84 * set this to a comma-separated list of 'egd' sockets to try out. These
85 * sockets will be tried in the order listed in case accessing the device
86 * files listed in DEVRANDOM did not return enough entropy.
88 # define DEVRANDOM_EGD "/var/run/egd-pool","/dev/egd-pool","/etc/egd-pool","/etc/entropy"
91 # if defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI)
92 # define NO_SYS_PARAM_H
97 /********************************************************************
99 ********************************************************************/
100 # if defined(OPENSSL_SYS_WIN32) && !defined(WIN32)
103 # if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS)
106 # if defined(OPENSSL_SYS_MSDOS) && !defined(MSDOS)
110 # if (defined(MSDOS) || defined(OPENSSL_SYS_UEFI)) && !defined(GETPID_IS_MEANINGLESS)
111 # define GETPID_IS_MEANINGLESS
116 # define get_last_sys_error() GetLastError()
117 # define clear_sys_error() SetLastError(0)
119 # define WIN_CONSOLE_BUG
122 # define get_last_sys_error() errno
123 # define clear_sys_error() errno=0
126 # if defined(WINDOWS)
127 # define get_last_socket_error() WSAGetLastError()
128 # define clear_socket_error() WSASetLastError(0)
129 # define readsocket(s,b,n) recv((s),(b),(n),0)
130 # define writesocket(s,b,n) send((s),(b),(n),0)
131 # elif defined(__DJGPP__)
133 # define WATT32_NO_OLDIES
134 # define get_last_socket_error() errno
135 # define clear_socket_error() errno=0
136 # define closesocket(s) close_s(s)
137 # define readsocket(s,b,n) read_s(s,b,n)
138 # define writesocket(s,b,n) send(s,b,n,0)
139 # elif defined(OPENSSL_SYS_VMS)
140 # define get_last_socket_error() errno
141 # define clear_socket_error() errno=0
142 # define ioctlsocket(a,b,c) ioctl(a,b,c)
143 # define closesocket(s) close(s)
144 # define readsocket(s,b,n) recv((s),(b),(n),0)
145 # define writesocket(s,b,n) send((s),(b),(n),0)
146 # elif defined(OPENSSL_SYS_VXWORKS)
147 # define get_last_socket_error() errno
148 # define clear_socket_error() errno=0
149 # define ioctlsocket(a,b,c) ioctl((a),(b),(int)(c))
150 # define closesocket(s) close(s)
151 # define readsocket(s,b,n) read((s),(b),(n))
152 # define writesocket(s,b,n) write((s),(char *)(b),(n))
154 # define get_last_socket_error() errno
155 # define clear_socket_error() errno=0
156 # define ioctlsocket(a,b,c) ioctl(a,b,c)
157 # define closesocket(s) close(s)
158 # define readsocket(s,b,n) read((s),(b),(n))
159 # define writesocket(s,b,n) write((s),(b),(n))
162 # if (defined(WINDOWS) || defined(MSDOS))
166 # include <sys/stat.h>
167 # include <sys/socket.h>
171 # define _setmode setmode
172 # define _O_TEXT O_TEXT
173 # define _O_BINARY O_BINARY
174 # define HAS_LFN_SUPPORT(name) (pathconf((name), _PC_NAME_MAX) > 12)
175 # undef DEVRANDOM_EGD /* Neither MS-DOS nor FreeDOS provide 'egd' sockets. */
177 # define DEVRANDOM "/dev/urandom\x24"
178 # endif /* __DJGPP__ */
181 # define S_IFDIR _S_IFDIR
185 # define S_IFMT _S_IFMT
188 # if !defined(WINNT) && !defined(__DJGPP__)
194 # if !defined(_WIN32_WCE) && !defined(_WIN32_WINNT)
196 * Defining _WIN32_WINNT here in e_os.h implies certain "discipline."
197 * Most notably we ought to check for availability of each specific
198 * routine that was introduced after denoted _WIN32_WINNT with
199 * GetProcAddress(). Normally newer functions are masked with higher
200 * _WIN32_WINNT in SDK headers. So that if you wish to use them in
201 * some module, you'd need to override _WIN32_WINNT definition in
202 * the target module in order to "reach for" prototypes, but replace
203 * calls to new functions with indirect calls. Alternatively it
204 * might be possible to achieve the goal by /DELAYLOAD-ing .DLLs
205 * and check for current OS version instead.
207 # define _WIN32_WINNT 0x0501
209 # if defined(_WIN32_WINNT) || defined(_WIN32_WCE)
211 * Just like defining _WIN32_WINNT including winsock2.h implies
212 * certain "discipline" for maintaining [broad] binary compatibility.
213 * As long as structures are invariant among Winsock versions,
214 * it's sufficient to check for specific Winsock2 API availability
215 * at run-time [DSO_global_lookup is recommended]...
217 # include <winsock2.h>
218 # include <ws2tcpip.h>
219 /* yes, they have to be #included prior to <windows.h> */
221 # include <windows.h>
225 # if defined(_WIN32_WCE) && !defined(EACCES)
230 # define strlen(s) _strlen31(s)
231 /* cut strings to 2GB */
232 static __inline unsigned int _strlen31(const char *str)
234 unsigned int len = 0;
235 while (*str && len < 0x80000000U)
237 return len & 0x7FFFFFFF;
241 # if defined(_MSC_VER) && _MSC_VER<=1200 && defined(_MT) && defined(isspace)
242 /* compensate for bug in VC6 ctype.h */
249 # if defined(_MSC_VER) && !defined(_WIN32_WCE) && !defined(_DLL) && defined(stdin)
250 # if _MSC_VER>=1300 && _MSC_VER<1600
255 # define stdin (&__iob_func()[0])
256 # define stdout (&__iob_func()[1])
257 # define stderr (&__iob_func()[2])
258 # elif _MSC_VER<1300 && defined(I_CAN_LIVE_WITH_LNK4049)
263 * pre-1300 has __p__iob(), but it's available only in msvcrt.lib,
264 * or in other words with /MD. Declaring implicit import, i.e. with
265 * _imp_ prefix, works correctly with all compiler options, but
266 * without /MD results in LINK warning LNK4049: 'locally defined
267 * symbol "__iob" imported'.
269 extern FILE *_imp___iob;
270 # define stdin (&_imp___iob[0])
271 # define stdout (&_imp___iob[1])
272 # define stderr (&_imp___iob[2])
279 # ifdef OPENSSL_SYS_WINCE
280 # define OPENSSL_NO_POSIX_IO
283 # define EXIT(n) exit(n)
284 # define LIST_SEPARATOR_CHAR ';'
294 # ifdef OPENSSL_SYS_WINCE
295 # define DEFAULT_HOME ""
297 # define DEFAULT_HOME "C:"
300 /* Avoid Visual Studio 13 GetVersion deprecated problems */
301 # if defined(_MSC_VER) && _MSC_VER>=1800
302 # define check_winnt() (1)
303 # define check_win_minplat(x) (1)
305 # define check_winnt() (GetVersion() < 0x80000000)
306 # define check_win_minplat(x) (LOBYTE(LOWORD(GetVersion())) >= (x))
309 # else /* The non-microsoft world */
311 # ifdef OPENSSL_SYS_VMS
314 * some programs don't include stdlib, so exit() and others give implicit
321 # include <unixlib.h>
323 # define LIST_SEPARATOR_CHAR ','
324 /* We don't have any well-defined random devices on VMS, yet... */
327 We need to do this since VMS has the following coding on status codes:
329 Bits 0-2: status type: 0 = warning, 1 = success, 2 = error, 3 = info ...
330 The important thing to know is that odd numbers are considered
331 good, while even ones are considered errors.
332 Bits 3-15: actual status number
333 Bits 16-27: facility number. 0 is considered "unknown"
334 Bits 28-31: control bits. If bit 28 is set, the shell won't try to
335 output the message (which, for random codes, just looks ugly)
337 So, what we do here is to change 0 to 1 to get the default success status,
338 and everything else is shifted up to fit into the status number field, and
339 the status is tagged as an error, which is what is wanted here.
341 Finally, we add the VMS C facility code 0x35a000, because there are some
342 programs, such as Perl, that will reinterpret the code back to something
343 POSIXly. 'man perlvms' explains it further.
345 NOTE: the perlvms manual wants to turn all codes 2 to 255 into success
346 codes (status type = 1). I couldn't disagree more. Fortunately, the
347 status type doesn't seem to bother Perl.
350 # define EXIT(n) exit((n) ? (((n) << 3) | 2 | 0x10000000 | 0x35a000) : 1)
352 # define NO_SYS_PARAM_H
355 # define DEFAULT_HOME "SYS$LOGIN:"
359 # ifdef OPENSSL_UNISTD
360 # include OPENSSL_UNISTD
364 # ifndef NO_SYS_TYPES_H
365 # include <sys/types.h>
367 # ifdef OPENSSL_SYS_WIN32_CYGWIN
372 # define LIST_SEPARATOR_CHAR ':'
373 # define EXIT(n) exit(n)
381 # ifdef OPENSSL_NO_SOCK
382 # elif defined(WINDOWS) || defined(MSDOS)
384 # if !defined(__DJGPP__)
385 # if defined(_WIN32_WCE) && _WIN32_WCE<410
386 # define getservbyname _masked_declaration_getservbyname
388 # if !defined(IPPROTO_IP)
389 /* winsock[2].h was included already? */
390 # include <winsock.h>
392 # ifdef getservbyname
393 # undef getservbyname
394 /* this is used to be wcecompat/include/winsock_extras.h */
395 struct servent *PASCAL getservbyname(const char *, const char *);
400 * Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because
401 * the value constitutes an index in per-process table of limited size
402 * and not a real pointer. And we also depend on fact that all processors
403 * Windows run on happen to be two's-complement, which allows to
404 * interchange INVALID_SOCKET and -1.
406 # define socket(d,t,p) ((int)socket(d,t,p))
407 # define accept(s,f,l) ((int)accept(s,f,l))
414 # ifndef NO_SYS_PARAM_H
415 # include <sys/param.h>
417 # ifdef OPENSSL_SYS_VXWORKS
422 # if defined(OPENSSL_SYS_VMS_NODECC)
427 # include <sys/socket.h>
429 # ifdef OPENSSL_SYS_VXWORKS
430 # include <streams/un.h>
434 # ifndef UNIX_PATH_MAX
435 # define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
439 # include <sys/filio.h> /* FIONBIO in some SVR4, e.g. unixware, solaris */
441 # include <netinet/in.h>
442 # include <arpa/inet.h>
443 # include <netinet/tcp.h>
446 # ifdef OPENSSL_SYS_AIX
447 # include <sys/select.h>
451 # include <sys/select.h>
455 # include <sys/ioctl.h>
457 /* ioctl is only in VMS > 7.0 and when socketshr is not used */
458 # if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000)
459 # include <sys/ioctl.h>
465 # if defined(TCPIP_TYPE_SOCKETSHR)
466 # include <socketshr.h>
470 # ifndef INVALID_SOCKET
471 # define INVALID_SOCKET (-1)
472 # endif /* INVALID_SOCKET */
476 * Some IPv6 implementations are broken, disable them in known bad versions.
478 # if !defined(OPENSSL_USE_IPV6)
479 # if defined(AF_INET6) && !defined(NETWARE_CLIB)
480 # define OPENSSL_USE_IPV6 1
482 # define OPENSSL_USE_IPV6 0
488 # ifndef OPENSSL_EXIT
489 # if defined(MONOLITH) && !defined(OPENSSL_C)
490 # define OPENSSL_EXIT(n) return(n)
492 # define OPENSSL_EXIT(n) do { EXIT(n); return(n); } while(0)
496 /***********************************************/
498 # if defined(OPENSSL_SYS_WINDOWS)
499 # define strcasecmp _stricmp
500 # define strncasecmp _strnicmp
501 # if (_MSC_VER >= 1310)
503 # define fdopen _fdopen
504 # define close _close
506 # define strdup _strdup
508 # define unlink _unlink
511 # include <strings.h>
515 # if defined(OPENSSL_SYS_VXWORKS)
517 # include <tickLib.h>
520 # define TTY_STRUCT int
522 # define sleep(a) taskDelay((a) * sysClkRateGet())
524 # include <vxWorks.h>
525 # include <sockLib.h>
526 # include <taskLib.h>
528 # define getpid taskIdSelf
531 * NOTE: these are implemented by helpers in database app! if the database is
532 * not linked, we need to implement them elswhere
534 struct hostent *gethostbyname(const char *name);
535 struct hostent *gethostbyaddr(const char *addr, int length, int type);
536 struct servent *getservbyname(const char *name, const char *proto);
541 #define OSSL_NELEM(x) (sizeof(x)/sizeof(x[0]))
543 #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
544 # define CRYPTO_memcmp memcmp