From 617e78ebf0422ebe4faee26f1ad749ee9808e02e Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Sat, 26 Aug 2006 06:14:32 +0000 Subject: [PATCH] - Transform TRAP_PROLOG into a GAS macro. - Remove code in the page fault handler which was corrupting the trap frame. - Remove some ROS hacks that dealt with the fact the trap frame was getting corrupted, since now it isn't anymore. - Enable code that checks for Teb->GdiBatchCount during win32k system calls. The bugs that were mentionned in the #if 0 are fixed. svn path=/trunk/; revision=23714 --- reactos/include/ndk/asm.h | 1 + .../ntoskrnl/include/internal/i386/asmmacro.S | 143 +++++++----------- reactos/ntoskrnl/ke/i386/trap.s | 25 +-- reactos/ntoskrnl/mm/i386/pfault.c | 3 - 4 files changed, 61 insertions(+), 111 deletions(-) diff --git a/reactos/include/ndk/asm.h b/reactos/include/ndk/asm.h index fa999b2377b..bfe88fd844e 100644 --- a/reactos/include/ndk/asm.h +++ b/reactos/include/ndk/asm.h @@ -327,6 +327,7 @@ Author: #define TEB_EXCEPTION_CODE 0x1A4 #define TEB_ACTIVATION_CONTEXT_STACK_POINTER 0x1A8 #define TEB_DEALLOCATION_STACK 0xE0C +#define TEB_GDI_BATCH_COUNT 0xF70 #define TEB_GUARANTEED_STACK_BYTES 0xF78 #define TEB_FLS_DATA 0xFB4 diff --git a/reactos/ntoskrnl/include/internal/i386/asmmacro.S b/reactos/ntoskrnl/include/internal/i386/asmmacro.S index 4c99b0e97bc..fc90a3f71af 100644 --- a/reactos/ntoskrnl/include/internal/i386/asmmacro.S +++ b/reactos/ntoskrnl/include/internal/i386/asmmacro.S @@ -266,63 +266,64 @@ _KiUnexpectedInterrupt&Number: // /* Handle trap */ // // -#define TRAP_PROLOG(Label) \ - /* Just to be safe, clear out the HIWORD, since it's reserved */ \ - mov word ptr [esp+2], 0; \ -\ - /* Save the non-volatiles */ \ - push ebp; \ - push ebx; \ - push esi; \ - push edi; \ -\ - /* Save FS and set it to PCR */ \ - push fs; \ - mov ebx, KGDT_R0_PCR; \ - mov fs, bx; \ -\ - /* Save exception list and bogus previous mode */ \ - push fs:[KPCR_EXCEPTION_LIST]; \ - push -1; \ -\ - /* Save volatiles and segment registers */ \ - push eax; \ - push ecx; \ - push edx; \ - push ds; \ - push es; \ - push gs; \ -\ - /* Set the R3 data segment */ \ - mov ax, KGDT_R3_DATA + RPL_MASK; \ -\ - /* Skip debug registers and debug stuff */ \ - sub esp, 0x30; \ -\ - /* Load the segment registers */ \ - mov ds, ax; \ - mov es, ax; \ -\ - /* Set up frame */ \ - mov ebp, esp; \ -\ - /* Check if this was from V86 Mode */ \ - /* test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK; */ \ - /* jnz V86_Label; */ \ -\ - /* Get current thread */ \ - mov ecx, [fs:KPCR_CURRENT_THREAD]; \ - cld; \ -\ - /* Flush DR7 */ \ - and dword ptr [ebp+KTRAP_FRAME_DR7], 0; \ -\ - /* Check if the thread was being debugged */ \ - /* test byte ptr [ecx+KTHREAD_DEBUG_ACTIVE], 0xFF; */ \ - /* jnz Dr_Label; */ \ -\ - /* Set the Trap Frame Debug Header */ \ +.macro TRAP_PROLOG Label + /* Just to be safe, clear out the HIWORD, since it's reserved */ + mov word ptr [esp+2], 0 + + /* Save the non-volatiles */ + push ebp + push ebx + push esi + push edi + + /* Save FS and set it to PCR */ + push fs + mov ebx, KGDT_R0_PCR + mov fs, bx + + /* Save exception list and bogus previous mode */ + push fs:[KPCR_EXCEPTION_LIST] + push -1 + + /* Save volatiles and segment registers */ + push eax + push ecx + push edx + push ds + push es + push gs + + /* Set the R3 data segment */ + mov ax, KGDT_R3_DATA + RPL_MASK + + /* Skip debug registers and debug stuff */ + sub esp, 0x30 + + /* Load the segment registers */ + mov ds, ax + mov es, ax + + /* Set up frame */ + mov ebp, esp + + /* Check if this was from V86 Mode */ + /* test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK; */ + /* jnz V86_Label; */ + + /* Get current thread */ + mov ecx, [fs:KPCR_CURRENT_THREAD] + cld + + /* Flush DR7 */ + and dword ptr [ebp+KTRAP_FRAME_DR7], 0 + + /* Check if the thread was being debugged */ + /* test byte ptr [ecx+KTHREAD_DEBUG_ACTIVE], 0xFF; */ + /* jnz Dr_Label; */ + + /* Set the Trap Frame Debug Header */ SET_TF_DEBUG_HEADER +.endm // // @name INT_PROLOG @@ -507,23 +508,6 @@ _KiUnexpectedInterrupt&Number: /* Set the trap frame debug header */ SET_TF_DEBUG_HEADER -#ifdef DBG // FIXME: Is this for GDB? Can it be moved in the stub? - /* - * We want to know the address from where the syscall stub was called. - * If PrevMode is KernelMode, that address is stored in our own (kernel) - * stack, at location KTRAP_FRAME_ESP. - * If we're coming from UserMode, we load the usermode stack pointer - * and go back two frames (first frame is the syscall stub, second call - * is the caller of the stub). - */ - mov edi, [ebp+KTRAP_FRAME_ESP] - test byte ptr [esi+KTHREAD_PREVIOUS_MODE], 0x01 - jz 0f - mov edi, [edi+4] -0: - mov [ebp+KTRAP_FRAME_DEBUGEIP], edi -#endif - /* Enable interrupts */ sti .endm @@ -754,20 +738,9 @@ FastExit: #if DBG 0: -#if 0 - /* Print a message */ - mov esi, [esp+KTRAP_FRAME_DEBUGARGMARK] - mov edi, [esp+KTRAP_FRAME_DEBUGARGMARK-4] - push edi - push esi - push offset Broken - call _DbgPrint - add esp, 12 -#endif - jmp 2b // ros hack - /* Fix up the mask */ add dword ptr [esp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00 + 6: int 3 jmp 5b diff --git a/reactos/ntoskrnl/ke/i386/trap.s b/reactos/ntoskrnl/ke/i386/trap.s index 0ffd6f59262..8ec8610b6a8 100644 --- a/reactos/ntoskrnl/ke/i386/trap.s +++ b/reactos/ntoskrnl/ke/i386/trap.s @@ -187,23 +187,6 @@ _KiFastCallEntry: /* Set the trap frame debug header */ SET_TF_DEBUG_HEADER -#ifdef DBG // FIXME: Is this for GDB? Can it be moved in the stub? - /* - * We want to know the address from where the syscall stub was called. - * If PrevMode is KernelMode, that address is stored in our own (kernel) - * stack, at location KTRAP_FRAME_ESP. - * If we're coming from UserMode, we load the usermode stack pointer - * and go back two frames (first frame is the syscall stub, second call - * is the caller of the stub). - */ - mov edi, [ebp+KTRAP_FRAME_ESP] - test byte ptr [esi+KTHREAD_PREVIOUS_MODE], 0x01 - jz PrevWasKernelMode - mov edi, [edi+4] -PrevWasKernelMode: - mov [ebp+KTRAP_FRAME_DEBUGEIP], edi -#endif - /* Enable interrupts */ sti @@ -229,9 +212,6 @@ SharedCode: /* Invalid ID, try to load Win32K Table */ jnb KiBBTUnexpectedRange -#if 0 // <== Disabled for two reasons: We don't save TEB in 0x18, but KPCR. - // <== We don't have a KeGdiFlushUserBatch callback yet (needs to be - // sent through the PsInitializeWin32Callouts structure) /* Check if this was Win32K */ cmp ecx, SERVICE_TABLE_TEST jnz NotWin32K @@ -242,15 +222,14 @@ SharedCode: /* Check if we should flush the User Batch */ xor ebx, ebx or ebx, [ecx+TEB_GDI_BATCH_COUNT] - jz NoWin32K + jz NotWin32K /* Flush it */ push edx push eax - call [_KeGdiFlushUserBatch] + //call [_KeGdiFlushUserBatch] pop eax pop edx -#endif NotWin32K: /* Increase total syscall count */ diff --git a/reactos/ntoskrnl/mm/i386/pfault.c b/reactos/ntoskrnl/mm/i386/pfault.c index fb160e1aac6..0a94556cc63 100644 --- a/reactos/ntoskrnl/mm/i386/pfault.c +++ b/reactos/ntoskrnl/mm/i386/pfault.c @@ -36,9 +36,6 @@ ULONG KiPageFaultHandler(PKTRAP_FRAME Tf, ULONG ExceptionNr) ASSERT(ExceptionNr == 14); - /* Store the exception number in an unused field in the trap frame. */ - Tf->DbgArgMark = 14; - /* get the faulting address */ cr2 = Ke386GetCr2(); Tf->DbgArgPointer = cr2;