VirtualBox

source: vbox/trunk/src/libs/openssl-3.0.3/e_os.h@ 95218

最後變更 在這個檔案從95218是 94097,由 vboxsync 提交於 3 年 前

libs/openssl-3.0.1: e_os.h build fix, bugref:10128

檔案大小: 12.6 KB
 
1/*
2 * Copyright 1995-2021 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
10#ifndef OSSL_E_OS_H
11# define OSSL_E_OS_H
12
13# include <limits.h>
14# include <openssl/opensslconf.h>
15
16# include <openssl/e_os2.h>
17# include <openssl/crypto.h>
18# include "internal/nelem.h"
19
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 */
24
25# if defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI)
26# define NO_CHMOD
27# define NO_SYSLOG
28# endif
29
30# define get_last_sys_error() errno
31# define clear_sys_error() errno=0
32# define set_sys_error(e) errno=(e)
33
34/********************************************************************
35 The Microsoft section
36 ********************************************************************/
37# if defined(OPENSSL_SYS_WIN32) && !defined(WIN32)
38# define WIN32
39# endif
40# if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS)
41# define WINDOWS
42# endif
43# if defined(OPENSSL_SYS_MSDOS) && !defined(MSDOS)
44# define MSDOS
45# endif
46
47# ifdef WIN32
48# undef get_last_sys_error
49# undef clear_sys_error
50# undef set_sys_error
51# define get_last_sys_error() GetLastError()
52# define clear_sys_error() SetLastError(0)
53# define set_sys_error(e) SetLastError(e)
54# if !defined(WINNT)
55# define WIN_CONSOLE_BUG
56# endif
57# else
58# endif
59
60# if (defined(WINDOWS) || defined(MSDOS))
61
62# ifdef __DJGPP__
63# include <unistd.h>
64# include <sys/stat.h>
65# define _setmode setmode
66# define _O_TEXT O_TEXT
67# define _O_BINARY O_BINARY
68# undef DEVRANDOM_EGD /* Neither MS-DOS nor FreeDOS provide 'egd' sockets. */
69# undef DEVRANDOM
70# define DEVRANDOM "/dev/urandom\x24"
71# endif /* __DJGPP__ */
72
73# ifndef S_IFDIR
74# define S_IFDIR _S_IFDIR
75# endif
76
77# ifndef S_IFMT
78# define S_IFMT _S_IFMT
79# endif
80
81# if !defined(WINNT) && !defined(__DJGPP__)
82# define NO_SYSLOG
83# endif
84
85# ifdef WINDOWS
86# if !defined(_WIN32_WCE) && !defined(_WIN32_WINNT)
87 /*
88 * Defining _WIN32_WINNT here in e_os.h implies certain "discipline."
89 * Most notably we ought to check for availability of each specific
90 * routine that was introduced after denoted _WIN32_WINNT with
91 * GetProcAddress(). Normally newer functions are masked with higher
92 * _WIN32_WINNT in SDK headers. So that if you wish to use them in
93 * some module, you'd need to override _WIN32_WINNT definition in
94 * the target module in order to "reach for" prototypes, but replace
95 * calls to new functions with indirect calls. Alternatively it
96 * might be possible to achieve the goal by /DELAYLOAD-ing .DLLs
97 * and check for current OS version instead.
98 */
99# define _WIN32_WINNT 0x0501
100# endif
101# ifndef IN_RING0 /* bird */
102# if defined(_WIN32_WINNT) || defined(_WIN32_WCE)
103 /*
104 * Just like defining _WIN32_WINNT including winsock2.h implies
105 * certain "discipline" for maintaining [broad] binary compatibility.
106 * As long as structures are invariant among Winsock versions,
107 * it's sufficient to check for specific Winsock2 API availability
108 * at run-time [DSO_global_lookup is recommended]...
109 */
110# ifdef VBOX
111# include <iprt/win/winsock2.h>
112# include <iprt/win/ws2tcpip.h>
113# endif
114# include <winsock2.h>
115# include <ws2tcpip.h>
116 /*
117 * Clang-based C++Builder 10.3.3 toolchains cannot find C inline
118 * definitions at link-time. This header defines WspiapiLoad() as an
119 * __inline function. https://quality.embarcadero.com/browse/RSP-33806
120 */
121# if !defined(__BORLANDC__) || !defined(__clang__)
122# include <wspiapi.h>
123# endif
124 /* yes, they have to be #included prior to <windows.h> */
125# endif
126# ifdef VBOX
127# include <iprt/win/windows.h>
128# else
129# include <windows.h>
130# endif
131# endif /* bird */
132# include <stdio.h>
133# include <stddef.h>
134# include <errno.h>
135# if defined(_WIN32_WCE) && !defined(EACCES)
136# define EACCES 13
137# endif
138# include <string.h>
139# ifdef _WIN64
140# define strlen(s) _strlen31(s)
141/* cut strings to 2GB */
142# ifndef VBOX
143static __inline unsigned int _strlen31(const char *str)
144# else
145static __inline size_t _strlen31(const char *str)
146# endif
147{
148 unsigned int len = 0;
149 while (*str && len < 0x80000000U)
150 str++, len++;
151 return len & 0x7FFFFFFF;
152}
153# endif
154# include <malloc.h>
155# if defined(_MSC_VER) && !defined(_WIN32_WCE) && !defined(_DLL) && defined(stdin)
156# if _MSC_VER>=1300 && _MSC_VER<1600
157# undef stdin
158# undef stdout
159# undef stderr
160FILE * __cdecl __iob_func(); /* vbox/bird: added __cdecl */
161# define stdin (&__iob_func()[0])
162# define stdout (&__iob_func()[1])
163# define stderr (&__iob_func()[2])
164# endif
165# endif
166# endif
167# include <io.h>
168# include <fcntl.h>
169
170# ifdef OPENSSL_SYS_WINCE
171# define OPENSSL_NO_POSIX_IO
172# endif
173
174# define EXIT(n) exit(n)
175# define LIST_SEPARATOR_CHAR ';'
176# ifndef W_OK
177# define W_OK 2
178# endif
179# ifndef R_OK
180# define R_OK 4
181# endif
182# ifdef OPENSSL_SYS_WINCE
183# define DEFAULT_HOME ""
184# else
185# define DEFAULT_HOME "C:"
186# endif
187
188/* Avoid Visual Studio 13 GetVersion deprecated problems */
189# if defined(_MSC_VER) && _MSC_VER>=1800
190# define check_winnt() (1)
191# define check_win_minplat(x) (1)
192# else
193# define check_winnt() (GetVersion() < 0x80000000)
194# define check_win_minplat(x) (LOBYTE(LOWORD(GetVersion())) >= (x))
195# endif
196
197# else /* The non-microsoft world */
198
199# if defined(OPENSSL_SYS_VXWORKS)
200# include <time.h>
201# else
202# include <sys/time.h>
203# endif
204
205# ifdef OPENSSL_SYS_VMS
206# define VMS 1
207 /*
208 * some programs don't include stdlib, so exit() and others give implicit
209 * function warnings
210 */
211# include <stdlib.h>
212# if defined(__DECC)
213# include <unistd.h>
214# else
215# include <unixlib.h>
216# endif
217# define LIST_SEPARATOR_CHAR ','
218 /* We don't have any well-defined random devices on VMS, yet... */
219# undef DEVRANDOM
220 /*-
221 We need to do this since VMS has the following coding on status codes:
222
223 Bits 0-2: status type: 0 = warning, 1 = success, 2 = error, 3 = info ...
224 The important thing to know is that odd numbers are considered
225 good, while even ones are considered errors.
226 Bits 3-15: actual status number
227 Bits 16-27: facility number. 0 is considered "unknown"
228 Bits 28-31: control bits. If bit 28 is set, the shell won't try to
229 output the message (which, for random codes, just looks ugly)
230
231 So, what we do here is to change 0 to 1 to get the default success status,
232 and everything else is shifted up to fit into the status number field, and
233 the status is tagged as an error, which is what is wanted here.
234
235 Finally, we add the VMS C facility code 0x35a000, because there are some
236 programs, such as Perl, that will reinterpret the code back to something
237 POSIX. 'man perlvms' explains it further.
238
239 NOTE: the perlvms manual wants to turn all codes 2 to 255 into success
240 codes (status type = 1). I couldn't disagree more. Fortunately, the
241 status type doesn't seem to bother Perl.
242 -- Richard Levitte
243 */
244# define EXIT(n) exit((n) ? (((n) << 3) | 2 | 0x10000000 | 0x35a000) : 1)
245
246# define DEFAULT_HOME "SYS$LOGIN:"
247
248# else
249 /* !defined VMS */
250# include <unistd.h>
251# include <sys/types.h>
252# ifdef OPENSSL_SYS_WIN32_CYGWIN
253# include <io.h>
254# include <fcntl.h>
255# endif
256
257# define LIST_SEPARATOR_CHAR ':'
258# define EXIT(n) exit(n)
259# endif
260
261# endif
262
263/***********************************************/
264
265# if defined(OPENSSL_SYS_WINDOWS)
266# define strcasecmp _stricmp
267# define strncasecmp _strnicmp
268# if (_MSC_VER >= 1310) && !defined(_WIN32_WCE)
269# define open _open
270# define fdopen _fdopen
271# define close _close
272# ifndef strdup
273# define strdup _strdup
274# endif
275# define unlink _unlink
276# define fileno _fileno
277# endif
278# else
279# include <strings.h>
280# endif
281
282/* vxworks */
283# if defined(OPENSSL_SYS_VXWORKS)
284# include <ioLib.h>
285# include <tickLib.h>
286# include <sysLib.h>
287# include <vxWorks.h>
288# include <sockLib.h>
289# include <taskLib.h>
290
291# define TTY_STRUCT int
292# define sleep(a) taskDelay((a) * sysClkRateGet())
293
294/*
295 * NOTE: these are implemented by helpers in database app! if the database is
296 * not linked, we need to implement them elsewhere
297 */
298struct hostent *gethostbyname(const char *name);
299struct hostent *gethostbyaddr(const char *addr, int length, int type);
300struct servent *getservbyname(const char *name, const char *proto);
301
302# endif
303/* end vxworks */
304
305/* system-specific variants defining ossl_sleep() */
306#ifdef OPENSSL_SYS_UNIX
307# include <unistd.h>
308static ossl_inline void ossl_sleep(unsigned long millis)
309{
310# ifdef OPENSSL_SYS_VXWORKS
311 struct timespec ts;
312 ts.tv_sec = (long int) (millis / 1000);
313 ts.tv_nsec = (long int) (millis % 1000) * 1000000ul;
314 nanosleep(&ts, NULL);
315# elif defined(__TANDEM)
316# if !defined(_REENTRANT)
317# include <cextdecs.h(PROCESS_DELAY_)>
318 /* HPNS does not support usleep for non threaded apps */
319 PROCESS_DELAY_(millis * 1000);
320# elif defined(_SPT_MODEL_)
321# include <spthread.h>
322# include <spt_extensions.h>
323 usleep(millis * 1000);
324# else
325 usleep(millis * 1000);
326# endif
327# else
328 usleep(millis * 1000);
329# endif
330}
331#elif defined(_WIN32)
332# include <windows.h>
333static ossl_inline void ossl_sleep(unsigned long millis)
334{
335 Sleep(millis);
336}
337#else
338/* Fallback to a busy wait */
339static ossl_inline void ossl_sleep(unsigned long millis)
340{
341 struct timeval start, now;
342 unsigned long elapsedms;
343
344 gettimeofday(&start, NULL);
345 do {
346 gettimeofday(&now, NULL);
347 elapsedms = (((now.tv_sec - start.tv_sec) * 1000000)
348 + now.tv_usec - start.tv_usec) / 1000;
349 } while (elapsedms < millis);
350}
351#endif /* defined OPENSSL_SYS_UNIX */
352
353/* ----------------------------- HP NonStop -------------------------------- */
354/* Required to support platform variant without getpid() and pid_t. */
355# if defined(__TANDEM) && defined(_GUARDIAN_TARGET)
356# include <strings.h>
357# include <netdb.h>
358# define getservbyname(name,proto) getservbyname((char*)name,proto)
359# define gethostbyname(name) gethostbyname((char*)name)
360# define ioctlsocket(a,b,c) ioctl(a,b,c)
361# ifdef NO_GETPID
362inline int nssgetpid();
363# ifndef NSSGETPID_MACRO
364# define NSSGETPID_MACRO
365# include <cextdecs.h(PROCESSHANDLE_GETMINE_)>
366# include <cextdecs.h(PROCESSHANDLE_DECOMPOSE_)>
367 inline int nssgetpid()
368 {
369 short phandle[10]={0};
370 union pseudo_pid {
371 struct {
372 short cpu;
373 short pin;
374 } cpu_pin ;
375 int ppid;
376 } ppid = { 0 };
377 PROCESSHANDLE_GETMINE_(phandle);
378 PROCESSHANDLE_DECOMPOSE_(phandle, &ppid.cpu_pin.cpu, &ppid.cpu_pin.pin);
379 return ppid.ppid;
380 }
381# define getpid(a) nssgetpid(a)
382# endif /* NSSGETPID_MACRO */
383# endif /* NO_GETPID */
384/*# define setsockopt(a,b,c,d,f) setsockopt(a,b,c,(char*)d,f)*/
385/*# define getsockopt(a,b,c,d,f) getsockopt(a,b,c,(char*)d,f)*/
386/*# define connect(a,b,c) connect(a,(struct sockaddr *)b,c)*/
387/*# define bind(a,b,c) bind(a,(struct sockaddr *)b,c)*/
388/*# define sendto(a,b,c,d,e,f) sendto(a,(char*)b,c,d,(struct sockaddr *)e,f)*/
389# if defined(OPENSSL_THREADS) && !defined(_PUT_MODEL_)
390 /*
391 * HPNS SPT threads
392 */
393# define SPT_THREAD_SIGNAL 1
394# define SPT_THREAD_AWARE 1
395# include <spthread.h>
396# undef close
397# define close spt_close
398/*
399# define get_last_socket_error() errno
400# define clear_socket_error() errno=0
401# define ioctlsocket(a,b,c) ioctl(a,b,c)
402# define closesocket(s) close(s)
403# define readsocket(s,b,n) read((s),(char*)(b),(n))
404# define writesocket(s,b,n) write((s),(char*)(b),(n)
405*/
406# define accept(a,b,c) accept(a,(struct sockaddr *)b,c)
407# define recvfrom(a,b,c,d,e,f) recvfrom(a,b,(socklen_t)c,d,e,f)
408# endif
409# endif
410
411# ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
412# define CRYPTO_memcmp memcmp
413# endif
414
415# ifndef OPENSSL_NO_SECURE_MEMORY
416 /* unistd.h defines _POSIX_VERSION */
417# if (defined(OPENSSL_SYS_UNIX) \
418 && ( (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) \
419 || defined(__sun) || defined(__hpux) || defined(__sgi) \
420 || defined(__osf__) )) \
421 || defined(_WIN32)
422 /* secure memory is implemented */
423# else
424# define OPENSSL_NO_SECURE_MEMORY
425# endif
426# endif
427
428#endif
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette