[NTOS:KDBG] Portably read control registers.

Fixes clang warning:
..\ntoskrnl\kdbg\kdb.c(175,25):  warning: variable 'TrapCr4' is uninitialized when used here [-Wuninitialized]
    KdbTrapFrame->Cr4 = TrapCr4;
                        ^~~~~~~
..\ntoskrnl\kdbg\kdb.c(140,45):  note: initialize the variable 'TrapCr4' to silence this warning
    ULONG TrapCr0, TrapCr2, TrapCr3, TrapCr4;
                                            ^
                                             = 0
This commit is contained in:
Thomas Faber 2017-11-03 13:52:34 +01:00
parent 22f1c0650f
commit fcbfa843da
No known key found for this signature in database
GPG key ID: 076E7C3D44720826

View file

@ -137,42 +137,15 @@ KdbpTrapFrameToKdbTrapFrame(
PKTRAP_FRAME TrapFrame,
PKDB_KTRAP_FRAME KdbTrapFrame)
{
ULONG TrapCr0, TrapCr2, TrapCr3, TrapCr4;
/* Copy the TrapFrame only up to Eflags and zero the rest*/
RtlCopyMemory(&KdbTrapFrame->Tf, TrapFrame, FIELD_OFFSET(KTRAP_FRAME, HardwareEsp));
RtlZeroMemory((PVOID)((ULONG_PTR)&KdbTrapFrame->Tf + FIELD_OFFSET(KTRAP_FRAME, HardwareEsp)),
sizeof(KTRAP_FRAME) - FIELD_OFFSET(KTRAP_FRAME, HardwareEsp));
#ifndef _MSC_VER
asm volatile(
"movl %%cr0, %0" "\n\t"
"movl %%cr2, %1" "\n\t"
"movl %%cr3, %2" "\n\t"
"movl %%cr4, %3" "\n\t"
: "=r"(TrapCr0), "=r"(TrapCr2),
"=r"(TrapCr3), "=r"(TrapCr4));
#else
__asm
{
mov eax, cr0;
mov TrapCr0, eax;
mov eax, cr2;
mov TrapCr2, eax;
mov eax, cr3;
mov TrapCr3, eax;
/* FIXME: What's the problem with cr4? */
//mov eax, cr4;
//mov TrapCr4, eax;
}
#endif
KdbTrapFrame->Cr0 = TrapCr0;
KdbTrapFrame->Cr2 = TrapCr2;
KdbTrapFrame->Cr3 = TrapCr3;
KdbTrapFrame->Cr4 = TrapCr4;
KdbTrapFrame->Cr0 = __readcr0();
KdbTrapFrame->Cr2 = __readcr2();
KdbTrapFrame->Cr3 = __readcr3();
KdbTrapFrame->Cr4 = __readcr4();
KdbTrapFrame->Tf.HardwareEsp = KiEspFromTrapFrame(TrapFrame);
KdbTrapFrame->Tf.HardwareSegSs = (USHORT)(KiSsFromTrapFrame(TrapFrame) & 0xFFFF);