acadia/zion/capability/capability.h

50 lines
1.1 KiB
C
Raw Normal View History

#pragma once
#include <stdint.h>
#include "lib/ref_ptr.h"
#include "object/kernel_object.h"
class Process;
2023-06-06 16:24:03 -07:00
class Thread;
2023-06-07 06:21:36 -07:00
class Capability : public RefCounted<Capability> {
public:
enum Type {
UNDEFINED,
PROCESS,
2023-06-06 16:24:03 -07:00
THREAD,
ADDRESS_SPACE,
MEMORY_OBJECT,
CHANNEL,
PORT,
};
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>
RefPtr<T> obj();
uint64_t id() { return id_; }
void set_id(uint64_t id) { id_ = id; }
bool CheckType(Type type) { return type_ == type; }
uint64_t permissions() { return permissions_; }
bool HasPermissions(uint64_t requested) {
return (permissions_ & requested) == requested;
}
private:
RefPtr<KernelObject> obj_;
Type type_;
uint64_t id_;
uint64_t permissions_;
};