22 #ifndef LLVM_SUPPORT_WINDOWSSUPPORT_H
23 #define LLVM_SUPPORT_WINDOWSSUPPORT_H
30 #define _WIN32_WINNT 0x0601
31 #define _WIN32_IE 0x0800 // MinGW at it again. FIXME: verify if still needed.
32 #define WIN32_LEAN_AND_MEAN
41 #include "llvm/Config/config.h"
46 #include <system_error>
56 OSVERSIONINFOEXW osvi = {};
57 osvi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
58 osvi.dwMajorVersion = 6;
59 osvi.dwMinorVersion = 2;
60 osvi.wServicePackMajor = 0;
63 Mask = VerSetConditionMask(Mask, VER_MAJORVERSION, VER_GREATER_EQUAL);
64 Mask = VerSetConditionMask(Mask, VER_MINORVERSION, VER_GREATER_EQUAL);
65 Mask = VerSetConditionMask(Mask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
67 return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION |
72 inline bool MakeErrMsg(std::string *ErrMsg,
const std::string &prefix) {
76 DWORD LastError = GetLastError();
77 DWORD R = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
78 FORMAT_MESSAGE_FROM_SYSTEM |
79 FORMAT_MESSAGE_MAX_WIDTH_MASK,
80 NULL, LastError, 0, (LPSTR)&buffer, 1, NULL);
82 *ErrMsg = prefix +
": " + buffer;
84 *ErrMsg = prefix +
": Unknown error";
91 template <
typename HandleTraits>
93 typedef typename HandleTraits::handle_type handle_type;
100 : Handle(HandleTraits::GetInvalid()) {}
106 if (HandleTraits::IsValid(Handle))
107 HandleTraits::Close(Handle);
111 handle_type
t = Handle;
112 Handle = HandleTraits::GetInvalid();
117 if (HandleTraits::IsValid(Handle))
118 HandleTraits::Close(Handle);
124 explicit operator bool()
const {
125 return HandleTraits::IsValid(Handle) ?
true :
false;
128 operator handle_type()
const {
137 return INVALID_HANDLE_VALUE;
163 ::CryptReleaseContext(h, 0);
204 class SmallVectorImpl;
207 typename SmallVectorImpl<T>::const_pointer
217 ULARGE_INTEGER TimeInteger;
218 TimeInteger.LowPart = Time.dwLowDateTime;
219 TimeInteger.HighPart = Time.dwHighDateTime;
222 return std::chrono::nanoseconds(100 * TimeInteger.QuadPart);
226 ULARGE_INTEGER TimeInteger;
227 TimeInteger.LowPart = Time.dwLowDateTime;
228 TimeInteger.HighPart = Time.dwHighDateTime;
231 TimeInteger.QuadPart -= 11644473600ll * 10000000;
234 return TimePoint<>(std::chrono::nanoseconds(100 * TimeInteger.QuadPart));
238 ULARGE_INTEGER TimeInteger;
239 TimeInteger.QuadPart = TP.time_since_epoch().count() / 100;
240 TimeInteger.QuadPart += 11644473600ll * 10000000;
243 Time.dwLowDateTime = TimeInteger.LowPart;
244 Time.dwHighDateTime = TimeInteger.HighPart;
255 std::error_code
UTF16ToUTF8(
const wchar_t *utf16,
size_t utf16_len,
258 std::error_code
UTF16ToCurCP(
const wchar_t *utf16,
size_t utf16_len,
void push_back(const T &Elt)
FILETIME toFILETIME(TimePoint<> TP)
static handle_type GetInvalid()
static void Close(handle_type h)
static void Close(handle_type h)
static bool IsValid(handle_type h)
LLVM_ATTRIBUTE_ALWAYS_INLINE TimePoint< std::chrono::seconds > toTimePoint(std::time_t T)
Convert a std::time_t to a TimePoint.
static bool IsValid(handle_type h)
ScopedHandle< JobHandleTraits > ScopedJobHandle
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
ScopedHandle< CommonHandleTraits > ScopedCommonHandle
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
static void Close(handle_type h)
static handle_type GetInvalid()
ScopedHandle(handle_type h)
std::error_code UTF8ToUTF16(StringRef utf8, SmallVectorImpl< wchar_t > &utf16)
static handle_type GetInvalid()
ScopedHandle< FindHandleTraits > ScopedFindHandle
std::error_code UTF16ToUTF8(const wchar_t *utf16, size_t utf16_len, SmallVectorImpl< char > &utf8)
bool RunningWindows8OrGreater()
Determines if the program is running on Windows 8 or newer.
SmallVectorImpl< T >::const_pointer c_str(SmallVectorImpl< T > &str)
std::error_code UTF16ToCurCP(const wchar_t *utf16, size_t utf16_len, SmallVectorImpl< char > &utf8)
Convert from UTF16 to the current code page used in the system.
bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix)
pointer data()
Return a pointer to the vector's buffer, even if empty().
std::chrono::microseconds toDuration(const struct timeval &TV)
Convert a struct timeval to a duration.
ScopedHandle & operator=(handle_type h)
ScopedHandle< FileHandleTraits > ScopedFileHandle
static std::string utohexstr(uint64_t X, bool LowerCase=false)
static handle_type GetInvalid()
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
static void Close(handle_type h)
ScopedHandle< RegTraits > ScopedRegHandle
ScopedHandle< CryptContextTraits > ScopedCryptContext
StringRef - Represent a constant reference to a string, i.e.
static bool IsValid(handle_type h)
std::error_code widenPath(const Twine &Path8, SmallVectorImpl< wchar_t > &Path16)
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.