mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-06 15:00:17 +02:00
ELF Loading: Cleanups all around
This commit is contained in:
1 parent
59ce750af6
commit
80493487db
11 files changed
+8
-132
No files matched your search
@@ -178,11 +178,6 @@ namespace FEXCore::Context {
|
||||
bool GetDebugDataForRIP(uint64_t RIP, FEXCore::Core::DebugData *Data);
|
||||
bool FindHostCodeForRIP(uint64_t RIP, uint8_t **Code);
|
||||
|
||||
// XXX:
|
||||
// bool FindIRForRIP(uint64_t RIP, FEXCore::IR::IntrusiveIRList **ir);
|
||||
// void SetIRForRIP(uint64_t RIP, FEXCore::IR::IntrusiveIRList *const ir);
|
||||
//void LoadEntryList();
|
||||
|
||||
std::tuple<FEXCore::IR::IRListView *, FEXCore::IR::RegisterAllocationData *, uint64_t, uint64_t, uint64_t, uint64_t> GenerateIR(FEXCore::Core::InternalThreadState *Thread, uint64_t GuestRIP);
|
||||
|
||||
std::tuple<void *, FEXCore::IR::IRListView *, FEXCore::Core::DebugData *, FEXCore::IR::RegisterAllocationData *, bool, uint64_t, uint64_t> CompileCode(FEXCore::Core::InternalThreadState *Thread, uint64_t GuestRIP);
|
||||
@@ -226,11 +221,6 @@ namespace FEXCore::Context {
|
||||
FEXCore::CodeLoader *LocalLoader{};
|
||||
|
||||
// Entry Cache
|
||||
std::optional<std::string> GetFilenameHash(std::string const &Filename) const;
|
||||
//void AddThreadRIPsToEntryList(FEXCore::Core::InternalThreadState *Thread);
|
||||
//void SaveEntryList();
|
||||
//std::set<uint64_t> EntryList;
|
||||
//std::vector<uint64_t> InitLocations;
|
||||
uint64_t StartingRIP;
|
||||
std::mutex ExitMutex;
|
||||
std::unique_ptr<GdbServer> DebugServer;
|
||||
|
||||
+2
-89
@@ -196,78 +196,6 @@ namespace FEXCore::Context {
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::string> Context::GetFilenameHash(std::string const &Filename) const {
|
||||
// Calculate a hash for the input file
|
||||
std::ifstream Input(Filename, std::ios::in | std::ios::binary | std::ios::ate);
|
||||
if (!Input) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const auto Size = static_cast<size_t>(Input.tellg());
|
||||
Input.seekg(0, std::ios::beg);
|
||||
std::string Data(Size, '\0');
|
||||
Input.read(Data.data(), Size);
|
||||
Input.close();
|
||||
|
||||
std::hash<std::string> string_hash;
|
||||
return std::to_string(string_hash(Data));
|
||||
}
|
||||
#if 0
|
||||
void Context::AddThreadRIPsToEntryList(FEXCore::Core::InternalThreadState *Thread) {
|
||||
for (auto &IR : Thread->LocalIRCache) {
|
||||
EntryList.insert(IR.first);
|
||||
}
|
||||
}
|
||||
|
||||
void Context::SaveEntryList() {
|
||||
std::string const &Filename = AppFilename();
|
||||
|
||||
if (auto const hash = GetFilenameHash(Filename)) {
|
||||
auto DataPath = FEXCore::Paths::GetEntryCachePath();
|
||||
DataPath += "Entries_" + *hash;
|
||||
|
||||
std::ofstream Output(DataPath, std::ios::out | std::ios::binary);
|
||||
if (!Output) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto Entry : EntryList) {
|
||||
Output.write(reinterpret_cast<char const*>(&Entry), sizeof(Entry));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Context::LoadEntryList() {
|
||||
std::string const &Filename = AppFilename();
|
||||
|
||||
if (auto const hash = GetFilenameHash(Filename)) {
|
||||
auto DataPath = FEXCore::Paths::GetEntryCachePath();
|
||||
DataPath += "Entries_" + *hash;
|
||||
|
||||
std::ifstream Input(DataPath, std::ios::in | std::ios::binary | std::ios::ate);
|
||||
if (!Input) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto const Size = static_cast<size_t>(Input.tellg());
|
||||
Input.seekg(0, std::ios::beg);
|
||||
std::string Data(Size, '\0');
|
||||
if (!Input.read(Data.data(), Size)) {
|
||||
return;
|
||||
}
|
||||
Input.close();
|
||||
|
||||
size_t const EntryCount = Size / sizeof(uint64_t);
|
||||
|
||||
for (size_t i = 0; i < EntryCount; ++i) {
|
||||
uint64_t Entry = 0;
|
||||
std::memcpy(&Entry, &Data[i * sizeof(Entry)], sizeof(Entry));
|
||||
EntryList.insert(Entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Context::~Context() {
|
||||
{
|
||||
for (auto &Thread : Threads) {
|
||||
@@ -275,11 +203,7 @@ namespace FEXCore::Context {
|
||||
Thread->ExecutionThread->join(nullptr);
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
for (auto &Thread : Threads) {
|
||||
AddThreadRIPsToEntryList(Thread);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (auto &Thread : Threads) {
|
||||
|
||||
if (Thread->CompileService) {
|
||||
@@ -289,9 +213,7 @@ namespace FEXCore::Context {
|
||||
}
|
||||
Threads.clear();
|
||||
}
|
||||
#if 0
|
||||
SaveEntryList();
|
||||
#endif
|
||||
|
||||
// AOTIRCache needs manual clear
|
||||
for (auto &Mod: AOTIRCache) {
|
||||
for (auto &Entry: Mod.second) {
|
||||
@@ -333,7 +255,6 @@ namespace FEXCore::Context {
|
||||
Thread->CurrentFrame->State.gregs[X86State::REG_RSP] = Loader->SetupStack();
|
||||
|
||||
Loader->LoadMemory();
|
||||
//Loader->GetInitLocations(&InitLocations);
|
||||
|
||||
Thread->CurrentFrame->State.rip = StartingRIP = Loader->DefaultRIP();
|
||||
|
||||
@@ -543,14 +464,6 @@ namespace FEXCore::Context {
|
||||
|
||||
LocalLoader->AddIR(IRHandler);
|
||||
|
||||
#if 0
|
||||
// Compile all of our cached entries
|
||||
LogMan::Msg::D("Precompiling: %ld blocks...", EntryList.size());
|
||||
for (auto Entry : EntryList) {
|
||||
CompileRIP(Thread, Entry);
|
||||
}
|
||||
LogMan::Msg::D("Done", EntryList.size());
|
||||
#endif
|
||||
}
|
||||
|
||||
struct ExecutionThreadHandler {
|
||||
|
||||
@@ -1229,7 +1229,6 @@ void ELFContainer::PrintDynamicTable() const {
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
void ELFContainer::GetInitLocations(uint64_t GuestELFBase, std::vector<uint64_t> *Locations) {
|
||||
if (Mode == MODE_32BIT) {
|
||||
// If INIT exists then add that first
|
||||
@@ -1286,6 +1285,5 @@ void ELFContainer::GetInitLocations(uint64_t GuestELFBase, std::vector<uint64_t>
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace ELFLoader
|
||||
@@ -338,13 +338,11 @@ ELFSymbol const *ELFSymbolDatabase::GetSymbolInRange(RangeType Address) {
|
||||
return Sym->second;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void ELFSymbolDatabase::GetInitLocations(std::vector<uint64_t> *Locations) {
|
||||
// Walk the initialization order and fill the locations for initializations
|
||||
for (auto ELF : InitializationOrder) {
|
||||
ELF->Container->GetInitLocations(ELF->GuestBase, Locations);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -40,8 +40,6 @@ public:
|
||||
*/
|
||||
virtual uint64_t DefaultRIP() const = 0;
|
||||
|
||||
//virtual void GetInitLocations(std::vector<uint64_t> *Locations) {}
|
||||
|
||||
/**
|
||||
* @brief Allows the loader to map memory regions that it needs
|
||||
*
|
||||
@@ -60,14 +58,6 @@ public:
|
||||
*/
|
||||
virtual void LoadMemory() = 0;
|
||||
|
||||
/**
|
||||
* @brief Get the final RIP we are supposed to end up on in a debugger
|
||||
*
|
||||
* @return When the debugger reaches this RIP then we know that we have completed
|
||||
*/
|
||||
//virtual uint64_t GetFinalRIP() { return ~0ULL; }
|
||||
|
||||
//virtual char const *FindSymbolNameInRange(uint64_t Address) { return nullptr; }
|
||||
virtual std::vector<std::string> const *GetApplicationArguments() { return nullptr; }
|
||||
virtual void GetExecveArguments(std::vector<char const*> *Args) {}
|
||||
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ struct ELFSymbol {
|
||||
char const *Name;
|
||||
};
|
||||
|
||||
class __attribute__((visibility("default"))) ELFContainer {
|
||||
class ELFContainer {
|
||||
public:
|
||||
ELFContainer(std::string const &Filename, std::string const &RootFS, bool CustomInterpreter);
|
||||
~ELFContainer();
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
using SymbolAdder = std::function<void(ELFSymbol*)>;
|
||||
void AddSymbols(SymbolAdder Adder);
|
||||
|
||||
//void GetInitLocations(uint64_t GuestELFBase, std::vector<uint64_t> *Locations);
|
||||
void GetInitLocations(uint64_t GuestELFBase, std::vector<uint64_t> *Locations);
|
||||
|
||||
|
||||
bool HasTLS() const { return TLSHeader._64 != nullptr; }
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
::ELFLoader::ELFSymbol const *GetGlobalSymbolInRange(RangeType Address);
|
||||
::ELFLoader::ELFSymbol const *GetNoWeakSymbolInRange(RangeType Address);
|
||||
|
||||
//void GetInitLocations(std::vector<uint64_t> *Locations);
|
||||
void GetInitLocations(std::vector<uint64_t> *Locations);
|
||||
|
||||
private:
|
||||
::ELFLoader::ELFContainer *File;
|
||||
|
||||
@@ -285,31 +285,23 @@ public:
|
||||
}
|
||||
|
||||
void MapMemoryRegion() override {
|
||||
#if 1
|
||||
auto DoMMap = [](uint64_t Address, size_t Size, bool FixedNoReplace) -> void* {
|
||||
fprintf(stderr, "MAPPING %p %lu %x %x %d %ld\n", Address, Size, 0, FixedNoReplace, 0, 0l);
|
||||
|
||||
void *Result = mmap(reinterpret_cast<void*>(Address), Size, PROT_READ | PROT_WRITE, (FixedNoReplace ? MAP_FIXED_NOREPLACE : MAP_FIXED) | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
LogMan::Throw::A(Result != (void*)~0ULL, "Couldn't mmap");
|
||||
return Result;
|
||||
};
|
||||
|
||||
DB.MapMemoryRegions(DoMMap);
|
||||
#endif
|
||||
}
|
||||
|
||||
void LoadMemory() override {
|
||||
#if 1
|
||||
auto ELFLoaderWrapper = [&](void const *Data, uint64_t Addr, uint64_t Size) -> void {
|
||||
fprintf(stderr, "COPYING %p %lu %x %x %d %ld\n", Addr, Size, 0, 0, 0, 0l);
|
||||
memcpy(reinterpret_cast<void*>(Addr), Data, Size);
|
||||
};
|
||||
DB.WriteLoadableSections(ELFLoaderWrapper);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
char const *FindSymbolNameInRange(uint64_t Address) override {
|
||||
char const *FindSymbolNameInRange(uint64_t Address) {
|
||||
|
||||
ELFLoader::ELFSymbol const *Sym;
|
||||
Sym = DB.GetSymbolInRange(std::make_pair(Address, 1));
|
||||
@@ -320,10 +312,9 @@ public:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void GetInitLocations(std::vector<uint64_t> *Locations) override {
|
||||
void GetInitLocations(std::vector<uint64_t> *Locations) {
|
||||
DB.GetInitLocations(Locations);
|
||||
}
|
||||
#endif
|
||||
|
||||
std::vector<std::string> const *GetApplicationArguments() override { return &Args; }
|
||||
void GetExecveArguments(std::vector<char const*> *Args) override { *Args = LoaderArgs; }
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include <FEXCore/Core/CoreState.h>
|
||||
#include <FEXCore/Core/X86Enums.h>
|
||||
#include <FEXCore/Utils/LogManager.h>
|
||||
#include <FEXCore/Utils/ELFLoader.h>
|
||||
#include <FEXCore/Utils/ELFContainer.h>
|
||||
#include <FEXCore/Utils/ELFSymbolDatabase.h>
|
||||
|
||||
namespace FEX::HarnessHelper {
|
||||
@@ -419,7 +419,6 @@ namespace FEX::HarnessHelper {
|
||||
Config.LoadMemory();
|
||||
}
|
||||
|
||||
//uint64_t GetFinalRIP() override { return RIP + RawFile.size(); }
|
||||
|
||||
bool CompareStates(FEXCore::Core::CPUState const* State1, FEXCore::Core::CPUState const* State2) {
|
||||
return Config.CompareStates(State1, State2);
|
||||
|
||||
@@ -85,7 +85,6 @@ class IRCodeLoader final : public FEXCore::CodeLoader {
|
||||
IR->LoadMemory();
|
||||
}
|
||||
|
||||
//uint64_t GetFinalRIP() override { return 0; }
|
||||
|
||||
virtual void AddIR(IRHandler Handler) override {
|
||||
Handler(IR->GetEntryRIP(), IR->GetIREmitter());
|
||||
|
||||
@@ -72,8 +72,6 @@ public:
|
||||
using SyscallPtrArg5 = uint64_t(*)(FEXCore::Core::CpuStateFrame *Frame, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t);
|
||||
using SyscallPtrArg6 = uint64_t(*)(FEXCore::Core::CpuStateFrame *Frame, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t);
|
||||
|
||||
//virtual void *MemMap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) = 0;
|
||||
|
||||
struct SyscallFunctionDefinition {
|
||||
uint8_t NumArgs;
|
||||
union {
|
||||
|
||||
Reference in new issue
Block a user