Migrate to error constants in glacier

This commit is contained in:
Drew Galbraith 2023-06-21 18:28:54 -07:00
parent 3ab9b4d818
commit 0b86a94f14
30 changed files with 171 additions and 114 deletions

View file

@ -19,7 +19,7 @@ uint64_t strlen(const char* ptr) {
void Channel::adopt_cap(uint64_t id) {
if (chan_cap_ != 0) {
crash("Adopting over channel.", Z_ERR_EXISTS);
crash("Adopting over channel.", glcr::ALREADY_EXISTS);
}
chan_cap_ = id;
}
@ -33,14 +33,14 @@ z_cap_t Channel::cap() { return chan_cap_; }
z_err_t Channel::WriteStr(const char* msg) {
if (!chan_cap_) {
return Z_ERR_NULL;
return glcr::NULL_PTR;
}
return ZChannelSend(chan_cap_, strlen(msg), msg, 0, nullptr);
}
z_err_t Channel::ReadStr(char* buffer, uint64_t* size) {
if (!chan_cap_) {
return Z_ERR_NULL;
return glcr::NULL_PTR;
}
uint64_t num_caps = 0;
return ZChannelRecv(chan_cap_, size, reinterpret_cast<uint8_t*>(buffer),
@ -49,12 +49,9 @@ z_err_t Channel::ReadStr(char* buffer, uint64_t* size) {
z_err_t CreateChannels(Channel& c1, Channel& c2) {
z_cap_t chan1, chan2;
z_err_t err = ZChannelCreate(&chan1, &chan2);
if (err != Z_OK) {
return err;
}
RET_ERR(ZChannelCreate(&chan1, &chan2));
c1.adopt_cap(chan1);
c2.adopt_cap(chan2);
return Z_OK;
return glcr::OK;
}

View file

@ -1,5 +1,6 @@
#include "include/mammoth/debug.h"
#include <glacier/status/error.h>
#include <stdarg.h>
#include <stdio.h>
#include <zcall.h>
@ -25,18 +26,18 @@ void dbgln(const char* fmt, ...) {
void check(uint64_t code) {
switch (code) {
case Z_OK:
case glcr::OK:
return;
case Z_ERR_UNIMPLEMENTED:
case glcr::UNIMPLEMENTED:
dbgln("crash: UNIMPLEMENTED");
break;
case Z_ERR_CAP_NOT_FOUND:
case glcr::CAP_NOT_FOUND:
dbgln("crash: missing capability");
break;
case Z_ERR_CAP_TYPE:
case glcr::CAP_WRONG_TYPE:
dbgln("crash: capability of the wrong type");
break;
case Z_ERR_CAP_DENIED:
case glcr::CAP_PERMISSION_DENIED:
dbgln("crash: capability permissions error");
break;
default:

View file

@ -1,5 +1,6 @@
#include "mammoth/init.h"
#include <glacier/status/error.h>
#include <ztypes.h>
#include "mammoth/debug.h"
@ -16,7 +17,7 @@ z_err_t ParseInitPort(uint64_t init_port_cap) {
Port port(init_port_cap);
z_err_t ret;
uint64_t init_sig, init_cap;
while ((ret = port.PollForIntCap(&init_sig, &init_cap)) != Z_ERR_EMPTY) {
while ((ret = port.PollForIntCap(&init_sig, &init_cap)) != glcr::EMPTY) {
RET_ERR(ret);
switch (init_sig) {
case Z_INIT_SELF_PROC:
@ -39,5 +40,5 @@ z_err_t ParseInitPort(uint64_t init_port_cap) {
}
}
return Z_OK;
return glcr::OK;
}

View file

@ -1,5 +1,6 @@
#include "mammoth/port.h"
#include <glacier/status/error.h>
#include <zcall.h>
#include "mammoth/debug.h"
@ -13,10 +14,10 @@ z_err_t Port::PollForIntCap(uint64_t *msg, uint64_t *cap) {
cap));
if (bytes != sizeof(uint64_t)) {
return Z_ERR_INVALID;
return glcr::FAILED_PRECONDITION;
}
if (caps != 1) {
return Z_ERR_INVALID;
return glcr::FAILED_PRECONDITION;
}
return Z_OK;
return glcr::OK;
}

View file

@ -1,5 +1,6 @@
#include "mammoth/process.h"
#include <glacier/status/error.h>
#include <zcall.h>
#include "mammoth/channel.h"
@ -133,5 +134,5 @@ uint64_t SpawnProcessFromElfRegion(uint64_t program, Channel& local) {
#endif
check(ZThreadStart(thread_cap, entry_point, foreign_port_id, 0));
return Z_OK;
return glcr::OK;
}