Migrate to error constants in glacier
This commit is contained in:
parent
3ab9b4d818
commit
0b86a94f14
30 changed files with 171 additions and 114 deletions
|
|
@ -13,6 +13,7 @@ target_include_directories(mammoth_lib
|
|||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
target_link_libraries(mammoth_lib
|
||||
glacier
|
||||
c
|
||||
zion_lib)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/status/error.h>
|
||||
#include <stdint.h>
|
||||
#include <zcall.h>
|
||||
|
||||
|
|
@ -37,13 +38,10 @@ template <typename T>
|
|||
z_err_t Channel::ReadStructAndCap(T* obj, uint64_t* cap) {
|
||||
uint64_t num_bytes = sizeof(T);
|
||||
uint64_t num_caps = 1;
|
||||
uint64_t ret = ZChannelRecv(chan_cap_, &num_bytes, obj, &num_caps, cap);
|
||||
RET_ERR(ZChannelRecv(chan_cap_, &num_bytes, obj, &num_caps, cap));
|
||||
|
||||
if (ret != Z_OK) {
|
||||
return ret;
|
||||
}
|
||||
if (num_caps != 1 || num_bytes != sizeof(T)) {
|
||||
return Z_ERR_INVALID;
|
||||
return glcr::FAILED_PRECONDITION;
|
||||
}
|
||||
return Z_OK;
|
||||
return glcr::OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,3 @@ void dbgln(const char* fmt, ...);
|
|||
void check(uint64_t);
|
||||
|
||||
void crash(const char*, z_err_t);
|
||||
|
||||
#define RET_ERR(expr) \
|
||||
{ \
|
||||
z_err_t _tmp_err = expr; \
|
||||
if (_tmp_err != Z_OK) { \
|
||||
return _tmp_err; \
|
||||
} \
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue