From 8a4099a82b2c770f2a3fa4985016a80b62af9106 Mon Sep 17 00:00:00 2001 From: Dennis Bonke Date: Thu, 14 Mar 2024 20:31:33 +0100 Subject: [PATCH] sysdeps/managarm: Implement sys_reboot --- sysdeps/managarm/generic/file.cpp | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/sysdeps/managarm/generic/file.cpp b/sysdeps/managarm/generic/file.cpp index 27a69b2d6..e920f9c99 100644 --- a/sysdeps/managarm/generic/file.cpp +++ b/sysdeps/managarm/generic/file.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -1334,6 +1335,37 @@ int sys_signalfd_create(const sigset_t *masks, int flags, int *fd) { return 0; } +int sys_reboot(int command) { + if(command != RB_POWER_OFF && command != RB_AUTOBOOT) { + mlibc::infoLogger() << "mlibc: Anything other than power off or reboot is not supported yet!" << frg::endlog; + return EINVAL; + } + + SignalGuard sguard; + + managarm::posix::RebootRequest req(getSysdepsAllocator()); + req.set_cmd(command); + + auto [offer, sendReq, recvResp] = exchangeMsgsSync( + getPosixLane(), + helix_ng::offer( + helix_ng::sendBragiHeadOnly(req, getSysdepsAllocator()), + helix_ng::recvInline() + ) + ); + + HEL_CHECK(offer.error()); + HEL_CHECK(sendReq.error()); + HEL_CHECK(recvResp.error()); + + managarm::posix::SvrResponse resp(getSysdepsAllocator()); + resp.ParseFromArray(recvResp.data(), recvResp.length()); + if(resp.error() == managarm::posix::Errors::INSUFFICIENT_PERMISSION) + return EPERM; + __ensure(resp.error() == managarm::posix::Errors::SUCCESS); + return 0; +} + int sys_inotify_create(int flags, int *fd) { __ensure(!(flags & ~(IN_CLOEXEC | IN_NONBLOCK)));