From 2901029cae4cf8d9db67d5b3486c4db2935af1c9 Mon Sep 17 00:00:00 2001 From: Dennis Bonke Date: Mon, 23 Sep 2024 11:56:28 +0200 Subject: [PATCH] posix: Add sysconf request --- posix/subsystem/src/requests.cpp | 50 ++++++++++++++++++++++++++++++++ protocols/posix/posix.bragi | 11 +++++++ 2 files changed, 61 insertions(+) diff --git a/posix/subsystem/src/requests.cpp b/posix/subsystem/src/requests.cpp index 8538d9474..34a4d13c1 100644 --- a/posix/subsystem/src/requests.cpp +++ b/posix/subsystem/src/requests.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -3483,6 +3484,55 @@ async::result serveRequests(std::shared_ptr self, helix_ng::sendBragiHeadOnly(resp, frg::stl_allocator{}) ); HEL_CHECK(sendResp.error()); + }else if(preamble.id() == managarm::posix::SysconfRequest::message_id) { + auto req = bragi::parse_head_only(recv_head); + + if (!req) { + std::cout << "posix: Rejecting request due to decoding failure" << std::endl; + break; + } + + if(logRequests) + std::cout << "posix: SYSCONF" << std::endl; + + managarm::posix::SysconfResponse resp; + + // Configured == available == online + if(req->num() == _SC_NPROCESSORS_CONF || req->num() == _SC_NPROCESSORS_ONLN) { + managarm::kerncfg::GetNumCpuRequest kerncfgRequest; + auto [offer, kerncfgSendResp, kerncfgResp] = co_await helix_ng::exchangeMsgs( + getKerncfgLane(), + helix_ng::offer( + helix_ng::sendBragiHeadOnly(kerncfgRequest, frg::stl_allocator{}), + helix_ng::recvInline() + ) + ); + HEL_CHECK(offer.error()); + HEL_CHECK(kerncfgSendResp.error()); + HEL_CHECK(kerncfgResp.error()); + + auto kernResp = bragi::parse_head_only(kerncfgResp); + + resp.set_error(managarm::posix::Errors::SUCCESS); + resp.set_value(kernResp->num_cpu()); + + auto [send_resp] = co_await helix_ng::exchangeMsgs( + conversation, + helix_ng::sendBragiHeadOnly(resp, frg::stl_allocator{}) + ); + + HEL_CHECK(send_resp.error()); + } else { + // Not handled, bubble up EINVAL. + resp.set_error(managarm::posix::Errors::ILLEGAL_ARGUMENTS); + + auto [send_resp] = co_await helix_ng::exchangeMsgs( + conversation, + helix_ng::sendBragiHeadOnly(resp, frg::stl_allocator{}) + ); + + HEL_CHECK(send_resp.error()); + } }else{ std::cout << "posix: Illegal request" << std::endl; helix::SendBuffer send_resp; diff --git a/protocols/posix/posix.bragi b/protocols/posix/posix.bragi index cee33a2e3..5bb73f8b0 100644 --- a/protocols/posix/posix.bragi +++ b/protocols/posix/posix.bragi @@ -566,3 +566,14 @@ head(128): uint64 available_memory; uint64 memory_unit; } + +message SysconfRequest 93 { +head(128): + int32 num; +} + +message SysconfResponse 94 { +head(128): + Errors error; + int64 value; +}