Get rid of the type field on zmessage

This commit is contained in:
Drew Galbraith 2023-06-17 02:01:21 -07:00
parent 7bd6aa42b0
commit 685070d65e
13 changed files with 35 additions and 53 deletions

View File

@ -35,8 +35,7 @@ z_err_t Channel::WriteStr(const char* msg) {
if (!chan_cap_) {
return Z_ERR_NULL;
}
uint64_t type = 0;
return ZChannelSend(chan_cap_, type, strlen(msg),
return ZChannelSend(chan_cap_, strlen(msg),
reinterpret_cast<const uint8_t*>(msg), 0, 0);
}
@ -44,10 +43,9 @@ z_err_t Channel::ReadStr(char* buffer, uint64_t* size) {
if (!chan_cap_) {
return Z_ERR_NULL;
}
uint64_t type;
uint64_t num_caps;
return ZChannelRecv(chan_cap_, *size, reinterpret_cast<uint8_t*>(buffer), 0,
0, &type, size, &num_caps);
0, size, &num_caps);
}
z_err_t CreateChannels(Channel& c1, Channel& c2) {

View File

@ -7,10 +7,10 @@
Port::Port(uint64_t port_cap) : port_cap_(port_cap) {}
z_err_t Port::PollForIntCap(uint64_t *msg, uint64_t *cap) {
uint64_t bytes, caps, type;
uint64_t bytes, caps;
RET_ERR(ZPortPoll(port_cap_, sizeof(uint64_t),
reinterpret_cast<uint8_t *>(msg), /* num_caps= */ 1, cap,
&type, &bytes, &caps));
&bytes, &caps));
if (bytes != sizeof(uint64_t)) {
return Z_ERR_INVALID;

View File

@ -140,8 +140,8 @@ void AhciDriver::DumpPorts() {
void AhciDriver::InterruptLoop() {
dbgln("Starting interrupt loop");
while (true) {
uint64_t type, bytes, caps;
check(ZPortRecv(irq_port_cap_, 0, 0, 0, 0, &type, &bytes, &caps));
uint64_t bytes, caps;
check(ZPortRecv(irq_port_cap_, 0, 0, 0, 0, &bytes, &caps));
for (uint64_t i = 0; i < 32; i++) {
if (devices_[i] != nullptr && devices_[i]->IsInit() &&
(ahci_hba_->interrupt_status & (1 << i))) {

View File

@ -19,9 +19,13 @@ z_err_t DenaliServer::RunServer() {
while (true) {
uint64_t buff_size = kBuffSize;
uint64_t cap_size = 0;
uint64_t type = DENALI_INVALID;
RET_ERR(ZChannelRecv(channel_cap_, buff_size, read_buffer_, 0, nullptr,
&type, &buff_size, &cap_size));
&buff_size, &cap_size));
if (buff_size < sizeof(uint64_t)) {
dbgln("Skipping invalid message");
continue;
}
uint64_t type = *reinterpret_cast<uint64_t*>(read_buffer_);
switch (type) {
case Z_INVALID:
dbgln(reinterpret_cast<char*>(read_buffer_));
@ -55,6 +59,6 @@ void DenaliServer::HandleResponse(uint64_t lba, uint64_t size, uint64_t cap) {
.lba = lba,
.size = size,
};
check(ZChannelSend(channel_cap_, DENALI_READ, sizeof(resp),
check(ZChannelSend(channel_cap_, sizeof(resp),
reinterpret_cast<uint8_t*>(&resp), 1, &cap));
}

View File

@ -6,6 +6,7 @@
#define DENALI_READ 100
struct DenaliRead {
uint64_t request_type = DENALI_READ;
uint64_t device_id;
uint64_t lba;

View File

@ -22,17 +22,15 @@ uint64_t main(uint64_t port_cap) {
.lba = 0,
.size = 1,
};
check(ZChannelSend(local.cap(), DENALI_READ, sizeof(DenaliRead),
check(ZChannelSend(local.cap(), sizeof(DenaliRead),
reinterpret_cast<uint8_t*>(&read), 0, nullptr));
DenaliReadResponse resp;
uint64_t mem_cap, type, bytes, caps;
uint64_t mem_cap, bytes, caps;
check(ZChannelRecv(local.cap(), sizeof(resp),
reinterpret_cast<uint8_t*>(&resp), 1, &mem_cap, &type,
&bytes, &caps));
dbgln("Resp: %u", type);
reinterpret_cast<uint8_t*>(&resp), 1, &mem_cap, &bytes,
&caps));
check(ZAddressSpaceMap(gSelfVmasCap, 0, mem_cap, &vaddr));
uint32_t* mbr = reinterpret_cast<uint32_t*>(vaddr + 0x1FE);

View File

@ -36,13 +36,12 @@ void ZThreadExit();
uint64_t* vmmo_size);
[[nodiscard]] z_err_t ZChannelCreate(z_cap_t* channel1, z_cap_t* channel2);
[[nodiscard]] z_err_t ZChannelSend(z_cap_t chan_cap, uint64_t type,
uint64_t num_bytes, const uint8_t* bytes,
uint64_t num_caps, const z_cap_t* caps);
[[nodiscard]] z_err_t ZChannelSend(z_cap_t chan_cap, uint64_t num_bytes,
const uint8_t* bytes, uint64_t num_caps,
const z_cap_t* caps);
[[nodiscard]] z_err_t ZChannelRecv(z_cap_t chan_cap, uint64_t num_bytes,
uint8_t* bytes, uint64_t num_caps,
z_cap_t* caps, uint64_t* type,
uint64_t* actual_bytes,
z_cap_t* caps, uint64_t* actual_bytes,
uint64_t* actual_caps);
[[nodiscard]] z_err_t ZPortCreate(z_cap_t* port_cap);
@ -51,12 +50,12 @@ void ZThreadExit();
z_cap_t* caps);
[[nodiscard]] z_err_t ZPortRecv(z_cap_t port_cap, uint64_t num_bytes,
uint8_t* bytes, uint64_t num_caps,
z_cap_t* caps, uint64_t* type,
uint64_t* actual_bytes, uint64_t* actual_caps);
z_cap_t* caps, uint64_t* actual_bytes,
uint64_t* actual_caps);
[[nodiscard]] z_err_t ZPortPoll(z_cap_t port_cap, uint64_t num_bytes,
uint8_t* bytes, uint64_t num_caps,
z_cap_t* caps, uint64_t* type,
uint64_t* actual_bytes, uint64_t* actual_caps);
z_cap_t* caps, uint64_t* actual_bytes,
uint64_t* actual_caps);
[[nodiscard]] z_err_t ZIrqRegister(uint64_t irq_num, z_cap_t* port_cap);
[[nodiscard]] z_err_t ZCapDuplicate(z_cap_t cap_in, z_cap_t* cap_out);

View File

@ -34,7 +34,6 @@ z_err_t Channel::Read(ZMessage& msg) {
return Z_ERR_BUFF_SIZE;
}
msg.type = next_msg->type;
msg.num_bytes = next_msg->num_bytes;
for (uint64_t i = 0; i < msg.num_bytes; i++) {
@ -59,7 +58,6 @@ z_err_t Channel::EnqueueMessage(const ZMessage& msg) {
}
auto message = MakeShared<Message>();
message->type = msg.type;
// Copy Message body.
message->num_bytes = msg.num_bytes;

View File

@ -35,8 +35,6 @@ class Channel : public KernelObject {
Mutex mutex_{"channel"};
struct Message {
uint64_t type;
uint64_t num_bytes;
uint8_t* bytes;

View File

@ -11,7 +11,7 @@ z_err_t Port::Write(const ZMessage& msg) {
}
auto message = MakeShared<Message>();
message->type = msg.type, message->num_bytes = msg.num_bytes;
message->num_bytes = msg.num_bytes;
message->bytes = new uint8_t[msg.num_bytes];
for (uint64_t i = 0; i < msg.num_bytes; i++) {
message->bytes[i] = msg.bytes[i];
@ -54,7 +54,6 @@ z_err_t Port::Read(ZMessage& msg) {
return Z_ERR_BUFF_SIZE;
}
msg.type = next_msg->type;
msg.num_bytes = next_msg->num_bytes;
for (uint64_t i = 0; i < msg.num_bytes; i++) {
@ -76,7 +75,6 @@ void Port::WriteKernel(uint64_t init, RefPtr<Capability> cap) {
MutexHolder h(mutex_);
auto msg = MakeShared<Message>();
msg->type = 0;
msg->bytes = new uint8_t[8];
msg->num_bytes = sizeof(init);

View File

@ -30,7 +30,6 @@ class Port : public KernelObject {
private:
struct Message {
uint64_t type;
uint64_t num_bytes;
uint8_t* bytes;

View File

@ -125,14 +125,12 @@ z_err_t ZChannelCreate(z_cap_t* channel1, z_cap_t* channel2) {
return ret;
}
z_err_t ZChannelSend(z_cap_t chan_cap, uint64_t type, uint64_t num_bytes,
const uint8_t* bytes, uint64_t num_caps,
const z_cap_t* caps) {
z_err_t ZChannelSend(z_cap_t chan_cap, uint64_t num_bytes, const uint8_t* bytes,
uint64_t num_caps, const z_cap_t* caps) {
ZChannelSendReq req{
.chan_cap = chan_cap,
.message =
{
.type = type,
.num_bytes = num_bytes,
.bytes = const_cast<uint8_t*>(bytes),
.num_caps = num_caps,
@ -143,13 +141,12 @@ z_err_t ZChannelSend(z_cap_t chan_cap, uint64_t type, uint64_t num_bytes,
}
z_err_t ZChannelRecv(z_cap_t chan_cap, uint64_t num_bytes, uint8_t* bytes,
uint64_t num_caps, z_cap_t* caps, uint64_t* type,
uint64_t* actual_bytes, uint64_t* actual_caps) {
uint64_t num_caps, z_cap_t* caps, uint64_t* actual_bytes,
uint64_t* actual_caps) {
ZChannelRecvReq req{
.chan_cap = chan_cap,
.message =
{
.type = 0,
.num_bytes = num_bytes,
.bytes = bytes,
.num_caps = num_caps,
@ -157,7 +154,6 @@ z_err_t ZChannelRecv(z_cap_t chan_cap, uint64_t num_bytes, uint8_t* bytes,
},
};
z_err_t ret = SysCall1(Z_CHANNEL_RECV, &req);
*type = req.message.type;
*actual_bytes = req.message.num_bytes;
*actual_caps = req.message.num_caps;
return ret;
@ -174,7 +170,6 @@ z_err_t ZPortSend(z_cap_t port_cap, uint64_t num_bytes, const uint8_t* bytes,
uint64_t num_caps, z_cap_t* caps) {
ZPortSendReq req{.port_cap = port_cap,
.message = {
.type = 0,
.num_bytes = num_bytes,
.bytes = const_cast<uint8_t*>(bytes),
.num_caps = num_caps,
@ -184,13 +179,12 @@ z_err_t ZPortSend(z_cap_t port_cap, uint64_t num_bytes, const uint8_t* bytes,
}
z_err_t ZPortRecv(z_cap_t port_cap, uint64_t num_bytes, uint8_t* bytes,
uint64_t num_caps, z_cap_t* caps, uint64_t* type,
uint64_t* actual_bytes, uint64_t* actual_caps) {
uint64_t num_caps, z_cap_t* caps, uint64_t* actual_bytes,
uint64_t* actual_caps) {
ZPortRecvReq req{
.port_cap = port_cap,
.message =
{
.type = 0,
.num_bytes = num_bytes,
.bytes = bytes,
.num_caps = num_caps,
@ -198,20 +192,18 @@ z_err_t ZPortRecv(z_cap_t port_cap, uint64_t num_bytes, uint8_t* bytes,
},
};
z_err_t ret = SysCall1(Z_PORT_RECV, &req);
*type = req.message.type;
*actual_bytes = req.message.num_bytes;
*actual_caps = req.message.num_caps;
return ret;
}
z_err_t ZPortPoll(z_cap_t port_cap, uint64_t num_bytes, uint8_t* bytes,
uint64_t num_caps, z_cap_t* caps, uint64_t* type,
uint64_t* actual_bytes, uint64_t* actual_caps) {
uint64_t num_caps, z_cap_t* caps, uint64_t* actual_bytes,
uint64_t* actual_caps) {
ZPortRecvReq req{
.port_cap = port_cap,
.message =
{
.type = 0,
.num_bytes = num_bytes,
.bytes = bytes,
.num_caps = num_caps,
@ -219,7 +211,6 @@ z_err_t ZPortPoll(z_cap_t port_cap, uint64_t num_bytes, uint8_t* bytes,
},
};
z_err_t ret = SysCall1(Z_PORT_POLL, &req);
*type = req.message.type;
*actual_bytes = req.message.num_bytes;
*actual_caps = req.message.num_caps;
return ret;

View File

@ -69,8 +69,6 @@ struct ZChannelCreateResp {
};
struct ZMessage {
uint64_t type;
uint64_t num_bytes;
uint8_t* bytes;