* Use macro for APC-delivery.
* Mark function start/endings for the compiler.
Modified: trunk/reactos/ntoskrnl/include/internal/i386/asmmacro.S
Modified: trunk/reactos/ntoskrnl/ke/i386/syscall.S
Modified: trunk/reactos/ntoskrnl/ke/i386/trap.s
_____
Modified: trunk/reactos/ntoskrnl/include/internal/i386/asmmacro.S
--- trunk/reactos/ntoskrnl/include/internal/i386/asmmacro.S
2006-01-17 00:13:11 UTC (rev 20928)
+++ trunk/reactos/ntoskrnl/include/internal/i386/asmmacro.S
2006-01-17 01:22:21 UTC (rev 20929)
@@ -64,6 +64,73 @@
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
//
// TRAP_PROLOG
_____
Modified: trunk/reactos/ntoskrnl/ke/i386/syscall.S
--- trunk/reactos/ntoskrnl/ke/i386/syscall.S 2006-01-17 00:13:11 UTC
(rev 20928)
+++ trunk/reactos/ntoskrnl/ke/i386/syscall.S 2006-01-17 01:22:21 UTC
(rev 20929)
@@ -107,6 +107,7 @@
push 0
jmp _KiTrap6
+.func KiFastCallEntry
_KiFastCallEntry:
// ==================== UNIQUE SYSENTER STUB. DO NOT DUPLICATE
============//
@@ -186,7 +187,9 @@
/* 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 @@
/* 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 @@
/* 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 @@
//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 @@
pop ebp
mov esp, [esp]
iret
+.endfunc
.globl _NtRaiseException@12
_NtRaiseException@12:
_____
Modified: trunk/reactos/ntoskrnl/ke/i386/trap.s
--- trunk/reactos/ntoskrnl/ke/i386/trap.s 2006-01-17 00:13:11 UTC
(rev 20928)
+++ trunk/reactos/ntoskrnl/ke/i386/trap.s 2006-01-17 01:22:21 UTC
(rev 20929)
@@ -43,7 +43,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap1
@@ -64,7 +64,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap2
@@ -85,7 +85,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap3
@@ -106,7 +106,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap4
@@ -127,7 +127,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap5
@@ -148,7 +148,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap6
@@ -169,7 +169,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap7
@@ -190,7 +190,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap8
@@ -216,7 +216,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap10
@@ -234,7 +234,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap11
@@ -252,7 +252,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap12
@@ -270,7 +270,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap13
@@ -288,7 +288,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap14
@@ -306,7 +306,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap15
@@ -327,7 +327,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap16
@@ -348,7 +348,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap17
@@ -369,7 +369,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap18
@@ -390,7 +390,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrap19
@@ -411,7 +411,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiTrapUnknown
@@ -426,7 +426,7 @@
cmp eax, 1
/* Return to caller */
- jne Kei386EoiHelper@0
+ jne _Kei386EoiHelper@0
jmp _KiV86Complete
.globl _KiCoprocessorError@0