Commit in reactos/ntoskrnl on MAIN
ke/catch.c+18-71.43 -> 1.44
ke/i386/exp.c+61-361.86 -> 1.87
ps/debug.c+2-61.11 -> 1.12
+81-49
3 modified files
NtRaiseException fixed to not clobber EAX any more, and both NtContinue and NtRaiseException no longer clobber EDX. kmode SEH works now, but there are likely some lingering bugs. This patch was made possible by the collaborative efforts of myself, kjk_hyperion, Art Yerkes, and Skywing.

reactos/ntoskrnl/ke
catch.c 1.43 -> 1.44
diff -u -r1.43 -r1.44
--- catch.c	23 Jun 2004 22:31:51 -0000	1.43
+++ catch.c	2 Jul 2004 01:36:25 -0000	1.44
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: catch.c,v 1.43 2004/06/23 22:31:51 ion Exp $
+/* $Id: catch.c,v 1.44 2004/07/02 01:36:25 royce Exp $
  *
  * PROJECT:              ReactOS kernel
  * FILE:                 ntoskrnl/ke/catch.c
@@ -256,17 +256,28 @@
 	return FALSE;
 }
 
+VOID
+FASTCALL
+KeRosTrapReturn ( PKTRAP_FRAME TrapFrame, PKTRAP_FRAME PrevTrapFrame );
+
 NTSTATUS STDCALL
 NtRaiseException (IN PEXCEPTION_RECORD ExceptionRecord,
 		  IN PCONTEXT Context,
 		  IN BOOLEAN SearchFrames)
 {
-  KiDispatchException(ExceptionRecord,
-		      Context,
-		      PsGetCurrentThread()->Tcb.TrapFrame,
-		      (KPROCESSOR_MODE)ExGetPreviousMode(),
-		      SearchFrames);
-  return(STATUS_SUCCESS);
+	PKTRAP_FRAME TrapFrame = KeGetCurrentThread()->TrapFrame;
+	PKTRAP_FRAME PrevTrapFrame = (PKTRAP_FRAME)TrapFrame->Edx;
+
+	KeGetCurrentKPCR()->Tib.ExceptionList = TrapFrame->ExceptionList;
+
+	KiDispatchException(ExceptionRecord,
+		Context,
+		PsGetCurrentThread()->Tcb.TrapFrame,
+		(KPROCESSOR_MODE)ExGetPreviousMode(),
+		SearchFrames);
+
+	KeRosTrapReturn ( TrapFrame, PrevTrapFrame );
+	return(STATUS_SUCCESS);
 }
 
 /*

reactos/ntoskrnl/ke/i386
exp.c 1.86 -> 1.87
diff -u -r1.86 -r1.87
--- exp.c	23 Jun 2004 19:40:31 -0000	1.86
+++ exp.c	2 Jul 2004 01:36:25 -0000	1.87
@@ -79,7 +79,7 @@
 extern ULONG init_stack;
 extern ULONG init_stack_top;
 
-static char *ExceptionTypeStrings[] = 
+static char *ExceptionTypeStrings[] =
   {
     "Divide Error",
     "Debug Trap",
@@ -101,7 +101,7 @@
     "Machine Check"
   };
 
-static NTSTATUS ExceptionToNtStatus[] = 
+static NTSTATUS ExceptionToNtStatus[] =
   {
     STATUS_INTEGER_DIVIDE_BY_ZERO,
     STATUS_SINGLE_STEP,
@@ -142,11 +142,11 @@
    ULONG_PTR RelativeAddress;
 
    current_entry = ModuleTextListHead.Flink;
-   
+
    while (current_entry != &ModuleTextListHead &&
 	  current_entry != NULL)
      {
-	current = 
+	current =
 	  CONTAINING_RECORD(current_entry, MODULE_TEXT_SECTION, ListEntry);
 
 	if (address >= (PVOID)current->Base &&
@@ -219,7 +219,7 @@
   ULONG TraceLength;
   BOOLEAN FoundRepeat;
 #endif
-  
+
   OldTss = KeGetCurrentKPCR()->TSS;
   Esp0 = OldTss->Esp;
 
@@ -243,7 +243,7 @@
     {
       OldCr3 = 0xBEADF0AL;
     }
-   
+
    /*
     * Check for stack underflow
     */
@@ -254,7 +254,7 @@
 		 Esp0, (ULONG)PsGetCurrentThread()->Tcb.StackLimit);
 	ExceptionNr = 12;
      }
-   
+
    /*
     * Print out the CPU registers
     */
@@ -286,9 +286,9 @@
    DbgPrint("\n");
    DbgPrint("DS %x ES %x FS %x GS %x\n", OldTss->Ds, OldTss->Es,
 	    OldTss->Fs, OldTss->Gs);
-   DbgPrint("EAX: %.8x   EBX: %.8x   ECX: %.8x\n", OldTss->Eax, OldTss->Ebx, 
+   DbgPrint("EAX: %.8x   EBX: %.8x   ECX: %.8x\n", OldTss->Eax, OldTss->Ebx,
 	    OldTss->Ecx);
-   DbgPrint("EDX: %.8x   EBP: %.8x   ESI: %.8x\n   ESP: %.8x", OldTss->Edx, 
+   DbgPrint("EDX: %.8x   EBP: %.8x   ESI: %.8x\n   ESP: %.8x", OldTss->Edx,
 	    OldTss->Ebp, OldTss->Esi, Esp0);
    DbgPrint("EDI: %.8x   EFLAGS: %.8x ", OldTss->Edi, OldTss->Eflags);
    if (OldTss->Cs == KERNEL_CS)
@@ -298,7 +298,7 @@
 	  {
 	     DbgPrint("kernel stack base %x\n",
 		      PsGetCurrentThread()->Tcb.StackLimit);
-		      	     
+
 	  }
      }
    else
@@ -318,10 +318,10 @@
 	  StackBase = (ULONG)&init_stack;
 	}
 
-      /* 
+      /*
 	 Change to an #if 0 to reduce the amount of information printed on
-	 a recursive stack trace. 
-      */      
+	 a recursive stack trace.
+      */
 #if 1
       DbgPrint("Frames: ");
       Frame = (PULONG)OldTss->Ebp;
@@ -351,7 +351,7 @@
 	  FoundRepeat = FALSE;
 	  while ((j - i) <= (TraceLength - j) && FoundRepeat == FALSE)
 	    {
-	      if (memcmp(&StackTrace[i], &StackTrace[j], 
+	      if (memcmp(&StackTrace[i], &StackTrace[j],
 			 (j - i) * sizeof(PVOID)) == 0)
 		{
 		  StackRepeatCount[i] = 2;
@@ -369,10 +369,10 @@
 	      continue;
 	    }
 	  j = j + StackRepeatLength[i];
-	  while ((TraceLength - j) >= StackRepeatLength[i] && 
+	  while ((TraceLength - j) >= StackRepeatLength[i] &&
 		 FoundRepeat == TRUE)
 	    {
-	      if (memcmp(&StackTrace[i], &StackTrace[j], 
+	      if (memcmp(&StackTrace[i], &StackTrace[j],
 			 StackRepeatLength[i] * sizeof(PVOID)) == 0)
 		{
 		  StackRepeatCount[i]++;
@@ -411,7 +411,7 @@
 	}
 #endif
     }
-   
+
    DbgPrint("\n");
    for(;;);
    return 0;
@@ -429,7 +429,7 @@
   ULONG cr2 = (ULONG)Tf->DebugPointer;
 
   Esp0 = (ULONG)Tf;
-  
+
    /*
     * Print out the CPU registers
     */
@@ -464,7 +464,7 @@
    DbgPrint("DS %x ES %x FS %x GS %x\n", Tf->Ds&0xffff, Tf->Es&0xffff,
 	    Tf->Fs&0xffff, Tf->Gs&0xfff);
    DbgPrint("EAX: %.8x   EBX: %.8x   ECX: %.8x\n", Tf->Eax, Tf->Ebx, Tf->Ecx);
-   DbgPrint("EDX: %.8x   EBP: %.8x   ESI: %.8x   ESP: %.8x\n", Tf->Edx, 
+   DbgPrint("EDX: %.8x   EBP: %.8x   ESI: %.8x   ESP: %.8x\n", Tf->Edx,
 	    Tf->Ebp, Tf->Esi, Esp0);
    DbgPrint("EDI: %.8x   EFLAGS: %.8x ", Tf->Edi, Tf->Eflags);
    if ((Tf->Cs&0xffff) == KERNEL_CS)
@@ -474,7 +474,7 @@
 	  {
 	     DbgPrint("kernel stack base %x\n",
 		      PsGetCurrentThread()->Tcb.StackLimit);
-		      	     
+
 	  }
      }
 
@@ -486,7 +486,7 @@
      {
        StackLimit = (ULONG)&init_stack_top;
      }
-   
+
    /*
     * Dump the stack frames
     */
@@ -536,7 +536,7 @@
 ULONG
 KiTrapHandler(PKTRAP_FRAME Tf, ULONG ExceptionNr)
 /*
- * FUNCTION: Called by the lowlevel execption handlers to print an amusing 
+ * FUNCTION: Called by the lowlevel execption handlers to print an amusing
  * message and halt the computer
  * ARGUMENTS:
  *        Complete CPU context
@@ -551,7 +551,7 @@
 
    /* Use the address of the trap frame as approximation to the ring0 esp */
    Esp0 = (ULONG)&Tf->Eip;
-  
+
    /* Get CR2 */
 #if defined(__GNUC__)
    __asm__("movl %%cr2,%0\n\t" : "=d" (cr2_));
@@ -562,7 +562,7 @@
 #error Unknown compiler for inline assembler
 #endif
    Tf->DebugPointer = (PVOID)cr2_;
-   
+
    /*
     * If this was a V86 mode exception then handle it specially
     */
@@ -607,7 +607,7 @@
     */
    if (ExceptionNr == 3 && Tf->Eip == ((ULONG)DbgBreakPointNoBugCheck) + 1)
      {
-       /* 
+       /*
 	  EIP is already adjusted by the processor to point to the instruction
 	  after the breakpoint.
        */
@@ -627,13 +627,10 @@
     }
 }
 
-VOID 
+VOID
 KeDumpStackFrames(PULONG Frame)
 {
-	ULONG i;
-
 	DbgPrint("Frames: ");
-	i = 1;
 	while ( MmIsAddressValid(Frame) )
 	{
 		if (!KeRosPrintAddress((PVOID)Frame[1]))
@@ -641,15 +638,15 @@
 			DbgPrint("<%X>", (PVOID)Frame[1]);
 		}
 		Frame = (PULONG)Frame[0];
-		i++;
 		DbgPrint(" ");
 	}
+	DbgPrint("\n");
 }
 
 VOID STDCALL
 KeRosDumpStackFrames ( PULONG Frame, ULONG FrameCount )
 {
-	ULONG i;
+	ULONG i=0;
 
 	DbgPrint("Frames: ");
 	if ( !Frame )
@@ -657,7 +654,6 @@
 		__asm__("mov %%ebp, %%ebx" : "=b" (Frame) : );
 		Frame = (PULONG)Frame[0]; // step out of KeRosDumpStackFrames
 	}
-	i = 1;
 	while ( MmIsAddressValid(Frame) && i++ < FrameCount )
 	{
 		if (!KeRosPrintAddress((PVOID)Frame[1]))
@@ -667,6 +663,7 @@
 		Frame = (PULONG)Frame[0];
 		DbgPrint(" ");
 	}
+	DbgPrint("\n");
 }
 
 static void set_system_call_gate(unsigned int sel, unsigned int func)
@@ -683,7 +680,7 @@
    DPRINT("set_interrupt_gate(sel %d, func %x)\n",sel,func);
    KiIdt[sel].a = (((int)func)&0xffff) +
      (KERNEL_CS << 16);
-   KiIdt[sel].b = 0x8e00 + (((int)func)&0xffff0000);         
+   KiIdt[sel].b = 0x8e00 + (((int)func)&0xffff0000);
 }
 
 static void set_trap_gate(unsigned int sel, unsigned int func, unsigned int dpl)
@@ -692,7 +689,7 @@
    assert(dpl <= 3);
    KiIdt[sel].a = (((int)func)&0xffff) +
      (KERNEL_CS << 16);
-   KiIdt[sel].b = 0x8f00 + (dpl << 13) + (((int)func)&0xffff0000);         
+   KiIdt[sel].b = 0x8f00 + (dpl << 13) + (((int)func)&0xffff0000);
 }
 
 static void
@@ -732,12 +729,12 @@
    set_interrupt_gate(14, (ULONG)KiTrap14);
    set_trap_gate(15, (ULONG)KiTrap15, 0);
    set_trap_gate(16, (ULONG)KiTrap16, 0);
-   
+
    for (i=17;i<256;i++)
         {
 	   set_trap_gate(i,(int)KiTrapUnknown, 0);
         }
-   
+
    set_system_call_gate(0x2d,(int)interrupt_handler2d);
    set_system_call_gate(0x2e,(int)interrupt_handler2e);
 }
@@ -759,3 +756,31 @@
 	Thread->Teb->ExceptionCode = ExceptionCode;
 	return((NTSTATUS)OldEip);
 }
+
+VOID
+FASTCALL
+KeRosTrapReturn ( PKTRAP_FRAME TrapFrame, PKTRAP_FRAME PrevTrapFrame );
+
+/*
+ * @implemented
+ */
+NTSTATUS STDCALL
+NtRaiseException (
+	IN PEXCEPTION_RECORD ExceptionRecord,
+	IN PCONTEXT Context,
+	IN BOOLEAN SearchFrames)
+{
+	PKTRAP_FRAME TrapFrame = KeGetCurrentThread()->TrapFrame;
+	PKTRAP_FRAME PrevTrapFrame = (PKTRAP_FRAME)TrapFrame->Edx;
+
+	KeGetCurrentKPCR()->Tib.ExceptionList = TrapFrame->ExceptionList;
+
+	KiDispatchException(ExceptionRecord,
+		Context,
+		PsGetCurrentThread()->Tcb.TrapFrame,
+		(KPROCESSOR_MODE)ExGetPreviousMode(),
+		SearchFrames);
+
+	KeRosTrapReturn ( TrapFrame, PrevTrapFrame );
+	return(STATUS_SUCCESS);
+}

reactos/ntoskrnl/ps
debug.c 1.11 -> 1.12
diff -u -r1.11 -r1.12
--- debug.c	21 Jul 2003 21:36:01 -0000	1.11
+++ debug.c	2 Jul 2004 01:36:25 -0000	1.12
@@ -17,7 +17,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: debug.c,v 1.11 2003/07/21 21:36:01 dwelch Exp $
+/* $Id: debug.c,v 1.12 2004/07/02 01:36:25 royce Exp $
  *
  * PROJECT:                ReactOS kernel
  * FILE:                   ntoskrnl/ps/debug.c
@@ -69,11 +69,7 @@
 	TrapFrame->Eax = Context->Eax;
 	TrapFrame->Ebx = Context->Ebx;
 	TrapFrame->Ecx = Context->Ecx;
-	/*
-	 * Edx is used in the TrapFrame to hold the old trap frame pointer
-	 * so we don't want to overwrite it here
-	 */
-/*	TrapFrame->Edx = Context->Edx; */
+	TrapFrame->Edx = Context->Edx;
 	TrapFrame->Esi = Context->Esi;
 	TrapFrame->Edi = Context->Edi;
      }
CVSspam 0.2.8