[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

@@ -5,71 +5,72 @@
#include <j6/types.h>
#include <j6/protocols/service_locator.h>
#include <j6/syscalls.h>
#include <util/map.h>
#include <util/node_map.h>
#include "service_locator.h"
struct handle_entry
{
uint64_t protocol;
j6_handle_t handle;
};
uint64_t & get_map_key(handle_entry &e) { return e.protocol; }
void
service_locator_start(j6_handle_t mb)
{
// TODO: This should be a multimap
util::map<uint64_t, j6_handle_t> services;
util::node_map<uint64_t, handle_entry> services;
uint64_t tag;
uint64_t subtag;
uint16_t reply_tag;
uint8_t data[100];
size_t data_len = sizeof(data);
j6_handle_t handles[10];
size_t handles_count = sizeof(handles)/sizeof(j6_handle_t);
j6_status_t s = j6_mailbox_receive(mb, &tag,
data, &data_len,
j6_status_t s = j6_mailbox_receive(mb,
&tag, &subtag,
handles, &handles_count,
&reply_tag, nullptr,
&reply_tag,
j6_mailbox_block);
uint64_t proto_id;
uint64_t *data_words = reinterpret_cast<uint64_t*>(data);
while (true) {
j6_handle_t *found = nullptr;
handle_entry *found = nullptr;
switch (tag) {
case j6_proto_base_get_proto_id:
tag = j6_proto_base_proto_id;
*data_words = j6_proto_sl_id;
data_len = sizeof(j6_status_t);
subtag = j6_proto_sl_id;
handles_count = 0;
break;
case j6_proto_sl_register:
proto_id = *data_words;
proto_id = subtag;
if (handles_count != 1) {
tag = j6_proto_base_status;
*data_words = j6_err_invalid_arg;
data_len = sizeof(j6_status_t);
subtag = j6_err_invalid_arg;
handles_count = 0;
break;
}
services.insert( proto_id, handles[0] );
services.insert( {proto_id, handles[0]} );
tag = j6_proto_base_status;
*data_words = j6_status_ok;
data_len = sizeof(j6_status_t);
subtag = j6_status_ok;
handles_count = 0;
break;
case j6_proto_sl_find:
proto_id = *data_words;
proto_id = subtag;
tag = j6_proto_sl_result;
data_len = 0;
found = services.find(proto_id);
if (found) {
handles_count = 1;
handles[0] = *found;
handles[0] = found->handle;
} else {
handles_count = 0;
}
@@ -77,21 +78,18 @@ service_locator_start(j6_handle_t mb)
default:
tag = j6_proto_base_status;
*data_words = j6_err_invalid_arg;
data_len = sizeof(j6_status_t);
subtag = j6_err_invalid_arg;
handles_count = 0;
break;
}
size_t data_in = data_len;
size_t handles_in = handles_count;
data_len = sizeof(data);
handles_count = sizeof(handles)/sizeof(j6_handle_t);
s = j6_mailbox_respond_receive(mb, &tag,
data, &data_len, data_in,
s = j6_mailbox_respond_receive(mb,
&tag, &subtag,
handles, &handles_count, handles_in,
&reply_tag, nullptr,
&reply_tag,
j6_mailbox_block);
}
}