Add a skeleton framework for capabilities.
Use the first capability to spawn a child process.
This commit is contained in:
parent
09b8136ef9
commit
69b5cd001f
9 changed files with 97 additions and 4 deletions
44
zion/capability/capability.h
Normal file
44
zion/capability/capability.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "debug/debug.h"
|
||||
|
||||
class Process;
|
||||
|
||||
class Capability {
|
||||
public:
|
||||
enum Type {
|
||||
UNDEFINED,
|
||||
PROCESS,
|
||||
};
|
||||
Capability(void* obj, Type type, uint64_t id, uint64_t permissions)
|
||||
: obj_(obj), type_(type), id_(id), permissions_(permissions) {}
|
||||
|
||||
template <typename T>
|
||||
T& obj();
|
||||
|
||||
uint64_t id() { return id_; }
|
||||
|
||||
bool CheckType(Type type) { return type_ == type; }
|
||||
|
||||
uint64_t permissions() { return permissions_; }
|
||||
bool HasPermissions(uint64_t requested) {
|
||||
return (permissions_ & requested) == requested;
|
||||
}
|
||||
|
||||
private:
|
||||
// FIXME: This should somehow be a shared ptr to keep the object alive.
|
||||
void* obj_;
|
||||
Type type_;
|
||||
uint64_t id_;
|
||||
uint64_t permissions_;
|
||||
};
|
||||
|
||||
template <class Process>
|
||||
Process& Capability::obj() {
|
||||
if (type_ != PROCESS) {
|
||||
panic("Accessing %u cap as object.", type_);
|
||||
}
|
||||
return *static_cast<Process*>(obj_);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue