Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sysdeps/managarm: setitimer + CLOCK_BOOTTIME #1227

Merged
merged 2 commits into from
Jan 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions sysdeps/managarm/generic/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <mlibc/debug.hpp>
#include <mlibc/posix-pipe.hpp>

#include "posix.frigg_bragi.hpp"

struct TrackerPage {
uint64_t seqlock;
int32_t state;
Expand Down Expand Up @@ -63,11 +65,11 @@ int sys_clock_get(int clock, time_t *secs, long *nanos) {
*secs = 0;
*nanos = 0;
} else if (clock == CLOCK_BOOTTIME) {
mlibc::infoLogger() << "\e[31mmlibc: clock_gettime does not support CLOCK_BOOTTIME"
"\e[39m"
<< frg::endlog;
*secs = 0;
*nanos = 0;
uint64_t tick;
HEL_CHECK(helGetClock(&tick));

*secs = tick / 1000000000;
*nanos = tick % 1000000000;
} else {
mlibc::panicLogger() << "mlibc: Unexpected clock " << clock << frg::endlog;
}
Expand All @@ -82,4 +84,42 @@ int sys_clock_getres(int clock, time_t *secs, long *nanos) {
return 0;
}

int sys_setitimer(int which, const struct itimerval *new_value, struct itimerval *old_value) {
if (which != ITIMER_REAL) {
mlibc::infoLogger() << "mlibc: setitimers other than ITIMER_REAL are unsupported"
<< frg::endlog;
return EINVAL;
}

managarm::posix::SetIntervalTimerRequest<MemoryAllocator> req(getSysdepsAllocator());
req.set_which(which);
req.set_value_sec(new_value->it_value.tv_sec);
req.set_value_usec(new_value->it_value.tv_usec);
req.set_interval_sec(new_value->it_interval.tv_sec);
req.set_interval_usec(new_value->it_interval.tv_usec);

auto [offer, send_req, recv_resp] = exchangeMsgsSync(
getPosixLane(),
helix_ng::offer(
helix_ng::sendBragiHeadOnly(req, getSysdepsAllocator()), helix_ng::recvInline()
)
);
HEL_CHECK(offer.error());
HEL_CHECK(send_req.error());
HEL_CHECK(recv_resp.error());

managarm::posix::SetIntervalTimerResponse<MemoryAllocator> resp(getSysdepsAllocator());
resp.ParseFromArray(recv_resp.data(), recv_resp.length());
__ensure(resp.error() == managarm::posix::Errors::SUCCESS);

if (old_value) {
old_value->it_value.tv_sec = resp.value_sec();
old_value->it_value.tv_usec = resp.value_usec();
old_value->it_interval.tv_sec = resp.interval_sec();
old_value->it_interval.tv_usec = resp.interval_usec();
}

return 0;
}

} // namespace mlibc
Loading