[yellowstone] Add yellowstone server for endpoint registration.

This commit is contained in:
Drew Galbraith 2023-06-22 02:19:16 -07:00
parent 8dcb1ddabd
commit a46694d0f7
13 changed files with 248 additions and 31 deletions

View file

@ -12,6 +12,8 @@ class EndpointClient {
template <typename Req, typename Resp>
glcr::ErrorOr<glcr::Pair<Resp, z_cap_t>> CallEndpoint(const Req& req);
z_cap_t GetCap() { return cap_; }
private:
EndpointClient(uint64_t cap) : cap_(cap) {}
z_cap_t cap_;

View file

@ -1,17 +1,27 @@
#pragma once
#include <glacier/status/error_or.h>
#include <glacier/string/string.h>
#include <stdint.h>
#include <zcall.h>
// FIXME: Split send and receive.
class Port {
public:
static glcr::ErrorOr<Port> Create();
Port(uint64_t port_cap);
glcr::ErrorCode RecvCap(uint64_t* num_bytes, char* msg, uint64_t* cap);
z_err_t PollForIntCap(uint64_t* msg, uint64_t* cap);
template <typename T>
z_err_t WriteMessage(const T& obj, uint64_t cap);
glcr::ErrorCode WriteString(glcr::String str, uint64_t cap);
// FIXME: We can't create error_ors of ints
glcr::ErrorCode Duplicate(uint64_t* new_cap);
private:
uint64_t port_cap_;
};

View file

@ -1,8 +1,9 @@
#pragma once
#include <glacier/status/error_or.h>
#include <glacier/status/error.h>
#include <stdint.h>
#include "mammoth/endpoint_client.h"
glcr::ErrorOr<EndpointClient> SpawnProcessFromElfRegion(uint64_t program);
glcr::ErrorCode SpawnProcessFromElfRegion(uint64_t program,
EndpointClient client);

View file

@ -5,8 +5,23 @@
#include "mammoth/debug.h"
glcr::ErrorOr<Port> Port::Create() {
z_cap_t port;
RET_ERR(ZPortCreate(&port));
return Port(port);
}
Port::Port(uint64_t port_cap) : port_cap_(port_cap) {}
glcr::ErrorCode Port::RecvCap(uint64_t *num_bytes, char *msg, uint64_t *cap) {
uint64_t caps = 1;
RET_ERR(ZPortRecv(port_cap_, num_bytes, reinterpret_cast<uint8_t *>(msg),
&caps, cap));
if (caps != 1) {
return glcr::FAILED_PRECONDITION;
}
return glcr::OK;
}
z_err_t Port::PollForIntCap(uint64_t *msg, uint64_t *cap) {
uint64_t bytes = sizeof(uint64_t);
uint64_t caps = 1;
@ -21,3 +36,10 @@ z_err_t Port::PollForIntCap(uint64_t *msg, uint64_t *cap) {
}
return glcr::OK;
}
glcr::ErrorCode Port::WriteString(glcr::String str, uint64_t cap) {
return ZPortSend(port_cap_, str.length() + 1, str.cstr(), 1, &cap);
}
glcr::ErrorCode Port::Duplicate(uint64_t *new_cap) {
return ZCapDuplicate(port_cap_, new_cap);
}

View file

@ -95,10 +95,8 @@ uint64_t LoadElfProgram(uint64_t base, uint64_t as_cap) {
} // namespace
glcr::ErrorOr<EndpointClient> SpawnProcessFromElfRegion(uint64_t program) {
ASSIGN_OR_RETURN(EndpointServer server, EndpointServer::Create());
ASSIGN_OR_RETURN(EndpointClient client, server.CreateClient());
glcr::ErrorCode SpawnProcessFromElfRegion(uint64_t program,
EndpointClient client) {
uint64_t proc_cap;
uint64_t as_cap;
uint64_t foreign_port_id;
@ -114,8 +112,8 @@ glcr::ErrorOr<EndpointClient> SpawnProcessFromElfRegion(uint64_t program) {
#if MAM_PROC_DEBUG
dbgln("Spawn");
#endif
check(ZProcessSpawn(gSelfProcCap, port_cap_donate, &proc_cap, &as_cap,
&foreign_port_id));
RET_ERR(ZProcessSpawn(gSelfProcCap, port_cap_donate, &proc_cap, &as_cap,
&foreign_port_id));
uint64_t entry_point = LoadElfProgram(program, as_cap);
@ -123,17 +121,17 @@ glcr::ErrorOr<EndpointClient> SpawnProcessFromElfRegion(uint64_t program) {
dbgln("Thread Create");
#endif
uint64_t thread_cap;
check(ZThreadCreate(proc_cap, &thread_cap));
RET_ERR(ZThreadCreate(proc_cap, &thread_cap));
Port p(port_cap);
check(p.WriteMessage<uint64_t>(Z_INIT_SELF_PROC, proc_cap));
check(p.WriteMessage<uint64_t>(Z_INIT_SELF_VMAS, as_cap));
check(p.WriteMessage<uint64_t>(Z_INIT_ENDPOINT, server.GetCap()));
RET_ERR(p.WriteMessage<uint64_t>(Z_INIT_SELF_PROC, proc_cap));
RET_ERR(p.WriteMessage<uint64_t>(Z_INIT_SELF_VMAS, as_cap));
RET_ERR(p.WriteMessage<uint64_t>(Z_INIT_ENDPOINT, client.GetCap()));
#if MAM_PROC_DEBUG
dbgln("Thread start");
#endif
check(ZThreadStart(thread_cap, entry_point, foreign_port_id, 0));
RET_ERR(ZThreadStart(thread_cap, entry_point, foreign_port_id, 0));
return client;
return glcr::OK;
}