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 * BIO_printf format modifier for [u]int64_t.
35 # if defined(__LP64__) || (defined(__SIZEOF_LONG__) && __SIZEOF_LONG__==8)
36 # define BIO_PRI64 "l" /* 'll' does work "universally", but 'l' is
37 * here to shut -Wformat warnings in LP64... */
39 # define BIO_PRI64 "ll"
42 # if !defined(NDEBUG) && !defined(OPENSSL_NO_STDIO)
43 # define REF_ASSERT_ISNT(test) \
44 (void)((test) ? (OPENSSL_die("refcount error", __FILE__, __LINE__), 1) : 0)
46 # define REF_ASSERT_ISNT(i)
49 # define REF_PRINT_COUNT(a, b) \
50 fprintf(stderr, "%p:%4d:%s\n", b, b->references, a)
52 # define REF_PRINT_COUNT(a, b)
55 # define osslargused(x) (void)x
56 # define OPENSSL_CONF "openssl.cnf"
60 * set this to a comma-separated list of 'random' device files to try out. My
61 * default, we will try to read at least one of these files
63 # define DEVRANDOM "/dev/urandom","/dev/random","/dev/srandom"
65 # if !defined(OPENSSL_NO_EGD) && !defined(DEVRANDOM_EGD)
67 * set this to a comma-separated list of 'egd' sockets to try out. These
68 * sockets will be tried in the order listed in case accessing the device
69 * files listed in DEVRANDOM did not return enough entropy.
71 # define DEVRANDOM_EGD "/var/run/egd-pool","/dev/egd-pool","/etc/egd-pool","/etc/entropy"
74 # if defined(OPENSSL_SYS_VXWORKS)
75 # define NO_SYS_PARAM_H
80 /********************************************************************
82 ********************************************************************/
83 # if defined(OPENSSL_SYS_WIN32) && !defined(WIN32)
86 # if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS)
89 # if defined(OPENSSL_SYS_MSDOS) && !defined(MSDOS)
93 # if (defined(MSDOS) || defined(OPENSSL_SYS_UEFI)) && !defined(GETPID_IS_MEANINGLESS)
94 # define GETPID_IS_MEANINGLESS
99 # define get_last_sys_error() GetLastError()
100 # define clear_sys_error() SetLastError(0)
102 # define WIN_CONSOLE_BUG
105 # define get_last_sys_error() errno
106 # define clear_sys_error() errno=0
109 # if defined(WINDOWS)
110 # define get_last_socket_error() WSAGetLastError()
111 # define clear_socket_error() WSASetLastError(0)
112 # define readsocket(s,b,n) recv((s),(b),(n),0)
113 # define writesocket(s,b,n) send((s),(b),(n),0)
114 # elif defined(__DJGPP__)
116 # define WATT32_NO_OLDIES
117 # define get_last_socket_error() errno
118 # define clear_socket_error() errno=0
119 # define closesocket(s) close_s(s)
120 # define readsocket(s,b,n) read_s(s,b,n)
121 # define writesocket(s,b,n) send(s,b,n,0)
122 # elif defined(OPENSSL_SYS_VMS)
123 # define get_last_socket_error() errno
124 # define clear_socket_error() errno=0
125 # define ioctlsocket(a,b,c) ioctl(a,b,c)
126 # define closesocket(s) close(s)
127 # define readsocket(s,b,n) recv((s),(b),(n),0)
128 # define writesocket(s,b,n) send((s),(b),(n),0)
129 # elif defined(OPENSSL_SYS_VXWORKS)
130 # define get_last_socket_error() errno
131 # define clear_socket_error() errno=0
132 # define ioctlsocket(a,b,c) ioctl((a),(b),(int)(c))
133 # define closesocket(s) close(s)
134 # define readsocket(s,b,n) read((s),(b),(n))
135 # define writesocket(s,b,n) write((s),(char *)(b),(n))
137 # define get_last_socket_error() errno
138 # define clear_socket_error() errno=0
139 # define ioctlsocket(a,b,c) ioctl(a,b,c)
140 # define closesocket(s) close(s)
141 # define readsocket(s,b,n) read((s),(b),(n))
142 # define writesocket(s,b,n) write((s),(b),(n))
145 # if (defined(WINDOWS) || defined(MSDOS))
149 # include <sys/stat.h>
150 # include <sys/socket.h>
154 # define _setmode setmode
155 # define _O_TEXT O_TEXT
156 # define _O_BINARY O_BINARY
157 # define HAS_LFN_SUPPORT(name) (pathconf((name), _PC_NAME_MAX) > 12)
158 # undef DEVRANDOM_EGD /* Neither MS-DOS nor FreeDOS provide 'egd' sockets. */
160 # define DEVRANDOM "/dev/urandom\x24"
161 # endif /* __DJGPP__ */
164 # define S_IFDIR _S_IFDIR
168 # define S_IFMT _S_IFMT
171 # if !defined(WINNT) && !defined(__DJGPP__)
177 # if !defined(_WIN32_WCE) && !defined(_WIN32_WINNT)
179 * Defining _WIN32_WINNT here in e_os.h implies certain "discipline."
180 * Most notably we ought to check for availability of each specific
181 * routine that was introduced after denoted _WIN32_WINNT with
182 * GetProcAddress(). Normally newer functions are masked with higher
183 * _WIN32_WINNT in SDK headers. So that if you wish to use them in
184 * some module, you'd need to override _WIN32_WINNT definition in
185 * the target module in order to "reach for" prototypes, but replace
186 * calls to new functions with indirect calls. Alternatively it
187 * might be possible to achieve the goal by /DELAYLOAD-ing .DLLs
188 * and check for current OS version instead.
190 # define _WIN32_WINNT 0x0501
192 # if defined(_WIN32_WINNT) || defined(_WIN32_WCE)
194 * Just like defining _WIN32_WINNT including winsock2.h implies
195 * certain "discipline" for maintaining [broad] binary compatibility.
196 * As long as structures are invariant among Winsock versions,
197 * it's sufficient to check for specific Winsock2 API availability
198 * at run-time [DSO_global_lookup is recommended]...
200 # include <winsock2.h>
201 # include <ws2tcpip.h>
202 /* yes, they have to be #included prior to <windows.h> */
204 # include <windows.h>
208 # if defined(_WIN32_WCE) && !defined(EACCES)
213 # define strlen(s) _strlen31(s)
214 /* cut strings to 2GB */
215 static __inline unsigned int _strlen31(const char *str)
217 unsigned int len = 0;
218 while (*str && len < 0x80000000U)
220 return len & 0x7FFFFFFF;
224 # if defined(_MSC_VER) && _MSC_VER<=1200 && defined(_MT) && defined(isspace)
225 /* compensate for bug in VC6 ctype.h */
232 # if defined(_MSC_VER) && !defined(_WIN32_WCE) && !defined(_DLL) && defined(stdin)
233 # if _MSC_VER>=1300 && _MSC_VER<1600
238 # define stdin (&__iob_func()[0])
239 # define stdout (&__iob_func()[1])
240 # define stderr (&__iob_func()[2])
241 # elif _MSC_VER<1300 && defined(I_CAN_LIVE_WITH_LNK4049)
246 * pre-1300 has __p__iob(), but it's available only in msvcrt.lib,
247 * or in other words with /MD. Declaring implicit import, i.e. with
248 * _imp_ prefix, works correctly with all compiler options, but
249 * without /MD results in LINK warning LNK4049: 'locally defined
250 * symbol "__iob" imported'.
252 extern FILE *_imp___iob;
253 # define stdin (&_imp___iob[0])
254 # define stdout (&_imp___iob[1])
255 # define stderr (&_imp___iob[2])
262 # ifdef OPENSSL_SYS_WINCE
263 # define OPENSSL_NO_POSIX_IO
266 # define EXIT(n) exit(n)
267 # define LIST_SEPARATOR_CHAR ';'
277 # ifdef OPENSSL_SYS_WINCE
278 # define DEFAULT_HOME ""
280 # define DEFAULT_HOME "C:"
283 /* Avoid Visual Studio 13 GetVersion deprecated problems */
284 # if defined(_MSC_VER) && _MSC_VER>=1800
285 # define check_winnt() (1)
286 # define check_win_minplat(x) (1)
288 # define check_winnt() (GetVersion() < 0x80000000)
289 # define check_win_minplat(x) (LOBYTE(LOWORD(GetVersion())) >= (x))
292 # else /* The non-microsoft world */
294 # ifdef OPENSSL_SYS_VMS
297 * some programs don't include stdlib, so exit() and others give implicit
304 # include <unixlib.h>
306 # define LIST_SEPARATOR_CHAR ','
307 /* We don't have any well-defined random devices on VMS, yet... */
310 We need to do this since VMS has the following coding on status codes:
312 Bits 0-2: status type: 0 = warning, 1 = success, 2 = error, 3 = info ...
313 The important thing to know is that odd numbers are considered
314 good, while even ones are considered errors.
315 Bits 3-15: actual status number
316 Bits 16-27: facility number. 0 is considered "unknown"
317 Bits 28-31: control bits. If bit 28 is set, the shell won't try to
318 output the message (which, for random codes, just looks ugly)
320 So, what we do here is to change 0 to 1 to get the default success status,
321 and everything else is shifted up to fit into the status number field, and
322 the status is tagged as an error, which is what is wanted here.
324 Finally, we add the VMS C facility code 0x35a000, because there are some
325 programs, such as Perl, that will reinterpret the code back to something
326 POSIXly. 'man perlvms' explains it further.
328 NOTE: the perlvms manual wants to turn all codes 2 to 255 into success
329 codes (status type = 1). I couldn't disagree more. Fortunately, the
330 status type doesn't seem to bother Perl.
333 # define EXIT(n) exit((n) ? (((n) << 3) | 2 | 0x10000000 | 0x35a000) : 1)
335 # define NO_SYS_PARAM_H
338 # define DEFAULT_HOME "SYS$LOGIN:"
342 # ifdef OPENSSL_UNISTD
343 # include OPENSSL_UNISTD
347 # ifndef NO_SYS_TYPES_H
348 # include <sys/types.h>
350 # ifdef OPENSSL_SYS_WIN32_CYGWIN
355 # define LIST_SEPARATOR_CHAR ':'
356 # define EXIT(n) exit(n)
364 # ifdef OPENSSL_NO_SOCK
365 # elif defined(WINDOWS) || defined(MSDOS)
367 # if !defined(__DJGPP__)
368 # if defined(_WIN32_WCE) && _WIN32_WCE<410
369 # define getservbyname _masked_declaration_getservbyname
371 # if !defined(IPPROTO_IP)
372 /* winsock[2].h was included already? */
373 # include <winsock.h>
375 # ifdef getservbyname
376 # undef getservbyname
377 /* this is used to be wcecompat/include/winsock_extras.h */
378 struct servent *PASCAL getservbyname(const char *, const char *);
383 * Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because
384 * the value constitutes an index in per-process table of limited size
385 * and not a real pointer. And we also depend on fact that all processors
386 * Windows run on happen to be two's-complement, which allows to
387 * interchange INVALID_SOCKET and -1.
389 # define socket(d,t,p) ((int)socket(d,t,p))
390 # define accept(s,f,l) ((int)accept(s,f,l))
397 # ifndef NO_SYS_PARAM_H
398 # include <sys/param.h>
400 # ifdef OPENSSL_SYS_VXWORKS
405 # if defined(OPENSSL_SYS_VMS_NODECC)
410 # include <sys/socket.h>
412 # ifdef OPENSSL_SYS_VXWORKS
413 # include <streams/un.h>
417 # ifndef UNIX_PATH_MAX
418 # define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
422 # include <sys/filio.h> /* FIONBIO in some SVR4, e.g. unixware, solaris */
424 # include <netinet/in.h>
425 # include <arpa/inet.h>
426 # include <netinet/tcp.h>
429 # ifdef OPENSSL_SYS_AIX
430 # include <sys/select.h>
434 # include <sys/select.h>
438 # include <sys/ioctl.h>
440 /* ioctl is only in VMS > 7.0 and when socketshr is not used */
441 # if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000)
442 # include <sys/ioctl.h>
448 # if defined(TCPIP_TYPE_SOCKETSHR)
449 # include <socketshr.h>
453 # ifndef INVALID_SOCKET
454 # define INVALID_SOCKET (-1)
455 # endif /* INVALID_SOCKET */
459 * Some IPv6 implementations are broken, disable them in known bad versions.
461 # if !defined(OPENSSL_USE_IPV6)
462 # if defined(AF_INET6) && !defined(NETWARE_CLIB)
463 # define OPENSSL_USE_IPV6 1
465 # define OPENSSL_USE_IPV6 0
471 # ifndef OPENSSL_EXIT
472 # if defined(MONOLITH) && !defined(OPENSSL_C)
473 # define OPENSSL_EXIT(n) return(n)
475 # define OPENSSL_EXIT(n) do { EXIT(n); return(n); } while(0)
479 /***********************************************/
481 # if defined(OPENSSL_SYS_WINDOWS)
482 # define strcasecmp _stricmp
483 # define strncasecmp _strnicmp
484 # if (_MSC_VER >= 1310)
486 # define fdopen _fdopen
487 # define close _close
489 # define strdup _strdup
491 # define unlink _unlink
494 # include <strings.h>
498 # if defined(OPENSSL_SYS_VXWORKS)
500 # include <tickLib.h>
503 # define TTY_STRUCT int
505 # define sleep(a) taskDelay((a) * sysClkRateGet())
507 # include <vxWorks.h>
508 # include <sockLib.h>
509 # include <taskLib.h>
511 # define getpid taskIdSelf
514 * NOTE: these are implemented by helpers in database app! if the database is
515 * not linked, we need to implement them elswhere
517 struct hostent *gethostbyname(const char *name);
518 struct hostent *gethostbyaddr(const char *addr, int length, int type);
519 struct servent *getservbyname(const char *name, const char *proto);
524 #define OSSL_NELEM(x) (sizeof(x)/sizeof(x[0]))