sync to trunk head (35945)
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Fri, 5 Sep 2008 00:03:53 +0000 (00:03 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Fri, 5 Sep 2008 00:03:53 +0000 (00:03 +0000)
svn path=/branches/ros-amd64-bringup/; revision=35954

72 files changed:
1  2 
reactos/base/applications/calc/winmain.c
reactos/base/applications/network/ping/ping.c
reactos/base/applications/network/tracert/tracert.c
reactos/base/services/tcpsvcs/chargen.c
reactos/base/services/tcpsvcs/daytime.c
reactos/base/services/tcpsvcs/discard.c
reactos/base/services/tcpsvcs/echo.c
reactos/base/services/tcpsvcs/qotd.c
reactos/base/services/tcpsvcs/skelserver.c
reactos/boot/bootdata/packages/reactos.dff
reactos/boot/bootdata/txtsetup.sif
reactos/boot/freeldr/freeldr/bootmgr.c
reactos/boot/freeldr/freeldr/disk/ramdisk.c
reactos/boot/freeldr/freeldr/include/freeldr.h
reactos/boot/freeldr/freeldr/reactos/reactos.c
reactos/dll/ntdll/def/ntdll_arm.def
reactos/dll/win32/advapi32/service/scm.c
reactos/dll/win32/kernel32/misc/stubs.c
reactos/dll/win32/shell32/autocomplete.c
reactos/dll/win32/shell32/changenotify.c
reactos/drivers/network/afd/afd/listen.c
reactos/drivers/network/afd/afd/lock.c
reactos/drivers/network/afd/afd/main.c
reactos/drivers/network/ndis/ndis/io.c
reactos/drivers/network/tcpip/tcpip/dispatch.c
reactos/drivers/storage/ide/pciidex/pciidex.rbuild
reactos/drivers/storage/port/diskdump/diskdump.c
reactos/hal/hal/hal.c
reactos/hal/halx86/mp/apic.c
reactos/include/ddk/winddk.h
reactos/include/ndk/ketypes.h
reactos/include/psdk/winnt.h
reactos/include/psdk/winuser.h
reactos/include/reactos/libs/pseh/framebased.h
reactos/lib/drivers/oskittcp/include/freebsd/src/sys/sys/types.h
reactos/lib/sdk/crt/crt.rbuild
reactos/lib/sdk/crt/stdio/lnx_sprintf.c
reactos/ntoskrnl/config/cmkcbncb.c
reactos/ntoskrnl/ex/handle.c
reactos/ntoskrnl/ex/init.c
reactos/ntoskrnl/ex/sysinfo.c
reactos/ntoskrnl/include/internal/ex.h
reactos/ntoskrnl/include/internal/mm.h
reactos/ntoskrnl/include/internal/ntoskrnl.h
reactos/ntoskrnl/kdbg/amd64/kdb.c
reactos/ntoskrnl/kdbg/kdb.c
reactos/ntoskrnl/ke/amd64/spinlock.c
reactos/ntoskrnl/ke/bug.c
reactos/ntoskrnl/ke/clock.c
reactos/ntoskrnl/ke/freeldr.c
reactos/ntoskrnl/ke/spinlock.c
reactos/ntoskrnl/mm/amd64/page.c
reactos/ntoskrnl/mm/cont.c
reactos/ntoskrnl/mm/i386/page.c
reactos/ntoskrnl/mm/iospace.c
reactos/ntoskrnl/mm/mdlsup.c
reactos/ntoskrnl/mm/mm.c
reactos/ntoskrnl/mm/mminit.c
reactos/ntoskrnl/mm/ncache.c
reactos/ntoskrnl/mm/pool.c
reactos/ntoskrnl/mm/procsup.c
reactos/ntoskrnl/mm/region.c
reactos/ntoskrnl/mm/section.c
reactos/ntoskrnl/mm/sysldr.c
reactos/ntoskrnl/ntoskrnl-amd64hack.rbuild
reactos/ntoskrnl/ps/kill.c
reactos/ntoskrnl/rtl/libsupp.c
reactos/ntoskrnl/se/audit.c
reactos/subsystems/win32/win32k/eng/engwindow.c
reactos/subsystems/win32/win32k/ntuser/hook.c
reactos/subsystems/win32/win32k/ntuser/kbdlayout.c
reactos/subsystems/win32/win32k/ntuser/menu.c

@@@ -784,68 -784,18 +784,18 @@@ static void delete_stat_item(int n
  
  static char *ReadConversion(const char *formula)
  {
-     unsigned int  len = 256, n;
-     char         *str;
-     char         *code = NULL;
-     const char   *p = formula;
-     char          c;
-     calc_number_t x;
-     TCHAR         buffer[SIZEOF(calc.buffer)];
- #ifdef UNICODE
-     char          cbuffer[SIZEOF(calc.buffer)];
- #endif
+     int len = strlen(formula);
+     char *str = (char *)malloc(len+3);
  
-     str = (char *)malloc(len);
      if (str == NULL)
          return NULL;
  
-     /* prepare code string */
-     rpn_alloc(&x);
-     convert_text2number(&x);
-     prepare_rpn_result(&x,
-                    buffer, SIZEOF(buffer),
-                    calc.base);
-     rpn_free(&x);
- #ifdef UNICODE
-     WideCharToMultiByte(CP_ACP, 0, buffer, -1, cbuffer, SIZEOF(cbuffer), NULL, NULL);
- #endif
      str[0] = '(';
-     n = 1;
-     while (1) {
-         if (code != NULL) {
-             c = *code++;
-             if (*code == '\0')
-                 code = NULL;
-         } else
-             c = *p++;
-         if (c == '\0') {
-             str[n++] = ')';
-             if (n >= len-1) {
-                 str = (char *)realloc(str, len += 16);
-                 if (str == NULL)
-                     return NULL;
-             }
-             break;
-         } else
-         if (c == '$') {
- #ifdef UNICODE
-             code = cbuffer;
- #else
-             code = buffer;
- #endif
-             continue;
-         }
-         str[n++] = c;
-         if (n >= len-1) {
-             str = (char *)realloc(str, len += 16);
-             if (str == NULL)
-                 return NULL;
-         }
-     }
-     str[n] = '\0';
+     memcpy(str+1, formula, len);
+     str[len+1] = ')';
+     str[len+2] = '\0';
+     _tcscpy(calc.source, (*calc.buffer == _T('\0')) ? _T("0") : calc.buffer);
  
      /* clear display content before proceeding */
      calc.ptr = calc.buffer;
      return str;
  }
  
 -static LRESULT CALLBACK DlgStatProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
 +static INT_PTR CALLBACK DlgStatProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
  {
      TCHAR buffer[SIZEOF(calc.buffer)];
      DWORD n;
@@@ -991,6 -941,11 +941,11 @@@ static char *handle_sequence_input(HWN
          case 'Q': PostMessage(hwnd, WM_COMMAND, (WPARAM)IDC_BUTTON_CANC, 0); break;
          case 'R': PostMessage(hwnd, WM_COMMAND, (WPARAM)IDC_BUTTON_MR, 0); break;
          }
+     } else
+     if (ch == '$') {
+         calc.ptr =
+         _tcscpy(calc.buffer, calc.source) +
+         _tcslen(calc.source);
      } else {
          for (x=0; x<SIZEOF(key2code); x++) {
              if (!(key2code[x].mask & BITMASK_IS_ASCII) ||
@@@ -1224,7 -1179,7 +1179,7 @@@ static LRESULT CALLBACK SubclassButtonP
      return 1L;
  }
  
 -static LRESULT CALLBACK DlgMainProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
 +static INT_PTR CALLBACK DlgMainProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
  {
      unsigned int x;
      RECT         rc;
              if (IsWindow(calc.hStatWnd))
                  break;
              calc.hStatWnd = CreateDialog(calc.hInstance,
 -                                    MAKEINTRESOURCE(IDD_DIALOG_STAT), hWnd, (DLGPROC)DlgStatProc);
 +                                    MAKEINTRESOURCE(IDD_DIALOG_STAT), hWnd, DlgStatProc);
              if (calc.hStatWnd != NULL) {
                  enable_allowed_controls(hWnd, calc.base);
                  SendMessage(calc.hStatWnd, WM_SETFOCUS, 0, 0);
          }
          return TRUE;
      case WM_HANDLE_FROM:
-         if (handle_sequence_input(hWnd, &calc.Convert[0]) == NULL) {
+         if (calc.is_nan)
+             break;
+         if (handle_sequence_input(hWnd, &calc.Convert[0]) == NULL)
              PostMessage(hWnd, WM_START_CONV, 0,
                          MAKELPARAM(0x0001, WM_HANDLE_TO));
-         }
          return TRUE;
      case WM_HANDLE_TO:
-         handle_sequence_input(hWnd, &calc.Convert[1]);
+         if (!calc.is_nan)
+             handle_sequence_input(hWnd, &calc.Convert[1]);
          return TRUE;
      case WM_CLOSE:
          calc.action = IDC_STATIC;
      return FALSE;
  }
  
+ #if defined(__GNUC__) && !defined(__REACTOS__)
+ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
+ #else
  int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd)
+ #endif
  {
      MSG msg;
      DWORD dwLayout;
          else
              dwLayout = IDD_DIALOG_STANDARD;
  
-         CreateDialog(hInstance, MAKEINTRESOURCE(dwLayout), NULL, DlgMainProc);
+         /* This call will always fail if UNICODE for Win9x */
+         if (NULL == CreateDialog(hInstance, MAKEINTRESOURCE(dwLayout), NULL, (DLGPROC)DlgMainProc))
+             break;
  
          while (GetMessage(&msg, NULL, 0, 0)) {
  #ifndef USE_KEYBOARD_HOOK
@@@ -233,7 -233,7 +233,7 @@@ static BOOL ParseCmdline(int argc, char
                      DataSize = GetULONG2(&argv[i][2], argv[i + 1], &i);
                      if (DataSize > ICMP_MAXSIZE - sizeof(ICMP_ECHO_PACKET))
                      {
 -                        printf("Bad value for option -l, valid range is from 0 to %d.\n",
 +                        printf("Bad value for option -l, valid range is from 0 to %I64d.\n",
                              ICMP_MAXSIZE - sizeof(ICMP_ECHO_PACKET));
                          return FALSE;
                     }
@@@ -466,7 -466,7 +466,7 @@@ static BOOL DecodeResponse(PCHAR buffer
      }
  
  
 -    printf("Reply from %s: bytes=%d time%s%s TTL=%d\n", inet_ntoa(from->sin_addr),
 +    printf("Reply from %s: bytes=%I64d time%s%s TTL=%d\n", inet_ntoa(from->sin_addr),
        size - IphLength - sizeof(ICMP_ECHO_PACKET), Sign, Time, IpHeader->TTL);
      if (RelativeTime.QuadPart < MinRTT.QuadPart || !MinRTTSet)
      {
@@@ -541,6 -541,7 +541,7 @@@ static BOOL Ping(VOID
      }
      if (Status == SOCKET_ERROR)
      {
+         LostCount++;
          if (WSAGetLastError() == WSAEHOSTUNREACH)
              printf("Destination host unreachable.\n");
          else
          printf("\n");
  #endif /* !NDEBUG */
      }
+     else
+         LostCount++;
      if (Status == SOCKET_ERROR)
      {
          if (WSAGetLastError() != WSAETIMEDOUT)
      if (Status == 0)
      {
          printf("Request timed out.\n");
-         LostCount++;
          GlobalFree(Buffer);
          return TRUE;
      }
@@@ -644,9 -646,13 +646,13 @@@ int main(int argc, char* argv[]
          printf("\nPing statistics for %s:\n", TargetIP);
          printf("    Packets: Sent = %d, Received = %d, Lost = %d (%d%% loss),\n",
              SentCount, SentCount - LostCount, LostCount, Count);
-         printf("Approximate round trip times in milli-seconds:\n");
-         printf("    Minimum = %s, Maximum = %s, Average = %s\n",
-             MinTime, MaxTime, AvgTime);
+         /* Print approximate times or NO approximate times if 100% loss */
+         if ((SentCount - LostCount) > 0)
+         {
+             printf("Approximate round trip times in milli-seconds:\n");
+             printf("    Minimum = %s, Maximum = %s, Average = %s\n",
+                 MinTime, MaxTime, AvgTime);
+         }
      }
      return 0;
  }
@@@ -396,11 -396,7 +396,7 @@@ DecodeResponse(PAPPINFO pInfo
                      DebugPrint(_T("Rouge packet: header id,  process id  %d"), TTLExceedHdr->OrigIcmpHeader.id, GetCurrentProcessId());
                      return -1;
                  }
- #ifndef _WIN64
 -                _tprintf(_T("%3Ld ms"), (pInfo->lTimeEnd - pInfo->lTimeStart) / pInfo->TicksPerMs.QuadPart);
 +                _tprintf(_T("%3lld ms"), (pInfo->lTimeEnd - pInfo->lTimeStart) / pInfo->TicksPerMs.QuadPart);
- #else
-                 _tprintf(_T("%3I64d ms"), (pInfo->lTimeEnd - pInfo->lTimeStart) / pInfo->TicksPerMs.QuadPart);
- #endif
                  return 0;
  
             case ECHO_REPLY :
                      DebugPrint(_T("Rouge packet: header id %d, process id  %d"), IcmpHdr->icmpheader.id, GetCurrentProcessId());
                      return -1;
                  }
- #ifndef _WIN64
 -                _tprintf(_T("%3Ld ms"), (pInfo->lTimeEnd - pInfo->lTimeStart) / pInfo->TicksPerMs.QuadPart);
 +                _tprintf(_T("%3lld ms"), (pInfo->lTimeEnd - pInfo->lTimeStart) / pInfo->TicksPerMs.QuadPart);
- #else
-                 _tprintf(_T("%3I64d ms"), (pInfo->lTimeEnd - pInfo->lTimeStart) / pInfo->TicksPerMs.QuadPart);
- #endif
                  return 1;
  
             case DEST_UNREACHABLE :
@@@ -32,16 -32,16 +32,16 @@@ SendLine(SOCKET sock, LPSTR lpLine
          }
          else
          {
-             LogEvent(_T("Chargen: Not sent enough bytes"), 0, 0, LOG_FILE);
+             LogEvent(L"Chargen: Not sent enough bytes", 0, 0, LOG_FILE);
          }
      }
      else if (retVal == SOCKET_ERROR)
      {
-         LogEvent(_T("Chargen: Socket error\n"), WSAGetLastError(), 0, LOG_ERROR);
+         LogEvent(L"Chargen: Socket error\n", WSAGetLastError(), 0, LOG_ERROR);
      }
      else
      {
-         LogEvent(_T("Chargen: unknown error\n"), WSAGetLastError(), 0, LOG_ERROR);
+         LogEvent(L"Chargen: unknown error\n", WSAGetLastError(), 0, LOG_ERROR);
      }
  
      return bRet;;
@@@ -96,25 -96,25 +96,25 @@@ DWORD WINAP
  ChargenHandler(VOID* sock_)
  {
      INT retVal = 0;
 -    SOCKET sock = (SOCKET)sock_;
 +    SOCKET sock = (SOCKET)(UINT_PTR)sock_;
  
      if (!GenerateChars(sock))
      {
-         LogEvent(_T("Chargen: Char generation failed"), 0, 0, LOG_FILE);
+         LogEvent(L"Chargen: Char generation failed", 0, 0, LOG_FILE);
          retVal = 1;
      }
  
-     LogEvent(_T("Chargen: Shutting connection down..."), 0, 0, LOG_FILE);
+     LogEvent(L"Chargen: Shutting connection down...", 0, 0, LOG_FILE);
      if (ShutdownConnection(sock, FALSE))
      {
-         LogEvent(_T("Chargen: Connection is down"), 0, 0, LOG_FILE);
+         LogEvent(L"Chargen: Connection is down", 0, 0, LOG_FILE);
      }
      else
      {
-         LogEvent(_T("Chargen: Connection shutdown failed"), 0, 0, LOG_FILE);
+         LogEvent(L"Chargen: Connection shutdown failed", 0, 0, LOG_FILE);
          retVal = 1;
      }
  
-     LogEvent(_T("Chargen: Terminating thread"), 0, 0, LOG_FILE);
+     LogEvent(L"Chargen: Terminating thread", 0, 0, LOG_FILE);
      ExitThread(retVal);
  }
@@@ -15,7 -15,7 +15,7 @@@ SendTime(SOCKET sock, CHAR *time
      DWORD stringSize = strlen(time) + 1;
      if (send(sock, time, stringSize, 0) == SOCKET_ERROR)
      {
-         LogEvent(_T("DayTime: Error sending data"), WSAGetLastError(), 0, LOG_ERROR);
+         LogEvent(L"DayTime: Error sending data", WSAGetLastError(), 0, LOG_ERROR);
          return FALSE;
      }
  
@@@ -30,7 -30,7 +30,7 @@@ DaytimeHandler(VOID* Sock_
      time_t aclock;
      CHAR *pszTime;
      DWORD retVal = 0;
 -    SOCKET Sock = (SOCKET)Sock_;
 +    SOCKET Sock = (SOCKET)(UINT_PTR)Sock_;
  
      time(&aclock);
      localTime = localtime(&aclock);
              retVal = 1;
      }
  
-     LogEvent(_T("DayTime: Shutting connection down"), 0, 0, LOG_FILE);
+     LogEvent(L"DayTime: Shutting connection down", 0, 0, LOG_FILE);
      if (ShutdownConnection(Sock, FALSE))
-         LogEvent(_T("DayTime: Connection is down"), 0, 0, LOG_FILE);
+         LogEvent(L"DayTime: Connection is down", 0, 0, LOG_FILE);
      else
      {
-         LogEvent(_T("DayTime: Connection shutdown failed"), 0, 0, LOG_FILE);
+         LogEvent(L"DayTime: Connection shutdown failed", 0, 0, LOG_FILE);
          retVal = 1;
      }
  
-     LogEvent(_T("DayTime: Terminating thread"), 0, 0, LOG_FILE);
+     LogEvent(L"DayTime: Terminating thread", 0, 0, LOG_FILE);
      ExitThread(retVal);
  }
@@@ -14,7 -14,7 +14,7 @@@
  static BOOL
  RecieveIncomingPackets(SOCKET sock)
  {
-     char readBuffer[BUFSIZE];
+     CHAR readBuffer[BUFSIZE];
      INT readBytes;
  
      do
          {
              TCHAR logBuf[256];
  
-             _stprintf(logBuf, _T("Discard: Received %d bytes from client"), readBytes);
+             _swprintf(logBuf, L"Discard: Received %d bytes from client", readBytes);
              LogEvent(logBuf, 0, 0, LOG_FILE);
          }
          else if (readBytes == SOCKET_ERROR)
          {
-             LogEvent(_T("Discard: Socket Error"), WSAGetLastError(), 0, LOG_ERROR);
+             LogEvent(L"Discard: Socket Error", WSAGetLastError(), 0, LOG_ERROR);
              return FALSE;
          }
      } while ((readBytes > 0) && (!bShutdown));
  
      if (!bShutdown)
-         LogEvent(_T("Discard: Connection closed by peer"), 0, 0, LOG_FILE);
+         LogEvent(L"Discard: Connection closed by peer", 0, 0, LOG_FILE);
  
      return TRUE;
  }
@@@ -44,25 -44,25 +44,25 @@@ DWORD WINAP
  DiscardHandler(VOID* sock_)
  {
      DWORD retVal = 0;
 -    SOCKET sock = (SOCKET)sock_;
 +    SOCKET sock = (SOCKET)(UINT_PTR)sock_;
  
      if (!RecieveIncomingPackets(sock))
      {
-         LogEvent(_T("Discard: RecieveIncomingPackets failed"), 0, 0, LOG_FILE);
+         LogEvent(L"Discard: RecieveIncomingPackets failed", 0, 0, LOG_FILE);
          retVal = 1;
      }
  
-     LogEvent(_T("Discard: Shutting connection down"), 0, 0, LOG_FILE);
+     LogEvent(L"Discard: Shutting connection down", 0, 0, LOG_FILE);
      if (ShutdownConnection(sock, TRUE))
      {
-         LogEvent(_T("Discard: Connection is down."), 0, 0, LOG_FILE);
+         LogEvent(L"Discard: Connection is down.", 0, 0, LOG_FILE);
      }
      else
      {
-         LogEvent(_T("Discard: Connection shutdown failed"), 0, 0, LOG_FILE);
+         LogEvent(L"Discard: Connection shutdown failed", 0, 0, LOG_FILE);
          retVal = 1;
      }
  
-     LogEvent(_T("Discard: Terminating thread"), 0, 0, LOG_FILE);
+     LogEvent(L"Discard: Terminating thread", 0, 0, LOG_FILE);
      ExitThread(retVal);
  }
@@@ -15,7 -15,7 +15,7 @@@ static BOO
  EchoIncomingPackets(SOCKET sock)
  {
      CHAR readBuffer[RECV_BUF];
-     TCHAR logBuf[256];
+     WCHAR logBuf[256];
      INT totalSentBytes;
      INT readBytes;
      INT retVal;
@@@ -25,7 -25,7 +25,7 @@@
          readBytes = recv(sock, readBuffer, RECV_BUF, 0);
          if (readBytes > 0)
          {
-             _stprintf(logBuf, _T("Received %d bytes from client"), readBytes);
+             _swprintf(logBuf, L"Received %d bytes from client", readBytes);
              LogEvent(logBuf, 0, 0, LOG_FILE);
  
              totalSentBytes = 0;
                  retVal = send(sock, readBuffer + totalSentBytes, readBytes - totalSentBytes, 0);
                  if (retVal > 0)
                  {
-                     _stprintf(logBuf, _T("Sent %d bytes back to client"), retVal);
+                     _swprintf(logBuf, L"Sent %d bytes back to client", retVal);
                      LogEvent(logBuf, 0, 0, LOG_FILE);
                      totalSentBytes += retVal;
                  }
                  else if (retVal == SOCKET_ERROR)
                  {
-                     LogEvent(_T("Echo: socket error"), WSAGetLastError(), 0, LOG_ERROR);
+                     LogEvent(L"Echo: socket error", WSAGetLastError(), 0, LOG_ERROR);
                      return FALSE;
                  }
                  else
                  {
                      /* Client closed connection before we could reply to
                         all the data it sent, so quit early. */
-                     LogEvent(_T("Peer unexpectedly dropped connection!"), 0, 0, LOG_FILE);
+                     LogEvent(L"Peer unexpectedly dropped connection!", 0, 0, LOG_FILE);
                      return FALSE;
                  }
              }
          }
          else if (readBytes == SOCKET_ERROR)
          {
-             LogEvent(_T("Echo: socket error"), WSAGetLastError(), 0, LOG_ERROR);
+             LogEvent(L"Echo: socket error", WSAGetLastError(), 0, LOG_ERROR);
              return FALSE;
          }
      } while ((readBytes != 0) && (!bShutdown));
  
      if (!bShutdown)
-         LogEvent(_T("Echo: Connection closed by peer"), 0, 0, LOG_FILE);
+         LogEvent(L"Echo: Connection closed by peer", 0, 0, LOG_FILE);
  
      return TRUE;
  }
@@@ -69,26 -69,26 +69,26 @@@ DWORD WINAP
  EchoHandler(VOID* sock_)
  {
      DWORD retVal = 0;
 -    SOCKET sock = (SOCKET)sock_;
 +    SOCKET sock = (SOCKET)(UINT_PTR)sock_;
  
      if (!EchoIncomingPackets(sock))
      {
-         LogEvent(_T("Echo: EchoIncomingPackets failed"), 0, 0, LOG_FILE);
+         LogEvent(L"Echo: EchoIncomingPackets failed", 0, 0, LOG_FILE);
          retVal = 1;
      }
  
-     LogEvent(_T("Echo: Shutting connection down"), 0, 0, LOG_FILE);
+     LogEvent(L"Echo: Shutting connection down", 0, 0, LOG_FILE);
  
      if (ShutdownConnection(sock, TRUE))
      {
-         LogEvent(_T("Echo: Connection is down"), 0, 0, LOG_FILE);
+         LogEvent(L"Echo: Connection is down", 0, 0, LOG_FILE);
      }
      else
      {
-         LogEvent(_T("Echo: Connection shutdown failed"), 0, 0, LOG_FILE);
+         LogEvent(L"Echo: Connection shutdown failed", 0, 0, LOG_FILE);
          retVal = 1;
      }
  
-     LogEvent(_T("Echo: Terminating thread"), 0, 0, LOG_FILE);
+     LogEvent(L"Echo: Terminating thread", 0, 0, LOG_FILE);
      ExitThread(retVal);
  }
@@@ -9,7 -9,7 +9,7 @@@
  
  #include "tcpsvcs.h"
  
- static LPCTSTR lpFilePath = _T("\\drivers\\etc\\quotes");
+ static WCHAR szFilePath[] = L"\\drivers\\etc\\quotes";
  
  static BOOL
  SendQuote(SOCKET sock, char* Quote)
@@@ -25,33 -25,33 +25,33 @@@ static BOO
  RetrieveQuote(SOCKET sock)
  {
      HANDLE hFile;
-     TCHAR lpFullPath[MAX_PATH + 20];
+     WCHAR szFullPath[MAX_PATH + 20];
      DWORD dwBytesRead;
      LPSTR lpQuotes;
      LPSTR lpStr;
-     DWORD quoteNum;
-     DWORD NumQuotes = 0;
+     INT quoteNum;
+     INT NumQuotes = 0;
      INT i;
  
-     if(!GetSystemDirectory(lpFullPath, MAX_PATH))
+     if(!GetSystemDirectoryW(szFullPath, MAX_PATH))
      {
-         LogEvent(_T("QOTD: Getting system path failed"), GetLastError(), 0, LOG_FILE);
+         LogEvent(L"QOTD: Getting system path failed", GetLastError(), 0, LOG_FILE);
          return FALSE;
      }
-     _tcscat(lpFullPath, lpFilePath);
+     wcscat(szFullPath, szFilePath);
  
  
-     LogEvent(_T("QOTD: Opening quotes file"), 0, 0, LOG_FILE);
-     hFile = CreateFile(lpFullPath,
-                        GENERIC_READ,
-                        0,
-                        NULL,
-                        OPEN_EXISTING,
-                        FILE_ATTRIBUTE_NORMAL,
-                        NULL);
+     LogEvent(L"QOTD: Opening quotes file", 0, 0, LOG_FILE);
+     hFile = CreateFileW(szFullPath,
+                         GENERIC_READ,
+                         0,
+                         NULL,
+                         OPEN_EXISTING,
+                         FILE_ATTRIBUTE_NORMAL,
+                         NULL);
      if (hFile == INVALID_HANDLE_VALUE)
      {
-         LogEvent(_T("QOTD: Error opening quotes file"), GetLastError(), 0, LOG_FILE);
+         LogEvent(L"QOTD: Error opening quotes file", GetLastError(), 0, LOG_FILE);
      }
      else
      {
  
                  /* send the quote */
                  if (!SendQuote(sock, lpStart))
-                     LogEvent(_T("QOTD: Error sending data"), 0, 0, LOG_FILE);
+                     LogEvent(L"QOTD: Error sending data", 0, 0, LOG_FILE);
                  break;
              }
              else
  DWORD WINAPI
  QotdHandler(VOID* sock_)
  {
 -    SOCKET sock = (SOCKET)sock_;
 +    SOCKET sock = (SOCKET)(UINT_PTR)sock_;
      DWORD retVal = 0;
  
      if (!RetrieveQuote(sock))
      {
-         LogEvent(_T("QOTD: Error retrieving quote"), 0, 0, LOG_FILE);
+         LogEvent(L"QOTD: Error retrieving quote", 0, 0, LOG_FILE);
          retVal = 1;
      }
  
-     LogEvent(_T("QOTD: Shutting connection down"), 0, 0, LOG_FILE);
+     LogEvent(L"QOTD: Shutting connection down", 0, 0, LOG_FILE);
      if (ShutdownConnection(sock, FALSE))
      {
-         LogEvent(_T("QOTD: Connection is down"), 0, 0, LOG_FILE);
+         LogEvent(L"QOTD: Connection is down", 0, 0, LOG_FILE);
      }
      else
      {
-         LogEvent(_T("QOTD: Connection shutdown failed"), 0, 0, LOG_FILE);
-         LogEvent(_T("QOTD: Terminating thread"), 0, 0, LOG_FILE);
+         LogEvent(L"QOTD: Connection shutdown failed", 0, 0, LOG_FILE);
+         LogEvent(L"QOTD: Terminating thread", 0, 0, LOG_FILE);
          retVal = 1;
      }
  
-     LogEvent(_T("QOTD: Terminating thread"), 0, 0, LOG_FILE);
+     LogEvent(L"QOTD: Terminating thread", 0, 0, LOG_FILE);
      ExitThread(retVal);
  }
@@@ -33,17 -33,17 +33,17 @@@ SetUpListener(USHORT Port
              }
              else
              {
-                 LogEvent(_T("listen() failed"), WSAGetLastError(), 0, LOG_ERROR);
+                 LogEvent(L"listen() failed", WSAGetLastError(), 0, LOG_ERROR);
              }
          }
          else
          {
-             LogEvent(_T("bind() failed"), WSAGetLastError(), 0, LOG_ERROR);
+             LogEvent(L"bind() failed", WSAGetLastError(), 0, LOG_ERROR);
          }
      }
      else
      {
-         LogEvent(_T("socket() failed"), WSAGetLastError(), 0, LOG_ERROR);
+         LogEvent(L"socket() failed", WSAGetLastError(), 0, LOG_ERROR);
      }
  
      return bSetup ? sock : INVALID_SOCKET;
  static VOID
  AcceptConnections(SOCKET listeningSocket,
                    LPTHREAD_START_ROUTINE lpService,
-                   LPTSTR lpName)
+                   LPWSTR lpName)
  {
      SOCKADDR_IN client;
      SOCKET sock;
      HANDLE hThread;
      TIMEVAL timeVal;
      FD_SET readFD;
-     TCHAR logBuf[256];
+     WCHAR logBuf[256];
      INT timeOut = 2000;
  
      timeVal.tv_sec  = timeOut / 1000;
                  sock = accept(listeningSocket, (SOCKADDR*)&client, &addrSize);
                  if (sock != INVALID_SOCKET)
                  {
-                     _stprintf(logBuf,
-                               _T("Accepted connection to %s server from %s:%d"),
+                     _swprintf(logBuf,
+                               L"Accepted connection to %s server from %S:%d",
                                lpName,
                                inet_ntoa(client.sin_addr),
                                ntohs(client.sin_port));
                      LogEvent(logBuf, 0, 0, LOG_FILE);
  
-                     _stprintf(logBuf, _T("Creating worker thread for %s"), lpName);
+                     _swprintf(logBuf, L"Creating worker thread for %s", lpName);
                      LogEvent(logBuf, 0, 0, LOG_FILE);
  
                      if (!bShutdown)
                      {
 -                        hThread = CreateThread(0, 0, lpService, (void*)sock, 0, NULL);
 +                        hThread = CreateThread(0, 0, lpService, (PVOID)(UINT_PTR)sock, 0, NULL);
                          if (hThread != NULL)
                          {
                              CloseHandle(hThread);
                          }
                          else
                          {
-                             _stprintf(logBuf, _T("Failed to start worker thread for the %s server"),
+                             _swprintf(logBuf, L"Failed to start worker thread for the %s server",
                                        lpName);
                              LogEvent(logBuf, 0, 0, LOG_FILE);
                          }
                  }
                  else
                  {
-                     LogEvent(_T("accept failed"), WSAGetLastError(), 0, LOG_ERROR);
+                     LogEvent(L"accept failed", WSAGetLastError(), 0, LOG_ERROR);
                  }
              }
          }
          else if (selRet == SOCKET_ERROR)
          {
-             LogEvent(_T("select failed"), WSAGetLastError(), 0, LOG_ERROR);
+             LogEvent(L"select failed", WSAGetLastError(), 0, LOG_ERROR);
          }
      }
  }
@@@ -125,14 -125,14 +125,14 @@@ BOO
  ShutdownConnection(SOCKET sock,
                     BOOL bRec)
  {
-     TCHAR logBuf[256];
+     WCHAR logBuf[256];
  
      /* Disallow any further data sends.  This will tell the other side
         that we want to go away now.  If we skip this step, we don't
         shut the connection down nicely. */
      if (shutdown(sock, SD_SEND) == SOCKET_ERROR)
      {
-         LogEvent(_T("Error in shutdown()"), WSAGetLastError(), 0, LOG_ERROR);
+         LogEvent(L"Error in shutdown()", WSAGetLastError(), 0, LOG_ERROR);
          return FALSE;
      }
  
              ret = recv(sock, readBuffer, BUF, 0);
              if (ret >= 0)
              {
-                 _stprintf(logBuf, _T("FYI, received %d unexpected bytes during shutdown"), ret);
+                 _swprintf(logBuf, L"FYI, received %d unexpected bytes during shutdown", ret);
                  LogEvent(logBuf, 0, 0, LOG_FILE);
              }
          } while (ret > 0);
@@@ -169,7 -169,7 +169,7 @@@ StartServer(LPVOID lpParam
  
      pServices = (PSERVICES)lpParam;
  
-     _stprintf(logBuf, _T("Starting %s server"), pServices->Name);
+     _swprintf(logBuf, L"Starting %s server", pServices->lpName);
      LogEvent(logBuf, 0, 0, LOG_FILE);
  
      if (!bShutdown)
          listeningSocket = SetUpListener(htons(pServices->Port));
          if (!bShutdown && listeningSocket != INVALID_SOCKET)
          {
-             _stprintf(logBuf,
-                       _T("%s is waiting for connections on port %d"),
-                       pServices->Name,
+             _swprintf(logBuf,
+                       L"%s is waiting for connections on port %d",
+                       pServices->lpName,
                        pServices->Port);
              LogEvent(logBuf, 0, 0, LOG_FILE);
  
-             AcceptConnections(listeningSocket, pServices->Service, pServices->Name);
+             AcceptConnections(listeningSocket, pServices->lpService, pServices->lpName);
          }
          else
          {
-             LogEvent(_T("Socket error when setting up listener"), 0, 0, LOG_FILE);
+             LogEvent(L"Socket error when setting up listener", 0, 0, LOG_FILE);
          }
      }
  
-     _stprintf(logBuf,
-               _T("Exiting %s thread"),
-               pServices->Name);
+     _swprintf(logBuf,
+               L"Exiting %s thread",
+               pServices->lpName);
      LogEvent(logBuf, 0, 0, LOG_FILE);
      ExitThread(0);
  }
@@@ -30,646 -30,658 +30,657 @@@ Signature = "$ReactOS$
  
  
  ; Base files
 -base\applications\cacls\cacls.exe                       1
 -base\applications\calc\calc.exe                         1
 -base\applications\charmap\charmap.exe                   1
 -base\applications\cmdutils\dbgprint\dbgprint.exe        1
 -base\applications\cmdutils\doskey\doskey.exe            1
 -base\applications\cmdutils\find\find.exe                1
 -base\applications\cmdutils\hostname\hostname.exe        1
 -base\applications\cmdutils\more\more.exe                1
 -base\applications\cmdutils\xcopy\xcopy.exe              1
 -base\applications\control\control.exe                   1
 -base\applications\mscutils\devmgmt\devmgmt.exe          1
 -base\applications\mscutils\eventvwr\eventvwr.exe        1
 -base\applications\games\solitaire\sol.exe               1
 -base\applications\games\winemine\winemine.exe           1
 -base\applications\hh\hh.exe                             1
 -base\applications\kbswitch\kbswitch.exe                 1
 -base\applications\kbswitch\kbsdll\kbsdll.dll            1
 -base\applications\logoff\logoff.exe                     1
 -base\applications\msconfig\msconfig.exe                 1
 -base\applications\mstsc\mstsc.exe                       1
 -base\applications\network\arp\arp.exe                   1
 -base\applications\network\dwnl\dwnl.exe                 1
 -base\applications\network\route\route.exe               1
 -base\applications\network\finger\finger.exe             1
 -base\applications\network\ftp\ftp.exe                   1
 -base\applications\network\ipconfig\ipconfig.exe         1
 -base\applications\network\netstat\netstat.exe           1
 -base\applications\network\ping\ping.exe                 1
 -base\applications\network\telnet\telnet.exe             1
 -base\applications\network\tracert\tracert.exe           1
 -base\applications\network\whois\whois.exe               1
 -base\applications\notepad\notepad.exe                   1
 -base\applications\regedit\regedit.exe                   4
 -base\applications\regedit\clb\clb.dll                   1
 -base\applications\sc\sc.exe                             1
 -base\applications\screensavers\3dtext\3dtext.scr        1
 -base\applications\screensavers\logon\logon.scr          1
 -base\applications\mscutils\servman\servman.exe          1
 -base\applications\shutdown\shutdown.exe                 1
 -base\applications\sndvol32\sndvol32.exe                 1
 -base\applications\taskmgr\taskmgr.exe                   1
 -base\applications\winhlp32\winhlp32.exe                 1
 -base\applications\wordpad\wordpad.exe                   1
 -
 -base\services\audiosrv\audiosrv.exe                 1
 -base\services\dhcp\dhcp.exe                         1
 -base\services\eventlog\eventlog.exe                 1
 -base\services\rpcss\rpcss.exe                       1
 -base\services\spoolsv\spoolsv.exe                   1
 -base\services\tcpsvcs\tcpsvcs.exe                   1
 -base\services\tcpsvcs\quotes                        5
 -base\services\umpnpmgr\umpnpmgr.exe                 1
 -
 -base\setup\setup\setup.exe                          1
 -base\setup\vmwinst\vmwinst.exe                      1
 -
 -base\shell\cmd\cmd.exe                              1
 -base\shell\explorer\explorer.exe                    4
 -base\shell\explorer\explorer-cfg-template.xml       4
 -base\shell\explorer\notifyhook\notifyhook.dll       1
 -base\shell\explorer-new\explorer_new.exe            4   optional
 -
 -base\system\autochk\autochk.exe                     1
 -base\system\bootok\bootok.exe                       1
 -base\system\format\format.exe                       1
 -base\system\lsass\lsass.exe                         1
 -base\system\msiexec\msiexec.exe                     1
 -base\system\regsvr32\regsvr32.exe                   1
 -base\system\rundll32\rundll32.exe                   1
 -base\system\services\services.exe                   1
 -base\system\userinit\userinit.exe                   1
 -base\system\winlogon\winlogon.exe                   1
 -base\system\expand\expand.exe                       1
 -base\system\smss\smss.exe                           1
 +;base\applications\cacls\cacls.exe                       1
 +;base\applications\calc\calc.exe                         1
 +;base\applications\charmap\charmap.exe                   1
 +;base\applications\cmdutils\dbgprint\dbgprint.exe        1
 +;base\applications\cmdutils\doskey\doskey.exe            1
 +;base\applications\cmdutils\find\find.exe                1
 +;base\applications\cmdutils\hostname\hostname.exe        1
 +;base\applications\cmdutils\more\more.exe                1
 +;base\applications\cmdutils\xcopy\xcopy.exe              1
 +;base\applications\control\control.exe                   1
 +;base\applications\mscutils\devmgmt\devmgmt.exe          1
 +;base\applications\mscutils\eventvwr\eventvwr.exe        1
 +;base\applications\games\solitaire\sol.exe               1
 +;base\applications\games\winemine\winemine.exe           1
 +;base\applications\hh\hh.exe                             1
 +;base\applications\kbswitch\kbswitch.exe                 1
 +;base\applications\kbswitch\kbsdll\kbsdll.dll            1
 +;base\applications\logoff\logoff.exe                     1
 +;base\applications\msconfig\msconfig.exe                 1
 +;base\applications\mstsc\mstsc.exe                       1
 +;base\applications\network\arp\arp.exe                   1
 +;base\applications\network\dwnl\dwnl.exe                 1
 +;base\applications\network\route\route.exe               1
 +;base\applications\network\finger\finger.exe             1
 +;base\applications\network\ftp\ftp.exe                   1
 +;base\applications\network\ipconfig\ipconfig.exe         1
 +;base\applications\network\netstat\netstat.exe           1
 +;base\applications\network\ping\ping.exe                 1
 +;base\applications\network\telnet\telnet.exe             1
 +;base\applications\network\tracert\tracert.exe           1
 +;base\applications\network\whois\whois.exe               1
 +;base\applications\notepad\notepad.exe                   1
 +;base\applications\regedit\regedit.exe                   4
 +;base\applications\regedit\clb\clb.dll                   1
 +;base\applications\sc\sc.exe                             1
 +;base\applications\screensavers\3dtext\3dtext.scr        1
 +;base\applications\screensavers\logon\logon.scr          1
 +;base\applications\mscutils\servman\servman.exe          1
 +;base\applications\shutdown\shutdown.exe                 1
 +;base\applications\sndvol32\sndvol32.exe                 1
 +;base\applications\taskmgr\taskmgr.exe                   1
 +;base\applications\winhlp32\winhlp32.exe                 1
 +;base\applications\wordpad\wordpad.exe                   1
 +
++;base\services\audiosrv\audiosrv.exe                 1
 +;base\services\dhcp\dhcp.exe                         1
 +;base\services\eventlog\eventlog.exe                 1
 +;base\services\rpcss\rpcss.exe                       1
++;base\services\spoolsv\spoolsv.exe                   1
 +;base\services\tcpsvcs\tcpsvcs.exe                   1
 +;base\services\tcpsvcs\quotes                        5
 +;base\services\umpnpmgr\umpnpmgr.exe                 1
 +;base\services\audiosrv\audiosrv.exe                 1
 +
 +;base\setup\setup\setup.exe                          1
 +;base\setup\vmwinst\vmwinst.exe                      1
 +
 +;base\shell\cmd\cmd.exe                              1
 +;base\shell\explorer\explorer.exe                    4
 +;base\shell\explorer\explorer-cfg-template.xml       4
 +;base\shell\explorer\notifyhook\notifyhook.dll       1
 +;base\shell\explorer-new\explorer_new.exe            4   optional
 +
 +;base\system\autochk\autochk.exe                     1
++;base\system\bootok\bootok.exe                       1
 +;base\system\format\format.exe                       1
 +;base\system\lsass\lsass.exe                         1
 +;base\system\msiexec\msiexec.exe                     1
 +;base\system\regsvr32\regsvr32.exe                   1
 +;base\system\rundll32\rundll32.exe                   1
 +;base\system\services\services.exe                   1
 +;base\system\userinit\userinit.exe                   1
 +;base\system\winlogon\winlogon.exe                   1
 +;base\system\expand\expand.exe                       1
 +;base\system\smss\smss.exe                           1
  
  
  ; Dynamic Link Libraries
 -dll\3rdparty\freetype\freetype.dll                  1
 -dll\3rdparty\mesa32\mesa32.dll                      1
 -dll\3rdparty\dxtn\dxtn.dll                          1   optional
 -
 -dll\cpl\access\access.cpl                           1
 -dll\cpl\appwiz\appwiz.cpl                           1
 -dll\cpl\console\console.dll                         1
 -dll\cpl\desk\desk.cpl                               1
 -dll\cpl\intl\intl.cpl                               1
 -dll\cpl\main\main.cpl                               1
 -dll\cpl\mmsys\mmsys.cpl                             1
 -dll\cpl\ncpa\ncpa.cpl                               1
 -dll\cpl\powercfg\powercfg.cpl                       1
 -dll\cpl\sysdm\sysdm.cpl                             1
 -dll\cpl\timedate\timedate.cpl                       1
 -dll\cpl\input\input.dll                             1
 -dll\cpl\joy\joy.cpl                                 1
 -
 -dll\directx\dinput\dinput.dll                       1
 -dll\directx\dinput8\dinput8.dll                     1
 -dll\directx\dplay\dplay.dll                         1
 -dll\directx\dplayx\dplayx.dll                       1
 -dll\directx\dsound\dsound.dll                       1
 -dll\directx\dxdiagn\dxdiagn.dll                     1
 -dll\directx\ddraw\ddraw.dll                         1
 -dll\directx\d3d8thk\d3d8thk.dll                     1
 -dll\directx\devenum\devenum.dll                     1
 -dll\directx\ksproxy\ksproxy.ax                      1
 -dll\directx\ksuser\ksuser.dll                       1
 -dll\directx\msdmo\msdmo.dll                         1
 -dll\directx\quartz\quartz.dll                       1
 -dll\directx\qedit\qedit.dll                         1
 -dll\directx\wine\d3d8\d3d8.dll                      1
 -dll\directx\wine\wined3d\wined3d.dll                1
 -dll\directx\wine\d3d9\d3d9.dll                      1
 -
 -dll\keyboard\kbda1\kbda1.dll                        1
 -dll\keyboard\kbda2\kbda2.dll                        1
 -dll\keyboard\kbda3\kbda3.dll                        1
 -dll\keyboard\kbdal\kbdal.dll                        1
 -dll\keyboard\kbdarme\kbdarme.dll                    1
 -dll\keyboard\kbdarmw\kbdarmw.dll                    1
 -dll\keyboard\kbdaze\kbdaze.dll                      1
 -dll\keyboard\kbdazel\kbdazel.dll                    1
 -dll\keyboard\kbdbgm\kbdbgm.dll                      1
 -dll\keyboard\kbdbgt\kbdbgt.dll                      1
 -dll\keyboard\kbdblr\kbdblr.dll                      1
 -dll\keyboard\kbdbr\kbdbr.dll                        1
 -dll\keyboard\kbdbga\kbdbga.dll                      1
 -dll\keyboard\kbdbe\kbdbe.dll                        1
 -dll\keyboard\kbdbur\kbdbur.dll                      1
 -dll\keyboard\kbdcan\kbdcan.dll                      1
 -dll\keyboard\kbdcr\kbdcr.dll                        1
 -dll\keyboard\kbdcz1\kbdcz1.dll                      1
 -dll\keyboard\kbdda\kbdda.dll                        1
 -dll\keyboard\kbddv\kbddv.dll                        1
 -dll\keyboard\kbdes\kbdes.dll                        1
 -dll\keyboard\kbdest\kbdest.dll                      1
 -dll\keyboard\kbdfc\kbdfc.dll                        1
 -dll\keyboard\kbdfi\kbdfi.dll                        1
 -dll\keyboard\kbdfr\kbdfr.dll                        1
 -dll\keyboard\kbdgeo\kbdgeo.dll                      1
 -dll\keyboard\kbdgerg\kbdgerg.dll                    1
 -dll\keyboard\kbdgneo\kbdgneo.dll                    1
 -dll\keyboard\kbdgrist\kbdgrist.dll                  1
 -dll\keyboard\kbdgr\kbdgr.dll                        1
 -dll\keyboard\kbdhe\kbdhe.dll                        1
 -dll\keyboard\kbdheb\kbdheb.dll                      1
 -dll\keyboard\kbdhu\kbdhu.dll                        1
 -dll\keyboard\kbdic\kbdic.dll                        1
 -dll\keyboard\kbdinasa\kbdinasa.dll                  1
 -dll\keyboard\kbdinben\kbdinben.dll                  1
 -dll\keyboard\kbdindev\kbdindev.dll                  1
 -dll\keyboard\kbdinguj\kbdinguj.dll                  1
 -dll\keyboard\kbdinmal\kbdinmal.dll                  1
 -dll\keyboard\kbdir\kbdir.dll                        1
 -dll\keyboard\kbdit\kbdit.dll                        1
 -dll\keyboard\kbdja\kbdja.dll                        1
 -dll\keyboard\kbdkaz\kbdkaz.dll                      1
 -dll\keyboard\kbdla\kbdla.dll                        1
 -dll\keyboard\kbdlt\kbdlt.dll                        1
 -dll\keyboard\kbdlv\kbdlv.dll                        1
 -dll\keyboard\kbdmac\kbdmac.dll                      1
 -dll\keyboard\kbdne\kbdne.dll                        1
 -dll\keyboard\kbdno\kbdno.dll                        1
 -dll\keyboard\kbdpl1\kbdpl1.dll                      1
 -dll\keyboard\kbdpo\kbdpo.dll                        1
 -dll\keyboard\kbdro\kbdro.dll                        1
 -dll\keyboard\kbdru\kbdru.dll                        1
 -dll\keyboard\kbdru1\kbdru1.dll                      1
 -dll\keyboard\kbdsg\kbdsg.dll                        1
 -dll\keyboard\kbdsk\kbdsk.dll                        1
 -dll\keyboard\kbdsk1\kbdsk1.dll                      1
 -dll\keyboard\kbdsw\kbdsw.dll                        1
 -dll\keyboard\kbdtat\kbdtat.dll                      1
 -dll\keyboard\kbdth0\kbdth0.dll                      1
 -dll\keyboard\kbdth1\kbdth1.dll                      1
 -dll\keyboard\kbdth2\kbdth2.dll                      1
 -dll\keyboard\kbdth3\kbdth3.dll                      1
 -dll\keyboard\kbdtuf\kbdtuf.dll                      1
 -dll\keyboard\kbdtuq\kbdtuq.dll                      1
 -dll\keyboard\kbduk\kbduk.dll                        1
 -dll\keyboard\kbdur\kbdur.dll                        1
 -dll\keyboard\kbdurs\kbdurs.dll                      1
 -dll\keyboard\kbdus\kbdus.dll                        1
 -dll\keyboard\kbdusa\kbdusa.dll                      1
 -dll\keyboard\kbdusl\kbdusl.dll                      1
 -dll\keyboard\kbdusr\kbdusr.dll                      1
 -dll\keyboard\kbdusx\kbdusx.dll                      1
 -dll\keyboard\kbduzb\kbduzb.dll                      1
 -dll\keyboard\kbdvntc\kbdvntc.dll                    1
 -dll\keyboard\kbdycc\kbdycc.dll                      1
 -dll\keyboard\kbdycl\kbdycl.dll                      1
 -dll\keyboard\kbdko\kbdko.dll                        1
 -
 -dll\ntdll\ntdll.dll                                 1
 -
 -dll\win32\acledit\acledit.dll                       1
 -dll\win32\aclui\aclui.dll                           1
 -dll\win32\advapi32\advapi32.dll                     1
 -dll\win32\advpack\advpack.dll                       1
 -dll\win32\atl\atl.dll                               1
 -dll\win32\authz\authz.dll                           1
 -dll\win32\avifil32\avifil32.dll                     1
 -dll\win32\beepmidi\beepmidi.dll                     1
 -dll\win32\browseui\browseui.dll                     1
 -dll\win32\cabinet\cabinet.dll                       1
 -dll\win32\cards\cards.dll                           1
 -dll\win32\cfgmgr32\cfgmgr32.dll                     1
 -dll\win32\clusapi\clusapi.dll                       1
 -dll\win32\comcat\comcat.dll                         1
 -dll\win32\comctl32\comctl32.dll                     1
 -dll\win32\comdlg32\comdlg32.dll                     1
 -dll\win32\compstui\compstui.dll                     1
 -dll\win32\crtdll\crtdll.dll                         1
 -dll\win32\crypt32\crypt32.dll                       1
 -dll\win32\cryptdll\cryptdll.dll                     1
 -dll\win32\cryptnet\cryptnet.dll                     1
 -dll\win32\cryptui\cryptui.dll                       1
 -dll\win32\dbghelp\dbghelp.dll                       1
 -dll\win32\dciman32\dciman32.dll                     1
 -dll\win32\devmgr\devmgr.dll                         1
 -dll\win32\dhcpcsvc\dhcpcsvc.dll                     1
 -dll\win32\dnsapi\dnsapi.dll                         1
 -dll\win32\fmifs\fmifs.dll                           1
 -dll\win32\gdi32\gdi32.dll                           1
 -dll\win32\gdiplus\gdiplus.dll                       1
 -dll\win32\glu32\glu32.dll                           1
 -dll\win32\hhctrl.ocx\hhctrl.ocx                     1
 -dll\win32\hid\hid.dll                               1
 -dll\win32\hlink\hlink.dll                           1
 -dll\win32\icmp\icmp.dll                             1
 -dll\win32\imagehlp\imagehlp.dll                     1
 -dll\win32\imm32\imm32.dll                           1
 -dll\win32\inetcomm\inetcomm.dll                     1
 -dll\win32\inetmib1\inetmib1.dll                     1
 -dll\win32\iphlpapi\iphlpapi.dll                     1
 -dll\win32\kernel32\kernel32.dll                     1
 -dll\win32\lsasrv\lsasrv.dll                         1
 -dll\win32\lz32\lz32.dll                             1
 -dll\win32\mapi32\mapi32.dll                         1
 -dll\win32\mlang\mlang.dll                           1
 -dll\win32\mmdrv\mmdrv.dll                           1
 -dll\win32\modemui\modemui.dll                       1
 -dll\win32\mpr\mpr.dll                               1
 -dll\win32\msacm32\msacm32.dll                       1
 -dll\win32\msafd\msafd.dll                           1
 -dll\win32\msgina\msgina.dll                         1
 -dll\win32\mshtml\mshtml.dll                         1
 -dll\win32\msi\msi.dll                               1
 -dll\win32\msimg32\msimg32.dll                       1
 -dll\win32\msvcrt\msvcrt.dll                         1
 -dll\win32\msvcrt20\msvcrt20.dll                     1
 -dll\win32\msvcrt40\msvcrt40.dll                     1
 -dll\win32\msvfw32\msvfw32.dll                       1
 -dll\win32\mswsock\mswsock.dll                       1
 -dll\win32\msxml3\msxml3.dll                         1
 -dll\win32\nddeapi\nddeapi.dll                       1
 -dll\win32\netapi32\netapi32.dll                     1
 -dll\win32\netcfgx\netcfgx.dll                       1
 -dll\win32\netid\netid.dll                           1
 -dll\win32\netshell\netshell.dll                     1
 -dll\win32\newdev\newdev.dll                         1
 -dll\win32\ntdsapi\ntdsapi.dll                       1
 -dll\win32\ntmarta\ntmarta.dll                       1
 -dll\win32\objsel\objsel.dll                         1
 -dll\win32\odbc32\odbc32.dll                         1
 -dll\win32\odbccp32\odbccp32.dll                     1
 -dll\win32\ole32\ole32.dll                           1
 -dll\win32\oleacc\oleacc.dll                         1
 -dll\win32\oleaut32\oleaut32.dll                     1
 -dll\win32\oledlg\oledlg.dll                         1
 -dll\win32\olepro32\olepro32.dll                     1
 -dll\win32\opengl32\opengl32.dll                     1
 -dll\win32\pdh\pdh.dll                               1
 -dll\win32\powrprof\powrprof.dll                     1
 -dll\win32\printui\printui.dll                       1
 -dll\win32\psapi\psapi.dll                           1
 -dll\win32\rasapi32\rasapi32.dll                     1
 -dll\win32\rasdlg\rasdlg.dll                         1
 -dll\win32\rasman\rasman.dll                         1
 -dll\win32\riched20\riched20.dll                     1
 -dll\win32\riched32\riched32.dll                     1
 -dll\win32\rpcrt4\rpcrt4.dll                         1
 -dll\win32\rsabase\rsabase.dll                       1
 -dll\win32\rsaenh\rsaenh.dll                         1
 -dll\win32\samlib\samlib.dll                         1
 -dll\win32\samsrv\samsrv.dll                         1
 -dll\win32\schannel\schannel.dll                     1
 -dll\win32\secur32\secur32.dll                       1
 -dll\win32\security\security.dll                     1
 -dll\win32\sensapi\sensapi.dll                       1
 -dll\win32\serialui\serialui.dll                     1
 -dll\win32\setupapi\setupapi.dll                     1
 -dll\win32\sfc\sfc.dll                               1
 -dll\win32\sfc_os\sfc_os.dll                         1
 -dll\win32\shdocvw\shdocvw.dll                       1
 -dll\win32\shell32\shell32.dll                       1
 -dll\win32\shfolder\shfolder.dll                     1
 -dll\win32\shimgvw\shimgvw.dll                       1
 -dll\win32\shlwapi\shlwapi.dll                       1
 -dll\win32\smdll\smdll.dll                           1
 -dll\win32\snmpapi\snmpapi.dll                       1
 -dll\win32\stdole2.tlb\stdole2.tlb                   1
 -dll\win32\sxs\sxs.dll                               1
 -dll\win32\syssetup\syssetup.dll                     1
 -dll\win32\tapi32\tapi32.dll                         1
 -dll\win32\tapiui\tapiui.dll                         1
 -dll\win32\twain_32\twain_32.dll                     1
 -dll\win32\uext2\uext2.dll                           1
 -dll\win32\ufat\ufat.dll                             1
 -dll\win32\ufatx\ufatx.dll                           1   optional
 -dll\win32\untfs\untfs.dll                           1
 -dll\win32\urlmon\urlmon.dll                         1
 -dll\win32\user32\user32.dll                         1
 -dll\win32\userenv\userenv.dll                       1
 -dll\win32\usp10\usp10.dll                           1
 -dll\win32\uxtheme\uxtheme.dll                       1
 -dll\win32\vdmdbg\vdmdbg.dll                         1
 -dll\win32\version\version.dll                       1
 -dll\win32\winfax\winfax.dll                         1
 -dll\win32\winhttp\winhttp.dll                       1
 -dll\win32\wininet\wininet.dll                       1
 -dll\win32\winmm\winmm.dll                           1
 -dll\win32\winspool\winspool.drv                     1
 -dll\win32\winsta\winsta.dll                         1
 -dll\win32\wintrust\wintrust.dll                     1
 -dll\win32\wldap32\wldap32.dll                       1
 -dll\win32\ws2_32\ws2_32.dll                         1
 -dll\win32\ws2help\ws2help.dll                       1
 -dll\win32\wshirda\wshirda.dll                       1
 -dll\win32\wshtcpip\wshtcpip.dll                     1
 -dll\win32\wsock32\wsock32.dll                       1
 -dll\win32\wtsapi32\wtsapi32.dll                     1
 -dll\win32\winmm\midimap\midimap.dll                 1
 -dll\win32\winmm\wavemap\msacm32.drv                 1   optional
 +;dll\3rdparty\freetype\freetype.dll                  1
 +;dll\3rdparty\mesa32\mesa32.dll                      1
 +;dll\3rdparty\dxtn\dxtn.dll                          1   optional
 +
 +;dll\cpl\access\access.cpl                           1
 +;dll\cpl\appwiz\appwiz.cpl                           1
 +;dll\cpl\console\console.dll                         1
 +;dll\cpl\desk\desk.cpl                               1
 +;dll\cpl\intl\intl.cpl                               1
 +;dll\cpl\main\main.cpl                               1
 +;dll\cpl\mmsys\mmsys.cpl                             1
 +;dll\cpl\ncpa\ncpa.cpl                               1
 +;dll\cpl\powercfg\powercfg.cpl                       1
 +;dll\cpl\sysdm\sysdm.cpl                             1
 +;dll\cpl\timedate\timedate.cpl                       1
 +;dll\cpl\input\input.dll                             1
 +;dll\cpl\joy\joy.cpl                                 1
 +
 +;dll\directx\dinput\dinput.dll                       1
 +;dll\directx\dinput8\dinput8.dll                     1
 +;dll\directx\dplay\dplay.dll                         1
 +;dll\directx\dplayx\dplayx.dll                       1
 +;dll\directx\dsound\dsound.dll                       1
 +;dll\directx\dxdiagn\dxdiagn.dll                     1
 +;dll\directx\ddraw\ddraw.dll                         1
 +;dll\directx\d3d8thk\d3d8thk.dll                     1
 +;dll\directx\devenum\devenum.dll                     1
 +;dll\directx\ksproxy\ksproxy.ax                      1
 +;dll\directx\ksuser\ksuser.dll                       1
 +;dll\directx\msdmo\msdmo.dll                         1
 +;dll\directx\quartz\quartz.dll                       1
 +;dll\directx\qedit\qedit.dll                         1
 +;dll\directx\wine\d3d8\d3d8.dll                      1
 +;dll\directx\wine\wined3d\wined3d.dll                1
 +;dll\directx\wine\d3d9\d3d9.dll                      1
 +
 +;dll\keyboard\kbda1\kbda1.dll                        1
 +;dll\keyboard\kbda2\kbda2.dll                        1
 +;dll\keyboard\kbda3\kbda3.dll                        1
 +;dll\keyboard\kbdal\kbdal.dll                        1
 +;dll\keyboard\kbdarme\kbdarme.dll                    1
 +;dll\keyboard\kbdarmw\kbdarmw.dll                    1
 +;dll\keyboard\kbdaze\kbdaze.dll                      1
 +;dll\keyboard\kbdazel\kbdazel.dll                    1
 +;dll\keyboard\kbdbgm\kbdbgm.dll                      1
 +;dll\keyboard\kbdbgt\kbdbgt.dll                      1
 +;dll\keyboard\kbdblr\kbdblr.dll                      1
 +;dll\keyboard\kbdbr\kbdbr.dll                        1
 +;dll\keyboard\kbdbga\kbdbga.dll                      1
 +;dll\keyboard\kbdbe\kbdbe.dll                        1
 +;dll\keyboard\kbdbur\kbdbur.dll                      1
 +;dll\keyboard\kbdcan\kbdcan.dll                      1
 +;dll\keyboard\kbdcr\kbdcr.dll                        1
 +;dll\keyboard\kbdcz1\kbdcz1.dll                      1
 +;dll\keyboard\kbdda\kbdda.dll                        1
 +;dll\keyboard\kbddv\kbddv.dll                        1
 +;dll\keyboard\kbdes\kbdes.dll                        1
 +;dll\keyboard\kbdest\kbdest.dll                      1
 +;dll\keyboard\kbdfc\kbdfc.dll                        1
 +;dll\keyboard\kbdfi\kbdfi.dll                        1
 +;dll\keyboard\kbdfr\kbdfr.dll                        1
 +;dll\keyboard\kbdgeo\kbdgeo.dll                      1
 +;dll\keyboard\kbdgerg\kbdgerg.dll                    1
 +;dll\keyboard\kbdgneo\kbdgneo.dll                    1
 +;dll\keyboard\kbdgrist\kbdgrist.dll                  1
 +;dll\keyboard\kbdgr\kbdgr.dll                        1
 +;dll\keyboard\kbdhe\kbdhe.dll                        1
 +;dll\keyboard\kbdheb\kbdheb.dll                      1
 +;dll\keyboard\kbdhu\kbdhu.dll                        1
 +;dll\keyboard\kbdic\kbdic.dll                        1
 +;dll\keyboard\kbdinasa\kbdinasa.dll                  1
 +;dll\keyboard\kbdinben\kbdinben.dll                  1
 +;dll\keyboard\kbdindev\kbdindev.dll                  1
 +;dll\keyboard\kbdinguj\kbdinguj.dll                  1
 +;dll\keyboard\kbdinmal\kbdinmal.dll                  1
 +;dll\keyboard\kbdir\kbdir.dll                        1
 +;dll\keyboard\kbdit\kbdit.dll                        1
 +;dll\keyboard\kbdja\kbdja.dll                        1
 +;dll\keyboard\kbdkaz\kbdkaz.dll                      1
 +;dll\keyboard\kbdla\kbdla.dll                        1
 +;dll\keyboard\kbdlt\kbdlt.dll                        1
 +;dll\keyboard\kbdlv\kbdlv.dll                        1
 +;dll\keyboard\kbdmac\kbdmac.dll                      1
 +;dll\keyboard\kbdne\kbdne.dll                        1
 +;dll\keyboard\kbdno\kbdno.dll                        1
 +;dll\keyboard\kbdpl1\kbdpl1.dll                      1
 +;dll\keyboard\kbdpo\kbdpo.dll                        1
 +;dll\keyboard\kbdro\kbdro.dll                        1
 +;dll\keyboard\kbdru\kbdru.dll                        1
 +;dll\keyboard\kbdru1\kbdru1.dll                      1
 +;dll\keyboard\kbdsg\kbdsg.dll                        1
 +;dll\keyboard\kbdsk\kbdsk.dll                        1
 +;dll\keyboard\kbdsk1\kbdsk1.dll                      1
 +;dll\keyboard\kbdsw\kbdsw.dll                        1
 +;dll\keyboard\kbdtat\kbdtat.dll                      1
 +;dll\keyboard\kbdth0\kbdth0.dll                      1
 +;dll\keyboard\kbdth1\kbdth1.dll                      1
 +;dll\keyboard\kbdth2\kbdth2.dll                      1
 +;dll\keyboard\kbdth3\kbdth3.dll                      1
 +;dll\keyboard\kbdtuf\kbdtuf.dll                      1
 +;dll\keyboard\kbdtuq\kbdtuq.dll                      1
 +;dll\keyboard\kbduk\kbduk.dll                        1
 +;dll\keyboard\kbdur\kbdur.dll                        1
 +;dll\keyboard\kbdurs\kbdurs.dll                      1
 +;dll\keyboard\kbdus\kbdus.dll                        1
 +;dll\keyboard\kbdusa\kbdusa.dll                      1
 +;dll\keyboard\kbdusl\kbdusl.dll                      1
 +;dll\keyboard\kbdusr\kbdusr.dll                      1
 +;dll\keyboard\kbdusx\kbdusx.dll                      1
 +;dll\keyboard\kbduzb\kbduzb.dll                      1
 +;dll\keyboard\kbdvntc\kbdvntc.dll                    1
 +;dll\keyboard\kbdycc\kbdycc.dll                      1
 +;dll\keyboard\kbdycl\kbdycl.dll                      1
 +;dll\keyboard\kbdko\kbdko.dll                        1
 +
 +;dll\nt;dll\ntdll.dll                                 1
 +
 +;dll\win32\acledit\acledit.dll                       1
 +;dll\win32\aclui\aclui.dll                           1
 +;dll\win32\advapi32\advapi32.dll                     1
 +;dll\win32\advpack\advpack.dll                       1
 +;dll\win32\atl\atl.dll                               1
 +;dll\win32\authz\authz.dll                           1
 +;dll\win32\avifil32\avifil32.dll                     1
 +;dll\win32\beepmidi\beepmidi.dll                     1
 +;dll\win32\browseui\browseui.dll                     1
 +;dll\win32\cabinet\cabinet.dll                       1
 +;dll\win32\cards\cards.dll                           1
 +;dll\win32\cfgmgr32\cfgmgr32.dll                     1
 +;dll\win32\clusapi\clusapi.dll                       1
 +;dll\win32\comcat\comcat.dll                         1
 +;dll\win32\comctl32\comctl32.dll                     1
 +;dll\win32\comdlg32\comdlg32.dll                     1
 +;dll\win32\compstui\compstui.dll                     1
 +;dll\win32\crtdll\crtdll.dll                         1
 +;dll\win32\crypt32\crypt32.dll                       1
 +;dll\win32\cryptdll\cryptdll.dll                     1
 +;dll\win32\cryptnet\cryptnet.dll                     1
 +;dll\win32\cryptui\cryptui.dll                       1
 +;dll\win32\dbghelp\dbghelp.dll                       1
 +;dll\win32\dciman32\dciman32.dll                     1
 +;dll\win32\devmgr\devmgr.dll                         1
 +;dll\win32\dhcpcsvc\dhcpcsvc.dll                     1
 +;dll\win32\dnsapi\dnsapi.dll                         1
 +;dll\win32\fmifs\fmifs.dll                           1
 +;dll\win32\gdi32\gdi32.dll                           1
 +;dll\win32\gdiplus\gdiplus.dll                       1
 +;dll\win32\glu32\glu32.dll                           1
 +;dll\win32\hhctrl.ocx\hhctrl.ocx                     1
 +;dll\win32\hid\hid.dll                               1
 +;dll\win32\hlink\hlink.dll                           1
 +;dll\win32\icmp\icmp.dll                             1
 +;dll\win32\imagehlp\imagehlp.dll                     1
 +;dll\win32\imm32\imm32.dll                           1
 +;dll\win32\inetcomm\inetcomm.dll                     1
 +;dll\win32\inetmib1\inetmib1.dll                     1
 +;dll\win32\iphlpapi\iphlpapi.dll                     1
 +;dll\win32\kernel32\kernel32.dll                     1
 +;dll\win32\lsasrv\lsasrv.dll                         1
 +;dll\win32\lz32\lz32.dll                             1
 +;dll\win32\mapi32\mapi32.dll                         1
 +;dll\win32\mlang\mlang.dll                           1
 +;dll\win32\mmdrv\mmdrv.dll                           1
 +;dll\win32\modemui\modemui.dll                       1
 +;dll\win32\mpr\mpr.dll                               1
 +;dll\win32\msacm32\msacm32.dll                       1
 +;dll\win32\msafd\msafd.dll                           1
 +;dll\win32\msgina\msgina.dll                         1
 +;dll\win32\mshtml\mshtml.dll                         1
 +;dll\win32\msi\msi.dll                               1
 +;dll\win32\msimg32\msimg32.dll                       1
 +;dll\win32\msvcrt\msvcrt.dll                         1
 +;dll\win32\msvcrt20\msvcrt20.dll                     1
 +;dll\win32\msvcrt40\msvcrt40.dll                     1
 +;dll\win32\msvfw32\msvfw32.dll                       1
 +;dll\win32\mswsock\mswsock.dll                       1
 +;dll\win32\msxml3\msxml3.dll                         1
 +;dll\win32\nddeapi\nddeapi.dll                       1
 +;dll\win32\netapi32\netapi32.dll                     1
 +;dll\win32\netcfgx\netcfgx.dll                       1
 +;dll\win32\netid\netid.dll                           1
++;dll\win32\netshell\netshell.dll                     1
 +;dll\win32\newdev\newdev.dll                         1
 +;dll\win32\ntdsapi\ntdsapi.dll                       1
 +;dll\win32\ntmarta\ntmarta.dll                       1
 +;dll\win32\objsel\objsel.dll                         1
 +;dll\win32\odbccp32\odbccp32.dll                     1
 +;dll\win32\ole32\ole32.dll                           1
 +;dll\win32\oleacc\oleacc.dll                         1
 +;dll\win32\oleaut32\oleaut32.dll                     1
 +;dll\win32\oledlg\oledlg.dll                         1
 +;dll\win32\olepro32\olepro32.dll                     1
 +;dll\win32\opengl32\opengl32.dll                     1
 +;dll\win32\pdh\pdh.dll                               1
 +;dll\win32\powrprof\powrprof.dll                     1
 +;dll\win32\printui\printui.dll                       1
 +;dll\win32\psapi\psapi.dll                           1
 +;dll\win32\rasapi32\rasapi32.dll                     1
 +;dll\win32\rasdlg\rasdlg.dll                         1
 +;dll\win32\rasman\rasman.dll                         1
 +;dll\win32\riched20\riched20.dll                     1
 +;dll\win32\riched32\riched32.dll                     1
 +;dll\win32\rpcrt4\rpcrt4.dll                         1
 +;dll\win32\rsabase\rsabase.dll                       1
 +;dll\win32\rsaenh\rsaenh.dll                         1
 +;dll\win32\samlib\samlib.dll                         1
 +;dll\win32\samsrv\samsrv.dll                         1
 +;dll\win32\schannel\schannel.dll                     1
 +;dll\win32\secur32\secur32.dll                       1
 +;dll\win32\security\security.dll                     1
 +;dll\win32\sensapi\sensapi.dll                       1
 +;dll\win32\serialui\serialui.dll                     1
 +;dll\win32\setupapi\setupapi.dll                     1
++;dll\win32\sfc\sfc.dll                               1
++;dll\win32\sfc_os\sfc_os.dll                         1
 +;dll\win32\shdocvw\shdocvw.dll                       1
 +;dll\win32\shell32\shell32.dll                       1
 +;dll\win32\shfolder\shfolder.dll                     1
 +;dll\win32\shimgvw\shimgvw.dll                       1
 +;dll\win32\shlwapi\shlwapi.dll                       1
 +;dll\win32\smdll\smdll.dll                           1
 +;dll\win32\snmpapi\snmpapi.dll                       1
 +;dll\win32\stdole2.tlb\stdole2.tlb                   1
++;dll\win32\sxs\sxs.dll                               1
 +;dll\win32\syssetup\syssetup.dll                     1
 +;dll\win32\tapi32\tapi32.dll                         1
 +;dll\win32\tapiui\tapiui.dll                         1
 +;dll\win32\twain_32\twain_32.dll                     1
 +;dll\win32\uext2\uext2.dll                           1
 +;dll\win32\ufat\ufat.dll                             1
 +;dll\win32\ufatx\ufatx.dll                           1   optional
 +;dll\win32\untfs\untfs.dll                           1
 +;dll\win32\urlmon\urlmon.dll                         1
 +;dll\win32\user32\user32.dll                         1
 +;dll\win32\userenv\userenv.dll                       1
 +;dll\win32\usp10\usp10.dll                           1
 +;dll\win32\uxtheme\uxtheme.dll                       1
 +;dll\win32\vdmdbg\vdmdbg.dll                         1
 +;dll\win32\version\version.dll                       1
 +;dll\win32\winfax\winfax.dll                         1
 +;dll\win32\winhttp\winhttp.dll                       1
 +;dll\win32\wininet\wininet.dll                       1
 +;dll\win32\winmm\winmm.dll                           1
 +;dll\win32\winspool\winspool.drv                     1
 +;dll\win32\winsta\winsta.dll                         1
 +;dll\win32\wintrust\wintrust.dll                     1
 +;dll\win32\wldap32\wldap32.dll                       1
 +;dll\win32\ws2_32\ws2_32.dll                         1
 +;dll\win32\ws2help\ws2help.dll                       1
 +;dll\win32\wshirda\wshirda.dll                       1
 +;dll\win32\wshtcpip\wshtcpip.dll                     1
 +;dll\win32\wsock32\wsock32.dll                       1
 +;dll\win32\wtsapi32\wtsapi32.dll                     1
 +;dll\win32\winmm\midimap\midimap.dll                 1
 +;dll\win32\winmm\wavemap\msacm32.drv                 1   optional
  
  ; Shell Extensions
 -dll\shellext\deskadp\deskadp.dll                    1
 -dll\shellext\deskmon\deskmon.dll                    1
 +;dll\shellext\deskadp\deskadp.dll                    1
 +;dll\shellext\deskmon\deskmon.dll                    1
  
  ; Drivers
 -drivers\base\bootvid\bootvid.dll                    1
 -drivers\base\beep\beep.sys                          2
 -drivers\base\null\null.sys                          2
 +;drivers\base\bootvid\bootvid.dll                    1
 +;drivers\base\beep\beep.sys                          2
 +;drivers\base\null\null.sys                          2
  
 -drivers\bus\isapnp\isapnp.sys                       2
 +;drivers\bus\isapnp\isapnp.sys                       2
  
 -drivers\directx\dxapi\dxapi.sys                     2
 -drivers\directx\dxg\dxg.sys                         2
 -drivers\directx\dxgthk\dxgthk.sys                   2
 +;drivers\directx\dxapi\dxapi.sys                     2
 +;drivers\directx\dxg\dxg.sys                         2
 +;drivers\directx\dxgthk\dxgthk.sys                   2
  
 -drivers\filesystems\fs_rec\fs_rec.sys               2
 -drivers\filesystems\msfs\msfs.sys                   2
 -drivers\filesystems\mup\mup.sys                     2
 -drivers\filesystems\npfs\npfs.sys                   2
 +;drivers\filesystems\fs_rec\fs_rec.sys               2
 +;drivers\filesystems\msfs\msfs.sys                   2
 +;drivers\filesystems\mup\mup.sys                     2
 +;drivers\filesystems\npfs\npfs.sys                   2
  
 -drivers\input\mouclass\mouclass.sys                 2
 -drivers\input\sermouse\sermouse.sys                 2
 +;drivers\input\mouclass\mouclass.sys                 2
 +;drivers\input\sermouse\sermouse.sys                 2
  
 -drivers\network\afd\afd.sys                         2
 -drivers\network\ndis\ndis.sys                       2
 -drivers\network\tcpip\tcpip.sys                     2
 -drivers\network\tdi\tdi.sys                         2
 -drivers\network\dd\ne2000\ne2000.sys                2
 -drivers\network\dd\pcnet\pcnet.sys                  2
 +;drivers\network\afd\afd.sys                         2
 +;drivers\network\ndis\ndis.sys                       2
 +;drivers\network\tcpip\tcpip.sys                     2
 +;drivers\network\tdi\tdi.sys                         2
 +;drivers\network\dd\ne2000\ne2000.sys                2
 +;drivers\network\dd\pcnet\pcnet.sys                  2
  
 -drivers\serial\serenum\serenum.sys                  2
 -drivers\serial\serial\serial.sys                    2
 +;drivers\serial\serenum\serenum.sys                  2
 +;drivers\serial\serial\serial.sys                    2
  
 -drivers\storage\ide\pciide\pciide.sys               2
 -drivers\storage\ide\pciidex\pciidex.sys             2
 +;drivers\storage\ide\pciide\pciide.sys               2
 +;drivers\storage\ide\pciidex\pciidex.sys             2
  
 -;drivers\usb\miniport\usbohci\usbohci.sys           2
 -;drivers\usb\miniport\usbuhci\usbuhci.sys           2
 -;drivers\usb\usbhub\usbhub.sys                      2
 -;drivers\usb\usbport\usbport.sys                    2
 -drivers\usb\nt4compat\usbdriver\usbdriver.sys       2
 +;;drivers\usb\miniport\usbohci\usbohci.sys           2
 +;;drivers\usb\miniport\usbuhci\usbuhci.sys           2
 +;;drivers\usb\usbhub\usbhub.sys                      2
 +;;drivers\usb\usbport\usbport.sys                    2
 +;drivers\usb\nt4compat\usbdriver\usbdriver.sys       2
  
 -drivers\video\displays\vga\vgaddi.dll               1
 -drivers\video\displays\framebuf\framebuf.dll        1
 -drivers\video\miniport\vga\vgamp.sys                2
 -drivers\video\miniport\vbe\vbemp.sys                2
 -drivers\video\videoprt\videoprt.sys                 2
 +;drivers\video\displays\vga\vgaddi.dll               1
 +;drivers\video\displays\framebuf\framebuf.dll        1
 +;drivers\video\miniport\vga\vgamp.sys                2
 +;drivers\video\miniport\vbe\vbemp.sys                2
 +;drivers\video\videoprt\videoprt.sys                 2
  
 -drivers\wmi\wmilib.sys                              2
 +;drivers\wmi\wmilib.sys                              2
  
  ; Media
 -media\fonts\DejaVuSans.ttf                          3
 -media\fonts\DejaVuSans-Bold.ttf                     3
 -media\fonts\DejaVuSans-BoldOblique.ttf              3
 -media\fonts\DejaVuSansCondensed.ttf                 3
 -media\fonts\DejaVuSansCondensed-Bold.ttf            3
 -media\fonts\DejaVuSansCondensed-BoldOblique.ttf     3
 -media\fonts\DejaVuSansCondensed-Oblique.ttf         3
 -media\fonts\DejaVuSans-ExtraLight.ttf               3
 -media\fonts\DejaVuSansMono.ttf                      3
 -media\fonts\DejaVuSansMono-Bold.ttf                 3
 -media\fonts\DejaVuSansMono-BoldOblique.ttf          3
 -media\fonts\DejaVuSansMono-Oblique.ttf              3
 -media\fonts\DejaVuSans-Oblique.ttf                  3
 -media\fonts\DejaVuSerif.ttf                         3
 -media\fonts\DejaVuSerif-Bold.ttf                    3
 -media\fonts\DejaVuSerif-BoldItalic.ttf              3
 -media\fonts\DejaVuSerifCondensed.ttf                3
 -media\fonts\DejaVuSerifCondensed-Bold.ttf           3
 -media\fonts\DejaVuSerifCondensed-BoldItalic.ttf     3
 -media\fonts\DejaVuSerifCondensed-Italic.ttf         3
 -media\fonts\DejaVuSerif-Italic.ttf                  3
 -
 -media\fonts\LiberationMono-Bold.ttf                 3
 -media\fonts\LiberationMono-BoldItalic.ttf           3
 -media\fonts\LiberationMono-Italic.ttf               3
 -media\fonts\LiberationMono-Regular.ttf              3
 -media\fonts\LiberationSans-Bold.ttf                 3
 -media\fonts\LiberationSans-BoldItalic.ttf           3
 -media\fonts\LiberationSans-Italic.ttf               3
 -media\fonts\LiberationSans-Regular.ttf              3
 -media\fonts\LiberationSerif-Bold.ttf                3
 -media\fonts\LiberationSerif-BoldItalic.ttf          3
 -media\fonts\LiberationSerif-Italic.ttf              3
 -media\fonts\LiberationSerif-Regular.ttf             3
 -
 -media\fonts\tahoma.ttf                              3
 -media\fonts\tahomabd.ttf                            3
 -
 -media\fonts\c0419bt_.ttf                            3
 -media\fonts\c0582bt_.ttf                            3
 -media\fonts\c0583bt_.ttf                            3
 -media\fonts\c0611bt_.ttf                            3
 -media\fonts\c0632bt_.ttf                            3
 -media\fonts\c0633bt_.ttf                            3
 -media\fonts\c0648bt_.ttf                            3
 -media\fonts\c0649bt_.ttf                            3
 -media\fonts\courbi.ttf                              3
 -media\fonts\courb.ttf                               3
 -media\fonts\cour.ttf                                3
 -media\fonts\helb____.ttf                            3
 -media\fonts\Marlett.ttf                             3
 -media\fonts\timr____.ttf                            3
 -media\fonts\UTBI____.ttf                            3
 -media\fonts\UTB_____.ttf                            3
 -media\fonts\UTI_____.ttf                            3
 -media\fonts\UTRG____.ttf                            3
 -media\nls\c_037.nls                                 1
 -media\nls\c_500.nls                                 1
 -media\nls\c_737.nls                                 1
 -media\nls\c_775.nls                                 1
 -media\nls\c_850.nls                                 1
 -media\nls\c_852.nls                                 1
 -media\nls\c_855.nls                                 1
 -media\nls\c_856.nls                                 1
 -media\nls\c_857.nls                                 1
 -media\nls\c_860.nls                                 1
 -media\nls\c_861.nls                                 1
 -media\nls\c_862.nls                                 1
 -media\nls\c_863.nls                                 1
 -media\nls\c_864.nls                                 1
 -media\nls\c_865.nls                                 1
 -media\nls\c_866.nls                                 1
 -media\nls\c_869.nls                                 1
 -media\nls\c_874.nls                                 1
 -media\nls\c_875.nls                                 1
 -media\nls\c_878.nls                                 1
 -media\nls\c_932.nls                                 1
 -media\nls\c_936.nls                                 1
 -media\nls\c_949.nls                                 1
 -media\nls\c_950.nls                                 1
 -media\nls\c_1006.nls                                1
 -media\nls\c_1026.nls                                1
 -media\nls\c_1250.nls                                1
 -media\nls\c_1251.nls                                1
 -media\nls\c_1253.nls                                1
 -media\nls\c_1254.nls                                1
 -media\nls\c_1255.nls                                1
 -media\nls\c_1256.nls                                1
 -media\nls\c_1257.nls                                1
 -media\nls\c_1258.nls                                1
 -media\nls\c_10000.nls                               1
 -media\nls\c_10006.nls                               1
 -media\nls\c_10007.nls                               1
 -media\nls\c_10029.nls                               1
 -media\nls\c_10079.nls                               1
 -media\nls\c_10081.nls                               1
 -media\nls\c_20866.nls                               1
 -media\nls\c_28591.nls                               1
 -media\nls\c_28592.nls                               1
 -media\nls\c_28593.nls                               1
 -media\nls\c_28594.nls                               1
 -media\nls\c_28595.nls                               1
 -media\nls\c_28596.nls                               1
 -media\nls\c_28597.nls                               1
 -media\nls\c_28598.nls                               1
 -media\nls\c_28599.nls                               1
 -media\drivers\etc\services                          5
 -media\inf\acpi.inf                                  6
 -media\inf\cdrom.inf                                 6
 -media\inf\display.inf                               6
 -media\inf\font.inf                                  6
 -media\inf\hdc.inf                                   6
 -media\inf\intl.inf                                  6
 -media\inf\layout.inf                                6
 -media\inf\machine.inf                               6
 -media\inf\msmouse.inf                               6
 -media\inf\keyboard.inf                              6
 -media\inf\NET_NIC.inf                               6
 -media\inf\netamd.inf                                6
 -media\inf\netisa.inf                                6
 -media\inf\netrtpnt.inf                              6
 -media\inf\nettcpip.inf                              6
 -media\inf\ports.inf                                 6
 -media\inf\scsi.inf                                  6
 -media\inf\syssetup.inf                              6
 -media\inf\usbport.inf                               6
 -media\inf\usb.inf                                   6
 -media\inf\usbstor.inf                               6
 -media\inf\xboxdisp.inf                              6
 +;media\fonts\DejaVuSans.ttf                          3
 +;media\fonts\DejaVuSans-Bold.ttf                     3
 +;media\fonts\DejaVuSans-BoldOblique.ttf              3
 +;media\fonts\DejaVuSansCondensed.ttf                 3
 +;media\fonts\DejaVuSansCondensed-Bold.ttf            3
 +;media\fonts\DejaVuSansCondensed-BoldOblique.ttf     3
 +;media\fonts\DejaVuSansCondensed-Oblique.ttf         3
 +;media\fonts\DejaVuSans-ExtraLight.ttf               3
 +;media\fonts\DejaVuSansMono.ttf                      3
 +;media\fonts\DejaVuSansMono-Bold.ttf                 3
 +;media\fonts\DejaVuSansMono-BoldOblique.ttf          3
 +;media\fonts\DejaVuSansMono-Oblique.ttf              3
 +;media\fonts\DejaVuSans-Oblique.ttf                  3
 +;media\fonts\DejaVuSerif.ttf                         3
 +;media\fonts\DejaVuSerif-Bold.ttf                    3
 +;media\fonts\DejaVuSerif-BoldItalic.ttf              3
 +;media\fonts\DejaVuSerifCondensed.ttf                3
 +;media\fonts\DejaVuSerifCondensed-Bold.ttf           3
 +;media\fonts\DejaVuSerifCondensed-BoldItalic.ttf     3
 +;media\fonts\DejaVuSerifCondensed-Italic.ttf         3
 +;media\fonts\DejaVuSerif-Italic.ttf                  3
 +
 +;media\fonts\LiberationMono-Bold.ttf                 3
 +;media\fonts\LiberationMono-BoldItalic.ttf           3
 +;media\fonts\LiberationMono-Italic.ttf               3
 +;media\fonts\LiberationMono-Regular.ttf              3
 +;media\fonts\LiberationSans-Bold.ttf                 3
 +;media\fonts\LiberationSans-BoldItalic.ttf           3
 +;media\fonts\LiberationSans-Italic.ttf               3
 +;media\fonts\LiberationSans-Regular.ttf              3
 +;media\fonts\LiberationSerif-Bold.ttf                3
 +;media\fonts\LiberationSerif-BoldItalic.ttf          3
 +;media\fonts\LiberationSerif-Italic.ttf              3
 +;media\fonts\LiberationSerif-Regular.ttf             3
 +
 +;media\fonts\tahoma.ttf                              3
 +;media\fonts\tahomabd.ttf                            3
 +
 +;media\fonts\c0419bt_.ttf                            3
 +;media\fonts\c0582bt_.ttf                            3
 +;media\fonts\c0583bt_.ttf                            3
 +;media\fonts\c0611bt_.ttf                            3
 +;media\fonts\c0632bt_.ttf                            3
 +;media\fonts\c0633bt_.ttf                            3
 +;media\fonts\c0648bt_.ttf                            3
 +;media\fonts\c0649bt_.ttf                            3
 +;media\fonts\courbi.ttf                              3
 +;media\fonts\courb.ttf                               3
 +;media\fonts\cour.ttf                                3
 +;media\fonts\helb____.ttf                            3
 +;media\fonts\Marlett.ttf                             3
 +;media\fonts\timr____.ttf                            3
 +;media\fonts\UTBI____.ttf                            3
 +;media\fonts\UTB_____.ttf                            3
 +;media\fonts\UTI_____.ttf                            3
 +;media\fonts\UTRG____.ttf                            3
 +;media\nls\c_037.nls                                 1
 +;media\nls\c_500.nls                                 1
 +;media\nls\c_737.nls                                 1
 +;media\nls\c_775.nls                                 1
 +;media\nls\c_850.nls                                 1
 +;media\nls\c_852.nls                                 1
 +;media\nls\c_855.nls                                 1
 +;media\nls\c_856.nls                                 1
 +;media\nls\c_857.nls                                 1
 +;media\nls\c_860.nls                                 1
 +;media\nls\c_861.nls                                 1
 +;media\nls\c_862.nls                                 1
 +;media\nls\c_863.nls                                 1
 +;media\nls\c_864.nls                                 1
 +;media\nls\c_865.nls                                 1
 +;media\nls\c_866.nls                                 1
 +;media\nls\c_869.nls                                 1
 +;media\nls\c_874.nls                                 1
 +;media\nls\c_875.nls                                 1
 +;media\nls\c_878.nls                                 1
 +;media\nls\c_932.nls                                 1
 +;media\nls\c_936.nls                                 1
 +;media\nls\c_949.nls                                 1
 +;media\nls\c_950.nls                                 1
 +;media\nls\c_1006.nls                                1
 +;media\nls\c_1026.nls                                1
 +;media\nls\c_1250.nls                                1
 +;media\nls\c_1251.nls                                1
 +;media\nls\c_1253.nls                                1
 +;media\nls\c_1254.nls                                1
 +;media\nls\c_1255.nls                                1
 +;media\nls\c_1256.nls                                1
 +;media\nls\c_1257.nls                                1
 +;media\nls\c_1258.nls                                1
 +;media\nls\c_10000.nls                               1
 +;media\nls\c_10006.nls                               1
 +;media\nls\c_10007.nls                               1
 +;media\nls\c_10029.nls                               1
 +;media\nls\c_10079.nls                               1
 +;media\nls\c_10081.nls                               1
 +;media\nls\c_20866.nls                               1
 +;media\nls\c_28591.nls                               1
 +;media\nls\c_28592.nls                               1
 +;media\nls\c_28593.nls                               1
 +;media\nls\c_28594.nls                               1
 +;media\nls\c_28595.nls                               1
 +;media\nls\c_28596.nls                               1
 +;media\nls\c_28597.nls                               1
 +;media\nls\c_28598.nls                               1
 +;media\nls\c_28599.nls                               1
 +;media\drivers\etc\services                          5
 +;media\inf\acpi.inf                                  6
 +;media\inf\cdrom.inf                                 6
 +;media\inf\display.inf                               6
 +;media\inf\font.inf                                  6
 +;media\inf\hdc.inf                                   6
 +;media\inf\intl.inf                                  6
 +;media\inf\layout.inf                                6
 +;media\inf\machine.inf                               6
 +;media\inf\msmouse.inf                               6
 +;media\inf\keyboard.inf                              6
 +;media\inf\NET_NIC.inf                               6
 +;media\inf\netamd.inf                                6
 +;media\inf\netisa.inf                                6
 +;media\inf\netrtpnt.inf                              6
 +;media\inf\nettcpip.inf                              6
 +;media\inf\ports.inf                                 6
 +;media\inf\scsi.inf                                  6
 +;media\inf\syssetup.inf                              6
 +;media\inf\usbport.inf                               6
 +;media\inf\usb.inf                                   6
 +;media\inf\usbstor.inf                               6
 +;media\inf\xboxdisp.inf                              6
  
  ; Subsystems
 -subsystems\win32\csrss\csrss.exe                    1
 -subsystems\win32\csrss\win32csr\win32csr.dll        1
 -subsystems\csr\csr.exe                              1   optional
 -subsystems\csr\csrsrv\csrsrv.dll                    1   optional
 -subsystems\win\basesrv\basesrv.dll                  1   optional
 -subsystems\win\winsrv\winsrv.dll                    1   optional
 -subsystems\ntvdm\ntvdm.exe                          1
 -subsystems\win32\win32k\win32k.sys                  1
 +;subsystems\win32\csrss\csrss.exe                    1
 +;subsystems\win32\csrss\win32csr\win32csr.dll        1
 +;subsystems\csr\csr.exe                              1   optional
 +;subsystems\csr\csrsrv\csrsrv.dll                    1   optional
 +;subsystems\win\basesrv\basesrv.dll                  1   optional
 +;subsystems\win\winsrv\winsrv.dll                    1   optional
 +;subsystems\ntvdm\ntvdm.exe                          1
 +;subsystems\win32\win32k\win32k.sys                  1
  
  boot\bootdata\bootcdregtest\testboot.bat            7   optional
  tools\dbgprint\dbgprint.exe                         7   optional
  
  ; Modules
 -modules\os2\server\os2srv.dll                                              1   optional
 -modules\os2\dll\win32\doscalls\doscalls.dll                                1   optional
 -modules\posix\server\psxsrv.dll                                            1   optional
 -modules\posix\dll\win32\psxdll\psxdll.dll                                  1   optional
 -modules\rosky\dll\win32\libsky\libsky.dll                                  1   optional
 -modules\rosky\dll\win32\libskygi\libskygi.dll                              1   optional
 -modules\vms\server\vmssrv.dll                                              1   optional
 -modules\vms\dll\win32\vmsdll\vmsdll.dll                                    1   optional
 -modules\rosapps\applications\screensavers\cylfrac\cylfrac.scr              1   optional
 -modules\rosapps\applications\screensavers\matrix\matrix.scr                1   optional
 -modules\rosapps\applications\screensavers\blankscr\scrnsave.scr            1   optional
 -modules\rosapps\applications\screensavers\starfield\starfield.scr          1   optional
 -modules\rosapps\applications\screensavers\mazescr\mazescr.scr              1   optional
 -modules\rosapps\applications\screensavers\butterflies\butterflies.scr      1   optional
 -modules\rosapps\applications\cmdutils\comp\comp.exe                                     1   optional
 -modules\rosapps\applications\cmdutils\mode\mode.exe                                     1   optional
 -modules\rosapps\applications\cmdutils\sort\sort.exe                                     1   optional
 -modules\rosapps\applications\cmdutils\tee\tee.exe                                       1   optional
 -modules\rosapps\applications\cmdutils\touch\touch.exe                                   1   optional
 -modules\rosapps\applications\cmdutils\uptime\uptime.exe                                 1   optional
 -modules\rosapps\applications\cmdutils\y\y.exe                                           1   optional
 -modules\rosapps\applications\devutils\gdb2\gdb2.exe                                     1   optional
 -modules\rosapps\applications\devutils\gdihv\gdihv.exe                                   1   optional
 -modules\rosapps\applications\devutils\genguid\genguid.exe                               1   optional
 -modules\rosapps\applications\devutils\gettype\gettype.exe                               1   optional
 -modules\rosapps\applications\devutils\roswebparser\roswebparser.exe                     1   optional
 -modules\rosapps\applications\devutils\zoomin\zoomin.exe                                 1   optional
 -modules\rosapps\applications\downloader\downloader.exe                                  1   optional
 -modules\rosapps\applications\downloader\downloader.xml                                  1   optional
 -modules\rosapps\applications\fontview\fontview.exe                                      1   optional
 -modules\rosapps\applications\imagesoft\imagesoft.exe                                    1   optional
 -modules\rosapps\applications\net\ncftp\ncftp.exe                                        1   optional
 -modules\rosapps\applications\net\netreg\netreg.exe                                      1   optional
 -modules\rosapps\applications\net\niclist\niclist.exe                                    1   optional
 -modules\rosapps\applications\net\roshttpd\roshttpd.exe                                  1   optional
 -modules\rosapps\applications\notevil\notevil.exe                                        1   optional
 -modules\rosapps\applications\magnify\magnify.exe                                        1   optional
 -modules\rosapps\applications\packmgr\cmd-line\rosget.exe                                1   optional
 -modules\rosapps\applications\packmgr\gui\packmgr.exe                                    1   optional
 -modules\rosapps\applications\packmgr\lib\package.dll                                    1   optional
 -modules\rosapps\applications\sysutils\chkdsk\chkdsk.exe                                 1   optional
 -modules\rosapps\applications\sysutils\systeminfo\systeminfo.exe                         1   optional
 -modules\rosapps\applications\sysutils\chklib\chklib.exe                                 1   optional
 -modules\rosapps\applications\sysutils\ctm\ctm.exe                                       1   optional
 -modules\rosapps\applications\sysutils\dosfsck\dosfsck.exe                                       1   optional
 -modules\rosapps\applications\sysutils\kill\kill.exe                                     1   optional
 -modules\rosapps\applications\sysutils\lsdd\lsdd.exe                                     1   optional
 -modules\rosapps\applications\sysutils\man\man.exe                                       1   optional
 -modules\rosapps\applications\sysutils\pedump\pedump.exe                                 1   optional
 -modules\rosapps\applications\sysutils\regexpl\regexpl.exe                               1   optional
 -modules\rosapps\applications\sysutils\tcat\tcat.exe                                     1   optional
 -modules\rosapps\applications\sysutils\tlist\tlist.exe                                   1   optional
 -modules\rosapps\applications\sysutils\screenshot\screenshot.exe                         1   optional
 -modules\rosapps\applications\sysutils\utils\binpatch\binpatch.exe                       1   optional
 -modules\rosapps\applications\sysutils\utils\cat\cat.exe                                 1   optional
 -modules\rosapps\applications\sysutils\utils\driver\load\load.exe                        1   optional
 -modules\rosapps\applications\sysutils\utils\driver\unload\unload.exe                    1   optional
 -modules\rosapps\applications\sysutils\utils\infinst\infinst.exe                         1   optional
 -modules\rosapps\applications\sysutils\utils\nts2w32err\nts2w32err.exe                   1   optional
 -modules\rosapps\applications\sysutils\utils\objdir\objdir.exe                           1   optional
 -modules\rosapps\applications\sysutils\utils\partinfo\partinfo.exe                       1   optional
 -modules\rosapps\applications\sysutils\utils\ps\ps.exe                                   1   optional
 -modules\rosapps\applications\sysutils\utils\rosperf\rosperf.exe                         1   optional
 -modules\rosapps\applications\sysutils\utils\stats\stats.exe                             1   optional
 -modules\rosapps\applications\sysutils\utils\tickcount\tickcount.exe                     1   optional
 -modules\rosapps\applications\winfile\winfile.exe                                        1   optional
 -modules\rosapps\applications\winver\winver.exe                                          1   optional
 -modules\rosapps\applications\write\write.exe                                            1   optional
 -modules\rosapps\demos\ddraw\ddraw_demo.exe                                 1   optional
 -modules\rosapps\demos\maze\maze.exe                                        1   optional
 -modules\rosapps\dflat32\edit.exe                                           1   optional
 -modules\rosapps\drivers\avtest\avtest.sys                                  1   optional
 -modules\rosapps\drivers\ramdrv\ramdrv.sys                                  1   optional
 -modules\rosapps\drivers\green\green.sys                                    1   optional
 -modules\rosapps\lib\dflat32\dflat32.dll                                    1   optional
 -modules\rosapps\templates\dialog.exe                                       1   optional
 -modules\rosapps\templates\mdi.exe                                          1   optional
 -modules\rostests\winetests\advapi32\advapi32_winetest.exe                  7   optional
 -modules\rostests\winetests\advpack\advpack_winetest.exe                    7   optional
 -modules\rostests\winetests\browseui\browseui_winetest.exe                  7   optional
 -modules\rostests\winetests\cabinet\cabinet_winetest.exe                    7   optional
 -modules\rostests\winetests\comcat\comcat_winetest.exe                      7   optional
 -modules\rostests\winetests\comctl32\comctl32_winetest.exe                  7   optional
 -modules\rostests\winetests\comdlg32\comdlg32_winetest.exe                  7   optional
 -modules\rostests\winetests\gdi32\gdi32_winetest.exe                        7   optional
 -modules\rostests\winetests\gdiplus\gdiplus_winetest.exe                    7   optional
 -modules\rostests\winetests\hlink\hlink_winetest.exe                        7   optional
 -modules\rostests\winetests\icmp\icmp_winetest.exe                          7   optional
 -modules\rostests\winetests\kernel32\kernel32_winetest.exe                  7   optional
 -modules\rostests\winetests\lz32\lz32_winetest.exe                          7   optional
 -modules\rostests\winetests\mapi32\mapi32_winetest.exe                      7   optional
 -modules\rostests\winetests\mlang\mlang_winetest.exe                        7   optional
 -modules\rostests\winetests\mshtml\mshtml_winetest.exe                      7   optional
 -modules\rostests\winetests\msi\msi_winetest.exe                            7   optional
 -modules\rostests\winetests\msvcrt\msvcrt_winetest.exe                      7   optional
 -modules\rostests\winetests\netapi32\netapi32_winetest.exe                  7   optional
 -modules\rostests\winetests\ntdll\ntdll_winetest.exe                        7   optional
 -modules\rostests\winetests\odbccp32\odbccp32_winetest.exe                  7   optional
 -modules\rostests\winetests\ole32\ole32_winetest.exe                        7   optional
 -modules\rostests\winetests\oleaut32\oleaut32_winetest.exe                  7   optional
 -modules\rostests\winetests\powrprof\powrprof_winetest.exe                  7   optional
 -modules\rostests\winetests\psapi\psapi_winetest.exe                        7   optional
 -modules\rostests\winetests\riched20\riched20_winetest.exe                  7   optional
 -modules\rostests\winetests\rpcrt4\rpcrt4_winetest.exe                      7   optional
 -modules\rostests\winetests\rsabase\rsabase_winetest.exe                    7   optional
 -modules\rostests\winetests\rsaenh\rsaenh_winetest.exe                      7   optional
 -modules\rostests\winetests\schannel\schannel_winetest.exe                  7   optional
 -modules\rostests\winetests\secur32\secur32_winetest.exe                    7   optional
 -modules\rostests\winetests\setupapi\setupapi_winetest.exe                  7   optional
 -modules\rostests\winetests\shdocvw\shdocvw_winetest.exe                    7   optional
 -modules\rostests\winetests\shell32\shell32_winetest.exe                    7   optional
 -modules\rostests\winetests\shlwapi\shlwapi_winetest.exe                    7   optional
 -modules\rostests\winetests\urlmon\urlmon_winetest.exe                      7   optional
 -modules\rostests\winetests\user32\user32_winetest.exe                      7   optional
 -modules\rostests\winetests\usp10\usp10_winetest.exe                        7   optional
 -modules\rostests\winetests\uxtheme\uxtheme_winetest.exe                    7   optional
 -modules\rostests\winetests\version\version_winetest.exe                    7   optional
 -modules\rostests\winetests\wininet\wininet_winetest.exe                    7   optional
 -modules\wallpaper\lake.bmp                                                 4   optional
 +;modules\os2\server\os2srv.dll                                              1   optional
 +;modules\os2\dll\win32\doscalls\doscalls.dll                                1   optional
 +;modules\posix\server\psxsrv.dll                                            1   optional
 +;modules\posix\dll\win32\psxdll\psxdll.dll                                  1   optional
 +;modules\rosky\dll\win32\libsky\libsky.dll                                  1   optional
 +;modules\rosky\dll\win32\libskygi\libskygi.dll                              1   optional
 +;modules\vms\server\vmssrv.dll                                              1   optional
 +;modules\vms\dll\win32\vmsdll\vmsdll.dll                                    1   optional
 +;modules\rosapps\applications\screensavers\cylfrac\cylfrac.scr              1   optional
 +;modules\rosapps\applications\screensavers\matrix\matrix.scr                1   optional
 +;modules\rosapps\applications\screensavers\blankscr\scrnsave.scr            1   optional
 +;modules\rosapps\applications\screensavers\starfield\starfield.scr          1   optional
 +;modules\rosapps\applications\screensavers\mazescr\mazescr.scr              1   optional
 +;modules\rosapps\applications\screensavers\butterflies\butterflies.scr      1   optional
 +;modules\rosapps\applications\cmdutils\comp\comp.exe                                     1   optional
 +;modules\rosapps\applications\cmdutils\mode\mode.exe                                     1   optional
 +;modules\rosapps\applications\cmdutils\sort\sort.exe                                     1   optional
 +;modules\rosapps\applications\cmdutils\tee\tee.exe                                       1   optional
 +;modules\rosapps\applications\cmdutils\touch\touch.exe                                   1   optional
 +;modules\rosapps\applications\cmdutils\uptime\uptime.exe                                 1   optional
 +;modules\rosapps\applications\cmdutils\y\y.exe                                           1   optional
 +;modules\rosapps\applications\devutils\gdb2\gdb2.exe                                     1   optional
 +;modules\rosapps\applications\devutils\gdihv\gdihv.exe                                   1   optional
 +;modules\rosapps\applications\devutils\genguid\genguid.exe                               1   optional
 +;modules\rosapps\applications\devutils\gettype\gettype.exe                               1   optional
 +;modules\rosapps\applications\devutils\roswebparser\roswebparser.exe                     1   optional
 +;modules\rosapps\applications\devutils\zoomin\zoomin.exe                                 1   optional
 +;modules\rosapps\applications\downloader\downloader.exe                                  1   optional
 +;modules\rosapps\applications\downloader\downloader.xml                                  1   optional
 +;modules\rosapps\applications\fontview\fontview.exe                                      1   optional
 +;modules\rosapps\applications\imagesoft\imagesoft.exe                                    1   optional
 +;modules\rosapps\applications\net\ncftp\ncftp.exe                                        1   optional
 +;modules\rosapps\applications\net\netreg\netreg.exe                                      1   optional
 +;modules\rosapps\applications\net\niclist\niclist.exe                                    1   optional
 +;modules\rosapps\applications\net\roshttpd\roshttpd.exe                                      1   optional
 +;modules\rosapps\applications\notevil\notevil.exe                                        1   optional
 +;modules\rosapps\applications\magnify\magnify.exe                                        1   optional
 +;modules\rosapps\applications\packmgr\cmd-line\rosget.exe                                1   optional
 +;modules\rosapps\applications\packmgr\gui\packmgr.exe                                    1   optional
 +;modules\rosapps\applications\packmgr\lib\package.dll                                    1   optional
 +;modules\rosapps\applications\sysutils\chkdsk\chkdsk.exe                                 1   optional
 +;modules\rosapps\applications\sysutils\systeminfo\systeminfo.exe                         1   optional
 +;modules\rosapps\applications\sysutils\chklib\chklib.exe                                 1   optional
 +;modules\rosapps\applications\sysutils\ctm\ctm.exe                                       1   optional
 +;modules\rosapps\applications\sysutils\kill\kill.exe                                     1   optional
 +;modules\rosapps\applications\sysutils\lsdd\lsdd.exe                                     1   optional
 +;modules\rosapps\applications\sysutils\man\man.exe                                       1   optional
 +;modules\rosapps\applications\sysutils\pedump\pedump.exe                                 1   optional
 +;modules\rosapps\applications\sysutils\regexpl\regexpl.exe                               1   optional
 +;modules\rosapps\applications\sysutils\tcat\tcat.exe                                     1   optional
 +;modules\rosapps\applications\sysutils\tlist\tlist.exe                                   1   optional
 +;modules\rosapps\applications\sysutils\screenshot\screenshot.exe                                  1   optional
 +;modules\rosapps\applications\sysutils\utils\binpatch\binpatch.exe                       1   optional
 +;modules\rosapps\applications\sysutils\utils\cat\cat.exe                                 1   optional
 +;modules\rosapps\applications\sysutils\utils\driver\load\load.exe                        1   optional
 +;modules\rosapps\applications\sysutils\utils\driver\unload\unload.exe                    1   optional
 +;modules\rosapps\applications\sysutils\utils\infinst\infinst.exe                         1   optional
 +;modules\rosapps\applications\sysutils\utils\nts2w32err\nts2w32err.exe                   1   optional
 +;modules\rosapps\applications\sysutils\utils\objdir\objdir.exe                           1   optional
 +;modules\rosapps\applications\sysutils\utils\partinfo\partinfo.exe                       1   optional
 +;modules\rosapps\applications\sysutils\utils\ps\ps.exe                                   1   optional
 +;modules\rosapps\applications\sysutils\utils\rosperf\rosperf.exe                         1   optional
 +;modules\rosapps\applications\sysutils\utils\stats\stats.exe                             1   optional
 +;modules\rosapps\applications\sysutils\utils\tickcount\tickcount.exe                     1   optional
 +;modules\rosapps\applications\winfile\winfile.exe                                        1   optional
 +;modules\rosapps\applications\winver\winver.exe                                          1   optional
 +;modules\rosapps\applications\write\write.exe                                            1   optional
 +;modules\rosapps\demos\ddraw\ddraw_demo.exe                                 1   optional
 +;modules\rosapps\demos\maze\maze.exe                                        1   optional
 +;modules\rosapps\dflat32\edit.exe                                           1   optional
 +;modules\rosapps\drivers\avtest\avtest.sys                                  1   optional
 +;modules\rosapps\drivers\ramdrv\ramdrv.sys                                  1   optional
 +;modules\rosapps\drivers\green\green.sys                                    1   optional
 +;modules\rosapps\lib\dflat32\dflat32.dll                                    1   optional
 +;modules\rosapps\templates\dialog.exe                                       1   optional
 +;modules\rosapps\templates\mdi.exe                                          1   optional
 +;modules\rostests\winetests\advapi32\advapi32_winetest.exe                  7   optional
 +;modules\rostests\winetests\advpack\advpack_winetest.exe                    7   optional
 +;modules\rostests\winetests\browseui\browseui_winetest.exe                  7   optional
 +;modules\rostests\winetests\cabinet\cabinet_winetest.exe                    7   optional
 +;modules\rostests\winetests\comcat\comcat_winetest.exe                      7   optional
 +;modules\rostests\winetests\comctl32\comctl32_winetest.exe                  7   optional
 +;modules\rostests\winetests\comdlg32\comdlg32_winetest.exe                  7   optional
 +;modules\rostests\winetests\gdi32\gdi32_winetest.exe                        7   optional
 +;modules\rostests\winetests\gdiplus\gdiplus_winetest.exe                    7   optional
 +;modules\rostests\winetests\hlink\hlink_winetest.exe                        7   optional
 +;modules\rostests\winetests\icmp\icmp_winetest.exe                          7   optional
 +;modules\rostests\winetests\kernel32\kernel32_winetest.exe                  7   optional
 +;modules\rostests\winetests\lz32\lz32_winetest.exe                          7   optional
 +;modules\rostests\winetests\mapi32\mapi32_winetest.exe                      7   optional
 +;modules\rostests\winetests\mlang\mlang_winetest.exe                        7   optional
 +;modules\rostests\winetests\mshtml\mshtml_winetest.exe                      7   optional
 +;modules\rostests\winetests\msi\msi_winetest.exe                            7   optional
 +;modules\rostests\winetests\msvcrt\msvcrt_winetest.exe                      7   optional
 +;modules\rostests\winetests\netapi32\netapi32_winetest.exe                  7   optional
 +;modules\rostests\winetests\ntdll\ntdll_winetest.exe                        7   optional
 +;modules\rostests\winetests\odbccp32\odbccp32_winetest.exe                  7   optional
 +;modules\rostests\winetests\ole32\ole32_winetest.exe                        7   optional
 +;modules\rostests\winetests\oleaut32\oleaut32_winetest.exe                  7   optional
 +;modules\rostests\winetests\powrprof\powrprof_winetest.exe                  7   optional
 +;modules\rostests\winetests\psapi\psapi_winetest.exe                        7   optional
 +;modules\rostests\winetests\riched20\riched20_winetest.exe                  7   optional
 +;modules\rostests\winetests\rpcrt4\rpcrt4_winetest.exe                      7   optional
 +;modules\rostests\winetests\rsabase\rsabase_winetest.exe                    7   optional
 +;modules\rostests\winetests\rsaenh\rsaenh_winetest.exe                      7   optional
 +;modules\rostests\winetests\schannel\schannel_winetest.exe                  7   optional
 +;modules\rostests\winetests\secur32\secur32_winetest.exe                    7   optional
 +;modules\rostests\winetests\setupapi\setupapi_winetest.exe                  7   optional
 +;modules\rostests\winetests\shdocvw\shdocvw_winetest.exe                    7   optional
 +;modules\rostests\winetests\shell32\shell32_winetest.exe                    7   optional
 +;modules\rostests\winetests\shlwapi\shlwapi_winetest.exe                    7   optional
 +;modules\rostests\winetests\urlmon\urlmon_winetest.exe                      7   optional
 +;modules\rostests\winetests\user32\user32_winetest.exe                      7   optional
 +;modules\rostests\winetests\usp10\usp10_winetest.exe                        7   optional
 +;modules\rostests\winetests\uxtheme\uxtheme_winetest.exe                    7   optional
 +;modules\rostests\winetests\version\version_winetest.exe                    7   optional
 +;modules\rostests\winetests\wininet\wininet_winetest.exe                    7   optional
 +;modules\wallpaper\lake.bmp                                                 4   optional
  
  ; Native libraries
 -modules\windows\mfc42.dll                                                  1   optional
 -modules\windows\vmx_fb.dll                                                 1   optional
 -modules\windows\vmx_mode.dll                                               1   optional
 -modules\windows\vmx_svga.sys                                               2   optional
 -modules\windows\vmx_svga.inf                                               6   optional
 +;modules\windows\mfc42.dll                                                  1   optional
++;modules\windows\vmx_fb.dll                                                 1   optional
++;modules\windows\vmx_mode.dll                                               1   optional
++;modules\windows\vmx_svga.sys                                               2   optional
++;modules\windows\vmx_svga.inf                                               6   optional
@@@ -33,7 -33,8 +33,8 @@@ pci.sys=,,,,,,,,,,,,
  scsiport.sys=,,,,,,x,,,,,,4
  uniata.sys=,,,,,,,,,,,,4
  fastfat.sys=,,,,,,x,,,,,,4
 -ramdisk.sys=,,,,,,x,,,,,,4
 -ext2.sys=,,,,,,x,,,,,,4
++;ramdisk.sys=,,,,,,x,,,,,,4
 +;ext2.sys=,,,,,,x,,,,,,4
  
  [HardwareIdsDatabase]
  *PNP0C08 = acpi
@@@ -23,7 -23,7 +23,7 @@@ VOID RunLoader(VOID
  {
        CHAR    SettingName[80];
        CHAR    SettingValue[80];
 -      ULONG           SectionId;
 +      ULONG_PTR       SectionId;
        ULONG           OperatingSystemCount;
        PCSTR   *OperatingSystemSectionNames;
        PCSTR   *OperatingSystemDisplayNames;
                return;
        }
  
-       //
-       // Check if we have a virtual RAM disk
-       // This is for x86 emulation -- on real hardware, the RAM disk will be
-       // located in one of the hardware memory descriptors as well as on the 
-       // freeldr command-line
-       //
-       RamDiskCheckForVirtualFile();
        if (!IniFileInitialize())
        {
                UiMessageBoxCritical("Error initializing .ini file");
@@@ -169,7 -161,7 +161,7 @@@ ULONG       GetDefaultOperatingSystem(PCSTR 
  {
        CHAR    DefaultOSText[80];
        PCSTR   DefaultOSName;
 -      ULONG   SectionId;
 +      ULONG_PTR       SectionId;
        ULONG   DefaultOS = 0;
        ULONG   Idx;
  
@@@ -206,7 -198,7 +198,7 @@@ LONG GetTimeOut(VOID
  {
        CHAR    TimeOutText[20];
        LONG            TimeOut;
 -      ULONG           SectionId;
 +      ULONG_PTR       SectionId;
  
        TimeOut = CmdLineGetTimeOut();
        if (0 <= TimeOut)
@@@ -27,7 -27,7 +27,7 @@@ RamDiskGetDataAtOffset(IN PVOID Offset
      //
      // Return data from our RAM Disk
      //
-     assert(((ULONG_PTR)gRamDiskBase + (ULONG_PTR)Offset) <
+     ASSERT(((ULONG_PTR)gRamDiskBase + (ULONG_PTR)Offset) <
             ((ULONG_PTR)gRamDiskBase + (ULONG_PTR)gRamDiskSize));
      return (PVOID)((ULONG_PTR)gRamDiskBase + (ULONG_PTR)(Offset));
  }
@@@ -66,7 -66,7 +66,7 @@@ RamDiskReadLogicalSectors(IN ULONG Rese
      //
      // Get actual pointers and lengths
      //
 -    StartAddress = (PVOID)((ULONG)SectorNumber * 512);
 +    StartAddress = (PVOID)((ULONG_PTR)SectorNumber * 512);
      Length = SectorCount * 512;
      
      //
  
  VOID
  NTAPI
- RamDiskCheckForVirtualFile(VOID)
+ RamDiskLoadVirtualFile(IN PCHAR FileName)
  {
      PFILE RamFile;
      ULONG TotalRead, ChunkSize;
-     
+       PCHAR MsgBuffer = "Loading ramdisk...";
+     ULONG PercentPerChunk, Percent;
      //
-     // Try opening the ramdisk file (this assumes the boot volume was opened)
+     // Display progress
      //
-     RamFile = FsOpenFile("reactos.img");
+     UiDrawProgressBarCenter(1, 100, MsgBuffer);
+     //
+     // Try opening the ramdisk file (this assumes the boot volume was opened)
+     //    
+     RamFile = FsOpenFile(FileName);
      if (RamFile)
      {
          //
          // Get the file size
          //
          gRamDiskSize = FsGetFileSize(RamFile);
-         TuiPrintf("Found virtual ramdisk (%dKB)\n", gRamDiskSize / 1024);
          if (!gRamDiskSize) return;
          
          //
          // Allocate memory for it
          //
          ChunkSize = 8 * 1024 * 1024;
+         Percent = PercentPerChunk = 100 / (gRamDiskSize / ChunkSize);
          gRamDiskBase = MmAllocateMemory(gRamDiskSize);
          if (!gRamDiskBase) return;
-         
+                 
          //
          // Read it in chunks
          //
-         TuiPrintf("Loading ramdisk @ 0x%x...", gRamDiskBase);
          for (TotalRead = 0; TotalRead < gRamDiskSize; TotalRead += ChunkSize)
          {
              //
                  //
                  ChunkSize = gRamDiskSize - TotalRead;
              }
-             
+             //
+             // Draw progress
+             //
+             UiDrawProgressBarCenter(Percent, 100, MsgBuffer);
+             Percent += PercentPerChunk;
              //
              // Copy the contents
              //
-             TuiPrintf(".");
+             
              if (!FsReadFile(RamFile,
                              ChunkSize,
                              NULL,
                  //
                  // Fail
                  //
-                 TuiPrintf("Failed to read ramdisk\n");
+                 UiMessageBox("Failed to read ramdisk\n");
              }
          }
-         TuiPrintf("\n");
      }
  }
  
@@@ -47,6 -47,7 +47,7 @@@
  #include <video.h>
  #include <ramdisk.h>
  /* NDK, needed for ReactOS/Windows loaders */
+ #include <ndk/asm.h>
  #include <ndk/rtlfuncs.h>
  #include <ndk/ldrtypes.h>
  #include <reactos.h>
@@@ -77,9 -78,6 +78,9 @@@
  #include <arch/arm/hardware.h>
  #elif defined(_M_MIPS)
  #include <arch/mips/arcbios.h>
 +#elif defined(_M_AMD64)
 +#include <arch/amd64/hardware.h>
 +#include <arch/amd64/machpc.h>
  #endif
  /* misc files */
  #include <keycodes.h>
  #define Ke386EraseFlags(x)     __asm__ __volatile__("pushl $0 ; popfl\n")
  #endif
  
 +#ifdef _M_AMD64
 +#define KeAmd64EraseFlags(x)     __asm__ __volatile__("pushq $0 ; popfq\n")
 +#endif
 +
  VOID BootMain(LPSTR CmdLine);
  VOID RunLoader(VOID);
  
@@@ -40,7 -40,7 +40,7 @@@ char reactos_arc_hardware_data[HW_MAX_A
  CHAR szHalName[255];
  CHAR szBootPath[255];
  CHAR SystemRoot[255];
- static CHAR szLoadingMsg[] = "Loading ReactOS...";
+ static CHAR szLoadingMsg[] = "ReactOS is loading files...";
  BOOLEAN FrLdrBootType;
  ULONG_PTR KernelBase;
  ROS_KERNEL_ENTRY_POINT KernelEntryPoint;
@@@ -571,11 -571,16 +571,16 @@@ LoadAndBootReactOS(PCSTR OperatingSyste
        CHAR szKernelName[255];
        CHAR szFileName[255];
        CHAR  MsgBuffer[256];
 -      ULONG SectionId;
 +      ULONG_PTR SectionId;
      PIMAGE_NT_HEADERS NtHeader;
      PVOID LoadBase;
        ULONG_PTR Base;
        ULONG Size;
+     
+     //
+     // Backdrop
+     //
+     UiDrawBackdrop();
  
        //
        // Open the operating system section
                return;
        }
  
-       UiDrawBackdrop();
-       UiDrawStatusText("Detecting Hardware...");
-     UiDrawProgressBarCenter(1, 100, szLoadingMsg);
+     //
+     // Read the command line
+     //
+       if (IniReadSettingByName(SectionId, "Options", value, sizeof(value)))
+       {
+         //
+         // Check if a ramdisk file was given
+         //
+         PCHAR File;
+         File = strstr(value, "/RDIMAGEPATH=");
+         if (File)
+         {
+             //
+             // Copy the file name and everything else after it
+             //
+             strcpy(szFileName, File + 13);
+             
+             //
+             // Null-terminate
+             //
+             *strstr(szFileName, " ") = ANSI_NULL;
+             
+             //
+             // Load the ramdisk
+             //
+             RamDiskLoadVirtualFile(szFileName);
+         }
+       }
  
        /*
         * Setup multiboot information structure
         */
+     UiDrawProgressBarCenter(1, 100, szLoadingMsg);
+       UiDrawStatusText("Detecting Hardware...");
        LoaderBlock.CommandLine = reactos_kernel_cmdline;
 -      LoaderBlock.PageDirectoryStart = (ULONG)&PageDirectoryStart;
 -      LoaderBlock.PageDirectoryEnd = (ULONG)&PageDirectoryEnd;
 +      LoaderBlock.PageDirectoryStart = (ULONG_PTR)&PageDirectoryStart;
 +      LoaderBlock.PageDirectoryEnd = (ULONG_PTR)&PageDirectoryEnd;
        LoaderBlock.ModsCount = 0;
        LoaderBlock.ModsAddr = reactos_modules;
      LoaderBlock.DrivesAddr = reactos_arc_disk_info;
 -    LoaderBlock.RdAddr = (ULONG)gRamDiskBase;
 +    LoaderBlock.RdAddr = (ULONG_PTR)gRamDiskBase;
      LoaderBlock.RdLength = gRamDiskSize;
 -    LoaderBlock.MmapLength = (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP)reactos_memory_map, 32) * sizeof(memory_map_t);
 +    LoaderBlock.MmapLength = (SIZE_T)MachGetMemoryMap((PBIOS_MEMORY_MAP)reactos_memory_map, 32) * sizeof(memory_map_t);
      if (LoaderBlock.MmapLength)
      {
          ULONG i;
          LoaderBlock.Flags |= MB_FLAGS_MEM_INFO | MB_FLAGS_MMAP_INFO;
 -        LoaderBlock.MmapAddr = (unsigned long)&reactos_memory_map;
 +        LoaderBlock.MmapAddr = (ULONG_PTR)&reactos_memory_map;
          reactos_memory_map_descriptor_size = sizeof(memory_map_t); // GetBiosMemoryMap uses a fixed value of 24
          for (i=0; i<(LoaderBlock.MmapLength/sizeof(memory_map_t)); i++)
          {
        /*
         * Detect hardware
         */
 -      LoaderBlock.ArchExtra = (ULONG)MachHwDetect();
 +      LoaderBlock.ArchExtra = (ULONG_PTR)MachHwDetect();
      UiDrawProgressBarCenter(5, 100, szLoadingMsg);
  
      LoaderBlock.DrivesCount = reactos_disk_count;
  }
  
  #undef DbgPrint
 +#if 0
  ULONG
  DbgPrint(const char *Format, ...)
  {
        va_end(ap);
        return 0;
  }
 +#else
 +VOID DebugPrintChar(UCHAR Character);
  
 +ULONG
 +DbgPrint(const char *Format, ...)
 +{
 +      va_list ap;
 +      CHAR Buffer[512];
 +      ULONG Length;
 +      char *ptr = Buffer;
 +
 +      va_start(ap, Format);
 +
 +      /* Construct a string */
 +      Length = _vsnprintf(Buffer, 512, Format, ap);
 +
 +      /* Check if we went past the buffer */
 +      if (Length == -1)
 +      {
 +              /* Terminate it if we went over-board */
 +              Buffer[sizeof(Buffer) - 1] = '\n';
 +
 +              /* Put maximum */
 +              Length = sizeof(Buffer);
 +      }
 +
 +      while (*ptr)
 +      {
 +              DebugPrintChar(*ptr++);
 +      }
 +
 +      va_end(ap);
 +      return 0;
 +}
 +#endif
  /* EOF */
@@@ -1,4 -1,3 +1,4 @@@
 +
  ; $Id: ntdll.def 34404 2008-07-10 09:46:25Z fireball $
  ;
  ; ReactOS Operating System
@@@ -292,6 -291,7 +292,7 @@@ NtWriteFileGathe
  NtWriteRequestData
  NtWriteVirtualMemory
  NtYieldExecution
+ NtGetCurrentProcessorNumber
  ;PfxFindPrefix
  ;PfxInitialize
  ;PfxInsertPrefix
@@@ -78,6 -78,26 +78,26 @@@ HandleUnbind(VOID
  #endif
  
  
+ static DWORD
+ ScmRpcStatusToWinError(RPC_STATUS Status)
+ {
+     switch (Status)
+     {
+         case RPC_X_SS_IN_NULL_CONTEXT:
+             return ERROR_INVALID_HANDLE;
+         case RPC_X_NULL_REF_POINTER:
+             return ERROR_INVALID_PARAMETER;
+         case STATUS_ACCESS_VIOLATION:
+             return ERROR_INVALID_ADDRESS;
+         default:
+             return (DWORD)Status;
+     }
+ }
  /**********************************************************************
   *  ChangeServiceConfig2A
   *
@@@ -116,9 -136,18 +136,18 @@@ ChangeServiceConfig2A(SC_HANDLE hServic
  
      HandleBind();
  
-     dwError = RChangeServiceConfig2A(BindingHandle,
-                                      (SC_RPC_HANDLE)(ULONG_PTR)hService,
-                                      Info);
+     _SEH_TRY
+     {
+         dwError = RChangeServiceConfig2A(BindingHandle,
 -                                         (SC_RPC_HANDLE)hService,
++                                         (SC_RPC_HANDLE)(ULONG_PTR)hService,
+                                          Info);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RChangeServiceConfig2A() failed (Error %lu)\n", dwError);
@@@ -170,9 -199,18 +199,18 @@@ ChangeServiceConfig2W(SC_HANDLE hServic
  
      HandleBind();
  
-     dwError = RChangeServiceConfig2W(BindingHandle,
-                                      (SC_RPC_HANDLE)hService,
-                                      Info);
+     _SEH_TRY
+     {
+         dwError = RChangeServiceConfig2W(BindingHandle,
+                                          (SC_RPC_HANDLE)hService,
+                                          Info);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RChangeServiceConfig2W() failed (Error %lu)\n", dwError);
@@@ -226,21 -264,30 +264,30 @@@ ChangeServiceConfigA(SC_HANDLE hService
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RChangeServiceConfigA(BindingHandle,
-                                     (SC_RPC_HANDLE)hService,
-                                     dwServiceType,
-                                     dwStartType,
-                                     dwErrorControl,
-                                     (LPSTR)lpBinaryPathName,
-                                     (LPSTR)lpLoadOrderGroup,
-                                     lpdwTagId,
-                                     (LPSTR)lpDependencies,
-                                     dwDependenciesLength,
-                                     (LPSTR)lpServiceStartName,
-                                     NULL,              /* FIXME: lpPassword */
-                                     0,                 /* FIXME: dwPasswordLength */
-                                     (LPSTR)lpDisplayName);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RChangeServiceConfigA(BindingHandle,
+                                         (SC_RPC_HANDLE)hService,
+                                         dwServiceType,
+                                         dwStartType,
+                                         dwErrorControl,
+                                         (LPSTR)lpBinaryPathName,
+                                         (LPSTR)lpLoadOrderGroup,
+                                         lpdwTagId,
+                                         (LPSTR)lpDependencies,
+                                         dwDependenciesLength,
+                                         (LPSTR)lpServiceStartName,
+                                         NULL,              /* FIXME: lpPassword */
+                                         0,                 /* FIXME: dwPasswordLength */
+                                         (LPSTR)lpDisplayName);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RChangeServiceConfigA() failed (Error %lu)\n", dwError);
@@@ -294,21 -341,30 +341,30 @@@ ChangeServiceConfigW(SC_HANDLE hService
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RChangeServiceConfigW(BindingHandle,
-                                     (SC_RPC_HANDLE)hService,
-                                     dwServiceType,
-                                     dwStartType,
-                                     dwErrorControl,
-                                     (LPWSTR)lpBinaryPathName,
-                                     (LPWSTR)lpLoadOrderGroup,
-                                     lpdwTagId,
-                                     (LPBYTE)lpDependencies,
-                                     dwDependenciesLength,
-                                     (LPWSTR)lpServiceStartName,
-                                     NULL,              /* FIXME: lpPassword */
-                                     0,                 /* FIXME: dwPasswordLength */
-                                     (LPWSTR)lpDisplayName);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RChangeServiceConfigW(BindingHandle,
+                                         (SC_RPC_HANDLE)hService,
+                                         dwServiceType,
+                                         dwStartType,
+                                         dwErrorControl,
+                                         (LPWSTR)lpBinaryPathName,
+                                         (LPWSTR)lpLoadOrderGroup,
+                                         lpdwTagId,
+                                         (LPBYTE)lpDependencies,
+                                         dwDependenciesLength,
+                                         (LPWSTR)lpServiceStartName,
+                                         NULL,              /* FIXME: lpPassword */
+                                         0,                 /* FIXME: dwPasswordLength */
+                                         (LPWSTR)lpDisplayName);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RChangeServiceConfigW() failed (Error %lu)\n", dwError);
@@@ -334,9 -390,18 +390,18 @@@ CloseServiceHandle(SC_HANDLE hSCObject
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RCloseServiceHandle(BindingHandle,
-                                   (LPSC_RPC_HANDLE)&hSCObject);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RCloseServiceHandle(BindingHandle,
+                                       (LPSC_RPC_HANDLE)&hSCObject);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError)
      {
          ERR("RCloseServiceHandle() failed (Error %lu)\n", dwError);
@@@ -367,11 -432,20 +432,20 @@@ ControlService(SC_HANDLE hService
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RControlService(BindingHandle,
-                               (SC_RPC_HANDLE)hService,
-                               dwControl,
-                               lpServiceStatus);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RControlService(BindingHandle,
+                                   (SC_RPC_HANDLE)hService,
+                                   dwControl,
+                                   lpServiceStatus);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RControlService() failed (Error %lu)\n", dwError);
@@@ -403,7 -477,6 +477,6 @@@ ControlServiceEx(IN SC_HANDLE hService
  }
  
  
  /**********************************************************************
   *  CreateServiceA
   *
@@@ -616,24 -689,33 +689,33 @@@ CreateServiceW(SC_HANDLE hSCManager
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RCreateServiceW(BindingHandle,
-                               (SC_RPC_HANDLE)hSCManager,
-                               (LPWSTR)lpServiceName,
-                               (LPWSTR)lpDisplayName,
-                               dwDesiredAccess,
-                               dwServiceType,
-                               dwStartType,
-                               dwErrorControl,
-                               (LPWSTR)lpBinaryPathName,
-                               (LPWSTR)lpLoadOrderGroup,
-                               lpdwTagId,
-                               (LPBYTE)lpDependencies,
-                               dwDependenciesLength,
-                               (LPWSTR)lpServiceStartName,
-                               NULL,              /* FIXME: lpPassword */
-                               0,                 /* FIXME: dwPasswordLength */
-                               (SC_RPC_HANDLE *)&hService);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RCreateServiceW(BindingHandle,
+                                   (SC_RPC_HANDLE)hSCManager,
+                                   (LPWSTR)lpServiceName,
+                                   (LPWSTR)lpDisplayName,
+                                   dwDesiredAccess,
+                                   dwServiceType,
+                                   dwStartType,
+                                   dwErrorControl,
+                                   (LPWSTR)lpBinaryPathName,
+                                   (LPWSTR)lpLoadOrderGroup,
+                                   lpdwTagId,
+                                   (LPBYTE)lpDependencies,
+                                   dwDependenciesLength,
+                                   (LPWSTR)lpServiceStartName,
+                                   NULL,              /* FIXME: lpPassword */
+                                   0,                 /* FIXME: dwPasswordLength */
+                                   (SC_RPC_HANDLE *)&hService);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RCreateServiceW() failed (Error %lu)\n", dwError);
@@@ -659,9 -741,18 +741,18 @@@ DeleteService(SC_HANDLE hService
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RDeleteService(BindingHandle,
-                              (SC_RPC_HANDLE)hService);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RDeleteService(BindingHandle,
+                                  (SC_RPC_HANDLE)hService);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RDeleteService() failed (Error %lu)\n", dwError);
@@@ -687,20 -778,28 +778,28 @@@ EnumDependentServicesA(SC_HANDLE hServi
                         LPDWORD lpServicesReturned)
  {
      LPENUM_SERVICE_STATUSA lpStatusPtr;
-     DWORD dwError = ERROR_SUCCESS;
+     DWORD dwError;
      DWORD dwCount;
  
      TRACE("EnumServicesStatusA() called\n");
  
      HandleBind();
  
-     dwError = REnumDependentServicesA(BindingHandle,
-                                       (SC_RPC_HANDLE)hService,
-                                       dwServiceState,
-                                       (LPBYTE)lpServices,
-                                       cbBufSize,
-                                       pcbBytesNeeded,
-                                       lpServicesReturned);
+     _SEH_TRY
+     {
+         dwError = REnumDependentServicesA(BindingHandle,
+                                           (SC_RPC_HANDLE)hService,
+                                           dwServiceState,
+                                           (LPBYTE)lpServices,
+                                           cbBufSize,
+                                           pcbBytesNeeded,
+                                           lpServicesReturned);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
  
      lpStatusPtr = (LPENUM_SERVICE_STATUSA)lpServices;
      for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
@@@ -743,20 -842,28 +842,28 @@@ EnumDependentServicesW(SC_HANDLE hServi
                         LPDWORD lpServicesReturned)
  {
      LPENUM_SERVICE_STATUSW lpStatusPtr;
-     DWORD dwError = ERROR_SUCCESS;
+     DWORD dwError;
      DWORD dwCount;
  
      TRACE("EnumServicesStatusW() called\n");
  
      HandleBind();
  
-     dwError = REnumDependentServicesW(BindingHandle,
-                                       (SC_RPC_HANDLE)hService,
-                                       dwServiceState,
-                                       (LPBYTE)lpServices,
-                                       cbBufSize,
-                                       pcbBytesNeeded,
-                                       lpServicesReturned);
+     _SEH_TRY
+     {
+         dwError = REnumDependentServicesW(BindingHandle,
+                                           (SC_RPC_HANDLE)hService,
+                                           dwServiceState,
+                                           (LPBYTE)lpServices,
+                                           cbBufSize,
+                                           pcbBytesNeeded,
+                                           lpServicesReturned);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
  
      lpStatusPtr = (LPENUM_SERVICE_STATUSW)lpServices;
      for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
@@@ -825,22 -932,30 +932,30 @@@ EnumServicesStatusA(SC_HANDLE hSCManage
                      LPDWORD lpResumeHandle)
  {
      LPENUM_SERVICE_STATUSA lpStatusPtr;
-     DWORD dwError = ERROR_SUCCESS;
+     DWORD dwError;
      DWORD dwCount;
  
      TRACE("EnumServicesStatusA() called\n");
  
      HandleBind();
  
-     dwError = REnumServicesStatusA(BindingHandle,
-                                    (SC_RPC_HANDLE)hSCManager,
-                                    dwServiceType,
-                                    dwServiceState,
-                                    (LPBYTE)lpServices,
-                                    cbBufSize,
-                                    pcbBytesNeeded,
-                                    lpServicesReturned,
-                                    lpResumeHandle);
+     _SEH_TRY
+     {
+         dwError = REnumServicesStatusA(BindingHandle,
+                                        (SC_RPC_HANDLE)hSCManager,
+                                        dwServiceType,
+                                        dwServiceState,
+                                        (LPBYTE)lpServices,
+                                        cbBufSize,
+                                        pcbBytesNeeded,
+                                        lpServicesReturned,
+                                        lpResumeHandle);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
  
      lpStatusPtr = (LPENUM_SERVICE_STATUSA)lpServices;
      for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
@@@ -885,22 -1000,30 +1000,30 @@@ EnumServicesStatusW(SC_HANDLE hSCManage
                      LPDWORD lpResumeHandle)
  {
      LPENUM_SERVICE_STATUSW lpStatusPtr;
-     DWORD dwError = ERROR_SUCCESS;
+     DWORD dwError;
      DWORD dwCount;
  
      TRACE("EnumServicesStatusW() called\n");
  
      HandleBind();
  
-     dwError = REnumServicesStatusW(BindingHandle,
-                                    (SC_RPC_HANDLE)hSCManager,
-                                    dwServiceType,
-                                    dwServiceState,
-                                    (LPBYTE)lpServices,
-                                    cbBufSize,
-                                    pcbBytesNeeded,
-                                    lpServicesReturned,
-                                    lpResumeHandle);
+     _SEH_TRY
+     {
+         dwError = REnumServicesStatusW(BindingHandle,
+                                        (SC_RPC_HANDLE)hSCManager,
+                                        dwServiceType,
+                                        dwServiceState,
+                                        (LPBYTE)lpServices,
+                                        cbBufSize,
+                                        pcbBytesNeeded,
+                                        lpServicesReturned,
+                                        lpResumeHandle);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
  
      lpStatusPtr = (LPENUM_SERVICE_STATUSW)lpServices;
      for (dwCount = 0; dwCount < *lpServicesReturned; dwCount++)
@@@ -947,24 -1070,32 +1070,32 @@@ EnumServicesStatusExA(SC_HANDLE hSCMana
                        LPCSTR pszGroupName)
  {
      LPENUM_SERVICE_STATUS_PROCESSA lpStatusPtr;
-     DWORD dwError = ERROR_SUCCESS;
+     DWORD dwError;
      DWORD dwCount;
  
      TRACE("EnumServicesStatusExA() called\n");
  
      HandleBind();
  
-     dwError = REnumServicesStatusExA(BindingHandle,
-                                      (SC_RPC_HANDLE)hSCManager,
-                                      InfoLevel,
-                                      dwServiceType,
-                                      dwServiceState,
-                                      (LPBYTE)lpServices,
-                                      cbBufSize,
-                                      pcbBytesNeeded,
-                                      lpServicesReturned,
-                                      lpResumeHandle,
-                                      (LPSTR)pszGroupName);
+     _SEH_TRY
+     {
+         dwError = REnumServicesStatusExA(BindingHandle,
+                                          (SC_RPC_HANDLE)hSCManager,
+                                          InfoLevel,
+                                          dwServiceType,
+                                          dwServiceState,
+                                          (LPBYTE)lpServices,
+                                          cbBufSize,
+                                          pcbBytesNeeded,
+                                          lpServicesReturned,
+                                          lpResumeHandle,
+                                          (LPSTR)pszGroupName);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
  
      if (dwError == ERROR_MORE_DATA)
      {
@@@ -1019,24 -1150,32 +1150,32 @@@ EnumServicesStatusExW(SC_HANDLE hSCMana
                        LPCWSTR pszGroupName)
  {
      LPENUM_SERVICE_STATUS_PROCESSW lpStatusPtr;
-     DWORD dwError = ERROR_SUCCESS;
+     DWORD dwError;
      DWORD dwCount;
  
      TRACE("EnumServicesStatusExW() called\n");
  
      HandleBind();
  
-     dwError = REnumServicesStatusExW(BindingHandle,
-                                      (SC_RPC_HANDLE)hSCManager,
-                                      InfoLevel,
-                                      dwServiceType,
-                                      dwServiceState,
-                                      (LPBYTE)lpServices,
-                                      cbBufSize,
-                                      pcbBytesNeeded,
-                                      lpServicesReturned,
-                                      lpResumeHandle,
-                                      (LPWSTR)pszGroupName);
+     _SEH_TRY
+     {
+         dwError = REnumServicesStatusExW(BindingHandle,
+                                          (SC_RPC_HANDLE)hSCManager,
+                                          InfoLevel,
+                                          dwServiceType,
+                                          dwServiceState,
+                                          (LPBYTE)lpServices,
+                                          cbBufSize,
+                                          pcbBytesNeeded,
+                                          lpServicesReturned,
+                                          lpResumeHandle,
+                                          (LPWSTR)pszGroupName);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
  
      if (dwError == ERROR_MORE_DATA)
      {
@@@ -1088,13 -1227,28 +1227,28 @@@ GetServiceDisplayNameA(SC_HANDLE hSCMan
  
      TRACE("GetServiceDisplayNameA() called\n");
  
+     if (!lpDisplayName)
+         *lpcchBuffer = 0;
      HandleBind();
  
-     dwError = RGetServiceDisplayNameA(BindingHandle,
-                                       (SC_RPC_HANDLE)hSCManager,
-                                       (LPSTR)lpServiceName,
-                                       lpDisplayName,
-                                       lpcchBuffer);
+     _SEH_TRY
+     {
+         dwError = RGetServiceDisplayNameA(BindingHandle,
+                                           (SC_RPC_HANDLE)hSCManager,
+                                           (LPSTR)lpServiceName,
+                                           lpDisplayName,
+                                           lpcchBuffer);
+     }
+     _SEH_HANDLE
+     {
+         /* HACK: because of a problem with rpcrt4, rpcserver is hacked to return 6 for ERROR_SERVICE_DOES_NOT_EXIST */
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RGetServiceDisplayNameA() failed (Error %lu)\n", dwError);
          return FALSE;
      }
  
-     (*lpcchBuffer)--;
      return TRUE;
  }
  
@@@ -1123,13 -1275,25 +1275,25 @@@ GetServiceDisplayNameW(SC_HANDLE hSCMan
  
      TRACE("GetServiceDisplayNameW() called\n");
  
+     if (!lpDisplayName)
+         *lpcchBuffer = 0;
      HandleBind();
  
-     dwError = RGetServiceDisplayNameW(BindingHandle,
-                                       (SC_RPC_HANDLE)hSCManager,
-                                       (LPWSTR)lpServiceName,
-                                       lpDisplayName,
-                                       lpcchBuffer);
+     _SEH_TRY
+     {
+         dwError = RGetServiceDisplayNameW(BindingHandle,
+                                           (SC_RPC_HANDLE)hSCManager,
+                                           (LPWSTR)lpServiceName,
+                                           lpDisplayName,
+                                           lpcchBuffer);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RGetServiceDisplayNameW() failed (Error %lu)\n", dwError);
          return FALSE;
      }
  
-     (*lpcchBuffer)--;
      return TRUE;
  }
  
@@@ -1158,13 -1320,25 +1320,25 @@@ GetServiceKeyNameA(SC_HANDLE hSCManager
  
      TRACE("GetServiceKeyNameA() called\n");
  
+     if (!lpServiceName)
+         *lpcchBuffer = 0;
      HandleBind();
  
-     dwError = RGetServiceKeyNameA(BindingHandle,
-                                   (SC_RPC_HANDLE)hSCManager,
-                                   (LPSTR)lpDisplayName,
-                                   lpServiceName,
-                                   lpcchBuffer);
+     _SEH_TRY
+     {
+         dwError = RGetServiceKeyNameA(BindingHandle,
+                                       (SC_RPC_HANDLE)hSCManager,
+                                       (LPSTR)lpDisplayName,
+                                       lpServiceName,
+                                       lpcchBuffer);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RGetServiceKeyNameA() failed (Error %lu)\n", dwError);
          return FALSE;
      }
  
-     (*lpcchBuffer)--;
      return TRUE;
  }
  
@@@ -1193,13 -1365,25 +1365,25 @@@ GetServiceKeyNameW(SC_HANDLE hSCManager
  
      TRACE("GetServiceKeyNameW() called\n");
  
+     if (!lpDisplayName)
+         *lpcchBuffer = 0;
      HandleBind();
  
-     dwError = RGetServiceKeyNameW(BindingHandle,
-                                   (SC_RPC_HANDLE)hSCManager,
-                                   (LPWSTR)lpDisplayName,
-                                   lpServiceName,
-                                   lpcchBuffer);
+     _SEH_TRY
+     {
+         dwError = RGetServiceKeyNameW(BindingHandle,
+                                       (SC_RPC_HANDLE)hSCManager,
+                                       (LPWSTR)lpDisplayName,
+                                       lpServiceName,
+                                       lpcchBuffer);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RGetServiceKeyNameW() failed (Error %lu)\n", dwError);
          return FALSE;
      }
  
-     (*lpcchBuffer)--;
      return TRUE;
  }
  
@@@ -1228,10 -1410,19 +1410,19 @@@ LockServiceDatabase(SC_HANDLE hSCManage
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RLockServiceDatabase(BindingHandle,
-                                    (SC_RPC_HANDLE)hSCManager,
-                                    (SC_RPC_LOCK *)&hLock);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RLockServiceDatabase(BindingHandle,
+                                        (SC_RPC_HANDLE)hSCManager,
+                                        (SC_RPC_LOCK *)&hLock);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RLockServiceDatabase() failed (Error %lu)\n", dwError);
@@@ -1305,12 -1496,21 +1496,21 @@@ OpenSCManagerA(LPCSTR lpMachineName
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = ROpenSCManagerA(BindingHandle,
-                               (LPSTR)lpMachineName,
-                               (LPSTR)lpDatabaseName,
-                               dwDesiredAccess,
-                               (SC_RPC_HANDLE *)&hScm);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = ROpenSCManagerA(BindingHandle,
+                                   (LPSTR)lpMachineName,
+                                   (LPSTR)lpDatabaseName,
+                                   dwDesiredAccess,
+                                   (SC_RPC_HANDLE *)&hScm);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("ROpenSCManagerA() failed (Error %lu)\n", dwError);
@@@ -1344,12 -1544,21 +1544,21 @@@ OpenSCManagerW(LPCWSTR lpMachineName
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = ROpenSCManagerW(BindingHandle,
-                               (LPWSTR)lpMachineName,
-                               (LPWSTR)lpDatabaseName,
-                               dwDesiredAccess,
-                               (SC_RPC_HANDLE *)&hScm);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = ROpenSCManagerW(BindingHandle,
+                                   (LPWSTR)lpMachineName,
+                                   (LPWSTR)lpDatabaseName,
+                                   dwDesiredAccess,
+                                   (SC_RPC_HANDLE *)&hScm);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("ROpenSCManagerW() failed (Error %lu)\n", dwError);
@@@ -1381,12 -1590,21 +1590,21 @@@ OpenServiceA(SC_HANDLE hSCManager
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = ROpenServiceA(BindingHandle,
-                             (SC_RPC_HANDLE)hSCManager,
-                             (LPSTR)lpServiceName,
-                             dwDesiredAccess,
-                             (SC_RPC_HANDLE *)&hService);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = ROpenServiceA(BindingHandle,
+                                 (SC_RPC_HANDLE)hSCManager,
+                                 (LPSTR)lpServiceName,
+                                 dwDesiredAccess,
+                                 (SC_RPC_HANDLE *)&hService);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("ROpenServiceA() failed (Error %lu)\n", dwError);
@@@ -1418,12 -1636,21 +1636,21 @@@ OpenServiceW(SC_HANDLE hSCManager
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = ROpenServiceW(BindingHandle,
-                             (SC_RPC_HANDLE)hSCManager,
-                             (LPWSTR)lpServiceName,
-                             dwDesiredAccess,
-                             (SC_RPC_HANDLE *)&hService);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = ROpenServiceW(BindingHandle,
+                                 (SC_RPC_HANDLE)hSCManager,
+                                 (LPWSTR)lpServiceName,
+                                 dwDesiredAccess,
+                                 (SC_RPC_HANDLE *)&hService);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          if (dwError == ERROR_SERVICE_DOES_NOT_EXIST)
@@@ -1458,12 -1685,21 +1685,21 @@@ QueryServiceConfigA(SC_HANDLE hService
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RQueryServiceConfigA(BindingHandle,
-                                    (SC_RPC_HANDLE)hService,
-                                    lpServiceConfig,
-                                    cbBufSize,
-                                    pcbBytesNeeded);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RQueryServiceConfigA(BindingHandle,
+                                        (SC_RPC_HANDLE)hService,
+                                        (LPBYTE)lpServiceConfig,
+                                        cbBufSize,
+                                        pcbBytesNeeded);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RQueryServiceConfigA() failed (Error %lu)\n", dwError);
@@@ -1521,12 -1757,21 +1757,21 @@@ QueryServiceConfigW(SC_HANDLE hService
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RQueryServiceConfigW(BindingHandle,
-                                    (SC_RPC_HANDLE)hService,
-                                    (LPBYTE)lpServiceConfig,
-                                    cbBufSize,
-                                    pcbBytesNeeded);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RQueryServiceConfigW(BindingHandle,
+                                        (SC_RPC_HANDLE)hService,
+                                        (LPBYTE)lpServiceConfig,
+                                        cbBufSize,
+                                        pcbBytesNeeded);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          if (dwError == ERROR_INSUFFICIENT_BUFFER)
@@@ -1586,15 -1831,38 +1831,38 @@@ QueryServiceConfig2A(SC_HANDLE hService
      TRACE("QueryServiceConfig2A(%p, %lu, %p, %lu, %p)\n",
             hService, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded);
  
+     if (dwInfoLevel != SERVICE_CONFIG_DESCRIPTION &&
+         dwInfoLevel != SERVICE_CONFIG_FAILURE_ACTIONS)
+     {
+         SetLastError(ERROR_INVALID_LEVEL);
+         return FALSE;
+     }
+     if ((lpBuffer == NULL && cbBufSize != 0) ||
+         pcbBytesNeeded == NULL)
+     {
+         SetLastError(ERROR_INVALID_ADDRESS);
+         return FALSE;
+     }
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RQueryServiceConfig2A(BindingHandle,
-                                     (SC_RPC_HANDLE)hService,
-                                     dwInfoLevel,
-                                     lpBuffer,
-                                     cbBufSize,
-                                     pcbBytesNeeded);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RQueryServiceConfig2A(BindingHandle,
+                                         (SC_RPC_HANDLE)hService,
+                                         dwInfoLevel,
+                                         lpBuffer,
+                                         cbBufSize,
+                                         pcbBytesNeeded);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RQueryServiceConfig2A() failed (Error %lu)\n", dwError);
@@@ -1661,15 -1929,38 +1929,38 @@@ QueryServiceConfig2W(SC_HANDLE hService
      TRACE("QueryServiceConfig2W(%p, %lu, %p, %lu, %p)\n",
             hService, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded);
  
+     if (dwInfoLevel != SERVICE_CONFIG_DESCRIPTION &&
+         dwInfoLevel != SERVICE_CONFIG_FAILURE_ACTIONS)
+     {
+         SetLastError(ERROR_INVALID_LEVEL);
+         return FALSE;
+     }
+     if ((lpBuffer == NULL && cbBufSize != 0) ||
+         pcbBytesNeeded == NULL)
+     {
+         SetLastError(ERROR_INVALID_ADDRESS);
+         return FALSE;
+     }
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RQueryServiceConfig2W(BindingHandle,
-                                     (SC_RPC_HANDLE)hService,
-                                     dwInfoLevel,
-                                     lpBuffer,
-                                     cbBufSize,
-                                     pcbBytesNeeded);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RQueryServiceConfig2W(BindingHandle,
+                                         (SC_RPC_HANDLE)hService,
+                                         dwInfoLevel,
+                                         lpBuffer,
+                                         cbBufSize,
+                                         pcbBytesNeeded);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RQueryServiceConfig2W() failed (Error %lu)\n", dwError);
@@@ -1736,12 -2027,21 +2027,21 @@@ QueryServiceLockStatusA(SC_HANDLE hSCMa
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RQueryServiceLockStatusA(BindingHandle,
-                                        (SC_RPC_HANDLE)hSCManager,
-                                        lpLockStatus,
-                                        cbBufSize,
-                                        pcbBytesNeeded);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RQueryServiceLockStatusA(BindingHandle,
+                                            (SC_RPC_HANDLE)hSCManager,
+                                            lpLockStatus,
+                                            cbBufSize,
+                                            pcbBytesNeeded);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RQueryServiceLockStatusA() failed (Error %lu)\n", dwError);
@@@ -1778,12 -2078,21 +2078,21 @@@ QueryServiceLockStatusW(SC_HANDLE hSCMa
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RQueryServiceLockStatusW(BindingHandle,
-                                        (SC_RPC_HANDLE)hSCManager,
-                                        lpLockStatus,
-                                        cbBufSize,
-                                        pcbBytesNeeded);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RQueryServiceLockStatusW(BindingHandle,
+                                            (SC_RPC_HANDLE)hSCManager,
+                                            lpLockStatus,
+                                            cbBufSize,
+                                            pcbBytesNeeded);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RQueryServiceLockStatusW() failed (Error %lu)\n", dwError);
@@@ -1822,13 -2131,22 +2131,22 @@@ QueryServiceObjectSecurity(SC_HANDLE hS
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RQueryServiceObjectSecurity(BindingHandle,
-                                           (SC_RPC_HANDLE)hService,
-                                           dwSecurityInformation,
-                                           (LPBYTE)lpSecurityDescriptor,
-                                           cbBufSize,
-                                           pcbBytesNeeded);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RQueryServiceObjectSecurity(BindingHandle,
+                                               (SC_RPC_HANDLE)hService,
+                                               dwSecurityInformation,
+                                               (LPBYTE)lpSecurityDescriptor,
+                                               cbBufSize,
+                                               pcbBytesNeeded);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("QueryServiceObjectSecurity() failed (Error %lu)\n", dwError);
@@@ -1883,12 -2201,20 +2201,20 @@@ SetServiceObjectSecurity(SC_HANDLE hSer
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RSetServiceObjectSecurity(BindingHandle,
-                                         (SC_RPC_HANDLE)hService,
-                                         dwSecurityInformation,
-                                         (LPBYTE)SelfRelativeSD,
-                                         Length);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RSetServiceObjectSecurity(BindingHandle,
+                                             (SC_RPC_HANDLE)hService,
+                                             dwSecurityInformation,
+                                             (LPBYTE)SelfRelativeSD,
+                                             Length);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
  
      HeapFree(GetProcessHeap(), 0, SelfRelativeSD);
  
@@@ -1919,10 -2245,19 +2245,19 @@@ QueryServiceStatus(SC_HANDLE hService
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RQueryServiceStatus(BindingHandle,
-                                   (SC_RPC_HANDLE)hService,
-                                   lpServiceStatus);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RQueryServiceStatus(BindingHandle,
+                                       (SC_RPC_HANDLE)hService,
+                                       lpServiceStatus);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RQueryServiceStatus() failed (Error %lu)\n", dwError);
@@@ -1952,13 -2287,22 +2287,22 @@@ QueryServiceStatusEx(SC_HANDLE hService
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RQueryServiceStatusEx(BindingHandle,
-                                     (SC_RPC_HANDLE)hService,
-                                     InfoLevel,
-                                     lpBuffer,
-                                     cbBufSize,
-                                     pcbBytesNeeded);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RQueryServiceStatusEx(BindingHandle,
+                                         (SC_RPC_HANDLE)hService,
+                                         InfoLevel,
+                                         lpBuffer,
+                                         cbBufSize,
+                                         pcbBytesNeeded);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RQueryServiceStatusEx() failed (Error %lu)\n", dwError);
@@@ -1982,11 -2326,18 +2326,18 @@@ StartServiceA(SC_HANDLE hService
  {
      DWORD dwError;
  
-     dwError = RStartServiceA(BindingHandle,
-                              (SC_RPC_HANDLE)hService,
-                              dwNumServiceArgs,
-                              (LPSTRING_PTRSA)lpServiceArgVectors);
+     _SEH_TRY
+     {
+         dwError = RStartServiceA(BindingHandle,
+                                  (SC_RPC_HANDLE)hService,
+                                  dwNumServiceArgs,
+                                  (LPSTRING_PTRSA)lpServiceArgVectors);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
  
      if (dwError != ERROR_SUCCESS)
      {
@@@ -2011,10 -2362,18 +2362,18 @@@ StartServiceW(SC_HANDLE hService
  {
      DWORD dwError;
  
-     dwError = RStartServiceW(BindingHandle,
-                              (SC_RPC_HANDLE)hService,
-                              dwNumServiceArgs,
-                              (LPSTRING_PTRSW)lpServiceArgVectors);
+     _SEH_TRY
+     {
+         dwError = RStartServiceW(BindingHandle,
+                                  (SC_RPC_HANDLE)hService,
+                                  dwNumServiceArgs,
+                                  (LPSTRING_PTRSW)lpServiceArgVectors);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
  
      if (dwError != ERROR_SUCCESS)
      {
@@@ -2041,9 -2400,18 +2400,18 @@@ UnlockServiceDatabase(SC_LOCK ScLock
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RUnlockServiceDatabase(BindingHandle,
-                                      (SC_RPC_LOCK)ScLock);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RUnlockServiceDatabase(BindingHandle,
+                                          (SC_RPC_LOCK)ScLock);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("RUnlockServiceDatabase() failed (Error %lu)\n", dwError);
@@@ -2069,10 -2437,19 +2437,19 @@@ NotifyBootConfigStatus(BOOL BootAccepta
  
      HandleBind();
  
-     /* Call to services.exe using RPC */
-     dwError = RNotifyBootConfigStatus(BindingHandle,
-                                       NULL,
-                                       BootAcceptable);
+     _SEH_TRY
+     {
+         /* Call to services.exe using RPC */
+         dwError = RNotifyBootConfigStatus(BindingHandle,
+                                           NULL,
+                                           BootAcceptable);
+     }
+     _SEH_HANDLE
+     {
+         dwError = ScmRpcStatusToWinError(RpcExceptionCode());
+     }
+     _SEH_END;
      if (dwError != ERROR_SUCCESS)
      {
          ERR("NotifyBootConfigStatus() failed (Error %lu)\n", dwError);
@@@ -1403,14 -1403,103 +1403,116 @@@ Wow64RevertWow64FsRedirection (VOID * p
      return FALSE;
  }
  
+ UINT
+ WINAPI
+ EnumSystemFirmwareTables(IN DWORD FirmwareTableProviderSignature,
+                          OUT PVOID pFirmwareTableBuffer,
+                          IN DWORD BufferSize)
+ {
+     STUB;
+     return 0;
+ }
+ BOOL
+ WINAPI
+ GetSystemFileCacheSize(OUT PSIZE_T lpMinimumFileCacheSize,
+                        OUT PSIZE_T lpMaximumFileCacheSize,
+                        OUT PDWORD lpFlags)
+ {
+     STUB;
+     return FALSE;
+ }
+ UINT
+ WINAPI
+ GetSystemFirmwareTable(IN DWORD FirmwareTableProviderSignature,
+                        IN DWORD FirmwareTableID,
+                        OUT PVOID pFirmwareTableBuffer,
+                        IN DWORD BufferSize)
+ {
+     STUB;
+     return 0;
+ }
+ BOOL
+ WINAPI
+ SetSystemFileCacheSize(IN SIZE_T MinimumFileCacheSize,
+                        IN SIZE_T MaximumFileCacheSize,
+                        IN DWORD Flags)
+ {
+     STUB;
+     return FALSE;
+ }
+ BOOL
+ WINAPI
+ SetThreadStackGuarantee(IN OUT PULONG StackSizeInBytes)
+ {
+     STUB;
+     return FALSE;
+ }
+ HANDLE
+ WINAPI
+ ReOpenFile(IN HANDLE hOriginalFile,
+            IN DWORD dwDesiredAccess,
+            IN DWORD dwShareMode,
+            IN DWORD dwFlags)
+ {
+     STUB;
+     return INVALID_HANDLE_VALUE;
+ }
+ BOOL
+ WINAPI
+ SetProcessWorkingSetSizeEx(IN HANDLE hProcess,
+                            IN SIZE_T dwMinimumWorkingSetSize,
+                            IN SIZE_T dwMaximumWorkingSetSize,
+                            IN DWORD Flags)
+ {
+     STUB;
+     return FALSE;
+ }
+ BOOL
+ WINAPI
+ GetProcessWorkingSetSizeEx(IN HANDLE hProcess,
+                            OUT PSIZE_T lpMinimumWorkingSetSize,
+                            OUT PSIZE_T lpMaximumWorkingSetSize,
+                            OUT PDWORD Flags)
+ {
+     STUB;
+     return FALSE;
+ }
+ BOOL
+ WINAPI
+ GetLogicalProcessorInformation(OUT PSYSTEM_LOGICAL_PROCESSOR_INFORMATION Buffer,
+                                IN OUT PDWORD ReturnLength)
+ {
+     STUB;
+     return FALSE;
+ }
+ BOOL
+ WINAPI
+ GetNumaAvailableMemoryNode(IN UCHAR Node,
+                            OUT PULONGLONG AvailableBytes)
+ {
+     STUB;
+     return FALSE;
+ }
++
 +BOOL WINAPI TermsrvAppInstallMode(void)
 +{
 +     STUB;
 +     return FALSE;
 +}
 +
 +DWORD WINAPI SetTermsrvAppInstallMode(BOOL bInstallMode)
 +{
 +    STUB;
 +    return 0;
 +}
++
    - implement ACO_RTLREADING style
  
   */
- #include "config.h"
- #include <stdarg.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #define COBJMACROS
- #include "wine/debug.h"
- #include "windef.h"
- #include "winbase.h"
- #include "winreg.h"
- #include "undocshell.h"
- #include "shlwapi.h"
- #include "winerror.h"
- #include "objbase.h"
- #include "pidl.h"
- #include "shlobj.h"
- #include "shldisp.h"
- #include "debughlp.h"
- #include "wine/unicode.h"
+ #include <precomp.h>
  
  WINE_DEFAULT_DEBUG_CHANNEL(shell);
  
@@@ -78,7 -58,7 +58,7 @@@ typedef struc
  static const IAutoCompleteVtbl acvt;
  static const IAutoComplete2Vtbl ac2vt;
  
- static inline IAutoCompleteImpl *impl_from_IAutoComplete2( IAutoComplete2 *iface )
+ static IAutoCompleteImpl * impl_from_IAutoComplete2( IAutoComplete2 *iface )
  {
      return (IAutoCompleteImpl *)((char*)iface - FIELD_OFFSET(IAutoCompleteImpl, lpvtblAutoComplete2));
  }
@@@ -234,7 -214,7 +214,7 @@@ static HRESULT WINAPI IAutoComplete_fnI
      static const WCHAR lbName[] = {'L','i','s','t','B','o','x',0};
  
      TRACE("(%p)->(0x%08lx, %p, %s, %s)\n",
 -        This, (long)hwndEdit, punkACL, debugstr_w(pwzsRegKeyPath), debugstr_w(pwszQuickComplete));
 +        This, hwndEdit, punkACL, debugstr_w(pwzsRegKeyPath), debugstr_w(pwszQuickComplete));
  
      if (This->options & ACO_AUTOSUGGEST) TRACE(" ACO_AUTOSUGGEST\n");
      if (This->options & ACO_AUTOAPPEND) TRACE(" ACO_AUTOAPPEND\n");
        LONG len;
  
        /* pwszRegKeyPath contains the key as well as the value, so we split */
-       key = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (lstrlenW(pwzsRegKeyPath)+1)*sizeof(WCHAR));
-       strcpyW(key, pwzsRegKeyPath);
+       key = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (wcslen(pwzsRegKeyPath)+1)*sizeof(WCHAR));
+       wcscpy(key, pwzsRegKeyPath);
        value = strrchrW(key, '\\');
        *value = 0;
        value++;
            res = RegQueryValueW(hKey, value, result, &len);
            if (res == ERROR_SUCCESS) {
                This->quickComplete = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len*sizeof(WCHAR));
-               strcpyW(This->quickComplete, result);
+               wcscpy(This->quickComplete, result);
            }
            RegCloseKey(hKey);
        }
      }
  
      if ((pwszQuickComplete) && (!This->quickComplete)) {
-       This->quickComplete = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (lstrlenW(pwszQuickComplete)+1)*sizeof(WCHAR));
-       lstrcpyW(This->quickComplete, pwszQuickComplete);
+       This->quickComplete = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (wcslen(pwszQuickComplete)+1)*sizeof(WCHAR));
+       wcscpy(This->quickComplete, pwszQuickComplete);
      }
  
      return S_OK;
@@@ -484,8 -464,8 +464,8 @@@ static LRESULT APIENTRY ACEditSubclassP
                    control = GetKeyState(VK_CONTROL) & 0x8000;
                    if (control && This->quickComplete) {
                        hwndQCText = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-                                                      (lstrlenW(This->quickComplete)+lstrlenW(hwndText))*sizeof(WCHAR));
-                       sel = sprintfW(hwndQCText, This->quickComplete, hwndText);
+                                                      (wcslen(This->quickComplete)+wcslen(hwndText))*sizeof(WCHAR));
+                       sel = swprintf(hwndQCText, This->quickComplete, hwndText);
                        SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)hwndQCText);
                        SendMessageW(hwnd, EM_SETSEL, 0, sel);
                        HeapFree(GetProcessHeap(), 0, hwndQCText);
                                msg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (len+1)*sizeof(WCHAR));
                                SendMessageW(This->hwndListBox, LB_GETTEXT, sel, (LPARAM)msg);
                                SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)msg);
-                               SendMessageW(hwnd, EM_SETSEL, lstrlenW(msg), lstrlenW(msg));
+                               SendMessageW(hwnd, EM_SETSEL, wcslen(msg), wcslen(msg));
                                HeapFree(GetProcessHeap(), 0, msg);
                            } else {
                                SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)This->txtbackup);
-                               SendMessageW(hwnd, EM_SETSEL, lstrlenW(This->txtbackup), lstrlenW(This->txtbackup));
+                               SendMessageW(hwnd, EM_SETSEL, wcslen(This->txtbackup), wcslen(This->txtbackup));
                            }
                        }
                        return 0;
  
            HeapFree(GetProcessHeap(), 0, This->txtbackup);
            This->txtbackup = HeapAlloc(GetProcessHeap(),
-                                                HEAP_ZERO_MEMORY, (lstrlenW(hwndText)+1)*sizeof(WCHAR));
-           lstrcpyW(This->txtbackup, hwndText);
+                                                HEAP_ZERO_MEMORY, (wcslen(hwndText)+1)*sizeof(WCHAR));
+           wcscpy(This->txtbackup, hwndText);
  
            /* Returns if there is no text to search and we doesn't want to display all the entries */
            if ((!displayall) && (! *hwndText) )
  
                    if (This->options & ACO_AUTOAPPEND) {
                        SetWindowTextW(hwnd, strs);
-                       SendMessageW(hwnd, EM_SETSEL, lstrlenW(hwndText), lstrlenW(strs));
+                       SendMessageW(hwnd, EM_SETSEL, wcslen(hwndText), wcslen(strs));
                        break;
                    }
  
@@@ -638,7 -618,7 +618,7 @@@ static LRESULT APIENTRY ACLBoxSubclassP
            msg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (len+1)*sizeof(WCHAR));
            SendMessageW(hwnd, LB_GETTEXT, sel, (LPARAM)msg);
            SendMessageW(This->hwndEdit, WM_SETTEXT, 0, (LPARAM)msg);
-           SendMessageW(This->hwndEdit, EM_SETSEL, 0, lstrlenW(msg));
+           SendMessageW(This->hwndEdit, EM_SETSEL, 0, wcslen(msg));
            ShowWindow(hwnd, SW_HIDE);
            HeapFree(GetProcessHeap(), 0, msg);
            break;
   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
   */
  
- #include <stdarg.h>
- #include <string.h>
+ #include <precomp.h>
  
- #define NONAMELESSUNION
- #define NONAMELESSSTRUCT
- #include "windef.h"
- #include "winbase.h"
- #include "wine/debug.h"
- #include "shell32_main.h"
  
  WINE_DEFAULT_DEBUG_CHANNEL(shell);
  
@@@ -35,7 -28,7 +28,7 @@@ static CRITICAL_SECTION_DEBUG critsect_
  {
      0, 0, &SHELL32_ChangenotifyCS,
      { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
 -      0, 0, { (DWORD_PTR)(__FILE__ ": SHELL32_ChangenotifyCS") }
 +      0, 0, { (DWORD_PTR)0/*(__FILE__ ": SHELL32_ChangenotifyCS")*/ }
  };
  static CRITICAL_SECTION SHELL32_ChangenotifyCS = { &critsect_debug, -1, 0, 0, 0, 0 };
  
@@@ -192,7 -185,7 +185,7 @@@ SHChangeNotifyRegister
      LONG wEventMask,
      UINT uMsg,
      int cItems,
-     SHChangeNotifyEntry *lpItems)
+     const SHChangeNotifyEntry *lpItems)
  {
      LPNOTIFICATIONLIST item;
      int i;
  
      LeaveCriticalSection(&SHELL32_ChangenotifyCS);
  
 -    return (ULONG)item;
 +    return PtrToUlong(item);
  }
  
  /*************************************************************************
@@@ -239,7 -232,7 +232,7 @@@ BOOL WINAPI SHChangeNotifyDeregister(UL
  
      EnterCriticalSection(&SHELL32_ChangenotifyCS);
  
 -    node = FindNode((HANDLE)hNotify);
 +    node = FindNode((HANDLE)UlongToPtr(hNotify));
      if( node )
          DeleteNode(node);
  
@@@ -315,8 -308,8 +308,8 @@@ void WINAPI SHChangeNotify(LONG wEventI
      switch (typeFlag)
      {
      case SHCNF_PATHA:
-         if (dwItem1) Pidls[0] = SHSimpleIDListFromPathA((LPCSTR)dwItem1);
-         if (dwItem2) Pidls[1] = SHSimpleIDListFromPathA((LPCSTR)dwItem2);
+         if (dwItem1) Pidls[0] = SHSimpleIDListFromPathA((LPCSTR)dwItem1); //FIXME
+         if (dwItem2) Pidls[1] = SHSimpleIDListFromPathA((LPCSTR)dwItem2); //FIXME
          break;
      case SHCNF_PATHW:
          if (dwItem1) Pidls[0] = SHSimpleIDListFromPathW((LPCWSTR)dwItem1);
@@@ -17,6 -17,7 +17,7 @@@ static VOID SatisfyAccept( PAFD_DEVICE_
                             PFILE_OBJECT NewFileObject,
                                   PAFD_TDI_OBJECT_QELT Qelt ) {
      PAFD_FCB FCB = NewFileObject->FsContext;
+     NTSTATUS Status;
  
      if( !SocketAcquireStateLock( FCB ) ) { 
          LostSocket( Irp );
      /* Transfer the connection to the new socket, launch the opening read */
      AFD_DbgPrint(MID_TRACE,("Completing a real accept (FCB %x)\n", FCB));
  
-     FCB->State = SOCKET_STATE_CONNECTED;
      FCB->Connection = Qelt->Object;
+     if( FCB->RemoteAddress ) ExFreePool( FCB->RemoteAddress );
      FCB->RemoteAddress =
        TaCopyTransportAddress( Qelt->ConnInfo->RemoteAddress );
  
-     if( Irp->MdlAddress ) UnlockRequest( Irp, IoGetCurrentIrpStackLocation( Irp ) );
+     if( !FCB->RemoteAddress ) 
+       Status = STATUS_NO_MEMORY;
+     else
+       Status = MakeSocketIntoConnection( FCB );
+     if( NT_SUCCESS(Status) ) {
+       FCB->PollState |= AFD_EVENT_SEND;
+       PollReeval( DeviceExt, NewFileObject );
+     }
  
+     if( Irp->MdlAddress ) UnlockRequest( Irp, IoGetCurrentIrpStackLocation( Irp ) );
+     
      Irp->IoStatus.Information = 0;
-     Irp->IoStatus.Status = STATUS_SUCCESS;
+     Irp->IoStatus.Status = Status;
      IoCompleteRequest( Irp, IO_NETWORK_INCREMENT );
  
-     MakeSocketIntoConnection( FCB );
-     FCB->PollState |= AFD_EVENT_SEND;
-     PollReeval( DeviceExt, NewFileObject );
      SocketStateUnlock( FCB );
  }
  
@@@ -61,6 -69,13 +69,13 @@@ static VOID SatisfyPreAccept( PIRP Irp
  
      IPAddr = (PTA_IP_ADDRESS)&ListenReceive->Address;
  
+     if( !IPAddr ) {
+       if( Irp->MdlAddress ) UnlockRequest( Irp, IoGetCurrentIrpStackLocation( Irp ) );
+       Irp->IoStatus.Status = STATUS_NO_MEMORY;
+       Irp->IoStatus.Information = 0;
+       IoCompleteRequest( Irp, IO_NETWORK_INCREMENT );
+     }
      AFD_DbgPrint(MID_TRACE,("IPAddr->TAAddressCount %d\n",
                              IPAddr->TAAddressCount));
      AFD_DbgPrint(MID_TRACE,("IPAddr->Address[0].AddressType %d\n",
@@@ -83,17 -98,16 +98,16 @@@ static NTSTATUS NTAPI ListenComplet
  ( PDEVICE_OBJECT DeviceObject,
    PIRP Irp,
    PVOID Context ) {
-     NTSTATUS Status = STATUS_UNSUCCESSFUL;
+     NTSTATUS Status = STATUS_SUCCESS;
      PAFD_FCB FCB = (PAFD_FCB)Context;
      PAFD_TDI_OBJECT_QELT Qelt;
  
-     if ( Irp->Cancel ) {
-       /* FIXME: is this anything else we need to do? */
-       FCB->ListenIrp.InFlightRequest = NULL;
-       return STATUS_SUCCESS;
+     if( Irp->Cancel ) {
+       if( FCB ) FCB->ListenIrp.InFlightRequest = NULL;
+       return STATUS_CANCELLED;
      }
  
-     if( !SocketAcquireStateLock( FCB ) ) return Status;
+     if( !SocketAcquireStateLock( FCB ) ) return STATUS_FILE_CLOSED;
  
      FCB->ListenIrp.InFlightRequest = NULL;
  
  
      Qelt = ExAllocatePool( NonPagedPool, sizeof(*Qelt) );
      if( !Qelt ) {
+       /* Is this correct? */
        TdiCloseDevice( FCB->Connection.Handle,
                        FCB->Connection.Object );
+       Status = STATUS_NO_MEMORY;
      } else {
          UINT AddressType =
              FCB->LocalAddress->Address[0].AddressType;
                                  ConnectionReturnInfo->RemoteAddress));
  
          TdiBuildNullConnectionInfo( &Qelt->ConnInfo, AddressType );
-         TaCopyTransportAddressInPlace
-             ( Qelt->ConnInfo->RemoteAddress,
-               FCB->ListenIrp.ConnectionReturnInfo->RemoteAddress );
-       InsertTailList( &FCB->PendingConnections, &Qelt->ListEntry );
+         if( Qelt->ConnInfo ) {
+             TaCopyTransportAddressInPlace
+                ( Qelt->ConnInfo->RemoteAddress,
+                  FCB->ListenIrp.ConnectionReturnInfo->RemoteAddress );
+             InsertTailList( &FCB->PendingConnections, &Qelt->ListEntry );
+         } else Status = STATUS_NO_MEMORY;
      }
  
      /* Satisfy a pre-accept request if one is available */
  
      SocketStateUnlock( FCB );
  
-     return STATUS_SUCCESS;
+     return Status;
  }
  
  NTSTATUS AfdListenSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
                                       0, NULL );
  
      if( FCB->State != SOCKET_STATE_BOUND ) {
-       Status = STATUS_UNSUCCESSFUL;
+       Status = STATUS_INVALID_PARAMETER;
        AFD_DbgPrint(MID_TRACE,("Could not listen an unbound socket\n"));
        return UnlockAndMaybeComplete( FCB, Status, Irp, 0, NULL );
      }
  
      if( !NT_SUCCESS(Status) ) return UnlockAndMaybeComplete( FCB, Status, Irp, 0, NULL );
  
-     FCB->State = SOCKET_STATE_LISTENING;
      TdiBuildNullConnectionInfo
        ( &FCB->ListenIrp.ConnectionCallInfo,
          FCB->LocalAddress->Address[0].AddressType );
        ( &FCB->ListenIrp.ConnectionReturnInfo,
          FCB->LocalAddress->Address[0].AddressType );
  
+     if( !FCB->ListenIrp.ConnectionReturnInfo || !FCB->ListenIrp.ConnectionCallInfo )
+       return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY, Irp, 0, NULL );
+     FCB->State = SOCKET_STATE_LISTENING;
      Status = TdiListen( &FCB->ListenIrp.InFlightRequest,
                        FCB->Connection.Object,
                        &FCB->ListenIrp.ConnectionCallInfo,
  
  NTSTATUS AfdWaitForListen( PDEVICE_OBJECT DeviceObject, PIRP Irp,
                           PIO_STACK_LOCATION IrpSp ) {
-     NTSTATUS Status = STATUS_SUCCESS;
      PFILE_OBJECT FileObject = IrpSp->FileObject;
      PAFD_FCB FCB = FileObject->FsContext;
  
          PollReeval( FCB->DeviceExt, FCB->FileObject );
  
        SocketStateUnlock( FCB );
-       return Status;
+       return Irp->IoStatus.Status;
      } else {
        AFD_DbgPrint(MID_TRACE,("Holding\n"));
  
@@@ -272,6 -291,8 +291,8 @@@ NTSTATUS AfdAccept( PDEVICE_OBJECT Devi
                ( &FCB->ListenIrp.ConnectionReturnInfo,
                  FCB->LocalAddress->Address[0].AddressType );
  
+           if( !FCB->ListenIrp.ConnectionReturnInfo ) return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY, Irp, 0, NULL );
            Status = TdiListen( &FCB->ListenIrp.InFlightRequest,
                                FCB->Connection.Object,
                                &FCB->ListenIrp.ConnectionCallInfo,
            RemoveEntryList( PendingConn );
  
            Status = ObReferenceObjectByHandle
 -              ( (HANDLE)AcceptData->ListenHandle,
 +              ( (HANDLE)(ULONG_PTR)AcceptData->ListenHandle,
                  FILE_ALL_ACCESS,
                  NULL,
                  KernelMode,
                  (PVOID *)&NewFileObject,
                  NULL );
  
+             if( !NT_SUCCESS(Status) ) UnlockAndMaybeComplete( FCB, Status, Irp, 0, NULL );
              ASSERT(NewFileObject != FileObject);
              ASSERT(NewFileObject->FsContext != FCB);
  
  
            ExFreePool( PendingConnObj );
  
-           if( IsListEmpty( &FCB->PendingConnections ) )
+           if( IsListEmpty( &FCB->PendingConnections ) ) {
                FCB->PollState &= ~AFD_EVENT_ACCEPT;
+               PollReeval( FCB->DeviceExt, FCB->FileObject );
+           }
  
            SocketStateUnlock( FCB );
-           return Status;
+           return Irp->IoStatus.Status;
        }
      }
  
-     SocketStateUnlock( FCB );
-     return STATUS_UNSUCCESSFUL;
+     return UnlockAndMaybeComplete( FCB, STATUS_UNSUCCESSFUL, Irp, 0, NULL );
  }
@@@ -15,6 -15,8 +15,8 @@@
  
  /* Lock a method_neither request so it'll be available from DISPATCH_LEVEL */
  PVOID LockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp ) {
+     BOOLEAN LockFailed = FALSE;
      Irp->MdlAddress =
        IoAllocateMdl( IrpSp->Parameters.DeviceIoControl.Type3InputBuffer,
                       IrpSp->Parameters.DeviceIoControl.InputBufferLength,
                       FALSE,
                       NULL );
      if( Irp->MdlAddress ) {
-       MmProbeAndLockPages( Irp->MdlAddress, KernelMode, IoModifyAccess );
+       _SEH_TRY {
+           MmProbeAndLockPages( Irp->MdlAddress, KernelMode, IoModifyAccess );
+       } _SEH_HANDLE {
+           LockFailed = TRUE;
+       } _SEH_END;
+       if( LockFailed ) {
+           IoFreeMdl( Irp->MdlAddress );
+           Irp->MdlAddress = NULL;
+           return NULL;
+       }
        IrpSp->Parameters.DeviceIoControl.Type3InputBuffer =
-           MmMapLockedPages( Irp->MdlAddress, KernelMode );
+           MmGetSystemAddressForMdlSafe( Irp->MdlAddress, NormalPagePriority );
+       if( !IrpSp->Parameters.DeviceIoControl.Type3InputBuffer ) {
+           IoFreeMdl( Irp->MdlAddress );
+           Irp->MdlAddress = NULL;
+           return NULL;
+       }    
        return IrpSp->Parameters.DeviceIoControl.Type3InputBuffer;
      } else return NULL;
  }
  
  VOID UnlockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp ) {
-     MmUnmapLockedPages( IrpSp->Parameters.DeviceIoControl.Type3InputBuffer,
-                       Irp->MdlAddress );
-     MmUnlockPages( Irp->MdlAddress );
-     IoFreeMdl( Irp->MdlAddress );
+     PVOID Buffer = MmGetSystemAddressForMdlSafe( Irp->MdlAddress, NormalPagePriority );
+     if( IrpSp->Parameters.DeviceIoControl.Type3InputBuffer == Buffer || Buffer == NULL ) {
+       MmUnmapLockedPages( IrpSp->Parameters.DeviceIoControl.Type3InputBuffer, Irp->MdlAddress );
+         MmUnlockPages( Irp->MdlAddress );
+         IoFreeMdl( Irp->MdlAddress );
+     }
      Irp->MdlAddress = NULL;
  }
  
@@@ -50,6 -73,7 +73,7 @@@ PAFD_WSABUF LockBuffers( PAFD_WSABUF Bu
      UINT Size = sizeof(AFD_WSABUF) * (Count + Lock);
      PAFD_WSABUF NewBuf = ExAllocatePool( PagedPool, Size * 2 );
      PMDL NewMdl;
+     BOOLEAN LockFailed = FALSE;
  
      AFD_DbgPrint(MID_TRACE,("Called(%08x)\n", NewBuf));
  
  
            if( MapBuf[i].Mdl ) {
                AFD_DbgPrint(MID_TRACE,("Probe and lock pages\n"));
-               MmProbeAndLockPages( MapBuf[i].Mdl, KernelMode,
-                                    Write ? IoModifyAccess : IoReadAccess );
+               _SEH_TRY {
+                   MmProbeAndLockPages( MapBuf[i].Mdl, KernelMode,
+                                        Write ? IoModifyAccess : IoReadAccess );
+               } _SEH_HANDLE {
+                   LockFailed = TRUE;
+               } _SEH_END;
                AFD_DbgPrint(MID_TRACE,("MmProbeAndLock finished\n"));
-           }
+               if( LockFailed ) {
+                   IoFreeMdl( MapBuf[i].Mdl );
+                   MapBuf[i].Mdl = NULL;
+                   ExFreePool( NewBuf );
+                   return NULL;
+               }
+           } else {
+               ExFreePool( NewBuf );
+               return NULL;
+           }     
        }
      }
  
@@@ -130,7 -168,7 +168,7 @@@ VOID UnlockBuffers( PAFD_WSABUF Buf, UI
   * pointers.  This will allow the system to do proper alerting */
  PAFD_HANDLE LockHandles( PAFD_HANDLE HandleArray, UINT HandleCount ) {
      UINT i;
-     NTSTATUS Status;
+     NTSTATUS Status = STATUS_SUCCESS;
  
      PAFD_HANDLE FileObjects = ExAllocatePool
        ( NonPagedPool, HandleCount * sizeof(AFD_HANDLE) );
        HandleArray[i].Status = 0;
        HandleArray[i].Events = HandleArray[i].Events;
          FileObjects[i].Handle = 0;
-       Status = ObReferenceObjectByHandle
-           ( (PVOID)(ULONG_PTR)HandleArray[i].Handle,
-             FILE_ALL_ACCESS,
-             NULL,
-             KernelMode,
-             (PVOID*)&FileObjects[i].Handle,
-             NULL );
+       if( !HandleArray[i].Handle ) continue;
+       if( NT_SUCCESS(Status) ) {
+               Status = ObReferenceObjectByHandle
 -              ( (PVOID)HandleArray[i].Handle,
++              ( (PVOID)(ULONG_PTR)HandleArray[i].Handle,
+                FILE_ALL_ACCESS,
+                NULL,
+                KernelMode,
+                (PVOID*)&FileObjects[i].Handle,
+                NULL );
+       }
+     }
+     if( !NT_SUCCESS(Status) ) {
+       UnlockHandles( FileObjects, HandleCount );
+       return NULL;
      }
  
      return FileObjects;
@@@ -156,7 -202,7 +202,7 @@@ VOID UnlockHandles( PAFD_HANDLE HandleA
  
      for( i = 0; i < HandleCount; i++ ) {
        if( HandleArray[i].Handle )
 -          ObDereferenceObject( (PVOID)HandleArray[i].Handle );
 +          ObDereferenceObject( (PVOID)(ULONG_PTR)HandleArray[i].Handle );
      }
  
      ExFreePool( HandleArray );
@@@ -167,7 -213,7 +213,7 @@@ UINT SocketAcquireStateLock( PAFD_FCB F
      NTSTATUS Status = STATUS_SUCCESS;
      PVOID CurrentThread = KeGetCurrentThread();
  
-     ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
+     ASSERT(KeGetCurrentIrql() <= APC_LEVEL);
  
      AFD_DbgPrint(MAX_TRACE,("Called on %x, attempting to lock\n", FCB));
  
@@@ -218,7 -264,7 +264,7 @@@ VOID SocketStateUnlock( PAFD_FCB FCB ) 
      PVOID CurrentThread = KeGetCurrentThread();
  #endif
      ASSERT(FCB->LockCount > 0);
-     ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
+     ASSERT(KeGetCurrentIrql() <= APC_LEVEL);
  
      ExAcquireFastMutex( &FCB->Mutex );
      FCB->LockCount--;
@@@ -262,7 -308,7 +308,7 @@@ NTSTATUS NTAPI UnlockAndMaybeComplet
  
  
  NTSTATUS LostSocket( PIRP Irp ) {
-     NTSTATUS Status = STATUS_INVALID_PARAMETER;
+     NTSTATUS Status = STATUS_FILE_CLOSED;
      AFD_DbgPrint(MIN_TRACE,("Called.\n"));
      Irp->IoStatus.Information = 0;
      Irp->IoStatus.Status = Status;
@@@ -30,7 -30,7 +30,7 @@@ void OskitDumpBuffer( PCHAR Data, UINT 
  
      for( i = 0; i < Len; i++ ) {
        if( i && !(i & 0xf) ) DbgPrint( "\n" );
 -      if( !(i & 0xf) ) DbgPrint( "%08x: ", (UINT)(Data + i) );
 +      if( !(i & 0xf) ) DbgPrint( "%08x: ", (UINT_PTR)(Data + i) );
        DbgPrint( " %02x", Data[i] & 0xff );
      }
      DbgPrint("\n");
@@@ -190,9 -190,8 +190,8 @@@ VOID DestroySocket( PAFD_FCB FCB ) 
        if( InFlightRequest[i]->InFlightRequest ) {
            AFD_DbgPrint(MID_TRACE,("Cancelling in flight irp %d (%x)\n",
                                    i, InFlightRequest[i]->InFlightRequest));
-           InFlightRequest[i]->InFlightRequest->IoStatus.Status = STATUS_CANCELLED;
-           InFlightRequest[i]->InFlightRequest->IoStatus.Information = 0;
-           IoCancelIrp( InFlightRequest[i]->InFlightRequest );
+           IoCancelIrp(InFlightRequest[i]->InFlightRequest);
+           InFlightRequest[i]->InFlightRequest = NULL;
        }
      }
  
        ExFreePool( FCB->LocalAddress );
      if( FCB->RemoteAddress )
        ExFreePool( FCB->RemoteAddress );
-     ExFreePool(FCB->TdiDeviceName.Buffer);
+     if( FCB->ListenIrp.ConnectionReturnInfo )
+       ExFreePool( FCB->ListenIrp.ConnectionReturnInfo );
+     if( FCB->ListenIrp.ConnectionCallInfo )
+       ExFreePool( FCB->ListenIrp.ConnectionCallInfo );
+     if( FCB->TdiDeviceName.Buffer )
+       ExFreePool(FCB->TdiDeviceName.Buffer);
  
      ExFreePool(FCB);
      AFD_DbgPrint(MIN_TRACE,("Deleted (%x)\n", FCB));
@@@ -133,7 -133,7 +133,7 @@@ NdisImmediateReadPortUchar
      OUT PUCHAR      Data)
  {
    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
 -  *Data = READ_PORT_UCHAR((PUCHAR)Port); // FIXME: What to do with WrapperConfigurationContext?
 +  *Data = READ_PORT_UCHAR(UlongToPtr(Port)); // FIXME: What to do with WrapperConfigurationContext?
  }
  
  \f
@@@ -148,7 -148,7 +148,7 @@@ NdisImmediateReadPortUlong
      OUT PULONG      Data)
  {
    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
 -  *Data = READ_PORT_ULONG((PULONG)Port); // FIXME: What to do with WrapperConfigurationContext?
 +  *Data = READ_PORT_ULONG(UlongToPtr(Port)); // FIXME: What to do with WrapperConfigurationContext?
  }
  
  \f
@@@ -163,7 -163,7 +163,7 @@@ NdisImmediateReadPortUshort
      OUT PUSHORT     Data)
  {
    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
 -  *Data = READ_PORT_USHORT((PUSHORT)Port); // FIXME: What to do with WrapperConfigurationContext?
 +  *Data = READ_PORT_USHORT(UlongToPtr(Port)); // FIXME: What to do with WrapperConfigurationContext?
  }
  
  \f
@@@ -178,7 -178,7 +178,7 @@@ NdisImmediateWritePortUchar
      IN  UCHAR       Data)
  {
    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
 -  WRITE_PORT_UCHAR((PUCHAR)Port, Data); // FIXME: What to do with WrapperConfigurationContext?
 +  WRITE_PORT_UCHAR(UlongToPtr(Port), Data); // FIXME: What to do with WrapperConfigurationContext?
  }
  
  \f
@@@ -193,7 -193,7 +193,7 @@@ NdisImmediateWritePortUlong
      IN  ULONG       Data)
  {
    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
 -  WRITE_PORT_ULONG((PULONG)Port, Data); // FIXME: What to do with WrapperConfigurationContext?
 +  WRITE_PORT_ULONG(UlongToPtr(Port), Data); // FIXME: What to do with WrapperConfigurationContext?
  }
  
  \f
@@@ -208,7 -208,7 +208,7 @@@ NdisImmediateWritePortUshort
      IN  USHORT      Data)
  {
    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
 -  WRITE_PORT_USHORT((PUSHORT)Port, Data); // FIXME: What to do with WrapperConfigurationContext?
 +  WRITE_PORT_USHORT(UlongToPtr(Port), Data); // FIXME: What to do with WrapperConfigurationContext?
  }
  
  \f
@@@ -841,6 -841,8 +841,8 @@@ NdisMRegisterIoPortRange
    PNDIS_MINIPORT_BLOCK Adapter  = (PNDIS_MINIPORT_BLOCK)MiniportAdapterHandle;
    ULONG                AddressSpace = 1;    /* FIXME The HAL handles this wrong atm */
  
+   *PortOffset = 0;
    NDIS_DbgPrint(MAX_TRACE, ("Called - InitialPort 0x%x, NumberOfPorts 0x%x\n", InitialPort, NumberOfPorts));
  
    memset(&PortAddress, 0, sizeof(PortAddress));
  
    NDIS_DbgPrint(MAX_TRACE, ("calling MmMapIoSpace\n"));
  
-   *PortOffset = 0;
    *PortOffset = MmMapIoSpace(TranslatedAddress, NumberOfPorts, MmNonCached);
    NDIS_DbgPrint(MAX_TRACE, ("Returning 0x%x for port range\n", *PortOffset));
  
@@@ -53,34 -53,6 +53,6 @@@ NTSTATUS DispPrepareIrpForCancel
      return IRPFinish(Irp, STATUS_CANCELLED);
  }
  
- VOID DispCancelComplete(
-     PVOID Context)
- /*
-  * FUNCTION: Completes a cancel request
-  * ARGUMENTS:
-  *     Context = Pointer to context information (FILE_OBJECT)
-  */
- {
-     /*KIRQL OldIrql;*/
-     PFILE_OBJECT FileObject;
-     PTRANSPORT_CONTEXT TranContext;
-     TI_DbgPrint(DEBUG_IRP, ("Called.\n"));
-     FileObject  = (PFILE_OBJECT)Context;
-     TranContext = (PTRANSPORT_CONTEXT)FileObject->FsContext;
-     /* Set the cleanup event */
-     KeSetEvent(&TranContext->CleanupEvent, 0, FALSE);
-     /* We are expected to release the cancel spin lock */
-     /*IoReleaseCancelSpinLock(OldIrql);*/
-     TI_DbgPrint(DEBUG_IRP, ("Leaving.\n"));
- }
  VOID DispDataRequestComplete(
      PVOID Context,
      NTSTATUS Status,
@@@ -155,8 -127,6 +127,6 @@@ VOID DispDoDisconnect( PVOID Data ) 
      TI_DbgPrint(DEBUG_IRP, ("PostCancel: DoDisconnect done\n"));
  
      DispDataRequestComplete(DisType->Irp, STATUS_CANCELLED, 0);
-     DispCancelComplete(DisType->FileObject);
  }
  
  VOID NTAPI DispCancelRequest(
        if( !ChewCreate( &WorkItem, sizeof(DISCONNECT_TYPE),
                         DispDoDisconnect, &DisType ) )
            ASSERT(0);
-         break;
+       IoReleaseCancelSpinLock(Irp->CancelIrql);
+         return;
  
      case TDI_SEND_DATAGRAM:
          if (FileObject->FsContext2 != (PVOID)TDI_TRANSPORT_ADDRESS_FILE) {
              TI_DbgPrint(MIN_TRACE, ("TDI_SEND_DATAGRAM, but no address file.\n"));
              break;
          }
-         /*DGCancelSendRequest(TranContext->Handle.AddressHandle, Irp);*/
          break;
  
      case TDI_RECEIVE_DATAGRAM:
              break;
          }
  
-         /*DGCancelReceiveRequest(TranContext->Handle.AddressHandle, Irp);*/
+         DGRemoveIRP(TranContext->Handle.AddressHandle, Irp);
          break;
  
      default:
      }
  
      IoReleaseCancelSpinLock(Irp->CancelIrql);
+     IoCompleteRequest(Irp, IO_NO_INCREMENT);
  
      TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));
  }
@@@ -280,8 -251,6 +251,6 @@@ VOID NTAPI DispCancelListenRequest
  
      DispDataRequestComplete(Irp, STATUS_CANCELLED, 0);
  
-     DispCancelComplete(FileObject);
      TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));
  }
  
@@@ -662,7 -631,7 +631,7 @@@ NTSTATUS DispTdiQueryInformation
  
          AddressInfo = (PTDI_ADDRESS_INFO)MmGetSystemAddressForMdl(Irp->MdlAddress);
  
 -        switch ((ULONG)IrpSp->FileObject->FsContext2) {
 +        switch ((ULONG_PTR)IrpSp->FileObject->FsContext2) {
            case TDI_TRANSPORT_ADDRESS_FILE:
              AddrFile = (PADDRESS_FILE)TranContext->Handle.AddressHandle;
              break;
          AddressInfo = (PTDI_CONNECTION_INFORMATION)
            MmGetSystemAddressForMdl(Irp->MdlAddress);
  
 -        switch ((ULONG)IrpSp->FileObject->FsContext2) {
 +        switch ((ULONG_PTR)IrpSp->FileObject->FsContext2) {
            case TDI_TRANSPORT_ADDRESS_FILE:
              AddrFile = (PADDRESS_FILE)TranContext->Handle.AddressHandle;
              break;
@@@ -1007,16 -976,12 +976,16 @@@ NTSTATUS DispTdiSendDatagram
                     (*((PADDRESS_FILE)Request.Handle.AddressHandle)->Send)));
  
          if( (*((PADDRESS_FILE)Request.Handle.AddressHandle)->Send) )
 +        {
 +              ULONG DataUsed = 0;
              Status = (*((PADDRESS_FILE)Request.Handle.AddressHandle)->Send)(
                  Request.Handle.AddressHandle,
                  DgramInfo->SendDatagramInformation,
                  DataBuffer,
                  BufferSize,
 -                &Irp->IoStatus.Information);
 +                &DataUsed);
 +            Irp->IoStatus.Information = DataUsed;
 +        }
          else
              Status = STATUS_UNSUCCESSFUL;
  
@@@ -1280,7 -1245,7 +1249,7 @@@ NTSTATUS DispTdiQueryInformationEx
  
      TranContext = (PTRANSPORT_CONTEXT)IrpSp->FileObject->FsContext;
  
 -    switch ((ULONG)IrpSp->FileObject->FsContext2) {
 +    switch ((ULONG_PTR)IrpSp->FileObject->FsContext2) {
      case TDI_TRANSPORT_ADDRESS_FILE:
          Request.Handle.AddressHandle = TranContext->Handle.AddressHandle;
          break;
@@@ -1455,7 -1420,7 +1424,7 @@@ NTSTATUS DispTdiSetInformationEx
      TranContext = (PTRANSPORT_CONTEXT)IrpSp->FileObject->FsContext;
      Info        = (PTCP_REQUEST_SET_INFORMATION_EX)Irp->AssociatedIrp.SystemBuffer;
  
 -    switch ((ULONG)IrpSp->FileObject->FsContext2) {
 +    switch ((ULONG_PTR)IrpSp->FileObject->FsContext2) {
      case TDI_TRANSPORT_ADDRESS_FILE:
          Request.Handle.AddressHandle = TranContext->Handle.AddressHandle;
          break;
@@@ -3,11 -3,11 +3,12 @@@
  <module name="pciidex" type="kernelmodedriver" installbase="system32/drivers" installname="pciidex.sys">
        <importlibrary definition="pciidex.spec.def" />
        <library>ntoskrnl</library>
 +      <file>pciidex.spec</file>
        <file>fdo.c</file>
        <file>miniport.c</file>
        <file>misc.c</file>
        <file>pciidex.c</file>
        <file>pdo.c</file>
        <file>pciidex.rc</file>
+       <file>pciidex.spec</file>
  </module>
@@@ -1,22 -1,22 +1,4 @@@
--/*
-- *  ReactOS kernel
-- *  Copyright (C) 2001, 2002, 2003 ReactOS Team
-- *
-- *  This program is free software; you can redistribute it and/or modify
-- *  it under the terms of the GNU General Public License as published by
-- *  the Free Software Foundation; either version 2 of the License, or
-- *  (at your option) any later version.
-- *
-- *  This program is distributed in the hope that it will be useful,
-- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
-- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- *  GNU General Public License for more details.
-- *
-- *  You should have received a copy of the GNU General Public License
-- *  along with this program; if not, write to the Free Software
-- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-- */
- /* $Id$
+ /* $Id: diskdump.c 29690 2007-10-19 23:21:45Z dreimer $
   *
   * COPYRIGHT:       See COPYING in the top level directory
   * PROJECT:         ReactOS Kernel
@@@ -366,9 -366,9 +348,9 @@@ DiskDumpPrepare(PDEVICE_OBJECT DeviceOb
            }
          else // hint-name
            {
 -            Name = (PCHAR)((ULONG)DriverBase +
 -                            *FunctionNameList + 2);
 -            Hint = *(PUSHORT)((ULONG)DriverBase + *FunctionNameList);
 +            Name = (PCHAR)((ULONG_PTR)DriverBase +
 +                            (ULONG_PTR)*FunctionNameList + 2);
 +            Hint = *(PUSHORT)((ULONG_PTR)DriverBase + (ULONG_PTR)*FunctionNameList);
            }
  #if 0
          DPRINT("  Hint:%04x  Name:%s\n", Hint, pName);
diff --combined reactos/hal/hal/hal.c
@@@ -49,7 -49,7 +49,7 @@@ VOI
  NTAPI
  HalStopProfileInterrupt(IN KPROFILE_SOURCE ProfileSource)
  {
-     KEBUGCHECK(0);
+     ASSERT(FALSE);
      return;
  }
  
@@@ -60,7 -60,7 +60,7 @@@ VOI
  NTAPI
  HalStartProfileInterrupt(IN KPROFILE_SOURCE ProfileSource)
  {
-     KEBUGCHECK(0);
+     ASSERT(FALSE);
      return;
  }
  
@@@ -71,11 -71,10 +71,11 @@@ ULONG_PT
  NTAPI
  HalSetProfileInterval(IN ULONG_PTR Interval)
  {
-     KEBUGCHECK(0);
+     ASSERT(FALSE);
      return Interval;
  }
  
 +#ifndef _M_AMD64
  VOID
  FASTCALL
  ExAcquireFastMutex(
@@@ -102,7 -101,7 +102,7 @@@ ExTryToAcquireFastMutex
  
    return TRUE;
  }
 -
 +#endif
  
  VOID
  NTAPI
@@@ -467,7 -466,7 +467,7 @@@ HalReportResourceUsage(VOID
  VOID
  NTAPI
  HalRequestIpi(
 -  ULONG Unknown)
 +    KAFFINITY TargetSet)
  {
    UNIMPLEMENTED;
  }
@@@ -785,7 -784,6 +785,7 @@@ KeFlushWriteBuffer(VOID
    UNIMPLEMENTED;
  }
  
 +#ifndef _M_AMD64
  #undef KeGetCurrentIrql
  KIRQL
  NTAPI
@@@ -804,7 -802,6 +804,7 @@@ KeLowerIrql
  {
    UNIMPLEMENTED;
  }
 +#endif
  
  
  LARGE_INTEGER
@@@ -821,7 -818,6 +821,7 @@@ KeQueryPerformanceCounter
    return Value;
  }
  
 +#ifndef _M_AMD64
  #undef KeRaiseIrql
  VOID
  NTAPI
@@@ -851,7 -847,6 +851,7 @@@ KeRaiseIrqlToSynchLevel(VOID
  
    return (KIRQL)0;
  }
 +#endif
  
  #undef KeReleaseSpinLock
  VOID
@@@ -896,7 -891,7 +896,7 @@@ KeTryToAcquireQueuedSpinLockRaiseToSync
    return FALSE;
  }
  
 -
 +#if !defined(_M_AMD64)
  KIRQL
  FASTCALL
  KfAcquireSpinLock(
@@@ -936,9 -931,8 +936,9 @@@ KfReleaseSpinLock
  {
    UNIMPLEMENTED;
  }
 +#endif
  
 -
 +#if !defined(_M_AMD64)
  VOID
  NTAPI
  READ_PORT_BUFFER_UCHAR(
@@@ -1064,7 -1058,6 +1064,7 @@@ WRITE_PORT_USHORT
  {
    UNIMPLEMENTED;
  }
 +#endif
  
  KIRQL
  FASTCALL
@@@ -228,7 -228,7 +228,7 @@@ __inline ULONG _APICRead(ULONG Offset
  {
     PULONG p;
  
 -   p = (PULONG)((ULONG)APICBase + Offset);
 +   p = (PULONG)((ULONG_PTR)APICBase + Offset);
     return *p;
  }
  
@@@ -238,7 -238,7 +238,7 @@@ __inline VOID APICWrite(ULONG Offset
  {
     PULONG p;
  
 -   p = (PULONG)((ULONG)APICBase + Offset);
 +   p = (PULONG)((ULONG_PTR)APICBase + Offset);
  
     *p = Value;
  }
@@@ -252,7 -252,7 +252,7 @@@ __inline VOID APICWrite(ULONG Offset
     lastregw[CPU] = Offset;
     lastvalw[CPU] = Value;
  
 -   p = (PULONG)((ULONG)APICBase + Offset);
 +   p = (PULONG)((ULONG_PTR)APICBase + Offset);
  
     *p = Value;
  }
@@@ -264,7 -264,7 +264,7 @@@ __inline ULONG APICRead(ULONG Offset
  {
     PULONG p;
  
 -   p = (PULONG)((ULONG)APICBase + Offset);
 +   p = (PULONG)((ULONG_PTR)APICBase + Offset);
     return *p;
  }
  #else
@@@ -276,7 -276,7 +276,7 @@@ __inline ULONG APICRead(ULONG Offset
     lastregr[CPU] = Offset;
     lastvalr[CPU] = 0;
  
 -   p = (PULONG)((ULONG)APICBase + Offset);
 +   p = (PULONG)((ULONG_PTR)APICBase + Offset);
  
     lastvalr[CPU] = *p;
     return lastvalr[CPU];
@@@ -775,9 -775,6 +775,9 @@@ VOI
  MpsIRQTrapFrameToTrapFrame(PKIRQ_TRAPFRAME IrqTrapFrame,
                           PKTRAP_FRAME TrapFrame)
  {
 +#ifdef _M_AMD64
 +    UNIMPLEMENTED;
 +#else
     TrapFrame->SegGs     = (USHORT)IrqTrapFrame->Gs;
     TrapFrame->SegFs     = (USHORT)IrqTrapFrame->Fs;
     TrapFrame->SegEs     = (USHORT)IrqTrapFrame->Es;
     TrapFrame->Eip    = IrqTrapFrame->Eip;
     TrapFrame->SegCs     = IrqTrapFrame->Cs;
     TrapFrame->EFlags = IrqTrapFrame->Eflags;
 +#endif
  }
  
  VOID
@@@ -868,7 -864,7 +868,7 @@@ APICCalibrateTimer(ULONG CPU
  
     APICSetupLVTT(1000000000);
  
 -   TSCPresent = ((PKIPCR)KeGetPcr())->PrcbData.FeatureBits & KF_RDTSC ? TRUE : FALSE;
 +   TSCPresent = KeGetCurrentPrcb()->FeatureBits & KF_RDTSC ? TRUE : FALSE;
  
     /*
      * The timer chip counts down to zero. Let's wait
        DPRINT("CPU clock speed is %ld.%04ld MHz.\n",
             CPUMap[CPU].CoreSpeed/1000000,
             CPUMap[CPU].CoreSpeed%1000000);
 -      ((PKIPCR)KeGetPcr())->PrcbData.MHz = CPUMap[CPU].CoreSpeed/1000000;
 +      KeGetCurrentPrcb()->MHz = CPUMap[CPU].CoreSpeed/1000000;
     }
  
     CPUMap[CPU].BusSpeed = (HZ * (long)(tt1 - tt2) * APIC_DIVISOR);
  }
  
  VOID 
 -SetInterruptGate(ULONG index, ULONG address)
 +SetInterruptGate(ULONG index, ULONG_PTR address)
  {
 +#ifdef _M_AMD64
 +UNIMPLEMENTED;
 +#else
    KIDTENTRY *idt;
    KIDT_ACCESS Access;
  
    idt->Selector = KGDT_R0_CODE;
    idt->Access = Access.Value;
    idt->ExtendedOffset = address >> 16;
 +#endif
  }
  
  VOID HaliInitBSP(VOID)
     /* Only initialize the BSP once */
     if (BSPInitialized)
     {
-       KEBUGCHECK(0);
+       ASSERT(FALSE);
        return;
     }
  
     BSPInitialized = TRUE;
  
     /* Setup interrupt handlers */
 -   SetInterruptGate(LOCAL_TIMER_VECTOR, (ULONG)MpsTimerInterrupt);
 -   SetInterruptGate(ERROR_VECTOR, (ULONG)MpsErrorInterrupt);
 -   SetInterruptGate(SPURIOUS_VECTOR, (ULONG)MpsSpuriousInterrupt);
 +   SetInterruptGate(LOCAL_TIMER_VECTOR, (ULONG_PTR)MpsTimerInterrupt);
 +   SetInterruptGate(ERROR_VECTOR, (ULONG_PTR)MpsErrorInterrupt);
 +   SetInterruptGate(SPURIOUS_VECTOR, (ULONG_PTR)MpsSpuriousInterrupt);
  #ifdef CONFIG_SMP
 -   SetInterruptGate(IPI_VECTOR, (ULONG)MpsIpiInterrupt);
 +   SetInterruptGate(IPI_VECTOR, (ULONG_PTR)MpsIpiInterrupt);
  #endif
     DPRINT("APIC is mapped at 0x%X\n", APICBase);
  
     else 
     {
        DPRINT("No APIC found\n");
-       KEBUGCHECK(0);
+       ASSERT(FALSE);
     }
  
     if (APICMode == amPIC) 
@@@ -1021,7 -1013,7 +1021,7 @@@ HaliStartApplicationProcessor(ULONG Cpu
         Cpu >= CPUCount ||
         OnlineCPUs & (1 << Cpu))
     {
-      KEBUGCHECK(0);
+      ASSERT(FALSE);
     }
     DPRINT1("Attempting to boot CPU %d\n", Cpu);
  
@@@ -5438,8 -5438,6 +5438,8 @@@ typedef struct _KPCR 
    ULONG HalReserved[16];            // For use by Hal
  } KPCR, *PKPCR;                 /* 54 */
  
 +#define KeGetPcr()                      PCR
 +
  typedef struct _KFLOATING_SAVE {
    ULONG  ControlWord;
    ULONG  StatusWord;
@@@ -5657,8 -5655,6 +5657,8 @@@ typedef struct _KPCR 
    UCHAR  Number;                /* 51 */
  } KPCR, *PKPCR;                 /* 54 */
  
 +#define KeGetPcr()                      PCR
 +
  static __inline
  ULONG
  DDKAPI
@@@ -5693,8 -5689,6 +5693,8 @@@ typedef struct _KPCR 
      ULONG  IDR;                   /* 30 */
  } KPCR, *PKPCR;
  
 +#define KeGetPcr()                      PCR
 +
  typedef struct _KFLOATING_SAVE {
  } KFLOATING_SAVE, *PKFLOATING_SAVE;
  
@@@ -5792,7 -5786,6 +5792,7 @@@ typedef struct _PCIBUSDAT
  } PCIBUSDATA, *PPCIBUSDATA;
  
  
 +/** INTERLOCKED FUNCTIONS *****************************************************/
  
  #if !defined(__INTERLOCKED_DECLARED)
  #define __INTERLOCKED_DECLARED
@@@ -5909,97 -5902,64 +5909,97 @@@ InterlockedExchangeAdd
  #define InterlockedPushEntrySList(Head, Entry) ExpInterlockedPushEntrySList(Head, Entry)
  #define InterlockedFlushSList(Head) ExpInterlockedFlushSList(Head)
  #define QueryDepthSList(Head) ExQueryDepthSList(Head)
 -#endif // !defined(_WINBASE_
 +#endif // !defined(_WINBASE_)
  
  #endif // _M_AMD64
  
  #endif /* !__INTERLOCKED_DECLARED */
  
 +
 +/** SPINLOCK FUNCTIONS ********************************************************/
 +
  NTKERNELAPI
 -VOID
 +BOOLEAN
  FASTCALL
 -KefAcquireSpinLockAtDpcLevel(
 -  IN PKSPIN_LOCK  SpinLock);
 +KeTryToAcquireSpinLockAtDpcLevel(
 +    IN OUT PKSPIN_LOCK SpinLock
 +);
 +
 +#if defined (_X86_)
  
  NTKERNELAPI
  VOID
 -FASTCALL
 -KefReleaseSpinLockFromDpcLevel(
 +NTAPI
 +KeInitializeSpinLock(
    IN PKSPIN_LOCK  SpinLock);
  
 -#if defined(_M_AMD64)
 -NTKERNELAPI
 +NTHALAPI
  KIRQL
  FASTCALL
  KfAcquireSpinLock(
    IN PKSPIN_LOCK SpinLock);
  
 -NTKERNELAPI
 +NTHALAPI
  VOID
  FASTCALL
  KfReleaseSpinLock(
    IN PKSPIN_LOCK SpinLock,
    IN KIRQL NewIrql);
 -#else
 -NTHALAPI
 -KIRQL
 -FASTCALL
 -KfAcquireSpinLock(
 -  IN PKSPIN_LOCK SpinLock);
  
 -NTHALAPI
 +NTKERNELAPI
  VOID
  FASTCALL
 -KfReleaseSpinLock(
 -  IN PKSPIN_LOCK SpinLock,
 -  IN KIRQL NewIrql);
 -#endif
 +KefAcquireSpinLockAtDpcLevel(
 +  IN PKSPIN_LOCK  SpinLock);
  
  NTKERNELAPI
 -BOOLEAN
 +VOID
  FASTCALL
 -KeTryToAcquireSpinLockAtDpcLevel(
 -    IN OUT PKSPIN_LOCK SpinLock
 -);
 +KefReleaseSpinLockFromDpcLevel(
 +  IN PKSPIN_LOCK  SpinLock);
  
  #define KeAcquireSpinLockAtDpcLevel(SpinLock) KefAcquireSpinLockAtDpcLevel(SpinLock)
  #define KeReleaseSpinLockFromDpcLevel(SpinLock) KefReleaseSpinLockFromDpcLevel(SpinLock)
  #define KeAcquireSpinLock(a,b)  *(b) = KfAcquireSpinLock(a)
  #define KeReleaseSpinLock(a,b)  KfReleaseSpinLock(a,b)
  
 +#else // !defined (_X86_)
 +
 +FORCEINLINE
 +VOID
 +NTAPI
 +KeInitializeSpinLock(
 +  PKSPIN_LOCK SpinLock)
 +{
 +    *SpinLock = 0;
 +}
 +
 +NTKERNELAPI
 +VOID
 +KeReleaseSpinLock(
 +  IN PKSPIN_LOCK SpinLock,
 +  IN KIRQL NewIrql);
 +
 +NTKERNELAPI
 +VOID
 +KeAcquireSpinLockAtDpcLevel(
 +  IN PKSPIN_LOCK SpinLock);
 +
 +NTKERNELAPI
 +VOID
 +KeReleaseSpinLockFromDpcLevel(
 +  IN PKSPIN_LOCK SpinLock);
 +
 +NTKERNELAPI
 +KIRQL
 +KeAcquireSpinLockRaiseToDpc(
 +  IN PKSPIN_LOCK SpinLock);
 +
 +#define KeAcquireSpinLock(SpinLock, OldIrql) \
 +  *(OldIrql) = KeAcquireSpinLockRaiseToDpc(SpinLock)
 +
 +#endif // !defined (_X86_)
 +
  #define RtlCopyMemoryNonTemporal RtlCopyMemory
  
  #define KeGetDcacheFillSize() 1L
@@@ -6398,23 -6358,17 +6398,23 @@@ RtlConvertLongToLargeInteger(LONG Signe
      return Result;
  }
  
 +static __inline
 +LARGE_INTEGER
 +NTAPI_INLINE
 +RtlConvertUlongToLargeInteger(
 +  ULONG UnsignedInteger)
 +{
 +    LARGE_INTEGER ret;
 +    ret.QuadPart = UnsignedInteger;
 +    return ret;
 +}
 +
  NTSYSAPI
  LUID
  NTAPI
  RtlConvertLongToLuid(
    IN LONG  Long);
  
 -NTSYSAPI
 -LARGE_INTEGER
 -NTAPI
 -RtlConvertUlongToLargeInteger(
 -  IN ULONG  UnsignedInteger);
  
  NTSYSAPI
  LUID
@@@ -6422,37 -6376,6 +6422,37 @@@ NTAP
  RtlConvertUlongToLuid(
    ULONG  Ulong);
  
 +#ifdef _M_AMD64
 +
 +static __inline
 +LARGE_INTEGER
 +NTAPI_INLINE
 +RtlExtendedIntegerMultiply(
 +  LARGE_INTEGER Multiplicand,
 +  LONG Multiplier)
 +{
 +    LARGE_INTEGER ret;
 +    ret.QuadPart = Multiplicand.QuadPart * Multiplier;
 +    return ret;
 +}
 +
 +static __inline
 +LARGE_INTEGER
 +NTAPI_INLINE
 +RtlExtendedLargeIntegerDivide(
 +  LARGE_INTEGER Dividend,
 +  ULONG Divisor,
 +  PULONG Remainder)
 +{
 +    LARGE_INTEGER ret;
 +    ret.QuadPart = (ULONG64)Dividend.QuadPart / Divisor;
 +    if (Remainder)
 +        *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
 +    return ret;
 +}
 +
 +#endif
 +
  /*
   * VOID
   * RtlCopyMemory(
@@@ -9658,6 -9581,12 +9658,6 @@@ KeInitializeSemaphore
    IN LONG  Count,
    IN LONG  Limit);
  
 -NTKERNELAPI
 -VOID
 -NTAPI
 -KeInitializeSpinLock(
 -  IN PKSPIN_LOCK  SpinLock);
 -
  NTKERNELAPI
  VOID
  NTAPI
@@@ -11481,6 -11410,9 +11481,9 @@@ NTAP
  PoSetDeviceBusy(
    PULONG  IdlePointer);
  
+ #define PoSetDeviceBusy(IdlePointer) \
+  ((void)(*(IdlePointer) = 0))
  NTKERNELAPI
  POWER_STATE
  NTAPI
@@@ -107,6 -107,11 +107,6 @@@ Author
  #define KINTERRUPT_DISPATCH_CODES       106
  #endif
  
 -//
 -// Get KPCR
 -//
 -#define KeGetPcr()                      PCR
 -
  #ifdef NTOS_MODE_USER
  
  //
@@@ -536,17 -541,6 +536,6 @@@ typedef enum _KAPC_ENVIRONMEN
      InsertApcEnvironment
  } KAPC_ENVIRONMENT;
  
- //
- // CPU Cache Types
- //
- typedef enum _PROCESSOR_CACHE_TYPE
- {
-     CacheUnified,
-     CacheInstruction,
-     CacheData,
-     CacheTrace,
- } PROCESSOR_CACHE_TYPE;
  //
  // PRCB DPC Data
  //
@@@ -567,18 -561,6 +556,6 @@@ typedef struct _PP_LOOKASIDE_LIS
      struct _GENERAL_LOOKASIDE *L;
  } PP_LOOKASIDE_LIST, *PPP_LOOKASIDE_LIST;
  
- //
- // CPU Cache Descriptor
- //
- typedef struct _CACHE_DESCRIPTOR
- {
-     UCHAR Level;
-     UCHAR Associativity;
-     USHORT LineSize;
-     ULONG Size;
-     PROCESSOR_CACHE_TYPE Type;
- } CACHE_DESCRIPTOR, *PCACHE_DESCRIPTOR;
  //
  // Architectural Types
  //
@@@ -947,10 -929,10 +924,10 @@@ typedef struct _KPROCES
      DISPATCHER_HEADER Header;
      LIST_ENTRY ProfileListHead;
  #if (NTDDI_VERSION >= NTDDI_LONGHORN)
 -    ULONG DirectoryTableBase;
 -    ULONG Unused0;
 +    ULONG_PTR DirectoryTableBase;
 +    ULONG_PTR Unused0;
  #else
 -    ULONG DirectoryTableBase[2];
 +    ULONG_PTR DirectoryTableBase[2];
  #endif
  #if defined(_M_IX86)
      KGDTENTRY LdtDescriptor;
@@@ -140,39 -140,41 +140,39 @@@ typedef WCHAR *PWCHAR,*LPWCH,*PWCH,*NWP
  typedef CONST WCHAR *LPCWCH,*PCWCH,*LPCWSTR,*PCWSTR;
  typedef CHAR *PCHAR,*LPCH,*PCH,*NPSTR,*LPSTR,*PSTR;
  typedef CONST CHAR *LPCCH,*PCCH,*PCSTR,*LPCSTR;
 +typedef PWSTR *PZPWSTR;
 +typedef CONST PWSTR *PCZPWSTR;
 +typedef WCHAR UNALIGNED *LPUWSTR,*PUWSTR;
 +typedef PCWSTR *PZPCWSTR;
 +typedef CONST WCHAR UNALIGNED *LPCUWSTR,*PCUWSTR;
 +typedef PSTR *PZPSTR;
 +typedef CONST PSTR *PCZPSTR;
 +typedef PCSTR *PZPCSTR;
 +
 +#ifdef UNICODE
  #ifndef _TCHAR_DEFINED
  #define _TCHAR_DEFINED
 -#ifdef UNICODE
 -/*
 - * NOTE: This tests UNICODE, which is different from the _UNICODE define
 - *       used to differentiate standard C runtime calls.
 - */
 -typedef WCHAR TCHAR;
 -typedef WCHAR _TCHAR;
 -#else
 -typedef CHAR TCHAR;
 -typedef CHAR _TCHAR;
 -#endif
 +  typedef WCHAR TCHAR,*PTCHAR;
 +  typedef WCHAR TBYTE ,*PTBYTE;
  #endif
 -typedef TCHAR TBYTE,*PTCH,*PTBYTE;
 -typedef TCHAR *LPTCH,*PTSTR,*LPTSTR,*LP,*PTCHAR;
 -typedef const TCHAR *LPCTSTR;
 -#ifdef UNICODE
 -/*
 - * __TEXT is a private macro whose specific use is to force the expansion of a
 - * macro passed as an argument to the macro TEXT.  DO NOT use this
 - * macro within your programs.  It's name and function could change without
 - * notice.
 - */
 -#define __TEXT(q) L##q
 +  typedef LPWSTR LPTCH,PTCH,PTSTR,LPTSTR,LP,PTCHAR;
 +  typedef LPCWSTR PCTSTR,LPCTSTR;
 +  typedef LPUWSTR PUTSTR,LPUTSTR;
 +  typedef LPCUWSTR PCUTSTR,LPCUTSTR;
 +#define __TEXT(quote) L##quote
  #else
 -#define __TEXT(q) q
 +#ifndef _TCHAR_DEFINED
 +#define _TCHAR_DEFINED
 +  typedef char TCHAR,*PTCHAR;
 +  typedef unsigned char TBYTE ,*PTBYTE;
  #endif
 -/*
 - * UNICODE a constant string when UNICODE is defined, else returns the string
 - * unmodified.
 - * The corresponding macros  _TEXT() and _T() for mapping _UNICODE strings
 - * passed to C runtime functions are defined in mingw/tchar.h
 - */
 -#define TEXT(q) __TEXT(q)
 +  typedef LPSTR LPTCH,PTCH,PTSTR,LPTSTR,PUTSTR,LPUTSTR,PTCHAR;
 +  typedef LPCSTR PCTSTR,LPCTSTR,PCUTSTR,LPCUTSTR;
 +#define __TEXT(quote) quote
 +#endif
 +
 +#define TEXT(quote) __TEXT(quote)
 +
  typedef SHORT *PSHORT;
  typedef LONG *PLONG;
  #ifdef STRICT
@@@ -1518,9 -1520,6 +1518,9 @@@ typedef enu
  #define IMAGE_REL_BASED_HIGHLOW 3
  #define IMAGE_REL_BASED_HIGHADJ 4
  #define IMAGE_REL_BASED_MIPS_JMPADDR 5
 +#define IMAGE_REL_BASED_MIPS_JMPADDR16 9
 +#define IMAGE_REL_BASED_IA64_IMM64 9
 +#define IMAGE_REL_BASED_DIR64 10
  #define IMAGE_ARCHIVE_START_SIZE 8
  #define IMAGE_ARCHIVE_START "!<arch>\n"
  #define IMAGE_ARCHIVE_END "`\n"
@@@ -4401,6 -4400,45 +4401,45 @@@ typedef OSVERSIONINFOEXA OSVERSIONINFOE
  ULONGLONG WINAPI VerSetConditionMask(ULONGLONG,DWORD,BYTE);
  #endif
  
+ typedef enum _PROCESSOR_CACHE_TYPE {
+     CacheUnified,
+     CacheInstruction,
+     CacheData,
+     CacheTrace 
+ } PROCESSOR_CACHE_TYPE;
+ typedef enum _LOGICAL_PROCESSOR_RELATIONSHIP {
+     RelationProcessorCore,
+     RelationNumaNode,
+     RelationCache,
+     RelationProcessorPackage 
+ } LOGICAL_PROCESSOR_RELATIONSHIP;
+ #define CACHE_FULLY_ASSOCIATIVE 0xFF
+ typedef struct _CACHE_DESCRIPTOR {
+     BYTE Level;
+     BYTE Associativity;
+     WORD LineSize;
+     DWORD Size;
+     PROCESSOR_CACHE_TYPE Type;
+ } CACHE_DESCRIPTOR, *PCACHE_DESCRIPTOR;
+ typedef struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION {
+     ULONG_PTR ProcessorMask;
+     LOGICAL_PROCESSOR_RELATIONSHIP Relationship;
+     union {
+         struct {
+             BYTE Flags;
+         } ProcessorCore;
+         struct {
+         DWORD NodeNumber;
+         } NumaNode;
+         CACHE_DESCRIPTOR Cache;
+         ULONGLONG Reserved[2];
+     };
+ } SYSTEM_LOGICAL_PROCESSOR_INFORMATION, *PSYSTEM_LOGICAL_PROCESSOR_INFORMATION;
  NTSYSAPI
  SIZE_T
  STDCALL
@@@ -4415,6 -4453,23 +4454,23 @@@ RtlCompareMemory 
  #define RtlFillMemory(d,l,f) memset((d), (f), (l))
  #define RtlZeroMemory(d,l) RtlFillMemory((d),(l),0)
  
+ FORCEINLINE
+ PVOID
+ RtlSecureZeroMemory(IN PVOID ptr,
+                     IN SIZE_T cnt)
+ {
+     volatile char *vptr = (volatile char *)ptr;
+     while (cnt)
+     {
+         *vptr = 0;
+         vptr++;
+         cnt--;
+     }
+     return ptr;
+ }
  typedef struct _OBJECT_TYPE_LIST {
      WORD   Level;
      WORD   Sbz;
@@@ -4436,11 -4491,7 +4492,11 @@@ static __inline__ PVOID GetCurrentFiber
  #elif defined (_M_AMD64)
  FORCEINLINE PVOID GetCurrentFiber(VOID)
  {
 +  #ifdef NONAMELESSUNION
 +    return (PVOID)__readgsqword(FIELD_OFFSET(NT_TIB, DUMMYUNIONNAME.FiberData));
 +  #else
      return (PVOID)__readgsqword(FIELD_OFFSET(NT_TIB, FiberData));
 +  #endif
  }
  #elif defined (_M_ARM)
      PVOID WINAPI GetCurrentFiber(VOID);
@@@ -4622,6 -4673,40 +4678,40 @@@ BitScanReverse(OUT ULONG *Index
  
  #endif
  
+ /* TODO: Other architectures than X86 */
+ #if defined(_M_IX86)
+ #define PF_TEMPORAL_LEVEL_1 
+ #define PF_NON_TEMPORAL_LEVEL_ALL
+ #define PreFetchCacheLine(l, a)
+ #elif defined (_M_AMD64)
+ #define PreFetchCacheLine(l, a)
+ #elif defined(_M_PPC)
+ #define PreFetchCacheLine(l, a)
+ #elif defined(_M_ARM)
+ #define PreFetchCacheLine(l, a)
+ #else
+ #error Unknown architecture
+ #endif
+ /* TODO: Other architectures than X86 */
+ #if defined(_M_IX86)
+ FORCEINLINE
+ VOID
+ MemoryBarrier(VOID)
+ {
+     LONG Barrier;
+     __asm__ __volatile__("xchgl %%eax, %[Barrier]" : : [Barrier] "m" (Barrier) : "memory");
+ }
+ #elif defined (_M_AMD64)
+ #define MemoryBarrier()
+ #elif defined(_M_PPC)
+ #define MemoryBarrier()
+ #elif defined(_M_ARM)
+ #define MemoryBarrier()
+ #else
+ #error Unknown architecture
+ #endif
  #if defined(_M_IX86)
  #define YieldProcessor() __asm__ __volatile__("pause");
  #elif defined (_M_AMD64)
@@@ -8,6 -8,13 +8,13 @@@
  extern "C" {
  #endif
  
+ #if !defined(_USER32_)
+ #define WINUSERAPI DECLSPEC_IMPORT
+ #else
+ #define WINUSERAPI
+ #endif
  #define WC_DIALOG MAKEINTATOM(0x8002)
  #define FALT  16
  #define FCONTROL      8
  #define STATE_SYSTEM_VALID 0x1fffffff
  
  #ifndef RC_INVOKED
 -typedef BOOL(CALLBACK *DLGPROC)(HWND,UINT,WPARAM,LPARAM);
 +typedef INT_PTR(CALLBACK *DLGPROC)(HWND,UINT,WPARAM,LPARAM);
  typedef VOID(CALLBACK *TIMERPROC)(HWND,UINT,UINT,DWORD);
  typedef BOOL(CALLBACK *GRAYSTRINGPROC)(HDC,LPARAM,int);
  typedef LRESULT(CALLBACK *HOOKPROC)(int,WPARAM,LPARAM);
@@@ -3709,12 -3716,12 +3716,12 @@@ BOOL WINAPI DestroyWindow(HWND)
  #define DialogBoxW(i,t,p,f) DialogBoxParamW(i,t,p,f,0)
  #define DialogBoxIndirectA(i,t,p,f) DialogBoxIndirectParamA(i,t,p,f,0)
  #define DialogBoxIndirectW(i,t,p,f) DialogBoxIndirectParamW(i,t,p,f,0)
 -int WINAPI DialogBoxIndirectParamA(HINSTANCE,LPCDLGTEMPLATE,HWND,DLGPROC,LPARAM);
 -int WINAPI DialogBoxIndirectParamW(HINSTANCE,LPCDLGTEMPLATE,HWND,DLGPROC,LPARAM);
 -int WINAPI DialogBoxParamA(HINSTANCE,LPCSTR,HWND,DLGPROC,LPARAM);
 -int WINAPI DialogBoxParamW(HINSTANCE,LPCWSTR,HWND,DLGPROC,LPARAM);
 -LONG WINAPI DispatchMessageA(const MSG*);
 -LONG WINAPI DispatchMessageW(const MSG*);
 +INT_PTR WINAPI DialogBoxIndirectParamA(HINSTANCE,LPCDLGTEMPLATE,HWND,DLGPROC,LPARAM);
 +INT_PTR WINAPI DialogBoxIndirectParamW(HINSTANCE,LPCDLGTEMPLATE,HWND,DLGPROC,LPARAM);
 +INT_PTR WINAPI DialogBoxParamA(HINSTANCE,LPCSTR,HWND,DLGPROC,LPARAM);
 +INT_PTR WINAPI DialogBoxParamW(HINSTANCE,LPCWSTR,HWND,DLGPROC,LPARAM);
 +LRESULT WINAPI DispatchMessageA(const MSG*);
 +LRESULT WINAPI DispatchMessageW(const MSG*);
  int WINAPI DlgDirListA(HWND,LPSTR,int,int,UINT);
  int WINAPI DlgDirListW(HWND,LPWSTR,int,int,UINT);
  int WINAPI DlgDirListComboBoxA(HWND,LPSTR,int,int,UINT);
@@@ -3747,7 -3754,7 +3754,7 @@@ BOOL WINAPI EnableMenuItem(HMENU,UINT,U
  BOOL WINAPI EnableScrollBar(HWND,UINT,UINT);
  BOOL WINAPI EnableWindow(HWND,BOOL);
  BOOL WINAPI EndDeferWindowPos(HDWP);
 -BOOL WINAPI EndDialog(HWND,int);
 +BOOL WINAPI EndDialog(HWND,INT_PTR);
  BOOL WINAPI EndMenu(void);
  BOOL WINAPI EndPaint(HWND,const PAINTSTRUCT*);
  #if (_WIN32_WINNT >= 0x0500)
@@@ -3804,8 -3811,8 +3811,8 @@@ BOOL WINAPI GetClassInfoExW(HINSTANCE,L
  DWORD WINAPI GetClassLongA(HWND,int);
  DWORD WINAPI GetClassLongW(HWND,int);
  #ifdef _WIN64
 -LONG_PTR WINAPI GetClassLongPtrA(HWND,int);
 -LONG_PTR WINAPI GetClassLongPtrW(HWND,int);
 +ULONG_PTR WINAPI GetClassLongPtrA(HWND,int);
 +ULONG_PTR WINAPI GetClassLongPtrW(HWND,int);
  #else
  #define GetClassLongPtrA GetClassLongA
  #define GetClassLongPtrW GetClassLongW
@@@ -3866,7 -3873,7 +3873,7 @@@ int WINAPI GetMenuStringA(HMENU,UINT,LP
  int WINAPI GetMenuStringW(HMENU,UINT,LPWSTR,int,UINT);
  BOOL WINAPI GetMessageA(LPMSG,HWND,UINT,UINT);
  BOOL WINAPI GetMessageW(LPMSG,HWND,UINT,UINT);
 -LONG WINAPI GetMessageExtraInfo(void);
 +LPARAM WINAPI GetMessageExtraInfo(void);
  DWORD WINAPI GetMessagePos(void);
  LONG WINAPI GetMessageTime(void);
  #if (_WIN32_WINNT >= 0x0500 || _WIN32_WINDOWS >= 0x0490)
@@@ -4001,8 -4008,8 +4008,8 @@@ BOOL WINAPI IsWindowVisible(HWND)
  BOOL WINAPI IsWinEventHookInstalled(DWORD);
  #endif
  BOOL WINAPI IsZoomed(HWND);
 -VOID WINAPI keybd_event(BYTE,BYTE,DWORD,DWORD);
 -BOOL WINAPI KillTimer(HWND,UINT);
 +VOID WINAPI keybd_event(BYTE,BYTE,DWORD,ULONG_PTR);
 +BOOL WINAPI KillTimer(HWND,UINT_PTR);
  HACCEL WINAPI LoadAcceleratorsA(HINSTANCE,LPCSTR);
  HACCEL WINAPI LoadAcceleratorsW(HINSTANCE,LPCWSTR);
  HBITMAP WINAPI LoadBitmapA(HINSTANCE,LPCSTR);
@@@ -4114,16 -4121,16 +4121,16 @@@ BOOL WINAPI ScreenToClient(HWND,LPPOINT
  BOOL WINAPI ScrollDC(HDC,int,int,LPCRECT,LPCRECT,HRGN,LPRECT);
  BOOL WINAPI ScrollWindow(HWND,int,int,LPCRECT,LPCRECT);
  int WINAPI ScrollWindowEx(HWND,int,int,LPCRECT,LPCRECT,HRGN,LPRECT,UINT);
 -LONG WINAPI SendDlgItemMessageA(HWND,int,UINT,WPARAM,LPARAM);
 -LONG WINAPI SendDlgItemMessageW(HWND,int,UINT,WPARAM,LPARAM);
 +LRESULT WINAPI SendDlgItemMessageA(HWND,int,UINT,WPARAM,LPARAM);
 +LRESULT WINAPI SendDlgItemMessageW(HWND,int,UINT,WPARAM,LPARAM);
  #if (_WIN32_WINNT >= 0x0403)
  UINT WINAPI SendInput(UINT,LPINPUT,int);
  #endif
  LRESULT WINAPI SendMessageA(HWND,UINT,WPARAM,LPARAM);
 -BOOL WINAPI SendMessageCallbackA(HWND,UINT,WPARAM,LPARAM,SENDASYNCPROC,DWORD);
 -BOOL WINAPI SendMessageCallbackW(HWND,UINT,WPARAM,LPARAM,SENDASYNCPROC,DWORD);
 -LRESULT WINAPI SendMessageTimeoutA(HWND,UINT,WPARAM,LPARAM,UINT,UINT,PDWORD);
 -LRESULT WINAPI SendMessageTimeoutW(HWND,UINT,WPARAM,LPARAM,UINT,UINT,PDWORD);
 +BOOL WINAPI SendMessageCallbackA(HWND,UINT,WPARAM,LPARAM,SENDASYNCPROC,ULONG_PTR);
 +BOOL WINAPI SendMessageCallbackW(HWND,UINT,WPARAM,LPARAM,SENDASYNCPROC,ULONG_PTR);
 +LRESULT WINAPI SendMessageTimeoutA(HWND,UINT,WPARAM,LPARAM,UINT,UINT,PDWORD_PTR);
 +LRESULT WINAPI SendMessageTimeoutW(HWND,UINT,WPARAM,LPARAM,UINT,UINT,PDWORD_PTR);
  LRESULT WINAPI SendMessageW(HWND,UINT,WPARAM,LPARAM);
  BOOL WINAPI SendNotifyMessageA(HWND,UINT,WPARAM,LPARAM);
  BOOL WINAPI SendNotifyMessageW(HWND,UINT,WPARAM,LPARAM);
@@@ -4179,7 -4186,7 +4186,7 @@@ HANDLE WINAPI SetSysColorsTemp(const CO
  #define SetSysModalWindow(h) (NULL)
  BOOL WINAPI SetSystemCursor(HCURSOR,DWORD);
  BOOL WINAPI SetThreadDesktop(HDESK);
 -UINT WINAPI SetTimer(HWND,UINT,UINT,TIMERPROC);
 +UINT_PTR WINAPI SetTimer(HWND,UINT_PTR,UINT,TIMERPROC);
  BOOL WINAPI SetUserObjectInformationA(HANDLE,int,PVOID,DWORD);
  BOOL WINAPI SetUserObjectInformationW(HANDLE,int,PVOID,DWORD);
  BOOL WINAPI SetUserObjectSecurity(HANDLE,PSECURITY_INFORMATION,PSECURITY_DESCRIPTOR);
@@@ -154,6 -154,7 +154,7 @@@ static _SEHPortableTryLevel_t * const _
                _SEHHandlers.SH_Finally = (FINALLY_);
  #endif
  
+ #define _SEH_SetExceptionCode(CODE_) (_SEHPortableFrame->SPF_Code = (CODE_))
  #define _SEH_GetExceptionCode() (unsigned long)(_SEHPortableFrame->SPF_Code)
  
  #define _SEH_GetExceptionPointers() \
                STMT_; \
        }
  
 -#ifdef _ARM_
 +#if defined(_ARM_) || defined(_M_AMD64)
  
  #define _SEH_TRY \
        for(;;) \
@@@ -126,6 -126,6 +126,7 @@@ typedef    _BSD_SIZE_T_    size_t
  
  #ifdef        _BSD_SSIZE_T_
  typedef       _BSD_SSIZE_T_   ssize_t;
++#define _SSIZE_T_DEFINED
  #undef        _BSD_SSIZE_T_
  #endif
  
@@@ -1,6 -1,6 +1,6 @@@
  <?xml version="1.0"?>
  <!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd">
 -<module name="crt" type="staticlibrary">
 +<module name="crt" type="staticlibrary" allowwarnings="true">
        <include base="crt">.</include>
        <include base="crt">include</include>
        <define name="_DISABLE_TIDENTS" />
                                <file>chkstk_asm.s</file>
                        </directory>
                </if>
 +              <if property="ARCH" value="amd64">
 +                      <directory name="amd64">
 +                              <file>seh.s</file>
 +                              <file>chkstk_asm.s</file>
 +                      </directory>
 +              </if>
                <file>xcptfil.c</file>
        </directory>
        <directory name="float">
                                <file>statfp.c</file>
                        </directory>
                </if>
 +              <if property="ARCH" value="amd64">
 +                      <directory name="i386">
 +                              <file>clearfp.c</file>
 +                              <file>cntrlfp.c</file>
 +                              <file>logb.c</file>
 +                              <file>statfp.c</file>
 +                      </directory>
 +              </if>
        </directory>
        <directory name="locale">
                <file>locale.c</file>
                <file>cabs.c</file>
                <file>cosh.c</file>
                <file>div.c</file>
+               <file>fdivbug.c</file>
                <file>frexp.c</file>
                <file>huge_val.c</file>
                <file>hypot.c</file>
                <file>rand.c</file>
                <file>s_modf.c</file>
                <file>sinh.c</file>
-               <file>stubs.c</file>
                <file>tanh.c</file>
                <file>pow_asm.c</file>
  
                <if property="ARCH" value="i386">
                        <directory name="i386">
                                <file>atan2.c</file>
+                               <file>ci.c</file>
                                <file>exp.c</file>
                                <file>fmod.c</file>
                                <file>ldexp.c</file>
                                <file>log10_asm.s</file>
                        </directory>
                </if>
 +              <if property="ARCH" value="amd64">
 +                      <directory name="i386">
 +                              <file>atan2.c</file>
 +                              <file>exp.c</file>
 +                              <file>fmod.c</file>
 +                              <file>ldexp.c</file>
 +                      </directory>
 +              </if>
+               <ifnot property="ARCH" value="i386">
+                       <file>stubs.c</file>
+               </ifnot>
        </directory>
  
        <directory name="mbstring">
 -/*
 - * PROGRAMMERS:     David Welch
 - *                  Eric Kohl
 - *
 - * TODO:
 - *   - Verify the implementation of '%Z'.
 - */
 -
 -/*
 - *  linux/lib/vsprintf.c
 - *
 - *  Copyright (C) 1991, 1992  Linus Torvalds
 - */
 -
 -/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
 -/*
 - * Wirzenius wrote this portably, Torvalds fucked it up :-)
 - */
 -
 -#include <precomp.h>
 -
 -#include <wchar.h>
 -#include <tchar.h>
 -
 -#define ZEROPAD       1               /* pad with zero */
 -#define SIGN  2               /* unsigned/signed long */
 -#define PLUS  4               /* show plus */
 -#define SPACE 8               /* space if plus */
 -#define LEFT  16              /* left justified */
 -#define SPECIAL       32              /* 0x */
 -#define LARGE 64              /* use 'ABCDEF' instead of 'abcdef' */
 -#define REMOVEHEX     256             /* use 256 as remve 0x frim BASE 16  */
 -
 -static
 -__inline
 -int
 -do_div(long long *n, int base)
 -{
 -    int a;
 -    a = ((unsigned long long) *n) % (unsigned) base;
 -    *n = ((unsigned long long) *n) / (unsigned) base;
 -    return a;
 -}
 -
 -
 -static int skip_atoi(const char **s)
 -{
 -      int i=0;
 -
 -      while (isdigit(**s))
 -              i = i*10 + *((*s)++) - '0';
 -      return i;
 -}
 -
 -
 -static char *
 -number(char * buf, char * end, long long num, int base, int size, int precision, int type)
 -{
 -      char c,sign,tmp[66];
 -      const char *digits;
 -      const char *small_digits = "0123456789abcdefghijklmnopqrstuvwxyz";
 -      const char *large_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 -      int i;
 -
 -      digits = (type & LARGE) ? large_digits : small_digits;
 -      if (type & LEFT)
 -              type &= ~ZEROPAD;
 -      if (base < 2 || base > 36)
 -              return 0;
 -      c = (type & ZEROPAD) ? '0' : ' ';
 -      sign = 0;
 -      if (type & SIGN) {
 -              if (num < 0) {
 -                      sign = '-';
 -                      num = -num;
 -                      size--;
 -              } else if (type & PLUS) {
 -                      sign = '+';
 -                      size--;
 -              } else if (type & SPACE) {
 -                      sign = ' ';
 -                      size--;
 -              }
 -      }
 -
 -      if ((type & SPECIAL) && ((type & REMOVEHEX) == 0)) {
 -              if (base == 16)
 -                      size -= 2;
 -
 -      }
 -      i = 0;
 -      if ((num == 0) && (precision !=0))
 -              tmp[i++] = '0';
 -      else while (num != 0)
 -              tmp[i++] = digits[do_div(&num,base)];
 -      if (i > precision)
 -              precision = i;
 -      size -= precision;
 -      if (!(type&(ZEROPAD+LEFT))) {
 -              while(size-->0) {
 -                      if (buf <= end)
 -                              *buf = ' ';
 -                      ++buf;
 -              }
 -      }
 -      if (sign) {
 -              if (buf <= end)
 -                      *buf = sign;
 -              ++buf;
 -      }
 -
 -      if ((type & SPECIAL) && ((type & REMOVEHEX) == 0)) {
 -               if (base==16) {
 -                      if (buf <= end)
 -                              *buf = '0';
 -                      ++buf;
 -                      if (buf <= end)
 -                              *buf = digits[33];
 -                      ++buf;
 -              }
 -      }
 -
 -      if (!(type & LEFT)) {
 -              while (size-- > 0) {
 -                      if (buf <= end)
 -                              *buf = c;
 -                      ++buf;
 -              }
 -      }
 -      while (i < precision--) {
 -              if (buf <= end)
 -                      *buf = '0';
 -              ++buf;
 -      }
 -      while (i-- > 0) {
 -              if (buf <= end)
 -                      *buf = tmp[i];
 -              ++buf;
 -      }
 -      while (size-- > 0) {
 -              if (buf <= end)
 -                      *buf = ' ';
 -              ++buf;
 -      }
 -
 -      return buf;
 -}
 -
 -static char *
 -numberf(char * buf, char * end, double num, int base, int size, int precision, int type)
 -{
 -      char c,sign,tmp[66];
 -      const char *digits;
 -      const char *small_digits = "0123456789abcdefghijklmnopqrstuvwxyz";
 -      const char *large_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 -      int i;
 -      long long x;
 -
 -    /* FIXME
 -       the float version of number is direcly copy of number
 -    */
 -
 -      digits = (type & LARGE) ? large_digits : small_digits;
 -      if (type & LEFT)
 -              type &= ~ZEROPAD;
 -      if (base < 2 || base > 36)
 -              return 0;
 -      c = (type & ZEROPAD) ? '0' : ' ';
 -      sign = 0;
 -      if (num < 0) {
 -              sign = '-';
 -              num = -num;
 -              size--;
 -      } else if (type & PLUS) {
 -              sign = '+';
 -              size--;
 -      } else if (type & SPACE) {
 -              sign = ' ';
 -              size--;
 -      }
 -      if (type & SPECIAL)  {
 -              if (base == 16)
 -                      size -= 2;
 -              else if (base == 8)
 -                      size--;
 -      }
 -      i = 0;
 -      if (num == 0)
 -              tmp[i++] = '0';
 -      else while (num != 0)
 -    {
 -        x = num;
 -              tmp[i++] = digits[do_div(&x,base)];
 -              num=x;
 -    }
 -      if (i > precision)
 -              precision = i;
 -      size -= precision;
 -      if (!(type&(ZEROPAD+LEFT))) {
 -              while(size-->0) {
 -                      if (buf <= end)
 -                              *buf = ' ';
 -                      ++buf;
 -              }
 -      }
 -      if (sign) {
 -              if (buf <= end)
 -                      *buf = sign;
 -              ++buf;
 -      }
 -      if (type & SPECIAL) {
 -              if (base==8) {
 -                      if (buf <= end)
 -                              *buf = '0';
 -                      ++buf;
 -              } else if (base==16) {
 -                      if (buf <= end)
 -                              *buf = '0';
 -                      ++buf;
 -                      if (buf <= end)
 -                              *buf = digits[33];
 -                      ++buf;
 -              }
 -      }
 -      if (!(type & LEFT)) {
 -              while (size-- > 0) {
 -                      if (buf <= end)
 -                              *buf = c;
 -                      ++buf;
 -              }
 -      }
 -      if (type & ZEROPAD) {
 -              while (i < precision--) {
 -                      if (buf <= end)
 -                              *buf = '0';
 -                      ++buf;
 -              }
 -      }
 -      while (i-- > 0) {
 -              if (buf <= end)
 -                      *buf = tmp[i];
 -              ++buf;
 -      }
 -      while (size-- > 0) {
 -              if (buf <= end)
 -                      *buf = ' ';
 -              ++buf;
 -      }
 -      return buf;
 -}
 -
 -static char*
 -string(char* buf, char* end, const char* s, int len, int field_width, int precision, int flags)
 -{
 -      int i;
 -    char c;
 -
 -    c = (flags & ZEROPAD) ? '0' : ' ';
 -
 -      if (s == NULL)
 -      {
 -              s = "<NULL>";
 -              len = 6;
 -      }
 -      else
 -      {
 -              if (len == -1)
 -              {
 -                      len = 0;
 -                      while ((unsigned int)len < (unsigned int)precision && s[len])
 -                              len++;
 -              }
 -              else
 -              {
 -                      if ((unsigned int)len > (unsigned int)precision)
 -                              len = precision;
 -              }
 -      }
 -      if (!(flags & LEFT))
 -              while (len < field_width--)
 -              {
 -                      if (buf <= end)
 -                              *buf = c;
 -                      ++buf;
 -              }
 -      for (i = 0; i < len; ++i)
 -      {
 -              if (buf <= end)
 -                      *buf = *s++;
 -              ++buf;
 -      }
 -      while (len < field_width--)
 -      {
 -              if (buf <= end)
 -                      *buf = ' ';
 -              ++buf;
 -      }
 -      return buf;
 -}
 -
 -static char*
 -stringw(char* buf, char* end, const wchar_t* sw, int len, int field_width, int precision, int flags)
 -{
 -      int i;
 -      char c;
 -
 -    c = (flags & ZEROPAD) ? '0' : ' ';
 -
 -      if (sw == NULL)
 -      {
 -              sw = L"<NULL>";
 -              len = 6;
 -      }
 -      else
 -      {
 -              if (len == -1)
 -              {
 -                      len = 0;
 -                      while ((unsigned int)len < (unsigned int)precision && sw[len])
 -                              len++;
 -              }
 -              else
 -              {
 -                      if ((unsigned int)len > (unsigned int)precision)
 -                              len = precision;
 -              }
 -      }
 -      if (!(flags & LEFT))
 -              while (len < field_width--)
 -              {
 -                      if (buf <= end)
 -                              *buf = c;
 -                      buf++;
 -              }
 -      for (i = 0; i < len; ++i)
 -      {
 -              if (buf <= end)
 -                      *buf = (unsigned char)(*sw++);
 -              buf++;
 -      }
 -      while (len < field_width--)
 -      {
 -              if (buf <= end)
 -                      *buf = ' ';
 -              buf++;
 -      }
 -      return buf;
 -}
 -
 -/*
 - * @implemented
 - */
 -int __cdecl lnx_vsnprintf(char *buf, size_t cnt, const char *fmt, va_list args)
 -{
 -      int len;
 -      unsigned long long num;
 -      double _double;
 -
 -      int base;
 -      char *str, *end;
 -      const char *s;
 -      const wchar_t *sw;
 -
 -      int flags;              /* flags to number() */
 -
 -      int field_width;        /* width of output field */
 -      int precision;          /* min. # of digits for integers; max
 -                                 number of chars for from string */
 -      int qualifier;          /* 'h', 'l', 'L', 'I' or 'w' for integer fields */
 -
 -    /* clear the string buffer with zero so we do not need NULL terment it at end */
 -
 -      str = buf;
 -      end = buf + cnt - 1;
 -      if (end < buf - 1) {
 -              end = ((char *) -1);
 -              cnt = end - buf + 1;
 -      }
 -
 -      for ( ; *fmt ; ++fmt) {
 -              if (*fmt != '%') {
 -                      if (str <= end)
 -                              *str = *fmt;
 -                      ++str;
 -                      continue;
 -              }
 -
 -              /* process flags */
 -              flags = 0;
 -              repeat:
 -                      ++fmt;          /* this also skips first '%' */
 -                      switch (*fmt) {
 -                              case '-': flags |= LEFT; goto repeat;
 -                              case '+': flags |= PLUS; goto repeat;
 -                              case ' ': flags |= SPACE; goto repeat;
 -                              case '#': flags |= SPECIAL; goto repeat;
 -                              case '0': flags |= ZEROPAD; goto repeat;
 -                      }
 -
 -              /* get field width */
 -              field_width = -1;
 -              if (isdigit(*fmt))
 -                      field_width = skip_atoi(&fmt);
 -              else if (*fmt == '*') {
 -                      ++fmt;
 -                      /* it's the next argument */
 -                      field_width = va_arg(args, int);
 -                      if (field_width < 0) {
 -                              field_width = -field_width;
 -                              flags |= LEFT;
 -                      }
 -              }
 -
 -              /* get the precision */
 -              precision = -1;
 -              if (*fmt == '.') {
 -                      ++fmt;
 -                      if (isdigit(*fmt))
 -                              precision = skip_atoi(&fmt);
 -                      else if (*fmt == '*') {
 -                              ++fmt;
 -                              /* it's the next argument */
 -                              precision = va_arg(args, int);
 -                      }
 -                      if (precision < 0)
 -                              precision = 0;
 -              }
 -
 -              /* get the conversion qualifier */
 -              qualifier = -1;
 -              if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt == 'w') {
 -                      qualifier = *fmt;
 -                      ++fmt;
 -              } else if (*fmt == 'I' && *(fmt+1) == '6' && *(fmt+2) == '4') {
 -                      qualifier = *fmt;
 -                      fmt += 3;
 -              } else if (*fmt == 'I' && *(fmt+1) == '3' && *(fmt+2) == '2') {
 -                      qualifier = 'l';
 -                      fmt += 3;
 -              } else if (*fmt == 'F' && *(fmt+1) == 'p') {
 -                      fmt += 1;
 -            flags |= REMOVEHEX;
 -        }
 -
 -              /* default base */
 -              base = 10;
 -
 -              switch (*fmt) {
 -              case 'c': /* finished */
 -             if (qualifier == 'l' || qualifier == 'w') {
 -                    wchar_t sw1[2];
 -                              /* print unicode string */
 -                sw1[0] = (wchar_t) va_arg(args, int);
 -                sw1[1] = 0;
 -                              str = stringw(str, end, (wchar_t *)&sw1, -1, field_width, precision, flags);
 -                      } else {
 -                char s1[2];
 -                              /* print ascii string */
 -                s1[0] = ( unsigned char) va_arg(args, int);
 -                s1[1] = 0;
 -                              str = string(str, end, (char *)&s1, -1,  field_width, precision, flags);
 -                      }
 -            continue;
 -
 -              case 'C': /* finished */
 -                      if (!(flags & LEFT))
 -                              while (--field_width > 0) {
 -                                      if (str <= end)
 -                                              *str = ' ';
 -                                      ++str;
 -                              }
 -                      if (qualifier == 'h') {
 -                              if (str <= end)
 -                                      *str = (unsigned char) va_arg(args, int);
 -                              ++str;
 -                      } else {
 -                              if (str <= end)
 -                                      *str = (unsigned char)(wchar_t) va_arg(args, int);
 -                              ++str;
 -                      }
 -                      while (--field_width > 0) {
 -                              if (str <= end)
 -                                      *str = ' ';
 -                              ++str;
 -                      }
 -                      continue;
 -
 -              case 's': /* finished */
 -                      if (qualifier == 'l' || qualifier == 'w') {
 -                              /* print unicode string */
 -                              sw = va_arg(args, wchar_t *);
 -                              str = stringw(str, end, sw, -1, field_width, precision, flags);
 -                      } else {
 -                              /* print ascii string */
 -                              s = va_arg(args, char *);
 -                              str = string(str, end, s, -1,  field_width, precision, flags);
 -                      }
 -                      continue;
 -
 -              case 'S':
 -                      if (qualifier == 'h') {
 -                              /* print ascii string */
 -                              s = va_arg(args, char *);
 -                              str = string(str, end, s, -1,  field_width, precision, flags);
 -                      } else {
 -                              /* print unicode string */
 -                              sw = va_arg(args, wchar_t *);
 -                              str = stringw(str, end, sw, -1, field_width, precision, flags);
 -                      }
 -                      continue;
 -
 -              case 'Z':
 -                      if (qualifier == 'w') {
 -                              /* print counted unicode string */
 -                              PUNICODE_STRING pus = va_arg(args, PUNICODE_STRING);
 -                              if ((pus == NULL) || (pus->Buffer == NULL)) {
 -                                      sw = NULL;
 -                                      len = -1;
 -                              } else {
 -                                      sw = pus->Buffer;
 -                                      len = pus->Length / sizeof(WCHAR);
 -                              }
 -                              str = stringw(str, end, sw, len,  field_width, precision, flags);
 -                      } else {
 -                              /* print counted ascii string */
 -                              PANSI_STRING pus = va_arg(args, PANSI_STRING);
 -                              if ((pus == NULL) || (pus->Buffer == NULL)) {
 -                                      s = NULL;
 -                                      len = -1;
 -                              } else {
 -                                      s = pus->Buffer;
 -                                      len = pus->Length;
 -                              }
 -                              str = string(str, end, s, len,  field_width, precision, flags);
 -                      }
 -                      continue;
 -
 -              case 'p':
 -            if ((flags & LARGE) == 0)
 -                flags |= LARGE;
 -
 -                      if (field_width == -1) {
 -                              field_width = 2 * sizeof(void *);
 -                              flags |= ZEROPAD;
 -                      }
 -                      str = number(str, end,
 -                              (unsigned long) va_arg(args, void *), 16,
 -                              field_width, precision, flags);
 -                      continue;
 -
 -              case 'n':
 -                      /* FIXME: What does C99 say about the overflow case here? */
 -                      if (qualifier == 'l') {
 -                              long * ip = va_arg(args, long *);
 -                              *ip = (str - buf);
 -                      } else {
 -                              int * ip = va_arg(args, int *);
 -                              *ip = (str - buf);
 -                      }
 -                      continue;
 -
 -              /* float number formats - set up the flags and "break" */
 -        case 'e':
 -              case 'E':
 -              case 'f':
 -              case 'g':
 -              case 'G':
 -          _double = (double)va_arg(args, double);
 -         if ( _isnan(_double) ) {
 -            s = "Nan";
 -            len = 3;
 -            while ( len > 0 ) {
 -               if (str <= end)
 -                                      *str = *s++;
 -                              ++str;
 -               len --;
 -            }
 -         } else if ( _isinf(_double) < 0 ) {
 -            s = "-Inf";
 -            len = 4;
 -            while ( len > 0 ) {
 -                      if (str <= end)
 -                                      *str = *s++;
 -                              ++str;
 -               len --;
 -            }
 -         } else if ( _isinf(_double) > 0 ) {
 -            s = "+Inf";
 -            len = 4;
 -            while ( len > 0 ) {
 -               if (str <= end)
 -                                      *str = *s++;
 -                              ++str;
 -               len --;
 -            }
 -         } else {
 -            if ( precision == -1 )
 -               precision = 6;
 -                      str = numberf(str, end, (int)_double, base, field_width, precision, flags);
 -         }
 -
 -          continue;
 -
 -
 -              /* integer number formats - set up the flags and "break" */
 -              case 'o':
 -                      base = 8;
 -                      break;
 -
 -              case 'b':
 -                      base = 2;
 -                      break;
 -
 -              case 'X':
 -                      flags |= LARGE;
 -              case 'x':
 -                      base = 16;
 -                      break;
 -
 -              case 'd':
 -              case 'i':
 -                      flags |= SIGN;
 -              case 'u':
 -                      break;
 -
 -              default:
 -                      if (*fmt) {
 -                              if (str <= end)
 -                                      *str = *fmt;
 -                              ++str;
 -                      } else
 -                              --fmt;
 -                      continue;
 -              }
 -
 -              if (qualifier == 'I')
 -                      num = va_arg(args, unsigned long long);
 -              else if (qualifier == 'l') {
 -                      if (flags & SIGN)
 -                              num = va_arg(args, long);
 -                      else
 -                              num = va_arg(args, unsigned long);
 -              }
 -              else if (qualifier == 'h') {
 -                      if (flags & SIGN)
 -                              num = va_arg(args, int);
 -                      else
 -                              num = va_arg(args, unsigned int);
 -              }
 -              else {
 -                      if (flags & SIGN)
 -                              num = va_arg(args, int);
 -                      else
 -                              num = va_arg(args, unsigned int);
 -              }
 -              str = number(str, end, num, base, field_width, precision, flags);
 -      }
 -      if (str <= end)
 -              *str = '\0';
 -      else if (cnt > 0)
 -              /* don't write out a null byte if the buf size is zero */
 -              *end = '\0';
 -      return str-buf;
 -}
 -
 -
 -/*
 - * @implemented
 - */
 -int lnx_sprintf(char * buf, const char *fmt, ...)
 -{
 -      va_list args;
 -      int i;
 -
 -      va_start(args, fmt);
 -      i=lnx_vsnprintf(buf,MAXLONG,fmt,args);
 -      va_end(args);
 -      return i;
 -}
 -
 -#if 0
 -/*
 - * @implemented
 - */
 -int _snprintf(char * buf, size_t cnt, const char *fmt, ...)
 -{
 -      va_list args;
 -      int i;
 -
 -      va_start(args, fmt);
 -      i=_vsnprintf(buf,cnt,fmt,args);
 -      va_end(args);
 -      return i;
 -}
 -
 -
 -/*
 - * @implemented
 - */
 -int __cdecl vsprintf(char *buf, const char *fmt, va_list args)
 -{
 -      return _vsnprintf(buf,MAXLONG,fmt,args);
 -}
 -#endif
 -/* EOF */
 +/*\r
 + * PROGRAMMERS:     David Welch\r
 + *                  Eric Kohl\r
 + *\r
 + * TODO:\r
 + *   - Verify the implementation of '%Z'.\r
 + */\r
 +\r
 +/*\r
 + *  linux/lib/vsprintf.c\r
 + *\r
 + *  Copyright (C) 1991, 1992  Linus Torvalds\r
 + */\r
 +\r
 +/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */\r
 +/*\r
 + * Wirzenius wrote this portably, Torvalds fucked it up :-)\r
 + */\r
 +\r
 +#include <precomp.h>\r
 +\r
 +#include <wchar.h>\r
 +#include <tchar.h>\r
 +\r
 +#define ZEROPAD       1               /* pad with zero */\r
 +#define SIGN  2               /* unsigned/signed long */\r
 +#define PLUS  4               /* show plus */\r
 +#define SPACE 8               /* space if plus */\r
 +#define LEFT  16              /* left justified */\r
 +#define SPECIAL       32              /* 0x */\r
 +#define LARGE 64              /* use 'ABCDEF' instead of 'abcdef' */\r
 +#define REMOVEHEX     256             /* use 256 as remve 0x frim BASE 16  */\r
 +\r
 +static\r
 +__inline\r
 +int\r
 +do_div(long long *n, int base)\r
 +{\r
 +    int a;\r
 +    a = ((unsigned long long) *n) % (unsigned) base;\r
 +    *n = ((unsigned long long) *n) / (unsigned) base;\r
 +    return a;\r
 +}\r
 +\r
 +\r
 +static int skip_atoi(const char **s)\r
 +{\r
 +      int i=0;\r
 +\r
 +      while (isdigit(**s))\r
 +              i = i*10 + *((*s)++) - '0';\r
 +      return i;\r
 +}\r
 +\r
 +\r
 +static char *\r
 +number(char * buf, char * end, long long num, int base, int size, int precision, int type)\r
 +{\r
 +      char c,sign,tmp[66];\r
 +      const char *digits;\r
 +      const char *small_digits = "0123456789abcdefghijklmnopqrstuvwxyz";\r
 +      const char *large_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";\r
 +      int i;\r
 +\r
 +      digits = (type & LARGE) ? large_digits : small_digits;\r
 +      if (type & LEFT)\r
 +              type &= ~ZEROPAD;\r
 +      if (base < 2 || base > 36)\r
 +              return 0;\r
 +      c = (type & ZEROPAD) ? '0' : ' ';\r
 +      sign = 0;\r
 +      if (type & SIGN) {\r
 +              if (num < 0) {\r
 +                      sign = '-';\r
 +                      num = -num;\r
 +                      size--;\r
 +              } else if (type & PLUS) {\r
 +                      sign = '+';\r
 +                      size--;\r
 +              } else if (type & SPACE) {\r
 +                      sign = ' ';\r
 +                      size--;\r
 +              }\r
 +      }\r
 +\r
 +      if ((type & SPECIAL) && ((type & REMOVEHEX) == 0)) {\r
 +              if (base == 16)\r
 +                      size -= 2;\r
 +\r
 +      }\r
 +      i = 0;\r
 +      if ((num == 0) && (precision !=0))\r
 +              tmp[i++] = '0';\r
 +      else while (num != 0)\r
 +              tmp[i++] = digits[do_div(&num,base)];\r
 +      if (i > precision)\r
 +              precision = i;\r
 +      size -= precision;\r
 +      if (!(type&(ZEROPAD+LEFT))) {\r
 +              while(size-->0) {\r
 +                      if (buf <= end)\r
 +                              *buf = ' ';\r
 +                      ++buf;\r
 +              }\r
 +      }\r
 +      if (sign) {\r
 +              if (buf <= end)\r
 +                      *buf = sign;\r
 +              ++buf;\r
 +      }\r
 +\r
 +      if ((type & SPECIAL) && ((type & REMOVEHEX) == 0)) {\r
 +               if (base==16) {\r
 +                      if (buf <= end)\r
 +                              *buf = '0';\r
 +                      ++buf;\r
 +                      if (buf <= end)\r
 +                              *buf = digits[33];\r
 +                      ++buf;\r
 +              }\r
 +      }\r
 +\r
 +      if (!(type & LEFT)) {\r
 +              while (size-- > 0) {\r
 +                      if (buf <= end)\r
 +                              *buf = c;\r
 +                      ++buf;\r
 +              }\r
 +      }\r
 +      while (i < precision--) {\r
 +              if (buf <= end)\r
 +                      *buf = '0';\r
 +              ++buf;\r
 +      }\r
 +      while (i-- > 0) {\r
 +              if (buf <= end)\r
 +                      *buf = tmp[i];\r
 +              ++buf;\r
 +      }\r
 +      while (size-- > 0) {\r
 +              if (buf <= end)\r
 +                      *buf = ' ';\r
 +              ++buf;\r
 +      }\r
 +\r
 +      return buf;\r
 +}\r
 +\r
 +static char *\r
 +numberf(char * buf, char * end, double num, int base, int size, int precision, int type)\r
 +{\r
 +      char c,sign,tmp[66];\r
 +      const char *digits;\r
 +      const char *small_digits = "0123456789abcdefghijklmnopqrstuvwxyz";\r
 +      const char *large_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";\r
 +      int i;\r
 +      long long x;\r
 +\r
 +    /* FIXME\r
 +       the float version of number is direcly copy of number\r
 +    */\r
 +\r
 +      digits = (type & LARGE) ? large_digits : small_digits;\r
 +      if (type & LEFT)\r
 +              type &= ~ZEROPAD;\r
 +      if (base < 2 || base > 36)\r
 +              return 0;\r
 +      c = (type & ZEROPAD) ? '0' : ' ';\r
 +      sign = 0;\r
-       if (type & SIGN) {\r
-               if (num < 0) {\r
-                       sign = '-';\r
-                       num = -num;\r
-                       size--;\r
-               } else if (type & PLUS) {\r
-                       sign = '+';\r
-                       size--;\r
-               } else if (type & SPACE) {\r
-                       sign = ' ';\r
-                       size--;\r
-               }\r
++      if (num < 0) {\r
++              sign = '-';\r
++              num = -num;\r
++              size--;\r
++      } else if (type & PLUS) {\r
++              sign = '+';\r
++              size--;\r
++      } else if (type & SPACE) {\r
++              sign = ' ';\r
++              size--;\r
 +      }\r
 +      if (type & SPECIAL)  {\r
 +              if (base == 16)\r
 +                      size -= 2;\r
 +              else if (base == 8)\r
 +                      size--;\r
 +      }\r
 +      i = 0;\r
 +      if (num == 0)\r
 +              tmp[i++] = '0';\r
 +      else while (num != 0)\r
 +    {\r
 +        x = num;\r
 +              tmp[i++] = digits[do_div(&x,base)];\r
 +              num=x;\r
 +    }\r
 +      if (i > precision)\r
 +              precision = i;\r
 +      size -= precision;\r
 +      if (!(type&(ZEROPAD+LEFT))) {\r
 +              while(size-->0) {\r
 +                      if (buf <= end)\r
 +                              *buf = ' ';\r
 +                      ++buf;\r
 +              }\r
 +      }\r
 +      if (sign) {\r
 +              if (buf <= end)\r
 +                      *buf = sign;\r
 +              ++buf;\r
 +      }\r
 +      if (type & SPECIAL) {\r
 +              if (base==8) {\r
 +                      if (buf <= end)\r
 +                              *buf = '0';\r
 +                      ++buf;\r
 +              } else if (base==16) {\r
 +                      if (buf <= end)\r
 +                              *buf = '0';\r
 +                      ++buf;\r
 +                      if (buf <= end)\r
 +                              *buf = digits[33];\r
 +                      ++buf;\r
 +              }\r
 +      }\r
 +      if (!(type & LEFT)) {\r
 +              while (size-- > 0) {\r
 +                      if (buf <= end)\r
 +                              *buf = c;\r
 +                      ++buf;\r
 +              }\r
 +      }\r
-       while (i < precision--) {\r
-               if (buf <= end)\r
-                       *buf = '0';\r
-               ++buf;\r
++      if (type & ZEROPAD) {\r
++              while (i < precision--) {\r
++                      if (buf <= end)\r
++                              *buf = '0';\r
++                      ++buf;\r
++              }\r
 +      }\r
 +      while (i-- > 0) {\r
 +              if (buf <= end)\r
 +                      *buf = tmp[i];\r
 +              ++buf;\r
 +      }\r
 +      while (size-- > 0) {\r
 +              if (buf <= end)\r
 +                      *buf = ' ';\r
 +              ++buf;\r
 +      }\r
 +      return buf;\r
 +}\r
 +\r
 +static char*\r
 +string(char* buf, char* end, const char* s, int len, int field_width, int precision, int flags)\r
 +{\r
 +      int i;\r
 +    char c;\r
 +\r
 +    c = (flags & ZEROPAD) ? '0' : ' ';\r
 +\r
 +      if (s == NULL)\r
 +      {\r
 +              s = "<NULL>";\r
 +              len = 6;\r
 +      }\r
 +      else\r
 +      {\r
 +              if (len == -1)\r
 +              {\r
 +                      len = 0;\r
 +                      while ((unsigned int)len < (unsigned int)precision && s[len])\r
 +                              len++;\r
 +              }\r
 +              else\r
 +              {\r
 +                      if ((unsigned int)len > (unsigned int)precision)\r
 +                              len = precision;\r
 +              }\r
 +      }\r
 +      if (!(flags & LEFT))\r
 +              while (len < field_width--)\r
 +              {\r
 +                      if (buf <= end)\r
 +                              *buf = c;\r
 +                      ++buf;\r
 +              }\r
 +      for (i = 0; i < len; ++i)\r
 +      {\r
 +              if (buf <= end)\r
 +                      *buf = *s++;\r
 +              ++buf;\r
 +      }\r
 +      while (len < field_width--)\r
 +      {\r
 +              if (buf <= end)\r
 +                      *buf = ' ';\r
 +              ++buf;\r
 +      }\r
 +      return buf;\r
 +}\r
 +\r
 +static char*\r
 +stringw(char* buf, char* end, const wchar_t* sw, int len, int field_width, int precision, int flags)\r
 +{\r
 +      int i;\r
 +      char c;\r
 +\r
 +    c = (flags & ZEROPAD) ? '0' : ' ';\r
 +\r
 +      if (sw == NULL)\r
 +      {\r
 +              sw = L"<NULL>";\r
 +              len = 6;\r
 +      }\r
 +      else\r
 +      {\r
 +              if (len == -1)\r
 +              {\r
 +                      len = 0;\r
 +                      while ((unsigned int)len < (unsigned int)precision && sw[len])\r
 +                              len++;\r
 +              }\r
 +              else\r
 +              {\r
 +                      if ((unsigned int)len > (unsigned int)precision)\r
 +                              len = precision;\r
 +              }\r
 +      }\r
 +      if (!(flags & LEFT))\r
 +              while (len < field_width--)\r
 +              {\r
 +                      if (buf <= end)\r
 +                              *buf = c;\r
 +                      buf++;\r
 +              }\r
 +      for (i = 0; i < len; ++i)\r
 +      {\r
 +              if (buf <= end)\r
 +                      *buf = (unsigned char)(*sw++);\r
 +              buf++;\r
 +      }\r
 +      while (len < field_width--)\r
 +      {\r
 +              if (buf <= end)\r
 +                      *buf = ' ';\r
 +              buf++;\r
 +      }\r
 +      return buf;\r
 +}\r
 +\r
 +/*\r
 + * @implemented\r
 + */\r
 +int __cdecl lnx_vsnprintf(char *buf, size_t cnt, const char *fmt, va_list args)\r
 +{\r
 +      int len;\r
 +      unsigned long long num;\r
 +      double _double;\r
 +\r
 +      int base;\r
 +      char *str, *end;\r
 +      const char *s;\r
 +      const wchar_t *sw;\r
 +\r
 +      int flags;              /* flags to number() */\r
 +\r
 +      int field_width;        /* width of output field */\r
 +      int precision;          /* min. # of digits for integers; max\r
 +                                 number of chars for from string */\r
 +      int qualifier;          /* 'h', 'l', 'L', 'I' or 'w' for integer fields */\r
 +\r
 +    /* clear the string buffer with zero so we do not need NULL terment it at end */\r
 +\r
 +      str = buf;\r
 +      end = buf + cnt - 1;\r
 +      if (end < buf - 1) {\r
 +              end = ((char *) -1);\r
 +              cnt = end - buf + 1;\r
 +      }\r
 +\r
 +      for ( ; *fmt ; ++fmt) {\r
 +              if (*fmt != '%') {\r
 +                      if (str <= end)\r
 +                              *str = *fmt;\r
 +                      ++str;\r
 +                      continue;\r
 +              }\r
 +\r
 +              /* process flags */\r
 +              flags = 0;\r
 +              repeat:\r
 +                      ++fmt;          /* this also skips first '%' */\r
 +                      switch (*fmt) {\r
 +                              case '-': flags |= LEFT; goto repeat;\r
 +                              case '+': flags |= PLUS; goto repeat;\r
 +                              case ' ': flags |= SPACE; goto repeat;\r
 +                              case '#': flags |= SPECIAL; goto repeat;\r
 +                              case '0': flags |= ZEROPAD; goto repeat;\r
 +                      }\r
 +\r
 +              /* get field width */\r
 +              field_width = -1;\r
 +              if (isdigit(*fmt))\r
 +                      field_width = skip_atoi(&fmt);\r
 +              else if (*fmt == '*') {\r
 +                      ++fmt;\r
 +                      /* it's the next argument */\r
 +                      field_width = va_arg(args, int);\r
 +                      if (field_width < 0) {\r
 +                              field_width = -field_width;\r
 +                              flags |= LEFT;\r
 +                      }\r
 +              }\r
 +\r
 +              /* get the precision */\r
 +              precision = -1;\r
 +              if (*fmt == '.') {\r
 +                      ++fmt;\r
 +                      if (isdigit(*fmt))\r
 +                              precision = skip_atoi(&fmt);\r
 +                      else if (*fmt == '*') {\r
 +                              ++fmt;\r
 +                              /* it's the next argument */\r
 +                              precision = va_arg(args, int);\r
 +                      }\r
 +                      if (precision < 0)\r
 +                              precision = 0;\r
 +              }\r
 +\r
 +              /* get the conversion qualifier */\r
 +              qualifier = -1;\r
 +              if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt == 'w') {\r
 +                      qualifier = *fmt;\r
 +                      ++fmt;\r
 +              } else if (*fmt == 'I' && *(fmt+1) == '6' && *(fmt+2) == '4') {\r
 +                      qualifier = *fmt;\r
 +                      fmt += 3;\r
 +              } else if (*fmt == 'I' && *(fmt+1) == '3' && *(fmt+2) == '2') {\r
 +                      qualifier = 'l';\r
 +                      fmt += 3;\r
 +              } else if (*fmt == 'F' && *(fmt+1) == 'p') {\r
 +                      fmt += 1;\r
 +            flags |= REMOVEHEX;\r
 +        }\r
 +\r
 +              /* default base */\r
 +              base = 10;\r
 +\r
 +              switch (*fmt) {\r
 +              case 'c': /* finished */\r
 +             if (qualifier == 'l' || qualifier == 'w') {\r
 +                    wchar_t sw1[2];\r
 +                              /* print unicode string */\r
 +                sw1[0] = (wchar_t) va_arg(args, int);\r
 +                sw1[1] = 0;\r
 +                              str = stringw(str, end, (wchar_t *)&sw1, -1, field_width, precision, flags);\r
 +                      } else {\r
 +                char s1[2];\r
 +                              /* print ascii string */\r
 +                s1[0] = ( unsigned char) va_arg(args, int);\r
 +                s1[1] = 0;\r
 +                              str = string(str, end, (char *)&s1, -1,  field_width, precision, flags);\r
 +                      }\r
 +            continue;\r
 +\r
 +              case 'C': /* finished */\r
 +                      if (!(flags & LEFT))\r
 +                              while (--field_width > 0) {\r
 +                                      if (str <= end)\r
 +                                              *str = ' ';\r
 +                                      ++str;\r
 +                              }\r
 +                      if (qualifier == 'h') {\r
 +                              if (str <= end)\r
 +                                      *str = (unsigned char) va_arg(args, int);\r
 +                              ++str;\r
 +                      } else {\r
 +                              if (str <= end)\r
 +                                      *str = (unsigned char)(wchar_t) va_arg(args, int);\r
 +                              ++str;\r
 +                      }\r
 +                      while (--field_width > 0) {\r
 +                              if (str <= end)\r
 +                                      *str = ' ';\r
 +                              ++str;\r
 +                      }\r
 +                      continue;\r
 +\r
 +              case 's': /* finished */\r
 +                      if (qualifier == 'l' || qualifier == 'w') {\r
 +                              /* print unicode string */\r
 +                              sw = va_arg(args, wchar_t *);\r
 +                              str = stringw(str, end, sw, -1, field_width, precision, flags);\r
 +                      } else {\r
 +                              /* print ascii string */\r
 +                              s = va_arg(args, char *);\r
 +                              str = string(str, end, s, -1,  field_width, precision, flags);\r
 +                      }\r
 +                      continue;\r
 +\r
 +              case 'S':\r
 +                      if (qualifier == 'h') {\r
 +                              /* print ascii string */\r
 +                              s = va_arg(args, char *);\r
 +                              str = string(str, end, s, -1,  field_width, precision, flags);\r
 +                      } else {\r
 +                              /* print unicode string */\r
 +                              sw = va_arg(args, wchar_t *);\r
 +                              str = stringw(str, end, sw, -1, field_width, precision, flags);\r
 +                      }\r
 +                      continue;\r
 +\r
 +              case 'Z':\r
 +                      if (qualifier == 'w') {\r
 +                              /* print counted unicode string */\r
 +                              PUNICODE_STRING pus = va_arg(args, PUNICODE_STRING);\r
 +                              if ((pus == NULL) || (pus->Buffer == NULL)) {\r
 +                                      sw = NULL;\r
 +                                      len = -1;\r
 +                              } else {\r
 +                                      sw = pus->Buffer;\r
 +                                      len = pus->Length / sizeof(WCHAR);\r
 +                              }\r
 +                              str = stringw(str, end, sw, len,  field_width, precision, flags);\r
 +                      } else {\r
 +                              /* print counted ascii string */\r
 +                              PANSI_STRING pus = va_arg(args, PANSI_STRING);\r
 +                              if ((pus == NULL) || (pus->Buffer == NULL)) {\r
 +                                      s = NULL;\r
 +                                      len = -1;\r
 +                              } else {\r
 +                                      s = pus->Buffer;\r
 +                                      len = pus->Length;\r
 +                              }\r
 +                              str = string(str, end, s, len,  field_width, precision, flags);\r
 +                      }\r
 +                      continue;\r
 +\r
 +              case 'p':\r
 +            if ((flags & LARGE) == 0)\r
 +                flags |= LARGE;\r
 +\r
 +                      if (field_width == -1) {\r
 +                              field_width = 2 * sizeof(void *);\r
 +                              flags |= ZEROPAD;\r
 +                      }\r
 +                      str = number(str, end,\r
 +                              (uintptr_t) va_arg(args, void *), 16,\r
 +                              field_width, precision, flags);\r
 +                      continue;\r
 +\r
 +              case 'n':\r
 +                      /* FIXME: What does C99 say about the overflow case here? */\r
 +                      if (qualifier == 'l') {\r
 +                              long * ip = va_arg(args, long *);\r
 +                              *ip = (str - buf);\r
 +                      } else {\r
 +                              int * ip = va_arg(args, int *);\r
 +                              *ip = (str - buf);\r
 +                      }\r
 +                      continue;\r
 +\r
 +              /* float number formats - set up the flags and "break" */\r
 +        case 'e':\r
 +              case 'E':\r
 +              case 'f':\r
 +              case 'g':\r
 +              case 'G':\r
 +          _double = (double)va_arg(args, double);\r
 +         if ( _isnan(_double) ) {\r
 +            s = "Nan";\r
 +            len = 3;\r
 +            while ( len > 0 ) {\r
 +               if (str <= end)\r
 +                                      *str = *s++;\r
 +                              ++str;\r
 +               len --;\r
 +            }\r
 +         } else if ( _isinf(_double) < 0 ) {\r
 +            s = "-Inf";\r
 +            len = 4;\r
 +            while ( len > 0 ) {\r
 +                      if (str <= end)\r
 +                                      *str = *s++;\r
 +                              ++str;\r
 +               len --;\r
 +            }\r
 +         } else if ( _isinf(_double) > 0 ) {\r
 +            s = "+Inf";\r
 +            len = 4;\r
 +            while ( len > 0 ) {\r
 +               if (str <= end)\r
 +                                      *str = *s++;\r
 +                              ++str;\r
 +               len --;\r
 +            }\r
 +         } else {\r
 +            if ( precision == -1 )\r
 +               precision = 6;\r
 +                      str = numberf(str, end, (int)_double, base, field_width, precision, flags);\r
 +         }\r
 +\r
 +          continue;\r
 +\r
 +\r
 +              /* integer number formats - set up the flags and "break" */\r
 +              case 'o':\r
 +                      base = 8;\r
 +                      break;\r
 +\r
 +              case 'b':\r
 +                      base = 2;\r
 +                      break;\r
 +\r
 +              case 'X':\r
 +                      flags |= LARGE;\r
 +              case 'x':\r
 +                      base = 16;\r
 +                      break;\r
 +\r
 +              case 'd':\r
 +              case 'i':\r
 +                      flags |= SIGN;\r
 +              case 'u':\r
 +                      break;\r
 +\r
 +              default:\r
 +                      if (*fmt) {\r
 +                              if (str <= end)\r
 +                                      *str = *fmt;\r
 +                              ++str;\r
 +                      } else\r
 +                              --fmt;\r
 +                      continue;\r
 +              }\r
 +\r
 +              if (qualifier == 'I')\r
 +                      num = va_arg(args, unsigned long long);\r
 +              else if (qualifier == 'l') {\r
 +                      if (flags & SIGN)\r
 +                              num = va_arg(args, long);\r
 +                      else\r
 +                              num = va_arg(args, unsigned long);\r
 +              }\r
 +              else if (qualifier == 'h') {\r
 +                      if (flags & SIGN)\r
 +                              num = va_arg(args, int);\r
 +                      else\r
 +                              num = va_arg(args, unsigned int);\r
 +              }\r
 +              else {\r
 +                      if (flags & SIGN)\r
 +                              num = va_arg(args, int);\r
 +                      else\r
 +                              num = va_arg(args, unsigned int);\r
 +              }\r
 +              str = number(str, end, num, base, field_width, precision, flags);\r
 +      }\r
 +      if (str <= end)\r
 +              *str = '\0';\r
 +      else if (cnt > 0)\r
 +              /* don't write out a null byte if the buf size is zero */\r
 +              *end = '\0';\r
 +      return str-buf;\r
 +}\r
 +\r
 +\r
 +/*\r
 + * @implemented\r
 + */\r
 +int lnx_sprintf(char * buf, const char *fmt, ...)\r
 +{\r
 +      va_list args;\r
 +      int i;\r
 +\r
 +      va_start(args, fmt);\r
 +      i=lnx_vsnprintf(buf,MAXLONG,fmt,args);\r
 +      va_end(args);\r
 +      return i;\r
 +}\r
 +\r
 +#if 0\r
 +/*\r
 + * @implemented\r
 + */\r
 +int _snprintf(char * buf, size_t cnt, const char *fmt, ...)\r
 +{\r
 +      va_list args;\r
 +      int i;\r
 +\r
 +      va_start(args, fmt);\r
 +      i=_vsnprintf(buf,cnt,fmt,args);\r
 +      va_end(args);\r
 +      return i;\r
 +}\r
 +\r
 +\r
 +/*\r
 + * @implemented\r
 + */\r
 +int __cdecl vsprintf(char *buf, const char *fmt, va_list args)\r
 +{\r
 +      return _vsnprintf(buf,MAXLONG,fmt,args);\r
 +}\r
 +#endif\r
 +/* EOF */\r
@@@ -483,7 -483,7 +483,7 @@@ CmpCleanUpKcbCacheWithLock(IN PCM_KEY_C
      /* Cleanup the value cache */
      CmpCleanUpKcbValueCache(Kcb);
  
-     /* Reference the NCB */
+     /* Dereference the NCB */
      CmpDereferenceNameControlBlockWithLock(Kcb->NameBlock);
  
      /* Check if we have an index hint block and free it */
      /* Check if we were already deleted */
      Parent = Kcb->ParentKcb;
      if (!Kcb->Delete) CmpRemoveKeyControlBlock(Kcb);
-     
      /* Set invalid KCB signature */
      Kcb->Signature = CM_KCB_INVALID_SIGNATURE;
-     
      /* Free the KCB as well */
      CmpFreeKeyControlBlock(Kcb);
  
      {
          /* Dereference the parent */
          LockHeldExclusively ?
-             CmpDereferenceKeyControlBlockWithLock(Kcb,LockHeldExclusively) :
-             CmpDelayDerefKeyControlBlock(Kcb);
+             CmpDereferenceKeyControlBlockWithLock(Parent,LockHeldExclusively) :
+             CmpDelayDerefKeyControlBlock(Parent);
      }
  }
  
@@@ -886,6 -886,151 +886,151 @@@ CmpCreateKeyControlBlock(IN PHHIVE Hive
      return Kcb;
  }
  
+ PUNICODE_STRING
+ NTAPI
+ CmpConstructName(IN PCM_KEY_CONTROL_BLOCK Kcb)
+ {
+     PUNICODE_STRING KeyName;
+     ULONG NameLength, i;
+     PCM_KEY_CONTROL_BLOCK MyKcb;
+     PCM_KEY_NODE KeyNode;
+     BOOLEAN DeletedKey = FALSE;
+     PWCHAR TargetBuffer, CurrentNameW;
+     PUCHAR CurrentName;
+     /* Calculate how much size our key name is going to occupy */
+     NameLength = 0;
+     MyKcb = Kcb;
+     while (MyKcb)
+     {
+         /* Add length of the name */
+         if (!MyKcb->NameBlock->Compressed)
+         {
+             NameLength += MyKcb->NameBlock->NameLength;
+         }
+         else
+         {
+             NameLength += CmpCompressedNameSize(MyKcb->NameBlock->Name,
+                                                 MyKcb->NameBlock->NameLength);
+         }
+         /* Sum up the separator too */
+         NameLength += sizeof(WCHAR);
+         /* Go to the parent KCB */
+         MyKcb = MyKcb->ParentKcb;
+     }
+     /* Allocate the unicode string now */
+     KeyName = ExAllocatePoolWithTag(PagedPool,
+                                     NameLength + sizeof(UNICODE_STRING),
+                                     TAG_CM);
+     if (!KeyName) return NULL;
+     /* Set it up */
+     KeyName->Buffer = (PWSTR)(KeyName + 1);
+     KeyName->Length = NameLength;
+     KeyName->MaximumLength = NameLength;
+     /* Loop the keys again, now adding names */
+     NameLength = 0;
+     MyKcb = Kcb;
+     while (MyKcb)
+     {
+         /* Sanity checks for deleted and fake keys */
+         if ((!MyKcb->KeyCell && !MyKcb->Delete) ||
+             !MyKcb->KeyHive ||
+             MyKcb->ExtFlags & CM_KCB_KEY_NON_EXIST)
+         {
+             /* Failure */
+             ExFreePool(KeyName);
+             return NULL;
+         }
+         /* Try to get the name from the keynode,
+            if the key is not deleted */
+         if (!DeletedKey && !MyKcb->Delete)
+         {
+             KeyNode = HvGetCell(MyKcb->KeyHive, MyKcb->KeyCell);
+             if (!KeyNode)
+             {
+                 /* Failure */
+                 ExFreePool(KeyName);
+                 return NULL;
+             }
+         }
+         else
+         {
+             /* The key was deleted */
+             KeyNode = NULL;
+             DeletedKey = TRUE;
+         }
+         /* Get the pointer to the beginning of the current key name */
+         NameLength += (MyKcb->NameBlock->NameLength + 1) * sizeof(WCHAR);
+         TargetBuffer = &KeyName->Buffer[(KeyName->Length - NameLength) / sizeof(WCHAR)];
+         /* Add a separator */
+         TargetBuffer[0] = OBJ_NAME_PATH_SEPARATOR;
+         /* Add the name, but remember to go from the end to the beginning */
+         if (!MyKcb->NameBlock->Compressed)
+         {
+             /* Get the pointer to the name (from the keynode, if possible) */
+             if ((MyKcb->Flags & (KEY_HIVE_ENTRY | KEY_HIVE_EXIT)) ||
+                 !KeyNode)
+             {
+                 CurrentNameW = MyKcb->NameBlock->Name;
+             }
+             else
+             {
+                 CurrentNameW = KeyNode->Name;
+             }
+             /* Copy the name */
+             for (i=0; i < MyKcb->NameBlock->NameLength; i++)
+             {
+                 TargetBuffer[i+1] = *CurrentNameW;
+                 CurrentNameW++;
+             }
+         }
+         else
+         {
+             /* Get the pointer to the name (from the keynode, if possible) */
+             if ((MyKcb->Flags & (KEY_HIVE_ENTRY | KEY_HIVE_EXIT)) ||
+                 !KeyNode)
+             {
+                 CurrentName = (PUCHAR)MyKcb->NameBlock->Name;
+             }
+             else
+             {
+                 CurrentName = (PUCHAR)KeyNode->Name;
+             }
+             /* Copy the name */
+             for (i=0; i < MyKcb->NameBlock->NameLength; i++)
+             {
+                 TargetBuffer[i+1] = (WCHAR)*CurrentName;
+                 CurrentName++;
+             }
+         }
+         /* Release the cell, if needed */
+         if (KeyNode) HvReleaseCell(MyKcb->KeyHive, MyKcb->KeyCell);
+         /* Go to the parent KCB */
+         MyKcb = MyKcb->ParentKcb;
+     }
+     /* Return resulting buffer (both UNICODE_STRING and
+        its buffer following it) */
+     return KeyName;
+ }
  VOID
  NTAPI
  EnlistKeyBodyWithKCB(IN PCM_KEY_BODY KeyBody,
      for (i = 0; i < 4; i++)
      {
          /* Add it into the list */
 -        if (!InterlockedCompareExchangePointer(&KeyBody->KeyControlBlock->
 +        if (!InterlockedCompareExchangePointer((PVOID*)&KeyBody->KeyControlBlock->
                                                 KeyBodyArray[i],
                                                 KeyBody,
                                                 NULL))
@@@ -959,7 -1104,7 +1104,7 @@@ DelistKeyBodyFromKCB(IN PCM_KEY_BODY Ke
      for (i = 0; i < 4; i++)
      {
          /* Add it into the list */
 -        if (InterlockedCompareExchangePointer(&KeyBody->KeyControlBlock->
 +        if (InterlockedCompareExchangePointer((VOID*)&KeyBody->KeyControlBlock->
                                                KeyBodyArray[i],
                                                NULL,
                                                KeyBody) == KeyBody)
@@@ -59,7 -59,7 +59,7 @@@ ExpLookupHandleTableEntry(IN PHANDLE_TA
          /* Direct index */
          case 0:
  
-             /* Use level 1 and just get the entry directlry */
+             /* Use level 1 and just get the entry directly */
              Level1 = (PUCHAR)TableBase;
              Entry = (PVOID)&Level1[Handle.Value *
                                     (sizeof(HANDLE_TABLE_ENTRY) /
@@@ -210,8 -210,8 +210,8 @@@ ExpFreeHandleTable(IN PHANDLE_TABLE Han
      PEPROCESS Process = HandleTable->QuotaProcess;
      ULONG i, j;
      ULONG_PTR TableCode = HandleTable->TableCode;
-     ULONG TableLevel = TableCode & 3;
      ULONG_PTR TableBase = TableCode & ~3;
+     ULONG TableLevel = (ULONG)(TableCode & 3);
      PHANDLE_TABLE_ENTRY Level1, *Level2, **Level3;
      PAGED_CODE();
  
@@@ -516,7 -516,7 +516,7 @@@ ExpAllocateHandleTableEntrySlow(IN PHAN
  
          /* Write the new level and attempt to change the table code */
          TableBase = ((ULONG_PTR)Mid) | 1;
 -        Value = InterlockedExchangePointer(&HandleTable->TableCode, TableBase);
 +        Value = InterlockedExchangePointer((PVOID*)&HandleTable->TableCode, (PVOID)TableBase);
      }
      else if (TableLevel == 1)
      {
              if (!Low) return FALSE;
  
              /* Update the table */
 -            Value = InterlockedExchangePointer(&SecondLevel[i], Low);
 +            Value = InterlockedExchangePointer((PVOID*)&SecondLevel[i], Low);
              ASSERT(Value == NULL);
          }
          else
  
              /* Write the new table and change the table code */
              TableBase = ((ULONG_PTR)High) | 2;
 -            Value = InterlockedExchangePointer(&HandleTable->TableCode,
 +            Value = InterlockedExchangePointer((PVOID*)&HandleTable->TableCode,
                                                 (PVOID)TableBase);
          }
      }
              if (!Mid) return FALSE;
  
              /* Update the table pointer */
 -            Value = InterlockedExchangePointer(&ThirdLevel[i], Mid);
 +            Value = InterlockedExchangePointer((PVOID*)&ThirdLevel[i], Mid);
              ASSERT(Value == NULL);
          }
          else
              if (!Low) return FALSE;
  
              /* Update the table pointer */
 -            Value = InterlockedExchangePointer(&ThirdLevel[i][j], Low);
 +            Value = InterlockedExchangePointer((PVOID*)&ThirdLevel[i][j], Low);
              ASSERT(Value == NULL);
          }
      }
@@@ -661,7 -661,7 +661,7 @@@ ExpMoveFreeHandles(IN PHANDLE_TABLE Han
      }
  
      /* We are strict FIFO, we need to reverse the entries */
-     KEBUGCHECK(0);
+     ASSERT(FALSE);
      return LastFree;
  }
  
@@@ -886,8 -886,8 +886,8 @@@ ExpLockHandleTableEntry(IN PHANDLE_TABL
              /* It's not locked, remove the lock bit to lock it */
              NewValue = OldValue & ~EXHANDLE_TABLE_ENTRY_LOCK_BIT;
              if (InterlockedCompareExchangePointer(&HandleTableEntry->Object,
 -                                                  NewValue,
 -                                                  OldValue) == (PVOID)OldValue)
 +                                                  (PVOID)NewValue,
 +                                                  (PVOID)OldValue) == (PVOID)OldValue)
              {
                  /* We locked it, get out */
                  return TRUE;
@@@ -958,7 -958,7 +958,7 @@@ ExDestroyHandleTable(IN PHANDLE_TABLE H
      if (DestroyHandleProcedure)
      {
          /* FIXME: */
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
  
      /* Free the handle table */
@@@ -1010,7 -1010,7 +1010,7 @@@ ExDestroyHandle(IN PHANDLE_TABLE Handle
      }
  
      /* Clear the handle */
 -    Object = InterlockedExchangePointer(&HandleTableEntry->Object, NULL);
 +    Object = InterlockedExchangePointer((PVOID*)&HandleTableEntry->Object, NULL);
  
      /* Sanity checks */
      ASSERT(Object != NULL);
@@@ -68,7 -68,7 +68,7 @@@ PVOID ExpNlsTableBase
  ULONG ExpAnsiCodePageDataOffset, ExpOemCodePageDataOffset;
  ULONG ExpUnicodeCaseTableDataOffset;
  NLSTABLEINFO ExpNlsTableInfo;
 -ULONG ExpNlsTableSize;
 +SIZE_T ExpNlsTableSize;
  PVOID ExpNlsSectionPointer;
  
  /* CMOS Timer Sanity */
@@@ -196,7 -196,7 +196,7 @@@ ExpInitNls(IN PLOADER_PARAMETER_BLOCK L
      NTSTATUS Status;
      HANDLE NlsSection;
      PVOID SectionBase = NULL;
 -    ULONG ViewSize = 0;
 +    SIZE_T ViewSize = 0;
      LARGE_INTEGER SectionOffset = {{0}};
      PLIST_ENTRY ListHead, NextEntry;
      PMEMORY_ALLOCATION_DESCRIPTOR MdBlock;
      RtlCopyMemory(SectionBase, ExpNlsTableBase, ExpNlsTableSize);
  
      /* Free the previously allocated buffer and set the new location */
-     ExFreePool(ExpNlsTableBase);
+     ExFreePoolWithTag(ExpNlsTableBase, TAG('R', 't', 'l', 'i'));
      ExpNlsTableBase = SectionBase;
  
      /* Initialize the NLS Tables */
@@@ -369,7 -369,7 +369,7 @@@ ExpLoadInitialProcess(IN PINIT_BUFFER I
                        OUT PCHAR *ProcessEnvironment)
  {
      NTSTATUS Status;
 -    ULONG Size;
 +    SIZE_T Size;
      PWSTR p;
      UNICODE_STRING NullString = RTL_CONSTANT_STRING(L"");
      UNICODE_STRING SmssName, Environment, SystemDriveString, DebugString;
@@@ -829,7 -829,7 +829,7 @@@ ExpInitializeExecutive(IN ULONG Cpu
      PLDR_DATA_TABLE_ENTRY NtosEntry;
      PRTL_MESSAGE_RESOURCE_ENTRY MsgEntry;
      ANSI_STRING CsdString;
 -    ULONG Remaining = 0;
 +    SIZE_T Remaining = 0;
      PCHAR RcEnd = NULL;
      CHAR VersionBuffer [65];
  
  
      /* Now fill it in */
      Status = RtlAnsiStringToUnicodeString(&NtSystemRoot, &AnsiPath, FALSE);
-     if (!NT_SUCCESS(Status)) KEBUGCHECK(SESSION3_INITIALIZATION_FAILED);
+     if (!NT_SUCCESS(Status)) KeBugCheck(SESSION3_INITIALIZATION_FAILED);
  
      /* Setup bugcheck messages */
      KiInitializeBugCheck();
  
-     /* Setup initial system settings (FIXME: Needs Cm Rewrite) */
+     /* Setup initial system settings */
      CmGetSystemControlValues(LoaderBlock->RegistryBase, CmControlVector);
  
      /* Load static defaults for Service Pack 1 and add our SVN revision */
      }
  
      /* Initialize the executive at phase 0 */
-     if (!ExInitSystem()) KEBUGCHECK(PHASE0_INITIALIZATION_FAILED);
+     if (!ExInitSystem()) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
  
      /* Initialize the memory manager at phase 0 */
      if (!MmInitSystem(0, LoaderBlock)) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
  #endif
  
      /* Create the Basic Object Manager Types to allow new Object Types */
-     if (!ObInit()) KEBUGCHECK(OBJECT_INITIALIZATION_FAILED);
+     if (!ObInitSystem()) KeBugCheck(OBJECT_INITIALIZATION_FAILED);
  
      /* Load basic Security for other Managers */
-     if (!SeInit()) KEBUGCHECK(SECURITY_INITIALIZATION_FAILED);
+     if (!SeInitSystem()) KeBugCheck(SECURITY_INITIALIZATION_FAILED);
  
      /* Initialize the Process Manager */
-     if (!PsInitSystem(LoaderBlock)) KEBUGCHECK(PROCESS_INITIALIZATION_FAILED);
+     if (!PsInitSystem(LoaderBlock)) KeBugCheck(PROCESS_INITIALIZATION_FAILED);
  
      /* Initialize the PnP Manager */
-     if (!PpInitSystem()) KEBUGCHECK(PP0_INITIALIZATION_FAILED);
+     if (!PpInitSystem()) KeBugCheck(PP0_INITIALIZATION_FAILED);
  
      /* Initialize the User-Mode Debugging Subsystem */
      DbgkInitialize();
  #elif defined(_ARM_)
      SharedUserData->ImageNumberLow = IMAGE_FILE_MACHINE_ARM;
      SharedUserData->ImageNumberHigh = IMAGE_FILE_MACHINE_ARM;
 +#elif defined(_AMD64_)
 +    SharedUserData->ImageNumberLow = IMAGE_FILE_MACHINE_AMD64;
 +    SharedUserData->ImageNumberHigh = IMAGE_FILE_MACHINE_AMD64;
  #else
  #error "Unsupported ReactOS Target"
  #endif
@@@ -1261,8 -1258,7 +1261,8 @@@ Phase1InitializationDiscard(IN PVOID Co
      PCHAR StringBuffer, EndBuffer, BeginBuffer, MpString = "";
      PINIT_BUFFER InitBuffer;
      ANSI_STRING TempString;
 -    ULONG LastTzBias, Size, Length, YearHack = 0, Disposition, MessageCode = 0;
 +    ULONG LastTzBias, Size, YearHack = 0, Disposition, MessageCode = 0;
 +    SIZE_T Length;
      PRTL_USER_PROCESS_INFORMATION ProcessInfo;
      KEY_VALUE_PARTIAL_INFORMATION KeyPartialInfo;
      UNICODE_STRING KeyName, DebugString;
      InbvUpdateProgressBar(5);
  
      /* Call OB initialization again */
-     if (!ObInit()) KeBugCheck(OBJECT1_INITIALIZATION_FAILED);
+     if (!ObInitSystem()) KeBugCheck(OBJECT1_INITIALIZATION_FAILED);
  
      /* Initialize Basic System Objects and Worker Threads */
      if (!ExInitSystem()) KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, 0, 0, 1, 0);
      }
  
      /* Initialize the SRM in Phase 1 */
-     if (!SeInit()) KEBUGCHECK(SECURITY1_INITIALIZATION_FAILED);
+     if (!SeInitSystem()) KeBugCheck(SECURITY1_INITIALIZATION_FAILED);
  
      /* Update the progress bar */
      InbvUpdateProgressBar(10);
                                           KeyValuePartialInformation,
                                           &KeyPartialInfo,
                                           sizeof(KeyPartialInfo),
 -                                         &Length);
 +                                         &Size);
                  if (!NT_SUCCESS(Status)) AlternateShell = FALSE;
              }
  
      ZwClose(ProcessInfo->ProcessHandle);
  
      /* Free the initial process environment */
 -    Size = 0;
 +    Length = 0;
      ZwFreeVirtualMemory(NtCurrentProcess(),
                          (PVOID*)&Environment,
 -                        &Size,
 +                        &Length,
                          MEM_RELEASE);
  
      /* Free the initial process parameters */
 -    Size = 0;
 +    Length = 0;
      ZwFreeVirtualMemory(NtCurrentProcess(),
                          (PVOID*)&ProcessParameters,
 -                        &Size,
 +                        &Length,
                          MEM_RELEASE);
  
      /* Increase init phase */
@@@ -12,7 -12,7 +12,7 @@@
  
  #include <ntoskrnl.h>
  #define NDEBUG
- #include <internal/debug.h>
+ #include <debug.h>
  
  VOID MmPrintMemoryStatistic(VOID);
  
@@@ -899,7 -899,7 +899,7 @@@ QSI_DEF(SystemProcessorPerformanceInfor
        }
  
        CurrentTime.QuadPart = KeQueryInterruptTime();
 -      Prcb = KeGetPcr()->Prcb;
 +      Prcb = KeGetCurrentPrcb();
        for (i = 0; i < KeNumberProcessors; i++)
        {
           Spi->IdleTime.QuadPart = (Prcb->IdleThread->KernelTime + Prcb->IdleThread->UserTime) * 100000LL;
@@@ -1195,11 -1195,7 +1195,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
@@@ -1933,9 -1929,6 +1933,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
@@@ -465,7 -465,6 +465,7 @@@ ExDoCallBack(IN OUT PEX_CALLBACK Callba
  
  #ifdef _WIN64
  #define ExpChangeRundown(x, y, z) InterlockedCompareExchange64((PLONGLONG)x, y, z)
 +#define ExpChangePushlock(lock, new, old) InterlockedCompareExchangePointer((PVOID*)lock, (PVOID)new, (PVOID)old)
  #define ExpSetRundown(x, y) InterlockedExchange64((PLONGLONG)x, y)
  #else
  #define ExpChangeRundown(x, y, z) InterlockedCompareExchange((PLONG)x, PtrToLong(y), PtrToLong(z))
@@@ -934,8 -933,8 +934,8 @@@ ExReleasePushLockExclusive(PEX_PUSH_LOC
      ASSERT(PushLock->Waiting || PushLock->Shared == 0);
  
      /* Unlock the pushlock */
 -    OldValue.Value = InterlockedExchangeAddSizeT((PLONG)PushLock,
 -                                                 -(LONG)EX_PUSH_LOCK_LOCK);
 +    OldValue.Value = InterlockedExchangeAddSizeT((PSIZE_T)PushLock,
 +                                                 -(SIZE_T)EX_PUSH_LOCK_LOCK);
  
      /* Sanity checks */
      ASSERT(OldValue.Locked);
@@@ -1008,13 -1007,6 +1008,6 @@@ ExTryToAcquireResourceExclusiveLite
      IN PERESOURCE Resource
  );
  
- LONGLONG
- FASTCALL
- ExfpInterlockedExchange64(
-     LONGLONG volatile * Destination,
-     PLONGLONG Exchange
- );
  NTSTATUS
  ExpSetTimeZoneInformation(PTIME_ZONE_INFORMATION TimeZoneInformation);
  
@@@ -1069,7 -1061,4 +1062,4 @@@ XIPInit
  #define ExfInterlockedCompareExchange64UL(Destination, Exchange, Comperand) \
     (ULONGLONG)ExfInterlockedCompareExchange64((PLONGLONG)(Destination), (PLONGLONG)(Exchange), (PLONGLONG)(Comperand))
  
- #define ExfpInterlockedExchange64UL(Target, Value) \
-    (ULONGLONG)ExfpInterlockedExchange64((PLONGLONG)(Target), (PLONGLONG)(Value))
  #endif /* __NTOSKRNL_INCLUDE_INTERNAL_EXECUTIVE_H */
@@@ -164,6 -164,13 +164,13 @@@ typedef ULONG PFN_TYPE, *PPFN_TYPE
      (PAGE_WRITECOPY | \
      PAGE_EXECUTE_WRITECOPY)
  
+ #define InterlockedCompareExchangePte(PointerPte, Exchange, Comperand) \
+     InterlockedCompareExchange((PLONG)(PointerPte), Exchange, Comperand)
+ #define InterlockedExchangePte(PointerPte, Value) \
+     InterlockedExchange((PLONG)(PointerPte), Value)
  typedef struct
  {
      ULONG Entry[NR_SECTION_PAGE_ENTRIES];
@@@ -381,6 -388,8 +388,8 @@@ typedef VOI
      BOOLEAN Dirty
  );
  
+ PMM_AVL_TABLE MmKernelAddressSpace;
  /* marea.c *******************************************************************/
  
  NTSTATUS
@@@ -1052,13 -1061,6 +1061,6 @@@ PVOI
  NTAPI
  MmCreateHyperspaceMapping(PFN_TYPE Page);
  
- PFN_TYPE
- NTAPI
- MmChangeHyperspaceMapping(
-     PVOID Address,
-     PFN_TYPE Page
- );
  PFN_TYPE
  NTAPI
  MmDeleteHyperspaceMapping(PVOID Address);
@@@ -1210,13 -1212,6 +1212,6 @@@ VOI
  NTAPI
  MmReferencePageUnsafe(PFN_TYPE Page);
  
- BOOLEAN
- NTAPI
- MmIsAccessedAndResetAccessPage(
-     struct _EPROCESS *Process,
-     PVOID Address
- );
  ULONG
  NTAPI
  MmGetReferenceCountPage(PFN_TYPE Page);
@@@ -1275,14 -1270,14 +1270,14 @@@ NTAP
  MmCreateProcessAddressSpace(
      IN ULONG MinWs,
      IN PEPROCESS Dest,
 -    IN PULONG DirectoryTableBase
 +    IN PULONG_PTR DirectoryTableBase
  );
  
  NTSTATUS
  NTAPI
  MmInitializeHandBuiltProcess(
      IN PEPROCESS Process,
 -    IN PULONG DirectoryTableBase
 +    IN PULONG_PTR DirectoryTableBase
  );
  
  
@@@ -1552,11 -1547,25 +1547,25 @@@ MmCheckSystemImage
      IN BOOLEAN PurgeSection
  );
  
- /* ReactOS Mm Hack */
+ NTSTATUS
+ NTAPI
+ MmCallDllInitialize(
+     IN PLDR_DATA_TABLE_ENTRY LdrEntry,
+     IN PLIST_ENTRY ListHead
+ );
+ /* ReactOS Mm Hacks */
+ VOID
+ FASTCALL
+ MiSyncForProcessAttach(
+     IN PKTHREAD NextThread,
+     IN PEPROCESS Process
+ );
  VOID
  FASTCALL
- MiSyncThreadProcessViews(
-     IN PKTHREAD NextThread
+ MiSyncForContextSwitch(
+     IN PKTHREAD Thread
  );
  
  extern PMM_AVL_TABLE MmKernelAddressSpace;
  #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  #define InterlockedExchange          _InterlockedExchange
  #define InterlockedExchangeAdd       _InterlockedExchangeAdd
+ #define InterlockedOr                _InterlockedOr
+ #define InterlockedAnd               _InterlockedAnd
  
  #include "ke.h"
 +#ifdef _M_AMD64
 +#include "amd64/mm.h"
 +#else
  #include "i386/mm.h"
- #include "i386/fpu.h"
  #include "i386/v86m.h"
 +#endif
  #include "ob.h"
  #include "mm.h"
  #include "ex.h"
  #include "hal.h"
  #include "arch/intrin_i.h"
  
 +ULONG (*FrLdrDbgPrint)(const char *Format, ...);
 +
 +#include <pshpack1.h>
 +/*
 + * Defines a descriptor as it appears in the processor tables
 + */
 +typedef struct __DESCRIPTOR
 +{
 +  ULONG a;
 +  ULONG b;
 +} IDT_DESCRIPTOR, GDT_DESCRIPTOR;
 +
 +#include <poppack.h>
 +//extern GDT_DESCRIPTOR KiGdt[256];
 +
 +/*
 + * Initalization functions (called once by main())
 + */
 +BOOLEAN NTAPI ObInit(VOID);
 +BOOLEAN NTAPI CmInitSystem1(VOID);
 +VOID NTAPI CmShutdownSystem(VOID);
 +BOOLEAN NTAPI KdInitSystem(ULONG Reserved, PLOADER_PARAMETER_BLOCK LoaderBlock);
 +
 +/* FIXME - RtlpCreateUnicodeString is obsolete and should be removed ASAP! */
 +BOOLEAN FASTCALL
 +RtlpCreateUnicodeString(
 +   IN OUT PUNICODE_STRING UniDest,
 +   IN PCWSTR  Source,
 +   IN POOL_TYPE PoolType);
 +
 +VOID
 +NTAPI
 +RtlpLogException(IN PEXCEPTION_RECORD ExceptionRecord,
 +                 IN PCONTEXT ContextRecord,
 +                 IN PVOID ContextData,
 +                 IN ULONG Size);
 +
  /*
   * generic information class probing code
   */
@@@ -146,11 -106,7 +147,11 @@@ typedef struct _INFORMATION_CLASS_INF
  #define IQS(TypeQuery, TypeSet, AlignmentQuery, AlignmentSet, Flags)        \
    { sizeof(TypeQuery), sizeof(TypeSet), sizeof(AlignmentQuery), sizeof(AlignmentSet), Flags }
  
 +#ifndef _M_AMD64
  FORCEINLINE
 +#else
 +static inline
 +#endif
  NTSTATUS
  DefaultSetInfoBufferCheck(ULONG Class,
                            const INFORMATION_CLASS_INFO *ClassList,
      return Status;
  }
  
 +#ifndef _M_AMD64
  FORCEINLINE
 +#else
 +static inline
 +#endif
  NTSTATUS
  DefaultQueryInfoBufferCheck(ULONG Class,
                              const INFORMATION_CLASS_INFO *ClassList,
  
  #endif
  
 +#ifndef _WIN64
  C_ASSERT(FIELD_OFFSET(KUSER_SHARED_DATA, SystemCall) == 0x300);
  C_ASSERT(FIELD_OFFSET(KTHREAD, InitialStack) == KTHREAD_INITIAL_STACK);
  C_ASSERT(FIELD_OFFSET(KTHREAD, Teb) == KTHREAD_TEB);
@@@ -296,10 -247,8 +297,10 @@@ C_ASSERT(FIELD_OFFSET(KTHREAD, TrapFram
  C_ASSERT(FIELD_OFFSET(KTHREAD, CallbackStack) == KTHREAD_CALLBACK_STACK);
  C_ASSERT(FIELD_OFFSET(KTHREAD, ApcState.Process) == KTHREAD_APCSTATE_PROCESS);
  C_ASSERT(FIELD_OFFSET(KPROCESS, DirectoryTableBase) == KPROCESS_DIRECTORY_TABLE_BASE);
- //C_ASSERT(FIELD_OFFSET(KPCR, Tib.ExceptionList) == KPCR_EXCEPTION_LIST);
- //C_ASSERT(FIELD_OFFSET(KPCR, Self) == KPCR_SELF);
+ C_ASSERT(FIELD_OFFSET(KPCR, Tib.ExceptionList) == KPCR_EXCEPTION_LIST);
+ C_ASSERT(FIELD_OFFSET(KPCR, Self) == KPCR_SELF);
 +#endif
 +
  #ifdef _M_IX86
  C_ASSERT(FIELD_OFFSET(KPCR, IRR) == KPCR_IRR);
  C_ASSERT(FIELD_OFFSET(KPCR, IDR) == KPCR_IDR);
@@@ -309,7 -258,7 +310,7 @@@ C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) 
  C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, NpxThread) == KPCR_NPX_THREAD);
  C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) == KPCR_PRCB_DATA);
  C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, KeSystemCalls) == KPCR_SYSTEM_CALLS);
- C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcData) + /*FIELD_OFFSET(KDPC_DATA, DpcQueuDepth)*/12 == KPCR_PRCB_DPC_QUEUE_DEPTH);
+ C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcData) + FIELD_OFFSET(KDPC_DATA, DpcQueueDepth) == KPCR_PRCB_DPC_QUEUE_DEPTH);
  C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcData) + 16 == KPCR_PRCB_DPC_COUNT);
  C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcStack) == KPCR_PRCB_DPC_STACK);
  C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, TimerRequest) == KPCR_PRCB_TIMER_REQUEST);
@@@ -322,7 -271,7 +323,7 @@@ C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) 
  C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, QuantumEnd) == KPCR_PRCB_QUANTUM_END);
  C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DeferredReadyListHead) == KPCR_PRCB_DEFERRED_READY_LIST_HEAD);
  C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, PowerState) == KPCR_PRCB_POWER_STATE_IDLE_FUNCTION);
//C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, PrcbLock) == KPCR_PRCB_PRCB_LOCK);
+ C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, PrcbLock) == KPCR_PRCB_PRCB_LOCK);
  C_ASSERT(FIELD_OFFSET(KIPCR, PrcbData) + FIELD_OFFSET(KPRCB, DpcStack) == KPCR_PRCB_DPC_STACK);
  C_ASSERT(sizeof(FX_SAVE_AREA) == SIZEOF_FX_SAVE_AREA);
  
index 0fa9f7d,0000000..13602a8
mode 100644,000000..100644
--- /dev/null
@@@ -1,47 -1,0 +1,47 @@@
- #include <internal/debug.h>
 +/*
 + * COPYRIGHT:       See COPYING in the top level directory
 + * PROJECT:         ReactOS kernel
 + * FILE:            ntoskrnl/kdbg/kdb.c
 + * PURPOSE:         Kernel Debugger
 + *
 + * PROGRAMMERS:     Gregor Anich
 + */
 +
 +/* INCLUDES ******************************************************************/
 +
 +#include <ntoskrnl.h>
 +#define NDEBUG
++#include <debug.h>
 +
 +/* GLOBALS *******************************************************************/
 +
 +ULONG KdbDebugState = 0; /* KDBG Settings (NOECHO, KDSERIAL) */
 +
 +/* FUNCTIONS *****************************************************************/
 +
 +VOID
 +STDCALL
 +KdbpGetCommandLineSettings(PCHAR p1)
 +{
 +    PCHAR p2;
 +
 +    while (p1 && (p2 = strchr(p1, ' ')))
 +    {
 +        p2++;
 +
 +        if (!_strnicmp(p2, "KDSERIAL", 8))
 +        {
 +            p2 += 8;
 +            KdbDebugState |= KD_DEBUG_KDSERIAL;
 +            KdpDebugMode.Serial = TRUE;
 +        }
 +        else if (!_strnicmp(p2, "KDNOECHO", 8))
 +        {
 +            p2 += 8;
 +            KdbDebugState |= KD_DEBUG_KDNOECHO;
 +        }
 +
 +        p1 = p2;
 +    }
 +}
 +
@@@ -11,7 -11,7 +11,7 @@@
  
  #include <ntoskrnl.h>
  #define NDEBUG
- #include <internal/debug.h>
+ #include <debug.h>
  
  /* TYPES *********************************************************************/
  
@@@ -201,7 -201,6 +201,7 @@@ KdbpKdbTrapFrameFromKernelStack(PVOID K
  
     RtlZeroMemory(KdbTrapFrame, sizeof(KDB_KTRAP_FRAME));
     StackPtr = (ULONG_PTR *) KernelStack;
 +#if _M_X86_
     KdbTrapFrame->Tf.Ebp = StackPtr[3];
     KdbTrapFrame->Tf.Edi = StackPtr[4];
     KdbTrapFrame->Tf.Esi = StackPtr[5];
     KdbTrapFrame->Tf.SegDs = KGDT_R0_DATA;
     KdbTrapFrame->Tf.SegEs = KGDT_R0_DATA;
     KdbTrapFrame->Tf.SegGs = KGDT_R0_DATA;
 +#endif
  
     /* FIXME: what about the other registers??? */
  }
@@@ -407,7 -405,7 +407,7 @@@ KdbpStepIntoInstruction(ULONG_PTR Eip
     }
  
     /* Get the interrupt descriptor */
 -   if (!NT_SUCCESS(KdbpSafeReadMemory(IntDesc, (PVOID)(Idtr.Base + (IntVect * 8)), sizeof (IntDesc))))
 +   if (!NT_SUCCESS(KdbpSafeReadMemory(IntDesc, (PVOID)(ULONG_PTR)(Idtr.Base + (IntVect * 8)), sizeof (IntDesc))))
     {
        /*KdbpPrint("Couldn't access memory at 0x%p\n", (ULONG_PTR)Idtr.Base + (IntVect * 8));*/
        return FALSE;
@@@ -1075,7 -1073,7 +1075,7 @@@ KdbpAttachToThread
     /* Get a pointer to the thread */
     if (!NT_SUCCESS(PsLookupThreadByThreadId(ThreadId, &Thread)))
     {
 -      KdbpPrint("Invalid thread id: 0x%08x\n", (ULONG)ThreadId);
 +      KdbpPrint("Invalid thread id: 0x%08x\n", (ULONG_PTR)ThreadId);
        return FALSE;
     }
     Process = Thread->ThreadsProcess;
@@@ -1154,14 -1152,14 +1154,14 @@@ KdbpAttachToProcess
     /* Get a pointer to the process */
     if (!NT_SUCCESS(PsLookupProcessByProcessId(ProcessId, &Process)))
     {
 -      KdbpPrint("Invalid process id: 0x%08x\n", (ULONG)ProcessId);
 +      KdbpPrint("Invalid process id: 0x%08x\n", (ULONG_PTR)ProcessId);
        return FALSE;
     }
  
     Entry = Process->ThreadListHead.Flink;
     if (Entry == &KdbCurrentProcess->ThreadListHead)
     {
 -      KdbpPrint("No threads in process 0x%08x, cannot attach to process!\n", (ULONG)ProcessId);
 +      KdbpPrint("No threads in process 0x%p, cannot attach to process!\n", ProcessId);
        return FALSE;
     }
  
@@@ -1202,7 -1200,7 +1202,7 @@@ KdbpInternalEnter(
     SavedStackLimit = Thread->Tcb.StackLimit;
     SavedKernelStack = Thread->Tcb.KernelStack;
     Thread->Tcb.InitialStack = Thread->Tcb.StackBase = (char*)KdbStack + KDB_STACK_SIZE;
 -   Thread->Tcb.StackLimit = (ULONG)KdbStack;
 +   Thread->Tcb.StackLimit = (ULONG_PTR)KdbStack;
     Thread->Tcb.KernelStack = (char*)KdbStack + KDB_STACK_SIZE;
  
     /*KdbpPrint("Switching to KDB stack 0x%08x-0x%08x (Current Stack is 0x%08x)\n", Thread->Tcb.StackLimit, Thread->Tcb.StackBase, Esp);*/
@@@ -1333,7 -1331,7 +1333,7 @@@ KdbEnterDebuggerException
                                                    BreakPoint->Data.SavedInstruction, NULL)))
           {
              KdbpPrint("Couldn't restore original instruction after INT3! Cannot continue execution.\n");
-             KEBUGCHECK(0);
+             KeBugCheck(0); // FIXME: Proper bugcode!
           }
        }
  
        else if (BreakPoint->Type == KdbBreakPointTemporary &&
                 BreakPoint->Process == KdbCurrentProcess)
        {
-          ASSERT((TrapFrame->EFlags & X86_EFLAGS_TF) == 0);
+          ASSERT((TrapFrame->EFlags & EFLAGS_TF) == 0);
  
           /*
            * Delete the temporary breakpoint which was used to step over or into the instruction.
              if ((KdbSingleStepOver && !KdbpStepOverInstruction(TrapFrame->Eip)) ||
                  (!KdbSingleStepOver && !KdbpStepIntoInstruction(TrapFrame->Eip)))
              {
-                Context->EFlags |= X86_EFLAGS_TF;
+                Context->EFlags |= EFLAGS_TF;
              }
              goto continue_execution; /* return */
           }
                 BreakPoint->Type == KdbBreakPointTemporary)
        {
           ASSERT(ExceptionCode == STATUS_BREAKPOINT);
-          Context->EFlags |= X86_EFLAGS_TF;
+          Context->EFlags |= EFLAGS_TF;
           KdbBreakPointToReenable = BreakPoint;
        }
  
  
           /* Unset TF if we are no longer single stepping. */
           if (KdbNumSingleSteps == 0)
-             Context->EFlags &= ~X86_EFLAGS_TF;
+             Context->EFlags &= ~EFLAGS_TF;
           goto continue_execution; /* return */
        }
  
        /* Check if we expect a single step */
        if ((TrapFrame->Dr6 & 0xf) == 0 && KdbNumSingleSteps > 0)
        {
-          /*ASSERT((Context->Eflags & X86_EFLAGS_TF) != 0);*/
+          /*ASSERT((Context->Eflags & EFLAGS_TF) != 0);*/
           if (--KdbNumSingleSteps > 0)
           {
              if ((KdbSingleStepOver && KdbpStepOverInstruction(TrapFrame->Eip)) ||
                  (!KdbSingleStepOver && KdbpStepIntoInstruction(TrapFrame->Eip)))
              {
-                Context->EFlags &= ~X86_EFLAGS_TF;
+                Context->EFlags &= ~EFLAGS_TF;
              }
              else
              {
-                Context->EFlags |= X86_EFLAGS_TF;
+                Context->EFlags |= EFLAGS_TF;
              }
                        goto continue_execution; /* return */
           }
                 else 
                 {
-                        Context->EFlags &= ~X86_EFLAGS_TF;
+                        Context->EFlags &= ~EFLAGS_TF;
                         KdbEnteredOnSingleStep = TRUE;
                 }
        }
        if ((KdbSingleStepOver && KdbpStepOverInstruction(KdbCurrentTrapFrame->Tf.Eip)) ||
            (!KdbSingleStepOver && KdbpStepIntoInstruction(KdbCurrentTrapFrame->Tf.Eip)))
        {
-          ASSERT((KdbCurrentTrapFrame->Tf.EFlags & X86_EFLAGS_TF) == 0);
-          /*KdbCurrentTrapFrame->Tf.EFlags &= ~X86_EFLAGS_TF;*/
+          ASSERT((KdbCurrentTrapFrame->Tf.EFlags & EFLAGS_TF) == 0);
+          /*KdbCurrentTrapFrame->Tf.EFlags &= ~EFLAGS_TF;*/
        }
        else
        {
-          Context->EFlags |= X86_EFLAGS_TF;
+          Context->EFlags |= EFLAGS_TF;
        }
     }
  
@@@ -1610,14 -1608,14 +1610,14 @@@ continue_execution
        /* Set the RF flag so we don't trigger the same breakpoint again. */
        if (Resume)
        {
-          TrapFrame->EFlags |= X86_EFLAGS_RF;
+          TrapFrame->EFlags |= EFLAGS_RF;
        }
  
        /* Clear dr6 status flags. */
        TrapFrame->Dr6 &= ~0x0000e00f;
  
        /* Skip the current instruction */
 -      Context->Eip++;
 +//      Context->Eip++;
     }
  
     return ContinueType;
index c3ac026,0000000..73e1bce
mode 100644,000000..100644
--- /dev/null
@@@ -1,188 -1,0 +1,188 @@@
- #include <internal/debug.h>
 +/*
 + * PROJECT:         ReactOS HAL
 + * LICENSE:         GPL - See COPYING in the top level directory
 + * FILE:            hal/halx86/up/spinlock.c
 + * PURPOSE:         Spinlock and Queued Spinlock Support
 + * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
 + */
 +
 +/* INCLUDES ******************************************************************/
 +
 +#include <ntoskrnl.h>
 +#define NDEBUG
++#include <debug.h>
 +
 +#undef KeAcquireSpinLock
 +#undef KeReleaseSpinLock
 +
 +/* FUNCTIONS *****************************************************************/
 +
 +/*
 + * @implemented
 + */
 +KIRQL
 +KeAcquireSpinLockRaiseToSynch(PKSPIN_LOCK SpinLock)
 +{
 +#ifndef CONFIG_SMP
 +    /* Simply raise to dispatch */
 +    return KfRaiseIrql(DISPATCH_LEVEL);
 +#else
 +    UNIMPLEMENTED;
 +#endif
 +}
 +
 +/*
 + * @implemented
 + */
 +KIRQL
 +NTAPI
 +KeAcquireSpinLockRaiseToDpc(PKSPIN_LOCK SpinLock)
 +{
 +#ifndef CONFIG_SMP
 +    /* Simply raise to dispatch */
 +    return KfRaiseIrql(DISPATCH_LEVEL);
 +#else
 +    UNIMPLEMENTED;
 +#endif
 +}
 +
 +/*
 + * @implemented
 + */
 +VOID
 +NTAPI
 +KeReleaseSpinLock(PKSPIN_LOCK SpinLock,
 +                  KIRQL OldIrql)
 +{
 +#ifndef CONFIG_SMP
 +    /* Simply lower IRQL back */
 +    KfLowerIrql(OldIrql);
 +#else
 +    UNIMPLEMENTED;
 +#endif
 +}
 +
 +/*
 + * @implemented
 + */
 +KIRQL
 +KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
 +{
 +#ifndef CONFIG_SMP
 +    /* Simply raise to dispatch */
 +    return KfRaiseIrql(DISPATCH_LEVEL);
 +#else
 +    UNIMPLEMENTED;
 +#endif
 +}
 +
 +/*
 + * @implemented
 + */
 +KIRQL
 +KeAcquireQueuedSpinLockRaiseToSynch(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
 +{
 +#ifndef CONFIG_SMP
 +    /* Simply raise to dispatch */
 +    return KfRaiseIrql(DISPATCH_LEVEL);
 +#else
 +    UNIMPLEMENTED;
 +#endif
 +}
 +
 +/*
 + * @implemented
 + */
 +VOID
 +KeAcquireInStackQueuedSpinLock(IN PKSPIN_LOCK SpinLock,
 +                               IN PKLOCK_QUEUE_HANDLE LockHandle)
 +{
 +#ifndef CONFIG_SMP
 +    /* Simply raise to dispatch */
 +    LockHandle->OldIrql = KfRaiseIrql(DISPATCH_LEVEL);
 +#else
 +    UNIMPLEMENTED;
 +#endif
 +}
 +
 +/*
 + * @implemented
 + */
 +VOID
 +KeAcquireInStackQueuedSpinLockRaiseToSynch(IN PKSPIN_LOCK SpinLock,
 +                                           IN PKLOCK_QUEUE_HANDLE LockHandle)
 +{
 +#ifndef CONFIG_SMP
 +    /* Simply raise to synch */
 +    LockHandle->OldIrql = KfRaiseIrql(SYNCH_LEVEL);
 +#else
 +    UNIMPLEMENTED;
 +#endif
 +}
 +
 +/*
 + * @implemented
 + */
 +VOID
 +KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber,
 +                        IN KIRQL OldIrql)
 +{
 +#ifndef CONFIG_SMP
 +    /* Simply lower IRQL back */
 +    KfLowerIrql(OldIrql);
 +#else
 +    UNIMPLEMENTED;
 +#endif
 +}
 +
 +/*
 + * @implemented
 + */
 +VOID
 +KeReleaseInStackQueuedSpinLock(IN PKLOCK_QUEUE_HANDLE LockHandle)
 +{
 +#ifndef CONFIG_SMP
 +    /* Simply lower IRQL back */
 +    KfLowerIrql(LockHandle->OldIrql);
 +#else
 +    UNIMPLEMENTED;
 +#endif
 +}
 +
 +/*
 + * @implemented
 + */
 +BOOLEAN
 +KeTryToAcquireQueuedSpinLockRaiseToSynch(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber,
 +                                         IN PKIRQL OldIrql)
 +{
 +#ifndef CONFIG_SMP
 +    /* Simply raise to dispatch */
 +    *OldIrql = KfRaiseIrql(DISPATCH_LEVEL);
 +
 +    /* Always return true on UP Machines */
 +    return TRUE;
 +#else
 +    UNIMPLEMENTED;
 +#endif
 +}
 +
 +/*
 + * @implemented
 + */
 +LOGICAL
 +KeTryToAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber,
 +                             OUT PKIRQL OldIrql)
 +{
 +#ifndef CONFIG_SMP
 +    /* Simply raise to dispatch */
 +    *OldIrql = KfRaiseIrql(DISPATCH_LEVEL);
 +
 +    /* Always return true on UP Machines */
 +    return TRUE;
 +#else
 +    UNIMPLEMENTED;
 +#endif
 +}
 +
 +/* EOF */
@@@ -10,7 -10,7 +10,7 @@@
  
  #include <ntoskrnl.h>
  #define NDEBUG
- #include <internal/debug.h>
+ #include <debug.h>
  
  #if defined (ALLOC_PRAGMA)
  #pragma alloc_text(INIT, KiInitializeBugCheck)
@@@ -227,7 -227,7 +227,7 @@@ KeRosCaptureUserStackBackTrace(IN ULON
      return (USHORT)i;
  }
  
 -
 +#ifndef _M_AMD64
  VOID
  FASTCALL
  KeRosDumpStackFrameArray(IN PULONG Frames,
@@@ -316,7 -316,6 +316,7 @@@ KeRosDumpStackFrames(IN PULONG Frame OP
          }
      }
  }
 +#endif
  
  VOID
  NTAPI
@@@ -726,8 -725,8 +726,8 @@@ 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],
 +            "\r\n\r\n*** STOP: 0x%p (0x%p,0x%p,0x%p,0x%p)\r\n\r\n",
 +            (PVOID)KiBugCheckData[0],
              (PVOID)KiBugCheckData[1],
              (PVOID)KiBugCheckData[2],
              (PVOID)KiBugCheckData[3],
@@@ -76,7 -76,7 +76,7 @@@ KeSetSystemTime(IN PLARGE_INTEGER NewTi
      KeLowerIrql(OldIrql2);
  
      /* Check if we need to adjust interrupt time */
-     if (FixInterruptTime) KEBUGCHECK(0);
+     if (FixInterruptTime) ASSERT(FALSE);
  
      /* Setup a temporary list of absolute timers */
      InitializeListHead(&TempList);
@@@ -196,7 -196,6 +196,7 @@@ KeQueryTickCount(IN PLARGE_INTEGER Tick
      }
  }
  
 +#ifndef _M_AMD64
  /*
   * @implemented
   */
@@@ -239,7 -238,6 +239,7 @@@ KeQueryInterruptTime(VOID
      /* Return the time value */
      return CurrentTime.QuadPart;
  }
 +#endif
  
  /*
   * @implemented
  #ifdef _M_PPC
  #include <ppcmmu/mmu.h>
  #define KERNEL_RVA(x) RVA(x,0x80800000)
 -#define KERNEL_DESCRIPTOR_PAGE(x) (((ULONG_PTR)x + KernelBase) >> PAGE_SHIFT)
 +#define KERNEL_DESCRIPTOR_PAGE(x) (((ULONG_PTR)(x) + KernelBase) >> PAGE_SHIFT)
  #else
  #define KERNEL_RVA(x) RVA(x,KSEG0_BASE)
 -#define KERNEL_DESCRIPTOR_PAGE(x) (((ULONG_PTR)x &~ KSEG0_BASE) >> PAGE_SHIFT)
 +#define KERNEL_DESCRIPTOR_PAGE(x) (((ULONG_PTR)(x) & ~KSEG0_BASE) >> PAGE_SHIFT)
  #endif
  
  typedef struct _BIOS_MEMORY_DESCRIPTOR
@@@ -29,9 -29,6 +29,9 @@@
  
  /* GLOBALS *******************************************************************/
  
 +/* Function pointer for early debug prints */
 +ULONG (*FrLdrDbgPrint)(const char *Format, ...);
 +
  /* FreeLDR Loader Data */
  PROS_LOADER_PARAMETER_BLOCK KeRosLoaderBlock;
  BOOLEAN AcpiTableDetected = FALSE;
@@@ -76,7 -73,7 +76,7 @@@ NTAP
  KiRosGetMdFromArray(VOID)
  {
      /* Return the next MD from the list, but make sure we don't overflow */
-     if (BldrCurrentMd > 60) KEBUGCHECK(0);
+     if (BldrCurrentMd > 60) ASSERT(FALSE);
      return &BldrMemoryDescriptors[BldrCurrentMd++];
  }
  
@@@ -872,7 -869,7 +872,7 @@@ KiRosBuildArcMemoryList(VOID
  VOID
  NTAPI
  KiRosFixupComponentTree(IN PCONFIGURATION_COMPONENT_DATA p,
 -                        IN ULONG i)
 +                        IN ULONG_PTR i)
  {
      PCONFIGURATION_COMPONENT pp;
  
@@@ -949,7 -946,7 +949,7 @@@ KiRosFrldrLpbToNtLpb(IN PROS_LOADER_PAR
      /* Build entries for ReactOS memory ranges, which uses ARC Descriptors */
      KiRosBuildOsMemoryMap();
  
 -#ifdef _M_IX86
 +#if defined(_M_IX86) || defined(_M_AMD64)
      /* Build entries for the reserved map, which uses ARC Descriptors */
      KiRosBuildReservedMemoryMap();
  #endif
      /* Now mark the remainder of the FreeLDR 6MB area as "in use" */
      KiRosAllocateNtDescriptor(LoaderMemoryData,
                                KERNEL_DESCRIPTOR_PAGE(RosEntry->ModEnd),
 -                              KERNEL_DESCRIPTOR_PAGE((0x80800000 + 0x600000)) -
 +                              KERNEL_DESCRIPTOR_PAGE((RosLoaderBlock->KernelBase + 0x600000)) -
                                KERNEL_DESCRIPTOR_PAGE(RosEntry->ModEnd),
                                0,
                                &Base);
      LoaderBlock->Extension->MajorVersion = 5;
      LoaderBlock->Extension->MinorVersion = 2;
  
++
++// FIXME FIXME FIXME NOW!!!!
++
      /* FreeLDR hackllocates 1536 static pages for the initial boot images */
      LoaderBlock->Extension->LoaderPagesSpanned = 1536 * PAGE_SIZE;
  
@@@ -1300,15 -1297,12 +1303,15 @@@ KiRosPrepareForSystemStartup(IN ULONG D
      /* Save pointer to ROS Block */
      KeRosLoaderBlock = LoaderBlock;
  
 +    /* Get debugging function */
 +    FrLdrDbgPrint = LoaderBlock->FrLdrDbgPrint;
 +
      /* Save memory manager data */
      KeMemoryMapRangeCount = 0;
      if (LoaderBlock->Flags & MB_FLAGS_MMAP_INFO)
      {
          /* We have a memory map from the nice BIOS */
 -        ent = ((PULONG)(LoaderBlock->MmapAddr - sizeof(ULONG)));
 +        ent = ((PULONG)(LoaderBlock->MmapAddr - sizeof(ULONG))); // FIXME: this is ugly
          size = *ent;
          i = 0;
  
  
          /* Save data */
          LoaderBlock->MmapLength = KeMemoryMapRangeCount * sizeof(ADDRESS_RANGE);
 -        LoaderBlock->MmapAddr = (ULONG)KeMemoryMap;
 +        LoaderBlock->MmapAddr = (ULONG_PTR)KeMemoryMap;
      }
      else
      {
          /* Nothing from BIOS */
          LoaderBlock->MmapLength = 0;
 -        LoaderBlock->MmapAddr = (ULONG)KeMemoryMap;
 +        LoaderBlock->MmapAddr = (ULONG_PTR)KeMemoryMap;
      }
  
  #if defined(_M_IX86)
@@@ -10,7 -10,7 +10,7 @@@
  
  #include <ntoskrnl.h>
  #define NDEBUG
- #include <internal/debug.h>
+ #include <debug.h>
  
  #define LQ_WAIT     1
  #define LQ_OWN      2
@@@ -86,7 -86,6 +86,7 @@@ KeReleaseQueuedSpinLockFromDpcLevel(IN 
  
  /* PUBLIC FUNCTIONS **********************************************************/
  
 +#ifdef _X86_
  /*
   * @implemented
   */
@@@ -97,7 -96,6 +97,7 @@@ KeInitializeSpinLock(IN PKSPIN_LOCK Spi
      /* Clear it */
      *SpinLock = 0;
  }
 +#endif
  
  /*
   * @implemented
index 97848d6,0000000..b21af64
mode 100644,000000..100644
--- /dev/null
@@@ -1,354 -1,0 +1,354 @@@
- #include <internal/debug.h>
 +/*
 + * COPYRIGHT:       See COPYING in the top level directory
 + * PROJECT:         ReactOS kernel
 + * FILE:            ntoskrnl/mm/i386/page.c
 + * PURPOSE:         Low level memory managment manipulation
 + *
 + * PROGRAMMERS:     David Welch (welch@cwcom.net)
 + */
 +
 +/* INCLUDES ***************************************************************/
 +
 +#include <ntoskrnl.h>
 +#define NDEBUG
-         KEBUGCHECK(0);
++#include <debug.h>
 +
 +#if defined (ALLOC_PRAGMA)
 +#pragma alloc_text(INIT, MmInitGlobalKernelPageDirectory)
 +#pragma alloc_text(INIT, MiInitPageDirectoryMap)
 +#endif
 +
 +
 +/* GLOBALS *****************************************************************/
 +
 +ULONG64 MmGlobalKernelPageDirectory[512];
 +
 +
 +/* FUNCTIONS ***************************************************************/
 +
 +BOOLEAN MmUnmapPageTable(PULONG Pt);
 +
 +ULONG_PTR
 +NTAPI
 +MiFlushTlbIpiRoutine(ULONG_PTR Address)
 +{
 +    UNIMPLEMENTED;
 +    return 0;
 +}
 +
 +VOID
 +MiFlushTlb(PULONG Pt, PVOID Address)
 +{
 +    UNIMPLEMENTED;
 +}
 +
 +
 +
 +PULONG_PTR
 +MmGetPageDirectory(VOID)
 +{
 +   return (PULONG_PTR)__readcr3();
 +}
 +
 +static ULONG
 +ProtectToPTE(ULONG flProtect)
 +{
 +
 +}
 +
 +NTSTATUS
 +NTAPI
 +Mmi386ReleaseMmInfo(PEPROCESS Process)
 +{
 +    UNIMPLEMENTED;
 +    return STATUS_UNSUCCESSFUL;
 +}
 +
 +NTSTATUS
 +NTAPI
 +MmInitializeHandBuiltProcess(IN PEPROCESS Process,
 +                             IN PULONG_PTR DirectoryTableBase)
 +{
 +    UNIMPLEMENTED;
 +    return STATUS_UNSUCCESSFUL;
 +}
 +
 +BOOLEAN
 +STDCALL
 +MmCreateProcessAddressSpace(IN ULONG MinWs,
 +                            IN PEPROCESS Process,
 +                            IN PULONG_PTR DirectoryTableBase)
 +{
 +    UNIMPLEMENTED;
 +    return 0;
 +}
 +
 +VOID
 +NTAPI
 +MmDeletePageTable(PEPROCESS Process, PVOID Address)
 +{
 +    UNIMPLEMENTED;
 +}
 +
 +VOID
 +NTAPI
 +MmFreePageTable(PEPROCESS Process, PVOID Address)
 +{
 +    UNIMPLEMENTED;
 +}
 +
 +BOOLEAN MmUnmapPageTable(PULONG Pt)
 +{
 +    UNIMPLEMENTED;
 +    return FALSE;
 +}
 +
 +PFN_TYPE
 +NTAPI
 +MmGetPfnForProcess(PEPROCESS Process,
 +                   PVOID Address)
 +{
 +    UNIMPLEMENTED;
 +    return 0;
 +}
 +
 +VOID
 +NTAPI
 +MmDisableVirtualMapping(PEPROCESS Process, PVOID Address, BOOLEAN* WasDirty, PPFN_TYPE Page)
 +{
 +    UNIMPLEMENTED;
 +}
 +
 +VOID
 +NTAPI
 +MmRawDeleteVirtualMapping(PVOID Address)
 +{
 +    UNIMPLEMENTED;
 +}
 +
 +VOID
 +NTAPI
 +MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, BOOLEAN FreePage,
 +                       BOOLEAN* WasDirty, PPFN_TYPE Page)
 +{
 +    UNIMPLEMENTED;
 +}
 +
 +VOID
 +NTAPI
 +MmDeletePageFileMapping(PEPROCESS Process, PVOID Address,
 +                        SWAPENTRY* SwapEntry)
 +{
 +    UNIMPLEMENTED;
 +}
 +
 +BOOLEAN
 +Mmi386MakeKernelPageTableGlobal(PVOID PAddress)
 +{
 +    UNIMPLEMENTED;
 +    return FALSE;
 +}
 +
 +BOOLEAN
 +NTAPI
 +MmIsDirtyPage(PEPROCESS Process, PVOID Address)
 +{
 +    UNIMPLEMENTED;
 +    return FALSE;
 +}
 +
 +BOOLEAN
 +NTAPI
 +MmIsAccessedAndResetAccessPage(PEPROCESS Process, PVOID Address)
 +{
 +    UNIMPLEMENTED;
 +    return 0;
 +}
 +
 +VOID
 +NTAPI
 +MmSetCleanPage(PEPROCESS Process, PVOID Address)
 +{
 +    UNIMPLEMENTED;
 +}
 +
 +VOID
 +NTAPI
 +MmSetDirtyPage(PEPROCESS Process, PVOID Address)
 +{
 +    UNIMPLEMENTED;
 +}
 +
 +VOID
 +NTAPI
 +MmEnableVirtualMapping(PEPROCESS Process, PVOID Address)
 +{
 +    UNIMPLEMENTED;
 +}
 +
 +BOOLEAN
 +NTAPI
 +MmIsPagePresent(PEPROCESS Process, PVOID Address)
 +{
 +    UNIMPLEMENTED;
 +    return 0;
 +}
 +
 +BOOLEAN
 +NTAPI
 +MmIsPageSwapEntry(PEPROCESS Process, PVOID Address)
 +{
 +    UNIMPLEMENTED;
 +    return 0;
 +}
 +
 +NTSTATUS
 +NTAPI
 +MmCreateVirtualMappingForKernel(PVOID Address,
 +                                ULONG flProtect,
 +                                PPFN_TYPE Pages,
 +                              ULONG PageCount)
 +{
 +    UNIMPLEMENTED;
 +    return STATUS_UNSUCCESSFUL;
 +}
 +
 +NTSTATUS
 +NTAPI
 +MmCreatePageFileMapping(PEPROCESS Process,
 +                        PVOID Address,
 +                        SWAPENTRY SwapEntry)
 +{
 +    UNIMPLEMENTED;
 +    return STATUS_UNSUCCESSFUL;
 +}
 +
 +
 +NTSTATUS
 +NTAPI
 +MmCreateVirtualMappingUnsafe(PEPROCESS Process,
 +                             PVOID Address,
 +                             ULONG flProtect,
 +                             PPFN_TYPE Pages,
 +                             ULONG PageCount)
 +{
 +    UNIMPLEMENTED;
 +    return STATUS_UNSUCCESSFUL;
 +}
 +
 +NTSTATUS
 +NTAPI
 +MmCreateVirtualMapping(PEPROCESS Process,
 +                       PVOID Address,
 +                       ULONG flProtect,
 +                       PPFN_TYPE Pages,
 +                       ULONG PageCount)
 +{
 +    UNIMPLEMENTED;
 +    return STATUS_UNSUCCESSFUL;
 +}
 +
 +ULONG
 +NTAPI
 +MmGetPageProtect(PEPROCESS Process, PVOID Address)
 +{
 +    UNIMPLEMENTED;
 +    return 0;
 +}
 +
 +VOID
 +NTAPI
 +MmSetPageProtect(PEPROCESS Process, PVOID Address, ULONG flProtect)
 +{
 +    UNIMPLEMENTED;
 +}
 +
 +/*
 + * @implemented
 + */
 +PHYSICAL_ADDRESS STDCALL
 +MmGetPhysicalAddress(PVOID vaddr)
 +{
 +      PHYSICAL_ADDRESS ret = {{0}};
 +    UNIMPLEMENTED;
 +    return ret;
 +}
 +
 +PVOID
 +NTAPI
 +MmCreateHyperspaceMapping(PFN_TYPE Page)
 +{
 +    UNIMPLEMENTED;
 +    return NULL;
 +}
 +
 +PFN_TYPE
 +NTAPI
 +MmChangeHyperspaceMapping(PVOID Address, PFN_TYPE NewPage)
 +{
 +    UNIMPLEMENTED;
 +    return 0;
 +}
 +
 +PFN_TYPE
 +NTAPI
 +MmDeleteHyperspaceMapping(PVOID Address)
 +{
 +    UNIMPLEMENTED;
 +    return 0;
 +}
 +
 +VOID
 +NTAPI
 +MmUpdatePageDir(PEPROCESS Process, PVOID Address, ULONG Size)
 +{
 +    ULONG StartIndex, EndIndex, Index;
 +    PULONG64 Pde;
 +
 +    /* Sanity check */
 +    if (Address < MmSystemRangeStart)
 +    {
++        KeBugCheck(0);
 +    }
 +
 +    /* Get pointer to the page directory to update */
 +    if (Process != NULL && Process != PsGetCurrentProcess())
 +    {
 +//       Pde = MmCreateHyperspaceMapping(PTE_TO_PFN(Process->Pcb.DirectoryTableBase[0]));
 +    }
 +    else
 +    {
 +        Pde = (PULONG64)PXE_BASE;
 +    }
 +
 +    /* Update PML4 entries */
 +    StartIndex = VAtoPXI(Address);
 +    EndIndex = VAtoPXI((ULONG64)Address + Size);
 +    for (Index = StartIndex; Index <= EndIndex; Index++)
 +    {
 +        if (Index != VAtoPXI(PXE_BASE))
 +        {
 +            (void)InterlockedCompareExchangePointer((PVOID*)&Pde[Index],
 +                                                    MmGlobalKernelPageDirectory[Index],
 +                                                    0);
 +        }
 +    }
 +}
 +
 +VOID
 +INIT_FUNCTION
 +NTAPI
 +MmInitGlobalKernelPageDirectory(VOID)
 +{
 +    UNIMPLEMENTED;
 +}
 +
 +VOID
 +INIT_FUNCTION
 +NTAPI
 +MiInitPageDirectoryMap(VOID)
 +{
 +    UNIMPLEMENTED;
 +}
 +
 +/* EOF */
@@@ -11,7 -11,7 +11,7 @@@
  
  #include <ntoskrnl.h>
  #define NDEBUG
- #include <internal/debug.h>
+ #include <debug.h>
  
  /* FUNCTIONS *****************************************************************/
  
@@@ -225,7 -225,7 +225,7 @@@ MmFreeContiguousMemory(IN PVOID BaseAdd
   */
  VOID STDCALL
  MmFreeContiguousMemorySpecifyCache(IN PVOID BaseAddress,
 -                                   IN ULONG NumberOfBytes,
 +                                   IN SIZE_T NumberOfBytes,
                                     IN MEMORY_CACHING_TYPE CacheType)
  {
     MmLockAddressSpace(MmGetKernelAddressSpace());
@@@ -11,7 -11,7 +11,7 @@@
  
  #include <ntoskrnl.h>
  #define NDEBUG
- #include <internal/debug.h>
+ #include <debug.h>
  
  #if defined (ALLOC_PRAGMA)
  #pragma alloc_text(INIT, MmInitGlobalKernelPageDirectory)
@@@ -62,25 -62,6 +62,6 @@@ __inline LARGE_INTEGER PTE_TO_PAGE(ULON
  
  BOOLEAN MmUnmapPageTable(PULONG Pt);
  
- ULONG_PTR
- NTAPI
- MiFlushTlbIpiRoutine(ULONG_PTR Address)
- {
-     if (Address == (ULONG_PTR)-1)
-     {
-         KeFlushCurrentTb();
-     }
-     else if (Address == (ULONG_PTR)-2)
-     {
-         KeFlushCurrentTb();
-     }
-     else
-     {
-         __invlpg((PVOID)Address);
-     }
-     return 0;
- }
  VOID
  MiFlushTlb(PULONG Pt, PVOID Address)
  {
@@@ -90,8 -71,6 +71,6 @@@
      }
  }
  
  PULONG
  MmGetPageDirectory(VOID)
  {
@@@ -118,7 -97,7 +97,7 @@@ ProtectToPTE(ULONG flProtect
      else
      {
          DPRINT1("Unknown main protection type.\n");
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
      
      if (flProtect & PAGE_SYSTEM)
@@@ -185,7 -164,7 +164,7 @@@ Mmi386ReleaseMmInfo(PEPROCESS Process
  NTSTATUS
  NTAPI
  MmInitializeHandBuiltProcess(IN PEPROCESS Process,
 -                             IN PULONG DirectoryTableBase)
 +                             IN PULONG_PTR DirectoryTableBase)
  {
      /* Share the directory base with the idle process */
      DirectoryTableBase[0] = PsGetCurrentProcess()->Pcb.DirectoryTableBase[0];
@@@ -209,7 -188,7 +188,7 @@@ MmCreateProcessAddressSpace(IN ULONG Mi
      NTSTATUS Status;
      ULONG i, j;
      PFN_TYPE Pfn[2];
 -    PULONG PageDirectory;
 +    PULONG_PTR PageDirectory;
      
      DPRINT("MmCopyMmInfo(Src %x, Dest %x)\n", MinWs, Process);
      
@@@ -262,7 -241,7 +241,7 @@@ MmDeletePageTable(PEPROCESS Process, PV
      
      if (Address >= MmSystemRangeStart)
      {
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
          //       MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)] = 0;
      }
      if (Process != NULL && Process != CurrentProcess)
      }
  }
  
- VOID
- NTAPI
- MmFreePageTable(PEPROCESS Process, PVOID Address)
- {
-     PEPROCESS CurrentProcess = PsGetCurrentProcess();
-     ULONG i;
-     PFN_TYPE Pfn;
-     PULONG PageTable;
-     
-     DPRINT("ProcessId %d, Address %x\n", Process->UniqueProcessId, Address);
-     if (Process != NULL && Process != CurrentProcess)
-     {
-         KeAttachProcess(&Process->Pcb);
-     }
-     
-     PageTable = (PULONG)PAGE_ROUND_DOWN((PVOID)MiAddressToPte(Address));
-     for (i = 0; i < 1024; i++)
-     {
-         if (PageTable[i] != 0)
-         {
-             DbgPrint("Page table entry not clear at %x/%x (is %x)\n",
-                      ((ULONG)Address / (4*1024*1024)), i, PageTable[i]);
-             KEBUGCHECK(0);
-         }
-     }
-     Pfn = MiAddressToPde(Address)->u.Hard.PageFrameNumber;
-     MiAddressToPde(Address)->u.Long = 0;
-     MiFlushTlb((PULONG)MiAddressToPde(Address), MiAddressToPte(Address));
-     
-     if (Address >= MmSystemRangeStart)
-     {
-         //    MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)] = 0;
-         KEBUGCHECK(0);
-     }
-     else
-     {
-         MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn);
-     }
-     if (Process != NULL && Process != CurrentProcess)
-     {
-         KeDetachProcess();
-     }
- }
  static PULONG
  MmGetPageTableForProcess(PEPROCESS Process, PVOID Address, BOOLEAN Create)
  {
          PageDir = MmCreateHyperspaceMapping(PTE_TO_PFN(Process->Pcb.DirectoryTableBase[0]));
          if (PageDir == NULL)
          {
-             KEBUGCHECK(0);
+             ASSERT(FALSE);
          }
-         if (0 == InterlockedCompareExchangeUL(&PageDir[PdeOffset], 0, 0))
+         if (0 == InterlockedCompareExchangePte(&PageDir[PdeOffset], 0, 0))
          {
              if (Create == FALSE)
              {
              Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
              if (!NT_SUCCESS(Status) || Pfn == 0)
              {
-                 KEBUGCHECK(0);
+                 ASSERT(FALSE);
              }
-             Entry = InterlockedCompareExchangeUL(&PageDir[PdeOffset], PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER, 0);
+             Entry = InterlockedCompareExchangePte(&PageDir[PdeOffset], PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER, 0);
              if (Entry != 0)
              {
                  MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn);
          Pt = MmCreateHyperspaceMapping(Pfn);
          if (Pt == NULL)
          {
-             KEBUGCHECK(0);
+             ASSERT(FALSE);
          }
          return Pt + ADDR_TO_PTE_OFFSET(Address);
      }
      PageDir = (PULONG)MiAddressToPde(Address);
-     if (0 == InterlockedCompareExchangeUL(PageDir, 0, 0))
+     if (0 == InterlockedCompareExchangePte(PageDir, 0, 0))
      {
          if (Address >= MmSystemRangeStart)
          {
-             if (0 == InterlockedCompareExchangeUL(&MmGlobalKernelPageDirectory[PdeOffset], 0, 0))
+             if (0 == InterlockedCompareExchangePte(&MmGlobalKernelPageDirectory[PdeOffset], 0, 0))
              {
                  if (Create == FALSE)
                  {
                  Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
                  if (!NT_SUCCESS(Status) || Pfn == 0)
                  {
-                     KEBUGCHECK(0);
+                     ASSERT(FALSE);
                  }
                  Entry = PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE;
                  if (Ke386GlobalPagesEnabled)
                  {
                      Entry |= PA_GLOBAL;
                  }
-                 if(0 != InterlockedCompareExchangeUL(&MmGlobalKernelPageDirectory[PdeOffset], Entry, 0))
+                 if(0 != InterlockedCompareExchangePte(&MmGlobalKernelPageDirectory[PdeOffset], Entry, 0))
                  {
                      MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn);
                  }
              }
-             (void)InterlockedExchangeUL(PageDir, MmGlobalKernelPageDirectory[PdeOffset]);
+             InterlockedExchangePte(PageDir, MmGlobalKernelPageDirectory[PdeOffset]);
          }
          else
          {
              Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
              if (!NT_SUCCESS(Status) || Pfn == 0)
              {
-                 KEBUGCHECK(0);
+                 ASSERT(FALSE);
              }
-             Entry = InterlockedCompareExchangeUL(PageDir, PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER, 0);
+             Entry = InterlockedCompareExchangePte(PageDir, PFN_TO_PTE(Pfn) | PA_PRESENT | PA_READWRITE | PA_USER, 0);
              if (Entry != 0)
              {
                  MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn);
@@@ -468,7 -403,7 +403,7 @@@ MmDisableVirtualMapping(PEPROCESS Proce
      Pt = MmGetPageTableForProcess(Process, Address, FALSE);
      if (Pt == NULL)
      {
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
      /*
       * Atomically disable the present bit and get the old value.
      do
      {
          Pte = *Pt;
-     } while (Pte != InterlockedCompareExchangeUL(Pt, Pte & ~PA_PRESENT, Pte));
+     } while (Pte != InterlockedCompareExchangePte(Pt, Pte & ~PA_PRESENT, Pte));
      
      MiFlushTlb(Pt, Address);
      WasValid = (PAGE_MASK(Pte) != 0);
      if (!WasValid)
      {
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
      
      /*
@@@ -510,7 -445,7 +445,7 @@@ MmRawDeleteVirtualMapping(PVOID Address
          /*
           * Set the entry to zero
           */
-         (void)InterlockedExchangeUL(Pt, 0);
+         InterlockedExchangePte(Pt, 0);
          MiFlushTlb(Pt, Address);
      }
  }
@@@ -549,7 -484,7 +484,7 @@@ MmDeleteVirtualMapping(PEPROCESS Proces
      /*
       * Atomically set the entry to zero and get the old value.
       */
-     Pte = InterlockedExchangeUL(Pt, 0);
+     Pte = InterlockedExchangePte(Pt, 0);
      
      MiFlushTlb(Pt, Address);
      
@@@ -604,7 -539,7 +539,7 @@@ MmDeletePageFileMapping(PEPROCESS Proce
      /*
       * Atomically set the entry to zero and get the old value.
       */
-     Pte = InterlockedExchangeUL(Pt, 0);
+     Pte = InterlockedExchangePte(Pt, 0);
      
      MiFlushTlb(Pt, Address);
      
@@@ -637,42 -572,6 +572,6 @@@ MmIsDirtyPage(PEPROCESS Process, PVOID 
      return MmGetPageEntryForProcess(Process, Address) & PA_DIRTY ? TRUE : FALSE;
  }
  
- BOOLEAN
- NTAPI
- MmIsAccessedAndResetAccessPage(PEPROCESS Process, PVOID Address)
- {
-     PULONG Pt;
-     ULONG Pte;
-     
-     if (Address < MmSystemRangeStart && Process == NULL)
-     {
-         DPRINT1("MmIsAccessedAndResetAccessPage is called for user space without a process.\n");
-         KEBUGCHECK(0);
-     }
-     
-     Pt = MmGetPageTableForProcess(Process, Address, FALSE);
-     if (Pt == NULL)
-     {
-         KEBUGCHECK(0);
-     }
-     
-     do
-     {
-         Pte = *Pt;
-     } while (Pte != InterlockedCompareExchangeUL(Pt, Pte & ~PA_ACCESSED, Pte));
-     
-     if (Pte & PA_ACCESSED)
-     {
-         MiFlushTlb(Pt, Address);
-         return TRUE;
-     }
-     else
-     {
-         MmUnmapPageTable(Pt);
-         return FALSE;
-     }
- }
  VOID
  NTAPI
  MmSetCleanPage(PEPROCESS Process, PVOID Address)
      if (Address < MmSystemRangeStart && Process == NULL)
      {
          DPRINT1("MmSetCleanPage is called for user space without a process.\n");
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
      
      Pt = MmGetPageTableForProcess(Process, Address, FALSE);
      
      if (Pt == NULL)
      {
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
      
      do
      {
          Pte = *Pt;
-     } while (Pte != InterlockedCompareExchangeUL(Pt, Pte & ~PA_DIRTY, Pte));
+     } while (Pte != InterlockedCompareExchangePte(Pt, Pte & ~PA_DIRTY, Pte));
      
      if (Pte & PA_DIRTY)
      {
@@@ -718,19 -617,19 +617,19 @@@ MmSetDirtyPage(PEPROCESS Process, PVOI
      if (Address < MmSystemRangeStart && Process == NULL)
      {
          DPRINT1("MmSetDirtyPage is called for user space without a process.\n");
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
      
      Pt = MmGetPageTableForProcess(Process, Address, FALSE);
      if (Pt == NULL)
      {
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
      
      do
      {
          Pte = *Pt;
-     } while (Pte != InterlockedCompareExchangeUL(Pt, Pte | PA_DIRTY, Pte));
+     } while (Pte != InterlockedCompareExchangePte(Pt, Pte | PA_DIRTY, Pte));
      if (!(Pte & PA_DIRTY))
      {
          MiFlushTlb(Pt, Address);
@@@ -751,13 -650,13 +650,13 @@@ MmEnableVirtualMapping(PEPROCESS Proces
      Pt = MmGetPageTableForProcess(Process, Address, FALSE);
      if (Pt == NULL)
      {
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
      
      do
      {
          Pte = *Pt;
-     } while (Pte != InterlockedCompareExchangeUL(Pt, Pte | PA_PRESENT, Pte));
+     } while (Pte != InterlockedCompareExchangePte(Pt, Pte | PA_PRESENT, Pte));
      if (!(Pte & PA_PRESENT))
      {
          MiFlushTlb(Pt, Address);
@@@ -805,7 -704,7 +704,7 @@@ MmCreateVirtualMappingForKernel(PVOID A
      if (Address < MmSystemRangeStart)
      {
          DPRINT1("MmCreateVirtualMappingForKernel is called for user space\n");
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
      
      Attributes = ProtectToPTE(flProtect);
      Pt = MmGetPageTableForProcess(NULL, Addr, TRUE);
      if (Pt == NULL)
      {
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
      Pt--;
      
              DPRINT1("Setting physical address but not allowing access at address "
                      "0x%.8X with attributes %x/%x.\n",
                      Addr, Attributes, flProtect);
-             KEBUGCHECK(0);
+             ASSERT(FALSE);
          }
          
          PdeOffset = ADDR_TO_PDE_OFFSET(Addr);
              Pt = MmGetPageTableForProcess(NULL, Addr, TRUE);
              if (Pt == NULL)
              {
-                 KEBUGCHECK(0);
+                 ASSERT(FALSE);
              }
          }
          else
          Pte = *Pt;
          if (Pte != 0)
          {
-             KEBUGCHECK(0);
+             ASSERT(FALSE);
          }
-         (void)InterlockedExchangeUL(Pt, PFN_TO_PTE(Pages[i]) | Attributes);
+         InterlockedExchangePte(Pt, PFN_TO_PTE(Pages[i]) | Attributes);
      }
      
      return(STATUS_SUCCESS);
@@@ -877,29 -776,29 +776,29 @@@ MmCreatePageFileMapping(PEPROCESS Proce
      if (Process == NULL && Address < MmSystemRangeStart)
      {
          DPRINT1("No process\n");
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
      if (Process != NULL && Address >= MmSystemRangeStart)
      {
          DPRINT1("Setting kernel address with process context\n");
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
      if (SwapEntry & (1 << 31))
      {
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
      
      Pt = MmGetPageTableForProcess(Process, Address, TRUE);
      if (Pt == NULL)
      {
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
      Pte = *Pt;
      if (PAGE_MASK((Pte)) != 0)
      {
          MmMarkPageUnmapped(PTE_TO_PFN((Pte)));
      }
-     (void)InterlockedExchangeUL(Pt, SwapEntry << 1);
+     InterlockedExchangePte(Pt, SwapEntry << 1);
      if (Pte != 0)
      {
          MiFlushTlb(Pt, Address);
@@@ -937,13 -836,13 +836,13 @@@ MmCreateVirtualMappingUnsafe(PEPROCESS 
          if (Address < MmSystemRangeStart)
          {
              DPRINT1("No process\n");
-             KEBUGCHECK(0);
+             ASSERT(FALSE);
          }
          if (PageCount > 0x10000 ||
              (ULONG_PTR) Address / PAGE_SIZE + PageCount > 0x100000)
          {
              DPRINT1("Page count to large\n");
-             KEBUGCHECK(0);
+             ASSERT(FALSE);
          }
      }
      else
          if (Address >= MmSystemRangeStart)
          {
              DPRINT1("Setting kernel address with process context\n");
-             KEBUGCHECK(0);
+             ASSERT(FALSE);
          }
          if (PageCount > (ULONG_PTR)MmSystemRangeStart / PAGE_SIZE ||
              (ULONG_PTR) Address / PAGE_SIZE + PageCount >
              (ULONG_PTR)MmSystemRangeStart / PAGE_SIZE)
          {
              DPRINT1("Page Count to large\n");
-             KEBUGCHECK(0);
+             ASSERT(FALSE);
          }
      }
      
              DPRINT1("Setting physical address but not allowing access at address "
                      "0x%.8X with attributes %x/%x.\n",
                      Addr, Attributes, flProtect);
-             KEBUGCHECK(0);
+             ASSERT(FALSE);
          }
          PdeOffset = ADDR_TO_PDE_OFFSET(Addr);
          if (oldPdeOffset != PdeOffset)
              Pt = MmGetPageTableForProcess(Process, Addr, TRUE);
              if (Pt == NULL)
              {
-                 KEBUGCHECK(0);
+                 ASSERT(FALSE);
              }
          }
          else
          MmMarkPageMapped(Pages[i]);
          if (PAGE_MASK((Pte)) != 0 && !((Pte) & PA_PRESENT))
          {
-             KEBUGCHECK(0);
+             ASSERT(FALSE);
          }
          if (PAGE_MASK((Pte)) != 0)
          {
              MmMarkPageUnmapped(PTE_TO_PFN((Pte)));
          }
-         (void)InterlockedExchangeUL(Pt, PFN_TO_PTE(Pages[i]) | Attributes);
+         InterlockedExchangePte(Pt, PFN_TO_PTE(Pages[i]) | Attributes);
          if (Pte != 0)
          {
              if (Address > MmSystemRangeStart ||
@@@ -1051,7 -950,7 +950,7 @@@ MmCreateVirtualMapping(PEPROCESS Proces
          if (!MmIsPageInUse(Pages[i]))
          {
              DPRINT1("Page at address %x not in use\n", PFN_TO_PTE(Pages[i]));
-             KEBUGCHECK(0);
+             ASSERT(FALSE);
          }
      }
      
@@@ -1136,9 -1035,9 +1035,9 @@@ MmSetPageProtect(PEPROCESS Process, PVO
      Pt = MmGetPageTableForProcess(Process, Address, FALSE);
      if (Pt == NULL)
      {
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
-     InterlockedExchange((PLONG)Pt, PAGE_MASK(*Pt) | Attributes | (*Pt & (PA_ACCESSED|PA_DIRTY)));
+     InterlockedExchangePte(Pt, PAGE_MASK(*Pt) | Attributes | (*Pt & (PA_ACCESSED|PA_DIRTY)));
      MiFlushTlb(Pt, Address);
  }
  
@@@ -1200,7 -1099,7 +1099,7 @@@ MmCreateHyperspaceMapping(PFN_TYPE Page
              }
              if (i >= Page % 1024)
              {
-                 KEBUGCHECK(0);
+                 ASSERT(FALSE);
              }
          }
      }
              }
              if (i <= Page % 1024)
              {
-                 KEBUGCHECK(0);
+                 ASSERT(FALSE);
              }
          }
      }
      return Address;
  }
  
- PFN_TYPE
- NTAPI
- MmChangeHyperspaceMapping(PVOID Address, PFN_TYPE NewPage)
- {
-     PFN_TYPE Pfn;
-     ULONG Entry;
-     
-     ASSERT (IS_HYPERSPACE(Address));
-     
-     Entry = InterlockedExchange((PLONG)MiAddressToPte(Address), PFN_TO_PTE(NewPage) | PA_PRESENT | PA_READWRITE);
-     Pfn = PTE_TO_PFN(Entry);
-     
-     __invlpg(Address);
-     return Pfn;
- }
  PFN_TYPE
  NTAPI
  MmDeleteHyperspaceMapping(PVOID Address)
      
      ASSERT (IS_HYPERSPACE(Address));
      
-     Entry = InterlockedExchange((PLONG)MiAddressToPte(Address), 0);
+     Entry = InterlockedExchangePte(MiAddressToPte(Address), 0);
      Pfn = PTE_TO_PFN(Entry);
      
      __invlpg(Address);
@@@ -1275,7 -1158,7 +1158,7 @@@ MmUpdatePageDir(PEPROCESS Process, PVOI
      
      if (Address < MmSystemRangeStart)
      {
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
      
      StartOffset = ADDR_TO_PDE_OFFSET(Address);
      {
          if (Offset != ADDR_TO_PDE_OFFSET(PAGETABLE_MAP))
          {
-             (void)InterlockedCompareExchangeUL(&Pde[Offset], MmGlobalKernelPageDirectory[Offset], 0);
+             InterlockedCompareExchangePte(&Pde[Offset], MmGlobalKernelPageDirectory[Offset], 0);
          }
      }
      if (Pde != (PULONG)PAGEDIRECTORY_MAP)
@@@ -1354,7 -1237,7 +1237,7 @@@ MiInitPageDirectoryMap(VOID
                                  BoundaryAddressMultiple);
      if (!NT_SUCCESS(Status))
      {
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
      BaseAddress = (PVOID)HYPERSPACE;
      Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
                                  BoundaryAddressMultiple);
      if (!NT_SUCCESS(Status))
      {
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
  }
  
@@@ -11,7 -11,7 +11,7 @@@
  
  #include <ntoskrnl.h>
  #define NDEBUG
- #include <internal/debug.h>
+ #include <debug.h>
  
  /* FUNCTIONS *****************************************************************/
  
@@@ -104,7 -104,7 +104,7 @@@ MmMapIoSpace (IN PHYSICAL_ADDRESS Physi
        if (!NT_SUCCESS(Status))
        {
           DbgPrint("Unable to create virtual mapping\n");
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
     }
     return (PVOID)((ULONG_PTR)Result + Offset);
   */
  VOID STDCALL
  MmUnmapIoSpace (IN PVOID BaseAddress,
 -                IN ULONG NumberOfBytes)
 +                IN SIZE_T NumberOfBytes)
  {
     LONG Offset;
     PVOID Address = BaseAddress;
   */
  PVOID STDCALL
  MmMapVideoDisplay (IN PHYSICAL_ADDRESS PhysicalAddress,
 -                   IN ULONG   NumberOfBytes,
 +                   IN SIZE_T   NumberOfBytes,
                     IN MEMORY_CACHING_TYPE CacheType)
  {
     return MmMapIoSpace (PhysicalAddress, NumberOfBytes, (BOOLEAN)CacheType);
   */
  VOID STDCALL
  MmUnmapVideoDisplay (IN PVOID BaseAddress,
 -                     IN ULONG NumberOfBytes)
 +                     IN SIZE_T NumberOfBytes)
  {
     MmUnmapIoSpace (BaseAddress, NumberOfBytes);
  }
@@@ -11,7 -11,7 +11,7 @@@
  
  #include <ntoskrnl.h>
  #define NDEBUG
- #include <internal/debug.h>
+ #include <debug.h>
  
  #if defined (ALLOC_PRAGMA)
  #pragma alloc_text(INIT, MmInitializeMdlImplementation)
@@@ -57,7 -57,7 +57,7 @@@ MmInitializeMdlImplementation(VOID
      if (!NT_SUCCESS(Status))
      {
          MmUnlockAddressSpace(MmGetKernelAddressSpace());
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
      MmUnlockAddressSpace(MmGetKernelAddressSpace());
      
@@@ -81,7 -81,7 +81,7 @@@ PMD
  NTAPI
  MmCreateMdl(IN PMDL Mdl,
              IN PVOID Base,
 -            IN ULONG Length)
 +            IN SIZE_T Length)
  {
      ULONG Size;
      
  ULONG
  NTAPI
  MmSizeOfMdl(IN PVOID Base,
 -            IN ULONG Length)
 +            IN SIZE_T Length)
  {
      /* Return the MDL size */
      return sizeof(MDL) + (ADDRESS_AND_SIZE_TO_SPAN_PAGES(Base, Length) * sizeof(PFN_NUMBER));
@@@ -692,7 -692,7 +692,7 @@@ MmMapLockedPagesSpecifyCache(IN PMDL Md
              {
                  return NULL;
              }
-             KEBUGCHECK(0);
+             ASSERT(FALSE);
          }
          Base = (PVOID)((ULONG_PTR)MiMdlMappingRegionBase + StartingOffset * PAGE_SIZE);
          if (MiMdlMappingRegionHint == StartingOffset) MiMdlMappingRegionHint += PageCount;
diff --combined reactos/ntoskrnl/mm/mm.c
  
  #include <ntoskrnl.h>
  #define NDEBUG
- #include <internal/debug.h>
+ #include <debug.h>
  
  /* GLOBALS *****************************************************************/
  
 -ULONG MmUserProbeAddress = 0;
 +ULONG_PTR MmUserProbeAddress = 0;
  PVOID MmHighestUserAddress = NULL;
  PBOOLEAN Mm64BitPhysicalAddress = FALSE;
  PVOID MmSystemRangeStart = NULL;
@@@ -26,15 -26,31 +26,31 @@@ MM_STATS MmStats
  
  VOID
  FASTCALL
- MiSyncThreadProcessViews(IN PKTHREAD NextThread)
+ MiSyncForProcessAttach(IN PKTHREAD Thread,
+                        IN PEPROCESS Process)
  {
-     /* Hack Sync because Mm is broken  */
-     MmUpdatePageDir(PsGetCurrentProcess(),
-                     ((PETHREAD)NextThread)->ThreadsProcess,
-                     sizeof(EPROCESS));
-     MmUpdatePageDir(PsGetCurrentProcess(),
-                     (PVOID)((PETHREAD)NextThread)->Tcb.StackLimit,
-                     NextThread->LargeStack ?
+     PETHREAD Ethread = CONTAINING_RECORD(Thread, ETHREAD, Tcb);
+     /* Hack Sync because Mm is broken */
+     MmUpdatePageDir(Process, Ethread->ThreadsProcess, sizeof(EPROCESS));
+     MmUpdatePageDir(Process,
+                     (PVOID)Thread->StackLimit,
+                     Thread->LargeStack ?
+                     KERNEL_LARGE_STACK_SIZE : KERNEL_STACK_SIZE);
+ }
+ VOID
+ FASTCALL
+ MiSyncForContextSwitch(IN PKTHREAD Thread)
+ {
+     PVOID Process = PsGetCurrentProcess();
+     PETHREAD Ethread = CONTAINING_RECORD(Thread, ETHREAD, Tcb);
+     /* Hack Sync because Mm is broken */
+     MmUpdatePageDir(Process, Ethread->ThreadsProcess, sizeof(EPROCESS));
+     MmUpdatePageDir(Process,
+                     (PVOID)Thread->StackLimit,
+                     Thread->LargeStack ?
                      KERNEL_LARGE_STACK_SIZE : KERNEL_STACK_SIZE);
  }
  
@@@ -101,7 -117,7 +117,7 @@@ MmpAccessFault(KPROCESSOR_MODE Mode
  
     if (KeGetCurrentIrql() >= DISPATCH_LEVEL)
     {
-       CPRINT("Page fault at high IRQL was %d\n", KeGetCurrentIrql());
+       DPRINT1("Page fault at high IRQL was %d\n", KeGetCurrentIrql());
        return(STATUS_UNSUCCESSFUL);
     }
     if (PsGetCurrentProcess() == NULL)
@@@ -203,7 -219,7 +219,7 @@@ MmNotPresentFault(KPROCESSOR_MODE Mode
  
     if (KeGetCurrentIrql() >= DISPATCH_LEVEL)
     {
-       CPRINT("Page fault at high IRQL was %d, address %x\n", KeGetCurrentIrql(), Address);
+       DPRINT1("Page fault at high IRQL was %d, address %x\n", KeGetCurrentIrql(), Address);
        return(STATUS_UNSUCCESSFUL);
     }
  
         */
        if (Mode != KernelMode)
        {
-        CPRINT("Address: %x\n", Address);
+        DPRINT1("Address: %x\n", Address);
           return(STATUS_ACCESS_VIOLATION);
        }
        AddressSpace = MmGetKernelAddressSpace();
@@@ -364,6 -380,31 +380,31 @@@ MmCommitPagedPoolAddress(PVOID Address
  
  /* Miscellanea functions: they may fit somewhere else */
  
+ /*
+  * @implemented
+  */
+ BOOLEAN
+ NTAPI
+ MmIsRecursiveIoFault (VOID)
+ {
+     PETHREAD Thread = PsGetCurrentThread();
+     return (Thread->DisablePageFaultClustering | Thread->ForwardClusterOnly);
+ }
+ /*
+  * @unimplemented
+  */
+ NTSTATUS
+ NTAPI
+ MmMapUserAddressesToPage(IN PVOID BaseAddress,
+                          IN SIZE_T NumberOfBytes,
+                          IN PVOID PageAddress)
+ {
+     UNIMPLEMENTED;
+     return STATUS_NOT_IMPLEMENTED;
+ }
  /*
   * @unimplemented
   */
@@@ -409,7 -450,7 +450,7 @@@ NTSTATU
  NTAPI
  NtResetWriteWatch(IN HANDLE ProcessHandle,
                   IN PVOID BaseAddress,
 -                 IN ULONG RegionSize)
 +                 IN SIZE_T RegionSize)
  {
      UNIMPLEMENTED;
      return STATUS_NOT_IMPLEMENTED;
@@@ -10,7 -10,7 +10,7 @@@
  
  #include <ntoskrnl.h>
  #define NDEBUG
- #include <internal/debug.h>
+ #include <debug.h>
  
  /* GLOBALS *******************************************************************/
  
@@@ -368,13 -368,13 +368,13 @@@ NTAP
  MmInit1(VOID)
  {
      PLDR_DATA_TABLE_ENTRY LdrEntry;
 -    ULONG Dummy[2];
 +    ULONG_PTR Dummy[2];
      
      /* Dump memory descriptors */
      if (MiDbgEnableMdDump) MiDbgDumpMemoryDescriptors();
  
      /* Set the page directory */
 -    PsGetCurrentProcess()->Pcb.DirectoryTableBase[0] = (ULONG)MmGetPageDirectory();
 +    PsGetCurrentProcess()->Pcb.DirectoryTableBase[0] = (ULONG_PTR)MmGetPageDirectory();
  
      /* Get the size of FreeLDR's image allocations */
      MmBootImageSize = KeLoaderBlock->Extension->LoaderPagesSpanned;
@@@ -11,7 -11,7 +11,7 @@@
  
  #include <ntoskrnl.h>
  #define NDEBUG
- #include <internal/debug.h>
+ #include <debug.h>
  
  /* FUNCTIONS *****************************************************************/
  
@@@ -115,7 -115,7 +115,7 @@@ MmFreeNonCachedPage(PVOID Context, MEMO
   * @implemented
   */
  VOID STDCALL MmFreeNonCachedMemory (IN PVOID BaseAddress,
 -                                    IN ULONG NumberOfBytes)
 +                                    IN SIZE_T NumberOfBytes)
  {
     MmLockAddressSpace(MmGetKernelAddressSpace());
     MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
@@@ -12,7 -12,7 +12,7 @@@
  #include <ntoskrnl.h>
  
  #define NDEBUG
- #include <internal/debug.h>
+ #include <debug.h>
  
  extern ULONG MiNonPagedPoolLength;
  extern ULONG MmTotalPagedPoolQuota;
@@@ -21,6 -21,12 +21,12 @@@ extern MM_STATS MmStats
  
  /* FUNCTIONS ***************************************************************/
  
+ ULONG NTAPI
+ EiGetPagedPoolTag(IN PVOID Block);
+ ULONG NTAPI
+ EiGetNonPagedPoolTag(IN PVOID Block);
  static PVOID STDCALL
  EiAllocatePool(POOL_TYPE PoolType,
                 ULONG NumberOfBytes,
                 PVOID Caller)
  {
     PVOID Block;
+    PCHAR TagChars = (PCHAR)&Tag;
+    if (NumberOfBytes == 0)
+        KeBugCheckEx(BAD_POOL_CALLER, 0x00, 0, PoolType, Tag);
+    if (Tag == 0)
+        KeBugCheckEx(BAD_POOL_CALLER, 0x9b, PoolType, NumberOfBytes, (ULONG_PTR)Caller);
+    if (Tag == TAG('B','I','G',0))
+        KeBugCheckEx(BAD_POOL_CALLER, 0x9c, PoolType, NumberOfBytes, (ULONG_PTR)Caller);
+ #define IS_LETTER_OR_DIGIT(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z') || ((c) >= '0' && (c) <= '9'))
+    if (!IS_LETTER_OR_DIGIT(TagChars[0]) &&
+        !IS_LETTER_OR_DIGIT(TagChars[1]) &&
+        !IS_LETTER_OR_DIGIT(TagChars[2]) &&
+        !IS_LETTER_OR_DIGIT(TagChars[3]))
+        KeBugCheckEx(BAD_POOL_CALLER, 0x9d, Tag, PoolType, (ULONG_PTR)Caller);
+     /* FIXME: Handle SESSION_POOL_MASK, VERIFIER_POOL_MASK, QUOTA_POOL_MASK */
+     if (PoolType & PAGED_POOL_MASK)
+     {
+         if (KeGetCurrentIrql() > APC_LEVEL)
+             KeBugCheckEx(BAD_POOL_CALLER, 0x08, KeGetCurrentIrql(), PoolType, Tag);
+         Block = ExAllocatePagedPoolWithTag(PoolType, NumberOfBytes, Tag);
+     }
+     else
+     {
+         if (KeGetCurrentIrql() > DISPATCH_LEVEL)
+             KeBugCheckEx(BAD_POOL_CALLER, 0x08, KeGetCurrentIrql(), PoolType, Tag);
+         Block = ExAllocateNonPagedPoolWithTag(PoolType, NumberOfBytes, Tag, Caller);
+     }
  
-    /* FIXME: Handle SESSION_POOL_MASK, VERIFIER_POOL_MASK, QUOTA_POOL_MASK */
-    if (PoolType & PAGED_POOL_MASK)
-    {
-       Block = ExAllocatePagedPoolWithTag(PoolType,NumberOfBytes,Tag);
-    }
-    else
-    {
-       Block = ExAllocateNonPagedPoolWithTag(PoolType,NumberOfBytes,Tag,Caller);
-    }
-    if ((PoolType & MUST_SUCCEED_POOL_MASK) && Block==NULL)
-    {
-       KEBUGCHECK(MUST_SUCCEED_POOL_EMPTY);
-    }
-    return(Block);
+     if ((PoolType & MUST_SUCCEED_POOL_MASK) && !Block)
+         KeBugCheckEx(BAD_POOL_CALLER, 0x9a, PoolType, NumberOfBytes, Tag);
+     return Block;
  }
  
  /*
   * @implemented
   */
  PVOID STDCALL
 -ExAllocatePool (POOL_TYPE PoolType, ULONG NumberOfBytes)
 +ExAllocatePool (POOL_TYPE PoolType, SIZE_T NumberOfBytes)
  /*
   * FUNCTION: Allocates pool memory of a specified type and returns a pointer
   * to the allocated block. This routine is used for general purpose allocation
   * @implemented
   */
  PVOID STDCALL
 -ExAllocatePoolWithTag (POOL_TYPE PoolType, ULONG NumberOfBytes, ULONG Tag)
 +ExAllocatePoolWithTag (POOL_TYPE PoolType, SIZE_T NumberOfBytes, ULONG Tag)
  {
     PVOID Block;
  
   * @implemented
   */
  PVOID STDCALL
 -ExAllocatePoolWithQuota (POOL_TYPE PoolType, ULONG NumberOfBytes)
 +ExAllocatePoolWithQuota (POOL_TYPE PoolType, SIZE_T NumberOfBytes)
  {
     return(ExAllocatePoolWithQuotaTag(PoolType, NumberOfBytes, TAG_NONE));
  }
@@@ -180,7 -203,7 +203,7 @@@ _SEH_FILTER(FreeAndGoOn
  PVOID
  NTAPI
  ExAllocatePoolWithQuotaTag (IN POOL_TYPE PoolType,
 -                            IN ULONG NumberOfBytes,
 +                            IN SIZE_T NumberOfBytes,
                              IN ULONG Tag)
  {
      PEPROCESS Process;
   * @implemented
   */
  #undef ExFreePool
- VOID STDCALL
+ VOID NTAPI
  ExFreePool(IN PVOID Block)
  {
-    ASSERT_IRQL(DISPATCH_LEVEL);
-    if (Block >= MmPagedPoolBase && (char*)Block < ((char*)MmPagedPoolBase + MmPagedPoolSize))
-    {
-       ExFreePagedPool(Block);
-    }
-    else
-    {
-       ExFreeNonPagedPool(Block);
-    }
+     if (Block >= MmPagedPoolBase && (char*)Block < ((char*)MmPagedPoolBase + MmPagedPoolSize))
+     {
+         if (KeGetCurrentIrql() > APC_LEVEL)
+             KeBugCheckEx(BAD_POOL_CALLER, 0x09, KeGetCurrentIrql(), PagedPool, (ULONG_PTR)Block);
+         ExFreePagedPool(Block);
+     }
+     else
+     {
+         if (KeGetCurrentIrql() > DISPATCH_LEVEL)
+             KeBugCheckEx(BAD_POOL_CALLER, 0x09, KeGetCurrentIrql(), NonPagedPool, (ULONG_PTR)Block);
+         ExFreeNonPagedPool(Block);
+     }
  }
  
  /*
   * @implemented
   */
- VOID STDCALL
+ VOID NTAPI
  ExFreePoolWithTag(IN PVOID Block, IN ULONG Tag)
  {
-    /* FIXME: Validate the tag */
-    ExFreePool(Block);
+     ULONG BlockTag;
+     if (Block >= MmPagedPoolBase && (char*)Block < ((char*)MmPagedPoolBase + MmPagedPoolSize))
+         BlockTag = EiGetPagedPoolTag(Block);
+     else
+         BlockTag = EiGetNonPagedPoolTag(Block);
+     if (BlockTag != Tag)
+         KeBugCheckEx(BAD_POOL_CALLER, 0x0a, (ULONG_PTR)Block, BlockTag, Tag);
+     ExFreePool(Block);
  }
  
  /*
@@@ -11,7 -11,7 +11,7 @@@
  
  #include <ntoskrnl.h>
  #define NDEBUG
- #include <internal/debug.h>
+ #include <debug.h>
  
  extern ULONG NtMajorVersion;
  extern ULONG NtMinorVersion;
@@@ -215,7 -215,7 +215,7 @@@ MmCreateKernelStack(BOOLEAN GuiStack
      if (!NT_SUCCESS(Status))
      {
          DPRINT1("Failed to create thread stack\n");
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
  
      /*
      if (!NT_SUCCESS(Status))
      {
          DPRINT1("Could not create Virtual Mapping for Kernel Stack\n");
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
      }
  
      /* Return the stack base */
@@@ -384,7 -384,7 +384,7 @@@ MmCreatePeb(PEPROCESS Process
              ImageConfigData = RtlImageDirectoryEntryToData(Peb->ImageBaseAddress,
                                                             TRUE,
                                                             IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG,
 -                                                           &ViewSize);
 +                                                           (PULONG)&ViewSize);
  
              ProbeForRead(ImageConfigData,
                           sizeof(IMAGE_LOAD_CONFIG_DIRECTORY),
@@@ -709,11 -709,11 +709,11 @@@ MmDeleteProcessAddressSpace(PEPROCESS P
               break;
  
           case MEMORY_AREA_MDL_MAPPING:
-             KEBUGCHECK(PROCESS_HAS_LOCKED_PAGES);
+             KeBugCheck(PROCESS_HAS_LOCKED_PAGES);
              break;
  
           default:
-             KEBUGCHECK(0);
+             ASSERT(FALSE);
        }
     }
  
@@@ -11,7 -11,7 +11,7 @@@
  
  #include <ntoskrnl.h>
  #define NDEBUG
- #include <internal/debug.h>
+ #include <debug.h>
  
  /* FUNCTIONS *****************************************************************/
  
@@@ -238,7 -238,7 +238,7 @@@ MmAlterRegion(PMM_AVL_TABLE AddressSpac
  
  VOID
  NTAPI
 -MmInitializeRegion(PLIST_ENTRY RegionListHead, ULONG Length, ULONG Type,
 +MmInitializeRegion(PLIST_ENTRY RegionListHead, SIZE_T Length, ULONG Type,
                     ULONG Protect)
  {
     PMM_REGION Region;
@@@ -46,7 -46,7 +46,7 @@@
  
  #include <ntoskrnl.h>
  #define NDEBUG
- #include <internal/debug.h>
+ #include <debug.h>
  #include <reactos/exeformat.h>
  
  #if defined (ALLOC_PRAGMA)
@@@ -136,7 -136,7 +136,7 @@@ MmGetFileNameForSection(IN PROS_SECTION
      if (!NT_SUCCESS(Status))
      {
          /* Failed, free memory */
-         ExFreePool(ObjectNameInfo);
+         ExFreePoolWithTag(ObjectNameInfo, TAG('M', 'm', ' ', ' '));
          return Status;
      }
  
@@@ -250,7 -250,7 +250,7 @@@ MmFreeSectionSegments(PFILE_OBJECT File
           {
              DPRINT1("Image segment %d still referenced (was %d)\n", i,
                      SectionSegments[i].ReferenceCount);
-             KEBUGCHECK(0);
+             ASSERT(FALSE);
           }
           MmFreePageTablesSectionSegment(&SectionSegments[i]);
        }
        if (Segment->ReferenceCount != 0)
        {
           DPRINT1("Data segment still referenced\n");
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
        MmFreePageTablesSectionSegment(Segment);
        ExFreePool(Segment);
@@@ -316,7 -316,7 +316,7 @@@ MmSetPageEntrySectionSegment(PMM_SECTIO
                                       TAG_SECTION_PAGE_TABLE);
           if (Table == NULL)
           {
-             KEBUGCHECK(0);
+             ASSERT(FALSE);
           }
           memset(Table, 0, sizeof(SECTION_PAGE_TABLE));
           DPRINT("Table %x\n", Table);
@@@ -369,16 -369,16 +369,16 @@@ MmSharePageEntrySectionSegment(PMM_SECT
     if (Entry == 0)
     {
        DPRINT1("Entry == 0 for MmSharePageEntrySectionSegment\n");
-       KEBUGCHECK(0);
+       ASSERT(FALSE);
     }
     if (SHARE_COUNT_FROM_SSE(Entry) == MAX_SHARE_COUNT)
     {
        DPRINT1("Maximum share count reached\n");
-       KEBUGCHECK(0);
+       ASSERT(FALSE);
     }
     if (IS_SWAP_FROM_SSE(Entry))
     {
-       KEBUGCHECK(0);
+       ASSERT(FALSE);
     }
     Entry = MAKE_SSE(PAGE_FROM_SSE(Entry), SHARE_COUNT_FROM_SSE(Entry) + 1);
     MmSetPageEntrySectionSegment(Segment, Offset, Entry);
@@@ -399,16 -399,16 +399,16 @@@ MmUnsharePageEntrySectionSegment(PROS_S
     if (Entry == 0)
     {
        DPRINT1("Entry == 0 for MmUnsharePageEntrySectionSegment\n");
-       KEBUGCHECK(0);
+       ASSERT(FALSE);
     }
     if (SHARE_COUNT_FROM_SSE(Entry) == 0)
     {
        DPRINT1("Zero share count for unshare\n");
-       KEBUGCHECK(0);
+       ASSERT(FALSE);
     }
     if (IS_SWAP_FROM_SSE(Entry))
     {
-       KEBUGCHECK(0);
+       ASSERT(FALSE);
     }
     Entry = MAKE_SSE(PAGE_FROM_SSE(Entry), SHARE_COUNT_FROM_SSE(Entry) - 1);
     /*
              if (!NT_SUCCESS(Status))
              {
                 DPRINT1("CcRosUnmapCacheSegment failed, status = %x\n", Status);
-                KEBUGCHECK(0);
+                ASSERT(FALSE);
              }
           }
        }
                    if (!NT_SUCCESS(Status))
                    {
                       DPRINT1("MM: Failed to write to swap page (Status was 0x%.8X)\n", Status);
-                      KEBUGCHECK(0);
+                      ASSERT(FALSE);
                    }
                 }
                 MmSetPageEntrySectionSegment(Segment, Offset, MAKE_SWAP_SSE(SavedSwapEntry));
           else
           {
              DPRINT1("Found a swapentry for a non private page in an image or data file sgment\n");
-             KEBUGCHECK(0);
+             ASSERT(FALSE);
           }
        }
     }
@@@ -775,7 -775,7 +775,7 @@@ MmNotPresentFaultSectionView(PMM_AVL_TA
     if (PageOp == NULL)
     {
        DPRINT1("MmGetPageOp failed\n");
-       KEBUGCHECK(0);
+       ASSERT(FALSE);
     }
  
     /*
        if (Status != STATUS_SUCCESS)
        {
           DPRINT1("Failed to wait for page op, status = %x\n", Status);
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
        if (PageOp->Status == STATUS_PENDING)
        {
           DPRINT1("Woke for page op before completion\n");
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
        MmLockAddressSpace(AddressSpace);
        /*
           if (!NT_SUCCESS(Status))
           {
              DPRINT1("Unable to create virtual mapping\n");
-             KEBUGCHECK(0);
+             ASSERT(FALSE);
           }
           MmInsertRmap(Page, Process, (PVOID)PAddress);
        }
        if (Segment->Flags & MM_PAGEFILE_SEGMENT)
        {
           DPRINT1("Found a swaped out private page in a pagefile section.\n");
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
  
        MmUnlockSectionSegment(Segment);
        Status = MmRequestPageMemoryConsumer(MC_USER, TRUE, &Page);
        if (!NT_SUCCESS(Status))
        {
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
  
        Status = MmReadFromSwapPage(SwapEntry, Page);
        if (!NT_SUCCESS(Status))
        {
           DPRINT1("MmReadFromSwapPage failed, status = %x\n", Status);
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
        MmLockAddressSpace(AddressSpace);
        Status = MmCreateVirtualMapping(Process,
        if (!NT_SUCCESS(Status))
        {
           DPRINT("MmCreateVirtualMapping failed, not out of memory\n");
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
           return(Status);
        }
  
        if (!NT_SUCCESS(Status))
        {
           DPRINT("MmCreateVirtualMappingUnsafe failed, not out of memory\n");
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
           return(Status);
        }
        /*
        }
        if (!NT_SUCCESS(Status))
        {
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
        Status = MmCreateVirtualMapping(Process,
                                        Address,
        if (!NT_SUCCESS(Status))
        {
           DPRINT("MmCreateVirtualMapping failed, not out of memory\n");
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
           return(Status);
        }
        MmInsertRmap(Page, Process, (PVOID)PAddress);
        if (Entry != Entry1)
        {
           DPRINT1("Someone changed ppte entry while we slept\n");
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
  
        /*
        if (!NT_SUCCESS(Status))
        {
           DPRINT1("Unable to create virtual mapping\n");
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
        MmInsertRmap(Page, Process, (PVOID)PAddress);
  
        Status = MmRequestPageMemoryConsumer(MC_USER, TRUE, &Page);
        if (!NT_SUCCESS(Status))
        {
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
  
        Status = MmReadFromSwapPage(SwapEntry, Page);
        if (!NT_SUCCESS(Status))
        {
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
  
        /*
        if (Entry != Entry1)
        {
           DPRINT1("Someone changed ppte entry while we slept\n");
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
  
        /*
        if (!NT_SUCCESS(Status))
        {
           DPRINT1("Unable to create virtual mapping\n");
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
        MmInsertRmap(Page, Process, (PVOID)PAddress);
        if (Locked)
        if (!NT_SUCCESS(Status))
        {
           DPRINT1("Unable to create virtual mapping\n");
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
        MmInsertRmap(Page, Process, (PVOID)PAddress);
        if (Locked)
@@@ -1305,7 -1305,7 +1305,7 @@@ MmAccessFaultSectionView(PMM_AVL_TABLE 
     if (PageOp == NULL)
     {
        DPRINT1("MmGetPageOp failed\n");
-       KEBUGCHECK(0);
+       ASSERT(FALSE);
     }
  
     /*
        if (Status == STATUS_TIMEOUT)
        {
           DPRINT1("Failed to wait for page op, status = %x\n", Status);
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
        if (PageOp->Status == STATUS_PENDING)
        {
           DPRINT1("Woke for page op before completion\n");
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
        /*
        * Restart the operation
     Status = MmRequestPageMemoryConsumer(MC_USER, TRUE, &NewPage);
     if (!NT_SUCCESS(Status))
     {
-       KEBUGCHECK(0);
+       ASSERT(FALSE);
     }
  
     /*
     if (!NT_SUCCESS(Status))
     {
        DPRINT("MmCreateVirtualMapping failed, not out of memory\n");
-       KEBUGCHECK(0);
+       ASSERT(FALSE);
        return(Status);
     }
     if (!NT_SUCCESS(Status))
     {
        DPRINT1("Unable to create virtual mapping\n");
-       KEBUGCHECK(0);
+       ASSERT(FALSE);
     }
     if (Locked)
     {
@@@ -1509,7 -1509,7 +1509,7 @@@ MmPageOutSectionView(PMM_AVL_TABLE Addr
        DPRINT1("Trying to page out from physical memory section address 0x%X "
                "process %d\n", Address,
                Process ? Process->UniqueProcessId : 0);
-       KEBUGCHECK(0);
+       ASSERT(FALSE);
     }
  
     /*
     {
        DPRINT1("Trying to page out not-present page at (%d,0x%.8X).\n",
                Process ? Process->UniqueProcessId : 0, Address);
-       KEBUGCHECK(0);
+       ASSERT(FALSE);
     }
     Page = MmGetPfnForProcess(Process, Address);
     SwapEntry = MmGetSavedSwapEntryPage(Page);
        if(!MiIsPageFromCache(MemoryArea, Context.Offset))
        {
           DPRINT1("Direct mapped non private page is not associated with the cache.\n");
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
     }
     else
        if (!(Context.Segment->Flags & MM_PAGEFILE_SEGMENT) &&
              !(Context.Segment->Characteristics & IMAGE_SCN_MEM_SHARED))
        {
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
     }
  
        {
           DPRINT1("Found a %s private page (address %x) in a pagefile segment.\n",
                   Context.WasDirty ? "dirty" : "clean", Address);
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
        if (!Context.WasDirty && SwapEntry != 0)
        {
        {
           DPRINT1("Found a %s private page (address %x) in a shared section segment.\n",
                   Context.WasDirty ? "dirty" : "clean", Address);
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
        if (!Context.WasDirty || SwapEntry != 0)
        {
        {
           DPRINT1("Found a swapentry for a non private and direct mapped page (address %x)\n",
                   Address);
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
        Status = CcRosUnmapCacheSegment(Bcb, FileOffset, FALSE);
        if (!NT_SUCCESS(Status))
        {
           DPRINT1("CCRosUnmapCacheSegment failed, status = %x\n", Status);
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
        PageOp->Status = STATUS_SUCCESS;
        MmspCompleteAndReleasePageOp(PageOp);
        {
           DPRINT1("Found a swap entry for a non dirty, non private and not direct mapped page (address %x)\n",
                   Address);
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
        MmReleasePageMemoryConsumer(MC_USER, Page);
        PageOp->Status = STATUS_SUCCESS;
        MmUnlockAddressSpace(AddressSpace);
        if (!NT_SUCCESS(Status))
        {
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
        MmReleasePageMemoryConsumer(MC_USER, Page);
        PageOp->Status = STATUS_SUCCESS;
        MmUnlockAddressSpace(AddressSpace);
        if (!NT_SUCCESS(Status))
        {
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
     }
     else
@@@ -1862,7 -1862,7 +1862,7 @@@ MmWritePageSectionView(PMM_AVL_TABLE Ad
        DPRINT1("Trying to write back page from physical memory mapped at %X "
                "process %d\n", Address,
                Process ? Process->UniqueProcessId : 0);
-       KEBUGCHECK(0);
+       ASSERT(FALSE);
     }
  
     /*
     {
        DPRINT1("Trying to page out not-present page at (%d,0x%.8X).\n",
                Process ? Process->UniqueProcessId : 0, Address);
-       KEBUGCHECK(0);
+       ASSERT(FALSE);
     }
     Page = MmGetPfnForProcess(Process, Address);
     SwapEntry = MmGetSavedSwapEntryPage(Page);
@@@ -2036,7 -2036,6 +2036,6 @@@ MmProtectSectionView(PMM_AVL_TABLE Addr
     if ((MemoryArea->Flags & SEC_NO_CHANGE) &&
         Region->Protect != Protect)
     {
-       CHECKPOINT1;
        return STATUS_INVALID_PAGE_PROTECTION;
     }
  
@@@ -2242,7 -2241,7 +2241,7 @@@ MmCreatePhysicalMemorySection(VOID
     if (!NT_SUCCESS(Status))
     {
        DPRINT1("Failed to create PhysicalMemory section\n");
-       KEBUGCHECK(0);
+       ASSERT(FALSE);
     }
     Status = ObInsertObject(PhysSection,
                             NULL,
@@@ -2382,7 -2381,6 +2381,7 @@@ MmCreateDataFileSection(PROS_SECTION_OB
     LARGE_INTEGER Offset;
     CHAR Buffer;
     FILE_STANDARD_INFORMATION FileInfo;
 +   ULONG Length;
  
     /*
      * Create the section
                                     FileStandardInformation,
                                     sizeof(FILE_STANDARD_INFORMATION),
                                     &FileInfo,
 -                                   &Iosb.Information);
 +                                   &Length);
 +   Iosb.Information = Length;
     if (!NT_SUCCESS(Status))
     {
        ObDereferenceObject(Section);
@@@ -2685,7 -2682,7 +2684,7 @@@ ExeFmtpReadFile(IN PVOID File
  
     if(Length == 0)
     {
-       KEBUGCHECK(STATUS_INVALID_PARAMETER_4);
+       ASSERT(FALSE);
     }
  
     FileOffset = *Offset;
     /* Negative/special offset: it cannot be used in this context */
     if(FileOffset.u.HighPart < 0)
     {
-       KEBUGCHECK(STATUS_INVALID_PARAMETER_5);
+       ASSERT(FALSE);
     }
  
     AdjustOffset = PAGE_ROUND_DOWN(FileOffset.u.LowPart);
     }
     else
     {
-       ExFreePool(Buffer);
+       ExFreePoolWithTag(Buffer, TAG('M', 'm', 'X', 'r'));
     }
  
     return Status;
@@@ -3171,7 -3168,7 +3170,7 @@@ ExeFmtpCreateImageSection(HANDLE FileHa
           break;
     }
  
-    ExFreePool(FileHeaderBuffer);
+    ExFreePoolWithTag(FileHeaderBuffer, TAG('M', 'm', 'X', 'r'));
  
     /*
      * No loader handled the format
@@@ -3688,7 -3685,6 +3687,6 @@@ NtMapViewOfSection(IN HANDLE SectionHan
      */
     if (Protect & ~PAGE_FLAGS_VALID_FROM_USER_MODE)
     {
-      CHECKPOINT1;
       return STATUS_INVALID_PARAMETER_10;
     }
  
         tmpProtect != PAGE_EXECUTE_READWRITE &&
         tmpProtect != PAGE_EXECUTE_WRITECOPY)
     {
-      CHECKPOINT1;
       return STATUS_INVALID_PAGE_PROTECTION;
     }
  
@@@ -3867,7 -3862,7 +3864,7 @@@ MmFreeSectionPage(PVOID Context, MEMORY
        if (Status != STATUS_SUCCESS)
        {
           DPRINT1("Failed to wait for page op, status = %x\n", Status);
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
  
        MmLockAddressSpace(AddressSpace);
        if (Segment->Flags & MM_PAGEFILE_SEGMENT)
        {
           DPRINT1("Found a swap entry for a page in a pagefile section.\n");
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
        MmFreeSwapPage(SwapEntry);
     }
           if (Segment->Flags & MM_PAGEFILE_SEGMENT)
           {
              DPRINT1("Found a private page in a pagefile section.\n");
-             KEBUGCHECK(0);
+             ASSERT(FALSE);
           }
           /*
            * Just dereference private pages
@@@ -3968,7 -3963,7 +3965,7 @@@ MmUnmapViewOfSegment(PMM_AVL_TABLE Addr
     {
        CurrentEntry = RemoveHeadList(RegionListHead);
        CurrentRegion = CONTAINING_RECORD(CurrentEntry, MM_REGION, RegionListEntry);
-       ExFreePool(CurrentRegion);
+       ExFreePoolWithTag(CurrentRegion, TAG_MM_REGION);
     }
  
     if (Section->AllocationAttributes & SEC_PHYSICALMEMORY)
@@@ -4042,7 -4037,7 +4039,7 @@@ MmUnmapViewOfSection(PEPROCESS Process
              if (Status != STATUS_SUCCESS)
              {
                 DPRINT1("Failed to wait for page op, status = %x\n", Status);
-                KEBUGCHECK(0);
+                ASSERT(FALSE);
              }
              MmLockAddressSpace(AddressSpace);
              MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace,
        }
        if (i >= NrSegments)
        {
-          KEBUGCHECK(0);
+          ASSERT(FALSE);
        }
  
        for (i = 0; i < NrSegments; i++)
@@@ -4190,8 -4185,8 +4187,8 @@@ NTSTATUS STDCAL
  NtQuerySection(IN HANDLE SectionHandle,
                 IN SECTION_INFORMATION_CLASS SectionInformationClass,
                 OUT PVOID SectionInformation,
 -               IN ULONG SectionInformationLength,
 -               OUT PULONG ResultLength  OPTIONAL)
 +               IN SIZE_T SectionInformationLength,
 +               OUT PSIZE_T ResultLength  OPTIONAL)
  {
     PROS_SECTION_OBJECT Section;
     KPROCESSOR_MODE PreviousMode;
@@@ -4510,7 -4505,6 +4507,6 @@@ MmMapViewOfSection(IN PVOID SectionObje
         Protect != PAGE_EXECUTE_READWRITE &&
         Protect != PAGE_EXECUTE_WRITECOPY)
     {
-       CHECKPOINT1;
        return STATUS_INVALID_PAGE_PROTECTION;
     }
  
        if ((Protect & (PAGE_READWRITE|PAGE_EXECUTE_READWRITE)) &&
            !(Section->SectionPageProtection & (PAGE_READWRITE|PAGE_EXECUTE_READWRITE)))
        {
-          CHECKPOINT1;
           return STATUS_SECTION_PROTECTION;
        }
        /* check for read access */
        if ((Protect & (PAGE_READONLY|PAGE_WRITECOPY|PAGE_EXECUTE_READ|PAGE_EXECUTE_WRITECOPY)) &&
            !(Section->SectionPageProtection & (PAGE_READONLY|PAGE_READWRITE|PAGE_WRITECOPY|PAGE_EXECUTE_READ|PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY)))
        {
-          CHECKPOINT1;
           return STATUS_SECTION_PROTECTION;
        }
        /* check for execute access */
        if ((Protect & (PAGE_EXECUTE|PAGE_EXECUTE_READ|PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY)) &&
            !(Section->SectionPageProtection & (PAGE_EXECUTE|PAGE_EXECUTE_READ|PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY)))
        {
-          CHECKPOINT1;
           return STATUS_SECTION_PROTECTION;
        }
  
        {
           /* Following this pointer would lead to us to the dark side */
           /* What to do? Bugcheck? Return status? Do the mambo? */
-          KEBUGCHECK(MEMORY_MANAGEMENT);
+          KeBugCheck(MEMORY_MANAGEMENT);
        }
  
        if (SectionOffset == NULL)
@@@ -4742,7 -4733,7 +4735,7 @@@ MmForceSectionClosed 
  NTSTATUS STDCALL
  MmMapViewInSystemSpace (IN PVOID SectionObject,
                          OUT PVOID * MappedBase,
 -                        IN OUT PULONG ViewSize)
 +                        IN OUT PSIZE_T ViewSize)
  {
     PROS_SECTION_OBJECT Section;
     PMM_AVL_TABLE AddressSpace;
@@@ -4927,7 -4918,6 +4920,6 @@@ MmCreateSection (OUT PVOID  * Section
         Protection != PAGE_EXECUTE_READWRITE &&
         Protection != PAGE_EXECUTE_WRITECOPY)
     {
-      CHECKPOINT1;
       return STATUS_INVALID_PAGE_PROTECTION;
     }
  
@@@ -647,7 -647,7 +647,7 @@@ MiSnapThunk(IN PVOID DllBase
                      ForwardName->Hint = 0;\r
  \r
                      /* Set the new address */\r
 -                    *(PULONG)&ForwardThunk.u1.AddressOfData = (ULONG)ForwardName;\r
 +                    ForwardThunk.u1.AddressOfData = (ULONG_PTR)ForwardName;\r
  \r
                      /* Snap the forwarder */\r
                      Status = MiSnapThunk(LdrEntry->DllBase,\r
                                           &MissingForwarder);\r
  \r
                      /* Free the forwarder name and set the thunk */\r
-                     ExFreePool(ForwardName);\r
+                     ExFreePoolWithTag(ForwardName, TAG_LDR_WSTR);\r
                      Address->u1 = ForwardThunk.u1;\r
                      break;\r
                  }\r
@@@ -876,7 -876,7 +876,7 @@@ MiResolveImageReferences(IN PVOID Image
          {\r
              /* Failed */\r
              MiDereferenceImports(LoadedImports);\r
-             if (LoadedImports) ExFreePool(LoadedImports);\r
+             if (LoadedImports) ExFreePoolWithTag(LoadedImports, TAG_LDR_WSTR);\r
              return Status;\r
          }\r
  \r
@@@ -997,7 -997,7 +997,7 @@@ CheckDllState
                  /* Cleanup and return */\r
                  RtlFreeUnicodeString(&NameString);\r
                  MiDereferenceImports(LoadedImports);\r
-                 if (LoadedImports) ExFreePool(LoadedImports);\r
+                 if (LoadedImports) ExFreePoolWithTag(LoadedImports, TAG_LDR_WSTR);\r
                  return Status;\r
              }\r
  \r
          {\r
              /* Cleanup and return */\r
              MiDereferenceImports(LoadedImports);\r
-             if (LoadedImports) ExFreePool(LoadedImports);\r
+             if (LoadedImports) ExFreePoolWithTag(LoadedImports, TAG_LDR_WSTR);\r
              return STATUS_DRIVER_ENTRYPOINT_NOT_FOUND;\r
          }\r
  \r
                  {\r
                      /* Cleanup and return */\r
                      MiDereferenceImports(LoadedImports);\r
-                     if (LoadedImports) ExFreePool(LoadedImports);\r
+                     if (LoadedImports) ExFreePoolWithTag(LoadedImports, TAG_LDR_WSTR);\r
                      return Status;\r
                  }\r
  \r
          if (!ImportCount)\r
          {\r
              /* Free the list and set it to no imports */\r
-             ExFreePool(LoadedImports);\r
+             ExFreePoolWithTag(LoadedImports, TAG_LDR_WSTR);\r
              LoadedImports = (PVOID)-2;\r
          }\r
          else if (ImportCount == 1)\r
          {\r
              /* Just one entry, we can free the table and only use our entry */\r
-             ExFreePool(LoadedImports);\r
+             ExFreePoolWithTag(LoadedImports, TAG_LDR_WSTR);\r
              LoadedImports = (PLOAD_IMPORTS)ImportEntry;\r
          }\r
          else if (ImportCount != LoadedImports->Count)\r
                  }\r
  \r
                  /* Free the old copy */\r
-                 ExFreePool(LoadedImports);\r
+                 ExFreePoolWithTag(LoadedImports, TAG_LDR_WSTR);\r
                  LoadedImports = NewImports;\r
              }\r
          }\r
@@@ -1289,7 -1289,7 +1289,7 @@@ MiInitializeLoadedModuleList(IN PLOADER
      LdrEntry = CONTAINING_RECORD(NextEntry,\r
                                   LDR_DATA_TABLE_ENTRY,\r
                                   InLoadOrderLinks);\r
 -    PsNtosImageBase = (ULONG)LdrEntry->DllBase;\r
 +    PsNtosImageBase = (ULONG_PTR)LdrEntry->DllBase;\r
  \r
      /* Loop the loader block */\r
      while (NextEntry != ListHead)\r
@@@ -1834,7 -1834,7 +1834,7 @@@ LoaderScan
          }\r
  \r
          /* Free the entry itself */\r
-         ExFreePool(LdrEntry);\r
+         ExFreePoolWithTag(LdrEntry, TAG_MODULE_OBJECT);\r
          LdrEntry = NULL;\r
          goto Quickie;\r
      }\r
@@@ -1924,7 -1924,7 +1924,7 @@@ Quickie
      if (NamePrefix) ExFreePool(PrefixName.Buffer);\r
  \r
      /* Free the name buffer and return status */\r
-     ExFreePool(Buffer);\r
+     ExFreePoolWithTag(Buffer, TAG_LDR_WSTR);\r
      return Status;\r
  }\r
  \r
index c8908fa,0000000..386fd26
mode 100644,000000..100644
--- /dev/null
@@@ -1,486 -1,0 +1,482 @@@
-               <file>aspace.c</file>
 +<?xml version="1.0"?>
 +<!DOCTYPE module SYSTEM "../tools/rbuild/project.dtd">
 +<module name="ntoskrnl" type="kernel" installbase="system32" installname="ntoskrnl.exe" baseaddress="0xfffff80000800000" entrypoint="KiSystemStartup" allowwarnings="true">
 +      <bootstrap installbase="$(CDOUTPUT)" />
 +      <importlibrary definition="ntoskrnl_$(ARCH).def" />
 +      <define name="_DISABLE_TIDENTS" />
 +      <define name="__NTOSKRNL__" />
 +      <define name="_NTOSKRNL_" />
 +      <define name="_NTSYSTEM_" />
 +      <define name="__NO_CTYPE_INLINES" />
 +      <define name="WIN9X_COMPAT_SPINLOCK" />
 +      <define name="_IN_KERNEL_" />
 +      <if property="_WINKD_" value="1">
 +              <define name="_WINKD_" />
 +      </if>
 +      <if property="_ELF_" value="1">
 +              <define name="_ELF_" />
 +      </if>
 +      <include base="cmlib">.</include>
 +      <include base="ntoskrnl">include</include>
 +      <include base="ntoskrnl" root="intermediate"></include>
 +      <include base="ntoskrnl" root="intermediate">include</include>
 +      <include base="ntoskrnl" root="intermediate">include/internal</include>
 +      <include base="ReactOS">include/reactos/drivers</include>
 +      <library>csq</library>
 +      <library>hal</library>
 +      <library>pseh</library>
 +      <library>cmlib</library>
 +      <library>rtl</library>
 +      <library>rossym</library>
 +      <library>libcntpr</library>
 +      <library>kdcom</library>
 +      <library>bootvid</library>
 +      <library>wdmguid</library>
 +      <dependency>bugcodes</dependency>
 +      <directory name="include">
 +              <pch>ntoskrnl.h</pch>
 +      </directory>
 +      <file>amd64stubs.c</file>
 +      <directory name="ke">
 +              <if property="ARCH" value="i386">
 +                      <directory name="i386">
 +                              <file first="true">boot.S</file>
 +                              <file>abios.c</file>
 +                              <file>cpu.c</file>
 +                              <file>ctxswitch.S</file>
 +                              <file>exp.c</file>
 +                              <file>irqobj.c</file>
 +                              <file>kiinit.c</file>
 +                              <file>ldt.c</file>
 +                              <file>mtrr.c</file>
 +                              <file>patpge.c</file>
 +                              <file>systimer.S</file>
 +                              <file>thrdini.c</file>
 +                              <file>trap.s</file>
 +                              <file>usercall_asm.S</file>
 +                              <file>usercall.c</file>
 +                              <file>v86vdm.c</file>
 +                              <file>v86m_sup.S</file>
 +                      </directory>
 +              </if>
 +              <if property="ARCH" value="arm">
 +                      <directory name="arm">
 +                              <file first="true">boot.s</file>
 +                              <file>cpu.c</file>
 +                              <file>ctxswtch.s</file>
 +                              <file>exp.c</file>
 +                              <file>kiinit.c</file>
 +                              <file>stubs_asm.s</file>
 +                              <file>thrdini.c</file>
 +                              <file>time.c</file>
 +                              <file>trap.s</file>
 +                              <file>trapc.c</file>
 +                              <file>usercall.c</file>
 +                      </directory>
 +              </if>
 +              <if property="ARCH" value="powerpc">
 +                      <directory name="powerpc">
 +                              <file first="true">main_asm.S</file>
 +                              <file>cpu.c</file>
 +                              <file>exp.c</file>
 +                              <file>kiinit.c</file>
 +                              <file>ppc_irq.c</file>
 +                              <file>stubs.c</file>
 +                              <file>systimer.c</file>
 +                              <file>thrdini.c</file>
 +                              <file>ctxswitch.c</file>
 +                              <file>ctxhelp.S</file>
 +                      </directory>
 +              </if>
 +              <if property="ARCH" value="amd64">
 +                      <directory name="amd64">
 +                              <file first="true">boot.S</file>
 +                              <file>cpu.c</file>
 +                              <file>except.c</file>
 +                              <file>irql.c</file>
 +                              <file>kiinit.c</file>
 +                              <file>spinlock.c</file>
 +                              <file>thrdini.c</file>
 +                              <file>trap.S</file>
 +                      </directory>
 +              </if>
 +              <file>apc.c</file>
 +              <file>balmgr.c</file>
 +              <file>bug.c</file>
 +              <file>clock.c</file>
 +              <file>config.c</file>
 +              <file>devqueue.c</file>
 +              <file>dpc.c</file>
 +              <file>eventobj.c</file>
 +              <file>except.c</file>
 +              <file>freeldr.c</file>
 +              <file>gate.c</file>
 +              <file>gmutex.c</file>
 +              <file>ipi.c</file>
 +              <file>krnlinit.c</file>
 +              <file>mutex.c</file>
 +              <file>procobj.c</file>
 +              <file>profobj.c</file>
 +              <file>queue.c</file>
 +              <file>semphobj.c</file>
 +              <file>spinlock.c</file>
 +              <file>thrdschd.c</file>
 +              <file>thrdobj.c</file>
 +              <file>timerobj.c</file>
 +              <file>wait.c</file>
 +      </directory>
 +      <directory name="cc">
 +              <file>cacheman.c</file>
 +              <file>copy.c</file>
 +              <file>fs.c</file>
 +              <file>mdl.c</file>
 +              <file>pin.c</file>
 +              <file>view.c</file>
 +      </directory>
 +      <directory name="config">
 +              <if property="ARCH" value="i386">
 +                      <directory name="i386">
 +                              <file>cmhardwr.c</file>
 +                      </directory>
 +              </if>
 +              <if property="ARCH" value="arm">
 +                      <directory name="arm">
 +                              <file>cmhardwr.c</file>
 +                      </directory>
 +              </if>
 +              <if property="ARCH" value="powerpc">
 +                      <directory name="powerpc">
 +                              <file>cmhardwr.c</file>
 +                      </directory>
 +              </if>
 +              <file>cmalloc.c</file>
 +              <file>cmapi.c</file>
 +              <file>cmboot.c</file>
 +              <file>cmcheck.c</file>
 +              <file>cmcontrl.c</file>
 +              <file>cmconfig.c</file>
 +              <file>cmdata.c</file>
 +              <file>cmdelay.c</file>
 +              <file>cmindex.c</file>
 +              <file>cminit.c</file>
 +              <file>cmhook.c</file>
 +              <file>cmkcbncb.c</file>
 +              <file>cmkeydel.c</file>
 +              <file>cmlazy.c</file>
 +              <file>cmmapvw.c</file>
 +              <file>cmname.c</file>
 +              <file>cmparse.c</file>
 +              <file>cmse.c</file>
 +              <file>cmsecach.c</file>
 +              <file>cmsysini.c</file>
 +              <file>cmvalue.c</file>
 +              <file>cmvalche.c</file>
 +              <file>cmwraprs.c</file>
 +              <file>ntapi.c</file>
 +      </directory>
 +      <directory name="dbgk">
 +              <file>dbgkutil.c</file>
 +              <file>dbgkobj.c</file>
 +      </directory>
 +      <directory name="ex" root="intermediate">
 +              <file>zw.S</file>
 +      </directory>
 +      <directory name="ex">
 +              <if property="ARCH" value="i386">
 +                      <directory name="i386">
 +                              <file>interlck_asm.S</file>
 +                              <file>fastinterlck_asm.S</file>
 +                              <file>ioport.S</file>
 +                      </directory>
 +              </if>
 +              <file>atom.c</file>
 +              <file>callback.c</file>
 +              <file>dbgctrl.c</file>
 +              <file>efi.c</file>
 +              <file>event.c</file>
 +              <file>evtpair.c</file>
 +              <file>exintrin.c</file>
 +              <file>fastinterlck.c</file>
 +              <file>fmutex.c</file>
 +              <file>handle.c</file>
 +              <file>harderr.c</file>
 +              <file>hdlsterm.c</file>
 +              <file>init.c</file>
 +              <file>keyedevt.c</file>
 +              <file>locale.c</file>
 +              <file>lookas.c</file>
 +              <file>mutant.c</file>
 +              <file>pushlock.c</file>
 +              <file>profile.c</file>
 +              <file>resource.c</file>
 +              <file>rundown.c</file>
 +              <file>sem.c</file>
 +              <file>shutdown.c</file>
 +              <file>sysinfo.c</file>
 +              <file>time.c</file>
 +              <file>timer.c</file>
 +              <file>uuid.c</file>
 +              <file>win32k.c</file>
 +              <file>work.c</file>
 +              <file>xipdisp.c</file>
 +              <file>zone.c</file>
 +      </directory>
 +      <directory name="fsrtl">
 +              <file>dbcsname.c</file>
 +              <file>fastio.c</file>
 +              <file>faulttol.c</file>
 +              <file>filelock.c</file>
 +              <file>filter.c</file>
 +              <file>filtrctx.c</file>
 +              <file>fsfilter.c</file>
 +              <file>fsrtlpc.c</file>
 +              <file>largemcb.c</file>
 +              <file>name.c</file>
 +              <file>notify.c</file>
 +              <file>oplock.c</file>
 +              <file>pnp.c</file>
 +              <file>stackovf.c</file>
 +              <file>tunnel.c</file>
 +              <file>unc.c</file>
 +      </directory>
 +      <directory name="fstub">
 +              <file>disksup.c</file>
 +              <file>fstubex.c</file>
 +              <file>halstub.c</file>
 +      </directory>
 +      <directory name="inbv">
 +              <file>inbv.c</file>
 +      </directory>
 +      <directory name="io">
 +              <directory name="iomgr">
 +                      <file>adapter.c</file>
 +                      <file>arcname.c</file>
 +                      <file>bootlog.c</file>
 +                      <file>controller.c</file>
 +                      <file>device.c</file>
 +                      <file>deviface.c</file>
 +                      <file>driver.c</file>
 +                      <file>drvrlist.c</file>
 +                      <file>error.c</file>
 +                      <file>file.c</file>
 +                      <file>iocomp.c</file>
 +                      <file>ioevent.c</file>
 +                      <file>iofunc.c</file>
 +                      <file>iomdl.c</file>
 +                      <file>iomgr.c</file>
 +                      <file>iorsrce.c</file>
 +                      <file>iotimer.c</file>
 +                      <file>iowork.c</file>
 +                      <file>irp.c</file>
 +                      <file>irq.c</file>
 +                      <file>ramdisk.c</file>
 +                      <file>rawfs.c</file>
 +                      <file>remlock.c</file>
 +                      <file>util.c</file>
 +                      <file>symlink.c</file>
 +                      <file>volume.c</file>
 +              </directory>
 +              <directory name="pnpmgr">
 +                      <file>plugplay.c</file>
 +                      <file>pnpdma.c</file>
 +                      <file>pnpmgr.c</file>
 +                      <file>pnpnotify.c</file>
 +                      <file>pnpreport.c</file>
 +                      <file>pnproot.c</file>
 +              </directory>
 +      </directory>
 +      <if property="_WINKD_" value="0">
 +              <directory name="kdbg">
 +                      <if property="ARCH" value="i386">
 +                              <directory name="i386">
 +                                      <if property="KDBG" value="1">
 +                                              <group>
 +                                                      <file>i386-dis.c</file>
 +                                                      <file>kdb_help.S</file>
 +                                                      <file>longjmp.S</file>
 +                                                      <file>setjmp.S</file>
 +                                              </group>
 +                                      </if>
 +                              </directory>
 +                      </if>
 +                      <if property="KDBG" value="1">
 +                              <!-- file>kdb.c</file -->
 +                              <!-- file>kdb_cli.c</file -->
 +                              <!-- file>kdb_expr.c</file -->
 +                              <file>kdb_keyboard.c</file>
 +                              <file>kdb_serial.c</file>
 +                              <if property="ARCH" value="amd64">
 +                                      <directory name="amd64">
 +                                              <file>kdb.c</file>
 +                                      </directory>
 +                              </if>
 +                      </if>
 +                      <if property="DBG_OR_KDBG" value="true">
 +                              <file>kdb_symbols.c</file>
 +                      </if>
 +              </directory>
 +              <directory name="kd">
 +                      <directory name="wrappers">
 +                              <file>bochs.c</file>
 +                              <if property="ARCH" value="i386">
 +                                      <file>gdbstub.c</file>
 +                              </if>
 +                              <if property="ARCH" value="powerpc">
 +                                      <file>gdbstub_powerpc.c</file>
 +                              </if>
 +                              <file>kdbg.c</file>
 +                      </directory>
 +                      <file>kdinit.c</file>
 +                      <file>kdio.c</file>
 +                      <file>kdmain.c</file>
 +              </directory>
 +      </if>
 +      <if property="_WINKD_" value ="1">
 +              <directory name="kd64">
 +                      <file>kdapi.c</file>
 +                      <file>kdbreak.c</file>
 +                      <file>kddata.c</file>
 +                      <file>kdinit.c</file>
 +                      <file>kdlock.c</file>
 +                      <file>kdprint.c</file>
 +                      <file>kdtrap.c</file>
 +              </directory>
 +      </if>
 +      <directory name="lpc">
 +              <file>close.c</file>
 +              <file>complete.c</file>
 +              <file>connect.c</file>
 +              <file>create.c</file>
 +              <file>listen.c</file>
 +              <file>port.c</file>
 +              <file>reply.c</file>
 +              <file>send.c</file>
 +      </directory>
 +      <directory name="mm">
 +              <if property="ARCH" value="i386">
 +                      <directory name="i386">
 +                              <file>page.c</file>
 +                      </directory>
 +              </if>
 +              <if property="ARCH" value="arm">
 +                      <directory name="arm">
 +                              <file>stubs.c</file>
 +                      </directory>
 +              </if>
 +              <if property="ARCH" value="powerpc">
 +                      <directory name="powerpc">
 +                              <file>pfault.c</file>
 +                              <file>page.c</file>
 +                      </directory>
 +              </if>
 +              <if property="ARCH" value="amd64">
 +                      <directory name="amd64">
 +                              <file>page.c</file>
 +                      </directory>
 +              </if>
 +              <file>anonmem.c</file>
-               <file>pager.c</file>
-               <file>pagfault.c</file>
-               <file>paging.c</file>
 +              <file>balance.c</file>
 +              <file>cont.c</file>
 +              <file>drvlck.c</file>
 +              <file>freelist.c</file>
 +              <file>iospace.c</file>
 +              <file>kmap.c</file>
 +              <file>marea.c</file>
 +              <file>mdlsup.c</file>
 +              <file>mm.c</file>
 +              <file>mminit.c</file>
 +              <file>mpw.c</file>
 +              <file>ncache.c</file>
 +              <file>npool.c</file>
 +              <file>pagefile.c</file>
 +              <file>pageop.c</file>
 +              <file>pe.c</file>
 +              <file>physical.c</file>
 +              <file>pool.c</file>
 +              <file>ppool.c</file>
 +              <file>procsup.c</file>
 +              <file>region.c</file>
 +              <file>rmap.c</file>
 +              <file>section.c</file>
 +              <file>sysldr.c</file>
 +              <file>verifier.c</file>
 +              <file>virtual.c</file>
 +              <file>wset.c</file>
 +              <if property="_ELF_" value="1">
 +                      <file>elf32.c</file>
 +                      <file>elf64.c</file>
 +              </if>
 +      </directory>
 +      <directory name="ob">
 +              <file>obdir.c</file>
 +              <file>obinit.c</file>
 +              <file>obhandle.c</file>
 +              <file>obname.c</file>
 +              <file>oblife.c</file>
 +              <file>obref.c</file>
 +              <file>obsdcach.c</file>
 +              <file>obsecure.c</file>
 +              <file>oblink.c</file>
 +              <file>obwait.c</file>
 +      </directory>
 +      <directory name="po">
 +              <file>power.c</file>
 +              <file>events.c</file>
 +      </directory>
 +      <directory name="ps">
 +              <if property="ARCH" value="i386">
 +                      <directory name="i386">
 +                              <file>psctx.c</file>
 +                      </directory>
 +              </if>
 +              <if property="ARCH" value="arm">
 +                      <directory name="arm">
 +                              <file>psctx.c</file>
 +                      </directory>
 +              </if>
 +              <file>debug.c</file>
 +              <file>job.c</file>
 +              <file>kill.c</file>
 +              <file>psnotify.c</file>
 +              <file>process.c</file>
 +              <file>psmgr.c</file>
 +              <file>query.c</file>
 +              <file>quota.c</file>
 +              <file>security.c</file>
 +              <file>state.c</file>
 +              <file>thread.c</file>
 +              <file>win32.c</file>
 +      </directory>
 +      <directory name="rtl">
 +              <if property="ARCH" value="arm">
 +                      <directory name="arm">
 +                              <file>rtlexcpt.c</file>
 +                      </directory>
 +              </if>
 +              <file>libsupp.c</file>
 +              <file>misc.c</file>
 +      </directory>
 +      <directory name="se">
 +              <file>access.c</file>
 +              <file>acl.c</file>
 +              <file>audit.c</file>
 +              <file>lsa.c</file>
 +              <file>priv.c</file>
 +              <file>sd.c</file>
 +              <file>semgr.c</file>
 +              <file>sid.c</file>
 +              <file>token.c</file>
 +      </directory>
 +      <directory name="vdm">
 +              <if property="ARCH" value="i386">
 +                      <file>vdmmain.c</file>
 +                      <file>vdmexec.c</file>
 +              </if>
 +      </directory>
 +      <directory name="wmi">
 +              <file>wmi.c</file>
 +      </directory>
 +      <file>ntoskrnl.rc</file>
 +      <linkerscript>ntoskrnl_$(ARCH).lnk</linkerscript>
 +</module>
 +
@@@ -12,7 -12,7 +12,7 @@@
  
  #include <ntoskrnl.h>
  #define NDEBUG
- #include <internal/debug.h>
+ #include <debug.h>
  
  /* GLOBALS *******************************************************************/
  
@@@ -177,7 -177,7 +177,7 @@@ PspReapRoutine(IN PVOID Context
      do
      {
          /* Write magic value and return the next entry to process */
 -        NextEntry = InterlockedExchangePointer(&PspReaperListHead.Flink,
 +        NextEntry = InterlockedExchangePointer((PVOID*)&PspReaperListHead.Flink,
                                                 (PVOID)1);
          ASSERT((NextEntry != NULL) && (NextEntry != (PVOID)1));
  
          } while ((NextEntry != NULL) && (NextEntry != (PVOID)1));
  
          /* Remove magic value, keep looping if it got changed */
 -    } while (InterlockedCompareExchangePointer(&PspReaperListHead.Flink,
 -                                               0,
 -                                               1) != (PVOID)1);
 +    } while (InterlockedCompareExchangePointer((PVOID*)&PspReaperListHead.Flink,
 +                                               (PVOID)0,
 +                                               (PVOID)1) != (PVOID)1);
  }
  
  VOID
@@@ -310,7 -310,7 +310,7 @@@ PspDeleteProcess(IN PVOID ObjectBody
          if (!(ExDestroyHandle(PspCidTable, Process->UniqueProcessId, NULL)))
          {
              /* Something wrong happened, bugcheck */
-             KEBUGCHECK(CID_HANDLE_DELETION);
+             KeBugCheck(CID_HANDLE_DELETION);
          }
      }
  
@@@ -360,7 -360,7 +360,7 @@@ PspDeleteThread(IN PVOID ObjectBody
          if (!(ExDestroyHandle(PspCidTable, Thread->Cid.UniqueThread, NULL)))
          {
              /* Something wrong happened, bugcheck */
-             KEBUGCHECK(CID_HANDLE_DELETION);
+             KeBugCheck(CID_HANDLE_DELETION);
          }
      }
  
@@@ -403,7 -403,7 +403,7 @@@ PspExitThread(IN NTSTATUS ExitStatus
      PEPROCESS CurrentProcess;
      PETHREAD Thread, OtherThread, PreviousThread = NULL;
      PVOID DeallocationStack;
 -    ULONG Dummy;
 +    ULONG_PTR Dummy;
      BOOLEAN Last = FALSE;
      PTERMINATION_PORT TerminationPort, NextPort;
      PLIST_ENTRY FirstEntry, CurrentEntry;
      if (KeIsAttachedProcess())
      {
          /* Bugcheck */
-         KEBUGCHECKEX(INVALID_PROCESS_ATTACH_ATTEMPT,
+         KeBugCheckEx(INVALID_PROCESS_ATTACH_ATTEMPT,
                       (ULONG_PTR)CurrentProcess,
                       (ULONG_PTR)Thread->Tcb.ApcState.Process,
                       (ULONG_PTR)Thread->Tcb.ApcStateIndex,
      if (Thread->ActiveExWorker)
      {
          /* Bugcheck */
-         KEBUGCHECKEX(ACTIVE_EX_WORKER_THREAD_TERMINATION,
+         KeBugCheckEx(ACTIVE_EX_WORKER_THREAD_TERMINATION,
                       (ULONG_PTR)Thread,
                       0,
                       0,
      if (Thread->Tcb.CombinedApcDisable != 0)
      {
          /* Bugcheck */
-         KEBUGCHECKEX(KERNEL_APC_PENDING_DURING_EXIT,
+         KeBugCheckEx(KERNEL_APC_PENDING_DURING_EXIT,
                       0,
                       Thread->Tcb.CombinedApcDisable,
                       0,
          else
          {
              /* Bugcheck, we can't allow this */
-             KEBUGCHECKEX(CRITICAL_PROCESS_DIED,
+             KeBugCheckEx(CRITICAL_PROCESS_DIED,
                           (ULONG_PTR)CurrentProcess,
                           0,
                           0,
      if (!Thread->Tcb.EnableStackSwap)
      {
          /* Stack swap really shouldn't be disabled during exit! */
-         KEBUGCHECKEX(KERNEL_STACK_LOCKED_AT_EXIT, 0, 0, 0, 0);
+         KeBugCheckEx(KERNEL_STACK_LOCKED_AT_EXIT, 0, 0, 0, 0);
      }
  
      /* Cancel I/O for the thread. */
      if ((FirstEntry) || (Thread->Tcb.CombinedApcDisable != 0))
      {
          /* Bugcheck time */
-         KEBUGCHECKEX(KERNEL_APC_PENDING_DURING_EXIT,
+         KeBugCheckEx(KERNEL_APC_PENDING_DURING_EXIT,
                       (ULONG_PTR)FirstEntry,
                       Thread->Tcb.CombinedApcDisable,
                       KeGetCurrentIrql(),
@@@ -880,7 -880,7 +880,7 @@@ PsExitSpecialApc(IN PKAPC Apc
      if (Apc->SystemArgument2)
      {
          /* Free the APC */
 -        Status = (NTSTATUS)Apc->NormalContext;
 +        Status = (NTSTATUS)(ULONG_PTR)Apc->NormalContext;
          PspExitApcRundown(Apc);
  
          /* Terminate the Thread */
@@@ -985,7 -985,7 +985,7 @@@ PspTerminateThreadByPointer(IN PETHREA
                          PspExitApcRundown,
                          PspExitNormalApc,
                          KernelMode,
 -                        (PVOID)ExitStatus);
 +                        (PVOID)(ULONG_PTR)ExitStatus);
  
          /* Insert it into the APC Queue */
          if (!KeInsertQueueApc(Apc, Apc, NULL, 2))
@@@ -1142,7 -1142,7 +1142,7 @@@ NtTerminateProcess(IN HANDLE ProcessHan
      /* Lock the Process */
      if (!ExAcquireRundownProtection(&Process->RundownProtect))
      {
-         /* Failed to lock, fal */
+         /* Failed to lock, fail */
          ObDereferenceObject (Process);
          return STATUS_PROCESS_IS_TERMINATING;
      }
          /* Also make sure the caller gave us our handle */
          if (KillByHandle)
          {
-             /* Dereference the project */
+             /* Dereference the process */
              ObDereferenceObject(Process);
  
              /* Terminate ourselves */
@@@ -11,7 -11,9 +11,9 @@@
  
  #include <ntoskrnl.h>
  #define NDEBUG
- #include <internal/debug.h>
+ #include <debug.h>
+ #define TAG_ATMT TAG('A', 't', 'o', 'T') /* Atom table */
  
  extern ULONG NtGlobalFlag;
  
@@@ -74,13 -76,18 +76,18 @@@ RtlpAllocateMemory(ULONG Bytes
  }
  
  
+ #define TAG_USTR        TAG('U', 'S', 'T', 'R')
+ #define TAG_ASTR        TAG('A', 'S', 'T', 'R')
+ #define TAG_OSTR        TAG('O', 'S', 'T', 'R')
  VOID
  STDCALL
  RtlpFreeMemory(PVOID Mem,
                 ULONG Tag)
  {
-     ExFreePoolWithTag(Mem,
-                       Tag);
+     if (Tag == TAG_ASTR || Tag == TAG_OSTR || Tag == TAG_USTR)
+         ExFreePool(Mem);
+     else
+         ExFreePoolWithTag(Mem, Tag);
  }
  
  /*
@@@ -121,7 -128,7 +128,7 @@@ STDCAL
  RtlDeleteHeapLock(
      PRTL_CRITICAL_SECTION CriticalSection)
  {
-     KEBUGCHECK(0);
+     ASSERT(FALSE);
      return STATUS_SUCCESS;
  }
  
@@@ -130,7 -137,7 +137,7 @@@ STDCAL
  RtlEnterHeapLock(
      PRTL_CRITICAL_SECTION CriticalSection)
  {
-     KEBUGCHECK(0);
+     ASSERT(FALSE);
      return STATUS_SUCCESS;
  }
  
@@@ -139,7 -146,7 +146,7 @@@ STDCAL
  RtlInitializeHeapLock(
      PRTL_CRITICAL_SECTION CriticalSection)
  {
-    KEBUGCHECK(0);
+    ASSERT(FALSE);
     return STATUS_SUCCESS;
  }
  
@@@ -148,7 -155,7 +155,7 @@@ STDCAL
  RtlLeaveHeapLock(
      PRTL_CRITICAL_SECTION CriticalSection)
  {
-     KEBUGCHECK(0);
+     ASSERT(FALSE);
      return STATUS_SUCCESS;
  }
  
@@@ -159,7 -166,7 +166,7 @@@ CHECK_PAGED_CODE_RTL(char *file, int li
    if(KeGetCurrentIrql() > APC_LEVEL)
    {
      DbgPrint("%s:%i: Pagable code called at IRQL > APC_LEVEL (%d)\n", file, line, KeGetCurrentIrql());
-     KEBUGCHECK(0);
+     ASSERT(FALSE);
    }
  }
  #endif
@@@ -211,7 -218,7 +218,7 @@@ RtlpHandleDpcStackException(IN PEXCEPTI
      return FALSE;
  }
  
 -#ifndef _ARM_
 +#if !defined(_ARM_) && !defined(_AMD64_)
  
  BOOLEAN
  NTAPI
@@@ -477,21 -484,21 +484,21 @@@ RtlpFreeAtomTable(PRTL_ATOM_TABLE AtomT
  PRTL_ATOM_TABLE_ENTRY
  RtlpAllocAtomTableEntry(ULONG Size)
  {
-    PRTL_ATOM_TABLE_ENTRY Entry = ExAllocatePool(NonPagedPool,
-                                                 Size);
-    if (Entry != NULL)
-    {
-       RtlZeroMemory(Entry,
-                     Size);
-    }
+     PRTL_ATOM_TABLE_ENTRY Entry;
  
-    return Entry;
+     Entry = ExAllocatePoolWithTag(NonPagedPool, Size, TAG_ATMT);
+     if (Entry != NULL)
+     {
+         RtlZeroMemory(Entry, Size);
+     }
+     return Entry;
  }
  
  VOID
  RtlpFreeAtomTableEntry(PRTL_ATOM_TABLE_ENTRY Entry)
  {
-    ExFreePool(Entry);
+     ExFreePoolWithTag(Entry, TAG_ATMT);
  }
  
  VOID
@@@ -557,30 -564,6 +564,6 @@@ RtlpGetAtomEntry(PRTL_ATOM_TABLE AtomTa
     return Entry;
  }
  
- /* FIXME - RtlpCreateUnicodeString is obsolete and should be removed ASAP! */
- BOOLEAN FASTCALL
- RtlpCreateUnicodeString(
-    IN OUT PUNICODE_STRING UniDest,
-    IN PCWSTR  Source,
-    IN POOL_TYPE PoolType)
- {
-    ULONG Length;
-    Length = (wcslen (Source) + 1) * sizeof(WCHAR);
-    UniDest->Buffer = ExAllocatePoolWithTag(PoolType, Length, TAG('U', 'S', 'T', 'R'));
-    if (UniDest->Buffer == NULL)
-       return FALSE;
-    RtlCopyMemory (UniDest->Buffer,
-                   Source,
-                   Length);
-    UniDest->MaximumLength = (USHORT)Length;
-    UniDest->Length = (USHORT)Length - sizeof (WCHAR);
-    return TRUE;
- }
  /*
   * Ldr Resource support code
   */
@@@ -84,7 -84,7 +84,7 @@@ SeInitializeProcessAuditName(IN PFILE_O
          (!(NT_SUCCESS(Status)) || (ReturnLength == sizeof(LocalNameInfo))))
      {
          /* First, free any buffer we might've allocated */
-         KEBUGCHECK(0);
+         ASSERT(FALSE);
          if (ObjectNameInfo) ExFreePool(ObjectNameInfo);
  
          /* Now allocate a temporary one */
@@@ -137,7 -137,7 +137,7 @@@ SeLocateProcessImageName(IN PEPROCESS P
          if (NT_SUCCESS(Status))
          {
              /* Set it */
 -            if (InterlockedCompareExchangePointer(&Process->
 +            if (InterlockedCompareExchangePointer((PVOID*)&Process->
                                                    SeAuditProcessCreationInfo,
                                                    AuditName,
                                                    NULL))
@@@ -134,7 -134,7 +134,7 @@@ IntEngWndUpdateClipObj
  
    RtlCopyMemory(&WndObjInt->WndObj.coClient, ClipObj, sizeof (CLIPOBJ));
    RtlCopyMemory(&WndObjInt->WndObj.rclClient, &Window->Wnd->ClientRect, sizeof (RECT));
 -  OldClipObj = InterlockedExchangePointer(&WndObjInt->ClientClipObj, ClipObj);
 +  OldClipObj = InterlockedExchangePointer((PVOID*)&WndObjInt->ClientClipObj, ClipObj);
    if (OldClipObj != NULL)
      IntEngDeleteClipRegion(OldClipObj);
  
@@@ -153,7 -153,7 +153,7 @@@ IntEngWindowChanged
    PLIST_ENTRY CurrentEntry;
    WNDGDI *Current;
  
-   ASSERT_IRQL(PASSIVE_LEVEL);
+   ASSERT_IRQL_LESS_OR_EQUAL(PASSIVE_LEVEL);
  
    CurrentEntry = Window->WndObjListHead.Flink;
    while (CurrentEntry != &Window->WndObjListHead)
@@@ -275,7 -275,7 +275,7 @@@ IntCallLowLevelHook(PHOOK Hook, INT Cod
     /* FIXME should get timeout from
      * HKEY_CURRENT_USER\Control Panel\Desktop\LowLevelHooksTimeout */
     Status = co_MsqSendMessage(((PW32THREAD)Hook->Thread->Tcb.Win32Thread)->MessageQueue,
 -                                    (HWND) Code,
 +                               (HWND)(UINT_PTR)Code,
                                     Hook->HookId,
                                           wParam,
                                           lParam,
@@@ -942,7 -942,7 +942,7 @@@ CLEANUP
  HHOOK
  STDCALL
  NtUserSetWindowsHookAW(
 -   int idHook, 
 +   int idHook,
     HOOKPROC lpfn,
     BOOL Ansi)
  {
@@@ -1002,7 -1002,7 +1002,7 @@@ NtUserSetWindowsHookEx
        }
        Mod = NULL;
        Global = FALSE;
 -      if (! NT_SUCCESS(PsLookupThreadByThreadId((HANDLE) ThreadId, &Thread)))
 +      if (! NT_SUCCESS(PsLookupThreadByThreadId((HANDLE)(DWORD_PTR)ThreadId, &Thread)))
        {
           DPRINT1("Invalid thread id 0x%x\n", ThreadId);
           SetLastWin32Error(ERROR_INVALID_PARAMETER);
        Global = TRUE;
     }
  
-    if  ( Global ||
+    if ( ( Global && (HookId != WH_KEYBOARD_LL || HookId != WH_MOUSE_LL) ) ||
          WH_DEBUG == HookId ||
          WH_JOURNALPLAYBACK == HookId ||
          WH_JOURNALRECORD == HookId)
@@@ -1214,5 -1214,5 +1214,5 @@@ CLEANUP
     UserLeave();
     END_CLEANUP;
  }
 - 
 +
  /* EOF */
@@@ -92,7 -92,7 +92,7 @@@ static NTSTATUS NTAPI ReadRegistryValue
     if( !NT_SUCCESS(Status) )\r
     {\r
        NtClose(KeyHandle);\r
-       ExFreePool(KeyValuePartialInfo);\r
+       ExFreePoolWithTag(KeyValuePartialInfo, TAG_STRING);\r
        return Status;\r
     }\r
  \r
     if(!ReturnBuffer)\r
     {\r
        NtClose(KeyHandle);\r
-       ExFreePool(KeyValuePartialInfo);\r
+       ExFreePoolWithTag(KeyValuePartialInfo, TAG_STRING);\r
        return STATUS_NO_MEMORY;\r
     }\r
  \r
        KeyValuePartialInfo->DataLength);\r
     RtlInitUnicodeString(ReturnedValue, ReturnBuffer);\r
  \r
-    ExFreePool(KeyValuePartialInfo);\r
+    ExFreePoolWithTag(KeyValuePartialInfo, TAG_STRING);\r
     NtClose(KeyHandle);\r
  \r
     return Status;\r
@@@ -154,7 -154,7 +154,7 @@@ static BOOL UserLoadKbdDll(WCHAR *wsKLI
     FullLayoutPath.MaximumLength = sizeof(LayoutPathBuffer);\r
     RtlAppendUnicodeStringToString(&FullLayoutPath, &LayoutFile);\r
     DPRINT("Loading Keyboard DLL %wZ\n", &FullLayoutPath);\r
-    RtlFreeUnicodeString(&LayoutFile);\r
+    ExFreePoolWithTag(LayoutFile.Buffer, TAG_STRING);\r
  \r
     *phModule = EngLoadImage(FullLayoutPath.Buffer);\r
  \r
@@@ -228,7 -228,7 +228,7 @@@ static PKBL UserLoadDllAndCreateKbl(DWO
        hKl |= 0xe001 << 16; /* FIXME */\r
     else hKl |= hKl << 16;\r
  \r
 -   NewKbl->hkl = (HKL) hKl;\r
 +   NewKbl->hkl = (HKL)(ULONG_PTR) hKl;\r
     NewKbl->klid = LocaleId;\r
     NewKbl->Flags = 0;\r
     NewKbl->RefCount = 0;\r
@@@ -321,7 -321,10 +321,10 @@@ PKBL W32kGetDefaultKeyLayout(VOID
           Status = ReadRegistryValue(&FullKeyboardLayoutPath, &LayoutValueName, &LayoutLocaleIdString);\r
  \r
           if( NT_SUCCESS(Status) )\r
+          {\r
              RtlUnicodeStringToInteger(&LayoutLocaleIdString, 16, &LayoutLocaleId);\r
+             ExFreePoolWithTag(LayoutLocaleIdString.Buffer, TAG_STRING);\r
+          }\r
           else\r
              DPRINT1("ReadRegistryValue failed! (%08lx).\n", Status);\r
        }\r
@@@ -450,7 -453,7 +453,7 @@@ UserGetKeyboardLayout
        return W32Thread->KeyboardLayout->hkl;\r
     }\r
  \r
 -   Status = PsLookupThreadByThreadId((HANDLE)dwThreadId, &Thread);\r
 +   Status = PsLookupThreadByThreadId((HANDLE)(DWORD_PTR)dwThreadId, &Thread);\r
     if(!NT_SUCCESS(Status))\r
     {\r
        SetLastWin32Error(ERROR_INVALID_PARAMETER);\r
@@@ -95,7 -95,7 +95,7 @@@ UserMenuInfo
  { \
    if((MENU_ITEM_TYPE((MenuItem)->fType) == MF_STRING) && \
             (MenuItem)->Text.Length) { \
-     RtlFreeUnicodeString(&(MenuItem)->Text); \
+     ExFreePoolWithTag((MenuItem)->Text.Buffer, TAG_STRING); \
    } \
  }
  
@@@ -220,7 -220,6 +220,6 @@@ IntFreeMenuItem(PMENU_OBJECT Menu, PMEN
     }
  
     /* Free memory */
-    if (MenuItem->Text.Buffer) ExFreePool(MenuItem->Text.Buffer);
     ExFreePool(MenuItem);
  
     return TRUE;
@@@ -1886,7 -1885,7 +1885,7 @@@ NtUserGetMenuBarInfo
          RETURN(FALSE);
       }
  
 -   hMenu = (HMENU)WindowObject->Wnd->IDMenu;
 +   hMenu = (HMENU)(DWORD_PTR)WindowObject->Wnd->IDMenu;
  
     if (!(MenuObject = UserGetMenuObject(hMenu)))
       {
@@@ -2189,7 -2188,7 +2188,7 @@@ NtUserHiliteMenuItem
        RETURN(FALSE);
     }
  
 -   if(Window->Wnd->IDMenu == (UINT)hMenu)
 +   if(Window->Wnd->IDMenu == (UINT)(UINT_PTR)hMenu)
     {
        RETURN( IntHiliteMenuItem(Window, Menu, uItemHilite, uHilite));
     }
@@@ -2596,7 -2595,7 +2595,7 @@@ NtUserThunkedMenuItemInfo
        if bInsert == TRUE call NtUserInsertMenuItem() else NtUserSetMenuItemInfo()   */
  
     if (bInsert) return UserInsertMenuItem(hMenu, uItem, fByPosition, lpmii);
 -   
 +
     UNIMPLEMENTED
     return 0;
  }