26 FreeLibrary(HMODULE(Handle));
29 assert((!Process || Process ==
this) &&
"Bad Handle");
31 DynamicLibrary::SearchOrder = DynamicLibrary::SO_Linker;
38 return &getGlobals().OpenedHandles;
40 SmallVector<wchar_t, MAX_PATH> FileUnicode;
41 if (std::error_code ec = windows::UTF8ToUTF16(File, FileUnicode)) {
42 SetLastError(ec.value());
43 MakeErrMsg(Err, std::string(File) +
": Can't convert to UTF-16");
44 return &DynamicLibrary::Invalid;
47 HMODULE Handle = LoadLibraryW(FileUnicode.data());
49 MakeErrMsg(Err, std::string(File) +
": Can't open");
50 return &DynamicLibrary::Invalid;
53 return reinterpret_cast<void *
>(Handle);
58 return Handle == &Inst ? &Inst :
nullptr;
62 if (HandleSet *HS = IsOpenedHandlesInstance(Handle))
63 HS->Process =
nullptr;
65 FreeLibrary((HMODULE)Handle);
68static bool GetProcessModules(HANDLE
H, DWORD &Bytes, HMODULE *Data =
nullptr) {
73 !EnumProcessModulesEx(
H, Data, Bytes, &Bytes, LIST_MODULES_64BIT)
75 !EnumProcessModules(
H, Data, Bytes, &Bytes)
79 if (
MakeErrMsg(&Err,
"EnumProcessModules failure"))
87 HandleSet *
HS = IsOpenedHandlesInstance(Handle);
89 return (
void *)uintptr_t(GetProcAddress((HMODULE)Handle, Symbol));
111 HMODULE Self = HMODULE(GetCurrentProcess());
112 if (!GetProcessModules(Self, Bytes))
119 std::vector<HMODULE> Handles;
121 assert(Bytes && ((Bytes %
sizeof(HMODULE)) == 0) &&
122 "Should have at least one module and be aligned");
123 Handles.resize(Bytes /
sizeof(HMODULE));
124 if (!GetProcessModules(Self, Bytes, Handles.data()))
126 }
while (Bytes != (Handles.size() *
sizeof(HMODULE)));
129 if (FARPROC
Ptr = GetProcAddress(HMODULE(Handles.front()), Symbol))
130 return (
void *)uintptr_t(
Ptr);
132 if (Handles.size() > 1) {
139 for (
auto I = Handles.rbegin(),
E = Handles.rend() - 1;
I !=
E; ++
I) {
140 if (FARPROC
Ptr = GetProcAddress(HMODULE(*
I), Symbol))
141 return (
void *)uintptr_t(
Ptr);
149#define EXPLICIT_SYMBOL(SYM) \
153#define EXPLICIT_SYMBOL2(SYMFROM, SYMTO) EXPLICIT_SYMBOL(SYMTO)
161#define INLINE_DEF_SYMBOL1(TYP, SYM) \
162 extern "C" TYP inline_##SYM(TYP _X) { return SYM(_X); }
163#define INLINE_DEF_SYMBOL2(TYP, SYM) \
164 extern "C" TYP inline_##SYM(TYP _X, TYP _Y) { return SYM(_X, _Y); }
169#undef EXPLICIT_SYMBOL
170#undef EXPLICIT_SYMBOL2
171#undef INLINE_DEF_SYMBOL1
172#undef INLINE_DEF_SYMBOL2
174static void *DoSearch(
const char *SymbolName) {
176#define EXPLICIT_SYMBOL(SYM) \
177 if (!strcmp(SymbolName, #SYM)) \
179#define EXPLICIT_SYMBOL2(SYMFROM, SYMTO) \
180 if (!strcmp(SymbolName, #SYMFROM)) \
181 return (void *)&SYMTO;
184#define INLINE_DEF_SYMBOL1(TYP, SYM) \
185 if (!strcmp(SymbolName, #SYM)) \
186 return (void *)&inline_##SYM;
187#define INLINE_DEF_SYMBOL2(TYP, SYM) INLINE_DEF_SYMBOL1(TYP, SYM)
194#undef EXPLICIT_SYMBOL
195#undef EXPLICIT_SYMBOL2
196#undef INLINE_DEF_SYMBOL1
197#undef INLINE_DEF_SYMBOL2
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix, int errnum=-1)
This function builds an error message into ErrMsg using the prefix string and the Unix error number g...
static void * DLOpen(const char *Filename, std::string *Err)
static void * DLSym(void *Handle, const char *Symbol)
static void DLClose(void *Handle)
auto reverse(ContainerTy &&C)
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.