* Use macro for APC-delivery.

* Mark function start/endings for the compiler.

svn path=/trunk/; revision=20929
This commit is contained in:
Alex Ionescu
2006-01-17 01:22:21 +00:00
parent f697d968ef
commit 3ad6f05446
3 changed files with 106 additions and 163 deletions
@@ -63,6 +63,73 @@
mov [ebp+KTRAP_FRAME_DEBUGEBP], ebx; \
mov [ebp+KTRAP_FRAME_DEBUGEIP], edi;
//
// These macros help with USer-Mode APC delivery after exiting a trap.
//
// CHECK_FOR_APC_DELIVER
// This macro checks if the trapframe indicates a return to user-mode,
// and, if so, checks if user-mode APCs should be delivered.
//
.macro CHECK_FOR_APC_DELIVER PreserveEax
/* Check for V86 mode */
test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK
jnz 1f
/* Deliver APCs only if we were called from user mode */
test byte ptr [ebp+KTRAP_FRAME_CS], 1
je 2f
/* Get the current thread */
1:
mov ebx, [fs:KPCR_CURRENT_THREAD]
/* Make it non-alerted */
mov byte ptr [ebx+KTHREAD_ALERTED], 0
/* And only if any are actually pending */
cmp byte ptr [ebx+KTHREAD_PENDING_USER_APC], 0
je 2f
/* Save pointer to Trap Frame */
mov ebx, ebp
.if \PreserveEax
/* Save some stuff that raising IRQL will kill */
mov [ebx+KTRAP_FRAME_EAX], eax
mov dword ptr [ebx+KTRAP_FRAME_FS], KGDT_R3_TEB + RPL_MASK
mov dword ptr [ebx+KTRAP_FRAME_DS], KGDT_R3_DATA + RPL_MASK
mov dword ptr [ebx+KTRAP_FRAME_ES], KGDT_R3_DATA + RPL_MASK
mov dword ptr [ebx+KTRAP_FRAME_GS], 0
.endif
/* Raise IRQL to APC_LEVEL */
mov ecx, 1
call @KfRaiseIrql@4
/* Save old IRQL */
push eax
/* Deliver APCs */
sti
push ebx
push 0
push UserMode
call _KiDeliverApc@12
/* Return to old IRQL */
pop ecx
call @KfLowerIrql@4
/* Restore EAX (only in volatile case) */
.if \PreserveEax
mov eax, [ebx+KTRAP_FRAME_EAX]
.endif
cli
jmp 1b
2:
.endm
//
// These macros control common execution paths for Traps and System Call Code
//
+19 -143
View File
@@ -107,6 +107,7 @@ BadStack:
push 0
jmp _KiTrap6
.func KiFastCallEntry
_KiFastCallEntry:
// ==================== UNIQUE SYSENTER STUB. DO NOT DUPLICATE ============//
@@ -186,7 +187,9 @@ _KiFastCallEntry:
/* Jump to shared code or DR Save */
//jnz Dr_FastCallDrSave
jmp SharedCode
.endfunc
.func KiSystemService
_KiSystemService:
// ==================== UNIQUE SYSCALL TRAP ENTRY DO NOT DUPLICATE ============//
@@ -421,68 +424,16 @@ KeReturnFromSystemCall:
/* Restore the old trap frame pointer */
mov edx, [ebp+KTRAP_FRAME_EDX]
mov [ecx+KTHREAD_TRAP_FRAME], edx
.endfunc
.func KiServiceExit
_KiServiceExit:
/* Disable interrupts */
cli
// ================= COMMON USER-MODE APC DELIVERY CHECK ============//
/* Check for V86 mode */
test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK
jnz ApcLoop
/* Check for, and deliver, User-Mode APCs if needed */
CHECK_FOR_APC_DELIVER 1
/* Deliver APCs only if we were called from user mode */
test byte ptr [ebp+KTRAP_FRAME_CS], 1
je KiRosTrapReturn
/* Get the current thread */
ApcLoop:
mov ebx, [fs:KPCR_CURRENT_THREAD]
/* Make it non-alerted */
mov byte ptr [ebx+KTHREAD_ALERTED], 0
/* And only if any are actually pending */
cmp byte ptr [ebx+KTHREAD_PENDING_USER_APC], 0
je KiRosTrapReturn
/* Save pointer to Trap Frame */
mov ebx, ebp
// ================= PRESENT ONLY IF VOLATILES NEEDED ============//
/* Save some stuff that raising IRQL will kill */
mov [ebx+KTRAP_FRAME_EAX], eax
mov dword ptr [ebx+KTRAP_FRAME_FS], KGDT_R3_TEB + RPL_MASK
mov dword ptr [ebx+KTRAP_FRAME_DS], KGDT_R3_DATA + RPL_MASK
mov dword ptr [ebx+KTRAP_FRAME_ES], KGDT_R3_DATA + RPL_MASK
mov dword ptr [ebx+KTRAP_FRAME_GS], 0
// ============= END PRESENT ONLY IF VOLATILES NEEDED ============//
/* Raise IRQL to APC_LEVEL */
mov ecx, 1
call @KfRaiseIrql@4
/* Save old IRQL */
push eax
/* Deliver APCs */
sti
push ebx
push 0
push UserMode
call _KiDeliverApc@12
/* Return to old IRQL */
pop ecx
call @KfLowerIrql@4
/* Restore EAX (only in volatile case) */
mov eax, [ebx+KTRAP_FRAME_EAX]
cli
jmp ApcLoop
// ============== END COMMON USER-MODE APC DELIVERY CHECK ============//
KiRosTrapReturn:
// ========================= COMMON TRAP EXIT CODE ===================//
#ifdef DBG
/* Assert the flags */
@@ -778,55 +729,17 @@ InvalidCall:
/* Invalid System Call */
mov eax, STATUS_INVALID_SYSTEM_SERVICE
jmp KeReturnFromSystemCall
.endfunc
.func KiServiceExit2
_KiServiceExit2:
/* Disable interrupts */
cli
/* Check for V86 mode */
test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK
jnz ApcLoop2
/* Check for, and deliver, User-Mode APCs if needed */
CHECK_FOR_APC_DELIVER 0
/* Deliver APCs only if we were called from user mode */
test byte ptr [ebp+KTRAP_FRAME_CS], 1
je KiRosTrapReturn2
/* Get the current thread */
ApcLoop2:
mov ebx, [fs:KPCR_CURRENT_THREAD]
/* Make it non-alerted */
mov byte ptr [ebx+KTHREAD_ALERTED], 0
/* And only if any are actually pending */
cmp byte ptr [ebx+KTHREAD_PENDING_USER_APC], 0
je KiRosTrapReturn2
/* Save pointer to Trap Frame */
mov ebx, ebp
/* Raise IRQL to APC_LEVEL */
mov ecx, 1
call @KfRaiseIrql@4
/* Save old IRQL */
push eax
/* Deliver APCs */
sti
push ebx
push 0
push UserMode
call _KiDeliverApc@12
/* Return to old IRQL */
pop ecx
call @KfLowerIrql@4
cli
jmp ApcLoop2
KiRosTrapReturn2:
#ifdef DBG
/* Assert the flags */
pushfd
@@ -1028,57 +941,19 @@ NotUserMode:
//jz VdmProc
/* Exit through common routine */
jmp Kei386EoiHelper@0
jmp _Kei386EoiHelper@0
.endfunc
.globl Kei386EoiHelper@0
Kei386EoiHelper@0:
.globl _Kei386EoiHelper@0
.func Kei386EoiHelper@0
_Kei386EoiHelper@0:
/* Disable interrupts */
cli
/* Check for V86 mode */
test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK
jnz ApcLoop3
/* Check for, and deliver, User-Mode APCs if needed */
CHECK_FOR_APC_DELIVER 0
/* Deliver APCs only if we were called from user mode */
test byte ptr [ebp+KTRAP_FRAME_CS], 1
je KiRosTrapReturn3
/* Get the current thread */
ApcLoop3:
mov ebx, [fs:KPCR_CURRENT_THREAD]
/* Make it non-alerted */
mov byte ptr [ebx+KTHREAD_ALERTED], 0
/* And only if any are actually pending */
cmp byte ptr [ebx+KTHREAD_PENDING_USER_APC], 0
je KiRosTrapReturn3
/* Save pointer to Trap Frame */
mov ebx, ebp
/* Raise IRQL to APC_LEVEL */
mov ecx, 1
call @KfRaiseIrql@4
/* Save old IRQL */
push eax
/* Deliver APCs */
sti
push ebx
push 0
push UserMode
call _KiDeliverApc@12
/* Return to old IRQL */
pop ecx
call @KfLowerIrql@4
cli
jmp ApcLoop3
KiRosTrapReturn3:
#ifdef DBG
/* Assert the flags */
pushfd
@@ -1210,6 +1085,7 @@ EditedFrame3:
pop ebp
mov esp, [esp]
iret
.endfunc
.globl _NtRaiseException@12
_NtRaiseException@12:
+20 -20
View File
@@ -43,7 +43,7 @@ _KiTrap0:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap1
@@ -64,7 +64,7 @@ _KiTrap1:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap2
@@ -85,7 +85,7 @@ _KiTrap2:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap3
@@ -106,7 +106,7 @@ _KiTrap3:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap4
@@ -127,7 +127,7 @@ _KiTrap4:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap5
@@ -148,7 +148,7 @@ _KiTrap5:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap6
@@ -169,7 +169,7 @@ _KiTrap6:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap7
@@ -190,7 +190,7 @@ _KiTrap7:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap8
@@ -216,7 +216,7 @@ _KiTrap9:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap10
@@ -234,7 +234,7 @@ _KiTrap10:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap11
@@ -252,7 +252,7 @@ _KiTrap11:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap12
@@ -270,7 +270,7 @@ _KiTrap12:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap13
@@ -288,7 +288,7 @@ _KiTrap13:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap14
@@ -306,7 +306,7 @@ _KiTrap14:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap15
@@ -327,7 +327,7 @@ _KiTrap15:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap16
@@ -348,7 +348,7 @@ _KiTrap16:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap17
@@ -369,7 +369,7 @@ _KiTrap17:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap18
@@ -390,7 +390,7 @@ _KiTrap18:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap19
@@ -411,7 +411,7 @@ _KiTrap19:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrapUnknown
@@ -426,7 +426,7 @@ _KiTrapUnknown:
cmp eax, 1
/* Return to caller */
jne Kei386EoiHelper@0
jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiCoprocessorError@0