2024-02-23 21:32:32 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2023-05-23 04:48:25 +00:00
|
|
|
#pragma once
|
2023-06-19 04:51:56 +00:00
|
|
|
|
2024-06-15 11:36:07 +00:00
|
|
|
#include <algorithm>
|
2023-10-22 14:10:25 +00:00
|
|
|
#include <mutex>
|
2024-02-23 20:57:57 +00:00
|
|
|
#include <vector>
|
2024-06-05 19:08:18 +00:00
|
|
|
#include "core/module.h"
|
2023-11-05 23:11:54 +00:00
|
|
|
|
|
|
|
namespace Core {
|
2024-06-05 19:08:18 +00:00
|
|
|
|
2023-06-08 09:51:11 +00:00
|
|
|
struct DynamicModuleInfo;
|
2023-07-11 15:50:29 +00:00
|
|
|
class Linker;
|
2024-06-21 15:22:37 +00:00
|
|
|
class MemoryManager;
|
|
|
|
|
|
|
|
struct OrbisKernelMemParam {
|
|
|
|
u64 size;
|
|
|
|
u64* extended_page_table;
|
|
|
|
u64* flexible_memory_size;
|
|
|
|
u8* extended_memory_1;
|
|
|
|
u64* extended_gpu_page_table;
|
|
|
|
u8* extended_memory_2;
|
|
|
|
u64* exnteded_cpu_page_table;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OrbisProcParam {
|
|
|
|
u64 size;
|
|
|
|
u32 magic;
|
|
|
|
u32 entry_count;
|
|
|
|
u64 sdk_version;
|
|
|
|
char* process_name;
|
|
|
|
char* main_thread_name;
|
|
|
|
u32* main_thread_prio;
|
|
|
|
u32* main_thread_stack_size;
|
|
|
|
void* libc_param;
|
|
|
|
OrbisKernelMemParam* mem_param;
|
|
|
|
void* fs_param;
|
|
|
|
u32* process_preload_enable;
|
|
|
|
u64 unknown1;
|
|
|
|
};
|
2023-06-08 09:51:11 +00:00
|
|
|
|
2023-07-20 09:18:43 +00:00
|
|
|
struct EntryParams {
|
|
|
|
int argc;
|
|
|
|
u32 padding;
|
|
|
|
const char* argv[3];
|
|
|
|
};
|
|
|
|
|
2024-06-05 19:08:18 +00:00
|
|
|
using HeapApiFunc = PS4_SYSV_ABI void* (*)(size_t);
|
2023-06-12 05:16:20 +00:00
|
|
|
|
2024-06-05 19:08:18 +00:00
|
|
|
class Linker {
|
|
|
|
public:
|
|
|
|
explicit Linker();
|
|
|
|
~Linker();
|
2024-02-27 22:10:34 +00:00
|
|
|
|
2024-06-05 19:08:18 +00:00
|
|
|
Loader::SymbolsResolver& GetHLESymbols() {
|
|
|
|
return m_hle_symbols;
|
|
|
|
}
|
2023-05-23 04:48:25 +00:00
|
|
|
|
2024-06-21 15:22:37 +00:00
|
|
|
OrbisProcParam* GetProcParam() const {
|
|
|
|
return m_modules[0]->GetProcParam<OrbisProcParam*>();
|
2024-06-05 19:08:18 +00:00
|
|
|
}
|
2023-10-26 20:07:15 +00:00
|
|
|
|
2024-06-05 19:08:18 +00:00
|
|
|
Module* GetModule(s32 index) const {
|
|
|
|
return m_modules.at(index).get();
|
|
|
|
}
|
2024-03-11 11:26:33 +00:00
|
|
|
|
2024-06-15 11:36:07 +00:00
|
|
|
void RelocateAnyImports(Module* m) {
|
|
|
|
Relocate(m);
|
|
|
|
for (auto& module : m_modules) {
|
|
|
|
const auto imports = module->GetImportModules();
|
|
|
|
if (std::ranges::contains(imports, m->name, &ModuleInfo::name)) {
|
|
|
|
Relocate(module.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-05 19:08:18 +00:00
|
|
|
void SetHeapApiFunc(void* func) {
|
|
|
|
heap_api_func = *reinterpret_cast<HeapApiFunc*>(func);
|
|
|
|
}
|
2023-10-26 20:07:15 +00:00
|
|
|
|
2024-06-15 11:36:07 +00:00
|
|
|
void AdvanceGenerationCounter() noexcept {
|
|
|
|
dtv_generation_counter++;
|
|
|
|
}
|
|
|
|
|
2024-06-05 19:08:18 +00:00
|
|
|
void* TlsGetAddr(u64 module_index, u64 offset);
|
|
|
|
void InitTlsForThread(bool is_primary = false);
|
2023-11-21 15:27:11 +00:00
|
|
|
|
2024-06-21 16:02:49 +00:00
|
|
|
s32 LoadModule(const std::filesystem::path& elf_name, bool is_dynamic = false);
|
2024-06-15 11:36:07 +00:00
|
|
|
Module* FindByAddress(VAddr address);
|
2023-10-26 20:07:15 +00:00
|
|
|
|
2024-06-05 19:08:18 +00:00
|
|
|
void Relocate(Module* module);
|
2024-06-15 11:36:07 +00:00
|
|
|
bool Resolve(const std::string& name, Loader::SymbolType type, Module* module,
|
2024-02-23 20:57:57 +00:00
|
|
|
Loader::SymbolRecord* return_info);
|
2023-07-20 09:18:43 +00:00
|
|
|
void Execute();
|
2024-03-11 11:26:33 +00:00
|
|
|
void DebugDump();
|
2023-05-23 07:47:56 +00:00
|
|
|
|
2023-10-26 20:07:15 +00:00
|
|
|
private:
|
2024-06-05 19:08:18 +00:00
|
|
|
const Module* FindExportedModule(const ModuleInfo& m, const LibraryInfo& l);
|
2023-06-28 17:15:19 +00:00
|
|
|
|
2024-06-21 15:22:37 +00:00
|
|
|
MemoryManager* memory;
|
2024-06-05 19:08:18 +00:00
|
|
|
std::mutex mutex;
|
|
|
|
u32 dtv_generation_counter{1};
|
|
|
|
size_t static_tls_size{};
|
2024-06-15 11:36:07 +00:00
|
|
|
u32 max_tls_index{};
|
2024-06-21 16:02:49 +00:00
|
|
|
u32 num_static_modules{};
|
2024-06-05 19:08:18 +00:00
|
|
|
HeapApiFunc heap_api_func{};
|
2024-02-27 22:10:34 +00:00
|
|
|
std::vector<std::unique_ptr<Module>> m_modules;
|
2023-11-05 23:11:54 +00:00
|
|
|
Loader::SymbolsResolver m_hle_symbols{};
|
2023-10-26 19:55:13 +00:00
|
|
|
};
|
2023-11-05 23:11:54 +00:00
|
|
|
|
|
|
|
} // namespace Core
|