Endpoint syscalls implemented

This commit is contained in:
Drew Galbraith 2023-06-21 23:14:42 -07:00
parent 69501bfe01
commit c064af5fa7
27 changed files with 391 additions and 42 deletions

View file

@ -70,3 +70,59 @@ void UnboundedMessageQueue::WriteKernel(uint64_t init,
pending_messages_.PushBack(msg);
}
glcr::ErrorCode SingleMessageQueue::PushBack(uint64_t num_bytes,
const void* bytes,
uint64_t num_caps,
const z_cap_t* caps) {
if (has_written_) {
return glcr::FAILED_PRECONDITION;
}
num_bytes_ = num_bytes;
bytes_ = new uint8_t[num_bytes];
for (uint64_t i = 0; i < num_bytes; i++) {
bytes_[i] = reinterpret_cast<const uint8_t*>(bytes)[i];
}
for (uint64_t i = 0; i < num_caps; i++) {
// FIXME: This would feel safer closer to the relevant syscall.
auto cap = gScheduler->CurrentProcess().ReleaseCapability(caps[i]);
if (!cap) {
return glcr::CAP_NOT_FOUND;
}
caps_.PushBack(cap);
}
has_written_ = true;
return glcr::OK;
}
glcr::ErrorCode SingleMessageQueue::PopFront(uint64_t* num_bytes, void* bytes,
uint64_t* num_caps,
z_cap_t* caps) {
if (!has_written_ || has_read_) {
return glcr::FAILED_PRECONDITION;
}
if (num_bytes_ > *num_bytes) {
return glcr::BUFFER_SIZE;
}
if (caps_.size() > *num_caps) {
return glcr::BUFFER_SIZE;
}
*num_bytes = num_bytes_;
for (uint64_t i = 0; i < num_bytes_; i++) {
reinterpret_cast<uint8_t*>(bytes)[i] = bytes_[i];
}
*num_caps = caps_.size();
auto& proc = gScheduler->CurrentProcess();
for (uint64_t i = 0; i < *num_caps; i++) {
caps[i] = proc.AddExistingCapability(caps_.PopFront());
}
has_read_ = true;
return glcr::OK;
}

View file

@ -2,6 +2,7 @@
#include <glacier/memory/ref_ptr.h>
#include <glacier/memory/shared_ptr.h>
#include <glacier/status/error.h>
#include "capability/capability.h"
#include "include/ztypes.h"
@ -11,10 +12,10 @@ class MessageQueue {
public:
virtual ~MessageQueue() {}
virtual z_err_t PushBack(uint64_t num_bytes, const void* bytes,
uint64_t num_caps, const z_cap_t* caps) = 0;
virtual z_err_t PopFront(uint64_t* num_bytes, void* bytes, uint64_t* num_caps,
z_cap_t* caps) = 0;
virtual glcr::ErrorCode PushBack(uint64_t num_bytes, const void* bytes,
uint64_t num_caps, const z_cap_t* caps) = 0;
virtual glcr::ErrorCode PopFront(uint64_t* num_bytes, void* bytes,
uint64_t* num_caps, z_cap_t* caps) = 0;
};
class UnboundedMessageQueue : public MessageQueue {
@ -24,10 +25,10 @@ class UnboundedMessageQueue : public MessageQueue {
UnboundedMessageQueue& operator=(const UnboundedMessageQueue&) = delete;
virtual ~UnboundedMessageQueue() override {}
z_err_t PushBack(uint64_t num_bytes, const void* bytes, uint64_t num_caps,
const z_cap_t* caps) override;
z_err_t PopFront(uint64_t* num_bytes, void* bytes, uint64_t* num_caps,
z_cap_t* caps) override;
glcr::ErrorCode PushBack(uint64_t num_bytes, const void* bytes,
uint64_t num_caps, const z_cap_t* caps) override;
glcr::ErrorCode PopFront(uint64_t* num_bytes, void* bytes, uint64_t* num_caps,
z_cap_t* caps) override;
void WriteKernel(uint64_t init, glcr::RefPtr<Capability> cap);
@ -44,3 +45,25 @@ class UnboundedMessageQueue : public MessageQueue {
LinkedList<glcr::SharedPtr<Message>> pending_messages_;
};
class SingleMessageQueue : public MessageQueue {
public:
SingleMessageQueue() {}
SingleMessageQueue(const SingleMessageQueue&) = delete;
SingleMessageQueue(SingleMessageQueue&&) = delete;
virtual ~SingleMessageQueue() override {}
glcr::ErrorCode PushBack(uint64_t num_bytes, const void* bytes,
uint64_t num_caps, const z_cap_t* caps) override;
glcr::ErrorCode PopFront(uint64_t* num_bytes, void* bytes, uint64_t* num_caps,
z_cap_t* caps) override;
bool empty() { return has_written_ == false; };
private:
bool has_written_ = false;
bool has_read_ = false;
uint64_t num_bytes_;
uint8_t* bytes_;
LinkedList<glcr::RefPtr<Capability>> caps_;
};

View file

@ -5,7 +5,7 @@
void Mutex::Lock() {
while (__atomic_fetch_or(&lock_, 0x1, __ATOMIC_SEQ_CST) == 0x1) {
dbgln("Lock sleep: %s", name_);
// dbgln("Lock sleep: %s", name_);
gScheduler->Preempt();
}
}