[zion] Move channel syscalls to new format.

This commit is contained in:
Drew Galbraith 2023-06-20 14:41:44 -07:00
parent 1a70ce4855
commit 77bb3acfb4
11 changed files with 91 additions and 123 deletions

View file

@ -7,8 +7,8 @@ class Channel {
public:
Channel() {}
void adopt_cap(uint64_t id);
uint64_t release_cap();
uint64_t cap();
z_cap_t release_cap();
z_cap_t cap();
z_err_t WriteStr(const char* msg);
z_err_t ReadStr(char* buffer, uint64_t* size);
@ -23,7 +23,7 @@ class Channel {
~Channel() {}
private:
uint64_t chan_cap_ = 0;
z_cap_t chan_cap_ = 0;
};
uint64_t CreateChannels(Channel& c1, Channel& c2);
@ -35,9 +35,10 @@ z_err_t Channel::WriteStruct(T* obj) {
template <typename T>
z_err_t Channel::ReadStructAndCap(T* obj, uint64_t* cap) {
uint64_t num_bytes, num_caps;
uint64_t ret = ZChannelRecv(chan_cap_, sizeof(T), obj, /* num_caps= */ 1, cap,
&num_bytes, &num_caps);
uint64_t num_bytes = sizeof(T);
uint64_t num_caps = 1;
uint64_t ret = ZChannelRecv(chan_cap_, &num_bytes, obj, &num_caps, cap);
if (ret != Z_OK) {
return ret;
}

View file

@ -23,33 +23,32 @@ void Channel::adopt_cap(uint64_t id) {
}
chan_cap_ = id;
}
uint64_t Channel::release_cap() {
uint64_t cap = chan_cap_;
z_cap_t Channel::release_cap() {
z_cap_t cap = chan_cap_;
chan_cap_ = 0;
return cap;
}
uint64_t Channel::cap() { return chan_cap_; }
z_cap_t Channel::cap() { return chan_cap_; }
z_err_t Channel::WriteStr(const char* msg) {
if (!chan_cap_) {
return Z_ERR_NULL;
}
return ZChannelSend(chan_cap_, strlen(msg),
reinterpret_cast<const uint8_t*>(msg), 0, 0);
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;
}
uint64_t num_caps;
return ZChannelRecv(chan_cap_, *size, reinterpret_cast<uint8_t*>(buffer), 0,
0, size, &num_caps);
uint64_t num_caps = 0;
return ZChannelRecv(chan_cap_, size, reinterpret_cast<uint8_t*>(buffer),
&num_caps, nullptr);
}
z_err_t CreateChannels(Channel& c1, Channel& c2) {
uint64_t chan1, chan2;
z_cap_t chan1, chan2;
z_err_t err = ZChannelCreate(&chan1, &chan2);
if (err != Z_OK) {
return err;