1
0
mirror of https://github.com/EnderIce2/Fennix.git synced 2025-07-18 02:31:42 +00:00
Files
.github
.vscode
Bootloader
Drivers
Kernel
.vscode
arch
core
driver
memory
panic
time
video
acpi.cpp
console.cpp
cpu.cpp
debugger.cpp
disk.cpp
dsdt.cpp
interrupts_manager.cpp
lock.cpp
pci.cpp
power.cpp
random.cpp
smbios.cpp
smbios.hpp
stack_check.cpp
symbols.cpp
syscalls.cpp
ubsan.c
ubsan.h
exec
files
include
include_std
kshell
library
network
profiling
storage
subsystem
syscalls
tasking
tests
tty
virtualization
.editorconfig
.gdbinit
.gitignore
ISSUES.md
Makefile
README.md
TODO.md
dump.sh
kernel.cpp
kernel.h
kernel_config.cpp
kernel_thread.cpp
kernel_vfs.cpp
Userspace
initrd
tools
.editorconfig
.gitignore
.gitlab-ci.yml
CODE_OF_CONDUCT.md
CONTRIBUTING.md
CREDITS.md
Doxyfile
Fennix Bootloader.code-workspace
Fennix Drivers.code-workspace
Fennix Kernel.code-workspace
Fennix Userspace.code-workspace
Fennix Website.code-workspace
Fennix.code-workspace
LICENSE.md
LICENSES.md
Makefile
README.md
SECURITY.md
STYLE_GUIDE.md
config.mk
Fennix/Kernel/core/syscalls.cpp
2025-01-10 17:26:26 +02:00

104 lines
2.2 KiB
C++

/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include <syscalls.hpp>
#include <debug.h>
#include "../kernel.h"
class AutoSwitchPageTable
{
private:
void *Original;
public:
AutoSwitchPageTable()
{
#if defined(__amd64__) || defined(__i386__)
asmv("mov %%cr3, %0"
: "=r"(Original));
asmv("mov %0, %%cr3"
:
: "r"(KernelPageTable));
debug(" + %#lx %s(%d)", Original,
thisProcess->Name, thisProcess->ID);
#endif
}
~AutoSwitchPageTable()
{
#if defined(__amd64__) || defined(__i386__)
debug("- %#lx %s(%d)", Original,
thisProcess->Name, thisProcess->ID);
asmv("mov %0, %%cr3"
:
: "r"(Original));
#endif
}
};
extern "C" uintptr_t SystemCallsHandler(SyscallsFrame *Frame)
{
/* Automatically switch to kernel page table
and switch back when this function returns. */
AutoSwitchPageTable PageSwitcher;
uint64_t _ctime = TimeManager->GetCounter();
Tasking::TaskInfo *Ptinfo = &thisProcess->Info;
Tasking::TaskInfo *Ttinfo = &thisThread->Info;
uintptr_t ret;
if (Config.UseLinuxSyscalls)
{
ret = HandleLinuxSyscalls(Frame);
goto Ret;
}
switch (Ttinfo->Compatibility)
{
case Tasking::TaskCompatibility::Native:
{
ret = HandleNativeSyscalls(Frame);
break;
}
case Tasking::TaskCompatibility::Linux:
{
ret = HandleLinuxSyscalls(Frame);
break;
}
case Tasking::TaskCompatibility::Windows:
{
error("Windows compatibility not implemented yet.");
assert(false);
break;
}
default:
{
error("Unknown compatibility mode!");
assert(false);
break;
}
}
Ret:
Ptinfo->KernelTime += TimeManager->GetCounter() - _ctime;
Ttinfo->KernelTime += TimeManager->GetCounter() - _ctime;
return ret;
}