]> git.ipfire.org Git - thirdparty/openssl.git/blame - e_os.h
Make asn1 fuzzer more reproducible
[thirdparty/openssl.git] / e_os.h
CommitLineData
b6cff313
RS
1/*
2 * Copyright 1995-2016 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
MC
15# include <openssl/e_os2.h>
16/*
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.
19 */
fa470a84 20
d02b48c6
RE
21#ifdef __cplusplus
22extern "C" {
23#endif
24
58964a49 25/* Used to checking reference counts, most while doing perl5 stuff :-) */
f3f1cf84 26# if defined(OPENSSL_NO_STDIO)
f3f1cf84
RS
27# if defined(REF_PRINT)
28# error "REF_PRINT requires stdio"
29# endif
0f113f3e 30# endif
f3f1cf84 31
463a7b8c 32# if !defined(NDEBUG) && !defined(OPENSSL_NO_STDIO)
f3f1cf84 33# define REF_ASSERT_ISNT(test) \
040d43b3 34 (void)((test) ? (OPENSSL_die("refcount error", __FILE__, __LINE__), 1) : 0)
f3f1cf84
RS
35# else
36# define REF_ASSERT_ISNT(i)
984d6c60 37# endif
f3f1cf84
RS
38# ifdef REF_PRINT
39# define REF_PRINT_COUNT(a, b) \
40 fprintf(stderr, "%p:%4d:%s\n", b, b->references, a)
41# else
42# define REF_PRINT_COUNT(a, b)
984d6c60 43# endif
58964a49 44
a773b52a 45# define osslargused(x) (void)x
040d43b3 46# define OPENSSL_CONF "openssl.cnf"
a773b52a 47
0f113f3e
MC
48# ifndef DEVRANDOM
49/*
50 * set this to a comma-separated list of 'random' device files to try out. My
51 * default, we will try to read at least one of these files
52 */
53# define DEVRANDOM "/dev/urandom","/dev/random","/dev/srandom"
54# endif
0423f812 55# if !defined(OPENSSL_NO_EGD) && !defined(DEVRANDOM_EGD)
0f113f3e
MC
56/*
57 * set this to a comma-separated list of 'egd' sockets to try out. These
58 * sockets will be tried in the order listed in case accessing the device
59 * files listed in DEVRANDOM did not return enough entropy.
60 */
61# define DEVRANDOM_EGD "/var/run/egd-pool","/dev/egd-pool","/etc/egd-pool","/etc/entropy"
62# endif
d02b48c6 63
0f113f3e 64# if defined(OPENSSL_SYS_VXWORKS)
3e83e686
RL
65# define NO_SYS_PARAM_H
66# define NO_CHMOD
67# define NO_SYSLOG
0f113f3e
MC
68# endif
69
d02b48c6
RE
70/********************************************************************
71 The Microsoft section
72 ********************************************************************/
0f113f3e 73# if defined(OPENSSL_SYS_WIN32) && !defined(WIN32)
b8384651 74# define WIN32
0f113f3e
MC
75# endif
76# if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS)
cf1b7d96 77# define WINDOWS
0f113f3e
MC
78# endif
79# if defined(OPENSSL_SYS_MSDOS) && !defined(MSDOS)
cf1b7d96 80# define MSDOS
0f113f3e 81# endif
d02b48c6 82
4d60c7e1 83# if (defined(MSDOS) || defined(OPENSSL_SYS_UEFI)) && !defined(GETPID_IS_MEANINGLESS)
9a1e34e5 84# define GETPID_IS_MEANINGLESS
0f113f3e 85# endif
9a1e34e5 86
0f113f3e
MC
87# ifdef WIN32
88# define NO_SYS_UN_H
89# define get_last_sys_error() GetLastError()
90# define clear_sys_error() SetLastError(0)
91# if !defined(WINNT)
92# define WIN_CONSOLE_BUG
93# endif
94# else
95# define get_last_sys_error() errno
96# define clear_sys_error() errno=0
97# endif
58964a49 98
0f113f3e
MC
99# if defined(WINDOWS)
100# define get_last_socket_error() WSAGetLastError()
101# define clear_socket_error() WSASetLastError(0)
102# define readsocket(s,b,n) recv((s),(b),(n),0)
103# define writesocket(s,b,n) send((s),(b),(n),0)
104# elif defined(__DJGPP__)
105# define WATT32
2c25ebd1 106# define WATT32_NO_OLDIES
0f113f3e
MC
107# define get_last_socket_error() errno
108# define clear_socket_error() errno=0
109# define closesocket(s) close_s(s)
110# define readsocket(s,b,n) read_s(s,b,n)
111# define writesocket(s,b,n) send(s,b,n,0)
112# elif defined(OPENSSL_SYS_VMS)
113# define get_last_socket_error() errno
114# define clear_socket_error() errno=0
115# define ioctlsocket(a,b,c) ioctl(a,b,c)
116# define closesocket(s) close(s)
117# define readsocket(s,b,n) recv((s),(b),(n),0)
118# define writesocket(s,b,n) send((s),(b),(n),0)
119# elif defined(OPENSSL_SYS_VXWORKS)
120# define get_last_socket_error() errno
121# define clear_socket_error() errno=0
122# define ioctlsocket(a,b,c) ioctl((a),(b),(int)(c))
123# define closesocket(s) close(s)
124# define readsocket(s,b,n) read((s),(b),(n))
125# define writesocket(s,b,n) write((s),(char *)(b),(n))
0f113f3e
MC
126# else
127# define get_last_socket_error() errno
128# define clear_socket_error() errno=0
129# define ioctlsocket(a,b,c) ioctl(a,b,c)
130# define closesocket(s) close(s)
131# define readsocket(s,b,n) read((s),(b),(n))
132# define writesocket(s,b,n) write((s),(b),(n))
133# endif
58964a49 134
0f113f3e 135# if (defined(WINDOWS) || defined(MSDOS))
d02b48c6 136
f642ebc1 137# ifdef __DJGPP__
0f113f3e
MC
138# include <unistd.h>
139# include <sys/stat.h>
140# include <sys/socket.h>
2c25ebd1 141# include <sys/un.h>
0f113f3e
MC
142# include <tcp.h>
143# include <netdb.h>
144# define _setmode setmode
145# define _O_TEXT O_TEXT
146# define _O_BINARY O_BINARY
2c25ebd1
RL
147# define HAS_LFN_SUPPORT(name) (pathconf((name), _PC_NAME_MAX) > 12)
148# undef DEVRANDOM_EGD /* Neither MS-DOS nor FreeDOS provide 'egd' sockets. */
0f113f3e
MC
149# undef DEVRANDOM
150# define DEVRANDOM "/dev/urandom\x24"
151# endif /* __DJGPP__ */
f642ebc1 152
0056ef5d 153# ifndef S_IFDIR
0f113f3e 154# define S_IFDIR _S_IFDIR
0056ef5d 155# endif
6e064240 156
0056ef5d 157# ifndef S_IFMT
0f113f3e 158# define S_IFMT _S_IFMT
0056ef5d 159# endif
6e064240 160
f642ebc1 161# if !defined(WINNT) && !defined(__DJGPP__)
0f113f3e 162# define NO_SYSLOG
0056ef5d
RL
163# endif
164# define NO_DIRENT
d02b48c6 165
d02b48c6 166# ifdef WINDOWS
0f113f3e 167# if !defined(_WIN32_WCE) && !defined(_WIN32_WINNT)
e476f942 168 /*
0f113f3e
MC
169 * Defining _WIN32_WINNT here in e_os.h implies certain "discipline."
170 * Most notably we ought to check for availability of each specific
0ee05b73
AP
171 * routine that was introduced after denoted _WIN32_WINNT with
172 * GetProcAddress(). Normally newer functions are masked with higher
173 * _WIN32_WINNT in SDK headers. So that if you wish to use them in
174 * some module, you'd need to override _WIN32_WINNT definition in
175 * the target module in order to "reach for" prototypes, but replace
176 * calls to new functions with indirect calls. Alternatively it
177 * might be possible to achieve the goal by /DELAYLOAD-ing .DLLs
178 * and check for current OS version instead.
0f113f3e 179 */
0ee05b73 180# define _WIN32_WINNT 0x0501
0f113f3e 181# endif
2469e76b 182# if defined(_WIN32_WINNT) || defined(_WIN32_WCE)
61aa2134
AP
183 /*
184 * Just like defining _WIN32_WINNT including winsock2.h implies
8711efb4 185 * certain "discipline" for maintaining [broad] binary compatibility.
61aa2134
AP
186 * As long as structures are invariant among Winsock versions,
187 * it's sufficient to check for specific Winsock2 API availability
188 * at run-time [DSO_global_lookup is recommended]...
189 */
0f113f3e
MC
190# include <winsock2.h>
191# include <ws2tcpip.h>
8711efb4 192 /* yes, they have to be #included prior to <windows.h> */
0f113f3e
MC
193# endif
194# include <windows.h>
195# include <stdio.h>
196# include <stddef.h>
197# include <errno.h>
198# if defined(_WIN32_WCE) && !defined(EACCES)
199# define EACCES 13
200# endif
201# include <string.h>
202# ifdef _WIN64
203# define strlen(s) _strlen31(s)
1875e6db 204/* cut strings to 2GB */
55c7a4cf 205static __inline unsigned int _strlen31(const char *str)
0f113f3e
MC
206{
207 unsigned int len = 0;
208 while (*str && len < 0x80000000U)
209 str++, len++;
210 return len & 0x7FFFFFFF;
211}
212# endif
213# include <malloc.h>
214# if defined(_MSC_VER) && _MSC_VER<=1200 && defined(_MT) && defined(isspace)
e527201f 215 /* compensate for bug in VC6 ctype.h */
0f113f3e
MC
216# undef isspace
217# undef isdigit
218# undef isalnum
219# undef isupper
220# undef isxdigit
221# endif
222# if defined(_MSC_VER) && !defined(_WIN32_WCE) && !defined(_DLL) && defined(stdin)
223# if _MSC_VER>=1300 && _MSC_VER<1600
224# undef stdin
225# undef stdout
226# undef stderr
227FILE *__iob_func();
228# define stdin (&__iob_func()[0])
229# define stdout (&__iob_func()[1])
230# define stderr (&__iob_func()[2])
231# elif _MSC_VER<1300 && defined(I_CAN_LIVE_WITH_LNK4049)
232# undef stdin
233# undef stdout
234# undef stderr
235 /*
236 * pre-1300 has __p__iob(), but it's available only in msvcrt.lib,
237 * or in other words with /MD. Declaring implicit import, i.e. with
238 * _imp_ prefix, works correctly with all compiler options, but
239 * without /MD results in LINK warning LNK4049: 'locally defined
240 * symbol "__iob" imported'.
e527201f 241 */
0f113f3e
MC
242extern FILE *_imp___iob;
243# define stdin (&_imp___iob[0])
244# define stdout (&_imp___iob[1])
245# define stderr (&_imp___iob[2])
e527201f 246# endif
0f113f3e 247# endif
d02b48c6 248# endif
0f113f3e
MC
249# include <io.h>
250# include <fcntl.h>
d02b48c6 251
0bf23d9b 252# ifdef OPENSSL_SYS_WINCE
0f113f3e 253# define OPENSSL_NO_POSIX_IO
0bf23d9b
RL
254# endif
255
be7b4458 256# define EXIT(n) exit(n)
d02b48c6 257# define LIST_SEPARATOR_CHAR ';'
0056ef5d 258# ifndef X_OK
0f113f3e 259# define X_OK 0
0056ef5d
RL
260# endif
261# ifndef W_OK
0f113f3e 262# define W_OK 2
0056ef5d
RL
263# endif
264# ifndef R_OK
0f113f3e 265# define R_OK 4
0056ef5d 266# endif
0bf23d9b 267# ifdef OPENSSL_SYS_WINCE
0f113f3e 268# define DEFAULT_HOME ""
0bf23d9b 269# else
0f113f3e 270# define DEFAULT_HOME "C:"
0bf23d9b 271# endif
d02b48c6 272
86d21d0b 273/* Avoid Visual Studio 13 GetVersion deprecated problems */
0f113f3e
MC
274# if defined(_MSC_VER) && _MSC_VER>=1800
275# define check_winnt() (1)
276# define check_win_minplat(x) (1)
277# else
278# define check_winnt() (GetVersion() < 0x80000000)
279# define check_win_minplat(x) (LOBYTE(LOWORD(GetVersion())) >= (x))
280# endif
f511b25a 281
0f113f3e 282# else /* The non-microsoft world */
d02b48c6 283
cf1b7d96 284# ifdef OPENSSL_SYS_VMS
0f113f3e
MC
285# define VMS 1
286 /*
287 * some programs don't include stdlib, so exit() and others give implicit
288 * function warnings
289 */
290# include <stdlib.h>
291# if defined(__DECC)
292# include <unistd.h>
293# else
294# include <unixlib.h>
295# endif
0f113f3e 296# define LIST_SEPARATOR_CHAR ','
0c61e299 297 /* We don't have any well-defined random devices on VMS, yet... */
0f113f3e 298# undef DEVRANDOM
1d97c843
TH
299 /*-
300 We need to do this since VMS has the following coding on status codes:
511e596b
RL
301
302 Bits 0-2: status type: 0 = warning, 1 = success, 2 = error, 3 = info ...
303 The important thing to know is that odd numbers are considered
0f113f3e 304 good, while even ones are considered errors.
511e596b
RL
305 Bits 3-15: actual status number
306 Bits 16-27: facility number. 0 is considered "unknown"
307 Bits 28-31: control bits. If bit 28 is set, the shell won't try to
308 output the message (which, for random codes, just looks ugly)
309
310 So, what we do here is to change 0 to 1 to get the default success status,
311 and everything else is shifted up to fit into the status number field, and
f625d383 312 the status is tagged as an error, which is what is wanted here.
c3944a99
RL
313
314 Finally, we add the VMS C facility code 0x35a000, because there are some
315 programs, such as Perl, that will reinterpret the code back to something
316 POSIXly. 'man perlvms' explains it further.
f625d383 317
c3944a99
RL
318 NOTE: the perlvms manual wants to turn all codes 2 to 255 into success
319 codes (status type = 1). I couldn't disagree more. Fortunately, the
320 status type doesn't seem to bother Perl.
511e596b
RL
321 -- Richard Levitte
322 */
f625d383
RL
323# define EXIT(n) exit((n) ? (((n) << 3) | 2 | 0x10000000 | 0x35a000) : 1)
324
0f113f3e 325# define NO_SYS_PARAM_H
c168a027 326# define NO_SYS_UN_H
4d8743f4 327
b8f304f7
RL
328# define DEFAULT_HOME "SYS$LOGIN:"
329
d02b48c6 330# else
06018c46 331 /* !defined VMS */
0f113f3e
MC
332# ifdef OPENSSL_UNISTD
333# include OPENSSL_UNISTD
334# else
335# include <unistd.h>
336# endif
337# ifndef NO_SYS_TYPES_H
338# include <sys/types.h>
339# endif
340# ifdef OPENSSL_SYS_WIN32_CYGWIN
341# include <io.h>
342# include <fcntl.h>
343# endif
344
0f113f3e 345# define LIST_SEPARATOR_CHAR ':'
0f113f3e 346# define EXIT(n) exit(n)
d02b48c6 347# endif
d02b48c6 348
0f113f3e 349# endif
7d7d2cbc 350
d02b48c6
RE
351/*************/
352
0f113f3e 353# ifdef USE_SOCKETS
ffbc5b57
DW
354# ifdef OPENSSL_NO_SOCK
355# elif defined(WINDOWS) || defined(MSDOS)
37b1f8bd 356 /* windows world */
ffbc5b57 357# if !defined(__DJGPP__)
0f113f3e
MC
358# if defined(_WIN32_WCE) && _WIN32_WCE<410
359# define getservbyname _masked_declaration_getservbyname
360# endif
361# if !defined(IPPROTO_IP)
a6efc2d1 362 /* winsock[2].h was included already? */
0f113f3e
MC
363# include <winsock.h>
364# endif
365# ifdef getservbyname
366# undef getservbyname
63d3a9c5 367 /* this is used to be wcecompat/include/winsock_extras.h */
0f113f3e
MC
368struct servent *PASCAL getservbyname(const char *, const char *);
369# endif
63d3a9c5 370
0f113f3e 371# ifdef _WIN64
1875e6db
AP
372/*
373 * Even though sizeof(SOCKET) is 8, it's safe to cast it to int, because
374 * the value constitutes an index in per-process table of limited size
b13fdc48
AP
375 * and not a real pointer. And we also depend on fact that all processors
376 * Windows run on happen to be two's-complement, which allows to
377 * interchange INVALID_SOCKET and -1.
1875e6db 378 */
0f113f3e
MC
379# define socket(d,t,p) ((int)socket(d,t,p))
380# define accept(s,f,l) ((int)accept(s,f,l))
d02b48c6 381# endif
0f113f3e 382# else
0f113f3e 383# endif
d02b48c6 384
0f113f3e 385# else
d02b48c6 386
0f113f3e
MC
387# ifndef NO_SYS_PARAM_H
388# include <sys/param.h>
389# endif
390# ifdef OPENSSL_SYS_VXWORKS
391# include <time.h>
392# endif
393
394# include <netdb.h>
395# if defined(OPENSSL_SYS_VMS_NODECC)
396# include <socket.h>
397# include <in.h>
398# include <inet.h>
399# else
400# include <sys/socket.h>
401# ifndef NO_SYS_UN_H
402# ifdef OPENSSL_SYS_VXWORKS
403# include <streams/un.h>
404# else
405# include <sys/un.h>
406# endif
407# ifndef UNIX_PATH_MAX
408# define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
409# endif
a545c6f6 410# endif
0f113f3e 411# ifdef FILIO_H
f6739c3d 412# include <sys/filio.h> /* FIONBIO in some SVR4, e.g. unixware, solaris */
0f113f3e
MC
413# endif
414# include <netinet/in.h>
415# include <arpa/inet.h>
28a0841b 416# include <netinet/tcp.h>
0f113f3e
MC
417# endif
418
419# ifdef OPENSSL_SYS_AIX
420# include <sys/select.h>
421# endif
422
423# ifdef __QNX__
424# include <sys/select.h>
425# endif
426
2f2c805a
AP
427# ifndef VMS
428# include <sys/ioctl.h>
0f113f3e 429# else
2f2c805a
AP
430 /* ioctl is only in VMS > 7.0 and when socketshr is not used */
431# if !defined(TCPIP_TYPE_SOCKETSHR) && defined(__VMS_VER) && (__VMS_VER > 70000000)
0f113f3e 432# include <sys/ioctl.h>
d02b48c6 433# endif
0f113f3e 434# endif
d02b48c6 435
0f113f3e
MC
436# ifdef VMS
437# include <unixio.h>
438# if defined(TCPIP_TYPE_SOCKETSHR)
439# include <socketshr.h>
d02b48c6 440# endif
0f113f3e
MC
441# endif
442
0f113f3e
MC
443# ifndef INVALID_SOCKET
444# define INVALID_SOCKET (-1)
445# endif /* INVALID_SOCKET */
d02b48c6 446# endif
a6dab873 447
0f113f3e
MC
448/*
449 * Some IPv6 implementations are broken, disable them in known bad versions.
a6dab873
DSH
450 */
451# if !defined(OPENSSL_USE_IPV6)
0f113f3e
MC
452# if defined(AF_INET6) && !defined(NETWARE_CLIB)
453# define OPENSSL_USE_IPV6 1
454# else
455# define OPENSSL_USE_IPV6 0
456# endif
a6dab873
DSH
457# endif
458
0f113f3e 459# endif
d02b48c6 460
0f113f3e
MC
461# ifndef OPENSSL_EXIT
462# if defined(MONOLITH) && !defined(OPENSSL_C)
463# define OPENSSL_EXIT(n) return(n)
464# else
465# define OPENSSL_EXIT(n) do { EXIT(n); return(n); } while(0)
466# endif
1c3e4a36 467# endif
1c3e4a36 468
d02b48c6
RE
469/***********************************************/
470
0f113f3e 471# if defined(OPENSSL_SYS_WINDOWS)
e6fa67fa
RL
472# define strcasecmp _stricmp
473# define strncasecmp _strnicmp
dc6b5c7b
RL
474# if (_MSC_VER >= 1310)
475# define open _open
476# define fdopen _fdopen
477# define close _close
8d95ca36
M
478# ifndef strdup
479# define strdup _strdup
480# endif
dc6b5c7b
RL
481# define unlink _unlink
482# endif
7233bea2
RL
483# else
484# include <strings.h>
0f113f3e 485# endif
3bfd99bf 486
6a89a25c 487/* vxworks */
0f113f3e
MC
488# if defined(OPENSSL_SYS_VXWORKS)
489# include <ioLib.h>
490# include <tickLib.h>
491# include <sysLib.h>
6a89a25c 492
0f113f3e 493# define TTY_STRUCT int
6a89a25c 494
0f113f3e 495# define sleep(a) taskDelay((a) * sysClkRateGet())
6a89a25c 496
0f113f3e
MC
497# include <vxWorks.h>
498# include <sockLib.h>
499# include <taskLib.h>
6a89a25c 500
0f113f3e 501# define getpid taskIdSelf
6a89a25c 502
0f113f3e
MC
503/*
504 * NOTE: these are implemented by helpers in database app! if the database is
505 * not linked, we need to implement them elswhere
506 */
6a89a25c
RL
507struct hostent *gethostbyname(const char *name);
508struct hostent *gethostbyaddr(const char *addr, int length, int type);
509struct servent *getservbyname(const char *name, const char *proto);
510
0f113f3e 511# endif
6a89a25c
RL
512/* end vxworks */
513
b6eb9827
DSH
514#define OSSL_NELEM(x) (sizeof(x)/sizeof(x[0]))
515
d02b48c6
RE
516#ifdef __cplusplus
517}
518#endif
519
520#endif