[kernel] Make mailbox non-fixed-length again

Going back to letting mailboxes use variable-length data. Note that this
requires extra copies, so shared memory channels should be used for
anything in the hot path. But this allows better RPC over mailboxes and
other flexibility.

Other changes:
- added a j6::proto::sl::client class to act as a service locator
  client, instead of duplicating that code in every program.
- moved protocol ids into j6/tables/protocols.inc so that C++ clients
  can easily have their own API
This commit is contained in:
Justin C. Miller
2023-08-07 22:59:03 -07:00
parent a0f91ed0fd
commit 8b3fa3ed01
22 changed files with 329 additions and 81 deletions

View File

@@ -1,4 +1,5 @@
#include <unordered_map>
#include <stdlib.h>
#include <j6/errors.h>
#include <j6/flags.h>
@@ -24,45 +25,44 @@ service_locator_start(j6_handle_t mb)
std::unordered_map<uint64_t, j6_handle_t> services;
uint64_t tag = 0;
uint64_t subtag = 0;
uint64_t data = 0;
uint64_t handle_count = 1;
uint64_t reply_tag = 0;
j6_handle_t give_handle = j6_handle_invalid;
uint64_t proto_id;
while (true) {
j6_status_t s = j6_mailbox_respond(mb, &tag, &subtag, &give_handle,
&reply_tag, j6_flag_block);
uint64_t data_len = sizeof(uint64_t);
j6_status_t s = j6_mailbox_respond(mb, &tag,
&data, &data_len, data_len,
&give_handle, &handle_count,
&reply_tag, j6_flag_block);
if (s != j6_status_ok)
while (1);
exit(128);
handle_entry *found = nullptr;
switch (tag) {
case j6_proto_base_get_proto_id:
tag = j6_proto_base_proto_id;
subtag = j6_proto_sl_id;
give_handle = j6_handle_invalid;
break;
case j6_proto_sl_register:
proto_id = subtag;
proto_id = data;
if (give_handle == j6_handle_invalid) {
tag = j6_proto_base_status;
subtag = j6_err_invalid_arg;
data = j6_err_invalid_arg;
break;
}
services.insert( {proto_id, give_handle} );
tag = j6_proto_base_status;
subtag = j6_status_ok;
data = j6_status_ok;
give_handle = j6_handle_invalid;
break;
case j6_proto_sl_find:
proto_id = subtag;
proto_id = data;
tag = j6_proto_sl_result;
data = 0;
{
auto found = services.find(proto_id);
@@ -75,7 +75,7 @@ service_locator_start(j6_handle_t mb)
default:
tag = j6_proto_base_status;
subtag = j6_err_invalid_arg;
data = j6_err_invalid_arg;
give_handle = j6_handle_invalid;
break;
}

View File

@@ -2,4 +2,6 @@
/// \file service_locator.h
/// Definitions for srv.init's implementation of the service locator protocol
#include <j6/types.h>
void service_locator_start(j6_handle_t mb);