core: Properly implement TLS (#164)

* core: Split module code from linker

* linker: Properly implement thread local storage

* kernel: Fix a few memory functions

* kernel: Implement module loading

* Now it's easy to do anyway with new module rework
This commit is contained in:
TheTurtle 2024-06-05 22:08:18 +03:00 committed by GitHub
parent 7d61b7ab9b
commit 728249f58d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 1047 additions and 823 deletions

View file

@ -445,7 +445,7 @@ std::string Elf::ElfHeaderStr() {
return header;
}
std::string Elf::ElfPheaderTypeStr(u32 type) {
std::string_view Elf::ElfPheaderTypeStr(u32 type) {
switch (type) {
case PT_NULL:
return "Null";

View file

@ -3,7 +3,6 @@
#pragma once
#include <cinttypes>
#include <span>
#include <string>
#include <vector>
@ -482,11 +481,15 @@ public:
return m_elf_header.e_entry;
}
[[nodiscard]] bool IsSharedLib() const {
return m_elf_header.e_type == ET_SCE_DYNAMIC;
}
std::string SElfHeaderStr();
std::string SELFSegHeader(u16 no);
std::string ElfHeaderStr();
std::string ElfPHeaderStr(u16 no);
std::string ElfPheaderTypeStr(u32 type);
std::string_view ElfPheaderTypeStr(u32 type);
std::string ElfPheaderFlagsStr(u32 flags);
void LoadSegment(u64 virtual_addr, u64 file_offset, u64 size);

View file

@ -1,8 +1,8 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <fmt/format.h>
#include "common/io_file.h"
#include "common/logging/log.h"
#include "common/string_util.h"
#include "common/types.h"
#include "core/aerolib/aerolib.h"
@ -11,9 +11,7 @@
namespace Core::Loader {
void SymbolsResolver::AddSymbol(const SymbolResolver& s, u64 virtual_addr) {
SymbolRecord& r = m_symbols.emplace_back();
r.name = GenerateName(s);
r.virtual_address = virtual_addr;
m_symbols.emplace_back(GenerateName(s), s.nidName, virtual_addr);
}
std::string SymbolsResolver::GenerateName(const SymbolResolver& s) {
@ -38,22 +36,13 @@ void SymbolsResolver::DebugDump(const std::filesystem::path& file_name) {
Common::FS::FileType::TextFile};
for (const auto& symbol : m_symbols) {
const auto ids = Common::SplitString(symbol.name, '#');
std::string nidName = "";
auto aeronid = AeroLib::FindByNid(ids.at(0).c_str());
if (aeronid != nullptr) {
nidName = aeronid->name;
} else {
nidName = "UNK";
}
const auto aeronid = AeroLib::FindByNid(ids.at(0).c_str());
const auto nid_name = aeronid ? aeronid->name : "UNK";
f.WriteString(
fmt::format("0x{:<20x} {:<16} {:<60} {:<30} {:<2} {:<30} {:<2} {:<2} {:<10}\n",
symbol.virtual_address, ids.at(0), nidName, ids.at(1), ids.at(2), ids.at(3),
ids.at(4), ids.at(5), ids.at(6)));
symbol.virtual_address, ids.at(0), nid_name, ids.at(1), ids.at(2),
ids.at(3), ids.at(4), ids.at(5), ids.at(6)));
}
}
int SymbolsResolver::GetSize() {
return m_symbols.size();
}
} // namespace Core::Loader

View file

@ -3,8 +3,9 @@
#pragma once
#include <filesystem>
#include <span>
#include <string>
#include <unordered_map>
#include <vector>
#include "common/types.h"
@ -20,6 +21,7 @@ enum class SymbolType {
struct SymbolRecord {
std::string name;
std::string nid_name;
u64 virtual_address;
};
@ -42,6 +44,16 @@ public:
void AddSymbol(const SymbolResolver& s, u64 virtual_addr);
const SymbolRecord* FindSymbol(const SymbolResolver& s) const;
void DebugDump(const std::filesystem::path& file_name);
std::span<const SymbolRecord> GetSymbols() const {
return m_symbols;
}
size_t GetSize() const noexcept {
return m_symbols.size();
}
static std::string GenerateName(const SymbolResolver& s);
static std::string_view SymbolTypeToS(SymbolType sym_type) {
@ -59,9 +71,6 @@ public:
}
}
void DebugDump(const std::filesystem::path& file_name);
int GetSize();
private:
std::vector<SymbolRecord> m_symbols;
};