LLVM: include/llvm/Support/Windows/WindowsSupport.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21#ifndef LLVM_SUPPORT_WINDOWSSUPPORT_H

22#define LLVM_SUPPORT_WINDOWSSUPPORT_H

23

24

25#undef _WIN32_WINNT

26

27

28#define _WIN32_WINNT 0x0601

29#define WIN32_LEAN_AND_MEAN

30#ifndef NOMINMAX

31#define NOMINMAX

32#endif

33

38#include "llvm/Config/llvm-config.h"

44#include

45#include

46#include <system_error>

47#include <windows.h>

48

49

50#include <wincrypt.h>

51

52namespace llvm {

53

54

55

56

57

59

60

62

63

64

65

66

68

70

71

73 std::string ErrMsg;

76}

77

78template

79class ScopedHandle {

80 typedef typename HandleTraits::handle_type handle_type;

81 handle_type Handle;

82

83 ScopedHandle(const ScopedHandle &other) = delete;

84 void operator=(const ScopedHandle &other) = delete;

85public:

87 : Handle(HandleTraits::GetInvalid()) {}

88

91

93 if (HandleTraits::IsValid(Handle))

94 HandleTraits::Close(Handle);

95 }

96

98 handle_type t = Handle;

99 Handle = HandleTraits::GetInvalid();

100 return t;

101 }

102

104 if (HandleTraits::IsValid(Handle))

105 HandleTraits::Close(Handle);

106 Handle = h;

107 return *this;

108 }

109

110

111 explicit operator bool() const {

112 return HandleTraits::IsValid(Handle) ? true : false;

113 }

114

115 operator handle_type() const {

116 return Handle;

117 }

118};

119

122

124 return INVALID_HANDLE_VALUE;

125 }

126

128 ::CloseHandle(h);

129 }

130

134};

135

141

144

148

150 ::CryptReleaseContext(h, 0);

151 }

152

156};

157

160

164

166 ::RegCloseKey(h);

167 }

168

172};

173

176 ::FindClose(h);

177 }

178};

179

181

188

189template

191

192template

197 return str.data();

198}

199

200namespace sys {

201

202inline std::chrono::nanoseconds toDuration(FILETIME Time) {

203 ULARGE_INTEGER TimeInteger;

204 TimeInteger.LowPart = Time.dwLowDateTime;

205 TimeInteger.HighPart = Time.dwHighDateTime;

206

207

208 return std::chrono::nanoseconds(100 * TimeInteger.QuadPart);

209}

210

212 ULARGE_INTEGER TimeInteger;

213 TimeInteger.LowPart = Time.dwLowDateTime;

214 TimeInteger.HighPart = Time.dwHighDateTime;

215

216

217 TimeInteger.QuadPart -= 11644473600ll * 10000000;

218

219

220 return TimePoint<>(std::chrono::nanoseconds(100 * TimeInteger.QuadPart));

221}

222

224 ULARGE_INTEGER TimeInteger;

225 TimeInteger.QuadPart = TP.time_since_epoch().count() / 100;

226 TimeInteger.QuadPart += 11644473600ll * 10000000;

227

228 FILETIME Time;

229 Time.dwLowDateTime = TimeInteger.LowPart;

230 Time.dwHighDateTime = TimeInteger.HighPart;

231 return Time;

232}

233

235

236

237

241

242

243

246 size_t MaxPathLen = MAX_PATH);

247

248

249

250

252}

253}

254}

255

256#endif

This file defines the BumpPtrAllocator interface.

This file defines the SmallVector class.

Defines the llvm::VersionTuple class, which represents a version in the form major[....

Definition WindowsSupport.h:79

~ScopedHandle()

Definition WindowsSupport.h:92

ScopedHandle()

Definition WindowsSupport.h:86

ScopedHandle(handle_type h)

Definition WindowsSupport.h:89

ScopedHandle & operator=(handle_type h)

Definition WindowsSupport.h:103

handle_type take()

Definition WindowsSupport.h:97

This class consists of common code factored out of the SmallVector class to reduce code duplication b...

void push_back(const T &Elt)

pointer data()

Return a pointer to the vector's buffer, even if empty().

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

Represents a version number in the form major[.minor[.subminor[.build]]].

Definition WindowsSupport.h:234

LLVM_ABI std::error_code widenPath(const Twine &Path8, SmallVectorImpl< wchar_t > &Path16, size_t MaxPathLen=MAX_PATH)

Convert UTF-8 path to a suitable UTF-16 path for use with the Win32 Unicode File API.

LLVM_ABI HMODULE loadSystemModuleSecure(LPCWSTR lpModuleName)

Retrieves the handle to a in-memory system module such as ntdll.dll, while ensuring we're not retriev...

LLVM_ABI std::error_code GetCommandLineArguments(SmallVectorImpl< const char * > &Args, BumpPtrAllocator &Alloc)

std::chrono::nanoseconds toDuration(FILETIME Time)

Definition WindowsSupport.h:202

FILETIME toFILETIME(TimePoint<> TP)

Definition WindowsSupport.h:223

std::chrono::time_point< std::chrono::system_clock, D > TimePoint

A time point on the system clock.

TimePoint< std::chrono::seconds > toTimePoint(std::time_t T)

Convert a std::time_t to a TimePoint.

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI bool RunningWindows8OrGreater()

Determines if the program is running on Windows 8 or newer.

void ReportLastErrorFatal(const char *Msg)

Definition WindowsSupport.h:72

ScopedHandle< CommonHandleTraits > ScopedCommonHandle

Definition WindowsSupport.h:182

ScopedHandle< CryptContextTraits > ScopedCryptContext

Definition WindowsSupport.h:184

SmallVectorImpl< T >::const_pointer c_str(SmallVectorImpl< T > &str)

Definition WindowsSupport.h:194

LLVM_ABI llvm::VersionTuple GetWindowsOSVersion()

Returns the Windows version as Major.Minor.0.BuildNumber.

ScopedHandle< FindHandleTraits > ScopedFindHandle

Definition WindowsSupport.h:186

ScopedHandle< JobHandleTraits > ScopedJobHandle

Definition WindowsSupport.h:187

LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)

LLVM_ABI bool RunningWindows11OrGreater()

Determines if the program is running on Windows 11 or Windows Server 2022.

LLVM_ABI bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix)

ScopedHandle< RegTraits > ScopedRegHandle

Definition WindowsSupport.h:185

ScopedHandle< FileHandleTraits > ScopedFileHandle

Definition WindowsSupport.h:183

BumpPtrAllocatorImpl<> BumpPtrAllocator

The standard BumpPtrAllocator which just uses the default template parameters.

Definition WindowsSupport.h:120

static handle_type GetInvalid()

Definition WindowsSupport.h:123

static void Close(handle_type h)

Definition WindowsSupport.h:127

static bool IsValid(handle_type h)

Definition WindowsSupport.h:131

HANDLE handle_type

Definition WindowsSupport.h:121

Definition WindowsSupport.h:142

HCRYPTPROV handle_type

Definition WindowsSupport.h:143

static void Close(handle_type h)

Definition WindowsSupport.h:149

static handle_type GetInvalid()

Definition WindowsSupport.h:145

static bool IsValid(handle_type h)

Definition WindowsSupport.h:153

Definition WindowsSupport.h:180

Definition WindowsSupport.h:174

static void Close(handle_type h)

Definition WindowsSupport.h:175

Definition WindowsSupport.h:136

static handle_type GetInvalid()

Definition WindowsSupport.h:137

Definition WindowsSupport.h:158

static handle_type GetInvalid()

Definition WindowsSupport.h:161

static bool IsValid(handle_type h)

Definition WindowsSupport.h:169

HKEY handle_type

Definition WindowsSupport.h:159

static void Close(handle_type h)

Definition WindowsSupport.h:165