From a09e2eb65afd598069f94a0a377cad347d771f44 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Tue, 23 May 2023 07:48:25 +0300 Subject: [PATCH] initial work on linker --- CMakeLists.txt | 9 ++++++++- src/Core/PS4/Linker.cpp | 16 ++++++++++++++++ src/Core/PS4/Linker.h | 17 +++++++++++++++++ src/Util/Singleton.h | 27 +++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 src/Core/PS4/Linker.cpp create mode 100644 src/Core/PS4/Linker.h create mode 100644 src/Util/Singleton.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b08cb04..71e31bbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,14 @@ add_executable(shadps4 src/Loader/Elf.cpp src/Loader/Elf.h src/GUI/ElfViewer.cpp - src/GUI/ElfViewer.h "src/Util/Log.h" "src/Util/Log.cpp" "src/Core/Memory.cpp" "src/Core/Memory.h") + src/GUI/ElfViewer.h + src/Util/Log.h + src/Util/Log.cpp + src/Core/Memory.cpp + src/Core/Memory.h + src/Core/PS4/Linker.cpp + src/Core/PS4/Linker.h + "src/Util/Singleton.h") find_package(OpenGL REQUIRED) diff --git a/src/Core/PS4/Linker.cpp b/src/Core/PS4/Linker.cpp new file mode 100644 index 00000000..fa66ed3d --- /dev/null +++ b/src/Core/PS4/Linker.cpp @@ -0,0 +1,16 @@ +#include "Linker.h" + +Linker::Linker() +{ +} + +Linker::~Linker() +{ +} + +Module* Linker::LoadModule(const std::string& elf_name) +{ + auto* m = new Module; + + return m; +} \ No newline at end of file diff --git a/src/Core/PS4/Linker.h b/src/Core/PS4/Linker.h new file mode 100644 index 00000000..6543e648 --- /dev/null +++ b/src/Core/PS4/Linker.h @@ -0,0 +1,17 @@ +#pragma once +#include "../../Loader/Elf.h" + +/*this struct keeps neccesary info about loaded modules.Main executeable is included too as well*/ +struct Module +{ + Elf* elf = nullptr; +}; + +class Linker +{ +public: + Linker(); + virtual ~Linker(); + + Module* LoadModule(const std::string& elf_name); +}; \ No newline at end of file diff --git a/src/Util/Singleton.h b/src/Util/Singleton.h new file mode 100644 index 00000000..ef5228ba --- /dev/null +++ b/src/Util/Singleton.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include + +template +class Singleton +{ +public: + static T* Instance() + { + if (!m_instance) + { + m_instance = static_cast(std::malloc(sizeof(T))); + new (m_instance) T; + } + + return m_instance; + } + +protected: + Singleton(); + ~Singleton(); + +private: + static inline T* m_instance = nullptr; +}; \ No newline at end of file