[Yunq] Delete client capability in destructor.

Add a method to the server class to create an unowned capability. This
makes it simpler to create a capability for passing to other processes.

Duplicate the init yellowstone cap when using it temporarily.
This commit is contained in:
Drew Galbraith 2023-11-27 08:28:58 -08:00
parent 96a2f74e14
commit ad7794c694
24 changed files with 98 additions and 9 deletions

View file

@ -3,10 +3,18 @@
#include <glacier/buffer/byte_buffer.h>
#include <glacier/buffer/cap_buffer.h>
#include <mammoth/util/debug.h>
#include <zcall.h>
DenaliClient::~DenaliClient() {
if (endpoint_ != 0) {
check(ZCapRelease(endpoint_));
}
}
glcr::ErrorCode DenaliClient::Read(const ReadRequest& request, ReadResponse& response) {

View file

@ -13,6 +13,7 @@ class DenaliClient {
DenaliClient(z_cap_t Denali_cap) : endpoint_(Denali_cap) {}
DenaliClient(const DenaliClient&) = delete;
DenaliClient(DenaliClient&& other) : endpoint_(other.endpoint_) {other.endpoint_ = 0;};
~DenaliClient();
z_cap_t Capability() { return endpoint_; }

View file

@ -35,6 +35,12 @@ DenaliServerBase::~DenaliServerBase() {
}
}
glcr::ErrorOr<z_cap_t> DenaliServerBase::CreateClientCap() {
uint64_t client_cap;
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));
return client_cap;
}
glcr::ErrorOr<DenaliClient> DenaliServerBase::CreateClient() {
uint64_t client_cap;
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));

View file

@ -17,6 +17,7 @@ class DenaliServerBase {
DenaliServerBase(DenaliServerBase&&) = delete;
virtual ~DenaliServerBase();
glcr::ErrorOr<z_cap_t> CreateClientCap();
glcr::ErrorOr<DenaliClient> CreateClient();
[[nodiscard]] Thread RunServer();

View file

@ -3,10 +3,18 @@
#include <glacier/buffer/byte_buffer.h>
#include <glacier/buffer/cap_buffer.h>
#include <mammoth/util/debug.h>
#include <zcall.h>
VFSClient::~VFSClient() {
if (endpoint_ != 0) {
check(ZCapRelease(endpoint_));
}
}
glcr::ErrorCode VFSClient::OpenFile(const OpenFileRequest& request, OpenFileResponse& response) {

View file

@ -13,6 +13,7 @@ class VFSClient {
VFSClient(z_cap_t VFS_cap) : endpoint_(VFS_cap) {}
VFSClient(const VFSClient&) = delete;
VFSClient(VFSClient&& other) : endpoint_(other.endpoint_) {other.endpoint_ = 0;};
~VFSClient();
z_cap_t Capability() { return endpoint_; }

View file

@ -35,6 +35,12 @@ VFSServerBase::~VFSServerBase() {
}
}
glcr::ErrorOr<z_cap_t> VFSServerBase::CreateClientCap() {
uint64_t client_cap;
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));
return client_cap;
}
glcr::ErrorOr<VFSClient> VFSServerBase::CreateClient() {
uint64_t client_cap;
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));

View file

@ -17,6 +17,7 @@ class VFSServerBase {
VFSServerBase(VFSServerBase&&) = delete;
virtual ~VFSServerBase();
glcr::ErrorOr<z_cap_t> CreateClientCap();
glcr::ErrorOr<VFSClient> CreateClient();
[[nodiscard]] Thread RunServer();

View file

@ -3,10 +3,18 @@
#include <glacier/buffer/byte_buffer.h>
#include <glacier/buffer/cap_buffer.h>
#include <mammoth/util/debug.h>
#include <zcall.h>
VoyageursClient::~VoyageursClient() {
if (endpoint_ != 0) {
check(ZCapRelease(endpoint_));
}
}
glcr::ErrorCode VoyageursClient::RegisterKeyboardListener(const KeyboardListener& request) {

View file

@ -13,6 +13,7 @@ class VoyageursClient {
VoyageursClient(z_cap_t Voyageurs_cap) : endpoint_(Voyageurs_cap) {}
VoyageursClient(const VoyageursClient&) = delete;
VoyageursClient(VoyageursClient&& other) : endpoint_(other.endpoint_) {other.endpoint_ = 0;};
~VoyageursClient();
z_cap_t Capability() { return endpoint_; }

View file

@ -35,6 +35,12 @@ VoyageursServerBase::~VoyageursServerBase() {
}
}
glcr::ErrorOr<z_cap_t> VoyageursServerBase::CreateClientCap() {
uint64_t client_cap;
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));
return client_cap;
}
glcr::ErrorOr<VoyageursClient> VoyageursServerBase::CreateClient() {
uint64_t client_cap;
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));

View file

@ -17,6 +17,7 @@ class VoyageursServerBase {
VoyageursServerBase(VoyageursServerBase&&) = delete;
virtual ~VoyageursServerBase();
glcr::ErrorOr<z_cap_t> CreateClientCap();
glcr::ErrorOr<VoyageursClient> CreateClient();
[[nodiscard]] Thread RunServer();

View file

@ -3,10 +3,18 @@
#include <glacier/buffer/byte_buffer.h>
#include <glacier/buffer/cap_buffer.h>
#include <mammoth/util/debug.h>
#include <zcall.h>
YellowstoneClient::~YellowstoneClient() {
if (endpoint_ != 0) {
check(ZCapRelease(endpoint_));
}
}
glcr::ErrorCode YellowstoneClient::RegisterEndpoint(const RegisterEndpointRequest& request) {

View file

@ -13,6 +13,7 @@ class YellowstoneClient {
YellowstoneClient(z_cap_t Yellowstone_cap) : endpoint_(Yellowstone_cap) {}
YellowstoneClient(const YellowstoneClient&) = delete;
YellowstoneClient(YellowstoneClient&& other) : endpoint_(other.endpoint_) {other.endpoint_ = 0;};
~YellowstoneClient();
z_cap_t Capability() { return endpoint_; }

View file

@ -35,6 +35,12 @@ YellowstoneServerBase::~YellowstoneServerBase() {
}
}
glcr::ErrorOr<z_cap_t> YellowstoneServerBase::CreateClientCap() {
uint64_t client_cap;
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));
return client_cap;
}
glcr::ErrorOr<YellowstoneClient> YellowstoneServerBase::CreateClient() {
uint64_t client_cap;
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));

View file

@ -17,6 +17,7 @@ class YellowstoneServerBase {
YellowstoneServerBase(YellowstoneServerBase&&) = delete;
virtual ~YellowstoneServerBase();
glcr::ErrorOr<z_cap_t> CreateClientCap();
glcr::ErrorOr<YellowstoneClient> CreateClient();
[[nodiscard]] Thread RunServer();

View file

@ -25,13 +25,13 @@ uint64_t main(uint64_t port_cap) {
ASSIGN_OR_RETURN(auto server, YellowstoneServer::Create());
Thread server_thread = server->RunServer();
ASSIGN_OR_RETURN(YellowstoneClient client1, server->CreateClient());
check(SpawnProcess(gBootDenaliVmmoCap, client1.Capability()));
ASSIGN_OR_RETURN(uint64_t client_cap, server->CreateClientCap());
check(SpawnProcess(gBootDenaliVmmoCap, client_cap));
server->WaitDenaliRegistered();
ASSIGN_OR_RETURN(YellowstoneClient client2, server->CreateClient());
check(SpawnProcess(gBootVictoriaFallsVmmoCap, client2.Capability()));
ASSIGN_OR_RETURN(client_cap, server->CreateClientCap());
check(SpawnProcess(gBootVictoriaFallsVmmoCap, client_cap));
server->WaitVictoriaFallsRegistered();
@ -47,9 +47,9 @@ uint64_t main(uint64_t port_cap) {
mmth::File binary =
mmth::File::Open(glcr::StrFormat("/bin/{}", files[i]));
ASSIGN_OR_RETURN(YellowstoneClient client3, server->CreateClient());
ASSIGN_OR_RETURN(client_cap, server->CreateClientCap());
check(mmth::SpawnProcessFromElfRegion((uint64_t)binary.raw_ptr(),
client3.Capability()));
client_cap));
}
}

View file

@ -87,7 +87,9 @@ glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint(
dbgln("Registering {}.", req.endpoint_name().view());
check(endpoint_map_.Insert(req.endpoint_name(), req.endpoint_capability()));
if (req.endpoint_name() == "denali") {
auto part_info_or = HandleDenaliRegistration(req.endpoint_capability());
z_cap_t dup_cap;
check(ZCapDuplicate(req.endpoint_capability(), kZionPerm_All, &dup_cap));
auto part_info_or = HandleDenaliRegistration(dup_cap);
if (!part_info_or.ok()) {
check(part_info_or.error());
}