Compare commits
2 Commits
bcd9cf09bc
...
7dd10a3e53
Author | SHA1 | Date |
---|---|---|
Drew Galbraith | 7dd10a3e53 | |
Drew Galbraith | e66706d381 |
|
@ -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<glcr::ErrorCode>(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
|
||||
|
|
|
@ -29,7 +29,8 @@ class ResponseContext {
|
|||
code,
|
||||
};
|
||||
written_ = true;
|
||||
return ZReplyPortSend(reply_port_, sizeof(response), &response, 0, nullptr);
|
||||
return static_cast<glcr::ErrorCode>(
|
||||
ZReplyPortSend(reply_port_, sizeof(response), &response, 0, nullptr));
|
||||
}
|
||||
|
||||
bool HasWritten() { return written_; }
|
||||
|
|
|
@ -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<glcr::ErrorCode>(
|
||||
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;
|
||||
|
|
|
@ -19,5 +19,9 @@ glcr::ErrorOr<Mutex> 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<glcr::ErrorCode>(ZMutexLock(mutex_cap_));
|
||||
}
|
||||
glcr::ErrorCode Mutex::Release() {
|
||||
return static_cast<glcr::ErrorCode>(ZMutexRelease(mutex_cap_));
|
||||
}
|
||||
|
|
|
@ -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<glcr::ErrorCode>(
|
||||
ZPortSend(port_cap_, str.length() + 1, str.cstr(), 1, &cap));
|
||||
}
|
||||
|
|
|
@ -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<uint8_t *>(msg), &caps,
|
||||
|
|
|
@ -22,4 +22,6 @@ Thread::Thread(Entry e, const void* arg1) {
|
|||
reinterpret_cast<uint64_t>(arg1)));
|
||||
}
|
||||
|
||||
glcr::ErrorCode Thread::Join() { return ZThreadWait(thread_cap_); }
|
||||
glcr::ErrorCode Thread::Join() {
|
||||
return static_cast<glcr::ErrorCode>(ZThreadWait(thread_cap_));
|
||||
}
|
||||
|
|
|
@ -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<glcr::ErrorCode>(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<glcr::ErrorCode>(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<glcr::ErrorCode>(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);
|
||||
|
|
|
@ -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<glcr::ErrorCode>(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<glcr::ErrorCode>(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<glcr::ErrorCode>(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);
|
||||
|
|
|
@ -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<glcr::ErrorCode>(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<glcr::ErrorCode>(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<glcr::ErrorCode>(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);
|
||||
|
|
|
@ -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<glcr::ErrorCode>(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<glcr::ErrorCode>(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<glcr::ErrorCode>(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);
|
||||
|
|
|
@ -48,8 +48,8 @@ glcr::RefPtr<T> Capability::obj() {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
z_err_t ValidateCapability(const glcr::RefPtr<Capability>& cap,
|
||||
uint64_t permissions) {
|
||||
glcr::ErrorCode ValidateCapability(const glcr::RefPtr<Capability>& cap,
|
||||
uint64_t permissions) {
|
||||
if (!cap) {
|
||||
return glcr::CAP_NOT_FOUND;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include "lib/message_queue.h"
|
||||
#include "object/ipc_object.h"
|
||||
#include "object/kernel_object.h"
|
||||
#include "usr/zcall_internal.h"
|
||||
|
||||
class Channel;
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include "object/ipc_object.h"
|
||||
#include "object/kernel_object.h"
|
||||
#include "object/thread.h"
|
||||
#include "usr/zcall_internal.h"
|
||||
|
||||
class Port;
|
||||
|
||||
|
|
|
@ -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<Channel>(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<Channel>(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<Port>();
|
||||
*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>(port_cap, kZionPerm_Write));
|
||||
|
@ -48,22 +48,16 @@ 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>(port_cap, kZionPerm_Read));
|
||||
|
||||
auto port = port_cap->obj<Port>();
|
||||
ZMessage message{
|
||||
.num_bytes = *req->num_bytes,
|
||||
.data = const_cast<void*>(req->data),
|
||||
.num_caps = *req->num_caps,
|
||||
.caps = req->caps,
|
||||
};
|
||||
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>(port_cap, kZionPerm_Read));
|
||||
|
@ -77,7 +71,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.
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "usr/zcall_internal.h"
|
||||
|
||||
z_err_t SysCall1(uint64_t number, const void* first) {
|
||||
z_err_t return_code;
|
||||
asm("syscall" : "=a"(return_code) : "D"(number), "S"(first) : "rcx", "r11");
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "include/ztypes.h"
|
||||
|
||||
struct ZMessage {
|
||||
uint64_t num_bytes;
|
||||
void* data;
|
||||
|
||||
uint64_t num_caps;
|
||||
z_cap_t* caps;
|
||||
};
|
Loading…
Reference in New Issue