Remove unused SmartHeap class

This commit is contained in:
EnderIce2 2024-08-13 07:37:20 +03:00
parent e2e9cfe84d
commit 31dca2e9a6
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
5 changed files with 22 additions and 111 deletions

View File

@ -1,25 +0,0 @@
#include <memory.hpp>
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);
}
}

View File

@ -105,22 +105,22 @@ namespace Execute
std::vector<Elf64_Phdr> 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<Elf64_Phdr> 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;
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_KERNEL_MEMORY_SMART_HEAP_H__
#define __FENNIX_KERNEL_MEMORY_SMART_HEAP_H__
#include <types.h>
#include <memory/vma.hpp>
#include <convert.h>
#include <cstddef>
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__

View File

@ -22,6 +22,7 @@
#include <list>
#include <memory/table.hpp>
#include <memory/vma.hpp>
namespace Memory
{

View File

@ -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");