mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
Instead of handles / capabilities having numeric ids that are only valid for the owning process, they are now global in a system capabilities table. This will allow for specifying capabilities in IPC that doesn't need to be kernel-controlled. Processes will still need to be granted access to given capabilities, but that can become a simpler system call than the current method of sending them through mailbox messages (and worse, having to translate every one into a new capability like was the case before). In order to track which handles a process has access to, a new node_set based on node_map allows for an efficient storage and lookup of handles.
49 lines
1.1 KiB
C++
49 lines
1.1 KiB
C++
#pragma once
|
|
/// \file capabilities.h
|
|
/// Capability table definitions
|
|
|
|
#include <j6/types.h>
|
|
#include <util/node_map.h>
|
|
#include <util/spinlock.h>
|
|
|
|
#include "objects/kobject.h"
|
|
|
|
struct capability
|
|
{
|
|
j6_handle_t id;
|
|
j6_handle_t parent;
|
|
|
|
uint32_t holders;
|
|
j6_cap_t caps;
|
|
obj::kobject::type type;
|
|
// 1 byte alignment padding
|
|
|
|
obj::kobject *object;
|
|
};
|
|
|
|
class cap_table
|
|
{
|
|
public:
|
|
/// Constructor. Takes the start of the memory region to contain the cap table.
|
|
cap_table(uintptr_t start);
|
|
|
|
/// Create a new capability for the given object.
|
|
j6_handle_t create(obj::kobject *target, j6_cap_t caps);
|
|
|
|
/// Create a new capability from an existing one.
|
|
j6_handle_t derive(j6_handle_t id, j6_cap_t caps);
|
|
|
|
/// Get the capability referenced by a handle
|
|
capability * find(j6_handle_t id);
|
|
|
|
private:
|
|
using map_type = util::inplace_map<j6_handle_t, capability, j6_handle_invalid>;
|
|
map_type m_caps;
|
|
|
|
util::spinlock m_lock;
|
|
size_t m_count;
|
|
};
|
|
|
|
extern cap_table &g_cap_table;
|
|
inline uint64_t & get_map_key(capability &cap) { return cap.id; }
|