Add a skeleton framework for capabilities.
Use the first capability to spawn a child process.
This commit is contained in:
parent
09b8136ef9
commit
69b5cd001f
9 changed files with 97 additions and 4 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#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"
|
||||
|
|
@ -25,6 +26,8 @@ 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);
|
||||
}
|
||||
|
||||
|
|
@ -50,3 +53,15 @@ void Process::CheckState() {
|
|||
}
|
||||
state_ = FINISHED;
|
||||
}
|
||||
|
||||
SharedPtr<Capability> 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 {};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "capability/capability.h"
|
||||
#include "lib/linked_list.h"
|
||||
#include "lib/shared_ptr.h"
|
||||
#include "memory/virtual_memory.h"
|
||||
|
|
@ -26,6 +27,7 @@ class Process {
|
|||
void CreateThread(uint64_t entry);
|
||||
SharedPtr<Thread> GetThread(uint64_t tid);
|
||||
|
||||
SharedPtr<Capability> GetCapability(uint64_t cid);
|
||||
// Checks the state of all child threads and transitions to
|
||||
// finished if all have finished.
|
||||
void CheckState();
|
||||
|
|
@ -39,6 +41,8 @@ class Process {
|
|||
State state_;
|
||||
|
||||
uint64_t next_thread_id_ = 0;
|
||||
uint64_t next_cap_id_ = 0x100;
|
||||
|
||||
LinkedList<SharedPtr<Thread>> threads_;
|
||||
LinkedList<SharedPtr<Capability>> caps_;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue