Skip to content

Commit

Permalink
sysdeps/managarm: make sys_waitpid() cancelable
Browse files Browse the repository at this point in the history
  • Loading branch information
Geertiebear committed Dec 24, 2024
1 parent c16410c commit 922dd20
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions sysdeps/managarm/generic/fork-exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,44 @@ int sys_futex_wake(int *pointer) {
}

int sys_waitpid(pid_t pid, int *status, int flags, struct rusage *ru, pid_t *ret_pid) {
SignalGuard sguard;
if (ru) {
mlibc::infoLogger() << "mlibc: struct rusage in sys_waitpid is unsupported" << frg::endlog;
return ENOSYS;
}

HelHandle cancel_handle;
HEL_CHECK(helCreateOneshotEvent(&cancel_handle));
helix::UniqueDescriptor cancel_event{cancel_handle};

managarm::posix::CntRequest<MemoryAllocator> req(getSysdepsAllocator());
req.set_request_type(managarm::posix::CntReqType::WAIT);
req.set_pid(pid);
req.set_flags(flags);

auto [offer, send_head, recv_resp] = exchangeMsgsSync(
auto [offer, send_head, push_descriptor, recv_resp] = exchangeMsgsSyncCancellable(
getPosixLane(),
cancel_handle,
helix_ng::offer(
helix_ng::sendBragiHeadOnly(req, getSysdepsAllocator()), helix_ng::recvInline()
helix_ng::sendBragiHeadOnly(req, getSysdepsAllocator()),
helix_ng::pushDescriptor(cancel_event),
helix_ng::recvInline()
)
);

HEL_CHECK(offer.error());
HEL_CHECK(send_head.error());
HEL_CHECK(push_descriptor.error());
HEL_CHECK(recv_resp.error());

managarm::posix::SvrResponse<MemoryAllocator> resp(getSysdepsAllocator());
resp.ParseFromArray(recv_resp.data(), recv_resp.length());
if (resp.error() == managarm::posix::Errors::ILLEGAL_ARGUMENTS) {
return EINVAL;
}
if (resp.error() == managarm::posix::Errors::INTERRUPTED) {
mlibc::infoLogger() << "returning EINT" << frg::endlog;
return EINTR;
}
__ensure(resp.error() == managarm::posix::Errors::SUCCESS);
if (status)
*status = resp.mode();
Expand Down

0 comments on commit 922dd20

Please sign in to comment.