[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:
Drew Galbraith 2023-06-16 15:58:50 -07:00
parent 75b1f2d21c
commit 21b73b5b92
5 changed files with 71 additions and 24 deletions

View file

@ -8,6 +8,7 @@
#include "object/process.h"
#include "object/thread.h"
#include "scheduler/process_manager.h"
#include "scheduler/scheduler.h"
#define K_INIT_DEBUG 0
@ -127,7 +128,26 @@ void LoadInitProgram() {
RefPtr<MemoryObject> prog2_vmmo = MakeRefCounted<MemoryObject>(prog2.size);
prog2_vmmo->CopyBytesToObject(reinterpret_cast<uint64_t>(prog2.address),
prog2.size);
proc->AddNewCapabilityWithId(Z_INIT_BOOT_VMMO, prog2_vmmo, ZC_WRITE);
proc->CreateThread()->Start(entry, 0, 0);
// TODO: Probably add a way for the kernel to write caps directly rather than
// by installing them first.
uint64_t vmmo_cap =
gScheduler->CurrentProcess().AddNewCapability(prog2_vmmo, ZC_WRITE);
auto port = MakeRefCounted<Port>();
uint64_t port_cap = proc->AddNewCapability(port, ZC_READ | ZC_WRITE);
uint64_t vmmo_id = Z_INIT_BOOT_VMMO;
ZMessage vmmo_msg{
.type = 0,
.num_bytes = 8,
.bytes = reinterpret_cast<uint8_t*>(&vmmo_id),
.num_caps = 1,
.caps = &vmmo_cap,
};
if (port->Write(vmmo_msg) != Z_OK) {
panic("Failed to write cap");
}
proc->CreateThread()->Start(entry, port_cap, 0);
}

View file

@ -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();

View file

@ -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_;