diff --git a/lib/mammoth/file/file.cpp b/lib/mammoth/file/file.cpp index 77c50d4..53407a8 100644 --- a/lib/mammoth/file/file.cpp +++ b/lib/mammoth/file/file.cpp @@ -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(file_data_.vaddr()); } diff --git a/lib/mammoth/file/file.h b/lib/mammoth/file/file.h index 15021c5..176960c 100644 --- a/lib/mammoth/file/file.h +++ b/lib/mammoth/file/file.h @@ -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 diff --git a/sys/yellowstone/yellowstone.cpp b/sys/yellowstone/yellowstone.cpp index 2711283..7e575a0 100644 --- a/sys/yellowstone/yellowstone.cpp +++ b/sys/yellowstone/yellowstone.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -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(filemem.vaddr()), - response.size()); - - glcr::Vector files = glcr::StrSplit(file, '\n'); + glcr::Vector 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())); } } diff --git a/sys/yellowstone/yellowstone_server.cpp b/sys/yellowstone/yellowstone_server.cpp index e164b63..ab352a0 100644 --- a/sys/yellowstone/yellowstone_server.cpp +++ b/sys/yellowstone/yellowstone_server.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -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(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 YellowstoneServer::GetVFSClient() { - return vfs_client_; -} diff --git a/sys/yellowstone/yellowstone_server.h b/sys/yellowstone/yellowstone_server.h index b1de827..6447fa6 100644 --- a/sys/yellowstone/yellowstone_server.h +++ b/sys/yellowstone/yellowstone_server.h @@ -26,8 +26,6 @@ class YellowstoneServer : public YellowstoneServerBase { void WaitDenaliRegistered(); void WaitVictoriaFallsRegistered(); - glcr::SharedPtr GetVFSClient(); - private: glcr::HashMap endpoint_map_; diff --git a/sysroot/init.txt b/sysroot/init.txt index a6b83aa..00a31bd 100644 --- a/sysroot/init.txt +++ b/sysroot/init.txt @@ -1 +1,2 @@ teton +