Skip to content

Commit

Permalink
sysdeps/managarm: avoid variable-sized members in bragi heads
Browse files Browse the repository at this point in the history
This change is done in sync with managarm.
  • Loading branch information
no92 committed Feb 21, 2025
1 parent 5f70519 commit fb7f7d7
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions sysdeps/managarm/generic/ioctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,37 @@ int sys_ioctl(int fd, unsigned long request, void *arg, int *result) {

req_setup(req, ifr);

auto [offer, send_token_req, send_req, recv_resp] = exchangeMsgsSync(
auto [offer, send_token_req, send_req, send_req_tail, recv_resp] = exchangeMsgsSync(
getPosixLane(),
helix_ng::offer(
helix_ng::want_lane,
helix_ng::sendBragiHeadOnly(token_req, getSysdepsAllocator()),
helix_ng::sendBragiHeadOnly(req, getSysdepsAllocator()),
helix_ng::sendBragiHeadTail(req, getSysdepsAllocator()),
helix_ng::recvInline()
)
);

HEL_CHECK(offer.error());
HEL_CHECK(send_token_req.error());
HEL_CHECK(send_req.error());
HEL_CHECK(send_req_tail.error());
HEL_CHECK(recv_resp.error());

managarm::fs::IfreqReply<MemoryAllocator> resp(getSysdepsAllocator());
resp.ParseFromArray(recv_resp.data(), recv_resp.length());
auto preamble = bragi::read_preamble(recv_resp);

frg::vector<uint8_t, MemoryAllocator> tailBuffer{getSysdepsAllocator()};
tailBuffer.resize(preamble.tail_size());
auto [recv_tail] = exchangeMsgsSync(
offer.descriptor().getHandle(),
helix_ng::recvBuffer(tailBuffer.data(), tailBuffer.size())
);

HEL_CHECK(recv_tail.error());

auto resp = *bragi::parse_head_tail<managarm::fs::IfreqReply>(
recv_resp, tailBuffer, getSysdepsAllocator()
);
recv_resp.reset();

int ret = resp_parse(resp, ifr);

Expand Down Expand Up @@ -905,12 +920,12 @@ int sys_ioctl(int fd, unsigned long request, void *arg, int *result) {
managarm::fs::IfreqRequest<MemoryAllocator> req(getSysdepsAllocator());
req.set_command(request);

auto [offer, send_token_req, send_req, recv_resp] = exchangeMsgsSync(
auto [offer, send_token_req, send_req, send_tail, recv_resp] = exchangeMsgsSync(
getPosixLane(),
helix_ng::offer(
helix_ng::want_lane,
helix_ng::sendBragiHeadOnly(token_req, getSysdepsAllocator()),
helix_ng::sendBragiHeadOnly(req, getSysdepsAllocator()),
helix_ng::sendBragiHeadTail(req, getSysdepsAllocator()),
helix_ng::recvInline()
)
);
Expand All @@ -920,6 +935,7 @@ int sys_ioctl(int fd, unsigned long request, void *arg, int *result) {
HEL_CHECK(offer.error());
HEL_CHECK(send_token_req.error());
HEL_CHECK(send_req.error());
HEL_CHECK(send_tail.error());
HEL_CHECK(recv_resp.error());

auto preamble = bragi::read_preamble(recv_resp);
Expand Down

0 comments on commit fb7f7d7

Please sign in to comment.