From 31dca2e9a6799fb8350096caae2e7ddd3a1c319a Mon Sep 17 00:00:00 2001 From: EnderIce2 Date: Tue, 13 Aug 2024 07:37:20 +0300 Subject: [PATCH] Remove unused SmartHeap class --- core/memory/smart_heap.cpp | 25 ------------- exec/elf/elf_loader.cpp | 34 +++++++++--------- include/memory/smart_heap.hpp | 67 ----------------------------------- include/memory/stack.hpp | 1 + syscalls/linux.cpp | 6 ++-- 5 files changed, 22 insertions(+), 111 deletions(-) delete mode 100644 core/memory/smart_heap.cpp delete mode 100644 include/memory/smart_heap.hpp diff --git a/core/memory/smart_heap.cpp b/core/memory/smart_heap.cpp deleted file mode 100644 index ef954b47..00000000 --- a/core/memory/smart_heap.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include - -namespace Memory -{ - SmartHeap::SmartHeap(size_t Size, VirtualMemoryArea *vma) - { - if (vma) - { - this->vma = vma; - this->Object = vma->RequestPages(TO_PAGES(Size)); - } - else - this->Object = kmalloc(Size); - this->ObjectSize = Size; - memset(this->Object, 0, Size); - } - - SmartHeap::~SmartHeap() - { - if (this->vma) - this->vma->FreePages(this->Object, TO_PAGES(this->ObjectSize)); - else - kfree(this->Object); - } -} diff --git a/exec/elf/elf_loader.cpp b/exec/elf/elf_loader.cpp index 8c60315a..d3ec0dc3 100644 --- a/exec/elf/elf_loader.cpp +++ b/exec/elf/elf_loader.cpp @@ -105,22 +105,22 @@ namespace Execute std::vector PhdrINTERP = ELFGetSymbolType_x86_64(fd, PT_INTERP); foreach (auto Interp in PhdrINTERP) { - Memory::SmartHeap InterpreterPath = Memory::SmartHeap(256); - fd->Read(InterpreterPath, 256, Interp.p_offset); + std::string interpreterPath; + interpreterPath.resize(256); + fd->Read(interpreterPath.data(), 256, Interp.p_offset); + debug("Interpreter: %s", interpreterPath.c_str()); - FileNode *ifd = fs->GetByPath((const char *)InterpreterPath.Get(), TargetProcess->Info.RootNode); + FileNode *ifd = fs->GetByPath(interpreterPath.c_str(), TargetProcess->Info.RootNode); if (ifd == nullptr) { - warn("Failed to open interpreter file: %s", - (const char *)InterpreterPath.Get()); + warn("Failed to open interpreter file: %s", interpreterPath.c_str()); continue; } else { - if (GetBinaryType((const char *)InterpreterPath.Get()) != BinTypeELF) + if (GetBinaryType(interpreterPath) != BinTypeELF) { - warn("Interpreter %s is not an ELF file", - (const char *)InterpreterPath.Get()); + warn("Interpreter %s is not an ELF file", interpreterPath.c_str()); continue; } @@ -322,23 +322,23 @@ namespace Execute std::vector PhdrINTERP = ELFGetSymbolType_x86_64(fd, PT_INTERP); foreach (auto Interp in PhdrINTERP) { - Memory::SmartHeap InterpreterPath = Memory::SmartHeap(256); - fd->Read(InterpreterPath, 256, Interp.p_offset); - InterpreterPath = InterpreterPath; + std::string interpreterPath; + interpreterPath.resize(256); + fd->Read(interpreterPath.data(), 256, Interp.p_offset); + debug("Interpreter: %s", (const char *)interpreterPath.c_str()); - FileNode *ifd = fs->GetByPath((const char *)InterpreterPath.Get(), TargetProcess->Info.RootNode); + FileNode *ifd = fs->GetByPath(interpreterPath.c_str(), TargetProcess->Info.RootNode); if (ifd == nullptr) { - warn("Failed to open interpreter file: %s", - (const char *)InterpreterPath.Get()); + warn("Failed to open interpreter file: %s", interpreterPath.c_str()); continue; } else { - if (GetBinaryType((const char *)InterpreterPath.Get()) != BinTypeELF) + debug("ifd: %p, interpreter: %s", ifd, interpreterPath.c_str()); + if (GetBinaryType(interpreterPath) != BinTypeELF) { - warn("Interpreter %s is not an ELF file", - (const char *)InterpreterPath.Get()); + warn("Interpreter %s is not an ELF file", interpreterPath.c_str()); continue; } diff --git a/include/memory/smart_heap.hpp b/include/memory/smart_heap.hpp deleted file mode 100644 index a709f405..00000000 --- a/include/memory/smart_heap.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - This file is part of Fennix Kernel. - - Fennix Kernel is free software: you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation, either version 3 of - the License, or (at your option) any later version. - - Fennix Kernel is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Fennix Kernel. If not, see . -*/ - -#ifndef __FENNIX_KERNEL_MEMORY_SMART_HEAP_H__ -#define __FENNIX_KERNEL_MEMORY_SMART_HEAP_H__ - -#include -#include -#include -#include - -namespace Memory -{ - class SmartHeap - { - private: - VirtualMemoryArea *vma = nullptr; - void *Object = nullptr; - std::size_t ObjectSize = 0; - - public: - auto Get() { return Object; } - SmartHeap(std::size_t Size, - VirtualMemoryArea *vma = nullptr); - ~SmartHeap(); - - void *operator->() { return Object; } - void *operator*() { return Object; } - operator void *() { return Object; } - - operator const char *() - { - return r_cst(const char *, Object); - } - - operator uintptr_t() - { - return r_cst(uintptr_t, Object); - } - - operator uint8_t *() - { - return r_cst(uint8_t *, Object); - } - - void operator=(void *Address) - { - memcpy(Object, Address, ObjectSize); - } - }; -} - -#endif // !__FENNIX_KERNEL_MEMORY_SMART_HEAP_H__ diff --git a/include/memory/stack.hpp b/include/memory/stack.hpp index f4992b7f..db6ce473 100644 --- a/include/memory/stack.hpp +++ b/include/memory/stack.hpp @@ -22,6 +22,7 @@ #include #include +#include namespace Memory { diff --git a/syscalls/linux.cpp b/syscalls/linux.cpp index 2bddb554..efcad2e3 100644 --- a/syscalls/linux.cpp +++ b/syscalls/linux.cpp @@ -1758,8 +1758,8 @@ static int linux_uname(SysFrm *, struct utsname *buf) }; rn->Stat(&st); - Memory::SmartHeap sh = Memory::SmartHeap(st.Size); - rn->Read(sh.Get(), st.Size, 0); + char *sh = new char[st.Size]; + rn->Read(sh, st.Size, 0); ini_t *ini = ini_load(sh, NULL); int section = ini_find_section(ini, "uname", NULL); @@ -1790,6 +1790,8 @@ static int linux_uname(SysFrm *, struct utsname *buf) if (uMac && strcmp(uMac, "auto") != 0) strncpy(uname.machine, uMac, sizeof(uname.machine)); ini_destroy(ini); + + delete[] sh; } else warn("Couldn't open /etc/cross/linux");