[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:
parent
96a2f74e14
commit
ad7794c694
|
@ -3,6 +3,7 @@
|
|||
#include <glacier/string/str_split.h>
|
||||
#include <victoriafalls/victoriafalls.yunq.client.h>
|
||||
#include <yellowstone/yellowstone.yunq.client.h>
|
||||
#include <zcall.h>
|
||||
#include <zglobal.h>
|
||||
|
||||
#include "util/debug.h"
|
||||
|
@ -14,7 +15,11 @@ VFSClient* gVfsClient = nullptr;
|
|||
|
||||
void GetVfsClientIfNeeded() {
|
||||
if (gVfsClient == nullptr) {
|
||||
YellowstoneClient client(gInitEndpointCap);
|
||||
// TODO: Add an unowned client so we don't have to duplicate this cap every
|
||||
// time.
|
||||
uint64_t dup_cap;
|
||||
check(ZCapDuplicate(gInitEndpointCap, kZionPerm_All, &dup_cap));
|
||||
YellowstoneClient client(dup_cap);
|
||||
|
||||
GetEndpointRequest yreq;
|
||||
yreq.set_endpoint_name("victoriafalls");
|
||||
|
|
|
@ -24,7 +24,9 @@ KeyboardListenerBase::KeyboardListenerBase() {
|
|||
}
|
||||
|
||||
void KeyboardListenerBase::Register() {
|
||||
YellowstoneClient client(gInitEndpointCap);
|
||||
uint64_t dup_cap;
|
||||
check(ZCapDuplicate(gInitEndpointCap, kZionPerm_All, &dup_cap));
|
||||
YellowstoneClient client(dup_cap);
|
||||
|
||||
GetEndpointRequest req;
|
||||
req.set_endpoint_name("voyageurs");
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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_; }
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -17,6 +17,7 @@ class DenaliServerBase {
|
|||
DenaliServerBase(DenaliServerBase&&) = delete;
|
||||
virtual ~DenaliServerBase();
|
||||
|
||||
glcr::ErrorOr<z_cap_t> CreateClientCap();
|
||||
glcr::ErrorOr<DenaliClient> CreateClient();
|
||||
|
||||
[[nodiscard]] Thread RunServer();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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_; }
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -17,6 +17,7 @@ class VFSServerBase {
|
|||
VFSServerBase(VFSServerBase&&) = delete;
|
||||
virtual ~VFSServerBase();
|
||||
|
||||
glcr::ErrorOr<z_cap_t> CreateClientCap();
|
||||
glcr::ErrorOr<VFSClient> CreateClient();
|
||||
|
||||
[[nodiscard]] Thread RunServer();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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_; }
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -17,6 +17,7 @@ class VoyageursServerBase {
|
|||
VoyageursServerBase(VoyageursServerBase&&) = delete;
|
||||
virtual ~VoyageursServerBase();
|
||||
|
||||
glcr::ErrorOr<z_cap_t> CreateClientCap();
|
||||
glcr::ErrorOr<VoyageursClient> CreateClient();
|
||||
|
||||
[[nodiscard]] Thread RunServer();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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_; }
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -17,6 +17,7 @@ class YellowstoneServerBase {
|
|||
YellowstoneServerBase(YellowstoneServerBase&&) = delete;
|
||||
virtual ~YellowstoneServerBase();
|
||||
|
||||
glcr::ErrorOr<z_cap_t> CreateClientCap();
|
||||
glcr::ErrorOr<YellowstoneClient> CreateClient();
|
||||
|
||||
[[nodiscard]] Thread RunServer();
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -3,9 +3,17 @@
|
|||
|
||||
#include <glacier/buffer/byte_buffer.h>
|
||||
#include <glacier/buffer/cap_buffer.h>
|
||||
#include <mammoth/util/debug.h>
|
||||
#include <zcall.h>
|
||||
|
||||
{% for interface in interfaces %}
|
||||
|
||||
{{interface.name}}Client::~{{interface.name}}Client() {
|
||||
if (endpoint_ != 0) {
|
||||
check(ZCapRelease(endpoint_));
|
||||
}
|
||||
}
|
||||
|
||||
{% for method in interface.methods %}
|
||||
|
||||
{% if method.request == None %}
|
||||
|
|
|
@ -14,6 +14,7 @@ class {{interface.name}}Client {
|
|||
{{interface.name}}Client(z_cap_t {{interface.name}}_cap) : endpoint_({{interface.name}}_cap) {}
|
||||
{{interface.name}}Client(const {{interface.name}}Client&) = delete;
|
||||
{{interface.name}}Client({{interface.name}}Client&& other) : endpoint_(other.endpoint_) {other.endpoint_ = 0;};
|
||||
~{{interface.name}}Client();
|
||||
|
||||
z_cap_t Capability() { return endpoint_; }
|
||||
|
||||
|
|
|
@ -35,6 +35,12 @@ void {{interface.name}}ServerBaseThreadBootstrap(void* server_base) {
|
|||
}
|
||||
}
|
||||
|
||||
glcr::ErrorOr<z_cap_t> {{interface.name}}ServerBase::CreateClientCap() {
|
||||
uint64_t client_cap;
|
||||
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));
|
||||
return client_cap;
|
||||
}
|
||||
|
||||
glcr::ErrorOr<{{interface.name}}Client> {{interface.name}}ServerBase::CreateClient() {
|
||||
uint64_t client_cap;
|
||||
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));
|
||||
|
|
|
@ -17,6 +17,7 @@ class {{interface.name}}ServerBase {
|
|||
{{interface.name}}ServerBase({{interface.name}}ServerBase&&) = delete;
|
||||
virtual ~{{interface.name}}ServerBase();
|
||||
|
||||
glcr::ErrorOr<z_cap_t> CreateClientCap();
|
||||
glcr::ErrorOr<{{interface.name}}Client> CreateClient();
|
||||
|
||||
[[nodiscard]] Thread RunServer();
|
||||
|
|
Loading…
Reference in New Issue