[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

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