"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
QSI_DEF(SystemInterruptInformation)
{
PKPRCB Prcb;
- PKPCR Pcr;
LONG i;
ULONG ti;
PSYSTEM_INTERRUPT_INFORMATION sii = (PSYSTEM_INTERRUPT_INFORMATION)Buffer;
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;
#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
#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
PGET_SET_CTX_CONTEXT GetSetContext;
PKEVENT Event;
PCONTEXT Context;
- PKTHREAD Thread;
+ PETHREAD Thread;
KPROCESSOR_MODE Mode;
PKTRAP_FRAME TrapFrame = NULL;
PAGED_CODE();
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 */
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,
ULONG Eip;
BOOLEAN Result, StopSearch = FALSE;
ULONG i = 0;
- PKTHREAD Thread = KeGetCurrentThread();
+ PETHREAD Thread = PsGetCurrentThread();
PTEB Teb;
PKTRAP_FRAME TrapFrame;
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))
{
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;