[NTOSKRNL]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Thu, 17 Dec 2009 20:58:58 +0000 (20:58 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Thu, 17 Dec 2009 20:58:58 +0000 (20:58 +0000)
"Fix things": Add architecture specific macros KeGetTrapFrame, KeGetExceptionFrame and KeGetContextSwitches. Should fix kernel build on arm. Patch by Alex, modified by me.

svn path=/trunk/; revision=44640

reactos/ntoskrnl/ex/sysinfo.c
reactos/ntoskrnl/include/internal/arm/ke.h
reactos/ntoskrnl/include/internal/i386/ke.h
reactos/ntoskrnl/ps/i386/psctx.c
reactos/ntoskrnl/ps/thread.c
reactos/ntoskrnl/rtl/libsupp.c

index 94ab5b8..c04886d 100644 (file)
@@ -1238,7 +1238,6 @@ QSI_DEF(SystemPoolTagInformation)
 QSI_DEF(SystemInterruptInformation)
 {
     PKPRCB Prcb;
-    PKPCR Pcr;
     LONG i;
     ULONG ti;
     PSYSTEM_INTERRUPT_INFORMATION sii = (PSYSTEM_INTERRUPT_INFORMATION)Buffer;
@@ -1253,12 +1252,7 @@ QSI_DEF(SystemInterruptInformation)
     for (i = 0; i < KeNumberProcessors; i++)
     {
         Prcb = KiProcessorBlock[i];
-        Pcr = (PKPCR)CONTAINING_RECORD(Prcb, KIPCR, PrcbData);
-#ifdef _M_ARM // This code should probably be done differently
-        sii->ContextSwitches = Pcr->ContextSwitches;
-#else
-        sii->ContextSwitches = ((PKIPCR)Pcr)->ContextSwitches;
-#endif
+        sii->ContextSwitches = KeGetContextSwitches(Prcb);
         sii->DpcCount = Prcb->DpcData[0].DpcCount;
         sii->DpcRate = Prcb->DpcRequestRate;
         sii->TimeIncrement = ti;
index 67b8bef..8dace74 100644 (file)
 #define KeSetContextReturnRegister(Context, ReturnValue) \
     ((Context)->R0 = (ReturnValue))
 
+//
+// Macro to get trap and exception frame from a thread stack
+//
+#define KeGetTrapFrame(Thread) \
+    (PKTRAP_FRAME)((ULONG_PTR)((Thread)->InitialStack) - \
+                   sizeof(KTRAP_FRAME))
+
+#define KeGetExceptionFrame(Thread) \
+    (PKEXCEPTION_FRAME)((ULONG_PTR)KeGetTrapFrame(Thread) - \
+                        sizeof(KEXCEPTION_FRAME))
+
+//
+// Macro to get context switches from the PRCB
+// All architectures but x86 have it in the PRCB's KeContextSwitches
+//
+#define KeGetContextSwitches(Prcb)  \
+    Prcb->KeContextSwitches
+
 //
 // Returns the Interrupt State from a Trap Frame.
 // ON = TRUE, OFF = FALSE
index ea2f8bc..753ebbc 100644 (file)
@@ -41,6 +41,24 @@ extern ULONG Ke386CacheAlignment;
 #define KeSetContextReturnRegister(Context, ReturnValue) \
     ((Context)->Eax = (ReturnValue))
 
+//
+// Macro to get trap and exception frame from a thread stack
+//
+#define KeGetTrapFrame(Thread) \
+    (PKTRAP_FRAME)((ULONG_PTR)((Thread)->InitialStack) - \
+                   sizeof(KTRAP_FRAME) - \
+                   sizeof(FX_SAVE_AREA))
+
+#define KeGetExceptionFrame(Thread) \
+    NULL
+
+//
+// Macro to get context switches from the PRCB
+// All architectures but x86 have it in the PRCB's KeContextSwitches
+//
+#define KeGetContextSwitches(Prcb)  \
+    CONTAINING_RECORD(Prcb, KIPCR, PrcbData)->ContextSwitches
+
 //
 // Returns the Interrupt State from a Trap Frame.
 // ON = TRUE, OFF = FALSE
index b1dd1e5..207334e 100644 (file)
@@ -50,7 +50,7 @@ PspGetOrSetContextKernelRoutine(IN PKAPC Apc,
     PGET_SET_CTX_CONTEXT GetSetContext;
     PKEVENT Event;
     PCONTEXT Context;
-    PKTHREAD Thread;
+    PETHREAD Thread;
     KPROCESSOR_MODE Mode;
     PKTRAP_FRAME TrapFrame = NULL;
     PAGED_CODE();
@@ -63,15 +63,13 @@ PspGetOrSetContextKernelRoutine(IN PKAPC Apc,
     Thread = Apc->SystemArgument2;
     
     /* If this is a kernel-mode request, grab the saved trap frame */
-    if (Mode == KernelMode) TrapFrame = Thread->TrapFrame;
+    if (Mode == KernelMode) TrapFrame = Thread->Tcb.TrapFrame;
     
     /* If we don't have one, grab it from the stack */
     if (!TrapFrame)
     {
         /* Trap frame is right under our initial stack */
-        TrapFrame = (PKTRAP_FRAME)((ULONG_PTR)Thread->InitialStack -
-                                   ROUND_UP(sizeof(KTRAP_FRAME), KTRAP_FRAME_ALIGN) -
-                                   sizeof(FX_SAVE_AREA));
+        TrapFrame = KeGetTrapFrame(&Thread->Tcb);
     }
 
     /* Check if it's a set or get */
index e0ea695..d05fc85 100644 (file)
@@ -72,10 +72,8 @@ PspUserThreadStartup(IN PKSTART_ROUTINE StartRoutine,
         KeRaiseIrql(APC_LEVEL, &OldIrql);
 
         /* Queue the User APC */
-        KiInitializeUserApc(NULL,
-                            (PVOID)((ULONG_PTR)Thread->Tcb.InitialStack -
-                            sizeof(KTRAP_FRAME) -
-                            SIZEOF_FX_SAVE_AREA),
+        KiInitializeUserApc(KeGetExceptionFrame(&Thread->Tcb),
+                            KeGetTrapFrame(&Thread->Tcb),
                             PspSystemDllEntryPoint,
                             NULL,
                             PspSystemDllBase,
index 792b763..ae87fc5 100644 (file)
@@ -285,7 +285,7 @@ RtlWalkFrameChain(OUT PVOID *Callers,
     ULONG Eip;
     BOOLEAN Result, StopSearch = FALSE;
     ULONG i = 0;
-    PKTHREAD Thread = KeGetCurrentThread();
+    PETHREAD Thread = PsGetCurrentThread();
     PTEB Teb;
     PKTRAP_FRAME TrapFrame;
 
@@ -326,14 +326,12 @@ RtlWalkFrameChain(OUT PVOID *Callers,
         if (Flags == 1)
         {
             /* Get the trap frame and TEB */
-            TrapFrame = Thread->TrapFrame;
-            Teb = Thread->Teb;
+            TrapFrame = KeGetTrapFrame(&Thread->Tcb);
+            Teb = Thread->Tcb.Teb;
 
             /* Make sure we can trust the TEB and trap frame */
             if (!(Teb) ||
-                !((PVOID)((ULONG_PTR)TrapFrame & 0x80000000)) ||
-                ((PVOID)TrapFrame <= (PVOID)Thread->StackLimit) ||
-                ((PVOID)TrapFrame >= (PVOID)Thread->StackBase) ||
+                !(Thread->SystemThread) ||
                 (KeIsAttachedProcess()) ||
                 (KeGetCurrentIrql() >= DISPATCH_LEVEL))
             {
@@ -390,7 +388,7 @@ RtlWalkFrameChain(OUT PVOID *Callers,
             if ((StackBegin < Eip) && (Eip < StackEnd)) break;
 
             /* Check if we reached a user-mode address */
-            if (!(Flags) && !(Eip & 0x80000000)) break;
+            if (!(Flags) && !(Eip & 0x80000000)) break; // FIXME: 3GB breakage
 
             /* Save this frame */
             Callers[i] = (PVOID)Eip;