Sync to trunk head(r38096)
authorSamuel Serapion <samuel.serapion@gmail.com>
Mon, 15 Dec 2008 04:14:26 +0000 (04:14 +0000)
committerSamuel Serapion <samuel.serapion@gmail.com>
Mon, 15 Dec 2008 04:14:26 +0000 (04:14 +0000)
svn path=/branches/ros-amd64-bringup/; revision=38097

1  2 
reactos/config-amd64.template.rbuild
reactos/dll/win32/advapi32/sec/misc.c
reactos/drivers/storage/scsiport/scsiport.c
reactos/include/ddk/ntimage.h
reactos/include/ddk/winddk.h
reactos/ntoskrnl/ex/sysinfo.c
reactos/ntoskrnl/include/internal/ke.h
reactos/ntoskrnl/mm/virtual.c

index 20d50aa,0000000..b8169d5
mode 100644,000000..100644
--- /dev/null
@@@ -1,86 -1,0 +1,86 @@@
- <property name="OPTIMIZE" value="3" />
 +<?xml version="1.0"?>
 +<!DOCTYPE group SYSTEM "tools/rbuild/project.dtd">
 +<group>
 +
 +<!--
 +      This file is a template used as a starting point for compile-time
 +      configuration of ReactOS. Make a copy of this file and name it config.rbuild.
 +      Then change the options in config.rbuild. If you don't have a config.rbuild file,
 +      then the defaults in this file, config.template.rbuild, will be used instead.
 +
 +      Boolean options can obtain the values 0 (disabled) or 1 (enabled). String
 +      options can obtain any value specified in the comment before it.
 +-->
 +
 +
 +<!--
 +      Sub-architecture to build for. Specify one of:
 +-->
 +<property name="SARCH" value="" />
 +
 +
 +<!--
 +      Which CPU ReactOS should be optimized for. Specify one of:
 +              k8 opteron athlon64 athlon-fx
 +
 +      See GCC manual for more CPU names and which CPUs GCC can optimize for.
 +-->
 +<property name="OARCH" value="athlon64" />
 +
 +
 +<!--
 +      What level of optimisation to use.
 +              0 = off (will not work)
 +              1 = Default option, optimize for size (-Os) with some additional options
 +              2 = -Os
 +              3 = -O1
 +              4 = -O2
 +              5 = -O3
 +-->
++<property name="OPTIMIZE" value="1" />
 +
 +
 +<!--
 +      Whether to compile in the integrated kernel debugger.
 +-->
 +<property name="KDBG" value="0" />
 +
 +
 +<!--
 +      Whether to compile for debugging. No compiler optimizations will be
 +      performed.
 +-->
 +<property name="DBG" value="1" />
 +
 +
 +<!--
 +      Whether to compile for debugging with GDB. If you don't use GDB, don't
 +      enable this.
 +-->
 +<property name="GDB" value="0" />
 +
 +
 +<!--
 +      Whether to compile apps/libs with features covered software patents or not.
 +      If you live in a country where software patents are valid/apply, don't
 +      enable this (except they/you purchased a license from the patent owner).
 +      This settings is disabled (0) by default.
 +-->
 +<property name="NSWPAT" value="1" />
 +
 +<!--
 +      Whether to compile with the KD protocol. This will disable support for KDBG
 +      as well as rossym and symbol lookups, and allow WinDBG to connect to ReactOS.
 +      This is currently not fully working, and requires kdcom from Windows 2003 or
 +      TinyKRNL. Booting into debug mode with this flag enabled will result in a
 +      failure to enter GUI mode. Do not enable unless you know what you're doing.
 +-->
 +<property name="_WINKD_" value="1" />
 +
 +<!--
 +      Whether to compile support for ELF files. Do not enable unless you know what
 +      you're doing.
 +-->
 +<property name="_ELF_" value="0" />
 +
 +</group>
@@@ -289,7 -289,7 +289,7 @@@ CheckNtMartaPresent(VOID
  {
      DWORD ErrorCode;
  
 -    if (InterlockedCompareExchangePointer(&NtMarta,
 +    if (InterlockedCompareExchangePointer((PVOID)&NtMarta,
                                            NULL,
                                            NULL) == NULL)
      {
          if (ErrorCode == ERROR_SUCCESS)
          {
              /* try change the NtMarta pointer */
 -            if (InterlockedCompareExchangePointer(&NtMarta,
 +            if (InterlockedCompareExchangePointer((PVOID)&NtMarta,
                                                    &NtMartaStatic,
                                                    NULL) != NULL)
              {
  VOID
  UnloadNtMarta(VOID)
  {
 -    if (InterlockedExchangePointer(&NtMarta,
 +    if (InterlockedExchangePointer((PVOID)&NtMarta,
                                     NULL) != NULL)
      {
          FreeLibrary(NtMartaStatic.hDllInstance);
@@@ -1424,7 -1424,6 +1424,6 @@@ LookupPrivilegeValueW(LPCWSTR SystemNam
        L"SeAssignPrimaryTokenPrivilege",
        L"SeLockMemoryPrivilege",
        L"SeIncreaseQuotaPrivilege",
-       L"SeUnsolicitedInputPrivilege",
        L"SeMachineAccountPrivilege",
        L"SeTcbPrivilege",
        L"SeSecurityPrivilege",
      {
        if (0 == wcsicmp(PrivName, DefaultPrivNames[Priv]))
          {
-           Luid->LowPart = Priv + 1;
+           Luid->LowPart = Priv + SE_MIN_WELL_KNOWN_PRIVILEGE;
            Luid->HighPart = 0;
            return TRUE;
          }
@@@ -552,7 -552,7 +552,7 @@@ ScsiPortGetDeviceBase(IN PVOID HwDevice
  
      /* i/o space */
      if (AddressSpace != 0)
 -        return((PVOID)TranslatedAddress.u.LowPart);
 +        return((PVOID)(ULONG_PTR)TranslatedAddress.QuadPart);
  
      MappedAddress = MmMapIoSpace(TranslatedAddress,
                                   NumberOfBytes,
@@@ -1223,8 -1223,8 +1223,8 @@@ CreatePortConfig
              PortConfig->AccessRanges = (PVOID)(PortConfig+1);
  
              /* Align to LONGLONG */
 -            PortConfig->AccessRanges = (PVOID)((ULONG)(PortConfig->AccessRanges) + 7);
 -            PortConfig->AccessRanges = (PVOID)((ULONG)(PortConfig->AccessRanges) & ~7);
 +            PortConfig->AccessRanges = (PVOID)((ULONG_PTR)(PortConfig->AccessRanges) + 7);
 +            PortConfig->AccessRanges = (PVOID)((ULONG_PTR)(PortConfig->AccessRanges) & ~7);
  
              /* Copy the data */
              RtlCopyMemory(PortConfig->AccessRanges,
@@@ -1733,7 -1733,7 +1733,7 @@@ SpiCleanupAfterInit(PSCSI_PORT_DEVICE_E
  
              LunInfo = DeviceExtension->BusesConfig->BusScanInfo[Bus]->LunInfo;
  
-             while (!LunInfo)
+             while (LunInfo)
              {
                  /* Free current, but save pointer to the next one */
                  Ptr = LunInfo->Next;
@@@ -1957,9 -1957,12 +1957,12 @@@ ScsiPortNotification(IN SCSI_NOTIFICATI
                                                TargetId,
                                                Lun);
  
+             /* If returned LunExtension is NULL, break out */
+             if (!LunExtension) break;
              /* This request should not be processed if */
-             if ((LunExtension && LunExtension->ReadyLun) ||
-                 (LunExtension && LunExtension->SrbInfo.Srb))
+             if ((LunExtension->ReadyLun) ||
+                 (LunExtension->SrbInfo.Srb))
              {
                  /* Nothing to do here */
                  break;
@@@ -2900,7 -2903,7 +2903,7 @@@ ScsiPortStartIo(IN PDEVICE_OBJECT Devic
          // Store the MDL virtual address in SrbInfo structure
          SrbInfo->DataOffset = MmGetMdlVirtualAddress(Irp->MdlAddress);
  
-         if (DeviceExtension->MapBuffers && Irp->MdlAddress)
+         if (DeviceExtension->MapBuffers)
          {
              /* Calculate offset within DataBuffer */
              SrbInfo->DataOffset = MmGetSystemAddressForMdl(Irp->MdlAddress);
@@@ -419,7 -419,17 +419,17 @@@ typedef PIMAGE_NT_HEADERS3
       ((NtHeader))->FileHeader.SizeOfOptionalHeader   \
      ))
  
+ //
+ // Dll Characteristics
+ //
+ #define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE          0x0040
+ #define IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY       0x0080
+ #define IMAGE_DLLCHARACTERISTICS_NX_COMPAT             0x0100
+ #define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION          0x0200
+ #define IMAGE_DLLCHARACTERISTICS_NO_SEH                0x0400
+ #define IMAGE_DLLCHARACTERISTICS_NO_BIND               0x0800
+ #define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER            0x2000
+ #define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
  
  //
  // Directory Entry Specifiers
@@@ -470,7 -480,7 +480,7 @@@ typedef struct _IMAGE_THUNK_DATA32 
      } u1;
  } IMAGE_THUNK_DATA32, *PIMAGE_THUNK_DATA32;
  
 -#define IMAGE_ORDINAL_FLAG64 0x8000000000000000
 +#define IMAGE_ORDINAL_FLAG64 0x8000000000000000ULL
  #define IMAGE_ORDINAL_FLAG32 0x80000000
  #define IMAGE_ORDINAL64(Ordinal) (Ordinal & 0xffff)
  #define IMAGE_ORDINAL32(Ordinal) (Ordinal & 0xffff)
@@@ -3122,10 -3122,10 +3122,10 @@@ typedef struct 
  } HAL_DISPATCH, *PHAL_DISPATCH;
  
  #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTHAL_)
- extern DECL_IMPORT PHAL_DISPATCH HalDispatchTable;
+ extern DECLSPEC_IMPORT PHAL_DISPATCH HalDispatchTable;
  #define HALDISPATCH ((PHAL_DISPATCH)&HalDispatchTable)
  #else
- extern DECL_EXPORT HAL_DISPATCH HalDispatchTable;
+ extern DECLSPEC_EXPORT HAL_DISPATCH HalDispatchTable;
  #define HALDISPATCH (&HalDispatchTable)
  #endif
  
@@@ -5612,154 -5612,8 +5612,154 @@@ KeGetCurrentThread
  
  #define KI_USER_SHARED_DATA               0xffdf0000
  
 +#define PAGE_SIZE                         0x1000
 +#define PAGE_SHIFT                        12L
 +
 +#define SharedUserData                    ((KUSER_SHARED_DATA * CONST) KI_USER_SHARED_DATA)
 +
 +extern NTKERNELAPI PVOID MmHighestUserAddress;
 +extern NTKERNELAPI PVOID MmSystemRangeStart;
 +extern NTKERNELAPI ULONG_PTR MmUserProbeAddress;
 +
 +#define MM_HIGHEST_USER_ADDRESS           MmHighestUserAddress
 +#define MM_SYSTEM_RANGE_START             MmSystemRangeStart
 +#define MM_USER_PROBE_ADDRESS             MmUserProbeAddress
 +#define MM_LOWEST_USER_ADDRESS            (PVOID)0x10000
 +#define MM_LOWEST_SYSTEM_ADDRESS          (PVOID)0xC0C00000
 +
 +#define MM_KSEG0_BASE       MM_SYSTEM_RANGE_START
 +#define MM_SYSTEM_SPACE_END 0xFFFFFFFF
 +
  #elif defined(__x86_64__)
  
 +#define CONTEXT_AMD64 0x100000
 +#if !defined(RC_INVOKED)
 +#define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
 +#define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
 +#define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
 +#define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L)
 +#define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
 +
 +#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_EXCEPTION_ACTIVE 0x8000000
 +#define CONTEXT_SERVICE_ACTIVE 0x10000000
 +#define CONTEXT_EXCEPTION_REQUEST 0x40000000
 +#define CONTEXT_EXCEPTION_REPORTING 0x80000000
 +#endif
 +
 +typedef struct DECLSPEC_ALIGN(16) _M128A {
 +    ULONGLONG Low;
 +    LONGLONG High;
 +} M128A, *PM128A;
 +
 +typedef struct _XMM_SAVE_AREA32 {
 +    USHORT ControlWord;
 +    USHORT StatusWord;
 +    UCHAR TagWord;
 +    UCHAR Reserved1;
 +    USHORT ErrorOpcode;
 +    ULONG ErrorOffset;
 +    USHORT ErrorSelector;
 +    USHORT Reserved2;
 +    ULONG DataOffset;
 +    USHORT DataSelector;
 +    USHORT Reserved3;
 +    ULONG MxCsr;
 +    ULONG MxCsr_Mask;
 +    M128A FloatRegisters[8];
 +    M128A XmmRegisters[16];
 +    UCHAR Reserved4[96];
 +} XMM_SAVE_AREA32, *PXMM_SAVE_AREA32;
 +
 +typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
 +    ULONG64 P1Home;
 +    ULONG64 P2Home;
 +    ULONG64 P3Home;
 +    ULONG64 P4Home;
 +    ULONG64 P5Home;
 +    ULONG64 P6Home;
 +
 +    /* Control flags */
 +    ULONG ContextFlags;
 +    ULONG MxCsr;
 +
 +    /* Segment */
 +    USHORT SegCs;
 +    USHORT SegDs;
 +    USHORT SegEs;
 +    USHORT SegFs;
 +    USHORT SegGs;
 +    USHORT SegSs;
 +    USHORT EFlags;
 +
 +    /* Debug */
 +    ULONG64 Dr0;
 +    ULONG64 Dr1;
 +    ULONG64 Dr2;
 +    ULONG64 Dr3;
 +    ULONG64 Dr6;
 +    ULONG64 Dr7;
 +
 +    /* Integer */
 +    ULONG64 Rax;
 +    ULONG64 Rcx;
 +    ULONG64 Rdx;
 +    ULONG64 Rbx;
 +    ULONG64 Rsp;
 +    ULONG64 Rbp;
 +    ULONG64 Rsi;
 +    ULONG64 Rdi;
 +    ULONG64 R8;
 +    ULONG64 R9;
 +    ULONG64 R10;
 +    ULONG64 R11;
 +    ULONG64 R12;
 +    ULONG64 R13;
 +    ULONG64 R14;
 +    ULONG64 R15;
 +
 +    /* Counter */
 +    ULONG64 Rip;
 +
 +   /* Floating point */
 +   union {
 +       XMM_SAVE_AREA32 FltSave;
 +       struct {
 +           M128A Header[2];
 +           M128A Legacy[8];
 +           M128A Xmm0;
 +           M128A Xmm1;
 +           M128A Xmm2;
 +           M128A Xmm3;
 +           M128A Xmm4;
 +           M128A Xmm5;
 +           M128A Xmm6;
 +           M128A Xmm7;
 +           M128A Xmm8;
 +           M128A Xmm9;
 +           M128A Xmm10;
 +           M128A Xmm11;
 +           M128A Xmm12;
 +           M128A Xmm13;
 +           M128A Xmm14;
 +           M128A Xmm15;
 +      } DUMMYSTRUCTNAME;
 +    } DUMMYUNIONNAME;
 +
 +     /* Vector */
 +    M128A VectorRegister[26];
 +    ULONG64 VectorControl;
 +
 +    /* Debug control */
 +    ULONG64 DebugControl;
 +    ULONG64 LastBranchToRip;
 +    ULONG64 LastBranchFromRip;
 +    ULONG64 LastExceptionToRip;
 +    ULONG64 LastExceptionFromRip;
 +} CONTEXT;
 +
  //
  // Types to use to contain PFNs and their counts.
  //
@@@ -5802,13 -5656,6 +5802,13 @@@ typedef LONG64 SPFN_NUMBER, *PSPFN_NUMB
  #define PDE_TOP     0xFFFFF6FB7FFFFFFFULL
  #define PTE_TOP     0xFFFFF6FFFFFFFFFFULL
  
 +extern NTKERNELAPI PVOID MmHighestUserAddress;
 +extern NTKERNELAPI PVOID MmSystemRangeStart;
 +extern NTKERNELAPI ULONG_PTR MmUserProbeAddress;
 +
 +#define MM_HIGHEST_USER_ADDRESS           MmHighestUserAddress
 +#define MM_SYSTEM_RANGE_START             MmSystemRangeStart
 +#define MM_USER_PROBE_ADDRESS             MmUserProbeAddress
  #define MM_LOWEST_USER_ADDRESS   (PVOID)0x10000
  #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xFFFF080000000000ULL
  #define KI_USER_SHARED_DATA       0xFFFFF78000000000ULL
@@@ -6010,6 -5857,25 +6010,6 @@@ KeGetCurrentProcessorNumber(VOID
  #error Unknown architecture
  #endif
  
 -#define PAGE_SIZE                         0x1000
 -#define PAGE_SHIFT                        12L
 -
 -#define SharedUserData                    ((KUSER_SHARED_DATA * CONST) KI_USER_SHARED_DATA)
 -
 -extern NTKERNELAPI PVOID MmHighestUserAddress;
 -extern NTKERNELAPI PVOID MmSystemRangeStart;
 -extern NTKERNELAPI ULONG_PTR MmUserProbeAddress;
 -
 -#define MM_HIGHEST_USER_ADDRESS           MmHighestUserAddress
 -#define MM_SYSTEM_RANGE_START             MmSystemRangeStart
 -#define MM_USER_PROBE_ADDRESS             MmUserProbeAddress
 -#define MM_LOWEST_USER_ADDRESS            (PVOID)0x10000
 -#define MM_LOWEST_SYSTEM_ADDRESS          (PVOID)0xC0C00000
 -
 -#define MM_KSEG0_BASE       MM_SYSTEM_RANGE_START
 -#define MM_SYSTEM_SPACE_END 0xFFFFFFFF
 -
 -
  #define EFLAG_SIGN                        0x8000
  #define EFLAG_ZERO                        0x4000
  #define EFLAG_SELECT                      (EFLAG_SIGN | EFLAG_ZERO)
@@@ -6174,15 -6040,15 +6174,15 @@@ InterlockedExchangeAdd
  #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  #define InterlockedExchangePointer _InterlockedExchangePointer
  
 -#define ExInterlockedPopEntrySList(Head, Lock) ExpInterlockedPopEntrySList(Head)
 -#define ExInterlockedPushEntrySList(Head, Entry, Lock) ExpInterlockedPushEntrySList(Head, Entry)
 -#define ExInterlockedFlushSList(Head) ExpInterlockedFlushSList(Head)
 +//#define ExInterlockedPopEntrySList(Head, Lock) ExpInterlockedPopEntrySList(Head)
 +//#define ExInterlockedPushEntrySList(Head, Entry, Lock) ExpInterlockedPushEntrySList(Head, Entry)
 +//#define ExInterlockedFlushSList(Head) ExpInterlockedFlushSList(Head)
  
  #if !defined(_WINBASE_)
  #define InterlockedPopEntrySList(Head) ExpInterlockedPopEntrySList(Head)
  #define InterlockedPushEntrySList(Head, Entry) ExpInterlockedPushEntrySList(Head, Entry)
 -#define InterlockedFlushSList(Head) ExpInterlockedFlushSList(Head)
 -#define QueryDepthSList(Head) ExQueryDepthSList(Head)
 +//#define InterlockedFlushSList(Head) ExpInterlockedFlushSList(Head)
 +//#define QueryDepthSList(Head) ExQueryDepthSList(Head)
  #endif // !defined(_WINBASE_)
  
  #endif // _M_AMD64
@@@ -6911,18 -6777,12 +6911,18 @@@ NTAP
  RtlFreeUnicodeString(
    IN PUNICODE_STRING  UnicodeString);
  
 +#if (defined(_M_AMD64) || defined(_M_IA64)) && !defined(_REALLY_GET_CALLERS_CALLER_)
 +#define RtlGetCallersAddress(CallersAddress, CallersCaller) \
 +    *CallersAddress = (PVOID)_ReturnAddress(); \
 +    *CallersCaller = NULL;
 +#else
  NTSYSAPI
  VOID
  NTAPI
  RtlGetCallersAddress(
    OUT PVOID  *CallersAddress,
    OUT PVOID  *CallersCaller);
 +#endif
  
  NTSYSAPI
  NTSTATUS
@@@ -9437,12 -9297,11 +9437,12 @@@ IoReuseIrp
   *   IN PIRP  Irp,
   *   IN PDRIVER_CANCEL  CancelRoutine)
   */
 -#define IoSetCancelRoutine( Irp, NewCancelRoutine ) (  \
 - (PDRIVER_CANCEL)InterlockedExchange( (PLONG)&(Irp)->CancelRoutine, (LONG)(NewCancelRoutine) ) )
 -    
 -    
 -    /*
 +#define IoSetCancelRoutine(_Irp, \
 +                           _CancelRoutine) \
 +  ((PDRIVER_CANCEL) InterlockedExchangePointer( \
 +    (PVOID *) &(_Irp)->CancelRoutine, (PVOID) (_CancelRoutine)))
 +
 +/*
   * VOID
   * IoSetCompletionRoutine(
   *   IN PIRP  Irp,
  KeQueryPriorityThread(
    IN PRKTHREAD  Thread);
  
+ NTKERNELAPI
+ ULONG
+ NTAPI
+ KeQueryRuntimeThread(
+   IN PKTHREAD Thread,
+   OUT PULONG UserTime);
  #if !defined(_M_AMD64)
  NTKERNELAPI
  ULONGLONG
@@@ -538,6 -538,7 +538,7 @@@ QSI_DEF(SystemProcessorInformation
  /* Class 2 - Performance Information */
  QSI_DEF(SystemPerformanceInformation)
  {
+       ULONG IdleUser, IdleKernel;
        PSYSTEM_PERFORMANCE_INFORMATION Spi
                = (PSYSTEM_PERFORMANCE_INFORMATION) Buffer;
  
  
        TheIdleProcess = PsIdleProcess;
  
-       Spi->IdleProcessTime.QuadPart = TheIdleProcess->Pcb.KernelTime * 100000LL;
+       IdleKernel = KeQueryRuntimeProcess(&TheIdleProcess->Pcb, &IdleUser);
+       Spi->IdleProcessTime.QuadPart = UInt32x32To64(IdleKernel, KeMaximumIncrement);
        Spi->IoReadTransferCount = IoReadTransferCount;
        Spi->IoWriteTransferCount = IoWriteTransferCount;
        Spi->IoOtherTransferCount = IoOtherTransferCount;
@@@ -699,7 -700,8 +700,8 @@@ QSI_DEF(SystemProcessInformation
  {
        ULONG ovlSize = 0, nThreads;
        PEPROCESS pr = NULL, syspr;
-       unsigned char *pCur;
+       PUCHAR pCur;
+       ULONG TotalUser, TotalKernel;
        NTSTATUS Status = STATUS_SUCCESS;
  
        _SEH2_TRY
                        SpiCur->NextEntryOffset = curSize+inLen; // relative offset to the beginnnig of the next structure
                        SpiCur->NumberOfThreads = nThreads;
                        SpiCur->CreateTime = pr->CreateTime;
-                       SpiCur->UserTime.QuadPart = pr->Pcb.UserTime * 100000LL;
-                       SpiCur->KernelTime.QuadPart = pr->Pcb.KernelTime * 100000LL;
                        SpiCur->ImageName.Length = strlen(pr->ImageFileName) * sizeof(WCHAR);
                        SpiCur->ImageName.MaximumLength = (USHORT)inLen;
                        SpiCur->ImageName.Buffer = (void*)(pCur+curSize);
                                current = CONTAINING_RECORD(current_entry, ETHREAD,
                                                            ThreadListEntry);
  
-                               ThreadInfo->KernelTime.QuadPart = current->Tcb.KernelTime * 100000LL;
-                               ThreadInfo->UserTime.QuadPart = current->Tcb.UserTime * 100000LL;
+                               ThreadInfo->KernelTime.QuadPart = UInt32x32To64(current->Tcb.KernelTime, KeMaximumIncrement);
+                               ThreadInfo->UserTime.QuadPart = UInt32x32To64(current->Tcb.UserTime, KeMaximumIncrement);
                                ThreadInfo->CreateTime.QuadPart = current->CreateTime.QuadPart;
                                ThreadInfo->WaitTime = current->Tcb.WaitTime;
                                ThreadInfo->StartAddress = (PVOID) current->StartAddress;
                                ThreadInfo->ContextSwitches = current->Tcb.ContextSwitches;
                                ThreadInfo->ThreadState = current->Tcb.State;
                                ThreadInfo->WaitReason = current->Tcb.WaitReason;
                                ThreadInfo++;
                                current_entry = current_entry->Flink;
                        }
  
+                       /* Query total user/kernel times of a process */
+                       TotalKernel = KeQueryRuntimeProcess(&pr->Pcb, &TotalUser);
+                       SpiCur->UserTime.QuadPart = UInt32x32To64(TotalUser, KeMaximumIncrement);
+                       SpiCur->KernelTime.QuadPart = UInt32x32To64(TotalKernel, KeMaximumIncrement);
                        /* Handle idle process entry */
                        if (pr == PsIdleProcess) pr = NULL;
  
@@@ -882,37 -888,39 +888,39 @@@ QSI_DEF(SystemDeviceInformation
  /* Class 8 - Processor Performance Information */
  QSI_DEF(SystemProcessorPerformanceInformation)
  {
-       PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION Spi
-               = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) Buffer;
+     PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION Spi
+         = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) Buffer;
  
-         LONG i;
-       LARGE_INTEGER CurrentTime;
-       PKPRCB Prcb;
+     LONG i;
+     ULONG TotalTime;
+     LARGE_INTEGER CurrentTime;
+     PKPRCB Prcb;
  
-       *ReqSize = KeNumberProcessors * sizeof (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
-       /*
-        * Check user buffer's size
-        */
-       if (Size < KeNumberProcessors * sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION))
-       {
-               return (STATUS_INFO_LENGTH_MISMATCH);
-       }
+     *ReqSize = KeNumberProcessors * sizeof (SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
  
-       CurrentTime.QuadPart = KeQueryInterruptTime();
-       Prcb = KeGetCurrentPrcb();
-       for (i = 0; i < KeNumberProcessors; i++)
-       {
-          Spi->IdleTime.QuadPart = (Prcb->IdleThread->KernelTime + Prcb->IdleThread->UserTime) * 100000LL;
-            Spi->KernelTime.QuadPart =  Prcb->KernelTime * 100000LL;
-            Spi->UserTime.QuadPart = Prcb->UserTime * 100000LL;
-            Spi->DpcTime.QuadPart = Prcb->DpcTime * 100000LL;
-            Spi->InterruptTime.QuadPart = Prcb->InterruptTime * 100000LL;
-            Spi->InterruptCount = Prcb->InterruptCount;
-          Spi++;
-          Prcb = (PKPRCB)((ULONG_PTR)Prcb + PAGE_SIZE);
-       }
+     /* Check user buffer's size */
+     if (Size < *ReqSize)
+     {
+         return STATUS_INFO_LENGTH_MISMATCH;
+     }
  
-       return (STATUS_SUCCESS);
+     CurrentTime.QuadPart = KeQueryInterruptTime();
+     Prcb = KeGetPcr()->Prcb;
+     for (i = 0; i < KeNumberProcessors; i++)
+     {
+         /* Calculate total user and kernel times */
+         TotalTime = Prcb->IdleThread->KernelTime + Prcb->IdleThread->UserTime;
+         Spi->IdleTime.QuadPart = UInt32x32To64(TotalTime, KeMaximumIncrement);
+         Spi->KernelTime.QuadPart =  UInt32x32To64(Prcb->KernelTime, KeMaximumIncrement);
+         Spi->UserTime.QuadPart = UInt32x32To64(Prcb->UserTime, KeMaximumIncrement);
+         Spi->DpcTime.QuadPart = UInt32x32To64(Prcb->DpcTime, KeMaximumIncrement);
+         Spi->InterruptTime.QuadPart = UInt32x32To64(Prcb->InterruptTime, KeMaximumIncrement);
+         Spi->InterruptCount = Prcb->InterruptCount;
+         Spi++;
+         Prcb = (PKPRCB)((ULONG_PTR)Prcb + PAGE_SIZE);
+     }
+     return STATUS_SUCCESS;
  }
  
  /* Class 9 - Flags Information */
@@@ -1055,7 -1063,7 +1063,7 @@@ QSI_DEF(SystemHandleInformation
  
              for (Count = 0; HandleCount > 0 ; HandleCount--)
                 {
 -                 Shi->Handles[i].UniqueProcessId = (USHORT)(ULONG)pr->UniqueProcessId;
 +                 Shi->Handles[i].UniqueProcessId = (USHORT)(ULONG_PTR)pr->UniqueProcessId;
                   Count++;
                   i++;
                 }
@@@ -1195,11 -1203,7 +1203,11 @@@ QSI_DEF(SystemInterruptInformation
    for (i = 0; i < KeNumberProcessors; i++)
    {
      Prcb = KiProcessorBlock[i];
 +#ifdef _M_AMD64
 +    Pcr = CONTAINING_RECORD(Prcb, KPCR, CurrentPrcb);
 +#else
      Pcr = CONTAINING_RECORD(Prcb, KPCR, Prcb);
 +#endif
  #ifdef _M_ARM // This code should probably be done differently
      sii->ContextSwitches = Pcr->ContextSwitches;
  #else
@@@ -1937,9 -1941,6 +1945,9 @@@ NtFlushInstructionCache 
      for (;;);
  #elif defined(_M_ARM)
      __asm__ __volatile__("mov r1, #0; mcr p15, 0, r1, c7, c5, 0");
 +#elif defined(_M_AMD64)
 +    DPRINT1("NtFlushInstructionCache() is not implemented\n");
 +    for (;;);
  #else
  #error Unknown architecture
  #endif
@@@ -1954,4 -1955,4 +1962,4 @@@ NtGetCurrentProcessorNumber(VOID
      return KeGetCurrentProcessorNumber();
  }
  
--/* EOF */
++/* EOF */
@@@ -105,7 -105,7 +105,7 @@@ extern PULONG KiInterruptTemplateObject
  extern PULONG KiInterruptTemplateDispatch;
  extern PULONG KiInterruptTemplate2ndDispatch;
  extern ULONG KiUnexpectedEntrySize;
 -#ifdef _M_IX86
 +#if defined(_M_IX86) || defined(_M_AMD64)
  extern PVOID Ki386IopmSaveArea;
  extern ULONG KeI386EFlagsAndMaskV86;
  extern ULONG KeI386EFlagsOrMaskV86;
@@@ -192,7 -192,7 +192,7 @@@ extern ULONG KiDPCTimeout
  /* INTERNAL KERNEL FUNCTIONS ************************************************/
  
  /* Finds a new thread to run */
 -NTSTATUS
 +LONG_PTR
  FASTCALL
  KiSwapThread(
      IN PKTHREAD Thread,
@@@ -565,7 -565,7 +565,7 @@@ VOI
  FASTCALL
  KiUnwaitThread(
      IN PKTHREAD Thread,
 -    IN NTSTATUS WaitStatus,
 +    IN LONG_PTR WaitStatus,
      IN KPRIORITY Increment
  );
  
@@@ -716,6 -716,11 +716,11 @@@ VOI
  FASTCALL
  KiActivateWaiterQueue(IN PKQUEUE Queue);
  
+ ULONG
+ NTAPI
+ KeQueryRuntimeProcess(IN PKPROCESS Process,
+                       OUT PULONG UserTime);
  /* INITIALIZATION FUNCTIONS *************************************************/
  
  BOOLEAN
@@@ -807,7 -812,7 +812,7 @@@ KeInvalidAccessAllowed(IN PVOID TrapInf
  VOID
  NTAPI
  KeRosDumpStackFrames(
 -    PULONG Frame,
 +    PULONG_PTR Frame,
      ULONG FrameCount
  );
  
@@@ -1047,18 -1052,6 +1052,18 @@@ KiIdleLoop
      VOID
  );
  
 +PVOID
 +NTAPI
 +KiPcToFileHeader(IN PVOID Eip,
 +                 OUT PLDR_DATA_TABLE_ENTRY *LdrEntry,
 +                 IN BOOLEAN DriversOnly,
 +                 OUT PBOOLEAN InKernel);
 +
 +PVOID
 +NTAPI
 +KiRosPcToUserFileHeader(IN PVOID Eip,
 +                        OUT PLDR_DATA_TABLE_ENTRY *LdrEntry);
 +
  #include "ke_x.h"
  
  #endif /* __NTOSKRNL_INCLUDE_INTERNAL_KE_H */
@@@ -65,9 -65,9 +65,9 @@@ MiDoMappedCopy(IN PEPROCESS SourceProce
      PMDL Mdl = (PMDL)MdlBuffer;
      SIZE_T TotalSize, CurrentSize, RemainingSize;
      volatile BOOLEAN FailedInProbe = FALSE, FailedInMapping = FALSE, FailedInMoving;
-     BOOLEAN PagesLocked;
+     volatile BOOLEAN PagesLocked;
      PVOID CurrentAddress = SourceAddress, CurrentTargetAddress = TargetAddress;
-     PVOID MdlAddress;
+     volatile PVOID MdlAddress;
      KAPC_STATE ApcState;
      BOOLEAN HaveBadAddress;
      ULONG_PTR BadAddress;
@@@ -758,7 -758,7 +758,7 @@@ NtWriteVirtualMemory(IN HANDLE ProcessH
      KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
      PEPROCESS Process;
      NTSTATUS Status = STATUS_SUCCESS;
 -    ULONG BytesWritten = 0;
 +    SIZE_T BytesWritten = 0;
      PAGED_CODE();
  
      /* Check if we came from user mode */