Document missing EVP_PKEY_method_* items
[openssl.git] / e_os.h
1 /*
2  * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
3  *
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
8  */
9
10 #ifndef HEADER_E_OS_H
11 # define HEADER_E_OS_H
12
13 # include <openssl/opensslconf.h>
14
15 # include <openssl/e_os2.h>
16 # include <openssl/crypto.h>
17 # include <internal/nelem.h>
18
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  */
23
24 #ifdef  __cplusplus
25 extern "C" {
26 #endif
27
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"
32 #  endif
33 # endif
34
35 /*
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
39  * conscious choice...
40  */
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
53 #  define OSSLzu  "zu"
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 :-( */
57 # else
58 #  define OSSLzu  "lu"      /* To see that is works recall what does L
59                              * stand for in ILP32 and LP64 */
60 # endif
61
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)
65 # else
66 #  define REF_ASSERT_ISNT(i)
67 # endif
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)
73 # endif
74
75 # define osslargused(x)      (void)x
76 # define OPENSSL_CONF        "openssl.cnf"
77
78 # ifndef DEVRANDOM
79 /*
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
82  */
83 #  define DEVRANDOM "/dev/urandom","/dev/random","/dev/srandom"
84 # endif
85 # if !defined(OPENSSL_NO_EGD) && !defined(DEVRANDOM_EGD)
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
89  * files listed in DEVRANDOM did not return enough randomness.
90  */
91 #  define DEVRANDOM_EGD "/var/run/egd-pool","/dev/egd-pool","/etc/egd-pool","/etc/entropy"
92 # endif
93
94 # if defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI)
95 #  define NO_SYS_PARAM_H
96 #  define NO_CHMOD
97 #  define NO_SYSLOG
98 # endif
99
100 /********************************************************************
101  The Microsoft section
102  ********************************************************************/
103 # if defined(OPENSSL_SYS_WIN32) && !defined(WIN32)
104 #  define WIN32
105 # endif
106 # if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS)
107 #  define WINDOWS
108 # endif
109 # if defined(OPENSSL_SYS_MSDOS) && !defined(MSDOS)
110 #  define MSDOS
111 # endif
112
113 # if (defined(MSDOS) || defined(OPENSSL_SYS_UEFI)) && !defined(GETPID_IS_MEANINGLESS)
114 #  define GETPID_IS_MEANINGLESS
115 # endif
116
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
128
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
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))
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
164
165 # if (defined(WINDOWS) || defined(MSDOS))
166
167 #  ifdef __DJGPP__
168 #   include <unistd.h>
169 #   include <sys/stat.h>
170 #   include <sys/socket.h>
171 #   include <sys/un.h>
172 #   include <tcp.h>
173 #   include <netdb.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.  */
179 #   undef DEVRANDOM
180 #   define DEVRANDOM "/dev/urandom\x24"
181 #  endif                        /* __DJGPP__ */
182
183 #  ifndef S_IFDIR
184 #   define S_IFDIR     _S_IFDIR
185 #  endif
186
187 #  ifndef S_IFMT
188 #   define S_IFMT      _S_IFMT
189 #  endif
190
191 #  if !defined(WINNT) && !defined(__DJGPP__)
192 #   define NO_SYSLOG
193 #  endif
194 #  define NO_DIRENT
195
196 #  ifdef WINDOWS
197 #   if !defined(_WIN32_WCE) && !defined(_WIN32_WINNT)
198        /*
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.
209         */
210 #    define _WIN32_WINNT 0x0501
211 #   endif
212 #   if defined(_WIN32_WINNT) || defined(_WIN32_WCE)
213        /*
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]...
219         */
220 #    include <winsock2.h>
221 #    include <ws2tcpip.h>
222        /* yes, they have to be #included prior to <windows.h> */
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)
234 /* cut strings to 2GB */
235 static __inline unsigned int _strlen31(const char *str)
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)
245        /* compensate for bug in VC6 ctype.h */
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
257 FILE *__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'.
271           */
272 extern FILE *_imp___iob;
273 #     define stdin  (&_imp___iob[0])
274 #     define stdout (&_imp___iob[1])
275 #     define stderr (&_imp___iob[2])
276 #    endif
277 #   endif
278 #  endif
279 #  include <io.h>
280 #  include <fcntl.h>
281
282 #  ifdef OPENSSL_SYS_WINCE
283 #   define OPENSSL_NO_POSIX_IO
284 #  endif
285
286 #  define EXIT(n) exit(n)
287 #  define LIST_SEPARATOR_CHAR ';'
288 #  ifndef X_OK
289 #   define X_OK        0
290 #  endif
291 #  ifndef W_OK
292 #   define W_OK        2
293 #  endif
294 #  ifndef R_OK
295 #   define R_OK        4
296 #  endif
297 #  ifdef OPENSSL_SYS_WINCE
298 #   define DEFAULT_HOME  ""
299 #  else
300 #   define DEFAULT_HOME  "C:"
301 #  endif
302
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)
307 #  else
308 #   define check_winnt() (GetVersion() < 0x80000000)
309 #   define check_win_minplat(x) (LOBYTE(LOWORD(GetVersion())) >= (x))
310 #  endif
311
312 # else                          /* The non-microsoft world */
313
314 #  ifdef OPENSSL_SYS_VMS
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
326 #   define LIST_SEPARATOR_CHAR ','
327   /* We don't have any well-defined random devices on VMS, yet... */
328 #   undef DEVRANDOM
329   /*-
330      We need to do this since VMS has the following coding on status codes:
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
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)
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
342      the status is tagged as an error, which is what is wanted here.
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.
347
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.
351      -- Richard Levitte
352   */
353 #   define EXIT(n)  exit((n) ? (((n) << 3) | 2 | 0x10000000 | 0x35a000) : 1)
354
355 #   define NO_SYS_PARAM_H
356 #   define NO_SYS_UN_H
357
358 #   define DEFAULT_HOME "SYS$LOGIN:"
359
360 #  else
361      /* !defined VMS */
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
375 #   define LIST_SEPARATOR_CHAR ':'
376 #   define EXIT(n)             exit(n)
377 #  endif
378
379 # endif
380
381 /*************/
382
383 # ifdef USE_SOCKETS
384 #  ifdef OPENSSL_NO_SOCK
385 #  elif defined(WINDOWS) || defined(MSDOS)
386       /* windows world */
387 #   if !defined(__DJGPP__)
388 #    if defined(_WIN32_WCE) && _WIN32_WCE<410
389 #     define getservbyname _masked_declaration_getservbyname
390 #    endif
391 #    if !defined(IPPROTO_IP)
392          /* winsock[2].h was included already? */
393 #     include <winsock.h>
394 #    endif
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 *);
399 #    endif
400
401 #    ifdef _WIN64
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
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.
408  */
409 #     define socket(d,t,p)   ((int)socket(d,t,p))
410 #     define accept(s,f,l)   ((int)accept(s,f,l))
411 #    endif
412 #   else
413 #   endif
414
415 #  else
416
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
440 #    endif
441 #    ifdef FILIO_H
442 #     include <sys/filio.h> /* FIONBIO in some SVR4, e.g. unixware, solaris */
443 #    endif
444 #    include <netinet/in.h>
445 #    include <arpa/inet.h>
446 #    include <netinet/tcp.h>
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
457 #   ifndef VMS
458 #    include <sys/ioctl.h>
459 #   else
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>
463 #    endif
464 #   endif
465
466 #   ifdef VMS
467 #    include <unixio.h>
468 #    if defined(TCPIP_TYPE_SOCKETSHR)
469 #     include <socketshr.h>
470 #    endif
471 #   endif
472
473 #   ifndef INVALID_SOCKET
474 #    define INVALID_SOCKET      (-1)
475 #   endif                       /* INVALID_SOCKET */
476 #  endif
477
478 /*
479  * Some IPv6 implementations are broken, disable them in known bad versions.
480  */
481 #  if !defined(OPENSSL_USE_IPV6)
482 #   if defined(AF_INET6) && !defined(NETWARE_CLIB)
483 #    define OPENSSL_USE_IPV6 1
484 #   else
485 #    define OPENSSL_USE_IPV6 0
486 #   endif
487 #  endif
488
489 # endif
490
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
497 # endif
498
499 /***********************************************/
500
501 # if defined(OPENSSL_SYS_WINDOWS)
502 #  define strcasecmp _stricmp
503 #  define strncasecmp _strnicmp
504 #  if (_MSC_VER >= 1310)
505 #   define open _open
506 #   define fdopen _fdopen
507 #   define close _close
508 #   ifndef strdup
509 #    define strdup _strdup
510 #   endif
511 #   define unlink _unlink
512 #   define fileno _fileno
513 #  endif
514 # else
515 #  include <strings.h>
516 # endif
517
518 /* vxworks */
519 # if defined(OPENSSL_SYS_VXWORKS)
520 #  include <ioLib.h>
521 #  include <tickLib.h>
522 #  include <sysLib.h>
523
524 #  define TTY_STRUCT int
525
526 #  define sleep(a) taskDelay((a) * sysClkRateGet())
527
528 #  include <vxWorks.h>
529 #  include <sockLib.h>
530 #  include <taskLib.h>
531
532 #  define getpid taskIdSelf
533
534 /*
535  * NOTE: these are implemented by helpers in database app! if the database is
536  * not linked, we need to implement them elsewhere
537  */
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);
541
542 # endif
543 /* end vxworks */
544
545 #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
546 # define CRYPTO_memcmp memcmp
547 #endif
548
549 #ifdef  __cplusplus
550 }
551 #endif
552
553 #endif