1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:37:46 +00:00

Kernel+UserspaceEmulator: Add sys$emuctl() system call

This returns ENOSYS if you are running in the real kernel, and some
other result if you are running in UserspaceEmulator.

There are other ways we could check if we're inside an emulator, but
it seemed easier to just ask. :^)
This commit is contained in:
Andreas Kling 2021-03-09 08:16:00 +01:00
parent d650b38eb9
commit 84725ef3a5
6 changed files with 48 additions and 1 deletions

View file

@ -192,7 +192,8 @@ namespace Kernel {
S(abort) \ S(abort) \
S(anon_create) \ S(anon_create) \
S(msyscall) \ S(msyscall) \
S(readv) S(readv) \
S(emuctl)
namespace Syscall { namespace Syscall {

View file

@ -137,6 +137,7 @@ set(KERNEL_SOURCES
Syscalls/debug.cpp Syscalls/debug.cpp
Syscalls/disown.cpp Syscalls/disown.cpp
Syscalls/dup2.cpp Syscalls/dup2.cpp
Syscalls/emuctl.cpp
Syscalls/execve.cpp Syscalls/execve.cpp
Syscalls/exit.cpp Syscalls/exit.cpp
Syscalls/fcntl.cpp Syscalls/fcntl.cpp

View file

@ -211,6 +211,7 @@ public:
void stop_tracing(); void stop_tracing();
void tracer_trap(Thread&, const RegisterState&); void tracer_trap(Thread&, const RegisterState&);
KResultOr<int> sys$emuctl();
KResultOr<int> sys$yield(); KResultOr<int> sys$yield();
KResultOr<int> sys$sync(); KResultOr<int> sys$sync();
KResultOr<int> sys$beep(); KResultOr<int> sys$beep();

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <Kernel/Process.h>
namespace Kernel {
KResultOr<int> Process::sys$emuctl()
{
return ENOSYS;
}
}

View file

@ -518,6 +518,8 @@ u32 Emulator::virt_syscall(u32 function, u32 arg1, u32 arg2, u32 arg3)
return virt$getrandom(arg1, arg2, arg3); return virt$getrandom(arg1, arg2, arg3);
case SC_fork: case SC_fork:
return virt$fork(); return virt$fork();
case SC_emuctl:
return virt$emuctl();
case SC_sched_getparam: case SC_sched_getparam:
return virt$sched_getparam(arg1, arg2); return virt$sched_getparam(arg1, arg2);
case SC_sched_setparam: case SC_sched_setparam:
@ -1265,6 +1267,11 @@ int Emulator::virt$ioctl([[maybe_unused]] int fd, unsigned request, [[maybe_unus
TODO(); TODO();
} }
int Emulator::virt$emuctl()
{
return 0;
}
int Emulator::virt$fork() int Emulator::virt$fork()
{ {
int rc = fork(); int rc = fork();

View file

@ -82,6 +82,7 @@ private:
void register_signal_handlers(); void register_signal_handlers();
void setup_signal_trampoline(); void setup_signal_trampoline();
int virt$emuctl();
int virt$fork(); int virt$fork();
int virt$execve(FlatPtr); int virt$execve(FlatPtr);
int virt$access(FlatPtr, size_t, int); int virt$access(FlatPtr, size_t, int);