A local copy of OpenSSL from GitHub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

513 lines
15 KiB

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