Path: blob/main/crypto/openssl/include/internal/e_os.h
34879 views
/*1* Copyright 1995-2025 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89#ifndef OSSL_E_OS_H10# define OSSL_E_OS_H1112# include <limits.h>13# include <openssl/opensslconf.h>1415# include <openssl/e_os2.h>16# include <openssl/crypto.h>17# include "internal/numbers.h" /* Ensure the definition of SIZE_MAX */1819/*20* <openssl/e_os2.h> contains what we can justify to make visible to the21* outside; this file e_os.h is not part of the exported interface.22*/2324# if defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_UEFI)25# define NO_CHMOD26# define NO_SYSLOG27# endif2829# define get_last_sys_error() errno30# define clear_sys_error() errno=031# define set_sys_error(e) errno=(e)3233/********************************************************************34The Microsoft section35********************************************************************/36# if defined(OPENSSL_SYS_WIN32) && !defined(WIN32)37# define WIN3238# endif39# if defined(OPENSSL_SYS_WINDOWS) && !defined(WINDOWS)40# define WINDOWS41# endif42# if defined(OPENSSL_SYS_MSDOS) && !defined(MSDOS)43# define MSDOS44# endif4546# ifdef WIN3247# undef get_last_sys_error48# undef clear_sys_error49# undef set_sys_error50# define get_last_sys_error() GetLastError()51# define clear_sys_error() SetLastError(0)52# define set_sys_error(e) SetLastError(e)53# if !defined(WINNT)54# define WIN_CONSOLE_BUG55# endif56# else57# endif5859# if (defined(WINDOWS) || defined(MSDOS))6061# ifdef __DJGPP__62# include <unistd.h>63# include <sys/stat.h>64# define _setmode setmode65# define _O_TEXT O_TEXT66# define _O_BINARY O_BINARY67# undef DEVRANDOM_EGD /* Neither MS-DOS nor FreeDOS provide 'egd' sockets. */68# undef DEVRANDOM69# define DEVRANDOM "/dev/urandom\x24"70# endif /* __DJGPP__ */7172# ifndef S_IFDIR73# define S_IFDIR _S_IFDIR74# endif7576# ifndef S_IFMT77# define S_IFMT _S_IFMT78# endif7980# if !defined(WINNT) && !defined(__DJGPP__)81# define NO_SYSLOG82# endif8384# ifdef WINDOWS85# if !defined(_WIN32_WCE) && !defined(_WIN32_WINNT)86/*87* Defining _WIN32_WINNT here in e_os.h implies certain "discipline."88* Most notably we ought to check for availability of each specific89* routine that was introduced after denoted _WIN32_WINNT with90* GetProcAddress(). Normally newer functions are masked with higher91* _WIN32_WINNT in SDK headers. So that if you wish to use them in92* some module, you'd need to override _WIN32_WINNT definition in93* the target module in order to "reach for" prototypes, but replace94* calls to new functions with indirect calls. Alternatively it95* might be possible to achieve the goal by /DELAYLOAD-ing .DLLs96* and check for current OS version instead.97*/98# define _WIN32_WINNT 0x050199# endif100# include <windows.h>101# include <stdio.h>102# include <stddef.h>103# include <errno.h>104# if defined(_WIN32_WCE) && !defined(EACCES)105# define EACCES 13106# endif107# include <string.h>108# include <malloc.h>109# if defined(_MSC_VER) && !defined(_WIN32_WCE) && !defined(_DLL) && defined(stdin)110# if _MSC_VER>=1300 && _MSC_VER<1600111# undef stdin112# undef stdout113# undef stderr114FILE *__iob_func(void);115# define stdin (&__iob_func()[0])116# define stdout (&__iob_func()[1])117# define stderr (&__iob_func()[2])118# endif119# endif120# endif121122# include <io.h>123# include <fcntl.h>124125# ifdef OPENSSL_SYS_WINCE126# define OPENSSL_NO_POSIX_IO127# endif128129# define EXIT(n) exit(n)130# define LIST_SEPARATOR_CHAR ';'131# ifndef W_OK132# define W_OK 2133# endif134# ifndef R_OK135# define R_OK 4136# endif137# ifdef OPENSSL_SYS_WINCE138# define DEFAULT_HOME ""139# else140# define DEFAULT_HOME "C:"141# endif142143/* Avoid Visual Studio 13 GetVersion deprecated problems */144# if defined(_MSC_VER) && _MSC_VER>=1800145# define check_winnt() (1)146# define check_win_minplat(x) (1)147# else148# define check_winnt() (GetVersion() < 0x80000000)149# define check_win_minplat(x) (LOBYTE(LOWORD(GetVersion())) >= (x))150# endif151152# else /* The non-microsoft world */153154# if defined(OPENSSL_SYS_VXWORKS)155# include <time.h>156# else157# include <sys/time.h>158# endif159160# ifdef OPENSSL_SYS_VMS161# define VMS 1162/*163* some programs don't include stdlib, so exit() and others give implicit164* function warnings165*/166# include <stdlib.h>167# if defined(__DECC)168# include <unistd.h>169# else170# include <unixlib.h>171# endif172# define LIST_SEPARATOR_CHAR ','173/* We don't have any well-defined random devices on VMS, yet... */174# undef DEVRANDOM175/*-176We need to do this since VMS has the following coding on status codes:177178Bits 0-2: status type: 0 = warning, 1 = success, 2 = error, 3 = info ...179The important thing to know is that odd numbers are considered180good, while even ones are considered errors.181Bits 3-15: actual status number182Bits 16-27: facility number. 0 is considered "unknown"183Bits 28-31: control bits. If bit 28 is set, the shell won't try to184output the message (which, for random codes, just looks ugly)185186So, what we do here is to change 0 to 1 to get the default success status,187and everything else is shifted up to fit into the status number field, and188the status is tagged as an error, which is what is wanted here.189190Finally, we add the VMS C facility code 0x35a000, because there are some191programs, such as Perl, that will reinterpret the code back to something192POSIX. 'man perlvms' explains it further.193194NOTE: the perlvms manual wants to turn all codes 2 to 255 into success195codes (status type = 1). I couldn't disagree more. Fortunately, the196status type doesn't seem to bother Perl.197-- Richard Levitte198*/199# define EXIT(n) exit((n) ? (((n) << 3) | 2 | 0x10000000 | 0x35a000) : 1)200201# define DEFAULT_HOME "SYS$LOGIN:"202203# else204/* !defined VMS */205# include <unistd.h>206# include <sys/types.h>207# ifdef OPENSSL_SYS_WIN32_CYGWIN208# include <io.h>209# include <fcntl.h>210# endif211212# define LIST_SEPARATOR_CHAR ':'213# define EXIT(n) exit(n)214# endif215216# endif217218/***********************************************/219220# if defined(OPENSSL_SYS_WINDOWS)221# if defined(_MSC_VER) && (_MSC_VER >= 1310) && !defined(_WIN32_WCE)222# define open _open223# define fdopen _fdopen224# define close _close225# ifndef strdup226# define strdup _strdup227# endif228# define unlink _unlink229# define fileno _fileno230# define isatty _isatty231# endif232# else233# include <strings.h>234# endif235236/* vxworks */237# if defined(OPENSSL_SYS_VXWORKS)238# include <ioLib.h>239# include <tickLib.h>240# include <sysLib.h>241# include <vxWorks.h>242# include <sockLib.h>243# include <taskLib.h>244245# define TTY_STRUCT int246# define sleep(a) taskDelay((a) * sysClkRateGet())247248/*249* NOTE: these are implemented by helpers in database app! if the database is250* not linked, we need to implement them elsewhere251*/252struct hostent *gethostbyname(const char *name);253struct hostent *gethostbyaddr(const char *addr, int length, int type);254struct servent *getservbyname(const char *name, const char *proto);255256# endif257/* end vxworks */258259/* ----------------------------- HP NonStop -------------------------------- */260/* Required to support platform variant without getpid() and pid_t. */261# if defined(__TANDEM) && defined(_GUARDIAN_TARGET)262# include <strings.h>263# include <netdb.h>264# define getservbyname(name,proto) getservbyname((char*)name,proto)265# define gethostbyname(name) gethostbyname((char*)name)266# define ioctlsocket(a,b,c) ioctl(a,b,c)267# ifdef NO_GETPID268inline int nssgetpid(void);269# ifndef NSSGETPID_MACRO270# define NSSGETPID_MACRO271# include <cextdecs.h(PROCESSHANDLE_GETMINE_)>272# include <cextdecs.h(PROCESSHANDLE_DECOMPOSE_)>273inline int nssgetpid(void)274{275short phandle[10]={0};276union pseudo_pid {277struct {278short cpu;279short pin;280} cpu_pin ;281int ppid;282} ppid = { 0 };283PROCESSHANDLE_GETMINE_(phandle);284PROCESSHANDLE_DECOMPOSE_(phandle, &ppid.cpu_pin.cpu, &ppid.cpu_pin.pin);285return ppid.ppid;286}287# define getpid(a) nssgetpid(a)288# endif /* NSSGETPID_MACRO */289# endif /* NO_GETPID */290/*# define setsockopt(a,b,c,d,f) setsockopt(a,b,c,(char*)d,f)*/291/*# define getsockopt(a,b,c,d,f) getsockopt(a,b,c,(char*)d,f)*/292/*# define connect(a,b,c) connect(a,(struct sockaddr *)b,c)*/293/*# define bind(a,b,c) bind(a,(struct sockaddr *)b,c)*/294/*# define sendto(a,b,c,d,e,f) sendto(a,(char*)b,c,d,(struct sockaddr *)e,f)*/295# if defined(OPENSSL_THREADS) && !defined(_PUT_MODEL_)296/*297* HPNS SPT threads298*/299# define SPT_THREAD_SIGNAL 1300# define SPT_THREAD_AWARE 1301# include <spthread.h>302# undef close303# define close spt_close304/*305# define get_last_socket_error() errno306# define clear_socket_error() errno=0307# define ioctlsocket(a,b,c) ioctl(a,b,c)308# define closesocket(s) close(s)309# define readsocket(s,b,n) read((s),(char*)(b),(n))310# define writesocket(s,b,n) write((s),(char*)(b),(n)311*/312# define accept(a,b,c) accept(a,(struct sockaddr *)b,c)313# define recvfrom(a,b,c,d,e,f) recvfrom(a,b,(socklen_t)c,d,e,f)314# endif315# endif316317# ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION318# define CRYPTO_memcmp memcmp319# endif320321# ifndef OPENSSL_NO_SECURE_MEMORY322/* unistd.h defines _POSIX_VERSION */323# if (defined(OPENSSL_SYS_UNIX) \324&& ( (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L) \325|| defined(__sun) || defined(__hpux) || defined(__sgi) \326|| defined(__osf__) )) \327|| defined(_WIN32)328/* secure memory is implemented */329# else330# define OPENSSL_NO_SECURE_MEMORY331# endif332# endif333334/*335* str[n]casecmp_l is defined in POSIX 2008-01. Value is taken accordingly336* https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html337* There are also equivalent functions on Windows.338* There is no locale_t on NONSTOP.339*/340# if defined(OPENSSL_SYS_WINDOWS)341# define locale_t _locale_t342# define freelocale _free_locale343# define strcasecmp_l _stricmp_l344# define strncasecmp_l _strnicmp_l345# define strcasecmp _stricmp346# define strncasecmp _strnicmp347# elif !defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 200809L \348|| defined(OPENSSL_SYS_TANDEM)349# ifndef OPENSSL_NO_LOCALE350# define OPENSSL_NO_LOCALE351# endif352# endif353354#endif355356357