[zion] Dynamically check Capability type.

Instead of passing an enum with the capability when creating it, relying
on polymorphism and a template struct tag to determine the object type
at runtime.

This is cleaner and avoids errors where we pass the wrong capability
type with the cap and do a bad cast at runtime.
This commit is contained in:
Drew Galbraith 2023-06-16 14:53:57 -07:00
parent b4902a79ef
commit a47bac9966
13 changed files with 113 additions and 106 deletions

View file

@ -3,6 +3,12 @@
#include "lib/linked_list.h"
#include "object/kernel_object.h"
class MemoryObject;
template <>
struct KernelObjectTag<MemoryObject> {
static const uint64_t type = KernelObject::MEMORY_OBJECT;
};
/*
* MemoryObject is a page-aligned set of memory that corresponds
* to physical pages.
@ -11,6 +17,7 @@
* */
class MemoryObject : public KernelObject {
public:
uint64_t TypeTag() override { return KernelObject::MEMORY_OBJECT; }
MemoryObject(uint64_t size);
uint64_t size() { return size_; }