[Zion] Move away from storing pointers to IpcMessages.
This commit is contained in:
parent
59f147193a
commit
d2c77e1d18
|
@ -21,7 +21,7 @@ class Array {
|
||||||
|
|
||||||
Array(const Array&) = delete;
|
Array(const Array&) = delete;
|
||||||
|
|
||||||
Array(Array&& other) : data_(other.data), size_(other.size_) {
|
Array(Array&& other) : data_(other.data_), size_(other.size_) {
|
||||||
other.data_ = nullptr;
|
other.data_ = nullptr;
|
||||||
other.size_ = 0;
|
other.size_ = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "glacier/memory/move.h"
|
||||||
|
|
||||||
namespace glcr {
|
namespace glcr {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -15,20 +17,19 @@ class LinkedList {
|
||||||
uint64_t size() const { return size_; }
|
uint64_t size() const { return size_; }
|
||||||
|
|
||||||
void PushBack(const T& item) {
|
void PushBack(const T& item) {
|
||||||
size_++;
|
|
||||||
ListItem* new_item = new ListItem{
|
ListItem* new_item = new ListItem{
|
||||||
.item = item,
|
.item = item,
|
||||||
.next = nullptr,
|
.next = nullptr,
|
||||||
};
|
};
|
||||||
if (front_ == nullptr) {
|
PushBackInternal(new_item);
|
||||||
front_ = new_item;
|
}
|
||||||
return;
|
|
||||||
}
|
void PushBack(T&& item) {
|
||||||
ListItem* litem = front_;
|
ListItem* new_item = new ListItem{
|
||||||
while (litem->next != nullptr) {
|
.item = glcr::Move(item),
|
||||||
litem = litem->next;
|
.next = nullptr,
|
||||||
}
|
};
|
||||||
litem->next = new_item;
|
PushBackInternal(new_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
T PopFront() {
|
T PopFront() {
|
||||||
|
@ -36,12 +37,12 @@ class LinkedList {
|
||||||
|
|
||||||
ListItem* old_front = front_;
|
ListItem* old_front = front_;
|
||||||
front_ = front_->next;
|
front_ = front_->next;
|
||||||
T ret = old_front->item;
|
T ret = glcr::Move(old_front->item);
|
||||||
delete old_front;
|
delete old_front;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
T PeekFront() const { return front_->item; }
|
T& PeekFront() const { return front_->item; }
|
||||||
|
|
||||||
struct ListItem {
|
struct ListItem {
|
||||||
T item;
|
T item;
|
||||||
|
@ -73,6 +74,19 @@ class LinkedList {
|
||||||
uint64_t size_ = 0;
|
uint64_t size_ = 0;
|
||||||
|
|
||||||
ListItem* front_ = nullptr;
|
ListItem* front_ = nullptr;
|
||||||
|
|
||||||
|
void PushBackInternal(ListItem* new_item) {
|
||||||
|
size_++;
|
||||||
|
if (front_ == nullptr) {
|
||||||
|
front_ = new_item;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ListItem* litem = front_;
|
||||||
|
while (litem->next != nullptr) {
|
||||||
|
litem = litem->next;
|
||||||
|
}
|
||||||
|
litem->next = new_item;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace glcr
|
} // namespace glcr
|
||||||
|
|
|
@ -11,16 +11,16 @@ glcr::ErrorCode UnboundedMessageQueue::PushBack(
|
||||||
return glcr::UNIMPLEMENTED;
|
return glcr::UNIMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto msg_struct = glcr::MakeShared<IpcMessage>();
|
IpcMessage msg_struct;
|
||||||
msg_struct->data = glcr::Array<uint8_t>(message);
|
msg_struct.data = glcr::Array<uint8_t>(message);
|
||||||
|
|
||||||
if (reply_cap != kZionInvalidCapability) {
|
if (reply_cap != kZionInvalidCapability) {
|
||||||
// FIXME: We're just trusting that capability has the correct permissions.
|
// FIXME: We're just trusting that capability has the correct permissions.
|
||||||
msg_struct->reply_cap =
|
msg_struct.reply_cap =
|
||||||
gScheduler->CurrentProcess().ReleaseCapability(reply_cap);
|
gScheduler->CurrentProcess().ReleaseCapability(reply_cap);
|
||||||
}
|
}
|
||||||
|
|
||||||
msg_struct->caps.Resize(caps.size());
|
msg_struct.caps.Resize(caps.size());
|
||||||
for (uint64_t i = 0; i < caps.size(); i++) {
|
for (uint64_t i = 0; i < caps.size(); i++) {
|
||||||
// FIXME: This would feel safer closer to the relevant syscall.
|
// FIXME: This would feel safer closer to the relevant syscall.
|
||||||
// FIXME: Race conditions on get->check->release here. Would be better to
|
// FIXME: Race conditions on get->check->release here. Would be better to
|
||||||
|
@ -34,11 +34,11 @@ glcr::ErrorCode UnboundedMessageQueue::PushBack(
|
||||||
return glcr::CAP_PERMISSION_DENIED;
|
return glcr::CAP_PERMISSION_DENIED;
|
||||||
}
|
}
|
||||||
cap = gScheduler->CurrentProcess().ReleaseCapability(caps[i]);
|
cap = gScheduler->CurrentProcess().ReleaseCapability(caps[i]);
|
||||||
msg_struct->caps.PushBack(cap);
|
msg_struct.caps.PushBack(cap);
|
||||||
}
|
}
|
||||||
|
|
||||||
MutexHolder h(mutex_);
|
MutexHolder h(mutex_);
|
||||||
pending_messages_.PushBack(msg_struct);
|
pending_messages_.PushBack(glcr::Move(msg_struct));
|
||||||
|
|
||||||
if (blocked_threads_.size() > 0) {
|
if (blocked_threads_.size() > 0) {
|
||||||
auto thread = blocked_threads_.PopFront();
|
auto thread = blocked_threads_.PopFront();
|
||||||
|
@ -64,34 +64,34 @@ glcr::ErrorCode UnboundedMessageQueue::PopFront(uint64_t* num_bytes,
|
||||||
mutex_->Release();
|
mutex_->Release();
|
||||||
|
|
||||||
MutexHolder lock(mutex_);
|
MutexHolder lock(mutex_);
|
||||||
auto next_msg = pending_messages_.PeekFront();
|
auto& next_msg = pending_messages_.PeekFront();
|
||||||
if (next_msg->data.size() > *num_bytes) {
|
if (next_msg.data.size() > *num_bytes) {
|
||||||
return glcr::BUFFER_SIZE;
|
return glcr::BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
if (next_msg->caps.size() > *num_caps) {
|
if (next_msg.caps.size() > *num_caps) {
|
||||||
return glcr::BUFFER_SIZE;
|
return glcr::BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
next_msg = pending_messages_.PopFront();
|
next_msg = pending_messages_.PopFront();
|
||||||
|
|
||||||
*num_bytes = next_msg->data.size();
|
*num_bytes = next_msg.data.size();
|
||||||
|
|
||||||
for (uint64_t i = 0; i < *num_bytes; i++) {
|
for (uint64_t i = 0; i < *num_bytes; i++) {
|
||||||
static_cast<uint8_t*>(bytes)[i] = next_msg->data[i];
|
static_cast<uint8_t*>(bytes)[i] = next_msg.data[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& proc = gScheduler->CurrentProcess();
|
auto& proc = gScheduler->CurrentProcess();
|
||||||
if (reply_cap != nullptr) {
|
if (reply_cap != nullptr) {
|
||||||
if (!next_msg->reply_cap) {
|
if (!next_msg.reply_cap) {
|
||||||
dbgln("Tried to read reply capability off of a message without one");
|
dbgln("Tried to read reply capability off of a message without one");
|
||||||
return glcr::INTERNAL;
|
return glcr::INTERNAL;
|
||||||
}
|
}
|
||||||
*reply_cap = proc.AddExistingCapability(next_msg->reply_cap);
|
*reply_cap = proc.AddExistingCapability(next_msg.reply_cap);
|
||||||
}
|
}
|
||||||
|
|
||||||
*num_caps = next_msg->caps.size();
|
*num_caps = next_msg.caps.size();
|
||||||
for (uint64_t i = 0; i < *num_caps; i++) {
|
for (uint64_t i = 0; i < *num_caps; i++) {
|
||||||
caps[i] = proc.AddExistingCapability(next_msg->caps[i]);
|
caps[i] = proc.AddExistingCapability(next_msg.caps[i]);
|
||||||
}
|
}
|
||||||
return glcr::OK;
|
return glcr::OK;
|
||||||
}
|
}
|
||||||
|
@ -99,16 +99,16 @@ glcr::ErrorCode UnboundedMessageQueue::PopFront(uint64_t* num_bytes,
|
||||||
void UnboundedMessageQueue::WriteKernel(uint64_t init,
|
void UnboundedMessageQueue::WriteKernel(uint64_t init,
|
||||||
glcr::RefPtr<Capability> cap) {
|
glcr::RefPtr<Capability> cap) {
|
||||||
// FIXME: Add synchronization here in case it is ever used outside of init.
|
// FIXME: Add synchronization here in case it is ever used outside of init.
|
||||||
auto msg = glcr::MakeShared<IpcMessage>();
|
IpcMessage msg;
|
||||||
msg->data = glcr::Array<uint8_t>(sizeof(init));
|
msg.data = glcr::Array<uint8_t>(sizeof(init));
|
||||||
|
|
||||||
uint8_t* data = reinterpret_cast<uint8_t*>(&init);
|
uint8_t* data = reinterpret_cast<uint8_t*>(&init);
|
||||||
for (uint8_t i = 0; i < sizeof(init); i++) {
|
for (uint8_t i = 0; i < sizeof(init); i++) {
|
||||||
msg->data[i] = data[i];
|
msg.data[i] = data[i];
|
||||||
}
|
}
|
||||||
msg->caps.PushBack(cap);
|
msg.caps.PushBack(cap);
|
||||||
|
|
||||||
pending_messages_.PushBack(msg);
|
pending_messages_.PushBack(glcr::Move(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
glcr::ErrorCode SingleMessageQueue::PushBack(
|
glcr::ErrorCode SingleMessageQueue::PushBack(
|
||||||
|
|
|
@ -61,7 +61,7 @@ class UnboundedMessageQueue : public MessageQueue {
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
glcr::LinkedList<glcr::SharedPtr<IpcMessage>> pending_messages_;
|
glcr::LinkedList<IpcMessage> pending_messages_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SingleMessageQueue : public MessageQueue {
|
class SingleMessageQueue : public MessageQueue {
|
||||||
|
|
Loading…
Reference in New Issue