2010-07-24 01:12:13 +00:00
|
|
|
/*
|
|
|
|
* FILE: ntoskrnl/ke/amd64/trap.S
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PURPOSE: System Traps, Entrypoints and Exitpoints
|
|
|
|
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
#include <asm.inc>
|
|
|
|
#include <ksamd64.inc>
|
2011-09-16 17:47:32 +00:00
|
|
|
#include <trapamd64.inc>
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
EXTERN KiDispatchException:PROC
|
|
|
|
EXTERN KeBugCheckWithTf:PROC
|
|
|
|
EXTERN MmAccessFault:PROC
|
|
|
|
EXTERN KiSystemFatalException:PROC
|
|
|
|
EXTERN KiNpxNotAvailableFaultHandler:PROC
|
|
|
|
EXTERN KiGeneralProtectionFaultHandler:PROC
|
|
|
|
EXTERN KiXmmExceptionHandler:PROC
|
2011-09-16 18:39:55 +00:00
|
|
|
EXTERN KiDeliverApc:PROC
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
EXTERN KiDpcInterruptHandler:PROC
|
2018-02-04 22:44:43 +00:00
|
|
|
EXTERN PsConvertToGuiThread:PROC
|
[NTOS:KE:X64] Improve kernel stack switching on GUI system calls
To be 100% correct and not rely on assumptions, stack switching can only be done when all previous code - starting with the syscall entry point - is pure asm code, since we can't rely on the C compiler to not use stack addresses in a way that is not transparent. Therefore the new code uses the same mechanism as for normal system calls, returning the address of the asm function KiConvertToGuiThread, which is then called like an Nt* function would be called normally. KiConvertToGuiThread then allocated a new stack, switches to it (which is now fine, since all the code is asm), frees the old stack, calls PsConvertToGuiThread (which now will not try to allocate another stack, since we already have one) and then jumps into the middle of KiSystemCallEntry64, where the system call is handled again.
Also simplify KiSystemCallEntry64 a bit by copying the first parameters into the trap frame, avoiding to allocate additional stack space for the call to KiSystemCallHandler, which now overlaps with the space that is allocated for the Nt* function.
Finally fix the locations where r10 and r11 are stored, which is TrapFrame->Rcx and TrapFrame->EFlags, based on the situation in user mode.
2018-02-06 19:52:16 +00:00
|
|
|
EXTERN MmCreateKernelStack:PROC
|
|
|
|
EXTERN MmDeleteKernelStack:PROC
|
2015-08-28 14:01:58 +00:00
|
|
|
EXTERN KdSetOwedBreakpoints:PROC
|
2024-12-05 13:37:28 +00:00
|
|
|
EXTERN KeAcquireSpinLockAtDpcLevel:PROC
|
|
|
|
EXTERN KeReleaseSpinLockFromDpcLevel:PROC
|
2015-08-28 14:01:58 +00:00
|
|
|
|
|
|
|
|
2010-07-24 01:12:13 +00:00
|
|
|
/* Helper Macros *************************************************************/
|
|
|
|
|
2011-09-16 17:47:32 +00:00
|
|
|
MACRO(DispatchException, Status, Number, P1, P2, P3)
|
|
|
|
mov eax, Status
|
|
|
|
mov edx, Number
|
|
|
|
mov r9, P1
|
|
|
|
mov r10, P2
|
|
|
|
mov r11, P3
|
|
|
|
call InternalDispatchException
|
2010-07-24 01:12:13 +00:00
|
|
|
ENDM
|
|
|
|
|
2011-09-16 17:47:32 +00:00
|
|
|
MACRO(Fatal, BugcheckCode)
|
|
|
|
/* Bugcheck */
|
|
|
|
mov ecx, BugcheckCode
|
|
|
|
mov rdx, rbp
|
|
|
|
call KiSystemFatalException
|
2010-07-24 01:12:13 +00:00
|
|
|
ENDM
|
|
|
|
|
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
|
|
|
.code64
|
|
|
|
|
|
|
|
ALIGN 8
|
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
MACRO(UnexpectedVectorStub, Vector)
|
|
|
|
/* This nop is to make the relative jmp address 4 bytes aligned and to
|
|
|
|
make the whole code 8 bytes long */
|
|
|
|
nop
|
|
|
|
/* This is a push instruction with 8bit operand. Since the instruction
|
|
|
|
sign extends the value to 32 bits, we need to offset it */
|
|
|
|
PUBLIC KxUnexpectedInterrupt&Vector
|
|
|
|
KxUnexpectedInterrupt&Vector:
|
|
|
|
push (Vector - 128)
|
|
|
|
jmp KiUnexpectedInterrupt
|
|
|
|
ENDM
|
|
|
|
|
|
|
|
PUBLIC KiUnexpectedRange
|
|
|
|
KiUnexpectedRange:
|
2010-07-24 01:12:13 +00:00
|
|
|
Vector = 0
|
|
|
|
REPEAT 256
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
UnexpectedVectorStub %Vector
|
2010-07-24 01:12:13 +00:00
|
|
|
Vector = Vector+1
|
|
|
|
ENDR
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
PUBLIC KiUnexpectedRangeEnd
|
|
|
|
KiUnexpectedRangeEnd:
|
|
|
|
|
|
|
|
PUBLIC KiInterruptDispatchTemplate
|
|
|
|
KiInterruptDispatchTemplate:
|
|
|
|
/* This instruction pushes the return address on the stack, which is the
|
|
|
|
address of the interrupt object's DispatchCode member, then jumps
|
|
|
|
to the address stored in the interrupt object's DispatchAddress member */
|
|
|
|
call qword ptr KiInterruptDispatchTemplate[rip - KINTERRUPT_DispatchCode + KINTERRUPT_DispatchAddress]
|
|
|
|
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
// rbp = TrapFrame, eax = ExceptionCode, edx = NumParams, r9,r10,r11 = params
|
2014-09-18 14:06:31 +00:00
|
|
|
FUNC InternalDispatchException
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Allocate stack space for EXCEPTION_RECORD and KEXCEPTION_FRAME */
|
2011-02-10 10:30:43 +00:00
|
|
|
sub rsp, EXCEPTION_RECORD_LENGTH + KEXCEPTION_FRAME_LENGTH
|
|
|
|
.allocstack (EXCEPTION_RECORD_LENGTH + KEXCEPTION_FRAME_LENGTH)
|
2010-07-24 01:12:13 +00:00
|
|
|
.endprolog
|
|
|
|
|
|
|
|
/* Set up EXCEPTION_RECORD */
|
2011-02-10 10:30:43 +00:00
|
|
|
lea rcx, [rsp + KEXCEPTION_FRAME_LENGTH]
|
2010-07-24 01:12:13 +00:00
|
|
|
mov [rcx + EXCEPTION_RECORD_ExceptionCode], eax
|
|
|
|
xor rax, rax
|
|
|
|
mov [rcx + EXCEPTION_RECORD_ExceptionFlags], eax
|
|
|
|
mov [rcx + EXCEPTION_RECORD_ExceptionRecord], rax
|
|
|
|
mov rax, [rbp + KTRAP_FRAME_Rip]
|
|
|
|
mov [rcx + EXCEPTION_RECORD_ExceptionAddress], rax
|
|
|
|
mov [rcx + EXCEPTION_RECORD_NumberParameters], edx
|
|
|
|
mov [rcx + EXCEPTION_RECORD_ExceptionInformation + HEX(00)], r9
|
|
|
|
mov [rcx + EXCEPTION_RECORD_ExceptionInformation + HEX(08)], r10
|
|
|
|
mov [rcx + EXCEPTION_RECORD_ExceptionInformation + HEX(10)], r11
|
|
|
|
|
|
|
|
/* Set up KEXCEPTION_FRAME */
|
|
|
|
mov rax, [rbp + KTRAP_FRAME_Rbp]
|
|
|
|
mov [rsp + KEXCEPTION_FRAME_Rbp], rax
|
|
|
|
mov [rsp + KEXCEPTION_FRAME_Rbx], rbx
|
|
|
|
mov [rsp + KEXCEPTION_FRAME_Rdi], rdi
|
|
|
|
mov [rsp + KEXCEPTION_FRAME_Rsi], rsi
|
|
|
|
mov [rsp + KEXCEPTION_FRAME_R12], r12
|
|
|
|
mov [rsp + KEXCEPTION_FRAME_R13], r13
|
|
|
|
mov [rsp + KEXCEPTION_FRAME_R14], r14
|
|
|
|
mov [rsp + KEXCEPTION_FRAME_R15], r15
|
|
|
|
movdqa [rsp + KEXCEPTION_FRAME_Xmm6], xmm6
|
|
|
|
movdqa [rsp + KEXCEPTION_FRAME_Xmm7], xmm7
|
|
|
|
movdqa [rsp + KEXCEPTION_FRAME_Xmm8], xmm8
|
|
|
|
movdqa [rsp + KEXCEPTION_FRAME_Xmm9], xmm9
|
|
|
|
movdqa [rsp + KEXCEPTION_FRAME_Xmm10], xmm10
|
|
|
|
movdqa [rsp + KEXCEPTION_FRAME_Xmm11], xmm11
|
|
|
|
movdqa [rsp + KEXCEPTION_FRAME_Xmm12], xmm12
|
|
|
|
movdqa [rsp + KEXCEPTION_FRAME_Xmm13], xmm13
|
|
|
|
movdqa [rsp + KEXCEPTION_FRAME_Xmm14], xmm14
|
|
|
|
movdqa [rsp + KEXCEPTION_FRAME_Xmm15], xmm15
|
|
|
|
mov qword ptr [rsp + KEXCEPTION_FRAME_Return], 0
|
|
|
|
|
|
|
|
/* Call KiDispatchException */
|
|
|
|
// rcx already points to ExceptionRecord
|
|
|
|
mov rdx, rsp // ExceptionFrame
|
|
|
|
mov r8, rbp // TrapFrame
|
|
|
|
mov r9b, [r8 + KTRAP_FRAME_PreviousMode] // PreviousMode
|
|
|
|
mov byte ptr [rsp + KEXCEPTION_FRAME_P5], 1 // FirstChance
|
|
|
|
call KiDispatchException
|
|
|
|
|
|
|
|
/* Restore registers */
|
|
|
|
mov r12, [rsp + KEXCEPTION_FRAME_R12]
|
|
|
|
mov r13, [rsp + KEXCEPTION_FRAME_R13]
|
|
|
|
mov r14, [rsp + KEXCEPTION_FRAME_R14]
|
|
|
|
mov r15, [rsp + KEXCEPTION_FRAME_R15]
|
|
|
|
movdqa xmm6, [rsp + KEXCEPTION_FRAME_Xmm6]
|
|
|
|
movdqa xmm7, [rsp + KEXCEPTION_FRAME_Xmm7]
|
|
|
|
movdqa xmm8, [rsp + KEXCEPTION_FRAME_Xmm8]
|
|
|
|
movdqa xmm9, [rsp + KEXCEPTION_FRAME_Xmm9]
|
|
|
|
movdqa xmm10, [rsp + KEXCEPTION_FRAME_Xmm10]
|
|
|
|
movdqa xmm11, [rsp + KEXCEPTION_FRAME_Xmm11]
|
|
|
|
movdqa xmm12, [rsp + KEXCEPTION_FRAME_Xmm12]
|
|
|
|
movdqa xmm13, [rsp + KEXCEPTION_FRAME_Xmm13]
|
|
|
|
movdqa xmm14, [rsp + KEXCEPTION_FRAME_Xmm14]
|
|
|
|
movdqa xmm15, [rsp + KEXCEPTION_FRAME_Xmm15]
|
|
|
|
|
2011-02-10 10:30:43 +00:00
|
|
|
add rsp, EXCEPTION_RECORD_LENGTH + KEXCEPTION_FRAME_LENGTH
|
2010-07-24 01:12:13 +00:00
|
|
|
ret
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
/* CPU EXCEPTION HANDLERS ****************************************************/
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
PUBLIC KiDivideErrorFault
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiDivideErrorFault
|
2010-07-24 01:12:13 +00:00
|
|
|
/* Push pseudo error code */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap TF_SAVE_ALL
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Enable interrupts */
|
|
|
|
sti
|
|
|
|
|
|
|
|
/* Dispatch the exception */
|
2011-09-16 17:47:32 +00:00
|
|
|
DispatchException STATUS_INTEGER_DIVIDE_BY_ZERO, 0, 0, 0, 0
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Return */
|
2011-09-16 17:47:32 +00:00
|
|
|
ExitTrap TF_SAVE_ALL
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiDebugTrapOrFault
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiDebugTrapOrFault
|
2010-07-24 01:12:13 +00:00
|
|
|
/* Push pseudo error code */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap TF_SAVE_ALL
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Check if the frame was from kernelmode */
|
|
|
|
test word ptr [rbp + KTRAP_FRAME_SegCs], 3
|
|
|
|
jz KiDebugTrapOrFaultKMode
|
|
|
|
|
|
|
|
/* Enable interrupts for user-mode */
|
|
|
|
sti
|
|
|
|
|
|
|
|
KiDebugTrapOrFaultKMode:
|
|
|
|
/* Dispatch the exception */
|
2011-09-16 17:47:32 +00:00
|
|
|
DispatchException STATUS_SINGLE_STEP, 0, 0, 0, 0
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Return */
|
2011-09-16 17:47:32 +00:00
|
|
|
ExitTrap TF_SAVE_ALL
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
2023-12-06 17:51:07 +00:00
|
|
|
EXTERN KiNmiInterruptHandler:PROC
|
|
|
|
|
|
|
|
FUNC KiNmiInterruptWithEf
|
|
|
|
/* Generate a KEXCEPTION_FRAME on the stack */
|
|
|
|
GENERATE_EXCEPTION_FRAME
|
|
|
|
|
|
|
|
/* Call the C handler */
|
|
|
|
lea rcx, [rsp + KEXCEPTION_FRAME_LENGTH]
|
|
|
|
lea rdx, [rsp]
|
|
|
|
call KiNmiInterruptHandler
|
|
|
|
|
|
|
|
/* Restore the registers from the KEXCEPTION_FRAME */
|
|
|
|
RESTORE_EXCEPTION_STATE
|
|
|
|
|
|
|
|
/* Return */
|
|
|
|
ret
|
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
PUBLIC KiNmiInterrupt
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiNmiInterrupt
|
2010-07-24 01:12:13 +00:00
|
|
|
/* Push pseudo error code */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap TF_SAVE_ALL
|
2010-07-24 01:12:13 +00:00
|
|
|
|
2023-12-06 17:51:07 +00:00
|
|
|
call KiNmiInterruptWithEf
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Return */
|
2011-09-16 17:47:32 +00:00
|
|
|
ExitTrap TF_SAVE_ALL
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiBreakpointTrap
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiBreakpointTrap
|
2010-07-24 01:12:13 +00:00
|
|
|
/* Push pseudo error code */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap TF_SAVE_ALL
|
2010-07-24 01:12:13 +00:00
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
/* Check if the frame was from kernelmode */
|
|
|
|
test word ptr [rbp + KTRAP_FRAME_SegCs], 3
|
|
|
|
jz KiBreakpointTrapKMode
|
|
|
|
|
|
|
|
/* Enable interrupts for user-mode */
|
|
|
|
sti
|
|
|
|
|
|
|
|
KiBreakpointTrapKMode:
|
2010-07-24 01:12:13 +00:00
|
|
|
/* Dispatch the exception */
|
2013-04-17 06:05:14 +00:00
|
|
|
DispatchException STATUS_BREAKPOINT, 3, BREAKPOINT_BREAK, 0, 0
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Return */
|
2011-09-16 17:47:32 +00:00
|
|
|
ExitTrap TF_SAVE_ALL
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiOverflowTrap
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiOverflowTrap
|
2010-07-24 01:12:13 +00:00
|
|
|
/* Push pseudo error code */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap TF_SAVE_ALL
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Enable interrupts */
|
|
|
|
sti
|
|
|
|
|
|
|
|
/* Dispatch the exception */
|
2011-09-16 17:47:32 +00:00
|
|
|
DispatchException STATUS_INTEGER_OVERFLOW, 3, 0, 0, 0
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Return */
|
2011-09-16 17:47:32 +00:00
|
|
|
ExitTrap TF_SAVE_ALL
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiBoundFault
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiBoundFault
|
2017-12-31 16:41:01 +00:00
|
|
|
/* Push pseudo error code */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap TF_SAVE_ALL
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Check if the frame was from kernelmode */
|
|
|
|
test word ptr [rbp + KTRAP_FRAME_SegCs], 3
|
2011-09-16 17:47:32 +00:00
|
|
|
jnz KiBoundFaultUserMode
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Bugcheck */
|
2011-09-16 17:47:32 +00:00
|
|
|
Fatal EXCEPTION_BOUND_CHECK
|
2010-07-24 01:12:13 +00:00
|
|
|
|
2011-09-16 17:47:32 +00:00
|
|
|
KiBoundFaultUserMode:
|
2010-07-24 01:12:13 +00:00
|
|
|
/* Enable interrupts for user-mode */
|
|
|
|
sti
|
|
|
|
|
|
|
|
/* Dispatch the exception */
|
2011-09-16 17:47:32 +00:00
|
|
|
DispatchException STATUS_ARRAY_BOUNDS_EXCEEDED, 0, 0, 0, 0
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Return */
|
2011-09-16 17:47:32 +00:00
|
|
|
ExitTrap TF_SAVE_ALL
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiInvalidOpcodeFault
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiInvalidOpcodeFault
|
2017-12-31 16:41:01 +00:00
|
|
|
/* Push pseudo error code */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap TF_SAVE_ALL
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Enable interrupts */
|
|
|
|
sti
|
|
|
|
|
|
|
|
/* Check if the frame was from kernelmode */
|
|
|
|
test word ptr [rbp + KTRAP_FRAME_SegCs], 3
|
|
|
|
jz KiInvalidOpcodeKernel
|
|
|
|
|
|
|
|
// FIXME: handle STATUS_INVALID_LOCK_SEQUENCE
|
|
|
|
|
|
|
|
KiInvalidOpcodeKernel:
|
|
|
|
/* Kernel mode fault */
|
2011-02-10 10:30:43 +00:00
|
|
|
|
2010-07-24 01:12:13 +00:00
|
|
|
/* Dispatch the exception */
|
2021-06-26 16:49:47 +00:00
|
|
|
DispatchException STATUS_ILLEGAL_INSTRUCTION, 0, 0, 0, 0
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Return */
|
2011-09-16 17:47:32 +00:00
|
|
|
ExitTrap TF_SAVE_ALL
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiNpxNotAvailableFault
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiNpxNotAvailableFault
|
2017-12-31 16:41:01 +00:00
|
|
|
/* Push pseudo error code */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap TF_SAVE_ALL
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Call the C handler */
|
|
|
|
mov rcx, rbp
|
|
|
|
call KiNpxNotAvailableFaultHandler
|
|
|
|
|
|
|
|
/* Check the return status code */
|
|
|
|
test eax, eax
|
|
|
|
jz KiNpxNotAvailableFaultExit
|
|
|
|
|
|
|
|
/* Dispatch the exception */
|
2011-09-16 17:47:32 +00:00
|
|
|
DispatchException eax, 3, 0, 0, 0
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
KiNpxNotAvailableFaultExit:
|
|
|
|
/* Return */
|
2011-09-16 17:47:32 +00:00
|
|
|
ExitTrap TF_SAVE_ALL
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiDoubleFaultAbort
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiDoubleFaultAbort
|
2022-07-23 11:35:14 +00:00
|
|
|
|
|
|
|
/* Hack for VBox, which "forgets" to push an error code on the stack! */
|
|
|
|
and rsp, HEX(FFFFFFFFFFFFFFF0)
|
|
|
|
|
2017-12-31 16:41:01 +00:00
|
|
|
/* A zero error code is pushed */
|
|
|
|
EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
|
2010-07-24 01:12:13 +00:00
|
|
|
|
2018-03-09 21:06:03 +00:00
|
|
|
int 3
|
2014-09-18 14:06:31 +00:00
|
|
|
|
2010-07-24 01:12:13 +00:00
|
|
|
/* Bugcheck */
|
2011-09-16 17:47:32 +00:00
|
|
|
Fatal 8 // EXCEPTION_DOUBLE_FAULT
|
2010-07-24 01:12:13 +00:00
|
|
|
jmp $
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiNpxSegmentOverrunAbort
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiNpxSegmentOverrunAbort
|
2017-12-31 16:41:01 +00:00
|
|
|
/* Push pseudo error code */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap TF_SAVE_ALL
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Bugcheck */
|
2011-09-16 17:47:32 +00:00
|
|
|
Fatal EXCEPTION_NPX_OVERRUN
|
2014-09-18 14:06:31 +00:00
|
|
|
|
2010-07-24 01:12:13 +00:00
|
|
|
jmp $
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiInvalidTssFault
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiInvalidTssFault
|
2010-07-24 01:12:13 +00:00
|
|
|
/* We have an error code */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Bugcheck */
|
2011-09-16 17:47:32 +00:00
|
|
|
Fatal EXCEPTION_INVALID_TSS
|
2010-07-24 01:12:13 +00:00
|
|
|
jmp $
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiSegmentNotPresentFault
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiSegmentNotPresentFault
|
2010-07-24 01:12:13 +00:00
|
|
|
/* We have an error code */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Bugcheck */
|
2011-09-16 17:47:32 +00:00
|
|
|
Fatal EXCEPTION_SEGMENT_NOT_PRESENT
|
2010-07-24 01:12:13 +00:00
|
|
|
jmp $
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiStackFault
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiStackFault
|
2010-07-24 01:12:13 +00:00
|
|
|
/* We have an error code */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Bugcheck */
|
2011-09-16 17:47:32 +00:00
|
|
|
Fatal EXCEPTION_STACK_FAULT
|
2010-07-24 01:12:13 +00:00
|
|
|
jmp $
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiGeneralProtectionFault
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiGeneralProtectionFault
|
2010-07-24 01:12:13 +00:00
|
|
|
/* We have an error code */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Call the C handler */
|
2011-09-16 09:46:08 +00:00
|
|
|
mov rcx, rbp
|
2010-07-24 01:12:13 +00:00
|
|
|
call KiGeneralProtectionFaultHandler
|
|
|
|
|
|
|
|
/* Check for success */
|
|
|
|
test eax, eax
|
|
|
|
jge KiGpfExit
|
|
|
|
|
2021-06-26 16:49:47 +00:00
|
|
|
/* Check for access violation */
|
|
|
|
cmp eax, STATUS_ACCESS_VIOLATION
|
|
|
|
je DispatchAccessViolation
|
|
|
|
|
|
|
|
/* Dispatch privileged instruction fault */
|
|
|
|
DispatchException eax, 0, 0, 0, 0
|
2022-12-09 18:19:29 +00:00
|
|
|
jmp KiGpfExit
|
2021-06-26 16:49:47 +00:00
|
|
|
|
|
|
|
DispatchAccessViolation:
|
|
|
|
|
|
|
|
/* Dispatch access violation */
|
|
|
|
DispatchException eax, 2, 0, -1, 0
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
KiGpfExit:
|
2011-09-16 17:47:32 +00:00
|
|
|
/* Return */
|
|
|
|
ExitTrap TF_SAVE_ALL
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiPageFault
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiPageFault
|
2010-07-24 01:12:13 +00:00
|
|
|
/* We have an error code */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Save page fault address */
|
|
|
|
mov rdx, cr2
|
|
|
|
mov [rbp + KTRAP_FRAME_FaultAddress], rdx
|
2024-03-25 20:23:19 +00:00
|
|
|
|
2022-12-15 19:44:43 +00:00
|
|
|
/* If interrupts are off, do not enable them */
|
2022-07-23 10:42:20 +00:00
|
|
|
test dword ptr [rbp + KTRAP_FRAME_EFlags], EFLAGS_IF_MASK
|
2022-12-15 19:44:43 +00:00
|
|
|
jz IntsDisabled
|
2010-07-24 01:12:13 +00:00
|
|
|
|
2012-03-28 21:09:03 +00:00
|
|
|
/* Enable interrupts for the page fault handler */
|
|
|
|
sti
|
|
|
|
|
2022-12-15 19:44:43 +00:00
|
|
|
IntsDisabled:
|
|
|
|
|
2010-07-24 01:12:13 +00:00
|
|
|
/* Call page fault handler */
|
2018-01-01 14:25:45 +00:00
|
|
|
mov ecx, [rbp + KTRAP_FRAME_ErrorCode] // FaultCode
|
2010-07-24 01:12:13 +00:00
|
|
|
// rdx == Address
|
|
|
|
mov r8b, [rbp + KTRAP_FRAME_SegCs] // Mode
|
|
|
|
and r8b, 1
|
|
|
|
mov r9, rbp // TrapInformation
|
|
|
|
call MmAccessFault
|
|
|
|
|
|
|
|
/* Check for success */
|
|
|
|
test eax, eax
|
2015-08-28 03:03:26 +00:00
|
|
|
jl PageFaultError
|
2010-07-24 01:12:13 +00:00
|
|
|
|
2015-08-28 14:01:58 +00:00
|
|
|
/* Check whether the kernel debugger has owed breakpoints to be inserted */
|
2015-08-28 03:03:26 +00:00
|
|
|
call KdSetOwedBreakpoints
|
2015-08-28 14:01:58 +00:00
|
|
|
/* We succeeded, return */
|
2015-08-28 03:03:26 +00:00
|
|
|
jmp PageFaultReturn
|
|
|
|
|
|
|
|
PageFaultError:
|
2015-08-28 14:01:58 +00:00
|
|
|
|
2024-09-07 20:33:48 +00:00
|
|
|
/* Set parameter 1 to write/execute flag.
|
|
|
|
See https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-exception_record */
|
2010-07-24 01:12:13 +00:00
|
|
|
mov r9d, [rbp + KTRAP_FRAME_ErrorCode]
|
2024-09-07 20:33:48 +00:00
|
|
|
shr r9d, 1
|
|
|
|
and r9d, 9
|
2010-07-24 01:12:13 +00:00
|
|
|
|
2022-12-15 19:44:43 +00:00
|
|
|
/* Set parameter 2 to faulting address */
|
2010-07-24 01:12:13 +00:00
|
|
|
mov r10, cr2 // Param2 = faulting address
|
|
|
|
|
|
|
|
cmp eax, STATUS_ACCESS_VIOLATION
|
|
|
|
je AccessViolation
|
|
|
|
cmp eax, STATUS_GUARD_PAGE_VIOLATION
|
|
|
|
je SpecialCode
|
|
|
|
cmp eax, STATUS_STACK_OVERFLOW
|
|
|
|
je SpecialCode
|
|
|
|
|
|
|
|
InPageException:
|
|
|
|
/* Dispatch in-page exception */
|
|
|
|
mov r11d, eax // Param3 = Status
|
|
|
|
mov eax, STATUS_IN_PAGE_ERROR // ExceptionCode
|
|
|
|
mov edx, 3 // ParamCount
|
|
|
|
call InternalDispatchException
|
|
|
|
jmp PageFaultReturn
|
|
|
|
|
|
|
|
AccessViolation:
|
|
|
|
/* Use more proper status code */
|
|
|
|
mov eax, KI_EXCEPTION_ACCESS_VIOLATION
|
|
|
|
|
|
|
|
SpecialCode:
|
|
|
|
/* Setup a normal page fault exception */
|
|
|
|
mov edx, 2 // ParamCount
|
|
|
|
call InternalDispatchException
|
|
|
|
|
|
|
|
PageFaultReturn:
|
2022-12-15 19:44:43 +00:00
|
|
|
|
|
|
|
/* Disable interrupts for the return */
|
|
|
|
cli
|
|
|
|
|
2011-09-16 17:47:32 +00:00
|
|
|
/* Return */
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
ExitTrap (TF_SAVE_ALL or TF_CHECKUSERAPC)
|
2011-10-14 08:33:22 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiFloatingErrorFault
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiFloatingErrorFault
|
2017-12-31 16:41:01 +00:00
|
|
|
/* Push pseudo error code */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap TF_SAVE_ALL
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
UNIMPLEMENTED KiFloatingErrorFault
|
2011-09-16 17:47:32 +00:00
|
|
|
int 3
|
2010-07-24 01:12:13 +00:00
|
|
|
|
2011-09-16 17:47:32 +00:00
|
|
|
/* Return */
|
|
|
|
ExitTrap TF_SAVE_ALL
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiAlignmentFault
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiAlignmentFault
|
2010-07-24 01:12:13 +00:00
|
|
|
/* We have an error code */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Bugcheck */
|
2011-09-16 17:47:32 +00:00
|
|
|
Fatal EXCEPTION_ALIGNMENT_CHECK
|
2010-07-24 01:12:13 +00:00
|
|
|
jmp $
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiMcheckAbort
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiMcheckAbort
|
2017-12-31 16:41:01 +00:00
|
|
|
/* Push pseudo error code */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap TF_SAVE_ALL
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Bugcheck */
|
2011-09-16 17:47:32 +00:00
|
|
|
Fatal HEX(12)
|
2010-07-24 01:12:13 +00:00
|
|
|
jmp $
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiXmmException
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiXmmException
|
2017-12-31 16:41:01 +00:00
|
|
|
/* Push pseudo error code */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap TF_SAVE_ALL
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Call the C handler */
|
|
|
|
mov rcx, rbp
|
|
|
|
call KiXmmExceptionHandler
|
|
|
|
|
|
|
|
/* Check for success */
|
|
|
|
test eax, eax
|
|
|
|
jge KiXmmExit
|
|
|
|
|
|
|
|
/* Dispatch the exception */
|
2022-07-13 18:26:42 +00:00
|
|
|
DispatchException eax, 2, 0, [rbp+KTRAP_FRAME_MxCsr], 0
|
|
|
|
|
|
|
|
// FIXME: STATUS_FLOAT_MULTIPLE_TRAPS / STATUS_FLOAT_MULTIPLE_FAULTS
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
KiXmmExit:
|
2011-09-16 17:47:32 +00:00
|
|
|
/* Return */
|
|
|
|
ExitTrap TF_SAVE_ALL
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
/* SOFTWARE INTERRUPT SERVICES ***********************************************/
|
|
|
|
|
2010-07-24 01:12:13 +00:00
|
|
|
PUBLIC KiRaiseAssertion
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiRaiseAssertion
|
2010-07-24 01:12:13 +00:00
|
|
|
/* We have an error code */
|
2014-09-18 14:10:41 +00:00
|
|
|
EnterTrap (TF_SAVE_ALL)
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Decrement RIP to point to the INT2C instruction (2 bytes, not 1 like INT3) */
|
|
|
|
sub qword ptr [rbp + KTRAP_FRAME_Rip], 2
|
|
|
|
|
|
|
|
/* Dispatch the exception */
|
2011-09-16 17:47:32 +00:00
|
|
|
DispatchException STATUS_ASSERTION_FAILURE, 0, 0, 0, 0
|
2011-02-10 10:30:43 +00:00
|
|
|
|
2011-09-16 17:47:32 +00:00
|
|
|
/* Return */
|
|
|
|
ExitTrap TF_SAVE_ALL
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiDebugServiceTrap
|
2014-09-18 14:06:31 +00:00
|
|
|
FUNC KiDebugServiceTrap
|
2011-09-16 17:47:32 +00:00
|
|
|
/* No error code */
|
|
|
|
EnterTrap TF_SAVE_ALL
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
/* Increase Rip to skip the int3 */
|
|
|
|
inc qword ptr [rbp + KTRAP_FRAME_Rip]
|
|
|
|
|
2011-09-16 17:47:32 +00:00
|
|
|
/* Dispatch the exception (Params = service, buffer, legth) */
|
|
|
|
DispatchException STATUS_BREAKPOINT, 3, [rbp+KTRAP_FRAME_Rax], [rbp+KTRAP_FRAME_Rcx], [rbp+KTRAP_FRAME_Rdx]
|
2010-07-24 01:12:13 +00:00
|
|
|
|
2011-09-16 17:47:32 +00:00
|
|
|
/* Return */
|
|
|
|
ExitTrap TF_SAVE_ALL
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
2011-09-16 18:39:55 +00:00
|
|
|
|
|
|
|
PUBLIC KiApcInterrupt
|
|
|
|
.PROC KiApcInterrupt
|
|
|
|
/* No error code */
|
2022-12-03 12:59:14 +00:00
|
|
|
EnterTrap (TF_SAVE_ALL or TF_IRQL)
|
2011-09-16 18:39:55 +00:00
|
|
|
|
|
|
|
/* Raise to APC_LEVEL */
|
|
|
|
mov rax, APC_LEVEL
|
|
|
|
mov cr8, rax
|
|
|
|
|
|
|
|
/* End the interrupt */
|
|
|
|
mov dword ptr [APIC_EOI], 0
|
|
|
|
|
|
|
|
/* Enable interrupts */
|
|
|
|
sti
|
|
|
|
|
|
|
|
/* Call the worker routine */
|
|
|
|
mov cl, [rbp + KTRAP_FRAME_SegCs] // ProcessorMode
|
|
|
|
and cl, 1
|
|
|
|
mov rdx, 0 // ExceptionFrame
|
2018-02-12 19:53:15 +00:00
|
|
|
mov r8, rbp // TrapFrame
|
2011-09-16 18:39:55 +00:00
|
|
|
call KiDeliverApc
|
|
|
|
|
|
|
|
/* Disable interrupts */
|
|
|
|
cli
|
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
/* Lower IRQL back to PASSIVE */
|
|
|
|
mov rax, PASSIVE_LEVEL
|
|
|
|
mov cr8, rax
|
|
|
|
|
2011-09-16 18:39:55 +00:00
|
|
|
/* Return */
|
2022-12-03 12:59:14 +00:00
|
|
|
ExitTrap (TF_SAVE_ALL or TF_IRQL)
|
2011-10-14 08:33:22 +00:00
|
|
|
.ENDP
|
2011-09-16 18:39:55 +00:00
|
|
|
|
2018-03-21 09:33:31 +00:00
|
|
|
/*
|
|
|
|
* VOID
|
|
|
|
* KiRetireDpcList(
|
|
|
|
* PKPRCB Prcb);
|
|
|
|
*/
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
EXTERN KiRetireDpcList:PROC
|
2018-03-21 09:33:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* VOID
|
|
|
|
* KiRetireDpcListInDpcStack(
|
|
|
|
* PKPRCB Prcb,
|
|
|
|
* PVOID DpcStack);
|
|
|
|
*/
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
PUBLIC KiRetireDpcListInDpcStack
|
|
|
|
.PROC KiRetireDpcListInDpcStack
|
|
|
|
push rbp
|
|
|
|
.pushreg rbp
|
|
|
|
mov rbp, rsp
|
|
|
|
.setframe rbp, 0
|
|
|
|
.endprolog
|
|
|
|
|
2018-03-21 09:33:31 +00:00
|
|
|
/* Switch to the DpcStack */
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
mov rsp, rdx
|
2018-03-21 09:33:31 +00:00
|
|
|
|
|
|
|
/* The stack is 16 byte aligned, allocate 32 bytes home space */
|
|
|
|
sub rsp, 32
|
|
|
|
|
|
|
|
/* Call KiRetireDpcList on the given stack */
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
call KiRetireDpcList
|
|
|
|
|
|
|
|
/* Restore stack, cleanup and return */
|
|
|
|
mov rsp, rbp
|
|
|
|
pop rbp
|
|
|
|
ret
|
|
|
|
.ENDP
|
2011-09-16 18:39:55 +00:00
|
|
|
|
|
|
|
PUBLIC KiDpcInterrupt
|
|
|
|
.PROC KiDpcInterrupt
|
|
|
|
/* No error code */
|
2022-12-03 12:59:14 +00:00
|
|
|
EnterTrap (TF_SAVE_ALL or TF_IRQL)
|
2011-09-16 18:39:55 +00:00
|
|
|
|
|
|
|
/* Call the worker routine */
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
call KiDpcInterruptHandler
|
2011-09-16 18:39:55 +00:00
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
/* Return, but don't send an EOI! */
|
2022-12-03 12:59:14 +00:00
|
|
|
ExitTrap (TF_SAVE_ALL or TF_IRQL)
|
2011-10-14 08:33:22 +00:00
|
|
|
.ENDP
|
2011-09-16 18:39:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiIpiInterrupt
|
|
|
|
.PROC KiIpiInterrupt
|
|
|
|
/* No error code */
|
2022-12-03 12:59:14 +00:00
|
|
|
EnterTrap (TF_SAVE_ALL or TF_IRQL)
|
2011-09-16 18:39:55 +00:00
|
|
|
|
|
|
|
/* Raise to IPI_LEVEL */
|
|
|
|
mov rax, IPI_LEVEL
|
|
|
|
mov cr8, rax
|
|
|
|
|
|
|
|
/* End the interrupt */
|
|
|
|
mov dword ptr [APIC_EOI], 0
|
|
|
|
|
|
|
|
int 3
|
|
|
|
|
|
|
|
/* Return */
|
2022-12-03 12:59:14 +00:00
|
|
|
ExitTrap (TF_SAVE_ALL or TF_IRQL)
|
2011-10-14 08:33:22 +00:00
|
|
|
.ENDP
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiUnexpectedInterrupt
|
2011-09-16 17:47:32 +00:00
|
|
|
FUNC KiUnexpectedInterrupt
|
2010-07-24 01:12:13 +00:00
|
|
|
/* The error code is the vector */
|
2011-09-16 17:47:32 +00:00
|
|
|
EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
|
2010-07-24 01:12:13 +00:00
|
|
|
|
2011-09-16 09:46:08 +00:00
|
|
|
#if 0
|
2010-07-24 01:12:13 +00:00
|
|
|
/* Set bugcheck parameters */
|
|
|
|
mov ecx, TRAP_CAUSE_UNKNOWN
|
|
|
|
mov rdx, [rbp + KTRAP_FRAME_ErrorCode] // the vector
|
|
|
|
mov r8, 0 // The unknown floating-point exception
|
|
|
|
mov r9, 0 // The enabled and asserted status bits
|
|
|
|
sub rsp, 8
|
|
|
|
mov [rbp + KTRAP_FRAME_P5 + 8], rbp // trap frame
|
|
|
|
call KeBugCheckWithTf
|
|
|
|
jmp $
|
2011-09-16 09:46:08 +00:00
|
|
|
#endif
|
2011-09-16 17:47:32 +00:00
|
|
|
/* Return */
|
|
|
|
ExitTrap TF_SAVE_ALL
|
2014-12-13 11:01:57 +00:00
|
|
|
ENDFUNC
|
2010-07-24 01:12:13 +00:00
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
PUBLIC KiInterruptDispatch
|
|
|
|
FUNC KiInterruptDispatch
|
|
|
|
/* The error code is a pointer to the interrupt object's code */
|
|
|
|
EnterTrap (TF_HAS_ERROR_CODE or TF_SAVE_ALL or TF_IRQL)
|
|
|
|
|
|
|
|
/* Increase interrupt count */
|
|
|
|
inc dword ptr gs:[PcInterruptCount];
|
|
|
|
|
2018-03-09 22:55:54 +00:00
|
|
|
/* Save rbx and rsi in the trap frame */
|
|
|
|
mov [rbp + KTRAP_FRAME_Rbx], rbx
|
|
|
|
mov [rbp + KTRAP_FRAME_Rsi], rsi
|
|
|
|
|
|
|
|
/* Load the address of the dispatch code into rbx */
|
|
|
|
mov rbx, [rbp + KTRAP_FRAME_ErrorCode]
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
|
|
|
|
/* Substract offset of the DispatchCode member plus 6 for the call instruction */
|
2018-03-09 22:55:54 +00:00
|
|
|
sub rbx, KINTERRUPT_DispatchCode + 6
|
|
|
|
|
|
|
|
/* Save the address of the InterruptListEntry in rsi */
|
|
|
|
lea rsi, [rbx + KINTERRUPT_InterruptListEntry]
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
|
2018-03-09 22:55:54 +00:00
|
|
|
.DoDispatchInterrupt:
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
/* Raise IRQL to SynchronizeIrql */
|
2018-03-09 22:55:54 +00:00
|
|
|
movzx rax, byte ptr [rbx + KINTERRUPT_SynchronizeIrql]
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
mov cr8, rax
|
|
|
|
|
2024-12-05 13:37:28 +00:00
|
|
|
/* Enable interrupts */
|
|
|
|
sti
|
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Acquire interrupt lock */
|
2024-12-05 13:37:28 +00:00
|
|
|
mov rcx, [rbx + KINTERRUPT_ActualLock]
|
|
|
|
call KeAcquireSpinLockAtDpcLevel
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Call the ISR */
|
2018-03-09 22:55:54 +00:00
|
|
|
mov rcx, rbx
|
|
|
|
mov rdx, [rbx + KINTERRUPT_ServiceContext]
|
|
|
|
call qword ptr [rbx + KINTERRUPT_ServiceRoutine]
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Release interrupt lock */
|
2024-12-05 13:37:28 +00:00
|
|
|
mov rcx, [rbx + KINTERRUPT_ActualLock]
|
|
|
|
call KeReleaseSpinLockFromDpcLevel
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
#endif
|
|
|
|
|
2024-12-05 13:37:28 +00:00
|
|
|
/* Disable interrupts and go back to old irql */
|
|
|
|
cli
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
movzx rax, byte ptr [rbp + KTRAP_FRAME_PreviousIrql]
|
|
|
|
mov cr8, rax
|
|
|
|
|
2018-03-09 22:55:54 +00:00
|
|
|
/* Check for chained interrupts */
|
|
|
|
mov rax, [rbx + KINTERRUPT_InterruptListEntry]
|
|
|
|
cmp rax, rsi
|
|
|
|
je .Done
|
|
|
|
|
|
|
|
/* Load the next interrupt object into rbx and repeat */
|
|
|
|
lea rbx, [rax - KINTERRUPT_InterruptListEntry]
|
|
|
|
jmp .DoDispatchInterrupt
|
|
|
|
|
|
|
|
.Done:
|
|
|
|
/* Restore rbx and rsi */
|
|
|
|
mov rbx, [rbp + KTRAP_FRAME_Rbx]
|
|
|
|
mov rsi, [rbp + KTRAP_FRAME_Rsi]
|
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
/* Return */
|
|
|
|
ExitTrap (TF_SAVE_ALL or TF_SEND_EOI)
|
|
|
|
ENDFUNC
|
|
|
|
|
|
|
|
EXTERN KiSystemCallHandler:PROC
|
|
|
|
|
|
|
|
/*! \name KiSystemCallEntry64
|
|
|
|
*
|
|
|
|
* \brief This is the entrypoint for syscalls from 64bit user mode
|
|
|
|
*
|
|
|
|
* \param rax - The system call number
|
|
|
|
* \param rcx - User mode return address, set by the syscall instruction
|
|
|
|
* \param rdx,r8,r9 - Parameters 2-4 to the service function
|
|
|
|
* \param r10 - Parameter 1 to the service function
|
|
|
|
* \param r11 - RFLAGS saved by the syscall instruction
|
|
|
|
*--*/
|
|
|
|
PUBLIC KiSystemCallEntry64
|
|
|
|
.PROC KiSystemCallEntry64
|
2018-03-08 11:23:45 +00:00
|
|
|
/* The unwind info pretends we have a machine frame */
|
|
|
|
.PUSHFRAME
|
|
|
|
.ALLOCSTACK (KTRAP_FRAME_LENGTH + MAX_SYSCALL_PARAM_SIZE - MachineFrameLength)
|
2022-12-15 19:55:16 +00:00
|
|
|
.SAVEREG rbp, MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rbp
|
2018-03-08 11:23:45 +00:00
|
|
|
.ENDPROLOG
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
|
|
|
|
/* Swap gs to kernel, so we can access the PCR */
|
|
|
|
swapgs
|
|
|
|
|
|
|
|
/* Save the user mode rsp in the PCR */
|
|
|
|
mov gs:[PcUserRsp], rsp
|
|
|
|
|
|
|
|
/* Get the kernel stack from the PCR */
|
|
|
|
mov rsp, gs:[PcRspBase]
|
|
|
|
|
|
|
|
/* Allocate a TRAP_FRAME and space for parameters */
|
[NTOS:KE:X64] Improve kernel stack switching on GUI system calls
To be 100% correct and not rely on assumptions, stack switching can only be done when all previous code - starting with the syscall entry point - is pure asm code, since we can't rely on the C compiler to not use stack addresses in a way that is not transparent. Therefore the new code uses the same mechanism as for normal system calls, returning the address of the asm function KiConvertToGuiThread, which is then called like an Nt* function would be called normally. KiConvertToGuiThread then allocated a new stack, switches to it (which is now fine, since all the code is asm), frees the old stack, calls PsConvertToGuiThread (which now will not try to allocate another stack, since we already have one) and then jumps into the middle of KiSystemCallEntry64, where the system call is handled again.
Also simplify KiSystemCallEntry64 a bit by copying the first parameters into the trap frame, avoiding to allocate additional stack space for the call to KiSystemCallHandler, which now overlaps with the space that is allocated for the Nt* function.
Finally fix the locations where r10 and r11 are stored, which is TrapFrame->Rcx and TrapFrame->EFlags, based on the situation in user mode.
2018-02-06 19:52:16 +00:00
|
|
|
sub rsp, (KTRAP_FRAME_LENGTH + MAX_SYSCALL_PARAM_SIZE)
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
|
2022-12-15 19:55:16 +00:00
|
|
|
/* Save volatile registers and rbp in the trap frame */
|
[NTOS:KE:X64] Improve kernel stack switching on GUI system calls
To be 100% correct and not rely on assumptions, stack switching can only be done when all previous code - starting with the syscall entry point - is pure asm code, since we can't rely on the C compiler to not use stack addresses in a way that is not transparent. Therefore the new code uses the same mechanism as for normal system calls, returning the address of the asm function KiConvertToGuiThread, which is then called like an Nt* function would be called normally. KiConvertToGuiThread then allocated a new stack, switches to it (which is now fine, since all the code is asm), frees the old stack, calls PsConvertToGuiThread (which now will not try to allocate another stack, since we already have one) and then jumps into the middle of KiSystemCallEntry64, where the system call is handled again.
Also simplify KiSystemCallEntry64 a bit by copying the first parameters into the trap frame, avoiding to allocate additional stack space for the call to KiSystemCallHandler, which now overlaps with the space that is allocated for the Nt* function.
Finally fix the locations where r10 and r11 are stored, which is TrapFrame->Rcx and TrapFrame->EFlags, based on the situation in user mode.
2018-02-06 19:52:16 +00:00
|
|
|
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rax], rax
|
2018-03-08 11:23:45 +00:00
|
|
|
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rip], rcx
|
|
|
|
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rdx], rdx
|
|
|
|
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_R8], r8
|
|
|
|
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_R9], r9
|
[NTOS:KE:X64] Improve kernel stack switching on GUI system calls
To be 100% correct and not rely on assumptions, stack switching can only be done when all previous code - starting with the syscall entry point - is pure asm code, since we can't rely on the C compiler to not use stack addresses in a way that is not transparent. Therefore the new code uses the same mechanism as for normal system calls, returning the address of the asm function KiConvertToGuiThread, which is then called like an Nt* function would be called normally. KiConvertToGuiThread then allocated a new stack, switches to it (which is now fine, since all the code is asm), frees the old stack, calls PsConvertToGuiThread (which now will not try to allocate another stack, since we already have one) and then jumps into the middle of KiSystemCallEntry64, where the system call is handled again.
Also simplify KiSystemCallEntry64 a bit by copying the first parameters into the trap frame, avoiding to allocate additional stack space for the call to KiSystemCallHandler, which now overlaps with the space that is allocated for the Nt* function.
Finally fix the locations where r10 and r11 are stored, which is TrapFrame->Rcx and TrapFrame->EFlags, based on the situation in user mode.
2018-02-06 19:52:16 +00:00
|
|
|
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rcx], r10
|
|
|
|
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_EFlags], r11
|
2022-12-15 19:55:16 +00:00
|
|
|
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rbp], rbp
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
|
2018-03-08 11:23:45 +00:00
|
|
|
/* Store user stack pointer in the trap frame */
|
|
|
|
mov rax, gs:[PcUserRsp]
|
|
|
|
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rsp], rax
|
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
/* Set sane segments */
|
|
|
|
mov ax, (KGDT64_R3_DATA or RPL_MASK)
|
|
|
|
mov ds, ax
|
|
|
|
mov es, ax
|
|
|
|
|
2022-07-23 11:31:48 +00:00
|
|
|
/* Save MCXSR and set kernel value */
|
|
|
|
stmxcsr [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_MxCsr]
|
|
|
|
ldmxcsr gs:[PcMxCsr]
|
|
|
|
|
2024-03-25 13:57:34 +00:00
|
|
|
/* Get the current thread and the trap frame */
|
|
|
|
mov rax, gs:[PcCurrentThread]
|
|
|
|
mov rcx, [rax + ThTrapFrame]
|
|
|
|
|
|
|
|
/* Save the old trap frame */
|
|
|
|
lea rdx, [rsp + MAX_SYSCALL_PARAM_SIZE]
|
|
|
|
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_TrapFrame], rcx
|
|
|
|
mov [rax + ThTrapFrame], rdx
|
|
|
|
|
2020-03-09 06:01:05 +00:00
|
|
|
#if DBG
|
|
|
|
/* Check IRQL */
|
|
|
|
mov rax, cr8
|
|
|
|
test eax, eax
|
|
|
|
jz KiSystemCall64Again
|
|
|
|
int HEX(2C)
|
|
|
|
#endif
|
|
|
|
|
2018-03-08 11:23:45 +00:00
|
|
|
GLOBAL_LABEL KiSystemCall64Again
|
[NTOS:KE:X64] Improve kernel stack switching on GUI system calls
To be 100% correct and not rely on assumptions, stack switching can only be done when all previous code - starting with the syscall entry point - is pure asm code, since we can't rely on the C compiler to not use stack addresses in a way that is not transparent. Therefore the new code uses the same mechanism as for normal system calls, returning the address of the asm function KiConvertToGuiThread, which is then called like an Nt* function would be called normally. KiConvertToGuiThread then allocated a new stack, switches to it (which is now fine, since all the code is asm), frees the old stack, calls PsConvertToGuiThread (which now will not try to allocate another stack, since we already have one) and then jumps into the middle of KiSystemCallEntry64, where the system call is handled again.
Also simplify KiSystemCallEntry64 a bit by copying the first parameters into the trap frame, avoiding to allocate additional stack space for the call to KiSystemCallHandler, which now overlaps with the space that is allocated for the Nt* function.
Finally fix the locations where r10 and r11 are stored, which is TrapFrame->Rcx and TrapFrame->EFlags, based on the situation in user mode.
2018-02-06 19:52:16 +00:00
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
/* Call the C-handler (will enable interrupts) */
|
|
|
|
call KiSystemCallHandler
|
|
|
|
|
[NTOS:KE:X64] Improve kernel stack switching on GUI system calls
To be 100% correct and not rely on assumptions, stack switching can only be done when all previous code - starting with the syscall entry point - is pure asm code, since we can't rely on the C compiler to not use stack addresses in a way that is not transparent. Therefore the new code uses the same mechanism as for normal system calls, returning the address of the asm function KiConvertToGuiThread, which is then called like an Nt* function would be called normally. KiConvertToGuiThread then allocated a new stack, switches to it (which is now fine, since all the code is asm), frees the old stack, calls PsConvertToGuiThread (which now will not try to allocate another stack, since we already have one) and then jumps into the middle of KiSystemCallEntry64, where the system call is handled again.
Also simplify KiSystemCallEntry64 a bit by copying the first parameters into the trap frame, avoiding to allocate additional stack space for the call to KiSystemCallHandler, which now overlaps with the space that is allocated for the Nt* function.
Finally fix the locations where r10 and r11 are stored, which is TrapFrame->Rcx and TrapFrame->EFlags, based on the situation in user mode.
2018-02-06 19:52:16 +00:00
|
|
|
/* The return value from KiSystemCallHandler is the address of the Nt-function */
|
|
|
|
mov rcx, [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rcx]
|
|
|
|
mov rdx, [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rdx]
|
|
|
|
mov r8, [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_R8]
|
|
|
|
mov r9, [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_R9]
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
call rax
|
|
|
|
|
2018-03-08 11:23:45 +00:00
|
|
|
GLOBAL_LABEL KiSystemServiceExit
|
2018-02-05 00:26:11 +00:00
|
|
|
|
2024-03-24 16:58:44 +00:00
|
|
|
ASSERT_TRAP_FRAME_INTS_ENABLED rsp + MAX_SYSCALL_PARAM_SIZE
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
|
2024-03-27 21:17:29 +00:00
|
|
|
/* Check for pending user APCs */
|
|
|
|
mov rcx, gs:[PcCurrentThread]
|
2024-04-02 19:55:54 +00:00
|
|
|
cmp byte ptr [rcx + ThApcState + AsUserApcPending], 0
|
|
|
|
jz NoUserApcPending
|
2019-06-27 16:07:58 +00:00
|
|
|
|
2024-04-02 19:55:54 +00:00
|
|
|
/* Save missing regs in the trap frame */
|
|
|
|
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rax], rax
|
|
|
|
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rbp], rbp
|
|
|
|
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_R9], rbp
|
|
|
|
mov rax, [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rsp]
|
|
|
|
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_R8], rax
|
|
|
|
mov rax, [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rip]
|
|
|
|
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rcx], rax
|
|
|
|
mov rax, [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_EFlags]
|
|
|
|
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_R11], rax
|
|
|
|
xor rax, rax
|
|
|
|
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rdx], rax
|
|
|
|
mov [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_R10], rax
|
|
|
|
pxor xmm0, xmm0
|
|
|
|
movdqa [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Xmm0], xmm0
|
|
|
|
movdqa [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Xmm1], xmm0
|
|
|
|
movdqa [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Xmm2], xmm0
|
|
|
|
movdqa [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Xmm3], xmm0
|
|
|
|
movdqa [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Xmm4], xmm0
|
|
|
|
movdqa [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Xmm5], xmm0
|
|
|
|
|
|
|
|
lea rcx, [rsp + MAX_SYSCALL_PARAM_SIZE]
|
|
|
|
call KiInitiateUserApc
|
|
|
|
|
|
|
|
NoUserApcPending:
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
/* Disable interrupts for return */
|
|
|
|
cli
|
|
|
|
|
2022-07-23 11:31:48 +00:00
|
|
|
/* Restore MCXSR */
|
|
|
|
ldmxcsr [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_MxCsr]
|
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
/* Restore old trap frame */
|
|
|
|
mov rcx, gs:[PcCurrentThread]
|
|
|
|
mov rdx, [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_TrapFrame]
|
|
|
|
mov [rcx + KTHREAD_TrapFrame], rdx
|
|
|
|
|
|
|
|
/* Prepare user mode return address (rcx) and eflags (r11) for sysret */
|
[NTOS:KE:X64] Improve kernel stack switching on GUI system calls
To be 100% correct and not rely on assumptions, stack switching can only be done when all previous code - starting with the syscall entry point - is pure asm code, since we can't rely on the C compiler to not use stack addresses in a way that is not transparent. Therefore the new code uses the same mechanism as for normal system calls, returning the address of the asm function KiConvertToGuiThread, which is then called like an Nt* function would be called normally. KiConvertToGuiThread then allocated a new stack, switches to it (which is now fine, since all the code is asm), frees the old stack, calls PsConvertToGuiThread (which now will not try to allocate another stack, since we already have one) and then jumps into the middle of KiSystemCallEntry64, where the system call is handled again.
Also simplify KiSystemCallEntry64 a bit by copying the first parameters into the trap frame, avoiding to allocate additional stack space for the call to KiSystemCallHandler, which now overlaps with the space that is allocated for the Nt* function.
Finally fix the locations where r10 and r11 are stored, which is TrapFrame->Rcx and TrapFrame->EFlags, based on the situation in user mode.
2018-02-06 19:52:16 +00:00
|
|
|
mov rcx, [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rip]
|
|
|
|
mov r11, [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_EFlags]
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
|
|
|
|
/* Load user mode stack (It was copied to the trap frame) */
|
|
|
|
mov rsp, [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rsp]
|
|
|
|
|
2018-03-08 11:23:45 +00:00
|
|
|
/* r8 points to the user stack */
|
|
|
|
mov r8, rsp
|
|
|
|
|
|
|
|
/* r9 matches rbp */
|
|
|
|
mov r9, rbp
|
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
/* Swap gs back to user */
|
|
|
|
swapgs
|
|
|
|
|
2021-01-06 21:50:22 +00:00
|
|
|
/* Zero out volatiles */
|
2018-05-15 12:07:12 +00:00
|
|
|
pxor xmm0, xmm0
|
|
|
|
pxor xmm1, xmm1
|
|
|
|
pxor xmm2, xmm2
|
|
|
|
pxor xmm3, xmm3
|
|
|
|
pxor xmm4, xmm4
|
|
|
|
pxor xmm5, xmm5
|
|
|
|
xor rdx, rdx
|
|
|
|
xor r10, r10
|
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
/* return to user mode */
|
2021-04-22 15:33:24 +00:00
|
|
|
sysretq
|
[NTOS:KE:X64] Improve kernel stack switching on GUI system calls
To be 100% correct and not rely on assumptions, stack switching can only be done when all previous code - starting with the syscall entry point - is pure asm code, since we can't rely on the C compiler to not use stack addresses in a way that is not transparent. Therefore the new code uses the same mechanism as for normal system calls, returning the address of the asm function KiConvertToGuiThread, which is then called like an Nt* function would be called normally. KiConvertToGuiThread then allocated a new stack, switches to it (which is now fine, since all the code is asm), frees the old stack, calls PsConvertToGuiThread (which now will not try to allocate another stack, since we already have one) and then jumps into the middle of KiSystemCallEntry64, where the system call is handled again.
Also simplify KiSystemCallEntry64 a bit by copying the first parameters into the trap frame, avoiding to allocate additional stack space for the call to KiSystemCallHandler, which now overlaps with the space that is allocated for the Nt* function.
Finally fix the locations where r10 and r11 are stored, which is TrapFrame->Rcx and TrapFrame->EFlags, based on the situation in user mode.
2018-02-06 19:52:16 +00:00
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
.ENDP
|
|
|
|
|
|
|
|
|
2018-02-05 00:26:11 +00:00
|
|
|
/*!
|
|
|
|
* VOID
|
|
|
|
* DECLSPEC_NORETURN
|
2024-03-25 17:04:58 +00:00
|
|
|
* KiExceptionExit(
|
|
|
|
* _In_ PKTRAP_FRAME TrapFrame@<rcx>,
|
|
|
|
* _In_ PKEXCEPTION_FRAME ExceptionFrame@<rdx>);
|
2018-02-05 00:26:11 +00:00
|
|
|
*/
|
2024-03-25 17:04:58 +00:00
|
|
|
PUBLIC KiExceptionExit
|
|
|
|
KiExceptionExit:
|
|
|
|
|
|
|
|
/* Restore registers from exception frame */
|
|
|
|
movaps xmm6, [rdx + ExXmm6]
|
|
|
|
movaps xmm7, [rdx + ExXmm7]
|
|
|
|
movaps xmm8, [rdx + ExXmm8]
|
|
|
|
movaps xmm9, [rdx + ExXmm9]
|
|
|
|
movaps xmm10, [rdx + ExXmm10]
|
|
|
|
movaps xmm11, [rdx + ExXmm11]
|
|
|
|
movaps xmm12, [rdx + ExXmm12]
|
|
|
|
movaps xmm13, [rdx + ExXmm13]
|
|
|
|
movaps xmm14, [rdx + ExXmm14]
|
|
|
|
movaps xmm15, [rdx + ExXmm15]
|
|
|
|
mov rbx, [rdx + ExRbx]
|
|
|
|
mov rdi, [rdx + ExRdi]
|
|
|
|
mov rsi, [rdx + ExRsi]
|
|
|
|
mov r12, [rdx + ExR12]
|
|
|
|
mov r13, [rdx + ExR13]
|
|
|
|
mov r14, [rdx + ExR14]
|
|
|
|
mov r15, [rdx + ExR15]
|
|
|
|
|
|
|
|
/* Point rsp at the trap frame */
|
2022-08-08 07:30:49 +00:00
|
|
|
mov rsp, rcx
|
2024-03-25 17:04:58 +00:00
|
|
|
/* Fall through */
|
2022-08-08 07:30:49 +00:00
|
|
|
|
2024-03-25 17:04:58 +00:00
|
|
|
/*
|
|
|
|
* Internal function. Exits to user-mode with rsp pointing to the trap frame.
|
|
|
|
* All non-volatile register context must be set up already.
|
|
|
|
* Used by KiInitializeContextThread to set up the init path for a new thread.
|
|
|
|
*/
|
2022-08-08 07:30:49 +00:00
|
|
|
PUBLIC KiServiceExit3
|
|
|
|
.PROC KiServiceExit3
|
|
|
|
.PUSHFRAME
|
|
|
|
.ALLOCSTACK (KTRAP_FRAME_LENGTH - MachineFrameLength)
|
|
|
|
.ENDPROLOG
|
|
|
|
|
2018-02-05 00:26:11 +00:00
|
|
|
/* Return */
|
2022-08-08 07:30:49 +00:00
|
|
|
mov rbp, rsp
|
2024-03-25 17:04:58 +00:00
|
|
|
ExitTrap (TF_SEGMENTS or TF_CHECKUSERAPC)
|
2018-02-05 00:26:11 +00:00
|
|
|
.ENDP
|
|
|
|
|
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
PUBLIC KiSystemCallEntry32
|
|
|
|
KiSystemCallEntry32:
|
|
|
|
swapgs
|
|
|
|
int 3
|
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiZwSystemService
|
|
|
|
FUNC KiZwSystemService
|
|
|
|
push rbp
|
|
|
|
.pushreg rbp
|
|
|
|
sub rsp, KTRAP_FRAME_LENGTH
|
|
|
|
.allocstack KTRAP_FRAME_LENGTH
|
|
|
|
mov [rsp + KTRAP_FRAME_Rsi], rsi
|
|
|
|
.savereg rsi, KTRAP_FRAME_Rsi
|
|
|
|
mov [rsp + KTRAP_FRAME_Rdi], rdi
|
|
|
|
.savereg rdi, KTRAP_FRAME_Rdi
|
|
|
|
mov rbp, rsp
|
|
|
|
.setframe rbp, 0
|
|
|
|
.endprolog
|
|
|
|
|
|
|
|
/* Get current thread */
|
|
|
|
mov r11, gs:[PcCurrentThread]
|
|
|
|
|
2018-02-05 00:23:30 +00:00
|
|
|
/* Save PreviousMode in the trap frame */
|
|
|
|
mov dil, byte ptr [r11 + KTHREAD_PreviousMode]
|
|
|
|
mov byte ptr [rbp + KTRAP_FRAME_PreviousMode], dil
|
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
/* Save the old trap frame in TrapFrame.Rdx */
|
|
|
|
mov rdi, [r11 + KTHREAD_TrapFrame]
|
|
|
|
mov [rbp + KTRAP_FRAME_Rdx], rdi
|
|
|
|
|
|
|
|
/* Set the new trap frame and previous mode */
|
|
|
|
mov [r11 + ThTrapFrame], rbp
|
|
|
|
mov byte ptr [r11 + KTHREAD_PreviousMode], 0
|
|
|
|
|
|
|
|
/* allocate space for parameters */
|
|
|
|
sub rsp, r10
|
|
|
|
and rsp, HEX(0fffffffffffffff0)
|
|
|
|
|
|
|
|
/* Save rcx */
|
|
|
|
mov [rbp + KTRAP_FRAME_Rcx], rcx
|
|
|
|
|
|
|
|
/* copy parameters to the new location */
|
|
|
|
lea rsi, [rbp + KTRAP_FRAME_LENGTH + 16]
|
|
|
|
lea rdi, [rsp]
|
|
|
|
mov rcx, r10
|
|
|
|
shr rcx, 3
|
|
|
|
rep movsq
|
|
|
|
|
|
|
|
/* Restore rcx */
|
|
|
|
mov rcx, [rbp + KTRAP_FRAME_Rcx]
|
|
|
|
|
|
|
|
/* Call the service function */
|
|
|
|
call rax
|
|
|
|
|
|
|
|
/* Restore the old trap frame */
|
|
|
|
mov r11, gs:[PcCurrentThread]
|
2018-02-05 00:23:30 +00:00
|
|
|
mov rsi, [rbp + KTRAP_FRAME_Rdx]
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
mov [r11 + KTHREAD_TrapFrame], rsi
|
|
|
|
|
2018-02-05 00:23:30 +00:00
|
|
|
/* Restore PreviousMode from the trap frame */
|
|
|
|
mov dil, byte ptr [rbp + KTRAP_FRAME_PreviousMode]
|
|
|
|
mov byte ptr [r11 + KTHREAD_PreviousMode], dil
|
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
/* Restore rdi and rsi */
|
|
|
|
mov rsi, [rbp + KTRAP_FRAME_Rsi]
|
|
|
|
mov rdi, [rbp + KTRAP_FRAME_Rdi]
|
|
|
|
|
|
|
|
/* Cleanup the stack and return */
|
|
|
|
lea rsp, [rbp + KTRAP_FRAME_LENGTH]
|
|
|
|
pop rbp
|
|
|
|
ret
|
|
|
|
|
|
|
|
ENDFUNC
|
|
|
|
|
2018-02-04 22:44:43 +00:00
|
|
|
PUBLIC KiConvertToGuiThread
|
|
|
|
FUNC KiConvertToGuiThread
|
|
|
|
|
[NTOS:KE:X64] Improve kernel stack switching on GUI system calls
To be 100% correct and not rely on assumptions, stack switching can only be done when all previous code - starting with the syscall entry point - is pure asm code, since we can't rely on the C compiler to not use stack addresses in a way that is not transparent. Therefore the new code uses the same mechanism as for normal system calls, returning the address of the asm function KiConvertToGuiThread, which is then called like an Nt* function would be called normally. KiConvertToGuiThread then allocated a new stack, switches to it (which is now fine, since all the code is asm), frees the old stack, calls PsConvertToGuiThread (which now will not try to allocate another stack, since we already have one) and then jumps into the middle of KiSystemCallEntry64, where the system call is handled again.
Also simplify KiSystemCallEntry64 a bit by copying the first parameters into the trap frame, avoiding to allocate additional stack space for the call to KiSystemCallHandler, which now overlaps with the space that is allocated for the Nt* function.
Finally fix the locations where r10 and r11 are stored, which is TrapFrame->Rcx and TrapFrame->EFlags, based on the situation in user mode.
2018-02-06 19:52:16 +00:00
|
|
|
sub rsp, 40
|
|
|
|
.allocstack 40
|
2018-02-04 22:44:43 +00:00
|
|
|
.endprolog
|
|
|
|
|
2023-05-10 17:28:20 +00:00
|
|
|
/* Check if we already have a large stack */
|
|
|
|
mov rax, gs:[PcCurrentThread]
|
|
|
|
cmp byte ptr [rax + KTHREAD_LargeStack], 0
|
|
|
|
jnz AlreadyLargeStack
|
|
|
|
|
[NTOS:KE:X64] Improve kernel stack switching on GUI system calls
To be 100% correct and not rely on assumptions, stack switching can only be done when all previous code - starting with the syscall entry point - is pure asm code, since we can't rely on the C compiler to not use stack addresses in a way that is not transparent. Therefore the new code uses the same mechanism as for normal system calls, returning the address of the asm function KiConvertToGuiThread, which is then called like an Nt* function would be called normally. KiConvertToGuiThread then allocated a new stack, switches to it (which is now fine, since all the code is asm), frees the old stack, calls PsConvertToGuiThread (which now will not try to allocate another stack, since we already have one) and then jumps into the middle of KiSystemCallEntry64, where the system call is handled again.
Also simplify KiSystemCallEntry64 a bit by copying the first parameters into the trap frame, avoiding to allocate additional stack space for the call to KiSystemCallHandler, which now overlaps with the space that is allocated for the Nt* function.
Finally fix the locations where r10 and r11 are stored, which is TrapFrame->Rcx and TrapFrame->EFlags, based on the situation in user mode.
2018-02-06 19:52:16 +00:00
|
|
|
// NewStack = (ULONG_PTR)MmCreateKernelStack(TRUE, 0);
|
|
|
|
mov cl, 1
|
|
|
|
xor rdx, rdx
|
|
|
|
call MmCreateKernelStack
|
|
|
|
|
|
|
|
/* Check for failure */
|
|
|
|
test rax, rax
|
|
|
|
jz KiConvertToGuiThreadFailed
|
|
|
|
|
2023-05-10 17:28:20 +00:00
|
|
|
/* OldStack = KeSwitchKernelStack((PVOID)NewStack, (PVOID)(NewStack - KERNEL_LARGE_STACK_COMMIT )); */
|
[NTOS:KE:X64] Improve kernel stack switching on GUI system calls
To be 100% correct and not rely on assumptions, stack switching can only be done when all previous code - starting with the syscall entry point - is pure asm code, since we can't rely on the C compiler to not use stack addresses in a way that is not transparent. Therefore the new code uses the same mechanism as for normal system calls, returning the address of the asm function KiConvertToGuiThread, which is then called like an Nt* function would be called normally. KiConvertToGuiThread then allocated a new stack, switches to it (which is now fine, since all the code is asm), frees the old stack, calls PsConvertToGuiThread (which now will not try to allocate another stack, since we already have one) and then jumps into the middle of KiSystemCallEntry64, where the system call is handled again.
Also simplify KiSystemCallEntry64 a bit by copying the first parameters into the trap frame, avoiding to allocate additional stack space for the call to KiSystemCallHandler, which now overlaps with the space that is allocated for the Nt* function.
Finally fix the locations where r10 and r11 are stored, which is TrapFrame->Rcx and TrapFrame->EFlags, based on the situation in user mode.
2018-02-06 19:52:16 +00:00
|
|
|
mov rcx, rax
|
|
|
|
mov rdx, rax
|
2023-05-10 17:28:20 +00:00
|
|
|
sub rdx, KERNEL_LARGE_STACK_COMMIT
|
[NTOS:KE:X64] Improve kernel stack switching on GUI system calls
To be 100% correct and not rely on assumptions, stack switching can only be done when all previous code - starting with the syscall entry point - is pure asm code, since we can't rely on the C compiler to not use stack addresses in a way that is not transparent. Therefore the new code uses the same mechanism as for normal system calls, returning the address of the asm function KiConvertToGuiThread, which is then called like an Nt* function would be called normally. KiConvertToGuiThread then allocated a new stack, switches to it (which is now fine, since all the code is asm), frees the old stack, calls PsConvertToGuiThread (which now will not try to allocate another stack, since we already have one) and then jumps into the middle of KiSystemCallEntry64, where the system call is handled again.
Also simplify KiSystemCallEntry64 a bit by copying the first parameters into the trap frame, avoiding to allocate additional stack space for the call to KiSystemCallHandler, which now overlaps with the space that is allocated for the Nt* function.
Finally fix the locations where r10 and r11 are stored, which is TrapFrame->Rcx and TrapFrame->EFlags, based on the situation in user mode.
2018-02-06 19:52:16 +00:00
|
|
|
call KeSwitchKernelStack
|
|
|
|
|
|
|
|
// MmDeleteKernelStack(OldStack, FALSE);
|
|
|
|
mov rcx, rax
|
|
|
|
xor rdx, rdx
|
|
|
|
call MmDeleteKernelStack
|
|
|
|
|
2023-05-10 17:28:20 +00:00
|
|
|
AlreadyLargeStack:
|
|
|
|
|
2018-02-04 22:44:43 +00:00
|
|
|
/* Call the worker function */
|
|
|
|
call PsConvertToGuiThread
|
|
|
|
|
[NTOS:KE:X64] Improve kernel stack switching on GUI system calls
To be 100% correct and not rely on assumptions, stack switching can only be done when all previous code - starting with the syscall entry point - is pure asm code, since we can't rely on the C compiler to not use stack addresses in a way that is not transparent. Therefore the new code uses the same mechanism as for normal system calls, returning the address of the asm function KiConvertToGuiThread, which is then called like an Nt* function would be called normally. KiConvertToGuiThread then allocated a new stack, switches to it (which is now fine, since all the code is asm), frees the old stack, calls PsConvertToGuiThread (which now will not try to allocate another stack, since we already have one) and then jumps into the middle of KiSystemCallEntry64, where the system call is handled again.
Also simplify KiSystemCallEntry64 a bit by copying the first parameters into the trap frame, avoiding to allocate additional stack space for the call to KiSystemCallHandler, which now overlaps with the space that is allocated for the Nt* function.
Finally fix the locations where r10 and r11 are stored, which is TrapFrame->Rcx and TrapFrame->EFlags, based on the situation in user mode.
2018-02-06 19:52:16 +00:00
|
|
|
/* Check for failure */
|
2023-05-10 17:28:20 +00:00
|
|
|
test eax, eax
|
[NTOS:KE:X64] Improve kernel stack switching on GUI system calls
To be 100% correct and not rely on assumptions, stack switching can only be done when all previous code - starting with the syscall entry point - is pure asm code, since we can't rely on the C compiler to not use stack addresses in a way that is not transparent. Therefore the new code uses the same mechanism as for normal system calls, returning the address of the asm function KiConvertToGuiThread, which is then called like an Nt* function would be called normally. KiConvertToGuiThread then allocated a new stack, switches to it (which is now fine, since all the code is asm), frees the old stack, calls PsConvertToGuiThread (which now will not try to allocate another stack, since we already have one) and then jumps into the middle of KiSystemCallEntry64, where the system call is handled again.
Also simplify KiSystemCallEntry64 a bit by copying the first parameters into the trap frame, avoiding to allocate additional stack space for the call to KiSystemCallHandler, which now overlaps with the space that is allocated for the Nt* function.
Finally fix the locations where r10 and r11 are stored, which is TrapFrame->Rcx and TrapFrame->EFlags, based on the situation in user mode.
2018-02-06 19:52:16 +00:00
|
|
|
js KiConvertToGuiThreadFailed
|
2018-02-04 22:44:43 +00:00
|
|
|
|
[NTOS:KE:X64] Improve kernel stack switching on GUI system calls
To be 100% correct and not rely on assumptions, stack switching can only be done when all previous code - starting with the syscall entry point - is pure asm code, since we can't rely on the C compiler to not use stack addresses in a way that is not transparent. Therefore the new code uses the same mechanism as for normal system calls, returning the address of the asm function KiConvertToGuiThread, which is then called like an Nt* function would be called normally. KiConvertToGuiThread then allocated a new stack, switches to it (which is now fine, since all the code is asm), frees the old stack, calls PsConvertToGuiThread (which now will not try to allocate another stack, since we already have one) and then jumps into the middle of KiSystemCallEntry64, where the system call is handled again.
Also simplify KiSystemCallEntry64 a bit by copying the first parameters into the trap frame, avoiding to allocate additional stack space for the call to KiSystemCallHandler, which now overlaps with the space that is allocated for the Nt* function.
Finally fix the locations where r10 and r11 are stored, which is TrapFrame->Rcx and TrapFrame->EFlags, based on the situation in user mode.
2018-02-06 19:52:16 +00:00
|
|
|
/* Disable interrupts for return */
|
|
|
|
cli
|
|
|
|
|
|
|
|
// Restore register parameters
|
|
|
|
mov rcx, [rsp + 48 + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rip]
|
|
|
|
mov rdx, [rsp + 48 + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rdx]
|
|
|
|
mov r8, [rsp + 48 + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_R8]
|
|
|
|
mov r9, [rsp + 48 + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_R9]
|
2018-02-04 22:44:43 +00:00
|
|
|
|
[NTOS:KE:X64] Improve kernel stack switching on GUI system calls
To be 100% correct and not rely on assumptions, stack switching can only be done when all previous code - starting with the syscall entry point - is pure asm code, since we can't rely on the C compiler to not use stack addresses in a way that is not transparent. Therefore the new code uses the same mechanism as for normal system calls, returning the address of the asm function KiConvertToGuiThread, which is then called like an Nt* function would be called normally. KiConvertToGuiThread then allocated a new stack, switches to it (which is now fine, since all the code is asm), frees the old stack, calls PsConvertToGuiThread (which now will not try to allocate another stack, since we already have one) and then jumps into the middle of KiSystemCallEntry64, where the system call is handled again.
Also simplify KiSystemCallEntry64 a bit by copying the first parameters into the trap frame, avoiding to allocate additional stack space for the call to KiSystemCallHandler, which now overlaps with the space that is allocated for the Nt* function.
Finally fix the locations where r10 and r11 are stored, which is TrapFrame->Rcx and TrapFrame->EFlags, based on the situation in user mode.
2018-02-06 19:52:16 +00:00
|
|
|
/* Run KiSystemCallHandler again */
|
|
|
|
add rsp, 48
|
|
|
|
jmp KiSystemCall64Again
|
|
|
|
|
|
|
|
KiConvertToGuiThreadFailed:
|
|
|
|
|
|
|
|
/* Clean up the stack and return failure */
|
|
|
|
add rsp, 40
|
|
|
|
mov eax, HEX(C0000017) // STATUS_NO_MEMORY
|
2018-02-04 22:44:43 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
ENDFUNC
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
|
2018-05-15 12:06:27 +00:00
|
|
|
|
|
|
|
EXTERN KiSetTrapContextInternal:PROC
|
|
|
|
|
|
|
|
/*
|
|
|
|
* VOID
|
|
|
|
* KiSetTrapContext(
|
|
|
|
* _Out_ PKTRAP_FRAME TrapFrame,
|
|
|
|
* _In_ PCONTEXT Context,
|
|
|
|
* _In_ KPROCESSOR_MODE RequestorMode);
|
|
|
|
*/
|
|
|
|
PUBLIC KiSetTrapContext
|
|
|
|
.PROC KiSetTrapContext
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2018-05-15 12:06:27 +00:00
|
|
|
/* Generate a KEXCEPTION_FRAME on the stack */
|
|
|
|
GENERATE_EXCEPTION_FRAME
|
|
|
|
|
|
|
|
call KiSetTrapContextInternal
|
|
|
|
|
|
|
|
/* Restore the registers from the KEXCEPTION_FRAME */
|
|
|
|
RESTORE_EXCEPTION_STATE
|
|
|
|
|
|
|
|
/* Return */
|
|
|
|
ret
|
|
|
|
|
|
|
|
.ENDP
|
|
|
|
|
|
|
|
|
2021-01-06 21:50:22 +00:00
|
|
|
/*
|
|
|
|
* VOID
|
|
|
|
* KiDeliverApc(
|
|
|
|
* _In_ KPROCESSOR_MODE DeliveryMode,
|
|
|
|
* _In_ PKEXCEPTION_FRAME ExceptionFrame,
|
|
|
|
* _In_ PKTRAP_FRAME TrapFrame);
|
|
|
|
*
|
|
|
|
*/
|
2018-02-12 19:53:15 +00:00
|
|
|
EXTERN KiDeliverApc:PROC
|
|
|
|
|
2024-03-27 21:17:29 +00:00
|
|
|
/*
|
|
|
|
* VOID
|
|
|
|
* KiInitiateUserApc(
|
|
|
|
* _In_ PKTRAP_FRAME TrapFrame@<rcx>);
|
|
|
|
*
|
|
|
|
* This function is called to deliver user mode APCs.
|
|
|
|
* It clobbers all non-volatile registers, except rax.
|
|
|
|
*/
|
2018-02-12 19:53:15 +00:00
|
|
|
PUBLIC KiInitiateUserApc
|
|
|
|
.PROC KiInitiateUserApc
|
|
|
|
|
2021-01-06 21:50:22 +00:00
|
|
|
/* Generate a KEXCEPTION_FRAME on the stack */
|
2018-02-12 19:53:15 +00:00
|
|
|
GENERATE_EXCEPTION_FRAME
|
|
|
|
|
2021-01-06 21:50:22 +00:00
|
|
|
/* Raise IRQL to APC_LEVEL */
|
2018-02-12 19:53:15 +00:00
|
|
|
mov rax, APC_LEVEL
|
|
|
|
mov cr8, rax
|
|
|
|
|
2024-03-25 20:23:19 +00:00
|
|
|
/* Get the current thread */
|
|
|
|
mov rbp, gs:[PcCurrentThread]
|
|
|
|
|
2024-03-27 21:17:29 +00:00
|
|
|
/* Save the trap frame in rsi */
|
|
|
|
mov rsi, rcx
|
|
|
|
|
2021-01-06 21:50:22 +00:00
|
|
|
/* Enable interrupts */
|
2018-02-12 19:53:15 +00:00
|
|
|
sti
|
|
|
|
|
2021-01-06 21:50:22 +00:00
|
|
|
/* Call the C function */
|
2018-02-12 19:53:15 +00:00
|
|
|
mov ecx, 1
|
|
|
|
mov rdx, rsp
|
2024-03-27 21:17:29 +00:00
|
|
|
mov r8, rsi
|
2018-02-12 19:53:15 +00:00
|
|
|
call KiDeliverApc
|
|
|
|
|
2021-01-06 21:50:22 +00:00
|
|
|
/* Disable interrupts again */
|
2018-02-12 19:53:15 +00:00
|
|
|
cli
|
|
|
|
|
2020-03-09 06:01:05 +00:00
|
|
|
/* Go back to PASSIVE_LEVEL */
|
|
|
|
mov rax, PASSIVE_LEVEL
|
|
|
|
mov cr8, rax
|
|
|
|
|
2021-01-06 21:50:22 +00:00
|
|
|
/* Restore the registers from the KEXCEPTION_FRAME */
|
2018-02-12 19:53:15 +00:00
|
|
|
RESTORE_EXCEPTION_STATE
|
|
|
|
|
2021-01-06 21:50:22 +00:00
|
|
|
/* Return */
|
2018-02-12 19:53:15 +00:00
|
|
|
ret
|
|
|
|
|
|
|
|
.ENDP
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
PUBLIC KiInitializeSegments
|
|
|
|
KiInitializeSegments:
|
|
|
|
mov ax, KGDT64_R3_DATA or RPL_MASK
|
|
|
|
mov gs, ax
|
|
|
|
swapgs
|
|
|
|
mov gs, ax
|
|
|
|
ret
|
|
|
|
|
2018-02-04 22:44:43 +00:00
|
|
|
/*!
|
|
|
|
* VOID
|
|
|
|
* KiSwitchKernelStackHelper(
|
|
|
|
* LONG_PTR StackOffset,
|
|
|
|
* PVOID OldStackBase);
|
|
|
|
*/
|
|
|
|
PUBLIC KiSwitchKernelStackHelper
|
|
|
|
KiSwitchKernelStackHelper:
|
2021-04-22 15:33:24 +00:00
|
|
|
|
2018-02-04 22:44:43 +00:00
|
|
|
/* Pop return address from the current stack */
|
|
|
|
pop rax
|
|
|
|
|
|
|
|
/* Switch to new stack */
|
|
|
|
lea rsp, [rsp + rcx]
|
|
|
|
|
|
|
|
/* Push return address on the new stack */
|
|
|
|
push rax
|
|
|
|
|
|
|
|
/* Return on new stack */
|
|
|
|
mov rax, rdx
|
[NTOS:KE:X64] Improve kernel stack switching on GUI system calls
To be 100% correct and not rely on assumptions, stack switching can only be done when all previous code - starting with the syscall entry point - is pure asm code, since we can't rely on the C compiler to not use stack addresses in a way that is not transparent. Therefore the new code uses the same mechanism as for normal system calls, returning the address of the asm function KiConvertToGuiThread, which is then called like an Nt* function would be called normally. KiConvertToGuiThread then allocated a new stack, switches to it (which is now fine, since all the code is asm), frees the old stack, calls PsConvertToGuiThread (which now will not try to allocate another stack, since we already have one) and then jumps into the middle of KiSystemCallEntry64, where the system call is handled again.
Also simplify KiSystemCallEntry64 a bit by copying the first parameters into the trap frame, avoiding to allocate additional stack space for the call to KiSystemCallHandler, which now overlaps with the space that is allocated for the Nt* function.
Finally fix the locations where r10 and r11 are stored, which is TrapFrame->Rcx and TrapFrame->EFlags, based on the situation in user mode.
2018-02-06 19:52:16 +00:00
|
|
|
ret
|
2018-02-04 22:44:43 +00:00
|
|
|
|
2018-02-09 19:59:33 +00:00
|
|
|
EXTERN KiSwitchKernelStack:PROC
|
|
|
|
|
|
|
|
PUBLIC KeSwitchKernelStack
|
|
|
|
FUNC KeSwitchKernelStack
|
|
|
|
|
2023-08-15 19:51:05 +00:00
|
|
|
/* Save rcx and allocate callee home space */
|
|
|
|
mov [rsp + P1Home], rcx
|
|
|
|
.savereg rcx, P1Home
|
2018-02-09 19:59:33 +00:00
|
|
|
sub rsp, 40
|
|
|
|
.allocstack 40
|
|
|
|
.endprolog
|
|
|
|
|
2021-01-06 21:50:22 +00:00
|
|
|
/* Call the C handler, which returns the old stack in rax */
|
|
|
|
call KiSwitchKernelStack
|
2018-02-09 19:59:33 +00:00
|
|
|
|
2021-01-06 21:50:22 +00:00
|
|
|
/* Restore rcx (StackBase) */
|
2023-08-15 19:51:05 +00:00
|
|
|
mov rcx, [rsp + 40 + P1Home]
|
2018-02-09 19:59:33 +00:00
|
|
|
|
2021-01-06 21:50:22 +00:00
|
|
|
/* Switch to new stack: RSP += (StackBase - OldStackBase) */
|
2018-02-09 19:59:33 +00:00
|
|
|
sub rcx, rax
|
|
|
|
add rsp, rcx
|
|
|
|
|
2021-01-06 21:50:22 +00:00
|
|
|
/* Deallocate the home frame */
|
2018-02-09 19:59:33 +00:00
|
|
|
add rsp, 40
|
|
|
|
ret
|
|
|
|
|
|
|
|
ENDFUNC
|
|
|
|
|
|
|
|
|
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
|
2010-07-24 01:12:13 +00:00
|
|
|
#ifdef _MSC_VER
|
2011-06-06 19:08:39 +00:00
|
|
|
#undef lgdt
|
|
|
|
#undef lidt
|
2010-07-24 01:12:13 +00:00
|
|
|
|
|
|
|
//void __lgdt(void *Source);
|
|
|
|
PUBLIC __lgdt
|
|
|
|
__lgdt:
|
|
|
|
lgdt fword ptr [rcx]
|
|
|
|
ret
|
|
|
|
|
|
|
|
//void __sgdt(void *Destination);
|
|
|
|
PUBLIC __sgdt
|
|
|
|
__sgdt:
|
|
|
|
sgdt fword ptr [rcx]
|
|
|
|
ret
|
|
|
|
|
|
|
|
// void __lldt(unsigned short Value)
|
|
|
|
PUBLIC __lldt
|
|
|
|
__lldt:
|
|
|
|
lldt cx
|
|
|
|
ret
|
|
|
|
|
|
|
|
//void __sldt(void *Destination);
|
|
|
|
PUBLIC __sldt
|
|
|
|
__sldt:
|
|
|
|
sldt word ptr [rcx]
|
|
|
|
ret
|
|
|
|
|
|
|
|
//void __ltr(unsigned short Source);
|
|
|
|
PUBLIC __ltr
|
|
|
|
__ltr:
|
|
|
|
ltr cx
|
|
|
|
ret
|
|
|
|
|
|
|
|
//void __str(unsigned short *Destination);
|
|
|
|
PUBLIC __str
|
|
|
|
__str:
|
|
|
|
str word ptr [rcx]
|
|
|
|
ret
|
|
|
|
|
[NTOSKRNL/KE/AMD64]
- Fix stack alignment in KiSwitchToBootStack
- Handle ExceptionFrame == NULL in KeContextToTrapFrame and KeTrapFrameToContext
- Implement KiSwapContextInternal
- Fix KiSwapContext and KiThreadStartup
- Implement dispatching of user mode exceptions including in-paging of module data used by the kernel-debugger
- Implement KeInitializeInterrupt, KeConnectInterrupt, KeSynchronizeExecution
- Don't zero more than the actual PCR size in KiInitializePcr
- Add asm function KiInitializeSegments to initialize the segment selectors to proper values
- Initialize system call entrypoints in KiInitializeCpu
- Implement KiDpcInterruptHandler, KiIdleLoop, KiInitializeUserApc, KiSwapProcess, KiSystemCallHandler, KiInitializeContextThread, KiSwapContextResume
- Implement asm functions KiRetireDpcList, KiInterruptDispatch, KiSystemCallEntry64, KiZwSystemService
svn path=/trunk/; revision=55405
2012-02-04 11:32:13 +00:00
|
|
|
PUBLIC __swapgs
|
|
|
|
__swapgs:
|
|
|
|
swapgs
|
|
|
|
ret
|
|
|
|
|
2010-07-24 01:12:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
END
|