28 FreeLibrary(HMODULE(Handle));
31 assert((!Process || Process==
this) &&
"Bad Handle");
33 DynamicLibrary::SearchOrder = DynamicLibrary::SO_Linker;
40 return &(*OpenedHandles);
42 SmallVector<wchar_t, MAX_PATH> FileUnicode;
43 if (std::error_code ec = windows::UTF8ToUTF16(File, FileUnicode)) {
44 SetLastError(ec.value());
45 MakeErrMsg(Err, std::string(File) +
": Can't convert to UTF-16");
49 HMODULE Handle = LoadLibraryW(FileUnicode.data());
51 MakeErrMsg(Err, std::string(File) +
": Can't open");
55 return reinterpret_cast<void*
>(Handle);
59 if (!OpenedHandles.isConstructed())
62 return Handle == &Inst ? &Inst :
nullptr;
66 if (
HandleSet*
HS = IsOpenedHandlesInstance(Handle))
67 HS->Process =
nullptr;
69 FreeLibrary((HMODULE)Handle);
72 static bool GetProcessModules(HANDLE
H,
DWORD &Bytes, HMODULE *
Data =
nullptr) {
77 !EnumProcessModulesEx(H,
Data, Bytes, &Bytes, LIST_MODULES_64BIT)
79 !EnumProcessModules(H,
Data, Bytes, &Bytes)
83 if (
MakeErrMsg(&Err,
"EnumProcessModules failure"))
93 return (
void *)uintptr_t(GetProcAddress((HMODULE)Handle, Symbol));
115 HMODULE Self = HMODULE(GetCurrentProcess());
116 if (!GetProcessModules(Self, Bytes))
123 std::vector<HMODULE> Handles;
125 assert(Bytes && ((Bytes %
sizeof(HMODULE)) == 0) &&
126 "Should have at least one module and be aligned");
127 Handles.resize(Bytes /
sizeof(HMODULE));
128 if (!GetProcessModules(Self, Bytes, Handles.data()))
130 }
while (Bytes != (Handles.size() *
sizeof(HMODULE)));
133 if (FARPROC Ptr = GetProcAddress(HMODULE(Handles.front()), Symbol))
134 return (
void *) uintptr_t(Ptr);
136 if (Handles.size() > 1) {
143 for (
auto I = Handles.rbegin(),
E = Handles.rend()-1;
I !=
E; ++
I) {
144 if (FARPROC Ptr = GetProcAddress(HMODULE(*
I), Symbol))
145 return (
void *) uintptr_t(Ptr);
154 #define EXPLICIT_SYMBOL(SYM) \ 155 extern "C" { extern void *SYM; } 156 #define EXPLICIT_SYMBOL2(SYMFROM, SYMTO) EXPLICIT_SYMBOL(SYMTO) 164 #define INLINE_DEF_SYMBOL1(TYP, SYM) \ 165 extern "C" TYP inline_##SYM(TYP _X) { return SYM(_X); } 166 #define INLINE_DEF_SYMBOL2(TYP, SYM) \ 167 extern "C" TYP inline_##SYM(TYP _X, TYP _Y) { return SYM(_X, _Y); } 172 #undef EXPLICIT_SYMBOL 173 #undef EXPLICIT_SYMBOL2 174 #undef INLINE_DEF_SYMBOL1 175 #undef INLINE_DEF_SYMBOL2 177 static void *DoSearch(
const char *
SymbolName) {
179 #define EXPLICIT_SYMBOL(SYM) \ 180 if (!strcmp(SymbolName, #SYM)) \ 182 #define EXPLICIT_SYMBOL2(SYMFROM, SYMTO) \ 183 if (!strcmp(SymbolName, #SYMFROM)) \ 184 return (void *)&SYMTO; 187 #define INLINE_DEF_SYMBOL1(TYP, SYM) \ 188 if (!strcmp(SymbolName, #SYM)) \ 189 return (void *)&inline_##SYM; 190 #define INLINE_DEF_SYMBOL2(TYP, SYM) INLINE_DEF_SYMBOL1(TYP, SYM) 197 #undef EXPLICIT_SYMBOL 198 #undef EXPLICIT_SYMBOL2 199 #undef INLINE_DEF_SYMBOL1 200 #undef INLINE_DEF_SYMBOL2 raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
static void * DLSym(void *Handle, const char *Symbol)
static void * DLOpen(const char *Filename, std::string *Err)
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static void DLClose(void *Handle)
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...