2023-05-30 23:55:42 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2023-06-06 20:13:07 -07:00
|
|
|
#include "lib/ref_ptr.h"
|
|
|
|
#include "object/kernel_object.h"
|
2023-05-30 23:55:42 -07:00
|
|
|
|
|
|
|
class Process;
|
2023-06-06 16:24:03 -07:00
|
|
|
class Thread;
|
2023-05-30 23:55:42 -07:00
|
|
|
|
2023-06-07 06:21:36 -07:00
|
|
|
class Capability : public RefCounted<Capability> {
|
2023-05-30 23:55:42 -07:00
|
|
|
public:
|
2023-06-16 15:27:09 -07:00
|
|
|
Capability(const RefPtr<KernelObject>& obj, uint64_t permissions)
|
|
|
|
: obj_(obj), permissions_(permissions) {}
|
2023-05-30 23:55:42 -07:00
|
|
|
|
2023-06-06 20:13:07 -07:00
|
|
|
template <typename T>
|
2023-06-16 15:27:09 -07:00
|
|
|
Capability(const RefPtr<T>& obj, uint64_t permissions)
|
|
|
|
: Capability(StaticCastRefPtr<KernelObject>(obj), permissions) {}
|
2023-06-06 20:13:07 -07:00
|
|
|
|
2023-05-30 23:55:42 -07:00
|
|
|
template <typename T>
|
2023-06-07 00:04:53 -07:00
|
|
|
RefPtr<T> obj();
|
2023-05-30 23:55:42 -07:00
|
|
|
|
|
|
|
uint64_t permissions() { return permissions_; }
|
|
|
|
bool HasPermissions(uint64_t requested) {
|
|
|
|
return (permissions_ & requested) == requested;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2023-06-06 20:13:07 -07:00
|
|
|
RefPtr<KernelObject> obj_;
|
2023-05-30 23:55:42 -07:00
|
|
|
uint64_t permissions_;
|
|
|
|
};
|
2023-06-16 14:53:57 -07:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
RefPtr<T> Capability::obj() {
|
|
|
|
if (obj_->TypeTag() != KernelObjectTag<T>::type) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return StaticCastRefPtr<T>(obj_);
|
|
|
|
}
|