mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-10 23:09:18 +00:00
Refactor filesystem & stl code
This commit is contained in:
@ -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",
|
||||
|
@ -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()
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user