[zion/glacier] Move RefPtr to glacier.
This commit is contained in:
parent
8bcb574677
commit
e1af79b975
26 changed files with 130 additions and 106 deletions
|
|
@ -1,9 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/memory/ref_counted.h>
|
||||
#include <glacier/memory/ref_ptr.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "lib/ref_ptr.h"
|
||||
#include "include/ztypes.h"
|
||||
#include "object/kernel_object.h"
|
||||
|
||||
class Process;
|
||||
|
|
@ -11,17 +12,17 @@ class Thread;
|
|||
|
||||
class Capability : public glcr::RefCounted<Capability> {
|
||||
public:
|
||||
Capability(const RefPtr<KernelObject>& obj, uint64_t permissions)
|
||||
Capability(const glcr::RefPtr<KernelObject>& obj, uint64_t permissions)
|
||||
: obj_(obj), permissions_(permissions) {}
|
||||
|
||||
template <typename T>
|
||||
Capability(const RefPtr<T>& obj, uint64_t permissions)
|
||||
Capability(const glcr::RefPtr<T>& obj, uint64_t permissions)
|
||||
: Capability(StaticCastRefPtr<KernelObject>(obj), permissions) {}
|
||||
|
||||
template <typename T>
|
||||
RefPtr<T> obj();
|
||||
glcr::RefPtr<T> obj();
|
||||
|
||||
RefPtr<KernelObject> raw_obj() { return obj_; }
|
||||
glcr::RefPtr<KernelObject> raw_obj() { return obj_; }
|
||||
|
||||
uint64_t permissions() { return permissions_; }
|
||||
bool HasPermissions(uint64_t requested) {
|
||||
|
|
@ -29,12 +30,12 @@ class Capability : public glcr::RefCounted<Capability> {
|
|||
}
|
||||
|
||||
private:
|
||||
RefPtr<KernelObject> obj_;
|
||||
glcr::RefPtr<KernelObject> obj_;
|
||||
uint64_t permissions_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
RefPtr<T> Capability::obj() {
|
||||
glcr::RefPtr<T> Capability::obj() {
|
||||
if (obj_->TypeTag() != KernelObjectTag<T>::type) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -42,7 +43,7 @@ RefPtr<T> Capability::obj() {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
z_err_t ValidateCapability(const RefPtr<Capability>& cap,
|
||||
z_err_t ValidateCapability(const glcr::RefPtr<Capability>& cap,
|
||||
uint64_t permissions) {
|
||||
if (!cap) {
|
||||
return Z_ERR_CAP_NOT_FOUND;
|
||||
|
|
|
|||
|
|
@ -2,14 +2,15 @@
|
|||
|
||||
CapabilityTable::CapabilityTable() {}
|
||||
|
||||
uint64_t CapabilityTable::AddExistingCapability(const RefPtr<Capability>& cap) {
|
||||
uint64_t CapabilityTable::AddExistingCapability(
|
||||
const glcr::RefPtr<Capability>& cap) {
|
||||
MutexHolder h(lock_);
|
||||
uint64_t id = next_cap_id_++;
|
||||
capabilities_.PushBack({.id = id, .cap = cap});
|
||||
return id;
|
||||
}
|
||||
|
||||
RefPtr<Capability> CapabilityTable::GetCapability(uint64_t id) {
|
||||
glcr::RefPtr<Capability> CapabilityTable::GetCapability(uint64_t id) {
|
||||
MutexHolder h(lock_);
|
||||
auto iter = capabilities_.begin();
|
||||
while (iter != capabilities_.end()) {
|
||||
|
|
@ -23,7 +24,7 @@ RefPtr<Capability> CapabilityTable::GetCapability(uint64_t id) {
|
|||
return {};
|
||||
}
|
||||
|
||||
RefPtr<Capability> CapabilityTable::ReleaseCapability(uint64_t id) {
|
||||
glcr::RefPtr<Capability> CapabilityTable::ReleaseCapability(uint64_t id) {
|
||||
MutexHolder h(lock_);
|
||||
auto iter = capabilities_.begin();
|
||||
while (iter != capabilities_.end()) {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/memory/ref_ptr.h>
|
||||
|
||||
#include "capability/capability.h"
|
||||
#include "lib/linked_list.h"
|
||||
#include "lib/mutex.h"
|
||||
#include "lib/ref_ptr.h"
|
||||
|
||||
class CapabilityTable {
|
||||
public:
|
||||
|
|
@ -13,11 +14,12 @@ class CapabilityTable {
|
|||
CapabilityTable& operator=(CapabilityTable&) = delete;
|
||||
|
||||
template <typename T>
|
||||
uint64_t AddNewCapability(const RefPtr<T>& object, uint64_t permissions);
|
||||
uint64_t AddExistingCapability(const RefPtr<Capability>& cap);
|
||||
uint64_t AddNewCapability(const glcr::RefPtr<T>& object,
|
||||
uint64_t permissions);
|
||||
uint64_t AddExistingCapability(const glcr::RefPtr<Capability>& cap);
|
||||
|
||||
RefPtr<Capability> GetCapability(uint64_t id);
|
||||
RefPtr<Capability> ReleaseCapability(uint64_t id);
|
||||
glcr::RefPtr<Capability> GetCapability(uint64_t id);
|
||||
glcr::RefPtr<Capability> ReleaseCapability(uint64_t id);
|
||||
|
||||
private:
|
||||
Mutex lock_{"cap table"};
|
||||
|
|
@ -26,13 +28,13 @@ class CapabilityTable {
|
|||
// FIXME: use a map data structure.
|
||||
struct CapEntry {
|
||||
uint64_t id;
|
||||
RefPtr<Capability> cap;
|
||||
glcr::RefPtr<Capability> cap;
|
||||
};
|
||||
LinkedList<CapEntry> capabilities_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
uint64_t CapabilityTable::AddNewCapability(const RefPtr<T>& object,
|
||||
uint64_t CapabilityTable::AddNewCapability(const glcr::RefPtr<T>& object,
|
||||
uint64_t permissions) {
|
||||
MutexHolder h(lock_);
|
||||
uint64_t id = next_cap_id_++;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue