[yellowstone] Add yellowstone server for endpoint registration.
This commit is contained in:
parent
8dcb1ddabd
commit
a46694d0f7
13 changed files with 248 additions and 31 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue