[mammoth] Move EndpointClient to move-only semantics.

This commit is contained in:
Drew Galbraith 2023-06-26 11:54:36 -07:00
parent 2e89aee5a3
commit 90f33f31c5
15 changed files with 44 additions and 30 deletions

View file

@ -1,13 +1,18 @@
#pragma once
#include <glacier/container/pair.h>
#include <glacier/memory/unique_ptr.h>
#include <glacier/status/error_or.h>
#include <zcall.h>
#include <ztypes.h>
class EndpointClient {
public:
static EndpointClient AdoptEndpoint(z_cap_t cap);
EndpointClient() = delete;
EndpointClient(const EndpointClient&) = delete;
EndpointClient& operator=(const EndpointClient&) = delete;
static glcr::UniquePtr<EndpointClient> AdoptEndpoint(z_cap_t cap);
template <typename Req, typename Resp>
glcr::ErrorOr<glcr::Pair<Resp, z_cap_t>> CallEndpoint(const Req& req);

View file

@ -15,7 +15,7 @@ class EndpointServer {
static glcr::ErrorOr<glcr::UniquePtr<EndpointServer>> Create();
static glcr::UniquePtr<EndpointServer> Adopt(z_cap_t endpoint_cap);
glcr::ErrorOr<EndpointClient> CreateClient();
glcr::ErrorOr<glcr::UniquePtr<EndpointClient>> CreateClient();
// FIXME: Release Cap here.
z_cap_t GetCap() { return endpoint_cap_; }

View file

@ -5,5 +5,5 @@
#include "mammoth/endpoint_client.h"
glcr::ErrorCode SpawnProcessFromElfRegion(uint64_t program,
EndpointClient client);
glcr::ErrorCode SpawnProcessFromElfRegion(
uint64_t program, glcr::UniquePtr<EndpointClient> client);

View file

@ -1,3 +1,5 @@
#include "mammoth/endpoint_server.h"
EndpointClient EndpointClient::AdoptEndpoint(z_cap_t cap) { return {cap}; }
glcr::UniquePtr<EndpointClient> EndpointClient::AdoptEndpoint(z_cap_t cap) {
return glcr::UniquePtr<EndpointClient>(new EndpointClient(cap));
}

View file

@ -10,7 +10,7 @@ glcr::UniquePtr<EndpointServer> EndpointServer::Adopt(z_cap_t endpoint_cap) {
return glcr::UniquePtr<EndpointServer>(new EndpointServer(endpoint_cap));
}
glcr::ErrorOr<EndpointClient> EndpointServer::CreateClient() {
glcr::ErrorOr<glcr::UniquePtr<EndpointClient>> EndpointServer::CreateClient() {
uint64_t client_cap;
// FIXME: Restrict permissions to send-only here.
RET_ERR(ZCapDuplicate(endpoint_cap_, &client_cap));

View file

@ -96,8 +96,8 @@ uint64_t LoadElfProgram(uint64_t base, uint64_t as_cap) {
} // namespace
glcr::ErrorCode SpawnProcessFromElfRegion(uint64_t program,
EndpointClient client) {
glcr::ErrorCode SpawnProcessFromElfRegion(
uint64_t program, glcr::UniquePtr<EndpointClient> client) {
uint64_t proc_cap;
uint64_t as_cap;
uint64_t foreign_port_id;
@ -125,7 +125,7 @@ glcr::ErrorCode SpawnProcessFromElfRegion(uint64_t program,
RET_ERR(pclient.WriteMessage<uint64_t>(Z_INIT_SELF_PROC, proc_cap));
RET_ERR(pclient.WriteMessage<uint64_t>(Z_INIT_SELF_VMAS, as_cap));
RET_ERR(pclient.WriteMessage<uint64_t>(Z_INIT_ENDPOINT, client.GetCap()));
RET_ERR(pclient.WriteMessage<uint64_t>(Z_INIT_ENDPOINT, client->GetCap()));
#if MAM_PROC_DEBUG
dbgln("Thread start");