Amd64/misc 64bit fixes (#236)
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Mon, 1 Jan 2018 11:07:50 +0000 (12:07 +0100)
committerGitHub <noreply@github.com>
Mon, 1 Jan 2018 11:07:50 +0000 (12:07 +0100)
[REACTOS] Misc 64 bit fixes

* [NTOS:MM] Allow MEM_DOS_LIM in NtMapViewOfSection on x64 as well
* [NTOS:MM] Implement x64 version of MmIsDisabledPage
* [HAL] Remove obsolete code
* [NTOS:KE] Fix amd64 version of KeContextToTrapFrame and KeTrapFrameToContext
* [XDK] Fix CONTEXT_XSTATE definition
* [PCNET] Convert physical address types from pointers to PHYSICAL_ADDRESS

17 files changed:
dll/ntdll/dbg/dbgui.c
dll/win32/kernel32/client/handle.c
dll/win32/kernel32/winnls/string/format_msg.c
dll/win32/shell32/dialogs/dialogs.cpp
drivers/network/afd/afd/main.c
drivers/network/dd/pcnet/pcnet.c
drivers/network/dd/pcnet/pcnet.h
modules/rosapps/applications/explorer-old/shell/mainframe.cpp
modules/rosapps/applications/explorer-old/utility/utility.cpp
modules/rosapps/applications/explorer-old/utility/window.h
ntoskrnl/ke/amd64/context.c
ntoskrnl/ke/amd64/cpu.c
ntoskrnl/ke/bug.c
ntoskrnl/mm/ARM3/section.c
ntoskrnl/mm/amd64/page.c
sdk/include/ndk/ketypes.h
sdk/include/xdk/amd64/ke.h

index 80b0a1d..ccc89fb 100644 (file)
@@ -64,11 +64,10 @@ DbgUiConvertStateChangeStructure(IN PDBGUI_WAIT_STATE_CHANGE WaitStateChange,
     NTSTATUS Status;
     THREAD_BASIC_INFORMATION ThreadBasicInfo;
     LPDEBUG_EVENT DebugEvent = Win32DebugEvent;
-
+    
     /* Write common data */
-    DebugEvent->dwProcessId = (DWORD)WaitStateChange->
-                                     AppClientId.UniqueProcess;
-    DebugEvent->dwThreadId = (DWORD)WaitStateChange->AppClientId.UniqueThread;
+    DebugEvent->dwProcessId = PtrToUlong(WaitStateChange->AppClientId.UniqueProcess);
+    DebugEvent->dwThreadId = PtrToUlong(WaitStateChange->AppClientId.UniqueThread);
 
     /* Check what kind of even this is */
     switch (WaitStateChange->NewState)
index 3e5cbcf..3e116f5 100644 (file)
@@ -20,7 +20,7 @@ TranslateStdHandle(IN HANDLE hHandle)
 {
     PRTL_USER_PROCESS_PARAMETERS Ppb = NtCurrentPeb()->ProcessParameters;
 
-    switch ((ULONG)hHandle)
+    switch ((ULONG_PTR)hHandle)
     {
         case STD_INPUT_HANDLE:  return Ppb->StandardInput;
         case STD_OUTPUT_HANDLE: return Ppb->StandardOutput;
index 2f01c20..389cf1f 100644 (file)
@@ -63,14 +63,15 @@ static LPWSTR load_message( HMODULE module, UINT id, WORD lang )
 {
     MESSAGE_RESOURCE_ENTRY *mre;
     WCHAR *buffer;
-    NTSTATUS status;
+    NTSTATUS Status;
 
     TRACE("module = %p, id = %08x\n", module, id );
 
     if (!module) module = GetModuleHandleW( NULL );
-    if ((status = RtlFindMessage( module, (ULONG)RT_MESSAGETABLE, lang, id, &mre )) != STATUS_SUCCESS)
+    Status = RtlFindMessage(module, (ULONG_PTR)RT_MESSAGETABLE, lang, id, &mre);
+    if (!NT_SUCCESS(Status))
     {
-        SetLastError( RtlNtStatusToDosError(status) );
+        SetLastError(RtlNtStatusToDosError(Status));
         return NULL;
     }
 
index 3d66374..f266e79 100644 (file)
@@ -113,7 +113,7 @@ INT_PTR CALLBACK PickIconProc(HWND hwndDlg,
     {
     case WM_INITDIALOG:
         pIconContext = (PPICK_ICON_CONTEXT)lParam;
-        SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG)pIconContext);
+        SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pIconContext);
         pIconContext->hDlgCtrl = GetDlgItem(hwndDlg, IDC_PICKICON_LIST);
         SendMessageW(pIconContext->hDlgCtrl, LB_SETCOLUMNWIDTH, 32, 0);
         EnumResourceNamesW(pIconContext->hLibrary, RT_ICON, EnumPickIconResourceProc, (LPARAM)pIconContext->hDlgCtrl);
index df2eccc..8cdfb1a 100644 (file)
@@ -27,7 +27,7 @@ void OskitDumpBuffer( PCHAR Data, UINT Len ) {
 
     for( i = 0; i < Len; i++ ) {
         if( i && !(i & 0xf) ) DbgPrint( "\n" );
-        if( !(i & 0xf) ) DbgPrint( "%08x: ", (UINT)(Data + i) );
+        if( !(i & 0xf) ) DbgPrint( "%p: ", (Data + i) );
         DbgPrint( " %02x", Data[i] & 0xff );
     }
     DbgPrint("\n");
index 26a6527..0a78530 100644 (file)
@@ -139,8 +139,8 @@ MiniportHandleInterrupt(
               IndicatedData = TRUE;
 
               RtlZeroMemory(Descriptor, sizeof(RECEIVE_DESCRIPTOR));
-              Descriptor->RBADR =
-                  (ULONG)(Adapter->ReceiveBufferPtrPhys + Adapter->CurrentReceiveDescriptorIndex * BUFFER_SIZE);
+              Descriptor->RBADR = Adapter->ReceiveBufferPtrPhys.QuadPart +
+                                  (Adapter->CurrentReceiveDescriptorIndex * BUFFER_SIZE);
               Descriptor->BCNT = (-BUFFER_SIZE) | 0xf000;
               Descriptor->FLAGS |= RD_OWN;
 
@@ -308,11 +308,9 @@ MiFreeSharedMemory(
 {
   NDIS_PHYSICAL_ADDRESS PhysicalAddress;
 
-  PhysicalAddress.u.HighPart = 0;
-
   if(Adapter->InitializationBlockVirt)
     {
-      PhysicalAddress.u.LowPart = (ULONG)Adapter->InitializationBlockPhys;
+      PhysicalAddress = Adapter->InitializationBlockPhys;
       NdisMFreeSharedMemory(Adapter->MiniportAdapterHandle, Adapter->InitializationBlockLength,
           FALSE, Adapter->InitializationBlockVirt, PhysicalAddress);
       Adapter->InitializationBlockVirt = NULL;
@@ -320,7 +318,7 @@ MiFreeSharedMemory(
 
   if(Adapter->TransmitDescriptorRingVirt)
     {
-      PhysicalAddress.u.LowPart = (ULONG)Adapter->TransmitDescriptorRingPhys;
+      PhysicalAddress = Adapter->TransmitDescriptorRingPhys;
       NdisMFreeSharedMemory(Adapter->MiniportAdapterHandle, Adapter->TransmitDescriptorRingLength,
         FALSE, Adapter->TransmitDescriptorRingVirt, PhysicalAddress);
       Adapter->TransmitDescriptorRingVirt = NULL;
@@ -328,7 +326,7 @@ MiFreeSharedMemory(
 
   if(Adapter->ReceiveDescriptorRingVirt)
     {
-      PhysicalAddress.u.LowPart = (ULONG)Adapter->ReceiveDescriptorRingPhys;
+      PhysicalAddress = Adapter->ReceiveDescriptorRingPhys;
       NdisMFreeSharedMemory(Adapter->MiniportAdapterHandle, Adapter->ReceiveDescriptorRingLength,
           FALSE, Adapter->ReceiveDescriptorRingVirt, PhysicalAddress);
       Adapter->ReceiveDescriptorRingVirt = NULL;
@@ -336,7 +334,7 @@ MiFreeSharedMemory(
 
   if(Adapter->TransmitBufferPtrVirt)
     {
-      PhysicalAddress.u.LowPart = (ULONG)Adapter->TransmitBufferPtrPhys;
+      PhysicalAddress = Adapter->TransmitBufferPtrPhys;
       NdisMFreeSharedMemory(Adapter->MiniportAdapterHandle, Adapter->TransmitBufferLength,
           TRUE, Adapter->TransmitBufferPtrVirt, PhysicalAddress);
       Adapter->TransmitBufferPtrVirt = NULL;
@@ -344,7 +342,7 @@ MiFreeSharedMemory(
 
   if(Adapter->ReceiveBufferPtrVirt)
     {
-      PhysicalAddress.u.LowPart = (ULONG)Adapter->ReceiveBufferPtrPhys;
+      PhysicalAddress = Adapter->ReceiveBufferPtrPhys;
       NdisMFreeSharedMemory(Adapter->MiniportAdapterHandle, Adapter->ReceiveBufferLength,
           TRUE, Adapter->ReceiveBufferPtrVirt, PhysicalAddress);
       Adapter->ReceiveBufferPtrVirt = NULL;
@@ -383,13 +381,13 @@ MiAllocateSharedMemory(
          return NDIS_STATUS_RESOURCES;
       }
 
-      if(((ULONG)Adapter->InitializationBlockVirt & 0x00000003) != 0)
+      if (((ULONG_PTR)Adapter->InitializationBlockVirt & 0x00000003) != 0)
       {
          DPRINT1("address 0x%x not dword-aligned\n", Adapter->InitializationBlockVirt);
          return NDIS_STATUS_RESOURCES;
       }
 
-      Adapter->InitializationBlockPhys = (PINITIALIZATION_BLOCK)NdisGetPhysicalAddressLow(PhysicalAddress);
+      Adapter->InitializationBlockPhys = PhysicalAddress;
 
       /* allocate the transport descriptor ring */
       Adapter->TransmitDescriptorRingLength = sizeof(TRANSMIT_DESCRIPTOR) * BufferCount;
@@ -404,13 +402,13 @@ MiAllocateSharedMemory(
           continue;
       }
 
-      if (((ULONG)Adapter->TransmitDescriptorRingVirt & 0x00000003) != 0)
+      if (((ULONG_PTR)Adapter->TransmitDescriptorRingVirt & 0x00000003) != 0)
       {
          DPRINT1("address 0x%x not dword-aligned\n", Adapter->TransmitDescriptorRingVirt);
          return NDIS_STATUS_RESOURCES;
       }
 
-      Adapter->TransmitDescriptorRingPhys = (PTRANSMIT_DESCRIPTOR)NdisGetPhysicalAddressLow(PhysicalAddress);
+      Adapter->TransmitDescriptorRingPhys = PhysicalAddress;
       RtlZeroMemory(Adapter->TransmitDescriptorRingVirt, sizeof(TRANSMIT_DESCRIPTOR) * BufferCount);
 
       /* allocate the receive descriptor ring */
@@ -426,13 +424,13 @@ MiAllocateSharedMemory(
           continue;
       }
 
-      if (((ULONG)Adapter->ReceiveDescriptorRingVirt & 0x00000003) != 0)
+      if (((ULONG_PTR)Adapter->ReceiveDescriptorRingVirt & 0x00000003) != 0)
       {
           DPRINT1("address 0x%x not dword-aligned\n", Adapter->ReceiveDescriptorRingVirt);
           return NDIS_STATUS_RESOURCES;
       }
 
-      Adapter->ReceiveDescriptorRingPhys = (PRECEIVE_DESCRIPTOR)NdisGetPhysicalAddressLow(PhysicalAddress);
+      Adapter->ReceiveDescriptorRingPhys = PhysicalAddress;
       RtlZeroMemory(Adapter->ReceiveDescriptorRingVirt, sizeof(RECEIVE_DESCRIPTOR) * BufferCount);
 
       /* allocate transmit buffers */
@@ -448,13 +446,13 @@ MiAllocateSharedMemory(
           continue;
       }
 
-      if (((ULONG)Adapter->TransmitBufferPtrVirt & 0x00000003) != 0)
+      if(((ULONG_PTR)Adapter->TransmitBufferPtrVirt & 0x00000003) != 0)
       {
           DPRINT1("address 0x%x not dword-aligned\n", Adapter->TransmitBufferPtrVirt);
           return NDIS_STATUS_RESOURCES;
       }
 
-      Adapter->TransmitBufferPtrPhys = (PCHAR)NdisGetPhysicalAddressLow(PhysicalAddress);
+      Adapter->TransmitBufferPtrPhys = PhysicalAddress;
       RtlZeroMemory(Adapter->TransmitBufferPtrVirt, BUFFER_SIZE * BufferCount);
 
       /* allocate receive buffers */
@@ -470,13 +468,13 @@ MiAllocateSharedMemory(
           continue;
       }
 
-      if (((ULONG)Adapter->ReceiveBufferPtrVirt & 0x00000003) != 0)
+      if (((ULONG_PTR)Adapter->ReceiveBufferPtrVirt & 0x00000003) != 0)
       {
           DPRINT1("address 0x%x not dword-aligned\n", Adapter->ReceiveBufferPtrVirt);
           return NDIS_STATUS_RESOURCES;
       }
 
-      Adapter->ReceiveBufferPtrPhys = (PCHAR)NdisGetPhysicalAddressLow(PhysicalAddress);
+      Adapter->ReceiveBufferPtrPhys = PhysicalAddress;
       RtlZeroMemory(Adapter->ReceiveBufferPtrVirt, BUFFER_SIZE * BufferCount);
 
       break;
@@ -495,7 +493,7 @@ MiAllocateSharedMemory(
   TransmitDescriptor = Adapter->TransmitDescriptorRingVirt;
   for(i = 0; i < BufferCount; i++)
     {
-      (TransmitDescriptor+i)->TBADR = (ULONG)Adapter->TransmitBufferPtrPhys + i * BUFFER_SIZE;
+      (TransmitDescriptor+i)->TBADR = Adapter->TransmitBufferPtrPhys.QuadPart + i * BUFFER_SIZE;
       (TransmitDescriptor+i)->BCNT = 0xf000 | -BUFFER_SIZE; /* 2's compliment  + set top 4 bits */
       (TransmitDescriptor+i)->FLAGS = TD1_STP | TD1_ENP;
     }
@@ -506,7 +504,7 @@ MiAllocateSharedMemory(
   ReceiveDescriptor = Adapter->ReceiveDescriptorRingVirt;
   for(i = 0; i < BufferCount; i++)
     {
-      (ReceiveDescriptor+i)->RBADR = (ULONG)Adapter->ReceiveBufferPtrPhys + i * BUFFER_SIZE;
+      (ReceiveDescriptor+i)->RBADR = Adapter->ReceiveBufferPtrPhys.QuadPart + i * BUFFER_SIZE;
       (ReceiveDescriptor+i)->BCNT = 0xf000 | -BUFFER_SIZE; /* 2's compliment  + set top 4 bits */
       (ReceiveDescriptor+i)->FLAGS = RD_OWN;
     }
@@ -542,12 +540,12 @@ MiPrepareInitializationBlock(
 
   /* set up receive ring */
   DPRINT("Receive ring physical address: 0x%x\n", Adapter->ReceiveDescriptorRingPhys);
-  Adapter->InitializationBlockVirt->RDRA = (ULONG)Adapter->ReceiveDescriptorRingPhys;
+  Adapter->InitializationBlockVirt->RDRA = Adapter->ReceiveDescriptorRingPhys.QuadPart;
   Adapter->InitializationBlockVirt->RLEN = (Adapter->LogBufferCount << 4) & 0xf0;
 
   /* set up transmit ring */
   DPRINT("Transmit ring physical address: 0x%x\n", Adapter->TransmitDescriptorRingPhys);
-  Adapter->InitializationBlockVirt->TDRA = (ULONG)Adapter->TransmitDescriptorRingPhys;
+  Adapter->InitializationBlockVirt->TDRA = Adapter->TransmitDescriptorRingPhys.QuadPart;
   Adapter->InitializationBlockVirt->TLEN = (Adapter->LogBufferCount << 4) & 0xf0;
 }
 
@@ -730,9 +728,9 @@ MiInitChip(
 
   /* set up csr1 and csr2 with init block */
   NdisRawWritePortUshort(Adapter->PortOffset + RAP, CSR1);
-  NdisRawWritePortUshort(Adapter->PortOffset + RDP, (USHORT)((ULONG)Adapter->InitializationBlockPhys & 0xffff));
+  NdisRawWritePortUshort(Adapter->PortOffset + RDP, (USHORT)(Adapter->InitializationBlockPhys.LowPart & 0xffff));
   NdisRawWritePortUshort(Adapter->PortOffset + RAP, CSR2);
-  NdisRawWritePortUshort(Adapter->PortOffset + RDP, (USHORT)((ULONG)Adapter->InitializationBlockPhys >> 16) & 0xffff);
+  NdisRawWritePortUshort(Adapter->PortOffset + RDP, (USHORT)(Adapter->InitializationBlockPhys.LowPart >> 16) & 0xffff);
 
   DPRINT("programmed with init block\n");
 
@@ -1223,7 +1221,7 @@ MiniportSend(
   Adapter->CurrentTransmitEndIndex %= Adapter->BufferCount;
 
   Desc->FLAGS = TD1_OWN | TD1_STP | TD1_ENP;
-  Desc->BCNT = 0xf000 | -TotalPacketLength;
+  Desc->BCNT = 0xf000 | -(INT)TotalPacketLength;
 
   NdisMSynchronizeWithInterrupt(&Adapter->InterruptObject, MiSyncStartTransmit, Adapter);
 
index 5389c3e..578d1da 100644 (file)
@@ -79,27 +79,27 @@ typedef struct _ADAPTER
   /* initialization block */
   ULONG InitializationBlockLength;
   PINITIALIZATION_BLOCK InitializationBlockVirt;
-  PINITIALIZATION_BLOCK InitializationBlockPhys;
+  PHYSICAL_ADDRESS InitializationBlockPhys;
 
   /* transmit descriptor ring */
   ULONG TransmitDescriptorRingLength;
   PTRANSMIT_DESCRIPTOR TransmitDescriptorRingVirt;
-  PTRANSMIT_DESCRIPTOR TransmitDescriptorRingPhys;
+  PHYSICAL_ADDRESS TransmitDescriptorRingPhys;
 
   /* transmit buffers */
   ULONG TransmitBufferLength;
   PCHAR TransmitBufferPtrVirt;
-  PCHAR TransmitBufferPtrPhys;
+  PHYSICAL_ADDRESS TransmitBufferPtrPhys;
 
   /* receive descriptor ring */
   ULONG ReceiveDescriptorRingLength;
   PRECEIVE_DESCRIPTOR ReceiveDescriptorRingVirt;
-  PRECEIVE_DESCRIPTOR ReceiveDescriptorRingPhys;
+  PHYSICAL_ADDRESS ReceiveDescriptorRingPhys;
 
   /* receive buffers */
   ULONG ReceiveBufferLength;
   PCHAR ReceiveBufferPtrVirt;
-  PCHAR ReceiveBufferPtrPhys;
+  PHYSICAL_ADDRESS ReceiveBufferPtrPhys;
 
   /* buffer count */
   ULONG BufferCount;
index dd8618a..6cda867 100644 (file)
@@ -418,7 +418,7 @@ int MainFrameBase::Command(int id, int code)
 
                        HINSTANCE hinst = ShellExecute(_hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow);
 
-                       if ((int)hinst <= 32)
+                       if ((INT_PTR)hinst <= 32)
                                display_error(_hwnd, GetLastError());
                }
                break;}
index d20c73b..9fe745e 100644 (file)
@@ -192,7 +192,7 @@ BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow, LPCTSTR parameters)
 
        HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, parameters, NULL/*dir*/, nCmdShow);
 
-       if ((int)hinst <= 32) {
+       if ((INT_PTR)hinst <= 32) {
                display_error(hwnd, GetLastError());
                return FALSE;
        }
@@ -205,7 +205,7 @@ BOOL launch_fileA(HWND hwnd, LPSTR cmd, UINT nCmdShow, LPCSTR parameters)
 {
        HINSTANCE hinst = ShellExecuteA(hwnd, NULL/*operation*/, cmd, parameters, NULL/*dir*/, nCmdShow);
 
-       if ((int)hinst <= 32) {
+       if ((INT_PTR)hinst <= 32) {
                display_error(hwnd, GetLastError());
                return FALSE;
        }
@@ -387,7 +387,7 @@ BOOL launch_cpanel(HWND hwnd, LPCTSTR applet)
        _tcscpy(parameters, TEXT("shell32.dll,Control_RunDLL "));
        _tcscat(parameters, applet);
 
-       return ((int)ShellExecute(hwnd, TEXT("open"), TEXT("rundll32.exe"), parameters, NULL, SW_SHOWDEFAULT) > 32);
+       return ((INT_PTR)ShellExecute(hwnd, TEXT("open"), TEXT("rundll32.exe"), parameters, NULL, SW_SHOWDEFAULT) > 32);
 }
 
 
index 3bf913a..391f42a 100644 (file)
@@ -838,7 +838,7 @@ protected:
        {
                if (!_cmd.empty()) {
                        HINSTANCE hinst = ShellExecute(GetParent(_hwnd), _T("open"), _cmd, 0, 0, SW_SHOWNORMAL);
-                       return (int)hinst > HINSTANCE_ERROR;
+                       return (INT_PTR)hinst > HINSTANCE_ERROR;
                }
 
                return true;
@@ -861,7 +861,7 @@ struct ToolTip : public WindowHandle
        void add(HWND hparent, HWND htool, LPCTSTR txt=LPSTR_TEXTCALLBACK, LPARAM lparam=0)
        {
                TOOLINFO ti = {
-                       sizeof(TOOLINFO), TTF_SUBCLASS|TTF_IDISHWND|TTF_TRANSPARENT, hparent, (UINT)htool,
+                       sizeof(TOOLINFO), TTF_SUBCLASS|TTF_IDISHWND|TTF_TRANSPARENT, hparent, (UINT_PTR)htool,
                        {0,0,0,0}, 0, (LPTSTR)txt, lparam
                };
 
@@ -893,7 +893,7 @@ struct ToolTip : public WindowHandle
        void remove(HWND hparent, HWND htool)
        {
                TOOLINFO ti = {
-                       sizeof(TOOLINFO), TTF_IDISHWND, hparent, (UINT)htool,
+                       sizeof(TOOLINFO), TTF_IDISHWND, hparent, (UINT_PTR)htool,
                        {0,0,0,0}, 0, 0, 0
                };
 
index ec20efa..3e21cae 100644 (file)
@@ -57,8 +57,9 @@ KeContextToTrapFrame(IN PCONTEXT Context,
 
     /* Handle floating point registers */
     if ((ContextFlags & CONTEXT_FLOATING_POINT) &&
-        (Context->SegCs & MODE_MASK))
+        ((Context->SegCs & MODE_MASK) != KernelMode))
     {
+        TrapFrame->MxCsr = Context->MxCsr;
         TrapFrame->Xmm0 = Context->Xmm0;
         TrapFrame->Xmm1 = Context->Xmm1;
         TrapFrame->Xmm2 = Context->Xmm2;
@@ -84,7 +85,7 @@ KeContextToTrapFrame(IN PCONTEXT Context,
     if (ContextFlags & CONTEXT_CONTROL)
     {
         /* Check if this was a Kernel Trap */
-        if (Context->SegCs == KGDT64_R0_CODE)
+        if ((Context->SegCs & MODE_MASK) == KernelMode)
         {
             /* Set valid selectors */
             TrapFrame->SegCs = KGDT64_R0_CODE;
@@ -107,7 +108,7 @@ KeContextToTrapFrame(IN PCONTEXT Context,
     if (ContextFlags & CONTEXT_SEGMENTS)
     {
         /* Check if this was a Kernel Trap */
-        if (Context->SegCs == KGDT64_R0_CODE)
+        if ((Context->SegCs & MODE_MASK) == KernelMode)
         {
             /* Set valid selectors */
             TrapFrame->SegDs = KGDT64_R3_DATA | RPL_MASK;
@@ -147,14 +148,20 @@ KeTrapFrameToContext(IN PKTRAP_FRAME TrapFrame,
                      IN PKEXCEPTION_FRAME ExceptionFrame,
                      IN OUT PCONTEXT Context)
 {
+    ULONG ContextFlags;
     KIRQL OldIrql;
 
     /* Do this at APC_LEVEL */
     OldIrql = KeGetCurrentIrql();
     if (OldIrql < APC_LEVEL) KeRaiseIrql(APC_LEVEL, &OldIrql);
 
+    /* Make sure we have an amd64 context, then remove the flag */
+    ContextFlags = Context->ContextFlags;
+    ASSERT(ContextFlags & CONTEXT_AMD64);
+    ContextFlags &= ~CONTEXT_AMD64;
+
     /* Handle integer registers */
-    if ((Context->ContextFlags & CONTEXT_INTEGER) == CONTEXT_INTEGER)
+    if (ContextFlags & CONTEXT_INTEGER)
     {
         Context->Rax = TrapFrame->Rax;
         Context->Rbx = TrapFrame->Rbx;
@@ -178,8 +185,8 @@ KeTrapFrameToContext(IN PKTRAP_FRAME TrapFrame,
     }
 
     /* Handle floating point registers */
-    if (((Context->ContextFlags & CONTEXT_FLOATING_POINT) ==
-        CONTEXT_FLOATING_POINT) && (TrapFrame->SegCs & MODE_MASK))
+    if ((ContextFlags & CONTEXT_FLOATING_POINT) && 
+        ((TrapFrame->SegCs & MODE_MASK) != KernelMode))
     {
         Context->Xmm0 = TrapFrame->Xmm0;
         Context->Xmm1 = TrapFrame->Xmm1;
@@ -203,10 +210,10 @@ KeTrapFrameToContext(IN PKTRAP_FRAME TrapFrame,
     }
 
     /* Handle control registers */
-    if ((Context->ContextFlags & CONTEXT_CONTROL) == CONTEXT_CONTROL)
+    if (ContextFlags & CONTEXT_CONTROL)
     {
         /* Check if this was a Kernel Trap */
-        if (TrapFrame->SegCs == KGDT64_R0_CODE)
+        if ((TrapFrame->SegCs & MODE_MASK) == KernelMode)
         {
             /* Set valid selectors */
             Context->SegCs = KGDT64_R0_CODE;
@@ -226,10 +233,10 @@ KeTrapFrameToContext(IN PKTRAP_FRAME TrapFrame,
     }
 
     /* Handle segment selectors */
-    if ((Context->ContextFlags & CONTEXT_SEGMENTS) == CONTEXT_SEGMENTS)
+    if (ContextFlags & CONTEXT_SEGMENTS)
     {
         /* Check if this was a Kernel Trap */
-        if (TrapFrame->SegCs == KGDT64_R0_CODE)
+        if ((TrapFrame->SegCs & MODE_MASK) == KernelMode)
         {
             /* Set valid selectors */
             Context->SegDs = KGDT64_R3_DATA | RPL_MASK;
@@ -248,8 +255,7 @@ KeTrapFrameToContext(IN PKTRAP_FRAME TrapFrame,
     }
 
     /* Handle debug registers */
-    if ((Context->ContextFlags & CONTEXT_DEBUG_REGISTERS) ==
-        CONTEXT_DEBUG_REGISTERS)
+    if (ContextFlags & CONTEXT_DEBUG_REGISTERS)
     {
         /* Copy the debug registers */
         Context->Dr0 = TrapFrame->Dr0;
index 730bda1..3c2b706 100644 (file)
@@ -54,16 +54,9 @@ VOID
 NTAPI
 KiSetProcessorType(VOID)
 {
-    ULONG64 EFlags;
     CPU_INFO CpuInfo;
     ULONG Stepping, Type;
 
-    /* Start by assuming no CPUID data */
-    KeGetCurrentPrcb()->CpuID = 0;
-
-    /* Save EFlags */
-    EFlags = __readeflags();
-
     /* Do CPUID 1 now */
     KiCpuId(&CpuInfo, 1);
 
@@ -85,9 +78,6 @@ KiSetProcessorType(VOID)
     KeGetCurrentPrcb()->CpuID = TRUE;
     KeGetCurrentPrcb()->CpuType = (UCHAR)Type;
     KeGetCurrentPrcb()->CpuStep = (USHORT)Stepping;
-
-    /* Restore EFLAGS */
-    __writeeflags(EFlags);
 }
 
 ULONG
index 899debd..a92acb1 100644 (file)
@@ -716,7 +716,7 @@ KiDisplayBlueScreen(IN ULONG MessageId,
     /* Show the technical Data */
     sprintf(AnsiName,
             "\r\n\r\n*** STOP: 0x%08lX (0x%p,0x%p,0x%p,0x%p)\r\n\r\n",
-            KiBugCheckData[0],
+            (ULONG)KiBugCheckData[0],
             (PVOID)KiBugCheckData[1],
             (PVOID)KiBugCheckData[2],
             (PVOID)KiBugCheckData[3],
index c9b5daf..6a2710e 100644 (file)
@@ -3567,7 +3567,7 @@ NtMapViewOfSection(IN HANDLE SectionHandle,
     ACCESS_MASK DesiredAccess;
     ULONG ProtectionMask;
     KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
-#ifdef _M_IX86
+#if defined(_M_IX86) || defined(_M_AMD64)
     static const ULONG ValidAllocationType = (MEM_TOP_DOWN | MEM_LARGE_PAGES |
             MEM_DOS_LIM | SEC_NO_CHANGE | MEM_RESERVE);
 #else
index 864302b..c5f6158 100644 (file)
@@ -312,8 +312,10 @@ MmIsDisabledPage(PEPROCESS Process, PVOID Address)
 {
     MMPTE Pte;
     Pte.u.Long = MiGetPteValueForProcess(Process, Address);
-    __debugbreak(); // FIXME
-    return !Pte.u.Hard.Valid && !(Pte.u.Long & 0x800) && Pte.u.Hard.PageFrameNumber;
+
+    return (Pte.u.Hard.Valid == 0) && 
+           (Pte.u.Trans.Transition == 0) &&
+           (Pte.u.Hard.PageFrameNumber != 0);
 }
 
 BOOLEAN
index 7963217..839a0d7 100644 (file)
@@ -1975,7 +1975,7 @@ typedef struct _KPROCESS
     LIST_ENTRY ProfileListHead;
 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
     ULONG_PTR DirectoryTableBase;
-    ULONG Unused0;
+    ULONG_PTR Unused0;
 #else
     ULONG_PTR DirectoryTableBase[2];
 #endif
index f16b721..90abb70 100644 (file)
@@ -191,7 +191,7 @@ $if (_NTDDK_)
 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
 #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
 
-#define CONTEXT_XSTATE (CONTEXT_AMD64 | 0x20L)
+#define CONTEXT_XSTATE (CONTEXT_AMD64 | 0x40L)
 
 #define CONTEXT_EXCEPTION_ACTIVE 0x8000000
 #define CONTEXT_SERVICE_ACTIVE 0x10000000