mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:37:34 +00:00
Kernel/Userland: Add a halt syscall, and a shutdown binary to invoke it
This commit is contained in:
parent
9e0f7acfe5
commit
952382b413
5 changed files with 38 additions and 1 deletions
|
@ -68,3 +68,11 @@ void FS::sync()
|
||||||
for (auto fs : fses)
|
for (auto fs : fses)
|
||||||
fs->flush_writes();
|
fs->flush_writes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FS::lock_all()
|
||||||
|
{
|
||||||
|
for (auto& it : all_fses()) {
|
||||||
|
it.value->m_lock.lock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ public:
|
||||||
unsigned fsid() const { return m_fsid; }
|
unsigned fsid() const { return m_fsid; }
|
||||||
static FS* from_fsid(dword);
|
static FS* from_fsid(dword);
|
||||||
static void sync();
|
static void sync();
|
||||||
|
static void lock_all();
|
||||||
|
|
||||||
virtual bool initialize() = 0;
|
virtual bool initialize() = 0;
|
||||||
virtual const char* class_name() const = 0;
|
virtual const char* class_name() const = 0;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <Kernel/Arch/i386/CPU.h>
|
#include <Kernel/Arch/i386/CPU.h>
|
||||||
#include <Kernel/Console.h>
|
#include <Kernel/Console.h>
|
||||||
#include <Kernel/Process.h>
|
#include <Kernel/Process.h>
|
||||||
|
#include <Kernel/IO.h>
|
||||||
#include <Kernel/ProcessTracer.h>
|
#include <Kernel/ProcessTracer.h>
|
||||||
#include <Kernel/Scheduler.h>
|
#include <Kernel/Scheduler.h>
|
||||||
#include <Kernel/Syscall.h>
|
#include <Kernel/Syscall.h>
|
||||||
|
@ -281,6 +282,15 @@ static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2,
|
||||||
return current->process().sys$sched_setparam((pid_t)arg1, (struct sched_param*)arg2);
|
return current->process().sys$sched_setparam((pid_t)arg1, (struct sched_param*)arg2);
|
||||||
case Syscall::SC_sched_getparam:
|
case Syscall::SC_sched_getparam:
|
||||||
return current->process().sys$sched_setparam((pid_t)arg1, (struct sched_param*)arg2);
|
return current->process().sys$sched_setparam((pid_t)arg1, (struct sched_param*)arg2);
|
||||||
|
case Syscall::SC_halt: {
|
||||||
|
dbgprintf("<%u> halting! acquiring locks...\n");
|
||||||
|
FS::lock_all();
|
||||||
|
dbgprintf("<%u> halting! syncing...\n");
|
||||||
|
FS::sync();
|
||||||
|
dbgprintf("<%u> halting! bye, friends...\n");
|
||||||
|
IO::out16(0x604, 0x2000);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
kprintf("<%u> int0x82: Unknown function %u requested {%x, %x, %x}\n", current->process().pid(), function, arg1, arg2, arg3);
|
kprintf("<%u> int0x82: Unknown function %u requested {%x, %x, %x}\n", current->process().pid(), function, arg1, arg2, arg3);
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
|
|
|
@ -112,7 +112,8 @@ struct timeval;
|
||||||
__ENUMERATE_SYSCALL(getpeername) \
|
__ENUMERATE_SYSCALL(getpeername) \
|
||||||
__ENUMERATE_SYSCALL(sched_setparam) \
|
__ENUMERATE_SYSCALL(sched_setparam) \
|
||||||
__ENUMERATE_SYSCALL(sched_getparam) \
|
__ENUMERATE_SYSCALL(sched_getparam) \
|
||||||
__ENUMERATE_SYSCALL(fchown)
|
__ENUMERATE_SYSCALL(fchown) \
|
||||||
|
__ENUMERATE_SYSCALL(halt)
|
||||||
|
|
||||||
namespace Syscall {
|
namespace Syscall {
|
||||||
|
|
||||||
|
|
17
Userland/shutdown.cpp
Normal file
17
Userland/shutdown.cpp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#include <Kernel/Syscall.h>
|
||||||
|
#include <LibCore/CArgsParser.h>
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
CArgsParser args_parser("shutdown");
|
||||||
|
args_parser.add_arg("n", "shut down now");
|
||||||
|
CArgsParserResult args = args_parser.parse(argc, (const char**)argv);
|
||||||
|
|
||||||
|
if (args.is_present("n")) {
|
||||||
|
syscall(SC_halt);
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
args_parser.print_usage();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue