singleton: Use unique_ptr

This commit is contained in:
GPUCode 2023-10-26 23:13:07 +03:00
parent 7cbe7c762a
commit f3504b2d25
3 changed files with 8 additions and 13 deletions

View File

@ -500,7 +500,6 @@ static void relocate(u32 idx, elf_relocation* rel, Module* m, bool isJmpRel) {
bool rel_isResolved = false;
u08 rel_sym_type = 0;
std::string rel_name;
u08 rel_bind_type = -1; //-1 means it didn't resolve
switch (type) {
case R_X86_64_RELATIVE:
@ -531,7 +530,6 @@ static void relocate(u32 idx, elf_relocation* rel, Module* m, bool isJmpRel) {
}
switch (sym_bind) {
case STB_GLOBAL:
rel_bind_type = STB_GLOBAL;
rel_name = namesTlb + sym.st_name;
m->linker->Resolve(rel_name, rel_sym_type, m, &symrec);
symbol_vitrual_addr = symrec.virtual_address;

View File

@ -1,17 +1,14 @@
#pragma once
#include <cstdlib>
#include <new>
#include <memory>
template <class T>
class singleton {
public:
static T* instance() {
if (!m_instance) {
m_instance = static_cast<T*>(std::malloc(sizeof(T)));
new (m_instance) T;
m_instance = std::make_unique<T>();
}
return m_instance;
}
@ -20,5 +17,5 @@ class singleton {
~singleton();
private:
static inline T* m_instance = nullptr;
static inline std::unique_ptr<T> m_instance{};
};

View File

@ -54,7 +54,7 @@ int main(int argc, char* argv[]) {
const char* const path = argv[1]; // argument 1 is the path of self file to boot
auto* linker = singleton<Linker>::instance();
HLE::Libs::Init_HLE_Libs(linker->getHLESymbols());
HLE::Libs::Init_HLE_Libs(&linker->getHLESymbols());
auto* module = linker->LoadModule(path); // load main executable
std::jthread mainthread(
[](std::stop_token stop_token, void*) {