mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
This commit adds the 6s shell, and a bunch of supporting work for it. Major changes include: - New shell.yaml manifest to give 6s control of the TTY instead of srv.logger - Changes to mailbox syscalls to add max handles array size separate from input size. Also reversed the meaning of the similar data size argument in those syscalls. (Using the second arg as the max array size and the first as the current valid size allows for the auto verify code to verify handles properly, and simplifies user-side code.) - New util::unique_ptr smart pointer class similar to std::unique_ptr - New ipc::message format that uses util::unique_ptr to manage ownership and lifetimes and avoid extra copying. - The service locator protocol now supports multiple handles per entry - Channels got a major overhaul. They are now split into two VMAs, each containing a mutex, a condition, and a util::bip_buffer. The order of the VMAs determines which end of the pipe you're on. (ie, the creator swaps them before handing them to the other thread.) Their API also changed to be similar to that of util::bip_buffer, to avoid extra copies. - util::bip_buffer now keeps its state and its buffer together, so that there are no pointers. This allows multiple processes to share them in shared memory, like in channels. - The UART driver changed from keeping buffers for the serial ports to just keeping a channel, and the serial port objects read/write directly from/to the channel. Known issues: - The shell doesn't actually do anything yet. It echos its input back to the serial line and injects a prompt on new lines. - The shell is one character behind in printing back to the serial line.
68 lines
1.8 KiB
C++
68 lines
1.8 KiB
C++
#include <j6/errors.h>
|
|
#include <j6/protocols/service_locator.hh>
|
|
#include <j6/syscalls.h>
|
|
#include <j6/syslog.hh>
|
|
|
|
#ifndef __j6kernel
|
|
|
|
namespace j6::proto::sl {
|
|
|
|
client::client(j6_handle_t slp_mb) :
|
|
m_service {slp_mb}
|
|
{
|
|
}
|
|
|
|
j6_status_t
|
|
client::register_service(uint64_t proto_id, util::counted<j6_handle_t> handles)
|
|
{
|
|
uint64_t tag = j6_proto_sl_register;
|
|
size_t data = proto_id;
|
|
size_t data_size = sizeof(proto_id);
|
|
|
|
j6_status_t s = j6_mailbox_call(m_service, &tag,
|
|
&data, &data_size, data_size,
|
|
handles.pointer, &handles.count, handles.count);
|
|
|
|
if (s != j6_status_ok)
|
|
return s;
|
|
|
|
if (tag == j6_proto_base_status)
|
|
return data; // contains a status
|
|
|
|
return j6_err_unexpected;
|
|
}
|
|
|
|
j6_status_t
|
|
client::lookup_service(uint64_t proto_id, util::counted<j6_handle_t> &handles)
|
|
{
|
|
uint64_t tag = j6_proto_sl_find;
|
|
size_t data = proto_id;
|
|
size_t data_size = sizeof(proto_id);
|
|
size_t handles_size = handles.count;
|
|
handles.count = 0;
|
|
|
|
j6::syslog(j6::logs::proto, j6::log_level::verbose, "Looking up service for %x", proto_id);
|
|
j6_status_t s = j6_mailbox_call(m_service, &tag,
|
|
&data, &data_size, data_size,
|
|
handles.pointer, &handles.count, handles_size);
|
|
|
|
if (s != j6_status_ok) {
|
|
j6::syslog(j6::logs::proto, j6::log_level::error, "Received error %lx trying to call service lookup", s);
|
|
return s;
|
|
}
|
|
|
|
if (tag == j6_proto_sl_result)
|
|
return j6_status_ok; // handles are already in `handles`
|
|
|
|
else if (tag == j6_proto_base_status) {
|
|
j6::syslog(j6::logs::proto, j6::log_level::warn, "Received status %lx from service lookup", data);
|
|
return data; // contains a status
|
|
}
|
|
|
|
return j6_err_unexpected;
|
|
}
|
|
|
|
|
|
} // namespace j6::proto::sl
|
|
#endif // __j6kernel
|