Migrate to error constants in glacier
This commit is contained in:
parent
3ab9b4d818
commit
0b86a94f14
30 changed files with 171 additions and 114 deletions
|
|
@ -1,5 +1,7 @@
|
|||
#include "boot/acpi.h"
|
||||
|
||||
#include <glacier/status/error.h>
|
||||
|
||||
#include "boot/boot_info.h"
|
||||
#include "debug/debug.h"
|
||||
|
||||
|
|
@ -255,10 +257,10 @@ void ProbeRsdp() {
|
|||
|
||||
z_err_t GetPciExtendedConfiguration(uint64_t* base, uint64_t* offset) {
|
||||
if (gPcieEcSize == 0) {
|
||||
return Z_ERR_NOT_FOUND;
|
||||
return glcr::NOT_FOUND;
|
||||
}
|
||||
|
||||
*base = gPcieEcBase;
|
||||
*offset = gPcieEcSize;
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <glacier/memory/ref_counted.h>
|
||||
#include <glacier/memory/ref_ptr.h>
|
||||
#include <glacier/status/error.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "include/ztypes.h"
|
||||
|
|
@ -46,18 +47,18 @@ template <typename T>
|
|||
z_err_t ValidateCapability(const glcr::RefPtr<Capability>& cap,
|
||||
uint64_t permissions) {
|
||||
if (!cap) {
|
||||
return Z_ERR_CAP_NOT_FOUND;
|
||||
return glcr::CAP_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (cap->raw_obj()->TypeTag() != KernelObjectTag<T>::type) {
|
||||
return Z_ERR_CAP_TYPE;
|
||||
return glcr::CAP_WRONG_TYPE;
|
||||
}
|
||||
|
||||
if (!cap->HasPermissions(permissions)) {
|
||||
return Z_ERR_CAP_DENIED;
|
||||
return glcr::CAP_PERMISSION_DENIED;
|
||||
}
|
||||
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
#define RET_IF_NULL(expr) \
|
||||
|
|
|
|||
|
|
@ -8,14 +8,6 @@ void dbg(const char* fmt, ...);
|
|||
void dbgln(const char* str, ...);
|
||||
void panic(const char* str, ...);
|
||||
|
||||
#define RET_ERR(expr) \
|
||||
{ \
|
||||
z_err_t _tmp_err = expr; \
|
||||
if (_tmp_err != Z_OK) { \
|
||||
return _tmp_err; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define UNREACHABLE \
|
||||
panic("Unreachable %s, %s", __FILE__, __LINE__); \
|
||||
__builtin_unreachable();
|
||||
|
|
|
|||
|
|
@ -2,27 +2,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
/* ------------------------------
|
||||
* Error Types
|
||||
*
|
||||
* Bit 31 always set to 1 to
|
||||
* distinguish from user-space errors.
|
||||
* ------------------------------*/
|
||||
#define Z_OK 0x0
|
||||
|
||||
#define Z_ERR_NOT_FOUND 0x1000'0001
|
||||
#define Z_ERR_INVALID 0x1000'0002
|
||||
#define Z_ERR_DENIED 0x1000'0003
|
||||
#define Z_ERR_UNIMPLEMENTED 0x1000'0004
|
||||
#define Z_ERR_BUFF_SIZE 001000'0005
|
||||
#define Z_ERR_NULL 0x1000'0006
|
||||
#define Z_ERR_EXISTS 0x1000'0007
|
||||
#define Z_ERR_EMPTY 0x1000'0008
|
||||
|
||||
#define Z_ERR_CAP_NOT_FOUND 0x1001'0000
|
||||
#define Z_ERR_CAP_TYPE 0x1001'0001
|
||||
#define Z_ERR_CAP_DENIED 0x1001'0002
|
||||
|
||||
// Error codes defined in glacier/status/error.h
|
||||
typedef uint64_t z_err_t;
|
||||
|
||||
/* ------------------------------
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ z_err_t UnboundedMessageQueue::PushBack(uint64_t num_bytes, const void* bytes,
|
|||
const z_cap_t* caps) {
|
||||
if (num_bytes > 0x1000) {
|
||||
dbgln("Large message size unimplemented: %x", num_bytes);
|
||||
return Z_ERR_UNIMPLEMENTED;
|
||||
return glcr::UNIMPLEMENTED;
|
||||
}
|
||||
|
||||
auto message = glcr::MakeShared<Message>();
|
||||
|
|
@ -21,23 +21,23 @@ z_err_t UnboundedMessageQueue::PushBack(uint64_t num_bytes, const void* bytes,
|
|||
// FIXME: This would feel safer closer to the relevant syscall.
|
||||
auto cap = gScheduler->CurrentProcess().ReleaseCapability(caps[i]);
|
||||
if (!cap) {
|
||||
return Z_ERR_CAP_NOT_FOUND;
|
||||
return glcr::CAP_NOT_FOUND;
|
||||
}
|
||||
message->caps.PushBack(cap);
|
||||
}
|
||||
|
||||
pending_messages_.PushBack(message);
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
z_err_t UnboundedMessageQueue::PopFront(uint64_t* num_bytes, void* bytes,
|
||||
uint64_t* num_caps, z_cap_t* caps) {
|
||||
auto next_msg = pending_messages_.PeekFront();
|
||||
if (next_msg->num_bytes > *num_bytes) {
|
||||
return Z_ERR_BUFF_SIZE;
|
||||
return glcr::BUFFER_SIZE;
|
||||
}
|
||||
if (next_msg->caps.size() > *num_caps) {
|
||||
return Z_ERR_BUFF_SIZE;
|
||||
return glcr::BUFFER_SIZE;
|
||||
}
|
||||
|
||||
next_msg = pending_messages_.PopFront();
|
||||
|
|
@ -53,7 +53,7 @@ z_err_t UnboundedMessageQueue::PopFront(uint64_t* num_bytes, void* bytes,
|
|||
for (uint64_t i = 0; i < *num_caps; i++) {
|
||||
caps[i] = proc.AddExistingCapability(next_msg->caps.PopFront());
|
||||
}
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
void UnboundedMessageQueue::WriteKernel(uint64_t init,
|
||||
|
|
|
|||
|
|
@ -44,5 +44,5 @@ z_err_t Channel::WriteInternal(uint64_t num_bytes, const void* bytes,
|
|||
thread->SetState(Thread::RUNNABLE);
|
||||
gScheduler->Enqueue(thread);
|
||||
}
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ z_err_t Port::Write(uint64_t num_bytes, const void* bytes, uint64_t num_caps,
|
|||
thread->SetState(Thread::RUNNABLE);
|
||||
gScheduler->Enqueue(thread);
|
||||
}
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
z_err_t Port::Read(uint64_t* num_bytes, void* bytes, uint64_t* num_caps,
|
||||
|
|
|
|||
|
|
@ -20,5 +20,5 @@ z_err_t AddressSpaceMap(ZAddressSpaceMapReq* req) {
|
|||
} else {
|
||||
*req->vaddr = vmas->MapInMemoryObject(vmmo);
|
||||
}
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
#include "syscall/capability.h"
|
||||
|
||||
#include <glacier/status/error.h>
|
||||
|
||||
#include "scheduler/scheduler.h"
|
||||
|
||||
z_err_t CapDuplicate(ZCapDuplicateReq* req) {
|
||||
auto& proc = gScheduler->CurrentProcess();
|
||||
auto cap = proc.GetCapability(req->cap_in);
|
||||
if (!cap) {
|
||||
return Z_ERR_CAP_NOT_FOUND;
|
||||
return glcr::CAP_NOT_FOUND;
|
||||
}
|
||||
*req->cap_out = proc.AddExistingCapability(cap);
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ z_err_t ChannelCreate(ZChannelCreateReq* req) {
|
|||
*req->channel1 = proc.AddNewCapability(chan_pair.first(), ZC_WRITE | ZC_READ);
|
||||
*req->channel2 =
|
||||
proc.AddNewCapability(chan_pair.second(), ZC_WRITE | ZC_READ);
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
z_err_t ChannelSend(ZChannelSendReq* req) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
#include "syscall/debug.h"
|
||||
|
||||
#include <glacier/status/error.h>
|
||||
|
||||
#include "debug/debug.h"
|
||||
|
||||
z_err_t Debug(ZDebugReq* req) {
|
||||
dbgln("[Debug] %s", req->message);
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ z_err_t MemoryObjectCreate(ZMemoryObjectCreateReq* req) {
|
|||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
*req->vmmo_cap = curr_proc.AddNewCapability(
|
||||
glcr::MakeRefCounted<MemoryObject>(req->size), ZC_WRITE);
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
z_err_t MemoryObjectCreatePhysical(ZMemoryObjectCreatePhysicalReq* req) {
|
||||
|
|
@ -17,7 +17,7 @@ z_err_t MemoryObjectCreatePhysical(ZMemoryObjectCreatePhysicalReq* req) {
|
|||
auto vmmo_ref = glcr::MakeRefCounted<FixedMemoryObject>(paddr, req->size);
|
||||
*req->vmmo_cap = curr_proc.AddNewCapability(
|
||||
StaticCastRefPtr<MemoryObject>(vmmo_ref), ZC_WRITE);
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
z_err_t MemoryObjectCreateContiguous(ZMemoryObjectCreateContiguousReq* req) {
|
||||
|
|
@ -27,7 +27,7 @@ z_err_t MemoryObjectCreateContiguous(ZMemoryObjectCreateContiguousReq* req) {
|
|||
*req->vmmo_cap = curr_proc.AddNewCapability(
|
||||
StaticCastRefPtr<MemoryObject>(vmmo_ref), ZC_WRITE);
|
||||
*req->paddr = paddr;
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
z_err_t TempPcieConfigObjectCreate(ZTempPcieConfigObjectCreateReq* req) {
|
||||
|
|
@ -38,5 +38,5 @@ z_err_t TempPcieConfigObjectCreate(ZTempPcieConfigObjectCreateReq* req) {
|
|||
*req->vmmo_cap = curr_proc.AddNewCapability(
|
||||
StaticCastRefPtr<MemoryObject>(vmmo_ref), ZC_WRITE);
|
||||
*req->vmmo_size = pci_size;
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include "syscall/port.h"
|
||||
|
||||
#include <glacier/status/error.h>
|
||||
|
||||
#include "capability/capability.h"
|
||||
#include "interrupt/interrupt.h"
|
||||
#include "scheduler/scheduler.h"
|
||||
|
|
@ -8,7 +10,7 @@ z_err_t PortCreate(ZPortCreateReq* req) {
|
|||
auto& proc = gScheduler->CurrentProcess();
|
||||
auto port = glcr::MakeRefCounted<Port>();
|
||||
*req->port_cap = proc.AddNewCapability(port, ZC_WRITE | ZC_READ);
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
z_err_t PortSend(ZPortSendReq* req) {
|
||||
|
|
@ -44,7 +46,7 @@ z_err_t PortPoll(ZPortPollReq* req) {
|
|||
// FIXME: Race condition here where this call could block if the last message
|
||||
// is removed between this check and the port read.
|
||||
if (!port->HasMessages()) {
|
||||
return Z_ERR_EMPTY;
|
||||
return glcr::EMPTY;
|
||||
}
|
||||
return port->Read(req->num_bytes, req->data, req->num_caps, req->caps);
|
||||
}
|
||||
|
|
@ -53,10 +55,10 @@ z_err_t IrqRegister(ZIrqRegisterReq* req) {
|
|||
auto& proc = gScheduler->CurrentProcess();
|
||||
if (req->irq_num != Z_IRQ_PCI_BASE) {
|
||||
// FIXME: Don't hardcode this nonsense.
|
||||
return Z_ERR_UNIMPLEMENTED;
|
||||
return glcr::UNIMPLEMENTED;
|
||||
}
|
||||
glcr::RefPtr<Port> port = glcr::MakeRefCounted<Port>();
|
||||
*req->port_cap = proc.AddNewCapability(port, ZC_READ | ZC_WRITE);
|
||||
RegisterPciPort(port);
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ z_err_t ProcessExit(ZProcessExitReq* req) {
|
|||
// FIXME: kill process here.
|
||||
curr_thread->Exit();
|
||||
panic("Returned from thread exit");
|
||||
return Z_ERR_UNIMPLEMENTED;
|
||||
return glcr::UNIMPLEMENTED;
|
||||
}
|
||||
|
||||
z_err_t ProcessSpawn(ZProcessSpawnReq* req) {
|
||||
|
|
@ -28,11 +28,11 @@ z_err_t ProcessSpawn(ZProcessSpawnReq* req) {
|
|||
if (req->bootstrap_cap != 0) {
|
||||
auto cap = curr_proc.ReleaseCapability(req->bootstrap_cap);
|
||||
if (!cap) {
|
||||
return Z_ERR_CAP_NOT_FOUND;
|
||||
return glcr::CAP_NOT_FOUND;
|
||||
}
|
||||
// FIXME: Check permissions.
|
||||
*req->new_bootstrap_cap = proc->AddExistingCapability(cap);
|
||||
}
|
||||
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ extern "C" z_err_t SyscallHandler(uint64_t call_id, void* req) {
|
|||
CASE(Debug);
|
||||
default:
|
||||
dbgln("Unhandled syscall number: %x", call_id);
|
||||
return Z_ERR_UNIMPLEMENTED;
|
||||
return glcr::UNIMPLEMENTED;
|
||||
}
|
||||
UNREACHABLE
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ z_err_t ThreadCreate(ZThreadCreateReq* req) {
|
|||
auto parent_proc = cap->obj<Process>();
|
||||
auto thread = parent_proc->CreateThread();
|
||||
*req->thread_cap = curr_proc.AddNewCapability(thread, ZC_WRITE);
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
z_err_t ThreadStart(ZThreadStartReq* req) {
|
||||
|
|
@ -22,7 +22,7 @@ z_err_t ThreadStart(ZThreadStartReq* req) {
|
|||
auto thread = cap->obj<Thread>();
|
||||
// FIXME: validate entry point is in user space.
|
||||
thread->Start(req->entry, req->arg1, req->arg2);
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
z_err_t ThreadExit(ZThreadExitReq*) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue