]> git.ipfire.org Git - thirdparty/openssl.git/blame - e_os.h
Use "" not <> for internal/ includes
[thirdparty/openssl.git] / e_os.h
CommitLineData
b6cff313 1/*
b99fe5f4 2 * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
0f113f3e 3 *
b6cff313
RS
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
d02b48c6
RE
8 */
9
10#ifndef HEADER_E_OS_H
0f113f3e 11# define HEADER_E_OS_H
d02b48c6 12
0f113f3e 13# include <openssl/opensslconf.h>
06018c46 14
0f113f3e 15# include <openssl/e_os2.h>
98d132cf 16# include <openssl/crypto.h>
176db6dc 17# include "internal/nelem.h"
b99fe5f4 18
0f113f3e
MC
19/*
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.
22 */
fa470a84 23
d02b48c6
RE
24#ifdef __cplusplus
25extern "C" {
26#endif
27
58964a49 28/* Used to checking reference counts, most while doing perl5 stuff :-) */
f3f1cf84 29# if defined(OPENSSL_NO_STDIO)
f3f1cf84
RS
30# if defined(REF_PRINT)
31# error "REF_PRINT requires stdio"
32# endif
0f113f3e 33# endif
f3f1cf84 34
43708c15 35/*
5f584013
AP
36 * Format specifier for printing size_t. Original conundrum was to
37 * get it working with -Wformat [-Werror], which can be considered
a303e9a6 38 * overzealous, especially in multi-platform context, but it's
5f584013 39 * conscious choice...
43708c15 40 */
5f584013
AP
41# if defined(_WIN64)
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)
47# define OSSLzu "u"
48# elif defined(__VMS)
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
43708c15 53# define OSSLzu "zu"
5f584013
AP
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 :-( */
43708c15 57# else
5f584013
AP
58# define OSSLzu "lu" /* To see that is works recall what does L
59 * stand for in ILP32 and LP64 */
43708c15
RS
60# endif
61
463a7b8c 62# if !defined(NDEBUG) && !defined(OPENSSL_NO_STDIO)
f3f1cf84 63# define REF_ASSERT_ISNT(test) \
040d43b3 64 (void)((test) ? (OPENSSL_die("refcount error", __FILE__, __LINE__), 1) : 0)
f3f1cf84
RS
65# else
66# define REF_ASSERT_ISNT(i)
984d6c60 67# endif
f3f1cf84
RS
68# ifdef REF_PRINT
69# define REF_PRINT_COUNT(a, b) \
70 fprintf(stderr, "%p:%4d:%s\n", b, b->references, a)
71# else
72# define REF_PRINT_COUNT(a, b)
984d6c60 73# endif
58964a49 74
a773b52a 75# define osslargused(x) (void)x
040d43b3 76# define OPENSSL_CONF "openssl.cnf"
a773b52a 77
0f113f3e
MC
78# ifndef DEVRANDOM
79/*
f367ac2b 80 * set this to a comma-separated list of 'random' device files to try out. By
0f113f3e
MC
81 * default, we will try to read at least one of these files
82 */
83# define DEVRANDOM "/dev/urandom","/dev/random","/dev/srandom"
84# endif
0423f812 85# if !defined(OPENSSL_NO_EGD) && !defined(DEVRANDOM_EGD)
0f113f3e
MC
86/*
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
f367ac2b 89 * files listed in DEVRANDOM did not return enough randomness.
0f113f3e
MC
90 */
91# define DEVRANDOM_EGD "/var/run/egd-pool","/dev/egd-pool","/etc/egd-pool","/etc/entropy"
92# endif
d02b48c6 93
cff55b90 94# if defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI)
3e83e686
RL
95# define NO_SYS_PARAM_H
96# define NO_CHMOD
97# define NO_SYSLOG
0f113f3e
MC
98# endif
99
d02b48c6
RE
100/********************************************************************
101 The Microsoft section
102 ********************************************************************/
0f113f3e 103# if defined(OPENSSL_SYS_WIN32) && !defined(WIN32)
b8384651 104# define WIN32
0f113f3e
MC
105# endif
106# if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS)
cf1b7d96 107# define WINDOWS
0f113f3e
MC
108# endif
109# if defined(OPENSSL_SYS_MSDOS) && !defined(MSDOS)
cf1b7d96 110# define MSDOS
0f113f3e 111# endif
d02b48c6 112
4d60c7e1 113# if (defined(MSDOS) || defined(OPENSSL_SYS_UEFI)) && !defined(GETPID_IS_MEANINGLESS)
9a1e34e5 114# define GETPID_IS_MEANINGLESS
0f113f3e 115# endif
9a1e34e5 116
0f113f3e
MC
117# ifdef WIN32
118# define NO_SYS_UN_H
119# define get_last_sys_error() GetLastError()
120# define clear_sys_error() SetLastError(0)
121# if !defined(WINNT)
122# define WIN_CONSOLE_BUG
123# endif
124# else
125# define get_last_sys_error() errno
126# define clear_sys_error() errno=0
127# endif
58964a49 128
0f113f3e
MC
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__)
135# define WATT32
2c25ebd1 136# define WATT32_NO_OLDIES
0f113f3e
MC
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))
0f113f3e
MC
156# else
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))
163# endif
58964a49 164
0f113f3e 165# if (defined(WINDOWS) || defined(MSDOS))
d02b48c6 166
f642ebc1 167# ifdef __DJGPP__
0f113f3e
MC
168# include <unistd.h>
169# include <sys/stat.h>
170# include <sys/socket.h>
2c25ebd1 171# include <sys/un.h>
0f113f3e
MC
172# include <tcp.h>
173# include <netdb.h>
174# define _setmode setmode
175# define _O_TEXT O_TEXT
176# define _O_BINARY O_BINARY
2c25ebd1
RL
177# define HAS_LFN_SUPPORT(name) (pathconf((name), _PC_NAME_MAX) > 12)
178# undef DEVRANDOM_EGD /* Neither MS-DOS nor FreeDOS provide 'egd' sockets. */
0f113f3e
MC
179# undef DEVRANDOM
180# define DEVRANDOM "/dev/urandom\x24"
181# endif /* __DJGPP__ */
f642ebc1 182
0056ef5d 183# ifndef S_IFDIR
0f113f3e 184# define S_IFDIR _S_IFDIR
0056ef5d 185# endif
6e064240 186
0056ef5d 187# ifndef S_IFMT
0f113f3e 188# define S_IFMT _S_IFMT
0056ef5d 189# endif
6e064240 190
f642ebc1 191# if !defined(WINNT) && !defined(__DJGPP__)
0f113f3e 192# define NO_SYSLOG
0056ef5d
RL
193# endif
194# define NO_DIRENT
d02b48c6 195
d02b48c6 196# ifdef WINDOWS
0f113f3e 197# if !defined(_WIN32_WCE) && !defined(_WIN32_WINNT)
e476f942 198 /*
0f113f3e
MC
199 * Defining _WIN32_WINNT here in e_os.h implies certain "discipline."
200 * Most notably we ought to check for availability of each specific
0ee05b73
AP
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.
0f113f3e 209 */
0ee05b73 210# define _WIN32_WINNT 0x0501
0f113f3e 211# endif
2469e76b 212# if defined(_WIN32_WINNT) || defined(_WIN32_WCE)
61aa2134
AP
213 /*
214 * Just like defining _WIN32_WINNT including winsock2.h implies
8711efb4 215 * certain "discipline" for maintaining [broad] binary compatibility.
61aa2134
AP
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]...
219 */
0f113f3e
MC
220# include <winsock2.h>
221# include <ws2tcpip.h>
8711efb4 222 /* yes, they have to be #included prior to <windows.h> */
0f113f3e
MC
223# endif
224# include <windows.h>
225# include <stdio.h>
226# include <stddef.h>
227# include <errno.h>
228# if defined(_WIN32_WCE) && !defined(EACCES)
229# define EACCES 13
230# endif
231# include <string.h>
232# ifdef _WIN64
233# define strlen(s) _strlen31(s)
1875e6db 234/* cut strings to 2GB */
55c7a4cf 235static __inline unsigned int _strlen31(const char *str)
0f113f3e
MC
236{
237 unsigned int len = 0;
238 while (*str && len < 0x80000000U)
239 str++, len++;
240 return len & 0x7FFFFFFF;
241}
242# endif
243# include <malloc.h>
244# if defined(_MSC_VER) && _MSC_VER<=1200 && defined(_MT) && defined(isspace)
e527201f 245 /* compensate for bug in VC6 ctype.h */
0f113f3e
MC
246# undef isspace
247# undef isdigit
248# undef isalnum
249# undef isupper
250# undef isxdigit
251# endif
252# if defined(_MSC_VER) && !defined(_WIN32_WCE) && !defined(_DLL) && defined(stdin)
253# if _MSC_VER>=1300 && _MSC_VER<1600
254# undef stdin
255# undef stdout
256# undef stderr
257FILE *__iob_func();
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)
262# undef stdin
263# undef stdout
264# undef stderr
265 /*
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'.
e527201f 271 */
0f113f3e
MC
272extern FILE *_imp___iob;
273# define stdin (&_imp___iob[0])
274# define stdout (&_imp___iob[1])
275# define stderr (&_imp___iob[2])
e527201f 276# endif
0f113f3e 277# endif
d02b48c6 278# endif
0f113f3e
MC
279# include <io.h>
280# include <fcntl.h>
d02b48c6 281
0bf23d9b 282# ifdef OPENSSL_SYS_WINCE
0f113f3e 283# define OPENSSL_NO_POSIX_IO
0bf23d9b
RL
284# endif
285
be7b4458 286# define EXIT(n) exit(n)
d02b48c6 287# define LIST_SEPARATOR_CHAR ';'
0056ef5d 288# ifndef X_OK
0f113f3e 289# define X_OK 0
0056ef5d
RL
290# endif
291# ifndef W_OK
0f113f3e 292# define W_OK 2
0056ef5d
RL
293# endif
294# ifndef R_OK
0f113f3e 295# define R_OK 4
0056ef5d 296# endif
0bf23d9b 297# ifdef OPENSSL_SYS_WINCE
0f113f3e 298# define DEFAULT_HOME ""
0bf23d9b 299# else
0f113f3e 300# define DEFAULT_HOME "C:"
0bf23d9b 301# endif
d02b48c6 302
86d21d0b 303/* Avoid Visual Studio 13 GetVersion deprecated problems */
0f113f3e
MC
304# if defined(_MSC_VER) && _MSC_VER>=1800
305# define check_winnt() (1)
306# define check_win_minplat(x) (1)
307# else
308# define check_winnt() (GetVersion() < 0x80000000)
309# define check_win_minplat(x) (LOBYTE(LOWORD(GetVersion())) >= (x))
310# endif
f511b25a 311
0f113f3e 312# else /* The non-microsoft world */
d02b48c6 313
cf1b7d96 314# ifdef OPENSSL_SYS_VMS
0f113f3e
MC
315# define VMS 1
316 /*
317 * some programs don't include stdlib, so exit() and others give implicit
318 * function warnings
319 */
320# include <stdlib.h>
321# if defined(__DECC)
322# include <unistd.h>
323# else
324# include <unixlib.h>
325# endif
0f113f3e 326# define LIST_SEPARATOR_CHAR ','
0c61e299 327 /* We don't have any well-defined random devices on VMS, yet... */
0f113f3e 328# undef DEVRANDOM
1d97c843
TH
329 /*-
330 We need to do this since VMS has the following coding on status codes:
511e596b
RL
331
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
0f113f3e 334 good, while even ones are considered errors.
511e596b
RL
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)
339
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
f625d383 342 the status is tagged as an error, which is what is wanted here.
c3944a99
RL
343
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.
f625d383 347
c3944a99
RL
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.
511e596b
RL
351 -- Richard Levitte
352 */
f625d383
RL
353# define EXIT(n) exit((n) ? (((n) << 3) | 2 | 0x10000000 | 0x35a000) : 1)
354
0f113f3e 355# define NO_SYS_PARAM_H
c168a027 356# define NO_SYS_UN_H
4d8743f4 357
b8f304f7
RL
358# define DEFAULT_HOME "SYS$LOGIN:"
359
d02b48c6 360# else
06018c46 361 /* !defined VMS */
0f113f3e
MC
362# ifdef OPENSSL_UNISTD
363# include OPENSSL_UNISTD
364# else
365# include <unistd.h>
366# endif
367# ifndef NO_SYS_TYPES_H
368# include <sys/types.h>
369# endif
370# ifdef OPENSSL_SYS_WIN32_CYGWIN
371# include <io.h>
372# include <fcntl.h>
373# endif
374
0f113f3e 375# define LIST_SEPARATOR_CHAR ':'
0f113f3e 376# define EXIT(n) exit(n)
d02b48c6 377# endif
d02b48c6 378
0f113f3e 379# endif
7d7d2cbc 380
d02b48c6
RE
381/*************/
382
0f113f3e 383# ifdef USE_SOCKETS
ffbc5b57
DW
384# ifdef OPENSSL_NO_SOCK
385# elif defined(WINDOWS) || defined(MSDOS)
37b1f8bd 386 /* windows world */
ffbc5b57 387# if !defined(__DJGPP__)
0f113f3e
MC
388# if defined(_WIN32_WCE) && _WIN32_WCE<410
389# define getservbyname _masked_declaration_getservbyname
390# endif
391# if !defined(IPPROTO_IP)
a6efc2d1 392 /* winsock[2].h was included already? */
0f113f3e
MC
393# include <winsock.h>
394# endif
395# ifdef getservbyname
396# undef getservbyname
63d3a9c5 397 /* this is used to be wcecompat/include/winsock_extras.h */
0f113f3e
MC
398struct servent *PASCAL getservbyname(const char *, const char *);
399# endif
63d3a9c5 400
0f113f3e 401# ifdef _WIN64
1875e6db
AP
402/*
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
b13fdc48
AP
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.
1875e6db 408 */
0f113f3e
MC
409# define socket(d,t,p) ((int)socket(d,t,p))
410# define accept(s,f,l) ((int)accept(s,f,l))
d02b48c6 411# endif
0f113f3e 412# else
0f113f3e 413# endif
d02b48c6 414
0f113f3e 415# else
d02b48c6 416
0f113f3e
MC
417# ifndef NO_SYS_PARAM_H
418# include <sys/param.h>
419# endif
420# ifdef OPENSSL_SYS_VXWORKS
421# include <time.h>
422# endif
423
424# include <netdb.h>
425# if defined(OPENSSL_SYS_VMS_NODECC)
426# include <socket.h>
427# include <in.h>
428# include <inet.h>
429# else
430# include <sys/socket.h>
431# ifndef NO_SYS_UN_H
432# ifdef OPENSSL_SYS_VXWORKS
433# include <streams/un.h>
434# else
435# include <sys/un.h>
436# endif
437# ifndef UNIX_PATH_MAX
438# define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
439# endif
a545c6f6 440# endif
0f113f3e 441# ifdef FILIO_H
f6739c3d 442# include <sys/filio.h> /* FIONBIO in some SVR4, e.g. unixware, solaris */
0f113f3e
MC
443# endif
444# include <netinet/in.h>
445# include <arpa/inet.h>
28a0841b 446# include <netinet/tcp.h>
0f113f3e
MC
447# endif
448
449# ifdef OPENSSL_SYS_AIX
450# include <sys/select.h>
451# endif
452
453# ifdef __QNX__
454# include <sys/select.h>
455# endif
456
2f2c805a
AP
457# ifndef VMS
458# include <sys/ioctl.h>
0f113f3e 459# else
2f2c805a
AP
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)
0f113f3e 462# include <sys/ioctl.h>
d02b48c6 463# endif
0f113f3e 464# endif
d02b48c6 465
0f113f3e
MC
466# ifdef VMS
467# include <unixio.h>
468# if defined(TCPIP_TYPE_SOCKETSHR)
469# include <socketshr.h>
d02b48c6 470# endif
0f113f3e
MC
471# endif
472
0f113f3e
MC
473# ifndef INVALID_SOCKET
474# define INVALID_SOCKET (-1)
475# endif /* INVALID_SOCKET */
d02b48c6 476# endif
a6dab873 477
0f113f3e
MC
478/*
479 * Some IPv6 implementations are broken, disable them in known bad versions.
a6dab873
DSH
480 */
481# if !defined(OPENSSL_USE_IPV6)
0f113f3e
MC
482# if defined(AF_INET6) && !defined(NETWARE_CLIB)
483# define OPENSSL_USE_IPV6 1
484# else
485# define OPENSSL_USE_IPV6 0
486# endif
a6dab873
DSH
487# endif
488
0f113f3e 489# endif
d02b48c6 490
0f113f3e
MC
491# ifndef OPENSSL_EXIT
492# if defined(MONOLITH) && !defined(OPENSSL_C)
493# define OPENSSL_EXIT(n) return(n)
494# else
495# define OPENSSL_EXIT(n) do { EXIT(n); return(n); } while(0)
496# endif
1c3e4a36 497# endif
1c3e4a36 498
d02b48c6
RE
499/***********************************************/
500
0f113f3e 501# if defined(OPENSSL_SYS_WINDOWS)
e6fa67fa
RL
502# define strcasecmp _stricmp
503# define strncasecmp _strnicmp
dc6b5c7b
RL
504# if (_MSC_VER >= 1310)
505# define open _open
506# define fdopen _fdopen
507# define close _close
8d95ca36
M
508# ifndef strdup
509# define strdup _strdup
510# endif
dc6b5c7b 511# define unlink _unlink
2e38091c 512# define fileno _fileno
dc6b5c7b 513# endif
7233bea2
RL
514# else
515# include <strings.h>
0f113f3e 516# endif
3bfd99bf 517
6a89a25c 518/* vxworks */
0f113f3e
MC
519# if defined(OPENSSL_SYS_VXWORKS)
520# include <ioLib.h>
521# include <tickLib.h>
522# include <sysLib.h>
6a89a25c 523
0f113f3e 524# define TTY_STRUCT int
6a89a25c 525
0f113f3e 526# define sleep(a) taskDelay((a) * sysClkRateGet())
6a89a25c 527
0f113f3e
MC
528# include <vxWorks.h>
529# include <sockLib.h>
530# include <taskLib.h>
6a89a25c 531
0f113f3e 532# define getpid taskIdSelf
6a89a25c 533
0f113f3e
MC
534/*
535 * NOTE: these are implemented by helpers in database app! if the database is
a303e9a6 536 * not linked, we need to implement them elsewhere
0f113f3e 537 */
6a89a25c
RL
538struct hostent *gethostbyname(const char *name);
539struct hostent *gethostbyaddr(const char *addr, int length, int type);
540struct servent *getservbyname(const char *name, const char *proto);
541
0f113f3e 542# endif
6a89a25c
RL
543/* end vxworks */
544
43c56417
KR
545#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
546# define CRYPTO_memcmp memcmp
547#endif
548
d02b48c6
RE
549#ifdef __cplusplus
550}
551#endif
552
553#endif