20 #include "SyscallManager.h" 21 #include "pedigree/kernel/LockGuard.h" 22 #include "pedigree/kernel/Log.h" 23 #include "pedigree/kernel/Subsystem.h" 24 #include "pedigree/kernel/compiler.h" 25 #include "pedigree/kernel/process/Process.h" 26 #include "pedigree/kernel/process/Thread.h" 27 #include "pedigree/kernel/process/TimeTracker.h" 28 #include "pedigree/kernel/processor/Processor.h" 29 #include "pedigree/kernel/processor/ProcessorInformation.h" 30 #include "pedigree/kernel/processor/SyscallHandler.h" 31 #include "pedigree/kernel/processor/state.h" 35 #define TIME_SYSCALLS 0 50 if (
UNLIKELY(pHandler != 0 && m_pHandler[Service] != 0))
52 if (
UNLIKELY(pHandler == 0 && m_pHandler[Service] == 0))
55 m_pHandler[Service] = pHandler;
67 size_t syscallNumber = syscallState.getSyscallNumber();
74 size_t serviceNumber = syscallState.getSyscallService();
76 if (
UNLIKELY(serviceNumber >= serviceEnd))
85 pHandler = m_Instance.m_pHandler[serviceNumber];
90 uint64_t result = pHandler->
syscall(syscallState);
96 if (serviceNumber == linuxCompat)
100 syscallState.setSyscallReturnValue(-errno);
104 syscallState.setSyscallReturnValue(result);
109 syscallState.setSyscallReturnValue(result);
110 syscallState.setSyscallErrno(errno);
118 NOTICE(
"Unwind state exit, in interrupt handler");
128 if ((syscallState.m_RFlagsR11 & 0x200) != 0x200)
130 syscallState.m_RFlagsR11 |= 0x200;
135 Time::Timestamp value = syscallTimer.
value();
137 "SYSCALL pid=" <<
Dec << pProcess->
getId()
138 <<
" service=" << serviceNumber
139 <<
" num=" << syscallNumber <<
" ns=" << value <<
Hex);
144 Service_t service, uintptr_t
function, uintptr_t p1, uintptr_t p2,
145 uintptr_t p3, uintptr_t p4, uintptr_t p5)
147 uint64_t rax = (
static_cast<uint64_t
>(service) << 16) |
function;
149 asm volatile(
"mov %6, %%r8; \ 152 :
"0"(rax),
"b"(p1),
"d"(p2),
"S"(p3),
"D"(p4),
"m"(p5)
161 extern "C" void syscall_handler();
175 0xC0000082, reinterpret_cast<uint64_t>(syscall_handler));
184 for (
size_t i = 0; i < serviceEnd; i++)
static uint64_t readMachineSpecificRegister(uint32_t index)
static X64SyscallManager m_Instance
static EXPORTED_PUBLIC SyscallManager & instance()
virtual bool registerSyscallHandler(Service_t Service, SyscallHandler *pHandler)
X64SyscallManager() INITIALISATION_ONLY
virtual uintptr_t syscall(SyscallState &State)=0
static ProcessorInformation & information()
Timestamp value()
Read the stopwatch value in nanoseconds.
virtual ~X64SyscallManager()
static void writeMachineSpecificRegister(uint32_t index, uint64_t value)
void stop()
Stop the stopwatch if it is not already stopped.
SyscallHandler * m_pHandler[serviceEnd]
static X64SyscallManager & instance()
uintptr_t syscall(Service_t service, uintptr_t function, uintptr_t p1, uintptr_t p2, uintptr_t p3, uintptr_t p4, uintptr_t p5)
static void setInterrupts(bool bEnable)
static void initialiseProcessor() INITIALISATION_ONLY