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 * We need a format operator for some client tools for uint64_t. If inttypes.h
34 * isn't available or did not define it, just go with hard-coded.
36 # if defined(OPENSSL_SYS_UEFI)
40 # ifdef SIXTY_FOUR_BIT_LONG
47 /* Format specifier for printing size_t */
48 # if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
51 # ifdef THIRTY_TWO_BIT
54 # define OSSLzu PRIu64
58 # if !defined(NDEBUG) && !defined(OPENSSL_NO_STDIO)
59 # define REF_ASSERT_ISNT(test) \
60 (void)((test) ? (OPENSSL_die("refcount error", __FILE__, __LINE__), 1) : 0)
62 # define REF_ASSERT_ISNT(i)
65 # define REF_PRINT_COUNT(a, b) \
66 fprintf(stderr, "%p:%4d:%s\n", b, b->references, a)
68 # define REF_PRINT_COUNT(a, b)
71 # define osslargused(x) (void)x
72 # define OPENSSL_CONF "openssl.cnf"
76 * set this to a comma-separated list of 'random' device files to try out. My
77 * default, we will try to read at least one of these files
79 # define DEVRANDOM "/dev/urandom","/dev/random","/dev/srandom"
81 # if !defined(OPENSSL_NO_EGD) && !defined(DEVRANDOM_EGD)
83 * set this to a comma-separated list of 'egd' sockets to try out. These
84 * sockets will be tried in the order listed in case accessing the device
85 * files listed in DEVRANDOM did not return enough entropy.
87 # define DEVRANDOM_EGD "/var/run/egd-pool","/dev/egd-pool","/etc/egd-pool","/etc/entropy"
90 # if defined(OPENSSL_SYS_VXWORKS)
91 # define NO_SYS_PARAM_H
96 /********************************************************************
98 ********************************************************************/
99 # if defined(OPENSSL_SYS_WIN32) && !defined(WIN32)
102 # if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS)
105 # if defined(OPENSSL_SYS_MSDOS) && !defined(MSDOS)
109 # if (defined(MSDOS) || defined(OPENSSL_SYS_UEFI)) && !defined(GETPID_IS_MEANINGLESS)
110 # define GETPID_IS_MEANINGLESS
115 # define get_last_sys_error() GetLastError()
116 # define clear_sys_error() SetLastError(0)
118 # define WIN_CONSOLE_BUG
121 # define get_last_sys_error() errno
122 # define clear_sys_error() errno=0
125 # if defined(WINDOWS)
126 # define get_last_socket_error() WSAGetLastError()
127 # define clear_socket_error() WSASetLastError(0)
128 # define readsocket(s,b,n) recv((s),(b),(n),0)
129 # define writesocket(s,b,n) send((s),(b),(n),0)
130 # elif defined(__DJGPP__)
132 # define WATT32_NO_OLDIES
133 # define get_last_socket_error() errno
134 # define clear_socket_error() errno=0
135 # define closesocket(s) close_s(s)
136 # define readsocket(s,b,n) read_s(s,b,n)
137 # define writesocket(s,b,n) send(s,b,n,0)
138 # elif defined(OPENSSL_SYS_VMS)
139 # define get_last_socket_error() errno
140 # define clear_socket_error() errno=0
141 # define ioctlsocket(a,b,c) ioctl(a,b,c)
142 # define closesocket(s) close(s)
143 # define readsocket(s,b,n) recv((s),(b),(n),0)
144 # define writesocket(s,b,n) send((s),(b),(n),0)
145 # elif defined(OPENSSL_SYS_VXWORKS)
146 # define get_last_socket_error() errno
147 # define clear_socket_error() errno=0
148 # define ioctlsocket(a,b,c) ioctl((a),(b),(int)(c))
149 # define closesocket(s) close(s)
150 # define readsocket(s,b,n) read((s),(b),(n))
151 # define writesocket(s,b,n) write((s),(char *)(b),(n))
153 # define get_last_socket_error() errno
154 # define clear_socket_error() errno=0
155 # define ioctlsocket(a,b,c) ioctl(a,b,c)
156 # define closesocket(s) close(s)
157 # define readsocket(s,b,n) read((s),(b),(n))
158 # define writesocket(s,b,n) write((s),(b),(n))
161 # if (defined(WINDOWS) || defined(MSDOS))
165 # include <sys/stat.h>
166 # include <sys/socket.h>
170 # define _setmode setmode
171 # define _O_TEXT O_TEXT
172 # define _O_BINARY O_BINARY
173 # define HAS_LFN_SUPPORT(name) (pathconf((name), _PC_NAME_MAX) > 12)
174 # undef DEVRANDOM_EGD /* Neither MS-DOS nor FreeDOS provide 'egd' sockets. */
176 # define DEVRANDOM "/dev/urandom\x24"
177 # endif /* __DJGPP__ */
180 # define S_IFDIR _S_IFDIR
184 # define S_IFMT _S_IFMT
187 # if !defined(WINNT) && !defined(__DJGPP__)
193 # if !defined(_WIN32_WCE) && !defined(_WIN32_WINNT)
195 * Defining _WIN32_WINNT here in e_os.h implies certain "discipline."
196 * Most notably we ought to check for availability of each specific
197 * routine that was introduced after denoted _WIN32_WINNT with
198 * GetProcAddress(). Normally newer functions are masked with higher
199 * _WIN32_WINNT in SDK headers. So that if you wish to use them in
200 * some module, you'd need to override _WIN32_WINNT definition in
201 * the target module in order to "reach for" prototypes, but replace
202 * calls to new functions with indirect calls. Alternatively it
203 * might be possible to achieve the goal by /DELAYLOAD-ing .DLLs
204 * and check for current OS version instead.
206 # define _WIN32_WINNT 0x0501
208 # if defined(_WIN32_WINNT) || defined(_WIN32_WCE)
210 * Just like defining _WIN32_WINNT including winsock2.h implies
211 * certain "discipline" for maintaining [broad] binary compatibility.
212 * As long as structures are invariant among Winsock versions,
213 * it's sufficient to check for specific Winsock2 API availability
214 * at run-time [DSO_global_lookup is recommended]...
216 # include <winsock2.h>
217 # include <ws2tcpip.h>
218 /* yes, they have to be #included prior to <windows.h> */
220 # include <windows.h>
224 # if defined(_WIN32_WCE) && !defined(EACCES)
229 # define strlen(s) _strlen31(s)
230 /* cut strings to 2GB */
231 static __inline unsigned int _strlen31(const char *str)
233 unsigned int len = 0;
234 while (*str && len < 0x80000000U)
236 return len & 0x7FFFFFFF;
240 # if defined(_MSC_VER) && _MSC_VER<=1200 && defined(_MT) && defined(isspace)
241 /* compensate for bug in VC6 ctype.h */
248 # if defined(_MSC_VER) && !defined(_WIN32_WCE) && !defined(_DLL) && defined(stdin)
249 # if _MSC_VER>=1300 && _MSC_VER<1600
254 # define stdin (&__iob_func()[0])
255 # define stdout (&__iob_func()[1])
256 # define stderr (&__iob_func()[2])
257 # elif _MSC_VER<1300 && defined(I_CAN_LIVE_WITH_LNK4049)
262 * pre-1300 has __p__iob(), but it's available only in msvcrt.lib,
263 * or in other words with /MD. Declaring implicit import, i.e. with
264 * _imp_ prefix, works correctly with all compiler options, but
265 * without /MD results in LINK warning LNK4049: 'locally defined
266 * symbol "__iob" imported'.
268 extern FILE *_imp___iob;
269 # define stdin (&_imp___iob[0])
270 # define stdout (&_imp___iob[1])
271 # define stderr (&_imp___iob[2])
278 # ifdef OPENSSL_SYS_WINCE
279 # define OPENSSL_NO_POSIX_IO
282 # define EXIT(n) exit(n)
283 # define LIST_SEPARATOR_CHAR ';'
293 # ifdef OPENSSL_SYS_WINCE
294 # define DEFAULT_HOME ""
296 # define DEFAULT_HOME "C:"
299 /* Avoid Visual Studio 13 GetVersion deprecated problems */
300 # if defined(_MSC_VER) && _MSC_VER>=1800
301 # define check_winnt() (1)
302 # define check_win_minplat(x) (1)
304 # define check_winnt() (GetVersion() < 0x80000000)
305 # define check_win_minplat(x) (LOBYTE(LOWORD(GetVersion())) >= (x))
308 # else /* The non-microsoft world */
310 # ifdef OPENSSL_SYS_VMS
313 * some programs don't include stdlib, so exit() and others give implicit
320 # include <unixlib.h>
322 # define LIST_SEPARATOR_CHAR ','
323 /* We don't have any well-defined random devices on VMS, yet... */
326 We need to do this since VMS has the following coding on status codes:
328 Bits 0-2: status type: 0 = warning, 1 = success, 2 = error, 3 = info ...
329 The important thing to know is that odd numbers are considered
330 good, while even ones are considered errors.
331 Bits 3-15: actual status number
332 Bits 16-27: facility number. 0 is considered "unknown"
333 Bits 28-31: control bits. If bit 28 is set, the shell won't try to
334 output the message (which, for random codes, just looks ugly)
336 So, what we do here is to change 0 to 1 to get the default success status,
337 and everything else is shifted up to fit into the status number field, and
338 the status is tagged as an error, which is what is wanted here.
340 Finally, we add the VMS C facility code 0x35a000, because there are some
341 programs, such as Perl, that will reinterpret the code back to something
342 POSIXly. 'man perlvms' explains it further.
344 NOTE: the perlvms manual wants to turn all codes 2 to 255 into success
345 codes (status type = 1). I couldn't disagree more. Fortunately, the
346 status type doesn't seem to bother Perl.
349 # define EXIT(n) exit((n) ? (((n) << 3) | 2 | 0x10000000 | 0x35a000) : 1)
351 # define NO_SYS_PARAM_H
354 # define DEFAULT_HOME "SYS$LOGIN:"
358 # ifdef OPENSSL_UNISTD
359 # include OPENSSL_UNISTD
363 # ifndef NO_SYS_TYPES_H
364 # include <sys/types.h>
366 # ifdef OPENSSL_SYS_WIN32_CYGWIN
371 # define LIST_SEPARATOR_CHAR ':'
372 # define EXIT(n) exit(n)
380 # ifdef OPENSSL_NO_SOCK
381 # elif defined(WINDOWS) || defined(MSDOS)
383 # if !defined(__DJGPP__)
384 # if defined(_WIN32_WCE) && _WIN32_WCE<410
385 # define getservbyname _masked_declaration_getservbyname
387 # if !defined(IPPROTO_IP)
388 /* winsock[2].h was included already? */
389 # include <winsock.h>
391 # ifdef getservbyname
392 # undef getservbyname
393 /* this is used to be wcecompat/include/winsock_extras.h */
394 struct servent *PASCAL getservbyname(const char *, const char *);
399 * Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because
400 * the value constitutes an index in per-process table of limited size
401 * and not a real pointer. And we also depend on fact that all processors
402 * Windows run on happen to be two's-complement, which allows to
403 * interchange INVALID_SOCKET and -1.
405 # define socket(d,t,p) ((int)socket(d,t,p))
406 # define accept(s,f,l) ((int)accept(s,f,l))
413 # ifndef NO_SYS_PARAM_H
414 # include <sys/param.h>
416 # ifdef OPENSSL_SYS_VXWORKS
421 # if defined(OPENSSL_SYS_VMS_NODECC)
426 # include <sys/socket.h>
428 # ifdef OPENSSL_SYS_VXWORKS
429 # include <streams/un.h>
433 # ifndef UNIX_PATH_MAX
434 # define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
438 # include <sys/filio.h> /* FIONBIO in some SVR4, e.g. unixware, solaris */
440 # include <netinet/in.h>
441 # include <arpa/inet.h>
442 # include <netinet/tcp.h>
445 # ifdef OPENSSL_SYS_AIX
446 # include <sys/select.h>
450 # include <sys/select.h>
454 # include <sys/ioctl.h>
456 /* ioctl is only in VMS > 7.0 and when socketshr is not used */
457 # if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000)
458 # include <sys/ioctl.h>
464 # if defined(TCPIP_TYPE_SOCKETSHR)
465 # include <socketshr.h>
469 # ifndef INVALID_SOCKET
470 # define INVALID_SOCKET (-1)
471 # endif /* INVALID_SOCKET */
475 * Some IPv6 implementations are broken, disable them in known bad versions.
477 # if !defined(OPENSSL_USE_IPV6)
478 # if defined(AF_INET6) && !defined(NETWARE_CLIB)
479 # define OPENSSL_USE_IPV6 1
481 # define OPENSSL_USE_IPV6 0
487 # ifndef OPENSSL_EXIT
488 # if defined(MONOLITH) && !defined(OPENSSL_C)
489 # define OPENSSL_EXIT(n) return(n)
491 # define OPENSSL_EXIT(n) do { EXIT(n); return(n); } while(0)
495 /***********************************************/
497 # if defined(OPENSSL_SYS_WINDOWS)
498 # define strcasecmp _stricmp
499 # define strncasecmp _strnicmp
500 # if (_MSC_VER >= 1310)
502 # define fdopen _fdopen
503 # define close _close
505 # define strdup _strdup
507 # define unlink _unlink
510 # include <strings.h>
514 # if defined(OPENSSL_SYS_VXWORKS)
516 # include <tickLib.h>
519 # define TTY_STRUCT int
521 # define sleep(a) taskDelay((a) * sysClkRateGet())
523 # include <vxWorks.h>
524 # include <sockLib.h>
525 # include <taskLib.h>
527 # define getpid taskIdSelf
530 * NOTE: these are implemented by helpers in database app! if the database is
531 * not linked, we need to implement them elswhere
533 struct hostent *gethostbyname(const char *name);
534 struct hostent *gethostbyaddr(const char *addr, int length, int type);
535 struct servent *getservbyname(const char *name, const char *proto);
540 #define OSSL_NELEM(x) (sizeof(x)/sizeof(x[0]))
542 #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
543 # define CRYPTO_memcmp memcmp