mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-05-28 15:34:31 +00:00
refactor(kernel): improve code readability and formatting
This commit is contained in:
parent
03147b532c
commit
25713e0f13
@ -80,12 +80,9 @@ namespace Memory
|
|||||||
{
|
{
|
||||||
char *sections = r_cst(char *, bInfo.Kernel.Symbols.Sections);
|
char *sections = r_cst(char *, bInfo.Kernel.Symbols.Sections);
|
||||||
debug("Reserving sections region %#lx-%#lx...",
|
debug("Reserving sections region %#lx-%#lx...",
|
||||||
sections,
|
sections, (uintptr_t)sections + bInfo.Kernel.Symbols.EntSize * bInfo.Kernel.Symbols.Num);
|
||||||
(void *)((uintptr_t)sections + bInfo.Kernel.Symbols.EntSize *
|
|
||||||
bInfo.Kernel.Symbols.Num));
|
|
||||||
|
|
||||||
this->ReservePages(sections, TO_PAGES(bInfo.Kernel.Symbols.EntSize *
|
this->ReservePages(sections, TO_PAGES(bInfo.Kernel.Symbols.EntSize * bInfo.Kernel.Symbols.Num));
|
||||||
bInfo.Kernel.Symbols.Num));
|
|
||||||
|
|
||||||
Elf_Sym *Symbols = nullptr;
|
Elf_Sym *Symbols = nullptr;
|
||||||
uint8_t *StringAddress = nullptr;
|
uint8_t *StringAddress = nullptr;
|
||||||
@ -101,11 +98,9 @@ namespace Memory
|
|||||||
for (size_t i = 0; i < bInfo.Kernel.Symbols.Num; ++i)
|
for (size_t i = 0; i < bInfo.Kernel.Symbols.Num; ++i)
|
||||||
{
|
{
|
||||||
Elf_Shdr *sym = (Elf_Shdr *)§ions[bInfo.Kernel.Symbols.EntSize * i];
|
Elf_Shdr *sym = (Elf_Shdr *)§ions[bInfo.Kernel.Symbols.EntSize * i];
|
||||||
Elf_Shdr *str = (Elf_Shdr *)§ions[bInfo.Kernel.Symbols.EntSize *
|
Elf_Shdr *str = (Elf_Shdr *)§ions[bInfo.Kernel.Symbols.EntSize * sym->sh_link];
|
||||||
sym->sh_link];
|
|
||||||
|
|
||||||
if (sym->sh_type == SHT_SYMTAB &&
|
if (sym->sh_type == SHT_SYMTAB && str->sh_type == SHT_STRTAB)
|
||||||
str->sh_type == SHT_STRTAB)
|
|
||||||
{
|
{
|
||||||
Symbols = (Elf_Sym *)sym->sh_addr;
|
Symbols = (Elf_Sym *)sym->sh_addr;
|
||||||
StringAddress = (uint8_t *)str->sh_addr;
|
StringAddress = (uint8_t *)str->sh_addr;
|
||||||
@ -145,8 +140,7 @@ namespace Memory
|
|||||||
bInfo.Modules[i].Address,
|
bInfo.Modules[i].Address,
|
||||||
(void *)((uintptr_t)bInfo.Modules[i].Address + bInfo.Modules[i].Size));
|
(void *)((uintptr_t)bInfo.Modules[i].Address + bInfo.Modules[i].Size));
|
||||||
|
|
||||||
this->ReservePages((void *)bInfo.Modules[i].Address,
|
this->ReservePages((void *)bInfo.Modules[i].Address, TO_PAGES(bInfo.Modules[i].Size));
|
||||||
TO_PAGES(bInfo.Modules[i].Size));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__amd64__) || defined(__i386__)
|
#if defined(__amd64__) || defined(__i386__)
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include <symbols.hpp>
|
#include <symbols.hpp>
|
||||||
#include <memory.hpp>
|
#include <memory.hpp>
|
||||||
#include <convert.h>
|
#include <convert.h>
|
||||||
|
#include <algorithm>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
#include <elf.h>
|
#include <elf.h>
|
||||||
|
|
||||||
@ -115,8 +116,7 @@ namespace SymbolResolver
|
|||||||
Elf_Shdr *sym = (Elf_Shdr *)§ions[EntSize * i];
|
Elf_Shdr *sym = (Elf_Shdr *)§ions[EntSize * i];
|
||||||
Elf_Shdr *str = (Elf_Shdr *)§ions[EntSize * sym->sh_link];
|
Elf_Shdr *str = (Elf_Shdr *)§ions[EntSize * sym->sh_link];
|
||||||
|
|
||||||
if (sym->sh_type == SHT_SYMTAB &&
|
if (sym->sh_type == SHT_SYMTAB && str->sh_type == SHT_STRTAB)
|
||||||
str->sh_type == SHT_STRTAB)
|
|
||||||
{
|
{
|
||||||
Symbols = (Elf_Sym *)sym->sh_addr;
|
Symbols = (Elf_Sym *)sym->sh_addr;
|
||||||
StringAddress = (uint8_t *)str->sh_addr;
|
StringAddress = (uint8_t *)str->sh_addr;
|
||||||
@ -124,9 +124,7 @@ namespace SymbolResolver
|
|||||||
// StringSize = (int)str->sh_size;
|
// StringSize = (int)str->sh_size;
|
||||||
// TotalEntries = Section.sh_size / sizeof(Elf64_Sym)
|
// TotalEntries = Section.sh_size / sizeof(Elf64_Sym)
|
||||||
TotalEntries = sym->sh_size / sym->sh_entsize;
|
TotalEntries = sym->sh_size / sym->sh_entsize;
|
||||||
trace("Symbol table found, %d entries",
|
trace("Symbol table found, %d entries", SymbolSize / sym->sh_entsize);
|
||||||
SymbolSize / sym->sh_entsize);
|
|
||||||
UNUSED(SymbolSize);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,13 +136,20 @@ namespace SymbolResolver
|
|||||||
{
|
{
|
||||||
MinimumIndex = i;
|
MinimumIndex = i;
|
||||||
for (Index = i + 1; Index < TotalEntries; Index++)
|
for (Index = i + 1; Index < TotalEntries; Index++)
|
||||||
if (Symbols[Index].st_value < Symbols[MinimumIndex].st_value)
|
{
|
||||||
|
bool condition = Symbols[Index].st_value < Symbols[MinimumIndex].st_value;
|
||||||
|
if (condition)
|
||||||
MinimumIndex = Index;
|
MinimumIndex = Index;
|
||||||
|
}
|
||||||
|
|
||||||
Elf_Sym tmp = Symbols[MinimumIndex];
|
Elf_Sym tmp = Symbols[MinimumIndex];
|
||||||
Symbols[MinimumIndex] = Symbols[i];
|
Symbols[MinimumIndex] = Symbols[i];
|
||||||
Symbols[i] = tmp;
|
Symbols[i] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// std::sort(Symbols, Symbols + TotalEntries, [](const Elf_Sym &a, const Elf_Sym &b)
|
||||||
|
// { return a.st_value < b.st_value; });
|
||||||
|
|
||||||
while (Symbols[0].st_value == 0)
|
while (Symbols[0].st_value == 0)
|
||||||
{
|
{
|
||||||
if (TotalEntries <= 0)
|
if (TotalEntries <= 0)
|
||||||
@ -159,8 +164,7 @@ namespace SymbolResolver
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
trace("Symbol table loaded, %d entries (%ld KiB)",
|
trace("Symbol table loaded, %d entries (%ld KiB)", TotalEntries, TO_KiB(TotalEntries * sizeof(SymbolTable)));
|
||||||
TotalEntries, TO_KiB(TotalEntries * sizeof(SymbolTable)));
|
|
||||||
Elf_Sym *sym;
|
Elf_Sym *sym;
|
||||||
const char *name;
|
const char *name;
|
||||||
Memory::Virtual vmm;
|
Memory::Virtual vmm;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user