Skip to content

Commit

Permalink
posix: Add sysconf request
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennisbonke committed Sep 23, 2024
1 parent c2e1332 commit 2901029
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
50 changes: 50 additions & 0 deletions posix/subsystem/src/requests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <sys/timerfd.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <unistd.h>

#include <helix/timer.hpp>

Expand Down Expand Up @@ -3483,6 +3484,55 @@ async::result<void> serveRequests(std::shared_ptr<Process> 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<managarm::posix::SysconfRequest>(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<managarm::kerncfg::GetNumCpuResponse>(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;
Expand Down
11 changes: 11 additions & 0 deletions protocols/posix/posix.bragi
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 2901029

Please sign in to comment.