mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-29 06:02:07 +03:00
Kernel/Userland: Add a halt syscall, and a shutdown binary to invoke it
This commit is contained in:
parent
9e0f7acfe5
commit
952382b413
Notes:
sideshowbarker
2024-07-19 13:35:18 +09:00
Author: https://github.com/rburchell Commit: https://github.com/SerenityOS/serenity/commit/952382b4134 Pull-request: https://github.com/SerenityOS/serenity/pull/232 Reviewed-by: https://github.com/awesomekling
@ -68,3 +68,11 @@ void FS::sync()
|
||||
for (auto fs : fses)
|
||||
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; }
|
||||
static FS* from_fsid(dword);
|
||||
static void sync();
|
||||
static void lock_all();
|
||||
|
||||
virtual bool initialize() = 0;
|
||||
virtual const char* class_name() const = 0;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <Kernel/Arch/i386/CPU.h>
|
||||
#include <Kernel/Console.h>
|
||||
#include <Kernel/Process.h>
|
||||
#include <Kernel/IO.h>
|
||||
#include <Kernel/ProcessTracer.h>
|
||||
#include <Kernel/Scheduler.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);
|
||||
case Syscall::SC_sched_getparam:
|
||||
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:
|
||||
kprintf("<%u> int0x82: Unknown function %u requested {%x, %x, %x}\n", current->process().pid(), function, arg1, arg2, arg3);
|
||||
return -ENOSYS;
|
||||
|
@ -112,7 +112,8 @@ struct timeval;
|
||||
__ENUMERATE_SYSCALL(getpeername) \
|
||||
__ENUMERATE_SYSCALL(sched_setparam) \
|
||||
__ENUMERATE_SYSCALL(sched_getparam) \
|
||||
__ENUMERATE_SYSCALL(fchown)
|
||||
__ENUMERATE_SYSCALL(fchown) \
|
||||
__ENUMERATE_SYSCALL(halt)
|
||||
|
||||
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…
Reference in New Issue
Block a user