[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 } // namespace
void SetVfsCap(z_cap_t vfs_cap) { gVfsClient = new VFSClient(vfs_cap); }
File File::Open(glcr::StringView path) { File File::Open(glcr::StringView path) {
if (gVfsClient == 0) { if (gVfsClient == 0) {
YellowstoneClient client(gInitEndpointCap); YellowstoneClient client(gInitEndpointCap);
@ -30,11 +32,11 @@ File File::Open(glcr::StringView path) {
OpenFileResponse resp; OpenFileResponse resp;
check(gVfsClient->OpenFile(req, 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() { 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()); } void* File::raw_ptr() { return reinterpret_cast<void*>(file_data_.vaddr()); }

View File

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

View File

@ -1,5 +1,6 @@
#include <glacier/string/str_format.h> #include <glacier/string/str_format.h>
#include <glacier/string/str_split.h> #include <glacier/string/str_split.h>
#include <mammoth/file/file.h>
#include <mammoth/proc/process.h> #include <mammoth/proc/process.h>
#include <mammoth/util/debug.h> #include <mammoth/util/debug.h>
#include <mammoth/util/init.h> #include <mammoth/util/init.h>
@ -36,29 +37,19 @@ uint64_t main(uint64_t port_cap) {
dbgln("VFS Available."); dbgln("VFS Available.");
auto vfs_client = server->GetVFSClient(); mmth::File init_file = mmth::File::Open("/init.txt");
OpenFileRequest request;
request.set_path("/init.txt");
OpenFileResponse response;
check(vfs_client->OpenFile(request, response));
mmth::OwnedMemoryRegion filemem = glcr::Vector<glcr::StringView> files =
mmth::OwnedMemoryRegion::FromCapability(response.memory()); glcr::StrSplit(init_file.as_str(), '\n');
glcr::String file(reinterpret_cast<const char*>(filemem.vaddr()),
response.size());
glcr::Vector<glcr::StringView> files = glcr::StrSplit(file, '\n');
for (uint64_t i = 0; i < files.size(); i++) { for (uint64_t i = 0; i < files.size(); i++) {
if (!files[i].empty()) { if (!files[i].empty()) {
dbgln("Starting {}", files[i]); mmth::File binary =
OpenFileRequest req; mmth::File::Open(glcr::StrFormat("/bin/{}", files[i]));
req.set_path(glcr::StrFormat("/bin/{}", files[i]));
OpenFileResponse resp;
check(vfs_client->OpenFile(req, resp));
ASSIGN_OR_RETURN(YellowstoneClient client3, server->CreateClient()); 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 <denali/denali.yunq.client.h>
#include <glacier/string/string.h> #include <glacier/string/string.h>
#include <mammoth/file/file.h>
#include <mammoth/util/debug.h> #include <mammoth/util/debug.h>
#include <mammoth/util/init.h> #include <mammoth/util/init.h>
#include <mammoth/util/memory_region.h> #include <mammoth/util/memory_region.h>
@ -100,7 +101,7 @@ glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint(
} else if (req.endpoint_name() == "victoriafalls") { } else if (req.endpoint_name() == "victoriafalls") {
// FIXME: Probably make a separate copy for use within yellowstone vs // FIXME: Probably make a separate copy for use within yellowstone vs
// transmit to other processes. // transmit to other processes.
vfs_client_ = glcr::MakeShared<VFSClient>(req.endpoint_capability()); mmth::SetVfsCap(req.endpoint_capability());
has_victoriafalls_semaphore_.Signal(); has_victoriafalls_semaphore_.Signal();
} else { } else {
dbgln("[WARN] Got endpoint cap type: {}", req.endpoint_name().cstr()); dbgln("[WARN] Got endpoint cap type: {}", req.endpoint_name().cstr());
@ -125,7 +126,3 @@ void YellowstoneServer::WaitDenaliRegistered() { has_denali_semaphore_.Wait(); }
void YellowstoneServer::WaitVictoriaFallsRegistered() { void YellowstoneServer::WaitVictoriaFallsRegistered() {
has_victoriafalls_semaphore_.Wait(); 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 WaitDenaliRegistered();
void WaitVictoriaFallsRegistered(); void WaitVictoriaFallsRegistered();
glcr::SharedPtr<VFSClient> GetVFSClient();
private: private:
glcr::HashMap<glcr::String, z_cap_t> endpoint_map_; glcr::HashMap<glcr::String, z_cap_t> endpoint_map_;

View File

@ -1 +1,2 @@
teton teton