17#include "llvm/Config/config.h"
26 typedef std::vector<void *> HandleList;
31 static void *
DLOpen(
const char *Filename, std::string *Err);
33 static void *
DLSym(
void *Handle,
const char *Symbol);
38 HandleList::iterator
Find(
void *Handle) {
return find(Handles, Handle); }
41 return Handle ==
Process ||
Find(Handle) != Handles.end();
44 bool AddLibrary(
void *Handle,
bool IsProcess =
false,
bool CanClose =
true,
45 bool AllowDuplicates =
false) {
47 assert((Handle ==
this ? IsProcess : !IsProcess) &&
"Bad Handle.");
49 assert((!AllowDuplicates || !CanClose) &&
50 "CanClose must be false if AllowDuplicates is true.");
53 if (!AllowDuplicates &&
Find(Handle) != Handles.end()) {
58 Handles.push_back(Handle);
75 HandleList::iterator it =
Find(Handle);
76 if (it != Handles.end()) {
83 for (
void *Handle : Handles) {
84 if (
void *
Ptr =
DLSym(Handle, Symbol))
89 if (
void *
Ptr =
DLSym(Handle, Symbol))
132Globals &getGlobals() {
149char DynamicLibrary::Invalid;
155 return DoSearch(SymbolName);
160 auto &
G = getGlobals();
162 G.ExplicitSymbols[SymbolName] = SymbolValue;
167 auto &
G = getGlobals();
169 if (Handle != &Invalid) {
171 G.OpenedHandles.AddLibrary(Handle, FileName ==
nullptr);
179 auto &
G = getGlobals();
182 if (!
G.OpenedHandles.AddLibrary(Handle,
false,
184 *Err =
"Library already loaded";
191 assert(FileName &&
"Use getPermanentLibrary() for opening process handle");
193 if (Handle != &Invalid) {
194 auto &
G = getGlobals();
196 G.OpenedTemporaryHandles.AddLibrary(Handle,
false,
204 auto &
G = getGlobals();
207 G.OpenedTemporaryHandles.CloseLibrary(
Lib.Data);
220 auto &
G = getGlobals();
226 if (i !=
G.ExplicitSymbols.end())
232 if (
void *
Ptr =
G.OpenedTemporaryHandles.Lookup(SymbolName,
SearchOrder))
This file defines the StringMap class.
#define LLVM_LIKELY(EXPR)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool AddLibrary(void *Handle, bool IsProcess=false, bool CanClose=true, bool AllowDuplicates=false)
void * Lookup(const char *Symbol, DynamicLibrary::SearchOrdering Order)
bool Contains(void *Handle)
HandleList::iterator Find(void *Handle)
static void * DLOpen(const char *Filename, std::string *Err)
void * LibLookup(const char *Symbol, DynamicLibrary::SearchOrdering Order)
static void * DLSym(void *Handle, const char *Symbol)
static void DLClose(void *Handle)
void CloseLibrary(void *Handle)
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
This class provides a portable interface to dynamic libraries which also might be known as shared lib...
static DynamicLibrary getLibrary(const char *FileName, std::string *Err=nullptr)
This function loads the dynamic library at the given path, using the library load operation from the ...
static DynamicLibrary addPermanentLibrary(void *handle, std::string *errMsg=nullptr)
Registers an externally loaded library.
static void AddSymbol(StringRef symbolName, void *symbolValue)
This functions permanently adds the symbol symbolName with the value symbolValue.
static bool LoadLibraryPermanently(const char *Filename, std::string *ErrMsg=nullptr)
This function permanently loads the dynamic library at the given path.
@ SO_LoadedLast
SO_LoadedLast - Search as SO_Linker would, then loaded libraries.
@ SO_LoadOrder
SO_LoadOrder - Or this in to search libraries in the ordered loaded.
@ SO_Linker
SO_Linker - Search as a call to dlsym(dlopen(NULL)) would when DynamicLibrary::getPermanentLibrary(NU...
@ SO_LoadedFirst
SO_LoadedFirst - Search all loaded libraries, then as SO_Linker would.
static DynamicLibrary getPermanentLibrary(const char *filename, std::string *errMsg=nullptr)
This function permanently loads the dynamic library at the given path using the library load operatio...
static SearchOrdering SearchOrder
void * getAddressOfSymbol(const char *symbolName)
Searches through the library for the symbol symbolName.
bool isValid() const
Returns true if the object refers to a valid library.
static void * SearchForAddressOfSymbol(const char *symbolName)
This function will search through all previously loaded dynamic libraries for the symbol symbolName.
static void closeLibrary(DynamicLibrary &Lib)
This function closes the dynamic library at the given path, using the library close operation of the ...
A collection of legacy interfaces for querying information about the current executing process.
SmartMutex - A mutex with a compile time constant parameter that indicates whether this mutex should ...
LLVMBool LLVMLoadLibraryPermanently(const char *Filename)
This function permanently loads the dynamic library at the given path.
void LLVMAddSymbol(const char *symbolName, void *symbolValue)
This functions permanently adds the symbol symbolName with the value symbolValue.
void * LLVMSearchForAddressOfSymbol(const char *symbolName)
This function will search through all previously loaded dynamic libraries for the symbol symbolName.
std::lock_guard< SmartMutex< mt_only > > SmartScopedLock
This is an optimization pass for GlobalISel generic memory operations.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
auto reverse(ContainerTy &&C)
void * SearchForAddressOfSpecialSymbol(const char *SymbolName)