[kernel] Make capabilities/handles global

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.
This commit is contained in:
Justin C. Miller
2022-10-10 21:19:25 -07:00
parent 41bb97b179
commit 9ac4e51224
27 changed files with 337 additions and 383 deletions

View File

@@ -12,26 +12,26 @@
j6_handle_t __handle_self;
namespace {
constexpr size_t static_arr_size = 8;
j6_handle_t handle_array[static_arr_size];
constexpr size_t static_arr_count = 8;
j6_handle_descriptor handle_array[static_arr_count];
} // namespace
j6_handle_t
j6_find_first_handle(j6_object_type obj_type)
{
size_t count = static_arr_size;
j6_handle_t *handles = handle_array;
size_t count = static_arr_count;
j6_handle_descriptor *handles = handle_array;
j6_status_t s = j6_handle_list(handles, &count);
if (s != j6_err_insufficient && s != j6_status_ok)
return j6_handle_invalid;
if (count > static_arr_size)
count = static_arr_size;
if (count > static_arr_count)
count = static_arr_count;
for (size_t i = 0; i < count; ++i) {
uint8_t type = (handles[i] >> 56);
if (type == obj_type) return handles[i];
j6_handle_descriptor &desc = handle_array[i];
if (desc.type == obj_type) return desc.handle;
}
return j6_handle_invalid;

View File

@@ -27,15 +27,12 @@ typedef uint64_t j6_tag_t;
#define j6_tag_from_irq(x) ((x) | j6_tag_irq_base)
#define j6_tag_to_irq(x) ((x) & ~j6_tag_irq_base)
/// Handles are references and capabilities to other objects. A handle is
/// an id in the lower 32 bits, a bitfield of capabilities in bits 32-55
/// and a type id in bits 56-63.
/// Handles are references and capabilities to other objects.
typedef uint64_t j6_handle_t;
#define j6_handle_invalid 0
/// Bitfield for storage of capabilities on their own
typedef uint32_t j6_cap_t;
#define j6_handle_invalid ((j6_handle_t)-1)
typedef uint16_t j6_cap_t;
enum j6_object_type {
#define OBJECT_TYPE( name, val ) j6_object_type_ ## name = val,
@@ -44,3 +41,12 @@ enum j6_object_type {
j6_object_type_max
};
/// Description of a handle
struct j6_handle_descriptor
{
j6_handle_t handle;
j6_cap_t caps;
j6_object_type type;
};