Kernel: Keep track of a task's PPID

This commit is contained in:
apio 2022-10-18 17:18:37 +02:00
parent bdf1bb15a1
commit a9d3bdba6f
3 changed files with 8 additions and 0 deletions

View File

@ -18,6 +18,7 @@ struct Task
}; };
uint64_t id; uint64_t id;
uint64_t ppid;
Context regs; Context regs;
int64_t task_sleep = 0; int64_t task_sleep = 0;

View File

@ -41,6 +41,8 @@ void sys_fork(Context* context)
child->address_space = parent->address_space.clone(); child->address_space = parent->address_space.clone();
child->ppid = parent->id;
child->regs.rax = 0; child->regs.rax = 0;
context->rax = child->id; context->rax = child->id;

View File

@ -102,6 +102,7 @@ void Scheduler::add_kernel_task(const char* taskname, void (*task)(void))
ASSERT(new_task); ASSERT(new_task);
new_task->user_task = false; new_task->user_task = false;
new_task->id = free_tid++; new_task->id = free_tid++;
new_task->ppid = 0;
new_task->regs.rip = (uint64_t)task; new_task->regs.rip = (uint64_t)task;
new_task->allocated_stack = new_task->allocated_stack =
(uint64_t)MemoryManager::get_pages(TASK_PAGES_IN_STACK); // 16 KB is enough for everyone, right? (uint64_t)MemoryManager::get_pages(TASK_PAGES_IN_STACK); // 16 KB is enough for everyone, right?
@ -128,6 +129,7 @@ Task* Scheduler::create_user_task()
memset(&new_task->regs, 0, sizeof(Context)); memset(&new_task->regs, 0, sizeof(Context));
new_task->user_task = true; new_task->user_task = true;
new_task->id = free_tid++; new_task->id = free_tid++;
new_task->ppid = 0;
new_task->task_sleep = 0; new_task->task_sleep = 0;
new_task->task_time = 0; new_task->task_time = 0;
new_task->cpu_time = 0; new_task->cpu_time = 0;
@ -152,9 +154,11 @@ long Scheduler::load_user_task(const char* filename)
ASSERT(new_task); ASSERT(new_task);
memset(&new_task->regs, 0, sizeof(Context)); memset(&new_task->regs, 0, sizeof(Context));
new_task->id = free_tid++; new_task->id = free_tid++;
new_task->ppid = 0;
if (!new_task->allocator.init()) if (!new_task->allocator.init())
{ {
delete new_task; delete new_task;
free_tid--;
Interrupts::pop(); Interrupts::pop();
return -ENOMEM; return -ENOMEM;
} }
@ -173,6 +177,7 @@ long Scheduler::load_user_task(const char* filename)
{ {
new_task->address_space.destroy(); new_task->address_space.destroy();
delete new_task; delete new_task;
free_tid--;
ELFLoader::release_elf_image(image); ELFLoader::release_elf_image(image);
VMM::switch_back_to_kernel_address_space(); VMM::switch_back_to_kernel_address_space();
Interrupts::pop(); Interrupts::pop();