Remove ELFSymbolTable from PCB

This commit is contained in:
EnderIce2 2024-02-28 06:11:31 +02:00
parent e74c5f7bab
commit ddad5ca38a
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
8 changed files with 13 additions and 92 deletions

View File

@ -317,18 +317,6 @@ namespace Execute
TargetProcess->ProgramBreak->InitBrk(ProgramBreak); TargetProcess->ProgramBreak->InitBrk(ProgramBreak);
} }
struct stat statbuf;
fstat(fd, &statbuf);
Memory::SmartHeap sh = Memory::SmartHeap(statbuf.st_size);
lseek(fd, 0, SEEK_SET);
fread(fd, sh, statbuf.st_size);
TargetProcess->ELFSymbolTable->AppendSymbols(uintptr_t(sh.Get()));
#ifdef DEBUG
if (!TargetProcess->ELFSymbolTable->SymTableExists)
debug("NO SYMBOL TABLE FOUND?");
#endif
debug("Entry Point: %#lx", EntryPoint); debug("Entry Point: %#lx", EntryPoint);
this->GenerateAuxiliaryVector_x86_64(vma, fd, ELFHeader, this->GenerateAuxiliaryVector_x86_64(vma, fd, ELFHeader,
@ -742,18 +730,6 @@ namespace Execute
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
struct stat statbuf;
fstat(fd, &statbuf);
Memory::SmartHeap sh = Memory::SmartHeap(statbuf.st_size);
lseek(fd, 0, SEEK_SET);
fread(fd, sh, statbuf.st_size);
TargetProcess->ELFSymbolTable->AppendSymbols(uintptr_t(sh.Get()), BaseAddress);
if (!TargetProcess->ELFSymbolTable->SymTableExists)
{
debug("NO SYMBOL TABLE FOUND?");
}
debug("Entry Point: %#lx", EntryPoint); debug("Entry Point: %#lx", EntryPoint);
this->GenerateAuxiliaryVector_x86_64(vma, fd, ELFHeader, this->GenerateAuxiliaryVector_x86_64(vma, fd, ELFHeader,

View File

@ -99,11 +99,6 @@ namespace Execute
/* ------------------------------------------------------------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------------------------------------------------------------ */
void *ElfFile = KernelAllocator.RequestPages(TO_PAGES(statbuf.st_size + 1));
fread(fd, (uint8_t *)ElfFile, statbuf.st_size);
debug("Loaded elf %s at %#lx with the length of %ld",
Path, ElfFile, statbuf.st_size);
PCB *Process; PCB *Process;
if (Fork) if (Fork)
{ {
@ -119,10 +114,7 @@ namespace Execute
} }
fixme("free allocated memory"); fixme("free allocated memory");
fixme("change symbol table");
// Process->vma->FreeAllPages(); // Process->vma->FreeAllPages();
delete Process->ELFSymbolTable;
Process->ELFSymbolTable = new SymbolResolver::Symbols((uintptr_t)ElfFile);
} }
else else
{ {
@ -132,8 +124,7 @@ namespace Execute
Process = TaskManager->CreateProcess(Parent, Process = TaskManager->CreateProcess(Parent,
BaseName, BaseName,
TaskExecutionMode::User, TaskExecutionMode::User,
ElfFile, false, false, 0, 0);
0, 0);
Process->Info.Compatibility = Compatibility; Process->Info.Compatibility = Compatibility;
Process->Info.Architecture = Arch; Process->Info.Architecture = Arch;
} }
@ -141,8 +132,6 @@ namespace Execute
Process->SetWorkingDirectory(fs->GetNodeFromPath(Path)->Parent); Process->SetWorkingDirectory(fs->GetNodeFromPath(Path)->Parent);
Process->SetExe(Path); Process->SetExe(Path);
KernelAllocator.FreePages(ElfFile, TO_PAGES(statbuf.st_size + 1));
ELFObject *obj = new ELFObject(Path, Process, argv, envp); ELFObject *obj = new ELFObject(Path, Process, argv, envp);
if (!obj->IsValid) if (!obj->IsValid)
{ {

View File

@ -441,7 +441,6 @@ namespace Tasking
/* Other */ /* Other */
Signal *Signals; Signal *Signals;
SymbolResolver::Symbols *ELFSymbolTable;
/* Threads & Children */ /* Threads & Children */
std::list<TCB *> Threads; std::list<TCB *> Threads;
@ -462,10 +461,8 @@ namespace Tasking
PCB *Parent, PCB *Parent,
const char *Name, const char *Name,
TaskExecutionMode ExecutionMode, TaskExecutionMode ExecutionMode,
void *Image = nullptr,
bool UseKernelPageTable = false, bool UseKernelPageTable = false,
uint16_t UserID = -1, uint16_t UserID = -1, uint16_t GroupID = -1);
uint16_t GroupID = -1);
~PCB(); ~PCB();
}; };
@ -641,7 +638,6 @@ namespace Tasking
PCB *CreateProcess(PCB *Parent, PCB *CreateProcess(PCB *Parent,
const char *Name, const char *Name,
TaskExecutionMode TrustLevel, TaskExecutionMode TrustLevel,
void *Image = nullptr,
bool UseKernelPageTable = false, bool UseKernelPageTable = false,
uint16_t UserID = UINT16_MAX, uint16_t UserID = UINT16_MAX,
uint16_t GroupID = UINT16_MAX); uint16_t GroupID = UINT16_MAX);

View File

@ -686,10 +686,9 @@ static pid_t linux_fork(SysFrm *sf)
PCB *Parent = Thread->Parent; PCB *Parent = Thread->Parent;
PCB *NewProcess = PCB *NewProcess =
TaskManager->CreateProcess(Parent, TaskManager->CreateProcess(Parent, Parent->Name,
Parent->Name,
Parent->Security.ExecutionMode, Parent->Security.ExecutionMode,
nullptr, true); true);
if (unlikely(!NewProcess)) if (unlikely(!NewProcess))
{ {
error("Failed to create process for fork"); error("Failed to create process for fork");
@ -702,17 +701,6 @@ static pid_t linux_fork(SysFrm *sf)
NewProcess->ProgramBreak->SetTable(NewProcess->PageTable); NewProcess->ProgramBreak->SetTable(NewProcess->PageTable);
NewProcess->FileDescriptors->Fork(Parent->FileDescriptors); NewProcess->FileDescriptors->Fork(Parent->FileDescriptors);
if (Parent->ELFSymbolTable &&
Parent->ELFSymbolTable->SymTableExists)
{
NewProcess->ELFSymbolTable = new SymbolResolver::Symbols(0);
foreach (auto sym in Parent->ELFSymbolTable->GetSymTable())
{
NewProcess->ELFSymbolTable->AddSymbol(sym.Address,
sym.FunctionName);
}
}
TCB *NewThread = TCB *NewThread =
TaskManager->CreateThread(NewProcess, TaskManager->CreateThread(NewProcess,
0, 0,

View File

@ -58,10 +58,9 @@ int sys_fork(SysFrm *Frame)
TCB *Thread = thisThread; TCB *Thread = thisThread;
PCB *NewProcess = PCB *NewProcess =
TaskManager->CreateProcess(Parent, TaskManager->CreateProcess(Parent, Parent->Name,
Parent->Name,
Parent->Security.ExecutionMode, Parent->Security.ExecutionMode,
nullptr, true); true);
if (!NewProcess) if (!NewProcess)
{ {
@ -69,17 +68,6 @@ int sys_fork(SysFrm *Frame)
return -EAGAIN; return -EAGAIN;
} }
if (Parent->ELFSymbolTable &&
Parent->ELFSymbolTable->SymTableExists)
{
NewProcess->ELFSymbolTable = new SymbolResolver::Symbols(0);
foreach (auto sym in Parent->ELFSymbolTable->GetSymTable())
{
NewProcess->ELFSymbolTable->AddSymbol(sym.Address,
sym.FunctionName);
}
}
NewProcess->PageTable = Parent->PageTable->Fork(); NewProcess->PageTable = Parent->PageTable->Fork();
TCB *NewThread = TCB *NewThread =

View File

@ -127,7 +127,7 @@ namespace Tasking
} }
PCB::PCB(Task *ctx, PCB *Parent, const char *Name, PCB::PCB(Task *ctx, PCB *Parent, const char *Name,
TaskExecutionMode ExecutionMode, void *Image, TaskExecutionMode ExecutionMode,
bool UseKernelPageTable, bool UseKernelPageTable,
uint16_t UserID, uint16_t GroupID) uint16_t UserID, uint16_t GroupID)
: Node(ProcFS, std::to_string(ctx->NextPID), NodeType::DIRECTORY) : Node(ProcFS, std::to_string(ctx->NextPID), NodeType::DIRECTORY)
@ -208,9 +208,6 @@ namespace Tasking
this->ProgramBreak = new Memory::ProgramBreak(this->PageTable, this->vma); this->ProgramBreak = new Memory::ProgramBreak(this->PageTable, this->vma);
this->Signals = new Signal(this); this->Signals = new Signal(this);
if (Image)
this->ELFSymbolTable = new SymbolResolver::Symbols((uintptr_t)Image);
debug("Process page table: %#lx", this->PageTable); debug("Process page table: %#lx", this->PageTable);
debug("Created %s process \"%s\"(%d). Parent \"%s\"(%d)", debug("Created %s process \"%s\"(%d). Parent \"%s\"(%d)",
ExecutionMode == TaskExecutionMode::User ? "user" : "kernel", ExecutionMode == TaskExecutionMode::User ? "user" : "kernel",
@ -247,10 +244,6 @@ namespace Tasking
ctx->ProcessList.end(), ctx->ProcessList.end(),
this)); this));
debug("Freeing symbol table strings");
if (this->ELFSymbolTable)
delete this->ELFSymbolTable;
debug("Freeing signals"); debug("Freeing signals");
delete this->Signals; delete this->Signals;

View File

@ -313,15 +313,12 @@ namespace Tasking
PCB *Task::CreateProcess(PCB *Parent, PCB *Task::CreateProcess(PCB *Parent,
const char *Name, const char *Name,
TaskExecutionMode ExecutionMode, TaskExecutionMode ExecutionMode,
void *Image,
bool UseKernelPageTable, bool UseKernelPageTable,
uint16_t UserID, uint16_t UserID, uint16_t GroupID)
uint16_t GroupID)
{ {
SmartLock(TaskingLock); SmartLock(TaskingLock);
return new PCB(this, Parent, Name, ExecutionMode, return new PCB(this, Parent, Name, ExecutionMode,
Image, UseKernelPageTable, UseKernelPageTable, UserID, GroupID);
UserID, GroupID);
} }
void Task::StartScheduler() void Task::StartScheduler()
@ -383,10 +380,8 @@ namespace Tasking
#endif #endif
KernelProcess = CreateProcess(nullptr, "Kernel", KernelProcess = CreateProcess(nullptr, "Kernel",
TaskExecutionMode::Kernel, TaskExecutionMode::Kernel, true);
nullptr, true);
KernelProcess->PageTable = KernelPageTable; KernelProcess->PageTable = KernelPageTable;
KernelProcess->ELFSymbolTable = KernelSymbolTable;
TCB *kthrd = CreateThread(KernelProcess, EntryPoint, TCB *kthrd = CreateThread(KernelProcess, EntryPoint,
nullptr, nullptr, nullptr, nullptr,
std::vector<AuxiliaryVector>(), Arch); std::vector<AuxiliaryVector>(), Arch);
@ -418,9 +413,7 @@ namespace Tasking
} }
IdleProcess = CreateProcess(nullptr, (char *)"Idle", IdleProcess = CreateProcess(nullptr, (char *)"Idle",
TaskExecutionMode::Kernel, TaskExecutionMode::Kernel, true);
nullptr, true);
IdleProcess->ELFSymbolTable = KernelSymbolTable;
for (int i = 0; i < SMP::CPUCores; i++) for (int i = 0; i < SMP::CPUCores; i++)
{ {
TCB *thd = CreateThread(IdleProcess, IP(IdleProcessLoop)); TCB *thd = CreateThread(IdleProcess, IP(IdleProcessLoop));

View File

@ -153,13 +153,11 @@ void TaskMgr()
#if defined(a64) #if defined(a64)
printf(" \e%s-> \eAABBCC%s \e00AAAA%s %ld%% (KT: %ld UT: %ld, IP: \e24FF2B%#lx \eEDFF24%s\e00AAAA)\n\eAABBCC", printf(" \e%s-> \eAABBCC%s \e00AAAA%s %ld%% (KT: %ld UT: %ld, IP: \e24FF2B%#lx \eEDFF24%s\e00AAAA)\n\eAABBCC",
Statuses[State], Thd->Name, StatusesSign[State], ThreadCpuUsage, Thd->Info.KernelTime, Statuses[State], Thd->Name, StatusesSign[State], ThreadCpuUsage, Thd->Info.KernelTime,
Thd->Info.UserTime, Thd->Registers.rip, Thd->Info.UserTime, Thd->Registers.rip, "unknown");
Thd->Parent->ELFSymbolTable ? Thd->Parent->ELFSymbolTable->GetSymbol(Thd->Registers.rip) : "unknown");
#elif defined(a32) #elif defined(a32)
printf(" \e%s-> \eAABBCC%s \e00AAAA%s %lld%% (KT: %lld UT: %lld, IP: \e24FF2B%#x \eEDFF24%s\e00AAAA)\n\eAABBCC", printf(" \e%s-> \eAABBCC%s \e00AAAA%s %lld%% (KT: %lld UT: %lld, IP: \e24FF2B%#x \eEDFF24%s\e00AAAA)\n\eAABBCC",
Statuses[State], Thd->Name, StatusesSign[State], ThreadCpuUsage, Thd->Info.KernelTime, Statuses[State], Thd->Name, StatusesSign[State], ThreadCpuUsage, Thd->Info.KernelTime,
Thd->Info.UserTime, Thd->Registers.eip, Thd->Info.UserTime, Thd->Registers.eip, "unknown");
Thd->Parent->ELFSymbolTable ? Thd->Parent->ELFSymbolTable->GetSymbol(Thd->Registers.eip) : "unknown");
#elif defined(aa64) #elif defined(aa64)
#endif #endif
} }