Compare commits
2 Commits
5b781bb394
...
05e12aaa7d
Author | SHA1 | Date |
---|---|---|
|
05e12aaa7d | |
|
b516087922 |
|
@ -13,6 +13,11 @@ class CapBuffer {
|
|||
|
||||
~CapBuffer() { delete[] buffer_; }
|
||||
|
||||
void Reset() {
|
||||
// FIXME: Zero out caps here?
|
||||
used_slots_ = 0;
|
||||
}
|
||||
|
||||
uint64_t* RawPtr() { return buffer_; }
|
||||
|
||||
uint64_t UsedSlots() { return used_slots_; }
|
||||
|
|
|
@ -31,7 +31,7 @@ template <typename Req, typename Resp>
|
|||
glcr::ErrorOr<glcr::Pair<Resp, z_cap_t>> EndpointClient::CallEndpointGetCap(
|
||||
const Req& req) {
|
||||
uint64_t reply_port_cap;
|
||||
RET_ERR(ZEndpointSend(cap_, sizeof(Req), &req, &reply_port_cap));
|
||||
RET_ERR(ZEndpointSend(cap_, sizeof(Req), &req, 0, nullptr, &reply_port_cap));
|
||||
|
||||
Resp resp;
|
||||
z_cap_t cap = 0;
|
||||
|
@ -49,7 +49,7 @@ glcr::ErrorOr<glcr::Pair<Resp, z_cap_t>> EndpointClient::CallEndpointGetCap(
|
|||
template <typename Req, typename Resp>
|
||||
glcr::ErrorOr<Resp> EndpointClient::CallEndpoint(const Req& req) {
|
||||
uint64_t reply_port_cap;
|
||||
RET_ERR(ZEndpointSend(cap_, sizeof(Req), &req, &reply_port_cap));
|
||||
RET_ERR(ZEndpointSend(cap_, sizeof(Req), &req, 0, nullptr, &reply_port_cap));
|
||||
|
||||
Resp resp;
|
||||
uint64_t num_bytes = sizeof(Resp);
|
||||
|
|
|
@ -22,8 +22,10 @@ void EndpointServer::ServerThread() {
|
|||
while (true) {
|
||||
uint64_t message_size = kBufferSize;
|
||||
uint64_t reply_port_cap = 0;
|
||||
glcr::ErrorCode err = ZEndpointRecv(endpoint_cap_, &message_size,
|
||||
recieve_buffer_, &reply_port_cap);
|
||||
uint64_t num_caps = 0;
|
||||
glcr::ErrorCode err =
|
||||
ZEndpointRecv(endpoint_cap_, &message_size, recieve_buffer_, &num_caps,
|
||||
nullptr, &reply_port_cap);
|
||||
if (err != glcr::OK) {
|
||||
dbgln("Error in receive: %x", err);
|
||||
continue;
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
## Yellowstone
|
||||
|
||||
- Add registration to the base yellowstone yunq service
|
||||
- Requires: Adding ability to pass capabilities in endpoint calls.
|
||||
- Store registered services in a hashmap.
|
||||
- Requires: Adding hashmap to Glacier.
|
||||
- Start the next service from a configuration file.
|
||||
|
|
|
@ -29,16 +29,13 @@ uint64_t main(uint64_t init_port_cap) {
|
|||
ASSIGN_OR_RETURN(glcr::UniquePtr<EndpointClient> client,
|
||||
server->CreateClient());
|
||||
|
||||
RegisterInfo reg;
|
||||
Empty empty2;
|
||||
check(stub.GetRegister(empty2, reg));
|
||||
|
||||
PortClient register_port = PortClient::AdoptPort(reg.register_port());
|
||||
|
||||
check(register_port.WriteString("denali", client->GetCap()));
|
||||
|
||||
Thread server_thread = server->RunServer();
|
||||
|
||||
RegisterEndpointRequest req;
|
||||
req.set_endpoint_name("denali");
|
||||
req.set_endpoint_capability(client->GetCap());
|
||||
check(stub.RegisterEndpoint(req, empty));
|
||||
|
||||
check(server_thread.Join());
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
interface Yellowstone {
|
||||
method GetRegister(Empty) -> (RegisterInfo);
|
||||
method RegisterEndpoint(RegisterEndpointRequest) -> (Empty);
|
||||
method GetAhciInfo(Empty) -> (AhciInfo);
|
||||
method GetDenali(Empty) -> (DenaliInfo);
|
||||
}
|
||||
|
||||
message RegisterEndpointRequest {
|
||||
string endpoint_name;
|
||||
capability endpoint_capability;
|
||||
}
|
||||
|
||||
message Empty {
|
||||
|
||||
}
|
||||
|
||||
message RegisterInfo {
|
||||
capability register_port;
|
||||
}
|
||||
|
||||
message AhciInfo {
|
||||
capability ahci_region;
|
||||
u64 region_length;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
|
||||
|
||||
glcr::ErrorCode YellowstoneClient::GetRegister(const Empty& request, RegisterInfo& response) {
|
||||
glcr::ErrorCode YellowstoneClient::RegisterEndpoint(const RegisterEndpointRequest& request, Empty& response) {
|
||||
uint64_t buffer_size = kBufferSize;
|
||||
uint64_t cap_size = kCapBufferSize;
|
||||
|
||||
|
@ -16,12 +16,12 @@ glcr::ErrorCode YellowstoneClient::GetRegister(const Empty& request, RegisterInf
|
|||
buffer_.WriteAt<uint32_t>(0, kSentinel);
|
||||
buffer_.WriteAt<uint64_t>(8, 0);
|
||||
|
||||
cap_buffer_.Reset();
|
||||
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
|
||||
buffer_.WriteAt<uint32_t>(4, 16 + length);
|
||||
|
||||
z_cap_t 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));
|
||||
RET_ERR(ZEndpointSend(endpoint_, 16 + length, buffer_.RawPtr(), cap_buffer_.UsedSlots(), cap_buffer_.RawPtr(), &reply_port_cap));
|
||||
|
||||
// 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()));
|
||||
|
@ -48,12 +48,12 @@ glcr::ErrorCode YellowstoneClient::GetAhciInfo(const Empty& request, AhciInfo& r
|
|||
buffer_.WriteAt<uint32_t>(0, kSentinel);
|
||||
buffer_.WriteAt<uint64_t>(8, 1);
|
||||
|
||||
cap_buffer_.Reset();
|
||||
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
|
||||
buffer_.WriteAt<uint32_t>(4, 16 + length);
|
||||
|
||||
z_cap_t 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));
|
||||
RET_ERR(ZEndpointSend(endpoint_, 16 + length, buffer_.RawPtr(), cap_buffer_.UsedSlots(), cap_buffer_.RawPtr(), &reply_port_cap));
|
||||
|
||||
// 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()));
|
||||
|
@ -80,12 +80,12 @@ glcr::ErrorCode YellowstoneClient::GetDenali(const Empty& request, DenaliInfo& r
|
|||
buffer_.WriteAt<uint32_t>(0, kSentinel);
|
||||
buffer_.WriteAt<uint64_t>(8, 2);
|
||||
|
||||
cap_buffer_.Reset();
|
||||
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
|
||||
buffer_.WriteAt<uint32_t>(4, 16 + length);
|
||||
|
||||
z_cap_t 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));
|
||||
RET_ERR(ZEndpointSend(endpoint_, 16 + length, buffer_.RawPtr(), cap_buffer_.UsedSlots(), cap_buffer_.RawPtr(), &reply_port_cap));
|
||||
|
||||
// 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()));
|
||||
|
|
|
@ -17,7 +17,7 @@ class YellowstoneClient {
|
|||
z_cap_t Capability() { return endpoint_; }
|
||||
|
||||
|
||||
[[nodiscard]] glcr::ErrorCode GetRegister(const Empty& request, RegisterInfo& response);
|
||||
[[nodiscard]] glcr::ErrorCode RegisterEndpoint(const RegisterEndpointRequest& request, Empty& response);
|
||||
|
||||
[[nodiscard]] glcr::ErrorCode GetAhciInfo(const Empty& request, AhciInfo& response);
|
||||
|
||||
|
|
|
@ -27,6 +27,77 @@ void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size, u
|
|||
}
|
||||
|
||||
} // 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) {
|
||||
CheckHeader(bytes);
|
||||
}
|
||||
|
@ -55,47 +126,6 @@ uint64_t Empty::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr:
|
|||
|
||||
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) {
|
||||
CheckHeader(bytes);
|
||||
// Parse ahci_region.
|
||||
|
|
|
@ -5,6 +5,27 @@
|
|||
#include <glacier/buffer/cap_buffer.h>
|
||||
#include <glacier/string/string.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 {
|
||||
public:
|
||||
Empty() {}
|
||||
|
@ -19,24 +40,6 @@ class Empty {
|
|||
|
||||
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 {
|
||||
public:
|
||||
|
|
|
@ -42,14 +42,15 @@ Thread YellowstoneServerBase::RunServer() {
|
|||
|
||||
void YellowstoneServerBase::ServerThread() {
|
||||
glcr::ByteBuffer recv_buffer(0x1000);
|
||||
glcr::CapBuffer recv_cap(0x10);
|
||||
glcr::ByteBuffer resp_buffer(0x1000);
|
||||
uint64_t resp_cap_size = 0x10;
|
||||
glcr::CapBuffer resp_cap(resp_cap_size);
|
||||
glcr::CapBuffer resp_cap(0x10);
|
||||
z_cap_t reply_port_cap;
|
||||
|
||||
while (true) {
|
||||
uint64_t recv_cap_size = 0x10;
|
||||
uint64_t recv_buf_size = 0x1000;
|
||||
glcr::ErrorCode recv_err = ZEndpointRecv(endpoint_, &recv_buf_size, recv_buffer.RawPtr(), &reply_port_cap);
|
||||
glcr::ErrorCode recv_err = ZEndpointRecv(endpoint_, &recv_buf_size, recv_buffer.RawPtr(), &recv_cap_size, recv_cap.RawPtr(), &reply_port_cap);
|
||||
if (recv_err != glcr::OK) {
|
||||
dbgln("Error in receive: %x", recv_err);
|
||||
continue;
|
||||
|
@ -58,7 +59,7 @@ void YellowstoneServerBase::ServerThread() {
|
|||
uint64_t resp_length = 0;
|
||||
|
||||
glcr::ErrorCode reply_err = glcr::OK;
|
||||
glcr::ErrorCode err = HandleRequest(recv_buffer, resp_buffer, resp_length, resp_cap);
|
||||
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
|
||||
if (err != glcr::OK) {
|
||||
WriteError(resp_buffer, err);
|
||||
reply_err = ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr);
|
||||
|
@ -74,6 +75,7 @@ void YellowstoneServerBase::ServerThread() {
|
|||
}
|
||||
|
||||
glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||
const glcr::CapBuffer& req_caps,
|
||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
||||
glcr::CapBuffer& resp_caps) {
|
||||
if (request.At<uint32_t>(0) != kSentinel) {
|
||||
|
@ -84,12 +86,12 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
|
|||
|
||||
switch(method_select) {
|
||||
case 0: {
|
||||
Empty yunq_request;
|
||||
RegisterInfo yunq_response;
|
||||
RegisterEndpointRequest yunq_request;
|
||||
Empty yunq_response;
|
||||
|
||||
yunq_request.ParseFromBytes(request, kHeaderSize);
|
||||
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
||||
|
||||
RET_ERR(HandleGetRegister(yunq_request, yunq_response));
|
||||
RET_ERR(HandleRegisterEndpoint(yunq_request, yunq_response));
|
||||
|
||||
resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps);
|
||||
break;
|
||||
|
@ -98,7 +100,7 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
|
|||
Empty yunq_request;
|
||||
AhciInfo yunq_response;
|
||||
|
||||
yunq_request.ParseFromBytes(request, kHeaderSize);
|
||||
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
||||
|
||||
RET_ERR(HandleGetAhciInfo(yunq_request, yunq_response));
|
||||
|
||||
|
@ -109,7 +111,7 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
|
|||
Empty yunq_request;
|
||||
DenaliInfo yunq_response;
|
||||
|
||||
yunq_request.ParseFromBytes(request, kHeaderSize);
|
||||
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
||||
|
||||
RET_ERR(HandleGetDenali(yunq_request, yunq_response));
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ class YellowstoneServerBase {
|
|||
[[nodiscard]] Thread RunServer();
|
||||
|
||||
|
||||
[[nodiscard]] virtual glcr::ErrorCode HandleGetRegister(const Empty&, RegisterInfo&) = 0;
|
||||
[[nodiscard]] virtual glcr::ErrorCode HandleRegisterEndpoint(const RegisterEndpointRequest&, Empty&) = 0;
|
||||
|
||||
[[nodiscard]] virtual glcr::ErrorCode HandleGetAhciInfo(const Empty&, AhciInfo&) = 0;
|
||||
|
||||
|
@ -34,8 +34,8 @@ class YellowstoneServerBase {
|
|||
friend void YellowstoneServerBaseThreadBootstrap(void*);
|
||||
void ServerThread();
|
||||
|
||||
[[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, glcr::ByteBuffer& response,
|
||||
uint64_t& resp_length,
|
||||
[[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
|
||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
||||
glcr::CapBuffer& resp_caps);
|
||||
};
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ uint64_t main(uint64_t port_cap) {
|
|||
check(ParseInitPort(port_cap));
|
||||
|
||||
ASSIGN_OR_RETURN(auto server, YellowstoneServer::Create());
|
||||
Thread registration_thread = server->RunRegistration();
|
||||
Thread server_thread = server->RunServer();
|
||||
|
||||
uint64_t vaddr;
|
||||
|
@ -22,7 +21,6 @@ uint64_t main(uint64_t port_cap) {
|
|||
check(SpawnProcessFromElfRegion(vaddr, client.Capability()));
|
||||
|
||||
check(server_thread.Join());
|
||||
check(registration_thread.Join());
|
||||
dbgln("Yellowstone Finished Successfully.");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -13,11 +13,6 @@
|
|||
|
||||
namespace {
|
||||
|
||||
void RegistrationThreadBootstrap(void* yellowstone) {
|
||||
dbgln("Yellowstone registration starting");
|
||||
static_cast<YellowstoneServer*>(yellowstone)->RegistrationThread();
|
||||
}
|
||||
|
||||
struct PartitionInfo {
|
||||
uint64_t device_id;
|
||||
uint64_t partition_lba;
|
||||
|
@ -38,16 +33,11 @@ glcr::ErrorOr<PartitionInfo> HandleDenaliRegistration(z_cap_t endpoint_cap) {
|
|||
glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> YellowstoneServer::Create() {
|
||||
z_cap_t cap;
|
||||
RET_ERR(ZEndpointCreate(&cap));
|
||||
ASSIGN_OR_RETURN(PortServer port, PortServer::Create());
|
||||
return glcr::UniquePtr<YellowstoneServer>(new YellowstoneServer(cap, port));
|
||||
return glcr::UniquePtr<YellowstoneServer>(new YellowstoneServer(cap));
|
||||
}
|
||||
|
||||
YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap, PortServer port)
|
||||
: YellowstoneServerBase(endpoint_cap), register_port_(port) {}
|
||||
|
||||
Thread YellowstoneServer::RunRegistration() {
|
||||
return Thread(RegistrationThreadBootstrap, this);
|
||||
}
|
||||
YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap)
|
||||
: YellowstoneServerBase(endpoint_cap) {}
|
||||
|
||||
glcr::ErrorCode YellowstoneServer::HandleGetAhciInfo(const Empty&,
|
||||
AhciInfo& info) {
|
||||
|
@ -65,27 +55,12 @@ glcr::ErrorCode YellowstoneServer::HandleGetDenali(const Empty&,
|
|||
info.set_lba_offset(lba_offset_);
|
||||
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;
|
||||
}
|
||||
|
||||
void YellowstoneServer::RegistrationThread() {
|
||||
while (true) {
|
||||
uint64_t num_bytes = kBufferSize;
|
||||
z_cap_t endpoint_cap;
|
||||
// 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;
|
||||
glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint(
|
||||
const RegisterEndpointRequest& req, Empty&) {
|
||||
dbgln("Registering.");
|
||||
if (req.endpoint_name() == "denali") {
|
||||
denali_cap_ = req.endpoint_capability();
|
||||
auto part_info_or = HandleDenaliRegistration(denali_cap_);
|
||||
if (!part_info_or.ok()) {
|
||||
check(part_info_or.error());
|
||||
|
@ -94,22 +69,16 @@ void YellowstoneServer::RegistrationThread() {
|
|||
lba_offset_ = part_info_or.value().partition_lba;
|
||||
|
||||
uint64_t vaddr;
|
||||
check(
|
||||
ZAddressSpaceMap(gSelfVmasCap, 0, gBootVictoriaFallsVmmoCap, &vaddr));
|
||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, gBootVictoriaFallsVmmoCap, &vaddr));
|
||||
auto client_or = CreateClient();
|
||||
if (!client_or.ok()) {
|
||||
check(client_or.error());
|
||||
}
|
||||
check(SpawnProcessFromElfRegion(vaddr, client_or.value().Capability()));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (name == "victoriafalls") {
|
||||
victoria_falls_cap_ = endpoint_cap;
|
||||
continue;
|
||||
}
|
||||
|
||||
dbgln("[WARN] Got endpoint cap type:");
|
||||
dbgln(name.cstr());
|
||||
} else if (req.endpoint_name() == "victoriafalls") {
|
||||
victoria_falls_cap_ = req.endpoint_capability();
|
||||
} else {
|
||||
dbgln("[WARN] Got endpoint cap type: %s", req.endpoint_name().cstr());
|
||||
}
|
||||
return glcr::OK;
|
||||
}
|
||||
|
|
|
@ -13,22 +13,12 @@ class YellowstoneServer : public YellowstoneServerBase {
|
|||
public:
|
||||
static glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> Create();
|
||||
|
||||
Thread RunRegistration();
|
||||
|
||||
void RegistrationThread();
|
||||
|
||||
glcr::ErrorCode HandleGetAhciInfo(const Empty&, AhciInfo&) override;
|
||||
glcr::ErrorCode HandleGetDenali(const Empty&, DenaliInfo&) override;
|
||||
glcr::ErrorCode HandleGetRegister(const Empty&, RegisterInfo&) override;
|
||||
glcr::ErrorCode HandleRegisterEndpoint(const RegisterEndpointRequest&,
|
||||
Empty&) override;
|
||||
|
||||
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.
|
||||
z_cap_t denali_cap_ = 0;
|
||||
uint64_t device_id_ = 0;
|
||||
|
@ -37,5 +27,5 @@ class YellowstoneServer : public YellowstoneServerBase {
|
|||
|
||||
PciReader pci_reader_;
|
||||
|
||||
YellowstoneServer(z_cap_t endpoint_cap, PortServer port);
|
||||
YellowstoneServer(z_cap_t endpoint_cap);
|
||||
};
|
||||
|
|
|
@ -16,12 +16,12 @@ glcr::ErrorCode {{interface.name}}Client::{{method.name}}(const {{method.request
|
|||
buffer_.WriteAt<uint32_t>(0, kSentinel);
|
||||
buffer_.WriteAt<uint64_t>(8, {{loop.index0}});
|
||||
|
||||
cap_buffer_.Reset();
|
||||
uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_);
|
||||
buffer_.WriteAt<uint32_t>(4, 16 + length);
|
||||
|
||||
z_cap_t 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));
|
||||
RET_ERR(ZEndpointSend(endpoint_, 16 + length, buffer_.RawPtr(), cap_buffer_.UsedSlots(), cap_buffer_.RawPtr(), &reply_port_cap));
|
||||
|
||||
// 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()));
|
||||
|
|
|
@ -42,14 +42,15 @@ Thread {{interface.name}}ServerBase::RunServer() {
|
|||
|
||||
void {{interface.name}}ServerBase::ServerThread() {
|
||||
glcr::ByteBuffer recv_buffer(0x1000);
|
||||
glcr::CapBuffer recv_cap(0x10);
|
||||
glcr::ByteBuffer resp_buffer(0x1000);
|
||||
uint64_t resp_cap_size = 0x10;
|
||||
glcr::CapBuffer resp_cap(resp_cap_size);
|
||||
glcr::CapBuffer resp_cap(0x10);
|
||||
z_cap_t reply_port_cap;
|
||||
|
||||
while (true) {
|
||||
uint64_t recv_cap_size = 0x10;
|
||||
uint64_t recv_buf_size = 0x1000;
|
||||
glcr::ErrorCode recv_err = ZEndpointRecv(endpoint_, &recv_buf_size, recv_buffer.RawPtr(), &reply_port_cap);
|
||||
glcr::ErrorCode recv_err = ZEndpointRecv(endpoint_, &recv_buf_size, recv_buffer.RawPtr(), &recv_cap_size, recv_cap.RawPtr(), &reply_port_cap);
|
||||
if (recv_err != glcr::OK) {
|
||||
dbgln("Error in receive: %x", recv_err);
|
||||
continue;
|
||||
|
@ -58,7 +59,7 @@ void {{interface.name}}ServerBase::ServerThread() {
|
|||
uint64_t resp_length = 0;
|
||||
|
||||
glcr::ErrorCode reply_err = glcr::OK;
|
||||
glcr::ErrorCode err = HandleRequest(recv_buffer, resp_buffer, resp_length, resp_cap);
|
||||
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
|
||||
if (err != glcr::OK) {
|
||||
WriteError(resp_buffer, err);
|
||||
reply_err = ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr);
|
||||
|
@ -74,6 +75,7 @@ void {{interface.name}}ServerBase::ServerThread() {
|
|||
}
|
||||
|
||||
glcr::ErrorCode {{interface.name}}ServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||
const glcr::CapBuffer& req_caps,
|
||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
||||
glcr::CapBuffer& resp_caps) {
|
||||
if (request.At<uint32_t>(0) != kSentinel) {
|
||||
|
@ -88,7 +90,7 @@ glcr::ErrorCode {{interface.name}}ServerBase::HandleRequest(const glcr::ByteBuff
|
|||
{{method.request}} yunq_request;
|
||||
{{method.response}} yunq_response;
|
||||
|
||||
yunq_request.ParseFromBytes(request, kHeaderSize);
|
||||
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
||||
|
||||
RET_ERR(Handle{{method.name}}(yunq_request, yunq_response));
|
||||
|
||||
|
|
|
@ -30,8 +30,8 @@ class {{interface.name}}ServerBase {
|
|||
friend void {{interface.name}}ServerBaseThreadBootstrap(void*);
|
||||
void ServerThread();
|
||||
|
||||
[[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, glcr::ByteBuffer& response,
|
||||
uint64_t& resp_length,
|
||||
[[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
|
||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
||||
glcr::CapBuffer& resp_caps);
|
||||
};
|
||||
|
||||
|
|
|
@ -38,7 +38,9 @@
|
|||
## Capabilities
|
||||
|
||||
- Add syscalls for inspecting capabilities.
|
||||
- Add syscalls for restricting capabilities' permissions.
|
||||
- Randomize/obfuscate capability numbers passed to user space.
|
||||
- Remove ReplyPort capabilities once the response is sent.
|
||||
|
||||
## Scheduling
|
||||
|
||||
|
|
|
@ -2,90 +2,9 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "zcall_macros.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);
|
||||
|
||||
SYS1(ProcessExit, uint64_t, code);
|
||||
|
@ -127,10 +46,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);
|
||||
|
||||
SYS1(EndpointCreate, z_cap_t*, endpoint_cap);
|
||||
SYS4(EndpointSend, z_cap_t, endpoint_cap, uint64_t, num_bytes, const void*,
|
||||
data, z_cap_t*, reply_port_cap);
|
||||
SYS4(EndpointRecv, z_cap_t, endpoint_cap, uint64_t*, num_bytes, void*, data,
|
||||
z_cap_t*, reply_port_cap);
|
||||
SYS6(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);
|
||||
SYS6(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);
|
||||
SYS5(ReplyPortSend, z_cap_t, reply_port_cap, uint64_t, num_bytes, const void*,
|
||||
data, uint64_t, num_caps, z_cap_t*, caps);
|
||||
SYS5(ReplyPortRecv, z_cap_t, reply_port_cap, uint64_t*, num_bytes, void*, data,
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
#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); \
|
||||
}
|
|
@ -63,6 +63,8 @@ const uint64_t kZionDebug = 0x1'0000;
|
|||
|
||||
typedef uint64_t z_cap_t;
|
||||
|
||||
const uint64_t kZionInvalidCapability = 0x0;
|
||||
|
||||
// General Capability Permissions
|
||||
const uint64_t kZionPerm_Write = 0x1;
|
||||
const uint64_t kZionPerm_Read = 0x2;
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
#include "scheduler/scheduler.h"
|
||||
|
||||
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, const z_cap_t* caps,
|
||||
z_cap_t reply_cap) {
|
||||
if (num_bytes > 0x1000) {
|
||||
dbgln("Large message size unimplemented: %x", num_bytes);
|
||||
return glcr::UNIMPLEMENTED;
|
||||
|
@ -18,6 +18,12 @@ z_err_t UnboundedMessageQueue::PushBack(uint64_t num_bytes, const void* bytes,
|
|||
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++) {
|
||||
// FIXME: This would feel safer closer to the relevant syscall.
|
||||
// FIXME: Race conditions on get->check->release here. Would be better to
|
||||
|
@ -46,7 +52,8 @@ z_err_t UnboundedMessageQueue::PushBack(uint64_t num_bytes, const 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();
|
||||
while (pending_messages_.empty()) {
|
||||
auto thread = gScheduler->CurrentThread();
|
||||
|
@ -75,8 +82,16 @@ z_err_t UnboundedMessageQueue::PopFront(uint64_t* num_bytes, void* bytes,
|
|||
static_cast<uint8_t*>(bytes)[i] = next_msg->bytes[i];
|
||||
}
|
||||
|
||||
*num_caps = next_msg->caps.size();
|
||||
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();
|
||||
for (uint64_t i = 0; i < *num_caps; i++) {
|
||||
caps[i] = proc.AddExistingCapability(next_msg->caps.PopFront());
|
||||
}
|
||||
|
@ -102,7 +117,8 @@ void UnboundedMessageQueue::WriteKernel(uint64_t init,
|
|||
glcr::ErrorCode SingleMessageQueue::PushBack(uint64_t num_bytes,
|
||||
const void* bytes,
|
||||
uint64_t num_caps,
|
||||
const z_cap_t* caps) {
|
||||
const z_cap_t* caps,
|
||||
z_cap_t reply_port) {
|
||||
MutexHolder h(mutex_);
|
||||
if (has_written_) {
|
||||
return glcr::FAILED_PRECONDITION;
|
||||
|
@ -114,6 +130,11 @@ glcr::ErrorCode SingleMessageQueue::PushBack(uint64_t num_bytes,
|
|||
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++) {
|
||||
// FIXME: This would feel safer closer to the relevant syscall.
|
||||
auto cap = gScheduler->CurrentProcess().GetCapability(caps[i]);
|
||||
|
@ -139,8 +160,8 @@ glcr::ErrorCode SingleMessageQueue::PushBack(uint64_t num_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* caps,
|
||||
z_cap_t* reply_port) {
|
||||
mutex_.Lock();
|
||||
while (!has_written_) {
|
||||
auto thread = gScheduler->CurrentThread();
|
||||
|
@ -169,6 +190,11 @@ glcr::ErrorCode SingleMessageQueue::PopFront(uint64_t* num_bytes, void* bytes,
|
|||
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();
|
||||
auto& proc = gScheduler->CurrentProcess();
|
||||
for (uint64_t i = 0; i < *num_caps; i++) {
|
||||
|
|
|
@ -15,9 +15,11 @@ class MessageQueue {
|
|||
virtual ~MessageQueue() {}
|
||||
|
||||
virtual glcr::ErrorCode PushBack(uint64_t num_bytes, const void* bytes,
|
||||
uint64_t num_caps, const z_cap_t* caps) = 0;
|
||||
uint64_t num_caps, const z_cap_t* caps,
|
||||
z_cap_t reply_cap = 0) = 0;
|
||||
virtual glcr::ErrorCode PopFront(uint64_t* num_bytes, void* bytes,
|
||||
uint64_t* num_caps, z_cap_t* caps) = 0;
|
||||
uint64_t* num_caps, z_cap_t* caps,
|
||||
z_cap_t* reply_cap = nullptr) = 0;
|
||||
virtual bool empty() = 0;
|
||||
|
||||
protected:
|
||||
|
@ -35,9 +37,10 @@ class UnboundedMessageQueue : public MessageQueue {
|
|||
virtual ~UnboundedMessageQueue() override {}
|
||||
|
||||
glcr::ErrorCode PushBack(uint64_t num_bytes, const void* bytes,
|
||||
uint64_t num_caps, const z_cap_t* caps) override;
|
||||
uint64_t num_caps, const z_cap_t* caps,
|
||||
z_cap_t reply_cap) override;
|
||||
glcr::ErrorCode PopFront(uint64_t* num_bytes, void* bytes, uint64_t* num_caps,
|
||||
z_cap_t* caps) override;
|
||||
z_cap_t* caps, z_cap_t* reply_cap) override;
|
||||
|
||||
void WriteKernel(uint64_t init, glcr::RefPtr<Capability> cap);
|
||||
|
||||
|
@ -52,6 +55,7 @@ class UnboundedMessageQueue : public MessageQueue {
|
|||
uint8_t* bytes;
|
||||
|
||||
glcr::LinkedList<glcr::RefPtr<Capability>> caps;
|
||||
glcr::RefPtr<Capability> reply_cap;
|
||||
};
|
||||
|
||||
glcr::LinkedList<glcr::SharedPtr<Message>> pending_messages_;
|
||||
|
@ -65,9 +69,10 @@ class SingleMessageQueue : public MessageQueue {
|
|||
virtual ~SingleMessageQueue() override {}
|
||||
|
||||
glcr::ErrorCode PushBack(uint64_t num_bytes, const void* bytes,
|
||||
uint64_t num_caps, const z_cap_t* caps) override;
|
||||
uint64_t num_caps, const z_cap_t* caps,
|
||||
z_cap_t reply_cap) override;
|
||||
glcr::ErrorCode PopFront(uint64_t* num_bytes, void* bytes, uint64_t* num_caps,
|
||||
z_cap_t* caps) override;
|
||||
z_cap_t* caps, z_cap_t* reply_cap) override;
|
||||
|
||||
bool empty() override {
|
||||
MutexHolder h(mutex_);
|
||||
|
|
|
@ -5,3 +5,18 @@
|
|||
glcr::RefPtr<Endpoint> Endpoint::Create() {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -27,8 +27,11 @@ class Endpoint : public IpcObject {
|
|||
|
||||
static glcr::RefPtr<Endpoint> Create();
|
||||
|
||||
glcr::ErrorCode Read(uint64_t* num_bytes, void* data,
|
||||
z_cap_t* reply_port_cap);
|
||||
// FIXME: These are hacky "almost" overrides that could lead to bugs.
|
||||
glcr::ErrorCode Send(uint64_t num_bytes, const void* data, uint64_t num_caps,
|
||||
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 {
|
||||
return message_queue_;
|
||||
|
|
|
@ -106,7 +106,8 @@ glcr::ErrorCode EndpointSend(ZEndpointSendReq* req) {
|
|||
*req->reply_port_cap = proc.AddNewCapability(reply_port, kZionPerm_Read);
|
||||
uint64_t reply_port_cap_to_send =
|
||||
proc.AddNewCapability(reply_port, kZionPerm_Write | kZionPerm_Transmit);
|
||||
return endpoint->Send(req->num_bytes, req->data, 1, &reply_port_cap_to_send);
|
||||
return endpoint->Send(req->num_bytes, req->data, req->num_caps, req->caps,
|
||||
reply_port_cap_to_send);
|
||||
}
|
||||
|
||||
glcr::ErrorCode EndpointRecv(ZEndpointRecvReq* req) {
|
||||
|
@ -117,7 +118,7 @@ glcr::ErrorCode EndpointRecv(ZEndpointRecvReq* req) {
|
|||
auto endpoint = endpoint_cap->obj<Endpoint>();
|
||||
|
||||
uint64_t num_caps = 1;
|
||||
RET_ERR(endpoint->Recv(req->num_bytes, req->data, &num_caps,
|
||||
RET_ERR(endpoint->Recv(req->num_bytes, req->data, req->num_caps, req->caps,
|
||||
req->reply_port_cap));
|
||||
if (num_caps != 1) {
|
||||
return glcr::INTERNAL;
|
||||
|
|
Loading…
Reference in New Issue