mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-05-28 23:44:31 +00:00
Revise PID and TID generation to align with standards
This commit is contained in:
parent
525a102f20
commit
d3a16469ad
@ -501,6 +501,13 @@ namespace Driver
|
||||
return tcb->ID;
|
||||
}
|
||||
|
||||
pid_t GetCurrentProcess(dev_t MajorID)
|
||||
{
|
||||
dbg_api("%d", MajorID);
|
||||
|
||||
return TaskManager->GetCurrentProcess()->ID;
|
||||
}
|
||||
|
||||
int KillProcess(dev_t MajorID, pid_t pId, int ExitCode)
|
||||
{
|
||||
dbg_api("%d, %d, %d", MajorID, pId, ExitCode);
|
||||
@ -512,11 +519,11 @@ namespace Driver
|
||||
return 0;
|
||||
}
|
||||
|
||||
int KillThread(dev_t MajorID, pid_t tId, int ExitCode)
|
||||
int KillThread(dev_t MajorID, pid_t tId, pid_t pId, int ExitCode)
|
||||
{
|
||||
dbg_api("%d, %d, %d", MajorID, tId, ExitCode);
|
||||
|
||||
Tasking::TCB *tcb = TaskManager->GetThreadByID(tId);
|
||||
Tasking::TCB *tcb = TaskManager->GetThreadByID(tId, TaskManager->GetProcessByID(pId));
|
||||
if (!tcb)
|
||||
return -EINVAL;
|
||||
TaskManager->KillThread(tcb, (Tasking::KillCode)ExitCode);
|
||||
@ -913,6 +920,7 @@ namespace Driver
|
||||
|
||||
api->CreateKernelProcess = CreateKernelProcess;
|
||||
api->CreateKernelThread = CreateKernelThread;
|
||||
api->GetCurrentProcess = GetCurrentProcess;
|
||||
api->KillProcess = KillProcess;
|
||||
api->KillThread = KillThread;
|
||||
api->Yield = Yield;
|
||||
|
3
driver.h
3
driver.h
@ -298,8 +298,9 @@ typedef struct
|
||||
/* Scheduling */
|
||||
pid_t (*CreateKernelProcess)(dev_t MajorID, const char *Name);
|
||||
pid_t (*CreateKernelThread)(dev_t MajorID, pid_t pId, const char *Name, void *EntryPoint, void *Argument);
|
||||
pid_t (*GetCurrentProcess)(dev_t MajorID);
|
||||
int (*KillProcess)(dev_t MajorID, pid_t pId, int ExitCode);
|
||||
int (*KillThread)(dev_t MajorID, pid_t tId, int ExitCode);
|
||||
int (*KillThread)(dev_t MajorID, pid_t tId, pid_t pId, int ExitCode);
|
||||
void (*Yield)(dev_t MajorID);
|
||||
void (*Sleep)(dev_t MajorID, uint64_t Milliseconds);
|
||||
|
||||
|
@ -58,7 +58,7 @@ namespace Tasking::Scheduler
|
||||
assert(!"GetProcessByID not implemented");
|
||||
}
|
||||
|
||||
virtual TCB *GetThreadByID(TID ID)
|
||||
virtual TCB *GetThreadByID(TID ID, PCB* Parent)
|
||||
{
|
||||
assert(!"GetThreadByID not implemented");
|
||||
}
|
||||
@ -119,7 +119,7 @@ namespace Tasking::Scheduler
|
||||
bool RemoveThread(TCB *tcb) final;
|
||||
bool RemoveProcess(PCB *pcb) final;
|
||||
PCB *GetProcessByID(TID ID) final;
|
||||
TCB *GetThreadByID(TID ID) final;
|
||||
TCB *GetThreadByID(TID ID, PCB* Parent) final;
|
||||
std::list<PCB *> &GetProcessList() final;
|
||||
void StartIdleProcess() final;
|
||||
void StartScheduler() final;
|
||||
|
@ -474,7 +474,6 @@ namespace Tasking
|
||||
NewLock(TaskingLock);
|
||||
|
||||
PID NextPID = 0;
|
||||
TID NextTID = 0;
|
||||
|
||||
PCB *KernelProcess = nullptr;
|
||||
|
||||
@ -546,7 +545,7 @@ namespace Tasking
|
||||
|
||||
PCB *GetProcessByID(PID ID);
|
||||
|
||||
TCB *GetThreadByID(TID ID);
|
||||
TCB *GetThreadByID(TID ID, PCB* Parent);
|
||||
|
||||
/** Wait for process to terminate */
|
||||
void WaitForProcess(PCB *pcb);
|
||||
|
@ -114,7 +114,8 @@ void KernelMainThread()
|
||||
|
||||
KPrint("Executing %s", Config.InitPath);
|
||||
int ExitCode = -1;
|
||||
Tasking::TCB *initThread = nullptr;
|
||||
Tasking::TCB *initThread;
|
||||
Tasking::PCB *initProc;
|
||||
int tid = SpawnInit();
|
||||
if (tid < 0)
|
||||
{
|
||||
@ -127,7 +128,8 @@ void KernelMainThread()
|
||||
Config.InitPath);
|
||||
thisThread->SetPriority(Tasking::Idle);
|
||||
|
||||
initThread = TaskManager->GetThreadByID(tid);
|
||||
initProc = TaskManager->GetProcessByID(tid);
|
||||
initThread = TaskManager->GetThreadByID(tid, initProc);
|
||||
TaskManager->WaitForThread(initThread);
|
||||
ExitCode = initThread->GetExitCode();
|
||||
Exit:
|
||||
|
@ -1781,7 +1781,7 @@ static __noreturn void linux_exit_group(SysFrm *sf, int status)
|
||||
/* https://man7.org/linux/man-pages/man2/tgkill.2.html */
|
||||
static int linux_tgkill(SysFrm *sf, pid_t tgid, pid_t tid, int sig)
|
||||
{
|
||||
Tasking::TCB *target = thisProcess->GetContext()->GetThreadByID(tid);
|
||||
Tasking::TCB *target = thisProcess->GetContext()->GetThreadByID(tid, thisProcess);
|
||||
if (!target)
|
||||
return -ESRCH;
|
||||
|
||||
|
@ -155,15 +155,12 @@ namespace Tasking::Scheduler
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TCB *Custom::GetThreadByID(TID ID)
|
||||
TCB *Custom::GetThreadByID(TID ID, PCB *Parent)
|
||||
{
|
||||
foreach (auto p in ProcessList)
|
||||
foreach (auto t in Parent->Threads)
|
||||
{
|
||||
foreach (auto t in p->Threads)
|
||||
{
|
||||
if (t->ID == ID)
|
||||
return t;
|
||||
}
|
||||
if (t->ID == ID)
|
||||
return t;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -62,9 +62,9 @@ namespace Tasking
|
||||
return ((Scheduler::Base *)Scheduler)->GetProcessByID(ID);
|
||||
}
|
||||
|
||||
TCB *Task::GetThreadByID(TID ID)
|
||||
TCB *Task::GetThreadByID(TID ID, PCB* Parent)
|
||||
{
|
||||
return ((Scheduler::Base *)Scheduler)->GetThreadByID(ID);
|
||||
return ((Scheduler::Base *)Scheduler)->GetThreadByID(ID, Parent);
|
||||
}
|
||||
|
||||
std::list<PCB *> Task::GetProcessList()
|
||||
|
@ -426,7 +426,7 @@ namespace Tasking
|
||||
this->Parent = Parent;
|
||||
|
||||
this->ctx = ctx;
|
||||
this->ID = ctx->NextTID++;
|
||||
this->ID = (TID)this->Parent->ID + (TID)this->Parent->Threads.size();
|
||||
|
||||
if (this->Name)
|
||||
delete[] this->Name;
|
||||
|
Loading…
x
Reference in New Issue
Block a user