]>
git.ipfire.org Git - thirdparty/openssl.git/blob - e_os.h
2 * Copyright 1995-2017 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>
17 # include <internal/nelem.h>
20 * <openssl/e_os2.h> contains what we can justify to make visible to the
21 * outside; this file e_os.h is not part of the exported interface.
28 /* Used to checking reference counts, most while doing perl5 stuff :-) */
29 # if defined(OPENSSL_NO_STDIO)
30 # if defined(REF_PRINT)
31 # error "REF_PRINT requires stdio"
36 * Format specifier for printing size_t. Original conundrum was to
37 * get it working with -Wformat [-Werror], which can be considered
38 * overzealous, especially in multi-platform context, but it's
42 # define OSSLzu "I64u" /* One would expect _WIN{64|32} cases after
43 * __STDC_VERSION__, but there are corner
44 * cases of MinGW compilers that link with
45 * non-compliant MSVCRT.DLL... */
46 # elif defined(_WIN32)
49 # define OSSLzu "u" /* VMS suffers from similar problem as MinGW,
50 * i.e. C RTL falling behind compiler. Recall
51 * that sizeof(size_t)==4 even in LP64 case. */
52 # elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
54 # elif defined(__SIZEOF_SIZE_T__) && __SIZEOF_SIZE_T__==4
55 # define OSSLzu "u" /* 'lu' should have worked, but when generating
56 * 32-bit code gcc still complains :-( */
58 # define OSSLzu "lu" /* To see that is works recall what does L
59 * stand for in ILP32 and LP64 */
62 # if !defined(NDEBUG) && !defined(OPENSSL_NO_STDIO)
63 # define REF_ASSERT_ISNT(test) \
64 (void)((test) ? (OPENSSL_die("refcount error", __FILE__, __LINE__), 1) : 0)
66 # define REF_ASSERT_ISNT(i)
69 # define REF_PRINT_COUNT(a, b) \
70 fprintf(stderr, "%p:%4d:%s\n", b, b->references, a)
72 # define REF_PRINT_COUNT(a, b)
75 # define osslargused(x) (void)x
76 # define OPENSSL_CONF "openssl.cnf"
80 * set this to a comma-separated list of 'random' device files to try out. By
81 * default, we will try to read at least one of these files
83 # define DEVRANDOM "/dev/urandom","/dev/random","/dev/srandom"
85 # if !defined(OPENSSL_NO_EGD) && !defined(DEVRANDOM_EGD)
87 * set this to a comma-separated list of 'egd' sockets to try out. These
88 * sockets will be tried in the order listed in case accessing the device
89 * files listed in DEVRANDOM did not return enough randomness.
91 # define DEVRANDOM_EGD "/var/run/egd-pool","/dev/egd-pool","/etc/egd-pool","/etc/entropy"
94 # if defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI)
95 # define NO_SYS_PARAM_H
100 /********************************************************************
101 The Microsoft section
102 ********************************************************************/
103 # if defined(OPENSSL_SYS_WIN32) && !defined(WIN32)
106 # if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS)
109 # if defined(OPENSSL_SYS_MSDOS) && !defined(MSDOS)
113 # if (defined(MSDOS) || defined(OPENSSL_SYS_UEFI)) && !defined(GETPID_IS_MEANINGLESS)
114 # define GETPID_IS_MEANINGLESS
119 # define get_last_sys_error() GetLastError()
120 # define clear_sys_error() SetLastError(0)
122 # define WIN_CONSOLE_BUG
125 # define get_last_sys_error() errno
126 # define clear_sys_error() errno=0
129 # if defined(WINDOWS)
130 # define get_last_socket_error() WSAGetLastError()
131 # define clear_socket_error() WSASetLastError(0)
132 # define readsocket(s,b,n) recv((s),(b),(n),0)
133 # define writesocket(s,b,n) send((s),(b),(n),0)
134 # elif defined(__DJGPP__)
136 # define WATT32_NO_OLDIES
137 # define get_last_socket_error() errno
138 # define clear_socket_error() errno=0
139 # define closesocket(s) close_s(s)
140 # define readsocket(s,b,n) read_s(s,b,n)
141 # define writesocket(s,b,n) send(s,b,n,0)
142 # elif defined(OPENSSL_SYS_VMS)
143 # define get_last_socket_error() errno
144 # define clear_socket_error() errno=0
145 # define ioctlsocket(a,b,c) ioctl(a,b,c)
146 # define closesocket(s) close(s)
147 # define readsocket(s,b,n) recv((s),(b),(n),0)
148 # define writesocket(s,b,n) send((s),(b),(n),0)
149 # elif defined(OPENSSL_SYS_VXWORKS)
150 # define get_last_socket_error() errno
151 # define clear_socket_error() errno=0
152 # define ioctlsocket(a,b,c) ioctl((a),(b),(int)(c))
153 # define closesocket(s) close(s)
154 # define readsocket(s,b,n) read((s),(b),(n))
155 # define writesocket(s,b,n) write((s),(char *)(b),(n))
157 # define get_last_socket_error() errno
158 # define clear_socket_error() errno=0
159 # define ioctlsocket(a,b,c) ioctl(a,b,c)
160 # define closesocket(s) close(s)
161 # define readsocket(s,b,n) read((s),(b),(n))
162 # define writesocket(s,b,n) write((s),(b),(n))
165 # if (defined(WINDOWS) || defined(MSDOS))
169 # include <sys/stat.h>
170 # include <sys/socket.h>
174 # define _setmode setmode
175 # define _O_TEXT O_TEXT
176 # define _O_BINARY O_BINARY
177 # define HAS_LFN_SUPPORT(name) (pathconf((name), _PC_NAME_MAX) > 12)
178 # undef DEVRANDOM_EGD /* Neither MS-DOS nor FreeDOS provide 'egd' sockets. */
180 # define DEVRANDOM "/dev/urandom\x24"
181 # endif /* __DJGPP__ */
184 # define S_IFDIR _S_IFDIR
188 # define S_IFMT _S_IFMT
191 # if !defined(WINNT) && !defined(__DJGPP__)
197 # if !defined(_WIN32_WCE) && !defined(_WIN32_WINNT)
199 * Defining _WIN32_WINNT here in e_os.h implies certain "discipline."
200 * Most notably we ought to check for availability of each specific
201 * routine that was introduced after denoted _WIN32_WINNT with
202 * GetProcAddress(). Normally newer functions are masked with higher
203 * _WIN32_WINNT in SDK headers. So that if you wish to use them in
204 * some module, you'd need to override _WIN32_WINNT definition in
205 * the target module in order to "reach for" prototypes, but replace
206 * calls to new functions with indirect calls. Alternatively it
207 * might be possible to achieve the goal by /DELAYLOAD-ing .DLLs
208 * and check for current OS version instead.
210 # define _WIN32_WINNT 0x0501
212 # if defined(_WIN32_WINNT) || defined(_WIN32_WCE)
214 * Just like defining _WIN32_WINNT including winsock2.h implies
215 * certain "discipline" for maintaining [broad] binary compatibility.
216 * As long as structures are invariant among Winsock versions,
217 * it's sufficient to check for specific Winsock2 API availability
218 * at run-time [DSO_global_lookup is recommended]...
220 # include <winsock2.h>
221 # include <ws2tcpip.h>
222 /* yes, they have to be #included prior to <windows.h> */
224 # include <windows.h>
228 # if defined(_WIN32_WCE) && !defined(EACCES)
233 # define strlen(s) _strlen31(s)
234 /* cut strings to 2GB */
235 static __inline
unsigned int _strlen31(const char *str
)
237 unsigned int len
= 0;
238 while (*str
&& len
< 0x80000000U
)
240 return len
& 0x7FFFFFFF;
244 # if defined(_MSC_VER) && _MSC_VER<=1200 && defined(_MT) && defined(isspace)
245 /* compensate for bug in VC6 ctype.h */
252 # if defined(_MSC_VER) && !defined(_WIN32_WCE) && !defined(_DLL) && defined(stdin)
253 # if _MSC_VER>=1300 && _MSC_VER<1600
258 # define stdin (&__iob_func()[0])
259 # define stdout (&__iob_func()[1])
260 # define stderr (&__iob_func()[2])
261 # elif _MSC_VER<1300 && defined(I_CAN_LIVE_WITH_LNK4049)
266 * pre-1300 has __p__iob(), but it's available only in msvcrt.lib,
267 * or in other words with /MD. Declaring implicit import, i.e. with
268 * _imp_ prefix, works correctly with all compiler options, but
269 * without /MD results in LINK warning LNK4049: 'locally defined
270 * symbol "__iob" imported'.
272 extern FILE *_imp___iob
;
273 # define stdin (&_imp___iob[0])
274 # define stdout (&_imp___iob[1])
275 # define stderr (&_imp___iob[2])
282 # ifdef OPENSSL_SYS_WINCE
283 # define OPENSSL_NO_POSIX_IO
286 # define EXIT(n) exit(n)
287 # define LIST_SEPARATOR_CHAR ';'
297 # ifdef OPENSSL_SYS_WINCE
298 # define DEFAULT_HOME ""
300 # define DEFAULT_HOME "C:"
303 /* Avoid Visual Studio 13 GetVersion deprecated problems */
304 # if defined(_MSC_VER) && _MSC_VER>=1800
305 # define check_winnt() (1)
306 # define check_win_minplat(x) (1)
308 # define check_winnt() (GetVersion() < 0x80000000)
309 # define check_win_minplat(x) (LOBYTE(LOWORD(GetVersion())) >= (x))
312 # else /* The non-microsoft world */
314 # ifdef OPENSSL_SYS_VMS
317 * some programs don't include stdlib, so exit() and others give implicit
324 # include <unixlib.h>
326 # define LIST_SEPARATOR_CHAR ','
327 /* We don't have any well-defined random devices on VMS, yet... */
330 We need to do this since VMS has the following coding on status codes:
332 Bits 0-2: status type: 0 = warning, 1 = success, 2 = error, 3 = info ...
333 The important thing to know is that odd numbers are considered
334 good, while even ones are considered errors.
335 Bits 3-15: actual status number
336 Bits 16-27: facility number. 0 is considered "unknown"
337 Bits 28-31: control bits. If bit 28 is set, the shell won't try to
338 output the message (which, for random codes, just looks ugly)
340 So, what we do here is to change 0 to 1 to get the default success status,
341 and everything else is shifted up to fit into the status number field, and
342 the status is tagged as an error, which is what is wanted here.
344 Finally, we add the VMS C facility code 0x35a000, because there are some
345 programs, such as Perl, that will reinterpret the code back to something
346 POSIXly. 'man perlvms' explains it further.
348 NOTE: the perlvms manual wants to turn all codes 2 to 255 into success
349 codes (status type = 1). I couldn't disagree more. Fortunately, the
350 status type doesn't seem to bother Perl.
353 # define EXIT(n) exit((n) ? (((n) << 3) | 2 | 0x10000000 | 0x35a000) : 1)
355 # define NO_SYS_PARAM_H
358 # define DEFAULT_HOME "SYS$LOGIN:"
362 # ifdef OPENSSL_UNISTD
363 # include OPENSSL_UNISTD
367 # ifndef NO_SYS_TYPES_H
368 # include <sys/types.h>
370 # ifdef OPENSSL_SYS_WIN32_CYGWIN
375 # define LIST_SEPARATOR_CHAR ':'
376 # define EXIT(n) exit(n)
384 # ifdef OPENSSL_NO_SOCK
385 # elif defined(WINDOWS) || defined(MSDOS)
387 # if !defined(__DJGPP__)
388 # if defined(_WIN32_WCE) && _WIN32_WCE<410
389 # define getservbyname _masked_declaration_getservbyname
391 # if !defined(IPPROTO_IP)
392 /* winsock[2].h was included already? */
393 # include <winsock.h>
395 # ifdef getservbyname
396 # undef getservbyname
397 /* this is used to be wcecompat/include/winsock_extras.h */
398 struct servent
*PASCAL
getservbyname(const char *, const char *);
403 * Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because
404 * the value constitutes an index in per-process table of limited size
405 * and not a real pointer. And we also depend on fact that all processors
406 * Windows run on happen to be two's-complement, which allows to
407 * interchange INVALID_SOCKET and -1.
409 # define socket(d,t,p) ((int)socket(d,t,p))
410 # define accept(s,f,l) ((int)accept(s,f,l))
417 # ifndef NO_SYS_PARAM_H
418 # include <sys/param.h>
420 # ifdef OPENSSL_SYS_VXWORKS
425 # if defined(OPENSSL_SYS_VMS_NODECC)
430 # include <sys/socket.h>
432 # ifdef OPENSSL_SYS_VXWORKS
433 # include <streams/un.h>
437 # ifndef UNIX_PATH_MAX
438 # define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
442 # include <sys/filio.h> /* FIONBIO in some SVR4, e.g. unixware, solaris */
444 # include <netinet/in.h>
445 # include <arpa/inet.h>
446 # include <netinet/tcp.h>
449 # ifdef OPENSSL_SYS_AIX
450 # include <sys/select.h>
454 # include <sys/select.h>
458 # include <sys/ioctl.h>
460 /* ioctl is only in VMS > 7.0 and when socketshr is not used */
461 # if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000)
462 # include <sys/ioctl.h>
468 # if defined(TCPIP_TYPE_SOCKETSHR)
469 # include <socketshr.h>
473 # ifndef INVALID_SOCKET
474 # define INVALID_SOCKET (-1)
475 # endif /* INVALID_SOCKET */
479 * Some IPv6 implementations are broken, disable them in known bad versions.
481 # if !defined(OPENSSL_USE_IPV6)
482 # if defined(AF_INET6) && !defined(NETWARE_CLIB)
483 # define OPENSSL_USE_IPV6 1
485 # define OPENSSL_USE_IPV6 0
491 # ifndef OPENSSL_EXIT
492 # if defined(MONOLITH) && !defined(OPENSSL_C)
493 # define OPENSSL_EXIT(n) return(n)
495 # define OPENSSL_EXIT(n) do { EXIT(n); return(n); } while(0)
499 /***********************************************/
501 # if defined(OPENSSL_SYS_WINDOWS)
502 # define strcasecmp _stricmp
503 # define strncasecmp _strnicmp
504 # if (_MSC_VER >= 1310)
506 # define fdopen _fdopen
507 # define close _close
509 # define strdup _strdup
511 # define unlink _unlink
512 # define fileno _fileno
515 # include <strings.h>
519 # if defined(OPENSSL_SYS_VXWORKS)
521 # include <tickLib.h>
524 # define TTY_STRUCT int
526 # define sleep(a) taskDelay((a) * sysClkRateGet())
528 # include <vxWorks.h>
529 # include <sockLib.h>
530 # include <taskLib.h>
532 # define getpid taskIdSelf
535 * NOTE: these are implemented by helpers in database app! if the database is
536 * not linked, we need to implement them elsewhere
538 struct hostent
*gethostbyname(const char *name
);
539 struct hostent
*gethostbyaddr(const char *addr
, int length
, int type
);
540 struct servent
*getservbyname(const char *name
, const char *proto
);
545 #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
546 # define CRYPTO_memcmp memcmp