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.

373 lines
11 KiB

20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
  1. /*
  2. * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (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 OSSL_E_OS_H
  10. # define OSSL_E_OS_H
  11. # include <limits.h>
  12. # include <openssl/opensslconf.h>
  13. # include <openssl/e_os2.h>
  14. # include <openssl/crypto.h>
  15. # include "internal/nelem.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. */
  20. # if defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI)
  21. # define NO_CHMOD
  22. # define NO_SYSLOG
  23. # endif
  24. # define get_last_sys_error() errno
  25. # define clear_sys_error() errno=0
  26. # define set_sys_error(e) errno=(e)
  27. /********************************************************************
  28. The Microsoft section
  29. ********************************************************************/
  30. # if defined(OPENSSL_SYS_WIN32) && !defined(WIN32)
  31. # define WIN32
  32. # endif
  33. # if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS)
  34. # define WINDOWS
  35. # endif
  36. # if defined(OPENSSL_SYS_MSDOS) && !defined(MSDOS)
  37. # define MSDOS
  38. # endif
  39. # ifdef WIN32
  40. # undef get_last_sys_error
  41. # undef clear_sys_error
  42. # undef set_sys_error
  43. # define get_last_sys_error() GetLastError()
  44. # define clear_sys_error() SetLastError(0)
  45. # define set_sys_error(e) SetLastError(e)
  46. # if !defined(WINNT)
  47. # define WIN_CONSOLE_BUG
  48. # endif
  49. # else
  50. # endif
  51. # if (defined(WINDOWS) || defined(MSDOS))
  52. # ifdef __DJGPP__
  53. # include <unistd.h>
  54. # include <sys/stat.h>
  55. # define _setmode setmode
  56. # define _O_TEXT O_TEXT
  57. # define _O_BINARY O_BINARY
  58. # undef DEVRANDOM_EGD /* Neither MS-DOS nor FreeDOS provide 'egd' sockets. */
  59. # undef DEVRANDOM
  60. # define DEVRANDOM "/dev/urandom\x24"
  61. # endif /* __DJGPP__ */
  62. # ifndef S_IFDIR
  63. # define S_IFDIR _S_IFDIR
  64. # endif
  65. # ifndef S_IFMT
  66. # define S_IFMT _S_IFMT
  67. # endif
  68. # if !defined(WINNT) && !defined(__DJGPP__)
  69. # define NO_SYSLOG
  70. # endif
  71. # ifdef WINDOWS
  72. # if !defined(_WIN32_WCE) && !defined(_WIN32_WINNT)
  73. /*
  74. * Defining _WIN32_WINNT here in e_os.h implies certain "discipline."
  75. * Most notably we ought to check for availability of each specific
  76. * routine that was introduced after denoted _WIN32_WINNT with
  77. * GetProcAddress(). Normally newer functions are masked with higher
  78. * _WIN32_WINNT in SDK headers. So that if you wish to use them in
  79. * some module, you'd need to override _WIN32_WINNT definition in
  80. * the target module in order to "reach for" prototypes, but replace
  81. * calls to new functions with indirect calls. Alternatively it
  82. * might be possible to achieve the goal by /DELAYLOAD-ing .DLLs
  83. * and check for current OS version instead.
  84. */
  85. # define _WIN32_WINNT 0x0501
  86. # endif
  87. # if defined(_WIN32_WINNT) || defined(_WIN32_WCE)
  88. /*
  89. * Just like defining _WIN32_WINNT including winsock2.h implies
  90. * certain "discipline" for maintaining [broad] binary compatibility.
  91. * As long as structures are invariant among Winsock versions,
  92. * it's sufficient to check for specific Winsock2 API availability
  93. * at run-time [DSO_global_lookup is recommended]...
  94. */
  95. # include <winsock2.h>
  96. # include <ws2tcpip.h>
  97. /* yes, they have to be #included prior to <windows.h> */
  98. # endif
  99. # include <windows.h>
  100. # include <stdio.h>
  101. # include <stddef.h>
  102. # include <errno.h>
  103. # if defined(_WIN32_WCE) && !defined(EACCES)
  104. # define EACCES 13
  105. # endif
  106. # include <string.h>
  107. # ifdef _WIN64
  108. # define strlen(s) _strlen31(s)
  109. /* cut strings to 2GB */
  110. static __inline unsigned int _strlen31(const char *str)
  111. {
  112. unsigned int len = 0;
  113. while (*str && len < 0x80000000U)
  114. str++, len++;
  115. return len & 0x7FFFFFFF;
  116. }
  117. # endif
  118. # include <malloc.h>
  119. # if defined(_MSC_VER) && !defined(_WIN32_WCE) && !defined(_DLL) && defined(stdin)
  120. # if _MSC_VER>=1300 && _MSC_VER<1600
  121. # undef stdin
  122. # undef stdout
  123. # undef stderr
  124. FILE *__iob_func();
  125. # define stdin (&__iob_func()[0])
  126. # define stdout (&__iob_func()[1])
  127. # define stderr (&__iob_func()[2])
  128. # elif _MSC_VER<1300 && defined(I_CAN_LIVE_WITH_LNK4049)
  129. # undef stdin
  130. # undef stdout
  131. # undef stderr
  132. /*
  133. * pre-1300 has __p__iob(), but it's available only in msvcrt.lib,
  134. * or in other words with /MD. Declaring implicit import, i.e. with
  135. * _imp_ prefix, works correctly with all compiler options, but
  136. * without /MD results in LINK warning LNK4049: 'locally defined
  137. * symbol "__iob" imported'.
  138. */
  139. extern FILE *_imp___iob;
  140. # define stdin (&_imp___iob[0])
  141. # define stdout (&_imp___iob[1])
  142. # define stderr (&_imp___iob[2])
  143. # endif
  144. # endif
  145. # endif
  146. # include <io.h>
  147. # include <fcntl.h>
  148. # ifdef OPENSSL_SYS_WINCE
  149. # define OPENSSL_NO_POSIX_IO
  150. # endif
  151. # define EXIT(n) exit(n)
  152. # define LIST_SEPARATOR_CHAR ';'
  153. # ifndef W_OK
  154. # define W_OK 2
  155. # endif
  156. # ifndef R_OK
  157. # define R_OK 4
  158. # endif
  159. # ifdef OPENSSL_SYS_WINCE
  160. # define DEFAULT_HOME ""
  161. # else
  162. # define DEFAULT_HOME "C:"
  163. # endif
  164. /* Avoid Visual Studio 13 GetVersion deprecated problems */
  165. # if defined(_MSC_VER) && _MSC_VER>=1800
  166. # define check_winnt() (1)
  167. # define check_win_minplat(x) (1)
  168. # else
  169. # define check_winnt() (GetVersion() < 0x80000000)
  170. # define check_win_minplat(x) (LOBYTE(LOWORD(GetVersion())) >= (x))
  171. # endif
  172. # else /* The non-microsoft world */
  173. # if defined(OPENSSL_SYS_VXWORKS)
  174. # include <time.h>
  175. # else
  176. # include <sys/time.h>
  177. # endif
  178. # ifdef OPENSSL_SYS_VMS
  179. # define VMS 1
  180. /*
  181. * some programs don't include stdlib, so exit() and others give implicit
  182. * function warnings
  183. */
  184. # include <stdlib.h>
  185. # if defined(__DECC)
  186. # include <unistd.h>
  187. # else
  188. # include <unixlib.h>
  189. # endif
  190. # define LIST_SEPARATOR_CHAR ','
  191. /* We don't have any well-defined random devices on VMS, yet... */
  192. # undef DEVRANDOM
  193. /*-
  194. We need to do this since VMS has the following coding on status codes:
  195. Bits 0-2: status type: 0 = warning, 1 = success, 2 = error, 3 = info ...
  196. The important thing to know is that odd numbers are considered
  197. good, while even ones are considered errors.
  198. Bits 3-15: actual status number
  199. Bits 16-27: facility number. 0 is considered "unknown"
  200. Bits 28-31: control bits. If bit 28 is set, the shell won't try to
  201. output the message (which, for random codes, just looks ugly)
  202. So, what we do here is to change 0 to 1 to get the default success status,
  203. and everything else is shifted up to fit into the status number field, and
  204. the status is tagged as an error, which is what is wanted here.
  205. Finally, we add the VMS C facility code 0x35a000, because there are some
  206. programs, such as Perl, that will reinterpret the code back to something
  207. POSIX. 'man perlvms' explains it further.
  208. NOTE: the perlvms manual wants to turn all codes 2 to 255 into success
  209. codes (status type = 1). I couldn't disagree more. Fortunately, the
  210. status type doesn't seem to bother Perl.
  211. -- Richard Levitte
  212. */
  213. # define EXIT(n) exit((n) ? (((n) << 3) | 2 | 0x10000000 | 0x35a000) : 1)
  214. # define DEFAULT_HOME "SYS$LOGIN:"
  215. # else
  216. /* !defined VMS */
  217. # include <unistd.h>
  218. # include <sys/types.h>
  219. # ifdef OPENSSL_SYS_WIN32_CYGWIN
  220. # include <io.h>
  221. # include <fcntl.h>
  222. # endif
  223. # define LIST_SEPARATOR_CHAR ':'
  224. # define EXIT(n) exit(n)
  225. # endif
  226. # endif
  227. /***********************************************/
  228. # if defined(OPENSSL_SYS_WINDOWS)
  229. # define strcasecmp _stricmp
  230. # define strncasecmp _strnicmp
  231. # if (_MSC_VER >= 1310) && !defined(_WIN32_WCE)
  232. # define open _open
  233. # define fdopen _fdopen
  234. # define close _close
  235. # ifndef strdup
  236. # define strdup _strdup
  237. # endif
  238. # define unlink _unlink
  239. # define fileno _fileno
  240. # endif
  241. # else
  242. # include <strings.h>
  243. # endif
  244. /* vxworks */
  245. # if defined(OPENSSL_SYS_VXWORKS)
  246. # include <ioLib.h>
  247. # include <tickLib.h>
  248. # include <sysLib.h>
  249. # include <vxWorks.h>
  250. # include <sockLib.h>
  251. # include <taskLib.h>
  252. # define TTY_STRUCT int
  253. # define sleep(a) taskDelay((a) * sysClkRateGet())
  254. /*
  255. * NOTE: these are implemented by helpers in database app! if the database is
  256. * not linked, we need to implement them elsewhere
  257. */
  258. struct hostent *gethostbyname(const char *name);
  259. struct hostent *gethostbyaddr(const char *addr, int length, int type);
  260. struct servent *getservbyname(const char *name, const char *proto);
  261. # endif
  262. /* end vxworks */
  263. /* ----------------------------- HP NonStop -------------------------------- */
  264. /* Required to support platform variant without getpid() and pid_t. */
  265. # ifdef __TANDEM
  266. # include <strings.h>
  267. # include <netdb.h>
  268. # define getservbyname(name,proto) getservbyname((char*)name,proto)
  269. # define gethostbyname(name) gethostbyname((char*)name)
  270. # define ioctlsocket(a,b,c) ioctl(a,b,c)
  271. # ifdef NO_GETPID
  272. inline int nssgetpid();
  273. # ifndef NSSGETPID_MACRO
  274. # define NSSGETPID_MACRO
  275. # include <cextdecs.h(PROCESSHANDLE_GETMINE_)>
  276. # include <cextdecs.h(PROCESSHANDLE_DECOMPOSE_)>
  277. inline int nssgetpid()
  278. {
  279. short phandle[10]={0};
  280. union pseudo_pid {
  281. struct {
  282. short cpu;
  283. short pin;
  284. } cpu_pin ;
  285. int ppid;
  286. } ppid = { 0 };
  287. PROCESSHANDLE_GETMINE_(phandle);
  288. PROCESSHANDLE_DECOMPOSE_(phandle, &ppid.cpu_pin.cpu, &ppid.cpu_pin.pin);
  289. return ppid.ppid;
  290. }
  291. # define getpid(a) nssgetpid(a)
  292. # endif /* NSSGETPID_MACRO */
  293. # endif /* NO_GETPID */
  294. /*# define setsockopt(a,b,c,d,f) setsockopt(a,b,c,(char*)d,f)*/
  295. /*# define getsockopt(a,b,c,d,f) getsockopt(a,b,c,(char*)d,f)*/
  296. /*# define connect(a,b,c) connect(a,(struct sockaddr *)b,c)*/
  297. /*# define bind(a,b,c) bind(a,(struct sockaddr *)b,c)*/
  298. /*# define sendto(a,b,c,d,e,f) sendto(a,(char*)b,c,d,(struct sockaddr *)e,f)*/
  299. # if defined(OPENSSL_THREADS) && !defined(_PUT_MODEL_)
  300. /*
  301. * HPNS SPT threads
  302. */
  303. # define SPT_THREAD_SIGNAL 1
  304. # define SPT_THREAD_AWARE 1
  305. # include <spthread.h>
  306. # undef close
  307. # define close spt_close
  308. /*
  309. # define get_last_socket_error() errno
  310. # define clear_socket_error() errno=0
  311. # define ioctlsocket(a,b,c) ioctl(a,b,c)
  312. # define closesocket(s) close(s)
  313. # define readsocket(s,b,n) read((s),(char*)(b),(n))
  314. # define writesocket(s,b,n) write((s),(char*)(b),(n)
  315. */
  316. # define accept(a,b,c) accept(a,(struct sockaddr *)b,c)
  317. # define recvfrom(a,b,c,d,e,f) recvfrom(a,b,(socklen_t)c,d,e,f)
  318. # endif
  319. # endif
  320. # ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
  321. # define CRYPTO_memcmp memcmp
  322. # endif
  323. # ifndef OPENSSL_NO_SECURE_MEMORY
  324. /* unistd.h defines _POSIX_VERSION */
  325. # if (defined(OPENSSL_SYS_UNIX) \
  326. && ( (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) \
  327. || defined(__sun) || defined(__hpux) || defined(__sgi) \
  328. || defined(__osf__) )) \
  329. || defined(_WIN32)
  330. /* secure memory is implemented */
  331. # else
  332. # define OPENSSL_NO_SECURE_MEMORY
  333. # endif
  334. # endif
  335. #endif