Make a KernelObject base class for all Capabilities.

This commit is contained in:
Drew Galbraith 2023-06-06 20:13:07 -07:00
parent d358c1d672
commit 4e278a4664
9 changed files with 50 additions and 21 deletions

View file

@ -1,11 +1,14 @@
#include "capability/capability.h"
#include "scheduler/process.h"
#include "scheduler/thread.h"
template <>
Process& Capability::obj<Process>() {
if (type_ != PROCESS) {
panic("Accessing %u cap as object.", type_);
}
return *static_cast<Process*>(obj_);
return *static_cast<Process*>(obj_.get());
}
template <>
@ -13,5 +16,5 @@ Thread& Capability::obj<Thread>() {
if (type_ != THREAD) {
panic("Accessing %u cap as object.", type_);
}
return *static_cast<Thread*>(obj_);
return *static_cast<Thread*>(obj_.get());
}

View file

@ -2,7 +2,8 @@
#include <stdint.h>
#include "debug/debug.h"
#include "lib/ref_ptr.h"
#include "object/kernel_object.h"
class Process;
class Thread;
@ -14,9 +15,15 @@ class Capability {
PROCESS,
THREAD,
};
Capability(void* obj, Type type, uint64_t id, uint64_t permissions)
Capability(const RefPtr<KernelObject>& obj, Type type, uint64_t id,
uint64_t permissions)
: obj_(obj), type_(type), id_(id), permissions_(permissions) {}
template <typename T>
Capability(const RefPtr<T>& obj, Type type, uint64_t id, uint64_t permissions)
: Capability(StaticCastRefPtr<KernelObject>(obj), type, id, permissions) {
}
template <typename T>
T& obj();
@ -30,8 +37,7 @@ class Capability {
}
private:
// FIXME: This should somehow be a shared ptr to keep the object alive.
void* obj_;
RefPtr<KernelObject> obj_;
Type type_;
uint64_t id_;
uint64_t permissions_;