Refactor filesystem & stl code

This commit is contained in:
EnderIce2
2024-05-18 07:42:01 +03:00
parent 77a291d08b
commit 6801475243
186 changed files with 15784 additions and 9746 deletions

View File

@ -95,15 +95,15 @@ namespace Tasking
strcpy((char *)this->Name, name);
}
void PCB::SetWorkingDirectory(vfs::Node *node)
void PCB::SetWorkingDirectory(FileNode *node)
{
trace("Setting working directory of process %s to %#lx (%s)",
this->Name, node, node->Name);
CurrentWorkingDirectory = node;
Node *cwd = fs->GetNodeFromPath("cwd", this);
this->Name, node, node->Name.c_str());
CWD = node;
FileNode *cwd = fs->GetByPath("cwd", ProcDirectory);
if (cwd)
delete cwd;
cwd = fs->CreateLink("cwd", node->FullPath, this);
fs->Remove(cwd);
cwd = fs->CreateLink("cwd", ProcDirectory, node);
if (cwd == nullptr)
error("Failed to create cwd link");
}
@ -112,11 +112,11 @@ namespace Tasking
{
trace("Setting exe %s to %s",
this->Name, path);
Executable = fs->GetNodeFromPath(path);
Node *exe = fs->GetNodeFromPath("exe", this);
Executable = fs->GetByPath(path, ProcDirectory);
FileNode *exe = fs->GetByPath("exe", ProcDirectory);
if (exe)
delete exe;
exe = fs->CreateLink("exe", Executable->FullPath, this);
fs->Remove(exe);
exe = fs->CreateLink("exe", ProcDirectory, path);
if (exe == nullptr)
error("Failed to create exe link");
}
@ -139,8 +139,7 @@ namespace Tasking
TaskExecutionMode ExecutionMode,
bool UseKernelPageTable,
uint16_t UserID, uint16_t GroupID)
: Node(ProcFS, std::to_string(ctx->NextPID), NodeType::DIRECTORY),
Signals(this)
: Signals(this)
{
debug("+ %#lx", this);
@ -150,6 +149,18 @@ namespace Tasking
assert(ExecutionMode >= _ExecuteModeMin);
assert(ExecutionMode <= _ExecuteModeMax);
FileNode *procDir = fs->GetByPath("/proc", nullptr);
assert(procDir != nullptr);
/* d r-x r-x r-x */
mode_t mode = S_IROTH | S_IXOTH |
S_IRGRP | S_IXGRP |
S_IRUSR | S_IXUSR |
S_IFDIR;
ProcDirectory = fs->Create(procDir, std::to_string(ctx->NextPID).c_str(), mode);
assert(ProcDirectory != nullptr);
this->ctx = ctx;
this->ID = ctx->NextPID++;
@ -298,13 +309,10 @@ namespace Tasking
delete[] this->Name;
debug("Removing from parent process");
if (this->Parent)
if (likely(this->Parent))
{
std::list<Tasking::PCB *> &pChild = this->Parent->Children;
pChild.erase(std::find(pChild.begin(),
pChild.end(),
this));
this->Parent->Children.erase(std::find(this->Parent->Children.begin(),
this->Parent->Children.end(), this));
}
debug("Process \"%s\"(%d) destroyed",

View File

@ -185,7 +185,7 @@ namespace Tasking::Scheduler
}
}
std::list<PCB *> &Custom::GetProcessList()
std::vector<PCB *> &Custom::GetProcessList()
{
return ProcessList;
}
@ -246,7 +246,16 @@ namespace Tasking::Scheduler
void Custom::PopProcess(PCB *pcb)
{
this->ProcessList.remove(pcb);
auto it = std::find(this->ProcessList.begin(),
this->ProcessList.end(), pcb);
if (it == this->ProcessList.end())
{
debug("Process %d not found in the list", pcb->ID);
return;
}
this->ProcessList.erase(it);
}
std::pair<PCB *, TCB *> Custom::GetIdle()

View File

@ -67,7 +67,7 @@ namespace Tasking
return ((Scheduler::Base *)Scheduler)->GetThreadByID(ID, Parent);
}
std::list<PCB *> Task::GetProcessList()
std::vector<PCB *> Task::GetProcessList()
{
return ((Scheduler::Base *)Scheduler)->GetProcessList();
}

View File

@ -579,13 +579,31 @@ namespace Tasking
this->Info.Architecture = Architecture;
this->Info.Compatibility = Compatibility;
this->Security.ExecutionMode =
this->Parent->Security.ExecutionMode;
this->Security.ExecutionMode = this->Parent->Security.ExecutionMode;
switch (Compatibility)
{
case TaskCompatibility::Native:
// this->Info.RootNode = fs->FileSystemRoots->GetChildren()[0];
break;
case TaskCompatibility::Linux:
// this->Info.RootNode = fs->FileSystemRoots->GetChildren()[1];
break;
case TaskCompatibility::Windows:
// this->Info.RootNode = fs->FileSystemRoots->GetChildren()[2];
break;
default:
assert(!"Invalid compatibility mode");
break;
}
/* FIXME */
this->Info.RootNode = fs->GetRoot(0);
if (this->Parent->Threads.size() == 0)
{
this->Parent->Info.Architecture = this->Info.Architecture;
this->Parent->Info.Compatibility = this->Info.Compatibility;
this->Parent->Info.RootNode = this->Info.RootNode;
}
// TODO: Is really a good idea to use the FPU in kernel mode?
@ -647,10 +665,9 @@ namespace Tasking
/* Remove us from the process list so we
don't get scheduled anymore */
std::list<Tasking::TCB *> &Threads = this->Parent->Threads;
Threads.erase(std::find(Threads.begin(),
Threads.end(),
this));
this->Parent->Threads.erase(std::find(this->Parent->Threads.begin(),
this->Parent->Threads.end(),
this));
/* Free CPU Stack */
delete this->Stack;