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)));