#include "scheduler/process.h" #include "debug/debug.h" #include "include/cap_types.h" #include "memory/paging_util.h" #include "memory/physical_memory.h" #include "scheduler/scheduler.h" #include "scheduler/thread.h" namespace { static uint64_t gNextId = 1; } SharedPtr Process::RootProcess() { SharedPtr proc(new Process(0)); proc->threads_.PushBack(Thread::RootThread(*proc)); proc->next_thread_id_ = 1; return proc; } Process::Process() : id_(gNextId++), state_(RUNNING) {} void Process::CreateThread(uint64_t entry) { Thread* thread = new Thread(*this, next_thread_id_++, entry); threads_.PushBack(thread); caps_.PushBack(new Capability(this, Capability::PROCESS, next_cap_id_++, ZC_PROC_SPAWN_CHILD)); gScheduler->Enqueue(thread); } SharedPtr Process::GetThread(uint64_t tid) { auto iter = threads_.begin(); while (iter != threads_.end()) { if (iter->tid() == tid) { return *iter; } ++iter; } panic("Bad thread access."); return nullptr; } void Process::CheckState() { auto iter = threads_.begin(); while (iter != threads_.end()) { if (iter->GetState() != Thread::FINISHED) { return; } ++iter; } state_ = FINISHED; } SharedPtr Process::GetCapability(uint64_t cid) { auto iter = caps_.begin(); while (iter != caps_.end()) { if (iter->id() == cid) { return *iter; } ++iter; } dbgln("Bad cap access"); return {}; }