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