[zion] [yellowstone] Pass the denali VMMO by port as a POC.
Preparing to bootsrap via port write rather than hard coding capability ids.
This commit is contained in:
parent
75b1f2d21c
commit
21b73b5b92
5 changed files with 71 additions and 24 deletions
|
|
@ -5,23 +5,25 @@
|
|||
Port::Port() {}
|
||||
|
||||
z_err_t Port::Write(const ZMessage& msg) {
|
||||
if (msg.num_caps > 0) {
|
||||
dbgln("Unimplemented passing caps on port");
|
||||
return Z_ERR_UNIMPLEMENTED;
|
||||
}
|
||||
|
||||
if (msg.num_bytes > 0x1000) {
|
||||
dbgln("Large message size unimplemented: %x", msg.num_bytes);
|
||||
return Z_ERR_INVALID;
|
||||
}
|
||||
dbgln("port write");
|
||||
|
||||
Message message{
|
||||
.type = msg.type,
|
||||
.num_bytes = msg.num_bytes,
|
||||
.bytes = new uint8_t[msg.num_bytes],
|
||||
};
|
||||
auto message = MakeShared<Message>();
|
||||
message->type = msg.type, message->num_bytes = msg.num_bytes;
|
||||
message->bytes = new uint8_t[msg.num_bytes];
|
||||
for (uint64_t i = 0; i < msg.num_bytes; i++) {
|
||||
message.bytes[i] = msg.bytes[i];
|
||||
message->bytes[i] = msg.bytes[i];
|
||||
}
|
||||
|
||||
for (uint64_t i = 0; i < msg.num_caps; i++) {
|
||||
auto cap = gScheduler->CurrentProcess().ReleaseCapability(msg.caps[i]);
|
||||
if (!cap) {
|
||||
return Z_ERR_CAP_NOT_FOUND;
|
||||
}
|
||||
message->caps.PushBack(cap);
|
||||
}
|
||||
|
||||
MutexHolder lock(mutex_);
|
||||
|
|
@ -35,6 +37,7 @@ z_err_t Port::Write(const ZMessage& msg) {
|
|||
}
|
||||
|
||||
z_err_t Port::Read(ZMessage& msg) {
|
||||
dbgln("port read");
|
||||
mutex_.Lock();
|
||||
while (pending_messages_.size() < 1) {
|
||||
blocked_threads_.PushBack(gScheduler->CurrentThread());
|
||||
|
|
@ -45,17 +48,25 @@ z_err_t Port::Read(ZMessage& msg) {
|
|||
mutex_.Unlock();
|
||||
|
||||
MutexHolder lock(mutex_);
|
||||
Message next_msg = pending_messages_.PeekFront();
|
||||
if (next_msg.num_bytes > msg.num_bytes) {
|
||||
auto next_msg = pending_messages_.PeekFront();
|
||||
if (next_msg->num_bytes > msg.num_bytes) {
|
||||
return Z_ERR_BUFF_SIZE;
|
||||
}
|
||||
if (next_msg->caps.size() > msg.num_caps) {
|
||||
return Z_ERR_BUFF_SIZE;
|
||||
}
|
||||
|
||||
msg.type = next_msg.type;
|
||||
msg.num_bytes = next_msg.num_bytes;
|
||||
msg.num_caps = 0;
|
||||
msg.type = next_msg->type;
|
||||
msg.num_bytes = next_msg->num_bytes;
|
||||
|
||||
for (uint64_t i = 0; i < msg.num_bytes; i++) {
|
||||
msg.bytes[i] = next_msg.bytes[i];
|
||||
msg.bytes[i] = next_msg->bytes[i];
|
||||
}
|
||||
|
||||
msg.num_caps = next_msg->caps.size();
|
||||
auto& proc = gScheduler->CurrentProcess();
|
||||
for (uint64_t i = 0; i < msg.num_caps; i++) {
|
||||
msg.caps[i] = proc.AddExistingCapability(next_msg->caps.PopFront());
|
||||
}
|
||||
|
||||
pending_messages_.PopFront();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "capability/capability.h"
|
||||
#include "lib/linked_list.h"
|
||||
#include "lib/mutex.h"
|
||||
#include "lib/shared_ptr.h"
|
||||
#include "object/kernel_object.h"
|
||||
#include "object/thread.h"
|
||||
#include "usr/zcall_internal.h"
|
||||
|
|
@ -27,9 +29,11 @@ class Port : public KernelObject {
|
|||
uint64_t type;
|
||||
uint64_t num_bytes;
|
||||
uint8_t* bytes;
|
||||
|
||||
LinkedList<RefPtr<Capability>> caps;
|
||||
};
|
||||
|
||||
LinkedList<Message> pending_messages_;
|
||||
LinkedList<SharedPtr<Message>> pending_messages_;
|
||||
|
||||
LinkedList<RefPtr<Thread>> blocked_threads_;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue