diff --git a/lib/glacier/status/error.h b/lib/glacier/status/error.h index 95229d3..d8cbc78 100644 --- a/lib/glacier/status/error.h +++ b/lib/glacier/status/error.h @@ -4,37 +4,37 @@ namespace glcr { -typedef uint64_t ErrorCode; +enum ErrorCode : uint64_t { + OK = 0x0, + // First set of error codes generally indicate user errors. + INVALID_ARGUMENT = 0x1, + NOT_FOUND = 0x2, + PERMISSION_DENIED = 0x3, + NULL_PTR = 0x4, + EMPTY = 0x5, + ALREADY_EXISTS = 0x6, + BUFFER_SIZE = 0x7, + FAILED_PRECONDITION = 0x8, -#define RET_ERR(expr) \ - { \ - z_err_t _tmp_err = expr; \ - if (_tmp_err != glcr::OK) { \ - return _tmp_err; \ - } \ + // Second set of error codes generally indicate service errors. + INTERNAL = 0x100, + UNIMPLEMENTED = 0x101, + EXHAUSTED = 0x102, + INVALID_RESPONSE = 0x103, + + // Kernel specific error codes (relating to capabilities). + CAP_NOT_FOUND = 0x1000, + CAP_WRONG_TYPE = 0x1001, + CAP_PERMISSION_DENIED = 0x1002, + +}; + +#define RET_ERR(expr) \ + { \ + glcr::ErrorCode _tmp_err = static_cast(expr); \ + if (_tmp_err != glcr::OK) { \ + return _tmp_err; \ + } \ } -static const uint64_t OK = 0x0; - -// First set of error codes generally indicate user errors. -static const uint64_t INVALID_ARGUMENT = 0x1; -static const uint64_t NOT_FOUND = 0x2; -static const uint64_t PERMISSION_DENIED = 0x3; -static const uint64_t NULL_PTR = 0x4; -static const uint64_t EMPTY = 0x5; -static const uint64_t ALREADY_EXISTS = 0x6; -static const uint64_t BUFFER_SIZE = 0x7; -static const uint64_t FAILED_PRECONDITION = 0x8; - -// Second set of error codes generally indicate service errors. -static const uint64_t INTERNAL = 0x100; -static const uint64_t UNIMPLEMENTED = 0x101; -static const uint64_t EXHAUSTED = 0x102; -static const uint64_t INVALID_RESPONSE = 0x103; - -// Kernel specific error codes (relating to capabilities). -static const uint64_t CAP_NOT_FOUND = 0x1000; -static const uint64_t CAP_WRONG_TYPE = 0x1001; -static const uint64_t CAP_PERMISSION_DENIED = 0x1002; - } // namespace glcr diff --git a/lib/mammoth/include/mammoth/response_context.h b/lib/mammoth/include/mammoth/response_context.h index fbd0d2a..da5fcb1 100644 --- a/lib/mammoth/include/mammoth/response_context.h +++ b/lib/mammoth/include/mammoth/response_context.h @@ -29,7 +29,8 @@ class ResponseContext { code, }; written_ = true; - return ZReplyPortSend(reply_port_, sizeof(response), &response, 0, nullptr); + return static_cast( + ZReplyPortSend(reply_port_, sizeof(response), &response, 0, nullptr)); } bool HasWritten() { return written_; } diff --git a/lib/mammoth/src/endpoint_server.cpp b/lib/mammoth/src/endpoint_server.cpp index aa5a4c3..9e67cb6 100644 --- a/lib/mammoth/src/endpoint_server.cpp +++ b/lib/mammoth/src/endpoint_server.cpp @@ -23,9 +23,9 @@ void EndpointServer::ServerThread() { uint64_t message_size = kBufferSize; uint64_t reply_port_cap = 0; uint64_t num_caps = 0; - glcr::ErrorCode err = + glcr::ErrorCode err = static_cast( ZEndpointRecv(endpoint_cap_, &message_size, recieve_buffer_, &num_caps, - nullptr, &reply_port_cap); + nullptr, &reply_port_cap)); if (err != glcr::OK) { dbgln("Error in receive: %x", err); continue; diff --git a/lib/mammoth/src/mutex.cpp b/lib/mammoth/src/mutex.cpp index cca7223..dd49ce5 100644 --- a/lib/mammoth/src/mutex.cpp +++ b/lib/mammoth/src/mutex.cpp @@ -19,5 +19,9 @@ glcr::ErrorOr Mutex::Create() { return Mutex(mutex_cap); } -glcr::ErrorCode Mutex::Lock() { return ZMutexLock(mutex_cap_); } -glcr::ErrorCode Mutex::Release() { return ZMutexRelease(mutex_cap_); } +glcr::ErrorCode Mutex::Lock() { + return static_cast(ZMutexLock(mutex_cap_)); +} +glcr::ErrorCode Mutex::Release() { + return static_cast(ZMutexRelease(mutex_cap_)); +} diff --git a/lib/mammoth/src/port_client.cpp b/lib/mammoth/src/port_client.cpp index 64b2820..61ef1ef 100644 --- a/lib/mammoth/src/port_client.cpp +++ b/lib/mammoth/src/port_client.cpp @@ -9,5 +9,6 @@ PortClient PortClient::AdoptPort(z_cap_t cap) { return PortClient(cap); } PortClient::PortClient(z_cap_t port_cap) : port_cap_(port_cap) {} glcr::ErrorCode PortClient::WriteString(glcr::String str, z_cap_t cap) { - return ZPortSend(port_cap_, str.length() + 1, str.cstr(), 1, &cap); + return static_cast( + ZPortSend(port_cap_, str.length() + 1, str.cstr(), 1, &cap)); } diff --git a/lib/mammoth/src/port_server.cpp b/lib/mammoth/src/port_server.cpp index 13c0e83..c684104 100644 --- a/lib/mammoth/src/port_server.cpp +++ b/lib/mammoth/src/port_server.cpp @@ -31,7 +31,7 @@ glcr::ErrorCode PortServer::RecvCap(uint64_t *num_bytes, char *msg, return glcr::OK; } -z_err_t PortServer::PollForIntCap(uint64_t *msg, uint64_t *cap) { +glcr::ErrorCode PortServer::PollForIntCap(uint64_t *msg, uint64_t *cap) { uint64_t bytes = sizeof(uint64_t); uint64_t caps = 1; RET_ERR(ZPortPoll(port_cap_, &bytes, reinterpret_cast(msg), &caps, diff --git a/lib/mammoth/src/thread.cpp b/lib/mammoth/src/thread.cpp index 333f5ea..2d3eb8c 100644 --- a/lib/mammoth/src/thread.cpp +++ b/lib/mammoth/src/thread.cpp @@ -22,4 +22,6 @@ Thread::Thread(Entry e, const void* arg1) { reinterpret_cast(arg1))); } -glcr::ErrorCode Thread::Join() { return ZThreadWait(thread_cap_); } +glcr::ErrorCode Thread::Join() { + return static_cast(ZThreadWait(thread_cap_)); +} diff --git a/sys/denali/lib/denali/denali.yunq.server.cpp b/sys/denali/lib/denali/denali.yunq.server.cpp index 8d85e29..3e523da 100644 --- a/sys/denali/lib/denali/denali.yunq.server.cpp +++ b/sys/denali/lib/denali/denali.yunq.server.cpp @@ -51,7 +51,7 @@ void DenaliServerBase::ServerThread() { uint64_t recv_cap_size = 0x10; uint64_t recv_buf_size = 0x1000; recv_cap.Reset(); - 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 = static_cast(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; @@ -64,10 +64,10 @@ void DenaliServerBase::ServerThread() { 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); + reply_err = static_cast(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr)); } else { WriteHeader(resp_buffer, resp_length); - reply_err = ZReplyPortSend(reply_port_cap, kHeaderSize + resp_length, resp_buffer.RawPtr(), resp_cap.UsedSlots(), resp_cap.RawPtr()); + reply_err = static_cast(ZReplyPortSend(reply_port_cap, kHeaderSize + resp_length, resp_buffer.RawPtr(), resp_cap.UsedSlots(), resp_cap.RawPtr())); } if (reply_err != glcr::OK) { dbgln("Error in reply: %x", reply_err); diff --git a/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.server.cpp b/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.server.cpp index aa537ef..eea064d 100644 --- a/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.server.cpp +++ b/sys/victoriafalls/lib/victoriafalls/victoriafalls.yunq.server.cpp @@ -51,7 +51,7 @@ void VFSServerBase::ServerThread() { uint64_t recv_cap_size = 0x10; uint64_t recv_buf_size = 0x1000; recv_cap.Reset(); - 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 = static_cast(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; @@ -64,10 +64,10 @@ void VFSServerBase::ServerThread() { 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); + reply_err = static_cast(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr)); } else { WriteHeader(resp_buffer, resp_length); - reply_err = ZReplyPortSend(reply_port_cap, kHeaderSize + resp_length, resp_buffer.RawPtr(), resp_cap.UsedSlots(), resp_cap.RawPtr()); + reply_err = static_cast(ZReplyPortSend(reply_port_cap, kHeaderSize + resp_length, resp_buffer.RawPtr(), resp_cap.UsedSlots(), resp_cap.RawPtr())); } if (reply_err != glcr::OK) { dbgln("Error in reply: %x", reply_err); diff --git a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.cpp b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.cpp index 708c15b..ffa25aa 100644 --- a/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.cpp +++ b/sys/yellowstone/lib/yellowstone/yellowstone.yunq.server.cpp @@ -51,7 +51,7 @@ void YellowstoneServerBase::ServerThread() { uint64_t recv_cap_size = 0x10; uint64_t recv_buf_size = 0x1000; recv_cap.Reset(); - 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 = static_cast(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; @@ -64,10 +64,10 @@ void YellowstoneServerBase::ServerThread() { 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); + reply_err = static_cast(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr)); } else { WriteHeader(resp_buffer, resp_length); - reply_err = ZReplyPortSend(reply_port_cap, kHeaderSize + resp_length, resp_buffer.RawPtr(), resp_cap.UsedSlots(), resp_cap.RawPtr()); + reply_err = static_cast(ZReplyPortSend(reply_port_cap, kHeaderSize + resp_length, resp_buffer.RawPtr(), resp_cap.UsedSlots(), resp_cap.RawPtr())); } if (reply_err != glcr::OK) { dbgln("Error in reply: %x", reply_err); diff --git a/yunq/server.cpp.jinja b/yunq/server.cpp.jinja index c299c04..590027d 100644 --- a/yunq/server.cpp.jinja +++ b/yunq/server.cpp.jinja @@ -51,7 +51,7 @@ void {{interface.name}}ServerBase::ServerThread() { uint64_t recv_cap_size = 0x10; uint64_t recv_buf_size = 0x1000; recv_cap.Reset(); - 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 = static_cast(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; @@ -64,10 +64,10 @@ void {{interface.name}}ServerBase::ServerThread() { 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); + reply_err = static_cast(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr)); } else { WriteHeader(resp_buffer, resp_length); - reply_err = ZReplyPortSend(reply_port_cap, kHeaderSize + resp_length, resp_buffer.RawPtr(), resp_cap.UsedSlots(), resp_cap.RawPtr()); + reply_err = static_cast(ZReplyPortSend(reply_port_cap, kHeaderSize + resp_length, resp_buffer.RawPtr(), resp_cap.UsedSlots(), resp_cap.RawPtr())); } if (reply_err != glcr::OK) { dbgln("Error in reply: %x", reply_err); diff --git a/zion/capability/capability.h b/zion/capability/capability.h index 8f2c7fc..6a20183 100644 --- a/zion/capability/capability.h +++ b/zion/capability/capability.h @@ -48,8 +48,8 @@ glcr::RefPtr Capability::obj() { } template -z_err_t ValidateCapability(const glcr::RefPtr& cap, - uint64_t permissions) { +glcr::ErrorCode ValidateCapability(const glcr::RefPtr& cap, + uint64_t permissions) { if (!cap) { return glcr::CAP_NOT_FOUND; } diff --git a/zion/lib/message_queue.cpp b/zion/lib/message_queue.cpp index 5588ecf..9b3340c 100644 --- a/zion/lib/message_queue.cpp +++ b/zion/lib/message_queue.cpp @@ -3,9 +3,11 @@ #include "debug/debug.h" #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, - z_cap_t reply_cap) { +glcr::ErrorCode UnboundedMessageQueue::PushBack(uint64_t num_bytes, + const void* bytes, + 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; @@ -51,9 +53,10 @@ z_err_t UnboundedMessageQueue::PushBack(uint64_t num_bytes, const void* bytes, return glcr::OK; } -z_err_t UnboundedMessageQueue::PopFront(uint64_t* num_bytes, void* bytes, - uint64_t* num_caps, z_cap_t* caps, - z_cap_t* reply_cap) { +glcr::ErrorCode UnboundedMessageQueue::PopFront(uint64_t* num_bytes, + void* bytes, uint64_t* num_caps, + z_cap_t* caps, + z_cap_t* reply_cap) { mutex_->Lock(); while (pending_messages_.empty()) { auto thread = gScheduler->CurrentThread(); diff --git a/zion/syscall/ipc.cpp b/zion/syscall/ipc.cpp index e4d853c..f876825 100644 --- a/zion/syscall/ipc.cpp +++ b/zion/syscall/ipc.cpp @@ -6,7 +6,7 @@ #include "object/reply_port.h" #include "scheduler/scheduler.h" -z_err_t ChannelCreate(ZChannelCreateReq* req) { +glcr::ErrorCode ChannelCreate(ZChannelCreateReq* req) { auto& proc = gScheduler->CurrentProcess(); auto chan_pair = Channel::CreateChannelPair(); *req->channel1 = proc.AddNewCapability(chan_pair.first()); @@ -14,7 +14,7 @@ z_err_t ChannelCreate(ZChannelCreateReq* req) { return glcr::OK; } -z_err_t ChannelSend(ZChannelSendReq* req) { +glcr::ErrorCode ChannelSend(ZChannelSendReq* req) { auto& proc = gScheduler->CurrentProcess(); auto chan_cap = proc.GetCapability(req->chan_cap); RET_ERR(ValidateCapability(chan_cap, kZionPerm_Write)); @@ -23,7 +23,7 @@ z_err_t ChannelSend(ZChannelSendReq* req) { return chan->Send(req->num_bytes, req->data, req->num_caps, req->caps); } -z_err_t ChannelRecv(ZChannelRecvReq* req) { +glcr::ErrorCode ChannelRecv(ZChannelRecvReq* req) { auto& proc = gScheduler->CurrentProcess(); auto chan_cap = proc.GetCapability(req->chan_cap); RET_ERR(ValidateCapability(chan_cap, kZionPerm_Read)); @@ -32,14 +32,14 @@ z_err_t ChannelRecv(ZChannelRecvReq* req) { return chan->Recv(req->num_bytes, req->data, req->num_caps, req->caps); } -z_err_t PortCreate(ZPortCreateReq* req) { +glcr::ErrorCode PortCreate(ZPortCreateReq* req) { auto& proc = gScheduler->CurrentProcess(); auto port = glcr::MakeRefCounted(); *req->port_cap = proc.AddNewCapability(port); return glcr::OK; } -z_err_t PortSend(ZPortSendReq* req) { +glcr::ErrorCode PortSend(ZPortSendReq* req) { auto& proc = gScheduler->CurrentProcess(); auto port_cap = proc.GetCapability(req->port_cap); RET_ERR(ValidateCapability(port_cap, kZionPerm_Write)); @@ -48,7 +48,7 @@ z_err_t PortSend(ZPortSendReq* req) { return port->Send(req->num_bytes, req->data, req->num_caps, req->caps); } -z_err_t PortRecv(ZPortRecvReq* req) { +glcr::ErrorCode PortRecv(ZPortRecvReq* req) { auto& proc = gScheduler->CurrentProcess(); auto port_cap = proc.GetCapability(req->port_cap); RET_ERR(ValidateCapability(port_cap, kZionPerm_Read)); @@ -63,7 +63,7 @@ z_err_t PortRecv(ZPortRecvReq* req) { return port->Recv(req->num_bytes, req->data, req->num_caps, req->caps); } -z_err_t PortPoll(ZPortPollReq* req) { +glcr::ErrorCode PortPoll(ZPortPollReq* req) { auto& proc = gScheduler->CurrentProcess(); auto port_cap = proc.GetCapability(req->port_cap); RET_ERR(ValidateCapability(port_cap, kZionPerm_Read)); @@ -77,7 +77,7 @@ z_err_t PortPoll(ZPortPollReq* req) { return port->Recv(req->num_bytes, req->data, req->num_caps, req->caps); } -z_err_t IrqRegister(ZIrqRegisterReq* req) { +glcr::ErrorCode IrqRegister(ZIrqRegisterReq* req) { auto& proc = gScheduler->CurrentProcess(); if (req->irq_num != Z_IRQ_PCI_BASE) { // FIXME: Don't hardcode this nonsense.