Kernel+Userland: Addd reboot syscall (#334)

Rolling with the theme of adding a dialog to shutdown the machine, it is
probably nice to have a way to reboot the machine without performing a full
system powerdown.

A reboot program has been added to `/bin/` as well as a corresponding
`syscall` (SC_reboot). This syscall works by attempting to pulse the 8042
keyboard controller. Note that this is NOT supported on  new machines, and
should only be a fallback until we have proper ACPI support.

The implementation causes a triple fault in QEMU, which then restarts the
system. The filesystems are locked and synchronized before this occurs,
so there shouldn't be any corruption etctera.
This commit is contained in:
Jesse 2019-07-19 17:58:12 +10:00 committed by Andreas Kling
parent 23d45532fc
commit a27c9e3e01
Notes: sideshowbarker 2024-07-19 13:10:28 +09:00
7 changed files with 45 additions and 2 deletions

View file

@ -12,6 +12,7 @@
#include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/FileSystem/SharedMemory.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/IO.h>
#include <Kernel/KSyms.h>
#include <Kernel/Multiboot.h>
#include <Kernel/Net/Socket.h>
@ -19,8 +20,8 @@
#include <Kernel/ProcessTracer.h>
#include <Kernel/RTC.h>
#include <Kernel/Scheduler.h>
#include <Kernel/StdLib.h>
#include <Kernel/SharedBuffer.h>
#include <Kernel/StdLib.h>
#include <Kernel/Syscall.h>
#include <Kernel/TTY/MasterPTY.h>
#include <Kernel/kmalloc.h>
@ -2635,6 +2636,21 @@ int Process::sys$systrace(pid_t pid)
return fd;
}
int Process::sys$reboot()
{
if (!is_superuser())
return -EPERM;
dbgprintf("acquiring FS locks...\n");
FS::lock_all();
dbgprintf("syncing mounted filesystems...\n");
FS::sync();
dbgprintf("attempting reboot via KB Controller...\n");
IO::out8(0x64, 0xFE);
return ESUCCESS;
}
ProcessTracer& Process::ensure_tracer()
{
if (!m_tracer)