Properly bias frame, remove bugcheck added for debugging, re-add bugcheck removed for debugging

svn path=/trunk/; revision=17841
This commit is contained in:
Alex Ionescu 2005-09-13 20:13:05 +00:00
parent 736e7b9af0
commit 99e5e010dc
3 changed files with 13 additions and 19 deletions

View file

@ -614,7 +614,7 @@ KiEspToTrapFrame(IN PKTRAP_FRAME TrapFrame,
/* Don't allow ESP to be lowered, this is illegal */
if (Esp < Previous)
{
//KeBugCheck(SET_OF_INVALID_CONTEXT);
KeBugCheck(SET_OF_INVALID_CONTEXT);
}
/* Create an edit frame, check if it was alrady */
@ -767,7 +767,6 @@ KeContextToTrapFrame(IN PCONTEXT Context,
TrapFrame->Ds = USER_DS;
TrapFrame->Es = USER_DS;
TrapFrame->Fs = Context->SegFs;
KEBUGCHECK(0);
TrapFrame->Gs = 0;
}
else

View file

@ -72,7 +72,6 @@
/*
* FIXMEs:
* - Fix Win32k Callbacks so we can optimize stack usage.
* - Dig in trap code and see why we need to push/pop the segments,
* which -shouldn't- be needed on syscalls; one of the things
* missing for this to work is lazy loading in the GPF handler,
@ -94,6 +93,7 @@
BadStack:
/* Restore ESP0 stack */
int 3
mov ecx, [fs:KPCR_TSS]
mov esp, ss:[ecx+KTSS_ESP0]
@ -115,18 +115,6 @@ _KiFastCallEntry:
/* Set the current stack to Kernel Stack */
mov ecx, [fs:KPCR_TSS]
mov esp, ss:[ecx+KTSS_ESP0]
/*
* ^^^^^ Normally we should be able to use KTHREAD.InitialStack - sizeof
* KTRAP_FRAME - sizeof(NPX_AREA) and that will give us exactly
* our esp (ie: ebp == esp by the way the system is organized).
* This didn't work until I added v86m trap frame bias, which was
* needed anways. It works NICELY until we hit a Win32K Callback,
* which also messes up a lea esp, [ebp+...] below. It seems the
* stack for callbacks isn't properly set up (it's missing sizeof
* KTRAP_FRAME), which is understandable since the whole code is
* messed up and smashes new stacks instead of using the kernel
* assigned one.
*/
/* Set up a fake INT Stack. */
push USER_DS
@ -157,6 +145,9 @@ _KiFastCallEntry:
push [ebx+KPCR_EXCEPTION_LIST]
mov dword ptr [ebx+KPCR_EXCEPTION_LIST], -1
/* Use the thread's stack */
mov ebp, [esi+KTHREAD_INITIAL_STACK]
/* Push previous mode */
push UserMode
@ -169,11 +160,15 @@ _KiFastCallEntry:
sub $0x30, %esp // + 0x70
.intel_syntax noprefix
/* Make space for us on the stack */
sub ebp, 0x29C
/* Write the previous mode */
mov byte ptr [esi+KTHREAD_PREVIOUS_MODE], UserMode
/* Go on the Kernel stack frame */
mov ebp, esp
/* Sanity check */
cmp ebp, esp
jnz BadStack
/* Flush DR7 */
and dword ptr [ebp+KTRAP_FRAME_DR7], 0

View file

@ -203,7 +203,7 @@ KeUserModeCallback(IN ULONG RoutineIndex,
}
/* FIXME: Need to check whether we were interrupted from v86 mode. */
RtlCopyMemory((char*)NewStack + StackSize - sizeof(KTRAP_FRAME) - sizeof(FX_SAVE_AREA),
Thread->Tcb.TrapFrame, sizeof(KTRAP_FRAME) - (4 * sizeof(DWORD)));
Thread->Tcb.TrapFrame, sizeof(KTRAP_FRAME) - (4 * sizeof(ULONG)));
NewFrame = (PKTRAP_FRAME)((char*)NewStack + StackSize - sizeof(KTRAP_FRAME) - sizeof(FX_SAVE_AREA));
/* We need the stack pointer to remain 4-byte aligned */
NewFrame->Esp -= (((ArgumentLength + 3) & (~ 0x3)) + (4 * sizeof(ULONG)));
@ -236,7 +236,7 @@ KeUserModeCallback(IN ULONG RoutineIndex,
Thread->Tcb.InitialStack = Thread->Tcb.StackBase = (char*)NewStack + StackSize;
Thread->Tcb.StackLimit = (ULONG)NewStack;
Thread->Tcb.KernelStack = (char*)NewStack + StackSize - sizeof(KTRAP_FRAME) - sizeof(FX_SAVE_AREA);
KeGetCurrentKPCR()->TSS->Esp0 = (ULONG)Thread->Tcb.InitialStack - sizeof(FX_SAVE_AREA);
KeGetCurrentKPCR()->TSS->Esp0 = (ULONG)Thread->Tcb.InitialStack - sizeof(FX_SAVE_AREA) - 0x10;
KePushAndStackSwitchAndSysRet((ULONG)&SavedState, Thread->Tcb.KernelStack);
/*