Skip to content

Commit

Permalink
posix: Add GetMemoryInformation request
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwinci committed Oct 23, 2023
1 parent 9715ed5 commit cac938d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions posix/subsystem/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ namespace {
helix::UniqueLane kerncfgLane;
};

helix::UniqueLane &getKerncfgLane() {
return kerncfgLane;
}

struct CmdlineNode final : public procfs::RegularNode {
async::result<std::string> show() override {

Expand Down
33 changes: 33 additions & 0 deletions posix/subsystem/src/requests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <bragi/helpers-std.hpp>
#include <posix.bragi.hpp>
#include <kerncfg.bragi.hpp>

#include "debug-options.hpp"

Expand Down Expand Up @@ -3271,6 +3272,38 @@ async::result<void> serveRequests(std::shared_ptr<Process> self,
helix_ng::sendBuffer(affinity.data(), affinity.size())
);
HEL_CHECK(sendResp.error());
}else if(preamble.id() == managarm::posix::GetMemoryInformationRequest::message_id) {
auto req = bragi::parse_head_only<managarm::posix::GetMemoryInformationRequest>(recv_head);

if (!req) {
std::cout << "posix: Rejecting request due to decoding failure" << std::endl;
break;
}

if(logRequests)
std::cout << "posix: GET_MEMORY_INFORMATION" << std::endl;

managarm::kerncfg::GetMemoryInformationRequest kerncfgRequest;
auto [kerncfgSendResp, kerncfgResp] = co_await helix_ng::exchangeMsgs(
getKerncfgLane(),
helix_ng::sendBragiHeadOnly(kerncfgRequest, frg::stl_allocator{}),
helix_ng::RecvInline{}
);
HEL_CHECK(kerncfgSendResp.error());
HEL_CHECK(kerncfgResp.error());

auto kernResp = bragi::parse_head_only<managarm::kerncfg::GetMemoryInformationResponse>(kerncfgResp);

managarm::posix::GetMemoryInformationResponse resp;
resp.set_total_usable_memory(kernResp->total_usable_memory());
resp.set_available_memory(kernResp->available_memory());
resp.set_memory_unit(kernResp->memory_unit());

auto [sendResp] = co_await helix_ng::exchangeMsgs(
conversation,
helix_ng::sendBragiHeadOnly(resp, frg::stl_allocator{})
);
HEL_CHECK(sendResp.error());
}else{
std::cout << "posix: Illegal request" << std::endl;
helix::SendBuffer send_resp;
Expand Down
2 changes: 2 additions & 0 deletions posix/subsystem/src/requests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

async::result<void> serveRequests(std::shared_ptr<Process> self,
std::shared_ptr<Generation> generation);

helix::UniqueLane &getKerncfgLane();
11 changes: 11 additions & 0 deletions protocols/posix/posix.bragi
Original file line number Diff line number Diff line change
Expand Up @@ -521,3 +521,14 @@ head(128):
tail:
uint8[] mask;
}

message GetMemoryInformationRequest 91 {
head(128):
}

message GetMemoryInformationResponse 92 {
head(128):
uint64 total_usable_memory;
uint64 available_memory;
uint64 memory_unit;
}

0 comments on commit cac938d

Please sign in to comment.