aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Support/Windows/DynamicLibrary.inc
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-04-14 21:41:27 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-06-22 18:20:56 +0000
commitbdd1243df58e60e85101c09001d9812a789b6bc4 (patch)
treea1ce621c7301dd47ba2ddc3b8eaa63b441389481 /contrib/llvm-project/llvm/lib/Support/Windows/DynamicLibrary.inc
parent781624ca2d054430052c828ba8d2c2eaf2d733e7 (diff)
parente3b557809604d036af6e00c60f012c2025b59a5e (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/Windows/DynamicLibrary.inc')
-rw-r--r--contrib/llvm-project/llvm/lib/Support/Windows/DynamicLibrary.inc32
1 files changed, 15 insertions, 17 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/Windows/DynamicLibrary.inc b/contrib/llvm-project/llvm/lib/Support/Windows/DynamicLibrary.inc
index a3f78fb0d6ba..c434bd62f04c 100644
--- a/contrib/llvm-project/llvm/lib/Support/Windows/DynamicLibrary.inc
+++ b/contrib/llvm-project/llvm/lib/Support/Windows/DynamicLibrary.inc
@@ -10,8 +10,8 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/Support/Windows/WindowsSupport.h"
#include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/Windows/WindowsSupport.h"
#include "llvm/Support/raw_ostream.h"
#include <psapi.h>
@@ -21,13 +21,12 @@
//=== and must not be UNIX code.
//===----------------------------------------------------------------------===//
-
DynamicLibrary::HandleSet::~HandleSet() {
for (void *Handle : llvm::reverse(Handles))
FreeLibrary(HMODULE(Handle));
// 'Process' should not be released on Windows.
- assert((!Process || Process==this) && "Bad Handle");
+ assert((!Process || Process == this) && "Bad Handle");
// llvm_shutdown called, Return to default
DynamicLibrary::SearchOrder = DynamicLibrary::SO_Linker;
}
@@ -36,7 +35,7 @@ void *DynamicLibrary::HandleSet::DLOpen(const char *File, std::string *Err) {
// Create the instance and return it to be the *Process* handle
// simillar to dlopen(NULL, RTLD_LAZY|RTLD_GLOBAL)
if (!File)
- return &(*OpenedHandles);
+ return &getGlobals().OpenedHandles;
SmallVector<wchar_t, MAX_PATH> FileUnicode;
if (std::error_code ec = windows::UTF8ToUTF16(File, FileUnicode)) {
@@ -51,18 +50,16 @@ void *DynamicLibrary::HandleSet::DLOpen(const char *File, std::string *Err) {
return &DynamicLibrary::Invalid;
}
- return reinterpret_cast<void*>(Handle);
+ return reinterpret_cast<void *>(Handle);
}
static DynamicLibrary::HandleSet *IsOpenedHandlesInstance(void *Handle) {
- if (!OpenedHandles.isConstructed())
- return nullptr;
- DynamicLibrary::HandleSet &Inst = *OpenedHandles;
+ DynamicLibrary::HandleSet &Inst = getGlobals().OpenedHandles;
return Handle == &Inst ? &Inst : nullptr;
}
void DynamicLibrary::HandleSet::DLClose(void *Handle) {
- if (HandleSet* HS = IsOpenedHandlesInstance(Handle))
+ if (HandleSet *HS = IsOpenedHandlesInstance(Handle))
HS->Process = nullptr; // Just drop the *Process* handle.
else
FreeLibrary((HMODULE)Handle);
@@ -77,7 +74,7 @@ static bool GetProcessModules(HANDLE H, DWORD &Bytes, HMODULE *Data = nullptr) {
#else
!EnumProcessModules(H, Data, Bytes, &Bytes)
#endif
- ) {
+ ) {
std::string Err;
if (MakeErrMsg(&Err, "EnumProcessModules failure"))
llvm::errs() << Err << "\n";
@@ -87,7 +84,7 @@ static bool GetProcessModules(HANDLE H, DWORD &Bytes, HMODULE *Data = nullptr) {
}
void *DynamicLibrary::HandleSet::DLSym(void *Handle, const char *Symbol) {
- HandleSet* HS = IsOpenedHandlesInstance(Handle);
+ HandleSet *HS = IsOpenedHandlesInstance(Handle);
if (!HS)
return (void *)uintptr_t(GetProcAddress((HMODULE)Handle, Symbol));
@@ -130,7 +127,7 @@ void *DynamicLibrary::HandleSet::DLSym(void *Handle, const char *Symbol) {
// Try EXE first, mirroring what dlsym(dlopen(NULL)) does.
if (FARPROC Ptr = GetProcAddress(HMODULE(Handles.front()), Symbol))
- return (void *) uintptr_t(Ptr);
+ return (void *)uintptr_t(Ptr);
if (Handles.size() > 1) {
// This is different behaviour than what Posix dlsym(dlopen(NULL)) does.
@@ -139,19 +136,20 @@ void *DynamicLibrary::HandleSet::DLSym(void *Handle, const char *Symbol) {
// symbols from ucrt.dll first, but iterating NOT in reverse here would
// mean that the msvc.dll versions would be returned.
- for (auto I = Handles.rbegin(), E = Handles.rend()-1; I != E; ++I) {
+ for (auto I = Handles.rbegin(), E = Handles.rend() - 1; I != E; ++I) {
if (FARPROC Ptr = GetProcAddress(HMODULE(*I), Symbol))
- return (void *) uintptr_t(Ptr);
+ return (void *)uintptr_t(Ptr);
}
}
return nullptr;
}
-
// Stack probing routines are in the support library (e.g. libgcc), but we don't
// have dynamic linking on windows. Provide a hook.
-#define EXPLICIT_SYMBOL(SYM) \
- extern "C" { extern void *SYM; }
+#define EXPLICIT_SYMBOL(SYM) \
+ extern "C" { \
+ extern void *SYM; \
+ }
#define EXPLICIT_SYMBOL2(SYMFROM, SYMTO) EXPLICIT_SYMBOL(SYMTO)
#ifdef _M_IX86