[all] Add stub for new Endpoint kernel object
This commit is contained in:
parent
1f7a15eed4
commit
69501bfe01
15 changed files with 144 additions and 38 deletions
37
lib/mammoth/include/mammoth/endpoint_client.h
Normal file
37
lib/mammoth/include/mammoth/endpoint_client.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/container/pair.h>
|
||||
#include <glacier/status/error_or.h>
|
||||
#include <zcall.h>
|
||||
#include <ztypes.h>
|
||||
|
||||
class EndpointClient {
|
||||
public:
|
||||
static EndpointClient AdoptEndpoint(z_cap_t cap);
|
||||
|
||||
template <typename Req, typename Resp>
|
||||
glcr::ErrorOr<glcr::Pair<Resp, z_cap_t>> CallEndpoint(const Req& req);
|
||||
|
||||
private:
|
||||
EndpointClient(uint64_t cap) : cap_(cap) {}
|
||||
z_cap_t cap_;
|
||||
};
|
||||
|
||||
template <typename Req, typename Resp>
|
||||
glcr::ErrorOr<glcr::Pair<Resp, z_cap_t>> EndpointClient::CallEndpoint(
|
||||
const Req& req) {
|
||||
uint64_t reply_port_cap;
|
||||
RET_ERR(ZEndpointSend(cap_, sizeof(Req), &req, &reply_port_cap));
|
||||
|
||||
Resp resp;
|
||||
z_cap_t cap = 0;
|
||||
uint64_t num_caps = 1;
|
||||
uint64_t num_bytes = sizeof(Resp);
|
||||
RET_ERR(ZReplyPortRecv(reply_port_cap, &num_bytes, &resp, &num_caps, &cap));
|
||||
|
||||
if (num_bytes != sizeof(resp) || num_caps != 1) {
|
||||
return glcr::FAILED_PRECONDITION;
|
||||
}
|
||||
|
||||
return glcr::Pair{resp, cap};
|
||||
}
|
||||
22
lib/mammoth/include/mammoth/endpoint_server.h
Normal file
22
lib/mammoth/include/mammoth/endpoint_server.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/status/error_or.h>
|
||||
#include <ztypes.h>
|
||||
|
||||
#include "mammoth/endpoint_client.h"
|
||||
|
||||
class EndpointServer {
|
||||
public:
|
||||
static glcr::ErrorOr<EndpointServer> Create();
|
||||
static EndpointServer Adopt(z_cap_t endpoint_cap);
|
||||
|
||||
glcr::ErrorOr<EndpointClient> CreateClient();
|
||||
|
||||
// FIXME: Release Cap here.
|
||||
z_cap_t GetCap() { return endpoint_cap_; }
|
||||
|
||||
private:
|
||||
z_cap_t endpoint_cap_;
|
||||
|
||||
EndpointServer(z_cap_t cap) : endpoint_cap_(cap) {}
|
||||
};
|
||||
|
|
@ -3,6 +3,6 @@
|
|||
#include <glacier/status/error_or.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "mammoth/channel.h"
|
||||
#include "mammoth/endpoint_client.h"
|
||||
|
||||
glcr::ErrorOr<Channel> SpawnProcessFromElfRegion(uint64_t program);
|
||||
glcr::ErrorOr<EndpointClient> SpawnProcessFromElfRegion(uint64_t program);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue