From 685070d65e8ff4d5a728460335978aa842640874 Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Sat, 17 Jun 2023 02:01:21 -0700 Subject: [PATCH] Get rid of the type field on zmessage --- lib/mammoth/src/channel.cpp | 6 ++---- lib/mammoth/src/port.cpp | 4 ++-- sys/denali/ahci/ahci_driver.cpp | 4 ++-- sys/denali/denali_server.cpp | 10 +++++++--- sys/denali/include/denali/denali.h | 1 + sys/yellowstone/yellowstone.cpp | 10 ++++------ zion/include/zcall.h | 17 ++++++++--------- zion/object/channel.cpp | 2 -- zion/object/channel.h | 2 -- zion/object/port.cpp | 4 +--- zion/object/port.h | 1 - zion/usr/zcall.cpp | 25 ++++++++----------------- zion/usr/zcall_internal.h | 2 -- 13 files changed, 35 insertions(+), 53 deletions(-) diff --git a/lib/mammoth/src/channel.cpp b/lib/mammoth/src/channel.cpp index 39e30ee..0a3b7ad 100644 --- a/lib/mammoth/src/channel.cpp +++ b/lib/mammoth/src/channel.cpp @@ -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(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(buffer), 0, - 0, &type, size, &num_caps); + 0, size, &num_caps); } z_err_t CreateChannels(Channel& c1, Channel& c2) { diff --git a/lib/mammoth/src/port.cpp b/lib/mammoth/src/port.cpp index 4224a4b..9942757 100644 --- a/lib/mammoth/src/port.cpp +++ b/lib/mammoth/src/port.cpp @@ -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(msg), /* num_caps= */ 1, cap, - &type, &bytes, &caps)); + &bytes, &caps)); if (bytes != sizeof(uint64_t)) { return Z_ERR_INVALID; diff --git a/sys/denali/ahci/ahci_driver.cpp b/sys/denali/ahci/ahci_driver.cpp index 27aafe1..c7d036e 100644 --- a/sys/denali/ahci/ahci_driver.cpp +++ b/sys/denali/ahci/ahci_driver.cpp @@ -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))) { diff --git a/sys/denali/denali_server.cpp b/sys/denali/denali_server.cpp index 686032a..b819061 100644 --- a/sys/denali/denali_server.cpp +++ b/sys/denali/denali_server.cpp @@ -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(read_buffer_); switch (type) { case Z_INVALID: dbgln(reinterpret_cast(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(&resp), 1, &cap)); } diff --git a/sys/denali/include/denali/denali.h b/sys/denali/include/denali/denali.h index ba51636..806592a 100644 --- a/sys/denali/include/denali/denali.h +++ b/sys/denali/include/denali/denali.h @@ -6,6 +6,7 @@ #define DENALI_READ 100 struct DenaliRead { + uint64_t request_type = DENALI_READ; uint64_t device_id; uint64_t lba; diff --git a/sys/yellowstone/yellowstone.cpp b/sys/yellowstone/yellowstone.cpp index 8fc5cc5..954321e 100644 --- a/sys/yellowstone/yellowstone.cpp +++ b/sys/yellowstone/yellowstone.cpp @@ -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(&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(&resp), 1, &mem_cap, &type, - &bytes, &caps)); - - dbgln("Resp: %u", type); + reinterpret_cast(&resp), 1, &mem_cap, &bytes, + &caps)); check(ZAddressSpaceMap(gSelfVmasCap, 0, mem_cap, &vaddr)); uint32_t* mbr = reinterpret_cast(vaddr + 0x1FE); diff --git a/zion/include/zcall.h b/zion/include/zcall.h index 82679ab..f2295a8 100644 --- a/zion/include/zcall.h +++ b/zion/include/zcall.h @@ -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); diff --git a/zion/object/channel.cpp b/zion/object/channel.cpp index fdaf05c..d1365a9 100644 --- a/zion/object/channel.cpp +++ b/zion/object/channel.cpp @@ -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->type = msg.type; // Copy Message body. message->num_bytes = msg.num_bytes; diff --git a/zion/object/channel.h b/zion/object/channel.h index 80d44c2..6349cf2 100644 --- a/zion/object/channel.h +++ b/zion/object/channel.h @@ -35,8 +35,6 @@ class Channel : public KernelObject { Mutex mutex_{"channel"}; struct Message { - uint64_t type; - uint64_t num_bytes; uint8_t* bytes; diff --git a/zion/object/port.cpp b/zion/object/port.cpp index 22a0dda..cdc3b22 100644 --- a/zion/object/port.cpp +++ b/zion/object/port.cpp @@ -11,7 +11,7 @@ z_err_t Port::Write(const ZMessage& msg) { } auto message = MakeShared(); - 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 cap) { MutexHolder h(mutex_); auto msg = MakeShared(); - msg->type = 0; msg->bytes = new uint8_t[8]; msg->num_bytes = sizeof(init); diff --git a/zion/object/port.h b/zion/object/port.h index baff201..c0e5b1d 100644 --- a/zion/object/port.h +++ b/zion/object/port.h @@ -30,7 +30,6 @@ class Port : public KernelObject { private: struct Message { - uint64_t type; uint64_t num_bytes; uint8_t* bytes; diff --git a/zion/usr/zcall.cpp b/zion/usr/zcall.cpp index a663cc3..e871cbc 100644 --- a/zion/usr/zcall.cpp +++ b/zion/usr/zcall.cpp @@ -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(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(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; diff --git a/zion/usr/zcall_internal.h b/zion/usr/zcall_internal.h index 2eece32..105bbb3 100644 --- a/zion/usr/zcall_internal.h +++ b/zion/usr/zcall_internal.h @@ -69,8 +69,6 @@ struct ZChannelCreateResp { }; struct ZMessage { - uint64_t type; - uint64_t num_bytes; uint8_t* bytes;