Compare commits

..

No commits in common. "05e12aaa7d6ad372335ab7d39c5c43f0c2e6c017" and "5b781bb3940f44ab0adc31e4e6904d0753f1ac4d" have entirely different histories.

27 changed files with 284 additions and 358 deletions

View File

@ -13,11 +13,6 @@ class CapBuffer {
~CapBuffer() { delete[] buffer_; } ~CapBuffer() { delete[] buffer_; }
void Reset() {
// FIXME: Zero out caps here?
used_slots_ = 0;
}
uint64_t* RawPtr() { return buffer_; } uint64_t* RawPtr() { return buffer_; }
uint64_t UsedSlots() { return used_slots_; } uint64_t UsedSlots() { return used_slots_; }

View File

@ -31,7 +31,7 @@ template <typename Req, typename Resp>
glcr::ErrorOr<glcr::Pair<Resp, z_cap_t>> EndpointClient::CallEndpointGetCap( glcr::ErrorOr<glcr::Pair<Resp, z_cap_t>> EndpointClient::CallEndpointGetCap(
const Req& req) { const Req& req) {
uint64_t reply_port_cap; uint64_t reply_port_cap;
RET_ERR(ZEndpointSend(cap_, sizeof(Req), &req, 0, nullptr, &reply_port_cap)); RET_ERR(ZEndpointSend(cap_, sizeof(Req), &req, &reply_port_cap));
Resp resp; Resp resp;
z_cap_t cap = 0; z_cap_t cap = 0;
@ -49,7 +49,7 @@ glcr::ErrorOr<glcr::Pair<Resp, z_cap_t>> EndpointClient::CallEndpointGetCap(
template <typename Req, typename Resp> template <typename Req, typename Resp>
glcr::ErrorOr<Resp> EndpointClient::CallEndpoint(const Req& req) { glcr::ErrorOr<Resp> EndpointClient::CallEndpoint(const Req& req) {
uint64_t reply_port_cap; uint64_t reply_port_cap;
RET_ERR(ZEndpointSend(cap_, sizeof(Req), &req, 0, nullptr, &reply_port_cap)); RET_ERR(ZEndpointSend(cap_, sizeof(Req), &req, &reply_port_cap));
Resp resp; Resp resp;
uint64_t num_bytes = sizeof(Resp); uint64_t num_bytes = sizeof(Resp);

View File

@ -22,10 +22,8 @@ void EndpointServer::ServerThread() {
while (true) { while (true) {
uint64_t message_size = kBufferSize; uint64_t message_size = kBufferSize;
uint64_t reply_port_cap = 0; uint64_t reply_port_cap = 0;
uint64_t num_caps = 0; glcr::ErrorCode err = ZEndpointRecv(endpoint_cap_, &message_size,
glcr::ErrorCode err = recieve_buffer_, &reply_port_cap);
ZEndpointRecv(endpoint_cap_, &message_size, recieve_buffer_, &num_caps,
nullptr, &reply_port_cap);
if (err != glcr::OK) { if (err != glcr::OK) {
dbgln("Error in receive: %x", err); dbgln("Error in receive: %x", err);
continue; continue;

View File

@ -2,6 +2,8 @@
## Yellowstone ## Yellowstone
- Add registration to the base yellowstone yunq service
- Requires: Adding ability to pass capabilities in endpoint calls.
- Store registered services in a hashmap. - Store registered services in a hashmap.
- Requires: Adding hashmap to Glacier. - Requires: Adding hashmap to Glacier.
- Start the next service from a configuration file. - Start the next service from a configuration file.

View File

@ -29,12 +29,15 @@ uint64_t main(uint64_t init_port_cap) {
ASSIGN_OR_RETURN(glcr::UniquePtr<EndpointClient> client, ASSIGN_OR_RETURN(glcr::UniquePtr<EndpointClient> client,
server->CreateClient()); server->CreateClient());
Thread server_thread = server->RunServer(); RegisterInfo reg;
Empty empty2;
check(stub.GetRegister(empty2, reg));
RegisterEndpointRequest req; PortClient register_port = PortClient::AdoptPort(reg.register_port());
req.set_endpoint_name("denali");
req.set_endpoint_capability(client->GetCap()); check(register_port.WriteString("denali", client->GetCap()));
check(stub.RegisterEndpoint(req, empty));
Thread server_thread = server->RunServer();
check(server_thread.Join()); check(server_thread.Join());
return 0; return 0;

View File

@ -1,18 +1,17 @@
interface Yellowstone { interface Yellowstone {
method RegisterEndpoint(RegisterEndpointRequest) -> (Empty); method GetRegister(Empty) -> (RegisterInfo);
method GetAhciInfo(Empty) -> (AhciInfo); method GetAhciInfo(Empty) -> (AhciInfo);
method GetDenali(Empty) -> (DenaliInfo); method GetDenali(Empty) -> (DenaliInfo);
} }
message RegisterEndpointRequest {
string endpoint_name;
capability endpoint_capability;
}
message Empty { message Empty {
} }
message RegisterInfo {
capability register_port;
}
message AhciInfo { message AhciInfo {
capability ahci_region; capability ahci_region;
u64 region_length; u64 region_length;

View File

@ -8,7 +8,7 @@
glcr::ErrorCode YellowstoneClient::RegisterEndpoint(const RegisterEndpointRequest& request, Empty& response) { glcr::ErrorCode YellowstoneClient::GetRegister(const Empty& request, RegisterInfo& response) {
uint64_t buffer_size = kBufferSize; uint64_t buffer_size = kBufferSize;
uint64_t cap_size = kCapBufferSize; uint64_t cap_size = kCapBufferSize;
@ -16,12 +16,12 @@ glcr::ErrorCode YellowstoneClient::RegisterEndpoint(const RegisterEndpointReques
buffer_.WriteAt<uint32_t>(0, kSentinel); buffer_.WriteAt<uint32_t>(0, kSentinel);
buffer_.WriteAt<uint64_t>(8, 0); buffer_.WriteAt<uint64_t>(8, 0);
cap_buffer_.Reset();
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_); uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
buffer_.WriteAt<uint32_t>(4, 16 + length); buffer_.WriteAt<uint32_t>(4, 16 + length);
z_cap_t reply_port_cap; z_cap_t reply_port_cap;
RET_ERR(ZEndpointSend(endpoint_, 16 + length, buffer_.RawPtr(), cap_buffer_.UsedSlots(), cap_buffer_.RawPtr(), &reply_port_cap)); // FIXME: We need to be able to send capabilities via endpoint call.
RET_ERR(ZEndpointSend(endpoint_, 16 + length, buffer_.RawPtr(), &reply_port_cap));
// FIXME: Add a way to zero out the first buffer. // FIXME: Add a way to zero out the first buffer.
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr())); RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
@ -48,12 +48,12 @@ glcr::ErrorCode YellowstoneClient::GetAhciInfo(const Empty& request, AhciInfo& r
buffer_.WriteAt<uint32_t>(0, kSentinel); buffer_.WriteAt<uint32_t>(0, kSentinel);
buffer_.WriteAt<uint64_t>(8, 1); buffer_.WriteAt<uint64_t>(8, 1);
cap_buffer_.Reset();
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_); uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
buffer_.WriteAt<uint32_t>(4, 16 + length); buffer_.WriteAt<uint32_t>(4, 16 + length);
z_cap_t reply_port_cap; z_cap_t reply_port_cap;
RET_ERR(ZEndpointSend(endpoint_, 16 + length, buffer_.RawPtr(), cap_buffer_.UsedSlots(), cap_buffer_.RawPtr(), &reply_port_cap)); // FIXME: We need to be able to send capabilities via endpoint call.
RET_ERR(ZEndpointSend(endpoint_, 16 + length, buffer_.RawPtr(), &reply_port_cap));
// FIXME: Add a way to zero out the first buffer. // FIXME: Add a way to zero out the first buffer.
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr())); RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
@ -80,12 +80,12 @@ glcr::ErrorCode YellowstoneClient::GetDenali(const Empty& request, DenaliInfo& r
buffer_.WriteAt<uint32_t>(0, kSentinel); buffer_.WriteAt<uint32_t>(0, kSentinel);
buffer_.WriteAt<uint64_t>(8, 2); buffer_.WriteAt<uint64_t>(8, 2);
cap_buffer_.Reset();
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_); uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
buffer_.WriteAt<uint32_t>(4, 16 + length); buffer_.WriteAt<uint32_t>(4, 16 + length);
z_cap_t reply_port_cap; z_cap_t reply_port_cap;
RET_ERR(ZEndpointSend(endpoint_, 16 + length, buffer_.RawPtr(), cap_buffer_.UsedSlots(), cap_buffer_.RawPtr(), &reply_port_cap)); // FIXME: We need to be able to send capabilities via endpoint call.
RET_ERR(ZEndpointSend(endpoint_, 16 + length, buffer_.RawPtr(), &reply_port_cap));
// FIXME: Add a way to zero out the first buffer. // FIXME: Add a way to zero out the first buffer.
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr())); RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));

View File

@ -17,7 +17,7 @@ class YellowstoneClient {
z_cap_t Capability() { return endpoint_; } z_cap_t Capability() { return endpoint_; }
[[nodiscard]] glcr::ErrorCode RegisterEndpoint(const RegisterEndpointRequest& request, Empty& response); [[nodiscard]] glcr::ErrorCode GetRegister(const Empty& request, RegisterInfo& response);
[[nodiscard]] glcr::ErrorCode GetAhciInfo(const Empty& request, AhciInfo& response); [[nodiscard]] glcr::ErrorCode GetAhciInfo(const Empty& request, AhciInfo& response);

View File

@ -27,77 +27,6 @@ void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size, u
} }
} // namespace } // namespace
void RegisterEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
CheckHeader(bytes);
// Parse endpoint_name.
auto endpoint_name_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
set_endpoint_name(bytes.StringAt(offset + endpoint_name_pointer.offset, endpoint_name_pointer.length));
// Parse endpoint_capability.
// FIXME: Implement in-buffer capabilities for inprocess serialization.
set_endpoint_capability(0);
}
void RegisterEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
CheckHeader(bytes);
// Parse endpoint_name.
auto endpoint_name_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
set_endpoint_name(bytes.StringAt(offset + endpoint_name_pointer.offset, endpoint_name_pointer.length));
// Parse endpoint_capability.
uint64_t endpoint_capability_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 1));
set_endpoint_capability(caps.At(endpoint_capability_ptr));
}
uint64_t RegisterEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
uint32_t next_extension = header_size + 8 * 2;
const uint32_t core_size = next_extension;
// Write endpoint_name.
ExtPointer endpoint_name_ptr{
.offset = next_extension,
// FIXME: Check downcast of str length.
.length = (uint32_t)endpoint_name().length(),
};
bytes.WriteStringAt(offset + next_extension, endpoint_name());
next_extension += endpoint_name_ptr.length;
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), endpoint_name_ptr);
// Write endpoint_capability.
// FIXME: Implement inbuffer capabilities.
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), 0);
// The next extension pointer is the length of the message.
WriteHeader(bytes, offset, core_size, next_extension);
return next_extension;
}
uint64_t RegisterEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
uint32_t next_extension = header_size + 8 * 2;
const uint32_t core_size = next_extension;
uint64_t next_cap = 0;
// Write endpoint_name.
ExtPointer endpoint_name_ptr{
.offset = next_extension,
// FIXME: Check downcast of str length.
.length = (uint32_t)endpoint_name().length(),
};
bytes.WriteStringAt(offset + next_extension, endpoint_name());
next_extension += endpoint_name_ptr.length;
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), endpoint_name_ptr);
// Write endpoint_capability.
caps.WriteAt(next_cap, endpoint_capability());
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), next_cap++);
// The next extension pointer is the length of the message.
WriteHeader(bytes, offset, core_size, next_extension);
return next_extension;
}
void Empty::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { void Empty::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
CheckHeader(bytes); CheckHeader(bytes);
} }
@ -126,6 +55,47 @@ uint64_t Empty::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr:
return next_extension; return next_extension;
} }
void RegisterInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
CheckHeader(bytes);
// Parse register_port.
// FIXME: Implement in-buffer capabilities for inprocess serialization.
set_register_port(0);
}
void RegisterInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
CheckHeader(bytes);
// Parse register_port.
uint64_t register_port_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 0));
set_register_port(caps.At(register_port_ptr));
}
uint64_t RegisterInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
uint32_t next_extension = header_size + 8 * 1;
const uint32_t core_size = next_extension;
// Write register_port.
// FIXME: Implement inbuffer capabilities.
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), 0);
// The next extension pointer is the length of the message.
WriteHeader(bytes, offset, core_size, next_extension);
return next_extension;
}
uint64_t RegisterInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const {
uint32_t next_extension = header_size + 8 * 1;
const uint32_t core_size = next_extension;
uint64_t next_cap = 0;
// Write register_port.
caps.WriteAt(next_cap, register_port());
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), next_cap++);
// The next extension pointer is the length of the message.
WriteHeader(bytes, offset, core_size, next_extension);
return next_extension;
}
void AhciInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) { void AhciInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
CheckHeader(bytes); CheckHeader(bytes);
// Parse ahci_region. // Parse ahci_region.

View File

@ -5,27 +5,6 @@
#include <glacier/buffer/cap_buffer.h> #include <glacier/buffer/cap_buffer.h>
#include <glacier/string/string.h> #include <glacier/string/string.h>
#include <ztypes.h> #include <ztypes.h>
class RegisterEndpointRequest {
public:
RegisterEndpointRequest() {}
// Delete copy and move until implemented.
RegisterEndpointRequest(const RegisterEndpointRequest&) = delete;
RegisterEndpointRequest(RegisterEndpointRequest&&) = delete;
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
glcr::String endpoint_name() const { return endpoint_name_; }
void set_endpoint_name(const glcr::String& value) { endpoint_name_ = value; }
z_cap_t endpoint_capability() const { return endpoint_capability_; }
void set_endpoint_capability(const z_cap_t& value) { endpoint_capability_ = value; }
private:
glcr::String endpoint_name_;
z_cap_t endpoint_capability_;
};
class Empty { class Empty {
public: public:
Empty() {} Empty() {}
@ -40,6 +19,24 @@ class Empty {
private: private:
};
class RegisterInfo {
public:
RegisterInfo() {}
// Delete copy and move until implemented.
RegisterInfo(const RegisterInfo&) = delete;
RegisterInfo(RegisterInfo&&) = delete;
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
z_cap_t register_port() const { return register_port_; }
void set_register_port(const z_cap_t& value) { register_port_ = value; }
private:
z_cap_t register_port_;
}; };
class AhciInfo { class AhciInfo {
public: public:

View File

@ -42,15 +42,14 @@ Thread YellowstoneServerBase::RunServer() {
void YellowstoneServerBase::ServerThread() { void YellowstoneServerBase::ServerThread() {
glcr::ByteBuffer recv_buffer(0x1000); glcr::ByteBuffer recv_buffer(0x1000);
glcr::CapBuffer recv_cap(0x10);
glcr::ByteBuffer resp_buffer(0x1000); glcr::ByteBuffer resp_buffer(0x1000);
glcr::CapBuffer resp_cap(0x10); uint64_t resp_cap_size = 0x10;
glcr::CapBuffer resp_cap(resp_cap_size);
z_cap_t reply_port_cap; z_cap_t reply_port_cap;
while (true) { while (true) {
uint64_t recv_cap_size = 0x10;
uint64_t recv_buf_size = 0x1000; uint64_t recv_buf_size = 0x1000;
glcr::ErrorCode recv_err = ZEndpointRecv(endpoint_, &recv_buf_size, recv_buffer.RawPtr(), &recv_cap_size, recv_cap.RawPtr(), &reply_port_cap); glcr::ErrorCode recv_err = ZEndpointRecv(endpoint_, &recv_buf_size, recv_buffer.RawPtr(), &reply_port_cap);
if (recv_err != glcr::OK) { if (recv_err != glcr::OK) {
dbgln("Error in receive: %x", recv_err); dbgln("Error in receive: %x", recv_err);
continue; continue;
@ -59,7 +58,7 @@ void YellowstoneServerBase::ServerThread() {
uint64_t resp_length = 0; uint64_t resp_length = 0;
glcr::ErrorCode reply_err = glcr::OK; glcr::ErrorCode reply_err = glcr::OK;
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap); glcr::ErrorCode err = HandleRequest(recv_buffer, resp_buffer, resp_length, resp_cap);
if (err != glcr::OK) { if (err != glcr::OK) {
WriteError(resp_buffer, err); WriteError(resp_buffer, err);
reply_err = ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr); reply_err = ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr);
@ -75,7 +74,6 @@ void YellowstoneServerBase::ServerThread() {
} }
glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& request, glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& request,
const glcr::CapBuffer& req_caps,
glcr::ByteBuffer& response, uint64_t& resp_length, glcr::ByteBuffer& response, uint64_t& resp_length,
glcr::CapBuffer& resp_caps) { glcr::CapBuffer& resp_caps) {
if (request.At<uint32_t>(0) != kSentinel) { if (request.At<uint32_t>(0) != kSentinel) {
@ -86,12 +84,12 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
switch(method_select) { switch(method_select) {
case 0: { case 0: {
RegisterEndpointRequest yunq_request; Empty yunq_request;
Empty yunq_response; RegisterInfo yunq_response;
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps); yunq_request.ParseFromBytes(request, kHeaderSize);
RET_ERR(HandleRegisterEndpoint(yunq_request, yunq_response)); RET_ERR(HandleGetRegister(yunq_request, yunq_response));
resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps); resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps);
break; break;
@ -100,7 +98,7 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
Empty yunq_request; Empty yunq_request;
AhciInfo yunq_response; AhciInfo yunq_response;
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps); yunq_request.ParseFromBytes(request, kHeaderSize);
RET_ERR(HandleGetAhciInfo(yunq_request, yunq_response)); RET_ERR(HandleGetAhciInfo(yunq_request, yunq_response));
@ -111,7 +109,7 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
Empty yunq_request; Empty yunq_request;
DenaliInfo yunq_response; DenaliInfo yunq_response;
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps); yunq_request.ParseFromBytes(request, kHeaderSize);
RET_ERR(HandleGetDenali(yunq_request, yunq_response)); RET_ERR(HandleGetDenali(yunq_request, yunq_response));

View File

@ -21,7 +21,7 @@ class YellowstoneServerBase {
[[nodiscard]] Thread RunServer(); [[nodiscard]] Thread RunServer();
[[nodiscard]] virtual glcr::ErrorCode HandleRegisterEndpoint(const RegisterEndpointRequest&, Empty&) = 0; [[nodiscard]] virtual glcr::ErrorCode HandleGetRegister(const Empty&, RegisterInfo&) = 0;
[[nodiscard]] virtual glcr::ErrorCode HandleGetAhciInfo(const Empty&, AhciInfo&) = 0; [[nodiscard]] virtual glcr::ErrorCode HandleGetAhciInfo(const Empty&, AhciInfo&) = 0;
@ -34,8 +34,8 @@ class YellowstoneServerBase {
friend void YellowstoneServerBaseThreadBootstrap(void*); friend void YellowstoneServerBaseThreadBootstrap(void*);
void ServerThread(); void ServerThread();
[[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps, [[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, glcr::ByteBuffer& response,
glcr::ByteBuffer& response, uint64_t& resp_length, uint64_t& resp_length,
glcr::CapBuffer& resp_caps); glcr::CapBuffer& resp_caps);
}; };

View File

@ -13,6 +13,7 @@ uint64_t main(uint64_t port_cap) {
check(ParseInitPort(port_cap)); check(ParseInitPort(port_cap));
ASSIGN_OR_RETURN(auto server, YellowstoneServer::Create()); ASSIGN_OR_RETURN(auto server, YellowstoneServer::Create());
Thread registration_thread = server->RunRegistration();
Thread server_thread = server->RunServer(); Thread server_thread = server->RunServer();
uint64_t vaddr; uint64_t vaddr;
@ -21,6 +22,7 @@ uint64_t main(uint64_t port_cap) {
check(SpawnProcessFromElfRegion(vaddr, client.Capability())); check(SpawnProcessFromElfRegion(vaddr, client.Capability()));
check(server_thread.Join()); check(server_thread.Join());
check(registration_thread.Join());
dbgln("Yellowstone Finished Successfully."); dbgln("Yellowstone Finished Successfully.");
return 0; return 0;
} }

View File

@ -13,6 +13,11 @@
namespace { namespace {
void RegistrationThreadBootstrap(void* yellowstone) {
dbgln("Yellowstone registration starting");
static_cast<YellowstoneServer*>(yellowstone)->RegistrationThread();
}
struct PartitionInfo { struct PartitionInfo {
uint64_t device_id; uint64_t device_id;
uint64_t partition_lba; uint64_t partition_lba;
@ -33,11 +38,16 @@ glcr::ErrorOr<PartitionInfo> HandleDenaliRegistration(z_cap_t endpoint_cap) {
glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> YellowstoneServer::Create() { glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> YellowstoneServer::Create() {
z_cap_t cap; z_cap_t cap;
RET_ERR(ZEndpointCreate(&cap)); RET_ERR(ZEndpointCreate(&cap));
return glcr::UniquePtr<YellowstoneServer>(new YellowstoneServer(cap)); ASSIGN_OR_RETURN(PortServer port, PortServer::Create());
return glcr::UniquePtr<YellowstoneServer>(new YellowstoneServer(cap, port));
} }
YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap) YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap, PortServer port)
: YellowstoneServerBase(endpoint_cap) {} : YellowstoneServerBase(endpoint_cap), register_port_(port) {}
Thread YellowstoneServer::RunRegistration() {
return Thread(RegistrationThreadBootstrap, this);
}
glcr::ErrorCode YellowstoneServer::HandleGetAhciInfo(const Empty&, glcr::ErrorCode YellowstoneServer::HandleGetAhciInfo(const Empty&,
AhciInfo& info) { AhciInfo& info) {
@ -55,12 +65,27 @@ glcr::ErrorCode YellowstoneServer::HandleGetDenali(const Empty&,
info.set_lba_offset(lba_offset_); info.set_lba_offset(lba_offset_);
return glcr::OK; return glcr::OK;
} }
glcr::ErrorCode YellowstoneServer::HandleGetRegister(const Empty&,
RegisterInfo& info) {
auto client_or = register_port_.CreateClient();
if (!client_or.ok()) {
dbgln("Error creating register client: %u", client_or.error());
return glcr::INTERNAL;
}
info.set_register_port(client_or.value().cap());
return glcr::OK;
}
glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint( void YellowstoneServer::RegistrationThread() {
const RegisterEndpointRequest& req, Empty&) { while (true) {
dbgln("Registering."); uint64_t num_bytes = kBufferSize;
if (req.endpoint_name() == "denali") { z_cap_t endpoint_cap;
denali_cap_ = req.endpoint_capability(); // FIXME: Better error handling here.
check(register_port_.RecvCap(&num_bytes, registration_buffer_,
&endpoint_cap));
glcr::String name(registration_buffer_);
if (name == "denali") {
denali_cap_ = endpoint_cap;
auto part_info_or = HandleDenaliRegistration(denali_cap_); auto part_info_or = HandleDenaliRegistration(denali_cap_);
if (!part_info_or.ok()) { if (!part_info_or.ok()) {
check(part_info_or.error()); check(part_info_or.error());
@ -69,16 +94,22 @@ glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint(
lba_offset_ = part_info_or.value().partition_lba; lba_offset_ = part_info_or.value().partition_lba;
uint64_t vaddr; uint64_t vaddr;
check(ZAddressSpaceMap(gSelfVmasCap, 0, gBootVictoriaFallsVmmoCap, &vaddr)); check(
ZAddressSpaceMap(gSelfVmasCap, 0, gBootVictoriaFallsVmmoCap, &vaddr));
auto client_or = CreateClient(); auto client_or = CreateClient();
if (!client_or.ok()) { if (!client_or.ok()) {
check(client_or.error()); check(client_or.error());
} }
check(SpawnProcessFromElfRegion(vaddr, client_or.value().Capability())); check(SpawnProcessFromElfRegion(vaddr, client_or.value().Capability()));
} else if (req.endpoint_name() == "victoriafalls") { continue;
victoria_falls_cap_ = req.endpoint_capability(); }
} else {
dbgln("[WARN] Got endpoint cap type: %s", req.endpoint_name().cstr()); if (name == "victoriafalls") {
victoria_falls_cap_ = endpoint_cap;
continue;
}
dbgln("[WARN] Got endpoint cap type:");
dbgln(name.cstr());
} }
return glcr::OK;
} }

View File

@ -13,12 +13,22 @@ class YellowstoneServer : public YellowstoneServerBase {
public: public:
static glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> Create(); static glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> Create();
Thread RunRegistration();
void RegistrationThread();
glcr::ErrorCode HandleGetAhciInfo(const Empty&, AhciInfo&) override; glcr::ErrorCode HandleGetAhciInfo(const Empty&, AhciInfo&) override;
glcr::ErrorCode HandleGetDenali(const Empty&, DenaliInfo&) override; glcr::ErrorCode HandleGetDenali(const Empty&, DenaliInfo&) override;
glcr::ErrorCode HandleRegisterEndpoint(const RegisterEndpointRequest&, glcr::ErrorCode HandleGetRegister(const Empty&, RegisterInfo&) override;
Empty&) override;
private: private:
// FIXME: Separate this to its own service.
PortServer register_port_;
static const uint64_t kBufferSize = 128;
uint8_t server_buffer_[kBufferSize];
char registration_buffer_[kBufferSize];
// TODO: Store these in a data structure. // TODO: Store these in a data structure.
z_cap_t denali_cap_ = 0; z_cap_t denali_cap_ = 0;
uint64_t device_id_ = 0; uint64_t device_id_ = 0;
@ -27,5 +37,5 @@ class YellowstoneServer : public YellowstoneServerBase {
PciReader pci_reader_; PciReader pci_reader_;
YellowstoneServer(z_cap_t endpoint_cap); YellowstoneServer(z_cap_t endpoint_cap, PortServer port);
}; };

View File

@ -16,12 +16,12 @@ glcr::ErrorCode {{interface.name}}Client::{{method.name}}(const {{method.request
buffer_.WriteAt<uint32_t>(0, kSentinel); buffer_.WriteAt<uint32_t>(0, kSentinel);
buffer_.WriteAt<uint64_t>(8, {{loop.index0}}); buffer_.WriteAt<uint64_t>(8, {{loop.index0}});
cap_buffer_.Reset();
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_); uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
buffer_.WriteAt<uint32_t>(4, 16 + length); buffer_.WriteAt<uint32_t>(4, 16 + length);
z_cap_t reply_port_cap; z_cap_t reply_port_cap;
RET_ERR(ZEndpointSend(endpoint_, 16 + length, buffer_.RawPtr(), cap_buffer_.UsedSlots(), cap_buffer_.RawPtr(), &reply_port_cap)); // FIXME: We need to be able to send capabilities via endpoint call.
RET_ERR(ZEndpointSend(endpoint_, 16 + length, buffer_.RawPtr(), &reply_port_cap));
// FIXME: Add a way to zero out the first buffer. // FIXME: Add a way to zero out the first buffer.
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr())); RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));

View File

@ -42,15 +42,14 @@ Thread {{interface.name}}ServerBase::RunServer() {
void {{interface.name}}ServerBase::ServerThread() { void {{interface.name}}ServerBase::ServerThread() {
glcr::ByteBuffer recv_buffer(0x1000); glcr::ByteBuffer recv_buffer(0x1000);
glcr::CapBuffer recv_cap(0x10);
glcr::ByteBuffer resp_buffer(0x1000); glcr::ByteBuffer resp_buffer(0x1000);
glcr::CapBuffer resp_cap(0x10); uint64_t resp_cap_size = 0x10;
glcr::CapBuffer resp_cap(resp_cap_size);
z_cap_t reply_port_cap; z_cap_t reply_port_cap;
while (true) { while (true) {
uint64_t recv_cap_size = 0x10;
uint64_t recv_buf_size = 0x1000; uint64_t recv_buf_size = 0x1000;
glcr::ErrorCode recv_err = ZEndpointRecv(endpoint_, &recv_buf_size, recv_buffer.RawPtr(), &recv_cap_size, recv_cap.RawPtr(), &reply_port_cap); glcr::ErrorCode recv_err = ZEndpointRecv(endpoint_, &recv_buf_size, recv_buffer.RawPtr(), &reply_port_cap);
if (recv_err != glcr::OK) { if (recv_err != glcr::OK) {
dbgln("Error in receive: %x", recv_err); dbgln("Error in receive: %x", recv_err);
continue; continue;
@ -59,7 +58,7 @@ void {{interface.name}}ServerBase::ServerThread() {
uint64_t resp_length = 0; uint64_t resp_length = 0;
glcr::ErrorCode reply_err = glcr::OK; glcr::ErrorCode reply_err = glcr::OK;
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap); glcr::ErrorCode err = HandleRequest(recv_buffer, resp_buffer, resp_length, resp_cap);
if (err != glcr::OK) { if (err != glcr::OK) {
WriteError(resp_buffer, err); WriteError(resp_buffer, err);
reply_err = ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr); reply_err = ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr);
@ -75,7 +74,6 @@ void {{interface.name}}ServerBase::ServerThread() {
} }
glcr::ErrorCode {{interface.name}}ServerBase::HandleRequest(const glcr::ByteBuffer& request, glcr::ErrorCode {{interface.name}}ServerBase::HandleRequest(const glcr::ByteBuffer& request,
const glcr::CapBuffer& req_caps,
glcr::ByteBuffer& response, uint64_t& resp_length, glcr::ByteBuffer& response, uint64_t& resp_length,
glcr::CapBuffer& resp_caps) { glcr::CapBuffer& resp_caps) {
if (request.At<uint32_t>(0) != kSentinel) { if (request.At<uint32_t>(0) != kSentinel) {
@ -90,7 +88,7 @@ glcr::ErrorCode {{interface.name}}ServerBase::HandleRequest(const glcr::ByteBuff
{{method.request}} yunq_request; {{method.request}} yunq_request;
{{method.response}} yunq_response; {{method.response}} yunq_response;
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps); yunq_request.ParseFromBytes(request, kHeaderSize);
RET_ERR(Handle{{method.name}}(yunq_request, yunq_response)); RET_ERR(Handle{{method.name}}(yunq_request, yunq_response));

View File

@ -30,8 +30,8 @@ class {{interface.name}}ServerBase {
friend void {{interface.name}}ServerBaseThreadBootstrap(void*); friend void {{interface.name}}ServerBaseThreadBootstrap(void*);
void ServerThread(); void ServerThread();
[[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps, [[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, glcr::ByteBuffer& response,
glcr::ByteBuffer& response, uint64_t& resp_length, uint64_t& resp_length,
glcr::CapBuffer& resp_caps); glcr::CapBuffer& resp_caps);
}; };

View File

@ -38,9 +38,7 @@
## Capabilities ## Capabilities
- Add syscalls for inspecting capabilities. - Add syscalls for inspecting capabilities.
- Add syscalls for restricting capabilities' permissions.
- Randomize/obfuscate capability numbers passed to user space. - Randomize/obfuscate capability numbers passed to user space.
- Remove ReplyPort capabilities once the response is sent.
## Scheduling ## Scheduling

View File

@ -2,9 +2,90 @@
#include <stdint.h> #include <stdint.h>
#include "zcall_macros.h"
#include "ztypes.h" #include "ztypes.h"
#define SYS0(name) \
struct Z##name##Req {}; \
[[nodiscard]] inline z_err_t Z##name() { \
Z##name##Req req{}; \
return SysCall1(kZion##name, &req); \
}
#define SYS1(name, t1, a1) \
struct Z##name##Req { \
t1 a1; \
}; \
[[nodiscard]] inline z_err_t Z##name(t1 a1) { \
Z##name##Req req{ \
.a1 = a1, \
}; \
return SysCall1(kZion##name, &req); \
}
#define SYS2(name, t1, a1, t2, a2) \
struct Z##name##Req { \
t1 a1; \
t2 a2; \
}; \
[[nodiscard]] inline z_err_t Z##name(t1 a1, t2 a2) { \
Z##name##Req req{ \
.a1 = a1, \
.a2 = a2, \
}; \
return SysCall1(kZion##name, &req); \
}
#define SYS3(name, t1, a1, t2, a2, t3, a3) \
struct Z##name##Req { \
t1 a1; \
t2 a2; \
t3 a3; \
}; \
[[nodiscard]] inline z_err_t Z##name(t1 a1, t2 a2, t3 a3) { \
Z##name##Req req{ \
.a1 = a1, \
.a2 = a2, \
.a3 = a3, \
}; \
return SysCall1(kZion##name, &req); \
}
#define SYS4(name, t1, a1, t2, a2, t3, a3, t4, a4) \
struct Z##name##Req { \
t1 a1; \
t2 a2; \
t3 a3; \
t4 a4; \
}; \
[[nodiscard]] inline z_err_t Z##name(t1 a1, t2 a2, t3 a3, t4 a4) { \
Z##name##Req req{ \
.a1 = a1, \
.a2 = a2, \
.a3 = a3, \
.a4 = a4, \
}; \
return SysCall1(kZion##name, &req); \
}
#define SYS5(name, t1, a1, t2, a2, t3, a3, t4, a4, t5, a5) \
struct Z##name##Req { \
t1 a1; \
t2 a2; \
t3 a3; \
t4 a4; \
t5 a5; \
}; \
[[nodiscard]] inline z_err_t Z##name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) { \
Z##name##Req req{ \
.a1 = a1, \
.a2 = a2, \
.a3 = a3, \
.a4 = a4, \
.a5 = a5, \
}; \
return SysCall1(kZion##name, &req); \
}
z_err_t SysCall1(uint64_t code, const void* req); z_err_t SysCall1(uint64_t code, const void* req);
SYS1(ProcessExit, uint64_t, code); SYS1(ProcessExit, uint64_t, code);
@ -46,10 +127,10 @@ SYS5(PortPoll, z_cap_t, port_cap, uint64_t*, num_bytes, void*, data, uint64_t*,
SYS2(IrqRegister, uint64_t, irq_num, z_cap_t*, port_cap); SYS2(IrqRegister, uint64_t, irq_num, z_cap_t*, port_cap);
SYS1(EndpointCreate, z_cap_t*, endpoint_cap); SYS1(EndpointCreate, z_cap_t*, endpoint_cap);
SYS6(EndpointSend, z_cap_t, endpoint_cap, uint64_t, num_bytes, const void*, SYS4(EndpointSend, z_cap_t, endpoint_cap, uint64_t, num_bytes, const void*,
data, uint64_t, num_caps, const z_cap_t*, caps, z_cap_t*, reply_port_cap); data, z_cap_t*, reply_port_cap);
SYS6(EndpointRecv, z_cap_t, endpoint_cap, uint64_t*, num_bytes, void*, data, SYS4(EndpointRecv, z_cap_t, endpoint_cap, uint64_t*, num_bytes, void*, data,
uint64_t*, num_caps, z_cap_t*, caps, z_cap_t*, reply_port_cap); z_cap_t*, reply_port_cap);
SYS5(ReplyPortSend, z_cap_t, reply_port_cap, uint64_t, num_bytes, const void*, SYS5(ReplyPortSend, z_cap_t, reply_port_cap, uint64_t, num_bytes, const void*,
data, uint64_t, num_caps, z_cap_t*, caps); data, uint64_t, num_caps, z_cap_t*, caps);
SYS5(ReplyPortRecv, z_cap_t, reply_port_cap, uint64_t*, num_bytes, void*, data, SYS5(ReplyPortRecv, z_cap_t, reply_port_cap, uint64_t*, num_bytes, void*, data,

View File

@ -1,104 +0,0 @@
#pragma once
#define SYS0(name) \
struct Z##name##Req {}; \
[[nodiscard]] inline z_err_t Z##name() { \
Z##name##Req req{}; \
return SysCall1(kZion##name, &req); \
}
#define SYS1(name, t1, a1) \
struct Z##name##Req { \
t1 a1; \
}; \
[[nodiscard]] inline z_err_t Z##name(t1 a1) { \
Z##name##Req req{ \
.a1 = a1, \
}; \
return SysCall1(kZion##name, &req); \
}
#define SYS2(name, t1, a1, t2, a2) \
struct Z##name##Req { \
t1 a1; \
t2 a2; \
}; \
[[nodiscard]] inline z_err_t Z##name(t1 a1, t2 a2) { \
Z##name##Req req{ \
.a1 = a1, \
.a2 = a2, \
}; \
return SysCall1(kZion##name, &req); \
}
#define SYS3(name, t1, a1, t2, a2, t3, a3) \
struct Z##name##Req { \
t1 a1; \
t2 a2; \
t3 a3; \
}; \
[[nodiscard]] inline z_err_t Z##name(t1 a1, t2 a2, t3 a3) { \
Z##name##Req req{ \
.a1 = a1, \
.a2 = a2, \
.a3 = a3, \
}; \
return SysCall1(kZion##name, &req); \
}
#define SYS4(name, t1, a1, t2, a2, t3, a3, t4, a4) \
struct Z##name##Req { \
t1 a1; \
t2 a2; \
t3 a3; \
t4 a4; \
}; \
[[nodiscard]] inline z_err_t Z##name(t1 a1, t2 a2, t3 a3, t4 a4) { \
Z##name##Req req{ \
.a1 = a1, \
.a2 = a2, \
.a3 = a3, \
.a4 = a4, \
}; \
return SysCall1(kZion##name, &req); \
}
#define SYS5(name, t1, a1, t2, a2, t3, a3, t4, a4, t5, a5) \
struct Z##name##Req { \
t1 a1; \
t2 a2; \
t3 a3; \
t4 a4; \
t5 a5; \
}; \
[[nodiscard]] inline z_err_t Z##name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) { \
Z##name##Req req{ \
.a1 = a1, \
.a2 = a2, \
.a3 = a3, \
.a4 = a4, \
.a5 = a5, \
}; \
return SysCall1(kZion##name, &req); \
}
#define SYS6(name, t1, a1, t2, a2, t3, a3, t4, a4, t5, a5, t6, a6) \
struct Z##name##Req { \
t1 a1; \
t2 a2; \
t3 a3; \
t4 a4; \
t5 a5; \
t6 a6; \
}; \
[[nodiscard]] inline z_err_t Z##name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
t6 a6) { \
Z##name##Req req{ \
.a1 = a1, \
.a2 = a2, \
.a3 = a3, \
.a4 = a4, \
.a5 = a5, \
.a6 = a6, \
}; \
return SysCall1(kZion##name, &req); \
}

View File

@ -63,8 +63,6 @@ const uint64_t kZionDebug = 0x1'0000;
typedef uint64_t z_cap_t; typedef uint64_t z_cap_t;
const uint64_t kZionInvalidCapability = 0x0;
// General Capability Permissions // General Capability Permissions
const uint64_t kZionPerm_Write = 0x1; const uint64_t kZionPerm_Write = 0x1;
const uint64_t kZionPerm_Read = 0x2; const uint64_t kZionPerm_Read = 0x2;

View File

@ -4,8 +4,8 @@
#include "scheduler/scheduler.h" #include "scheduler/scheduler.h"
z_err_t UnboundedMessageQueue::PushBack(uint64_t num_bytes, const void* bytes, z_err_t UnboundedMessageQueue::PushBack(uint64_t num_bytes, const void* bytes,
uint64_t num_caps, const z_cap_t* caps, uint64_t num_caps,
z_cap_t reply_cap) { const z_cap_t* caps) {
if (num_bytes > 0x1000) { if (num_bytes > 0x1000) {
dbgln("Large message size unimplemented: %x", num_bytes); dbgln("Large message size unimplemented: %x", num_bytes);
return glcr::UNIMPLEMENTED; return glcr::UNIMPLEMENTED;
@ -18,12 +18,6 @@ z_err_t UnboundedMessageQueue::PushBack(uint64_t num_bytes, const void* bytes,
message->bytes[i] = static_cast<const uint8_t*>(bytes)[i]; message->bytes[i] = static_cast<const uint8_t*>(bytes)[i];
} }
if (reply_cap != kZionInvalidCapability) {
// FIXME: We're just trusting that capability has the correct permissions.
message->reply_cap =
gScheduler->CurrentProcess().ReleaseCapability(reply_cap);
}
for (uint64_t i = 0; i < num_caps; i++) { for (uint64_t i = 0; i < num_caps; i++) {
// FIXME: This would feel safer closer to the relevant syscall. // FIXME: This would feel safer closer to the relevant syscall.
// FIXME: Race conditions on get->check->release here. Would be better to // FIXME: Race conditions on get->check->release here. Would be better to
@ -52,8 +46,7 @@ z_err_t UnboundedMessageQueue::PushBack(uint64_t num_bytes, const void* bytes,
} }
z_err_t UnboundedMessageQueue::PopFront(uint64_t* num_bytes, void* bytes, z_err_t UnboundedMessageQueue::PopFront(uint64_t* num_bytes, void* bytes,
uint64_t* num_caps, z_cap_t* caps, uint64_t* num_caps, z_cap_t* caps) {
z_cap_t* reply_cap) {
mutex_.Lock(); mutex_.Lock();
while (pending_messages_.empty()) { while (pending_messages_.empty()) {
auto thread = gScheduler->CurrentThread(); auto thread = gScheduler->CurrentThread();
@ -82,16 +75,8 @@ z_err_t UnboundedMessageQueue::PopFront(uint64_t* num_bytes, void* bytes,
static_cast<uint8_t*>(bytes)[i] = next_msg->bytes[i]; static_cast<uint8_t*>(bytes)[i] = next_msg->bytes[i];
} }
auto& proc = gScheduler->CurrentProcess();
if (reply_cap != nullptr) {
if (!next_msg->reply_cap) {
dbgln("Tried to read reply capability off of a message without one");
return glcr::INTERNAL;
}
*reply_cap = proc.AddExistingCapability(next_msg->reply_cap);
}
*num_caps = next_msg->caps.size(); *num_caps = next_msg->caps.size();
auto& proc = gScheduler->CurrentProcess();
for (uint64_t i = 0; i < *num_caps; i++) { for (uint64_t i = 0; i < *num_caps; i++) {
caps[i] = proc.AddExistingCapability(next_msg->caps.PopFront()); caps[i] = proc.AddExistingCapability(next_msg->caps.PopFront());
} }
@ -117,8 +102,7 @@ void UnboundedMessageQueue::WriteKernel(uint64_t init,
glcr::ErrorCode SingleMessageQueue::PushBack(uint64_t num_bytes, glcr::ErrorCode SingleMessageQueue::PushBack(uint64_t num_bytes,
const void* bytes, const void* bytes,
uint64_t num_caps, uint64_t num_caps,
const z_cap_t* caps, const z_cap_t* caps) {
z_cap_t reply_port) {
MutexHolder h(mutex_); MutexHolder h(mutex_);
if (has_written_) { if (has_written_) {
return glcr::FAILED_PRECONDITION; return glcr::FAILED_PRECONDITION;
@ -130,11 +114,6 @@ glcr::ErrorCode SingleMessageQueue::PushBack(uint64_t num_bytes,
bytes_[i] = reinterpret_cast<const uint8_t*>(bytes)[i]; bytes_[i] = reinterpret_cast<const uint8_t*>(bytes)[i];
} }
if (reply_port != kZionInvalidCapability) {
dbgln("Sent a reply port to a single message queue");
return glcr::INTERNAL;
}
for (uint64_t i = 0; i < num_caps; i++) { for (uint64_t i = 0; i < num_caps; i++) {
// FIXME: This would feel safer closer to the relevant syscall. // FIXME: This would feel safer closer to the relevant syscall.
auto cap = gScheduler->CurrentProcess().GetCapability(caps[i]); auto cap = gScheduler->CurrentProcess().GetCapability(caps[i]);
@ -160,8 +139,8 @@ glcr::ErrorCode SingleMessageQueue::PushBack(uint64_t num_bytes,
} }
glcr::ErrorCode SingleMessageQueue::PopFront(uint64_t* num_bytes, void* bytes, glcr::ErrorCode SingleMessageQueue::PopFront(uint64_t* num_bytes, void* bytes,
uint64_t* num_caps, z_cap_t* caps, uint64_t* num_caps,
z_cap_t* reply_port) { z_cap_t* caps) {
mutex_.Lock(); mutex_.Lock();
while (!has_written_) { while (!has_written_) {
auto thread = gScheduler->CurrentThread(); auto thread = gScheduler->CurrentThread();
@ -190,11 +169,6 @@ glcr::ErrorCode SingleMessageQueue::PopFront(uint64_t* num_bytes, void* bytes,
reinterpret_cast<uint8_t*>(bytes)[i] = bytes_[i]; reinterpret_cast<uint8_t*>(bytes)[i] = bytes_[i];
} }
if (reply_port != nullptr) {
dbgln("Tried to read a reply port a single message queue");
return glcr::INTERNAL;
}
*num_caps = caps_.size(); *num_caps = caps_.size();
auto& proc = gScheduler->CurrentProcess(); auto& proc = gScheduler->CurrentProcess();
for (uint64_t i = 0; i < *num_caps; i++) { for (uint64_t i = 0; i < *num_caps; i++) {

View File

@ -15,11 +15,9 @@ class MessageQueue {
virtual ~MessageQueue() {} virtual ~MessageQueue() {}
virtual glcr::ErrorCode PushBack(uint64_t num_bytes, const void* bytes, virtual glcr::ErrorCode PushBack(uint64_t num_bytes, const void* bytes,
uint64_t num_caps, const z_cap_t* caps, uint64_t num_caps, const z_cap_t* caps) = 0;
z_cap_t reply_cap = 0) = 0;
virtual glcr::ErrorCode PopFront(uint64_t* num_bytes, void* bytes, virtual glcr::ErrorCode PopFront(uint64_t* num_bytes, void* bytes,
uint64_t* num_caps, z_cap_t* caps, uint64_t* num_caps, z_cap_t* caps) = 0;
z_cap_t* reply_cap = nullptr) = 0;
virtual bool empty() = 0; virtual bool empty() = 0;
protected: protected:
@ -37,10 +35,9 @@ class UnboundedMessageQueue : public MessageQueue {
virtual ~UnboundedMessageQueue() override {} virtual ~UnboundedMessageQueue() override {}
glcr::ErrorCode PushBack(uint64_t num_bytes, const void* bytes, glcr::ErrorCode PushBack(uint64_t num_bytes, const void* bytes,
uint64_t num_caps, const z_cap_t* caps, uint64_t num_caps, const z_cap_t* caps) override;
z_cap_t reply_cap) override;
glcr::ErrorCode PopFront(uint64_t* num_bytes, void* bytes, uint64_t* num_caps, glcr::ErrorCode PopFront(uint64_t* num_bytes, void* bytes, uint64_t* num_caps,
z_cap_t* caps, z_cap_t* reply_cap) override; z_cap_t* caps) override;
void WriteKernel(uint64_t init, glcr::RefPtr<Capability> cap); void WriteKernel(uint64_t init, glcr::RefPtr<Capability> cap);
@ -55,7 +52,6 @@ class UnboundedMessageQueue : public MessageQueue {
uint8_t* bytes; uint8_t* bytes;
glcr::LinkedList<glcr::RefPtr<Capability>> caps; glcr::LinkedList<glcr::RefPtr<Capability>> caps;
glcr::RefPtr<Capability> reply_cap;
}; };
glcr::LinkedList<glcr::SharedPtr<Message>> pending_messages_; glcr::LinkedList<glcr::SharedPtr<Message>> pending_messages_;
@ -69,10 +65,9 @@ class SingleMessageQueue : public MessageQueue {
virtual ~SingleMessageQueue() override {} virtual ~SingleMessageQueue() override {}
glcr::ErrorCode PushBack(uint64_t num_bytes, const void* bytes, glcr::ErrorCode PushBack(uint64_t num_bytes, const void* bytes,
uint64_t num_caps, const z_cap_t* caps, uint64_t num_caps, const z_cap_t* caps) override;
z_cap_t reply_cap) override;
glcr::ErrorCode PopFront(uint64_t* num_bytes, void* bytes, uint64_t* num_caps, glcr::ErrorCode PopFront(uint64_t* num_bytes, void* bytes, uint64_t* num_caps,
z_cap_t* caps, z_cap_t* reply_cap) override; z_cap_t* caps) override;
bool empty() override { bool empty() override {
MutexHolder h(mutex_); MutexHolder h(mutex_);

View File

@ -5,18 +5,3 @@
glcr::RefPtr<Endpoint> Endpoint::Create() { glcr::RefPtr<Endpoint> Endpoint::Create() {
return glcr::AdoptPtr(new Endpoint); return glcr::AdoptPtr(new Endpoint);
} }
glcr::ErrorCode Endpoint::Send(uint64_t num_bytes, const void* data,
uint64_t num_caps, const z_cap_t* caps,
z_cap_t reply_port_cap) {
auto& message_queue = GetSendMessageQueue();
return message_queue.PushBack(num_bytes, data, num_caps, caps,
reply_port_cap);
}
glcr::ErrorCode Endpoint::Recv(uint64_t* num_bytes, void* data,
uint64_t* num_caps, z_cap_t* caps,
z_cap_t* reply_port_cap) {
auto& message_queue = GetRecvMessageQueue();
return message_queue.PopFront(num_bytes, data, num_caps, caps,
reply_port_cap);
}

View File

@ -27,11 +27,8 @@ class Endpoint : public IpcObject {
static glcr::RefPtr<Endpoint> Create(); static glcr::RefPtr<Endpoint> Create();
// FIXME: These are hacky "almost" overrides that could lead to bugs. glcr::ErrorCode Read(uint64_t* num_bytes, void* data,
glcr::ErrorCode Send(uint64_t num_bytes, const void* data, uint64_t num_caps, z_cap_t* reply_port_cap);
const z_cap_t* caps, z_cap_t reply_port_cap);
glcr::ErrorCode Recv(uint64_t* num_bytes, void* data, uint64_t* num_caps,
z_cap_t* caps, z_cap_t* reply_port_cap);
virtual MessageQueue& GetSendMessageQueue() override { virtual MessageQueue& GetSendMessageQueue() override {
return message_queue_; return message_queue_;

View File

@ -106,8 +106,7 @@ glcr::ErrorCode EndpointSend(ZEndpointSendReq* req) {
*req->reply_port_cap = proc.AddNewCapability(reply_port, kZionPerm_Read); *req->reply_port_cap = proc.AddNewCapability(reply_port, kZionPerm_Read);
uint64_t reply_port_cap_to_send = uint64_t reply_port_cap_to_send =
proc.AddNewCapability(reply_port, kZionPerm_Write | kZionPerm_Transmit); proc.AddNewCapability(reply_port, kZionPerm_Write | kZionPerm_Transmit);
return endpoint->Send(req->num_bytes, req->data, req->num_caps, req->caps, return endpoint->Send(req->num_bytes, req->data, 1, &reply_port_cap_to_send);
reply_port_cap_to_send);
} }
glcr::ErrorCode EndpointRecv(ZEndpointRecvReq* req) { glcr::ErrorCode EndpointRecv(ZEndpointRecvReq* req) {
@ -118,7 +117,7 @@ glcr::ErrorCode EndpointRecv(ZEndpointRecvReq* req) {
auto endpoint = endpoint_cap->obj<Endpoint>(); auto endpoint = endpoint_cap->obj<Endpoint>();
uint64_t num_caps = 1; uint64_t num_caps = 1;
RET_ERR(endpoint->Recv(req->num_bytes, req->data, req->num_caps, req->caps, RET_ERR(endpoint->Recv(req->num_bytes, req->data, &num_caps,
req->reply_port_cap)); req->reply_port_cap));
if (num_caps != 1) { if (num_caps != 1) {
return glcr::INTERNAL; return glcr::INTERNAL;