[Yellowstone] Use the file api to load the init file.

This commit is contained in:
Drew Galbraith 2023-11-22 16:58:13 -08:00
parent 86ce0a68a3
commit 8ceab2ad23
6 changed files with 23 additions and 27 deletions

View File

@ -13,6 +13,8 @@ VFSClient* gVfsClient = nullptr;
} // namespace
void SetVfsCap(z_cap_t vfs_cap) { gVfsClient = new VFSClient(vfs_cap); }
File File::Open(glcr::StringView path) {
if (gVfsClient == 0) {
YellowstoneClient client(gInitEndpointCap);
@ -30,11 +32,11 @@ File File::Open(glcr::StringView path) {
OpenFileResponse resp;
check(gVfsClient->OpenFile(req, resp));
return File(OwnedMemoryRegion::FromCapability(resp.memory()));
return File(OwnedMemoryRegion::FromCapability(resp.memory()), resp.size());
}
glcr::StringView File::as_str() {
return glcr::StringView((char*)raw_ptr(), file_data_.size());
return glcr::StringView((char*)raw_ptr(), size_);
}
void* File::raw_ptr() { return reinterpret_cast<void*>(file_data_.vaddr()); }

View File

@ -7,10 +7,15 @@
namespace mmth {
// Intended for use in yellowstone since it already has the VFS cap.
void SetVfsCap(z_cap_t vfs_cap);
class File {
public:
static File Open(glcr::StringView path);
uint64_t size() { return size_; }
glcr::StringView as_str();
void* raw_ptr();
@ -18,8 +23,10 @@ class File {
private:
OwnedMemoryRegion file_data_;
uint64_t size_;
File(OwnedMemoryRegion&& file) : file_data_(glcr::Move(file)) {}
File(OwnedMemoryRegion&& file, uint64_t size)
: file_data_(glcr::Move(file)), size_(size) {}
};
} // namespace mmth

View File

@ -1,5 +1,6 @@
#include <glacier/string/str_format.h>
#include <glacier/string/str_split.h>
#include <mammoth/file/file.h>
#include <mammoth/proc/process.h>
#include <mammoth/util/debug.h>
#include <mammoth/util/init.h>
@ -36,29 +37,19 @@ uint64_t main(uint64_t port_cap) {
dbgln("VFS Available.");
auto vfs_client = server->GetVFSClient();
OpenFileRequest request;
request.set_path("/init.txt");
OpenFileResponse response;
check(vfs_client->OpenFile(request, response));
mmth::File init_file = mmth::File::Open("/init.txt");
mmth::OwnedMemoryRegion filemem =
mmth::OwnedMemoryRegion::FromCapability(response.memory());
glcr::String file(reinterpret_cast<const char*>(filemem.vaddr()),
response.size());
glcr::Vector<glcr::StringView> files = glcr::StrSplit(file, '\n');
glcr::Vector<glcr::StringView> files =
glcr::StrSplit(init_file.as_str(), '\n');
for (uint64_t i = 0; i < files.size(); i++) {
if (!files[i].empty()) {
dbgln("Starting {}", files[i]);
OpenFileRequest req;
req.set_path(glcr::StrFormat("/bin/{}", files[i]));
OpenFileResponse resp;
check(vfs_client->OpenFile(req, resp));
mmth::File binary =
mmth::File::Open(glcr::StrFormat("/bin/{}", files[i]));
ASSIGN_OR_RETURN(YellowstoneClient client3, server->CreateClient());
check(SpawnProcess(resp.memory(), client3.Capability()));
check(mmth::SpawnProcessFromElfRegion((uint64_t)binary.raw_ptr(),
client3.Capability()));
}
}

View File

@ -2,6 +2,7 @@
#include <denali/denali.yunq.client.h>
#include <glacier/string/string.h>
#include <mammoth/file/file.h>
#include <mammoth/util/debug.h>
#include <mammoth/util/init.h>
#include <mammoth/util/memory_region.h>
@ -100,7 +101,7 @@ glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint(
} else if (req.endpoint_name() == "victoriafalls") {
// FIXME: Probably make a separate copy for use within yellowstone vs
// transmit to other processes.
vfs_client_ = glcr::MakeShared<VFSClient>(req.endpoint_capability());
mmth::SetVfsCap(req.endpoint_capability());
has_victoriafalls_semaphore_.Signal();
} else {
dbgln("[WARN] Got endpoint cap type: {}", req.endpoint_name().cstr());
@ -125,7 +126,3 @@ void YellowstoneServer::WaitDenaliRegistered() { has_denali_semaphore_.Wait(); }
void YellowstoneServer::WaitVictoriaFallsRegistered() {
has_victoriafalls_semaphore_.Wait();
}
glcr::SharedPtr<VFSClient> YellowstoneServer::GetVFSClient() {
return vfs_client_;
}

View File

@ -26,8 +26,6 @@ class YellowstoneServer : public YellowstoneServerBase {
void WaitDenaliRegistered();
void WaitVictoriaFallsRegistered();
glcr::SharedPtr<VFSClient> GetVFSClient();
private:
glcr::HashMap<glcr::String, z_cap_t> endpoint_map_;

View File

@ -1 +1,2 @@
teton