#include "llvm/Config/config.h"
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/ErrorHandling.h"
#include <cstdlib>
#ifdef __linux__
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#include <fcntl.h>
#include <unistd.h>
#endif
namespace llvm {
RTDyldMemoryManager::~RTDyldMemoryManager() = default;
#if defined(HAVE_REGISTER_FRAME) && defined(HAVE_DEREGISTER_FRAME) && \
!defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
extern "C" void __register_frame(void *);
extern "C" void __deregister_frame(void *);
#else
static void __register_frame(void *p) {
static bool Searched = false;
static void((*rf)(void *)) = 0;
if (!Searched) {
Searched = true;
*(void **)&rf =
llvm::sys::DynamicLibrary::SearchForAddressOfSymbol("__register_frame");
}
if (rf)
rf(p);
}
static void __deregister_frame(void *p) {
static bool Searched = false;
static void((*df)(void *)) = 0;
if (!Searched) {
Searched = true;
*(void **)&df = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(
"__deregister_frame");
}
if (df)
df(p);
}
#endif
#if defined(HAVE_UNW_ADD_DYNAMIC_FDE) || defined(__APPLE__)
static const char *processFDE(const char *Entry, bool isDeregister) {
const char *P = Entry;
uint32_t Length = *((const uint32_t *)P);
P += 4;
uint32_t Offset = *((const uint32_t *)P);
if (Offset != 0) {
if (isDeregister)
__deregister_frame(const_cast<char *>(Entry));
else
__register_frame(const_cast<char *>(Entry));
}
return P + Length;
}
void RTDyldMemoryManager::registerEHFramesInProcess(uint8_t *Addr,
size_t Size) {
const char *P = (const char *)Addr;
const char *End = P + Size;
while (P != End)
P = processFDE(P, false);
}
void RTDyldMemoryManager::deregisterEHFramesInProcess(uint8_t *Addr,
size_t Size) {
const char *P = (const char *)Addr;
const char *End = P + Size;
while (P != End)
P = processFDE(P, true);
}
#else
void RTDyldMemoryManager::registerEHFramesInProcess(uint8_t *Addr,
size_t Size) { … }
void RTDyldMemoryManager::deregisterEHFramesInProcess(uint8_t *Addr,
size_t Size) { … }
#endif
void RTDyldMemoryManager::registerEHFrames(uint8_t *Addr, uint64_t LoadAddr,
size_t Size) { … }
void RTDyldMemoryManager::deregisterEHFrames() { … }
static int jit_noop() { … }
#if defined(__BIONIC__) && defined(__arm__)
#define ARM_MATH_IMPORTS …
#define ARM_MATH_DECL …
ARM_MATH_IMPORTS(ARM_MATH_DECL)
#undef ARM_MATH_DECL
#endif
#if defined(__linux__) && defined(__GLIBC__) && \
(defined(__i386__) || defined(__x86_64__))
extern "C" LLVM_ATTRIBUTE_WEAK void __morestack();
#endif
uint64_t
RTDyldMemoryManager::getSymbolAddressInProcess(const std::string &Name) { … }
void *RTDyldMemoryManager::getPointerToNamedFunction(const std::string &Name,
bool AbortOnFailure) { … }
void RTDyldMemoryManager::anchor() { … }
void MCJITMemoryManager::anchor() { … }
}