include/csrss/csrss.h: Include a define for the size of the common
authorDavid Welch <welch@cwcom.net>
Sun, 25 Nov 2001 15:21:11 +0000 (15:21 +0000)
committerDavid Welch <welch@cwcom.net>
Sun, 25 Nov 2001 15:21:11 +0000 (15:21 +0000)
part of the csrss message header.
lib/kernel32/misc/console.c: WriteConsole: Use the same meanings for the
Length argument to CsrClientCallServer as all other callers.
lib/kernel32/misc/console.c: WriteConsoleOutput: Break up long requests
(not very efficently).
lib/ntdll/csr/lpc.c: CsrClientCallServer: Fill out DataSize and
MessageSize correctly.
lib/kernel32/misc/dllmain.c: DllMain: Die if we can't connect to csrss.
ntoskrnl/include/internal/ntoskrnl.c: Increase size of non-paged pool
ntoskrnl/ke/i386/exp.c: On double fault print loops in the stack trace
only once.
ntoskrnl/ke/i386/usertrap.c: Corrected checking in stack trace.
ntoskrnl/lpc/send.c: NtRequestWaitReplyPort: Check message consistency and
copy in safely.
ntoskrnl/mm/aspace.c: MmLockAddressSpace: Don't bother locking if we are
the only thread running.
ntoskrnl/mm/kmap.c: Implementing support functions for whole page
allocation.
ntoskrnl/mm/npool.c: Implementing allocation mode where every block is
allocated in a whole page and placed against the end so writes beyond the
allocated portion are caught immediately.

svn path=/trunk/; revision=2393

22 files changed:
reactos/include/csrss/csrss.h
reactos/install.bochs
reactos/lib/kernel32/misc/console.c
reactos/lib/kernel32/misc/dllmain.c
reactos/lib/ntdll/csr/lpc.c
reactos/lib/ntdll/rtl/error.c
reactos/ntoskrnl/Makefile
reactos/ntoskrnl/include/internal/ntoskrnl.h
reactos/ntoskrnl/include/internal/port.h
reactos/ntoskrnl/ke/i386/exp.c
reactos/ntoskrnl/ke/i386/usertrap.c
reactos/ntoskrnl/ke/kthread.c
reactos/ntoskrnl/ke/main.c
reactos/ntoskrnl/ke/wait.c
reactos/ntoskrnl/lpc/queue.c
reactos/ntoskrnl/lpc/reply.c
reactos/ntoskrnl/lpc/send.c
reactos/ntoskrnl/mm/aspace.c
reactos/ntoskrnl/mm/kmap.c
reactos/ntoskrnl/mm/mminit.c
reactos/ntoskrnl/mm/npool.c
reactos/tools/wmc/makefile

index c6a76a7..0bb8d0c 100644 (file)
@@ -237,16 +237,17 @@ typedef struct
 
 typedef struct
 {
-   HANDLE     ConsoleHandle;
-   SMALL_RECT ScrollRectangle;
-   BOOLEAN    UseClipRectangle;
-        SMALL_RECT ClipRectangle;
-        COORD      DestinationOrigin;
-   CHAR_INFO  Fill;
+  HANDLE     ConsoleHandle;
+  SMALL_RECT ScrollRectangle;
+  BOOLEAN    UseClipRectangle;
+  SMALL_RECT ClipRectangle;
+  COORD      DestinationOrigin;
+  CHAR_INFO  Fill;
 } CSRSS_SCROLL_CONSOLE_SCREEN_BUFFER_REQUEST, *PCSRSS_SCROLL_CONSOLE_SCREEN_BUFFER_REQUEST;
 
 
-#define CSRSS_MAX_WRITE_CONSOLE_REQUEST       (MAX_MESSAGE_DATA - sizeof( ULONG ) - sizeof( CSRSS_WRITE_CONSOLE_REQUEST))
+#define CSRSS_MAX_WRITE_CONSOLE_REQUEST       \
+      (MAX_MESSAGE_DATA - sizeof(ULONG) - sizeof(CSRSS_WRITE_CONSOLE_REQUEST))
 
 #define CSRSS_MAX_SET_TITLE_REQUEST           (MAX_MESSAGE_DATA - sizeof( HANDLE ) - sizeof( DWORD ) - sizeof( ULONG ) - sizeof( LPC_MESSAGE_HEADER ))
 
@@ -286,60 +287,63 @@ typedef struct
 #define CSRSS_FLUSH_INPUT_BUFFER            (0x18)
 #define CSRSS_SCROLL_CONSOLE_SCREEN_BUFFER  (0x19)
 
-
-typedef struct
-{
-   LPC_MESSAGE_HEADER Header;
-   ULONG Type;
-   union
-     {
-       CSRSS_CREATE_PROCESS_REQUEST CreateProcessRequest;
-       CSRSS_CONNECT_PROCESS_REQUEST ConnectRequest;
-       CSRSS_WRITE_CONSOLE_REQUEST WriteConsoleRequest;
-       CSRSS_READ_CONSOLE_REQUEST ReadConsoleRequest;
-       CSRSS_SCREEN_BUFFER_INFO_REQUEST ScreenBufferInfoRequest;
-       CSRSS_SET_CURSOR_REQUEST SetCursorRequest;
-       CSRSS_FILL_OUTPUT_REQUEST FillOutputRequest;
-       CSRSS_READ_INPUT_REQUEST ReadInputRequest;
-       CSRSS_WRITE_CONSOLE_OUTPUT_CHAR_REQUEST WriteConsoleOutputCharRequest;
-       CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB_REQUEST WriteConsoleOutputAttribRequest;
-  CSRSS_FILL_OUTPUT_ATTRIB_REQUEST FillOutputAttribRequest;
-       CSRSS_SET_CURSOR_INFO_REQUEST SetCursorInfoRequest;
-       CSRSS_GET_CURSOR_INFO_REQUEST GetCursorInfoRequest;
-       CSRSS_SET_ATTRIB_REQUEST SetAttribRequest;
-       CSRSS_SET_CONSOLE_MODE_REQUEST SetConsoleModeRequest;
-       CSRSS_GET_CONSOLE_MODE_REQUEST GetConsoleModeRequest;
-       CSRSS_CREATE_SCREEN_BUFFER_REQUEST CreateScreenBufferRequest;
-       CSRSS_SET_ACTIVE_SCREEN_BUFFER_REQUEST SetActiveScreenBufferRequest;
-  CSRSS_SET_TITLE_REQUEST SetTitleRequest;
-  CSRSS_GET_TITLE_REQUEST GetTitleRequest;
-  CSRSS_WRITE_CONSOLE_OUTPUT_REQUEST WriteConsoleOutputRequest;
-  CSRSS_FLUSH_INPUT_BUFFER_REQUEST FlushInputBufferRequest;
-  CSRSS_SCROLL_CONSOLE_SCREEN_BUFFER_REQUEST ScrollConsoleScreenBufferRequest;
-     } Data;
+/* Keep in sync with definition below. */
+#define CSRSS_REQUEST_HEADER_SIZE (sizeof(LPC_MESSAGE_HEADER) + sizeof(ULONG))
+
+typedef struct
+{
+  LPC_MESSAGE_HEADER Header;
+  ULONG Type;
+  union
+  {
+    CSRSS_CREATE_PROCESS_REQUEST CreateProcessRequest;
+    CSRSS_CONNECT_PROCESS_REQUEST ConnectRequest;
+    CSRSS_WRITE_CONSOLE_REQUEST WriteConsoleRequest;
+    CSRSS_READ_CONSOLE_REQUEST ReadConsoleRequest;
+    CSRSS_SCREEN_BUFFER_INFO_REQUEST ScreenBufferInfoRequest;
+    CSRSS_SET_CURSOR_REQUEST SetCursorRequest;
+    CSRSS_FILL_OUTPUT_REQUEST FillOutputRequest;
+    CSRSS_READ_INPUT_REQUEST ReadInputRequest;
+    CSRSS_WRITE_CONSOLE_OUTPUT_CHAR_REQUEST WriteConsoleOutputCharRequest;
+    CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB_REQUEST WriteConsoleOutputAttribRequest;
+    CSRSS_FILL_OUTPUT_ATTRIB_REQUEST FillOutputAttribRequest;
+    CSRSS_SET_CURSOR_INFO_REQUEST SetCursorInfoRequest;
+    CSRSS_GET_CURSOR_INFO_REQUEST GetCursorInfoRequest;
+    CSRSS_SET_ATTRIB_REQUEST SetAttribRequest;
+    CSRSS_SET_CONSOLE_MODE_REQUEST SetConsoleModeRequest;
+    CSRSS_GET_CONSOLE_MODE_REQUEST GetConsoleModeRequest;
+    CSRSS_CREATE_SCREEN_BUFFER_REQUEST CreateScreenBufferRequest;
+    CSRSS_SET_ACTIVE_SCREEN_BUFFER_REQUEST SetActiveScreenBufferRequest;
+    CSRSS_SET_TITLE_REQUEST SetTitleRequest;
+    CSRSS_GET_TITLE_REQUEST GetTitleRequest;
+    CSRSS_WRITE_CONSOLE_OUTPUT_REQUEST WriteConsoleOutputRequest;
+    CSRSS_FLUSH_INPUT_BUFFER_REQUEST FlushInputBufferRequest;
+    CSRSS_SCROLL_CONSOLE_SCREEN_BUFFER_REQUEST 
+    ScrollConsoleScreenBufferRequest;
+  } Data;
 } CSRSS_API_REQUEST, *PCSRSS_API_REQUEST;
 
 typedef struct
 {
-   LPC_MESSAGE_HEADER Header;
-   NTSTATUS Status;
-   union
-     {
-       CSRSS_CREATE_PROCESS_REPLY CreateProcessReply;
-       CSRSS_CONNECT_PROCESS_REPLY ConnectReply;
-       CSRSS_WRITE_CONSOLE_REPLY WriteConsoleReply;
-       CSRSS_READ_CONSOLE_REPLY ReadConsoleReply;
-       CSRSS_ALLOC_CONSOLE_REPLY AllocConsoleReply;
-       CSRSS_SCREEN_BUFFER_INFO_REPLY ScreenBufferInfoReply;
-       CSRSS_READ_INPUT_REPLY ReadInputReply;
-       CSRSS_WRITE_CONSOLE_OUTPUT_CHAR_REPLY WriteConsoleOutputCharReply;
-       CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB_REPLY WriteConsoleOutputAttribReply;
-       CSRSS_GET_CURSOR_INFO_REPLY GetCursorInfoReply;
-       CSRSS_GET_CONSOLE_MODE_REPLY GetConsoleModeReply;
-       CSRSS_CREATE_SCREEN_BUFFER_REPLY CreateScreenBufferReply;
-  CSRSS_GET_TITLE_REPLY GetTitleReply;
-  CSRSS_WRITE_CONSOLE_OUTPUT_REPLY WriteConsoleOutputReply;
-     } Data;
+  LPC_MESSAGE_HEADER Header;
+  NTSTATUS Status;
+  union
+  {
+    CSRSS_CREATE_PROCESS_REPLY CreateProcessReply;
+    CSRSS_CONNECT_PROCESS_REPLY ConnectReply;
+    CSRSS_WRITE_CONSOLE_REPLY WriteConsoleReply;
+    CSRSS_READ_CONSOLE_REPLY ReadConsoleReply;
+    CSRSS_ALLOC_CONSOLE_REPLY AllocConsoleReply;
+    CSRSS_SCREEN_BUFFER_INFO_REPLY ScreenBufferInfoReply;
+    CSRSS_READ_INPUT_REPLY ReadInputReply;
+    CSRSS_WRITE_CONSOLE_OUTPUT_CHAR_REPLY WriteConsoleOutputCharReply;
+    CSRSS_WRITE_CONSOLE_OUTPUT_ATTRIB_REPLY WriteConsoleOutputAttribReply;
+    CSRSS_GET_CURSOR_INFO_REPLY GetCursorInfoReply;
+    CSRSS_GET_CONSOLE_MODE_REPLY GetConsoleModeReply;
+    CSRSS_CREATE_SCREEN_BUFFER_REPLY CreateScreenBufferReply;
+    CSRSS_GET_TITLE_REPLY GetTitleReply;
+    CSRSS_WRITE_CONSOLE_OUTPUT_REPLY WriteConsoleOutputReply;
+  } Data;
 } CSRSS_API_REPLY, *PCSRSS_API_REPLY;
 
 #endif /* __INCLUDE_CSRSS_CSRSS_H */
index 677ea43..ee86aa5 100644 (file)
@@ -1,14 +1,6 @@
 #!/bin/sh
 /sbin/modprobe loop
-echo "Installing to floppy."
-mount -t vfat /bochs/1.44a.dos /mnt/floppy -o loop,rw
-./install-system.sh /mnt/floppy
-umount /mnt/floppy
 echo "Installing to disk."
-mount -t vfat /bochs/10M.vga.dos /mnt/floppy -o loop,offset=8704,rw
+mount -t vfat /mnt/hda3/bochs/10M.vga.dos /mnt/floppy -o loop,offset=8704,rw
 ./install.sh /mnt/floppy
 umount /mnt/floppy
-echo "Installing to minix disk."
-#mount -t minix /bochs/10M.vga.minix /mnt/floppy -o loop,offset=8704,rw
-#./install.sh /mnt/floppy
-#umount /mnt/floppy
index ea74eb4..e4103e5 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: console.c,v 1.36 2001/11/20 02:29:44 dwelch Exp $
+/* $Id: console.c,v 1.37 2001/11/25 15:21:09 dwelch Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
@@ -643,57 +643,64 @@ SetStdHandle(DWORD nStdHandle,
 /*--------------------------------------------------------------
  *     WriteConsoleA
  */
-WINBOOL STDCALL WriteConsoleA(HANDLE hConsoleOutput,
-                             CONST VOID *lpBuffer,
-                             DWORD nNumberOfCharsToWrite,
-                             LPDWORD lpNumberOfCharsWritten,
-                             LPVOID lpReserved)
+WINBOOL STDCALL 
+WriteConsoleA(HANDLE hConsoleOutput,
+             CONST VOID *lpBuffer,
+             DWORD nNumberOfCharsToWrite,
+             LPDWORD lpNumberOfCharsWritten,
+             LPVOID lpReserved)
 {
-   PCSRSS_API_REQUEST Request;
-   CSRSS_API_REPLY Reply;
-   NTSTATUS Status;
-   WORD Size;
-   
-   Request = RtlAllocateHeap(GetProcessHeap(),
-                      HEAP_ZERO_MEMORY,
-                      sizeof(CSRSS_API_REQUEST) + CSRSS_MAX_WRITE_CONSOLE_REQUEST);
-   if (Request == NULL)
-     {
-       return(FALSE);
-     }
-
-   Request->Type = CSRSS_WRITE_CONSOLE;
-   Request->Data.WriteConsoleRequest.ConsoleHandle = hConsoleOutput;
-   if (lpNumberOfCharsWritten != NULL)
-      *lpNumberOfCharsWritten = nNumberOfCharsToWrite;
-   while( nNumberOfCharsToWrite )
-      {
-        Size = nNumberOfCharsToWrite > CSRSS_MAX_WRITE_CONSOLE_REQUEST ? CSRSS_MAX_WRITE_CONSOLE_REQUEST : nNumberOfCharsToWrite;
-
-        Request->Data.WriteConsoleRequest.NrCharactersToWrite = Size;
+  PCSRSS_API_REQUEST Request;
+  CSRSS_API_REPLY Reply;
+  NTSTATUS Status;
+  USHORT Size;
+  ULONG MessageSize;
+  
+  Request = RtlAllocateHeap(GetProcessHeap(),
+                           HEAP_ZERO_MEMORY,
+                           sizeof(CSRSS_API_REQUEST) + 
+                           CSRSS_MAX_WRITE_CONSOLE_REQUEST);
+  if (Request == NULL)
+    {
+      return(FALSE);
+    }
+  
+  Request->Type = CSRSS_WRITE_CONSOLE;
+  Request->Data.WriteConsoleRequest.ConsoleHandle = hConsoleOutput;
+  if (lpNumberOfCharsWritten != NULL)
+    *lpNumberOfCharsWritten = nNumberOfCharsToWrite;
+  while (nNumberOfCharsToWrite)
+    {
+      if (nNumberOfCharsToWrite > CSRSS_MAX_WRITE_CONSOLE_REQUEST)
+       {
+         Size = CSRSS_MAX_WRITE_CONSOLE_REQUEST;
+       }
+      else
+       {
+         Size = nNumberOfCharsToWrite;
+       }
+      Request->Data.WriteConsoleRequest.NrCharactersToWrite = Size;
+      
+      memcpy(Request->Data.WriteConsoleRequest.Buffer, lpBuffer, Size);
 
-        //   DbgPrint("nNumberOfCharsToWrite %d\n", nNumberOfCharsToWrite);
-        //   DbgPrint("Buffer %s\n", Request->Data.WriteConsoleRequest.Buffer);
-        
-        memcpy( Request->Data.WriteConsoleRequest.Buffer, lpBuffer, Size );
-   
-        Status = CsrClientCallServer(Request,
-                                     &Reply,
-                                     sizeof(CSRSS_WRITE_CONSOLE_REQUEST) + 
-                                     Size,
-                                     sizeof(CSRSS_API_REPLY));
-        
-        if (!NT_SUCCESS(Status) || !NT_SUCCESS( Status = Reply.Status ) )
-           {
-              RtlFreeHeap( GetProcessHeap(), 0, Request );
-              SetLastErrorByStatus (Status);
-              return(FALSE);
-           }
-        nNumberOfCharsToWrite -= Size;
-        lpBuffer += Size;
-      }
-   RtlFreeHeap( GetProcessHeap(), 0, Request );
-   return TRUE;
+      MessageSize = CSRSS_REQUEST_HEADER_SIZE + 
+       sizeof(CSRSS_WRITE_CONSOLE_REQUEST) + Size;
+      Status = CsrClientCallServer(Request,
+                                  &Reply,
+                                  MessageSize,
+                                  sizeof(CSRSS_API_REPLY));
+      
+      if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
+       {
+         RtlFreeHeap(GetProcessHeap(), 0, Request);
+         SetLastErrorByStatus(Status);
+         return(FALSE);
+       }
+      nNumberOfCharsToWrite -= Size;
+      lpBuffer += Size;
+    }
+  RtlFreeHeap(GetProcessHeap(), 0, Request);
+  return TRUE;
 }
 
 
@@ -1133,48 +1140,91 @@ ReadConsoleOutputW(
 /*--------------------------------------------------------------
  *     WriteConsoleOutputA
  */
-WINBASEAPI
-BOOL
-WINAPI
-WriteConsoleOutputA(
-       HANDLE           hConsoleOutput,
-       CONST CHAR_INFO *lpBuffer,
-       COORD            dwBufferSize,
-       COORD            dwBufferCoord,
-       PSMALL_RECT      lpWriteRegion
-       )
+WINBASEAPI BOOL WINAPI
+WriteConsoleOutputA(HANDLE              hConsoleOutput,
+                   CONST CHAR_INFO     *lpBuffer,
+                   COORD                dwBufferSize,
+                   COORD                dwBufferCoord,
+                   PSMALL_RECT  lpWriteRegion)
 {
-   PCSRSS_API_REQUEST Request;
-   CSRSS_API_REPLY Reply;
-   NTSTATUS Status;
-   DWORD Size;
+  PCSRSS_API_REQUEST Request;
+  CSRSS_API_REPLY Reply;
+  NTSTATUS Status;
+  ULONG Size;
+  BOOLEAN Result;
+  ULONG i, j;
 
-   Size = dwBufferSize.Y * dwBufferSize.X * sizeof(CHAR_INFO);
+  Size = dwBufferSize.Y * dwBufferSize.X * sizeof(CHAR_INFO);
 
-   Request = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(CSRSS_API_REQUEST) + Size);
-   if( !Request )
-     {
-       SetLastError( ERROR_OUTOFMEMORY );
-       return FALSE;
-     }
-   Request->Type = CSRSS_WRITE_CONSOLE_OUTPUT;
-   Request->Data.WriteConsoleOutputRequest.ConsoleHandle = hConsoleOutput;
-   Request->Data.WriteConsoleOutputRequest.BufferSize = dwBufferSize;
-   Request->Data.WriteConsoleOutputRequest.BufferCoord = dwBufferCoord;
-   Request->Data.WriteConsoleOutputRequest.WriteRegion = *lpWriteRegion;
-   RtlCopyMemory(&Request->Data.WriteConsoleOutputRequest.CharInfo, lpBuffer, Size);
-
-   Status = CsrClientCallServer( Request, &Reply, sizeof( CSRSS_API_REQUEST ) + Size, sizeof( CSRSS_API_REPLY ) );
-        if( !NT_SUCCESS( Status ) || !NT_SUCCESS( Status = Reply.Status ) )
-           {
-         RtlFreeHeap( GetProcessHeap(), 0, Request );
-              SetLastErrorByStatus ( Status );
-              return FALSE;
-           }
+  if ((sizeof(CSRSS_API_REQUEST) + Size) > 
+      (sizeof(LPC_MESSAGE) + MAX_MESSAGE_DATA))
+    {
+      COORD FragDim, FragCoord;
+      SMALL_RECT FragRegion;
+      DWORD SizeX, SizeY;
+      CONST CHAR_INFO* lpFragBuffer;
 
-   *lpWriteRegion = Reply.Data.WriteConsoleOutputReply.WriteRegion;
+      SizeX = min(dwBufferSize.X - dwBufferCoord.X, 
+                 lpWriteRegion->Right - lpWriteRegion->Left);
+      SizeY = min(dwBufferSize.Y - dwBufferCoord.Y, 
+                 lpWriteRegion->Bottom - lpWriteRegion->Top);
 
-   return TRUE;
+      for (i = dwBufferCoord.Y; i < (dwBufferCoord.Y + SizeY); i++)
+       {
+         for (j = dwBufferCoord.X; j < (dwBufferCoord.X + SizeX); j++)
+           {
+             FragDim.X = 1;
+             FragDim.Y = 1;
+             FragCoord.X = 0;
+             FragCoord.Y = 0;
+             FragRegion.Left = lpWriteRegion->Left + j;
+             FragRegion.Right = lpWriteRegion->Left + j + 1;
+             FragRegion.Top = lpWriteRegion->Top + i;
+             FragRegion.Bottom = lpWriteRegion->Bottom + i + 1;
+
+             lpFragBuffer = lpBuffer + (i * dwBufferSize.X) + j;
+             Result = WriteConsoleOutputA(hConsoleOutput,
+                                          lpFragBuffer,
+                                          FragDim,
+                                          FragCoord,
+                                          &FragRegion);
+             if (!Result)
+               {
+                 return(FALSE);
+               }             
+           }
+       }
+      return(TRUE);
+    }
+  
+  Request = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, 
+                           sizeof(CSRSS_API_REQUEST) + Size);
+  if (Request == NULL)
+    {
+      SetLastError(ERROR_OUTOFMEMORY);
+      return FALSE;
+    }
+  Request->Type = CSRSS_WRITE_CONSOLE_OUTPUT;
+  Request->Data.WriteConsoleOutputRequest.ConsoleHandle = hConsoleOutput;
+  Request->Data.WriteConsoleOutputRequest.BufferSize = dwBufferSize;
+  Request->Data.WriteConsoleOutputRequest.BufferCoord = dwBufferCoord;
+  Request->Data.WriteConsoleOutputRequest.WriteRegion = *lpWriteRegion;
+  RtlCopyMemory(&Request->Data.WriteConsoleOutputRequest.CharInfo, lpBuffer, 
+               Size);
+  
+  Status = CsrClientCallServer(Request, &Reply, 
+                              sizeof(CSRSS_API_REQUEST) + Size, 
+                              sizeof(CSRSS_API_REPLY));
+  if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Reply.Status))
+    {
+      RtlFreeHeap(GetProcessHeap(), 0, Request);
+      SetLastErrorByStatus(Status);
+      return FALSE;
+    }
+      
+  *lpWriteRegion = Reply.Data.WriteConsoleOutputReply.WriteRegion;
+  RtlFreeHeap(GetProcessHeap(), 0, Request);
+  return(TRUE);
 }
 
 
index d36331b..fe0dd2d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: dllmain.c,v 1.18 2001/04/04 22:21:30 dwelch Exp $
+/* $Id: dllmain.c,v 1.19 2001/11/25 15:21:09 dwelch Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
@@ -108,8 +108,9 @@ DllMain(HANDLE hInst,
             Status = CsrClientConnectToServer();
             if (!NT_SUCCESS(Status))
               {
-                 DbgPrint("Failed to connect to csrss.exe: expect trouble\n");
-                 //    ZwTerminateProcess(NtCurrentProcess(), Status);
+                 DbgPrint("Failed to connect to csrss.exe: expect trouble "
+                          "Status was %X\n", Status);
+                 ZwTerminateProcess(NtCurrentProcess(), Status);
               }
 
             hProcessHeap = RtlGetProcessHeap();
index 7ef0b8f..dcfe2de 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: lpc.c,v 1.2 2001/08/31 20:06:17 ea Exp $
+/* $Id: lpc.c,v 1.3 2001/11/25 15:21:09 dwelch Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -57,27 +57,21 @@ CsrClientCallServer(PCSRSS_API_REQUEST Request,
                    ULONG Length,
                    ULONG ReplyLength)
 {
-   NTSTATUS Status;
-
-   if (INVALID_HANDLE_VALUE == WindowsApiPort)
-   {
-          DbgPrint ("NTDLL.%s: client not connected to CSRSS!\n", __FUNCTION__);
-          return (STATUS_UNSUCCESSFUL);
-   }
-   
-//   DbgPrint("CsrClientCallServer(Request %x, Reply %x, Length %d, "
-//         "ReplyLength %d)\n", Request, Reply, Length, ReplyLength);
-   
-   Request->Header.DataSize = Length;
-   Request->Header.MessageSize = sizeof(LPC_MESSAGE_HEADER) + Length;
+  NTSTATUS Status;
+  
+  if (INVALID_HANDLE_VALUE == WindowsApiPort)
+    {
+      DbgPrint ("NTDLL.%s: client not connected to CSRSS!\n", __FUNCTION__);
+      return (STATUS_UNSUCCESSFUL);
+    }
   
+   Request->Header.DataSize = Length - sizeof(LPC_MESSAGE_HEADER);
+   Request->Header.MessageSize = Length;
    
    Status = NtRequestWaitReplyPort(WindowsApiPort,
                                   &Request->Header,
                                   (Reply?&Reply->Header:&Request->Header));
    
-//   DbgPrint("Status %x\n", Status);
-   
    return(Status);
 }
 
index 19639ee..c95f901 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: error.c,v 1.8 2001/08/03 17:18:50 ekohl Exp $
+/* $Id: error.c,v 1.9 2001/11/25 15:21:09 dwelch Exp $
  *
  * COPYRIGHT:         See COPYING in the top level directory
  * PROJECT:           ReactOS kernel
@@ -881,7 +881,9 @@ RtlNtStatusToDosErrorNoTeb(NTSTATUS Status)
                        if (!ret)
                                ret = Status;  /* 0 means 1:1 mapping */
                        else if (ret == ERROR_MR_MID_NOT_FOUND)
-                               DbgPrint("RTL: RtlNtStatusToDosErrorNoTeb(0x%lx): no valid W32 error mapping\n", Status);
+                         {
+                           DbgPrint("RTL: RtlNtStatusToDosErrorNoTeb(0x%lx): no valid W32 error mapping\n", Status);
+                         }
                        return ret;
                }
                Table++;
@@ -894,7 +896,6 @@ RtlNtStatusToDosErrorNoTeb(NTSTATUS Status)
                return LOWORD(Status);
 
        DbgPrint("RTL: RtlNtStatusToDosErrorNoTeb(0x%lx): no valid W32 error mapping\n", Status);
-
        return ERROR_MR_MID_NOT_FOUND;
 }
 
index 9a8b31d..8f8a88f 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.57 2001/11/03 16:48:07 chorns Exp $
+# $Id: Makefile,v 1.58 2001/11/25 15:21:10 dwelch Exp $
 #
 # ReactOS Operating System
 #
@@ -623,7 +623,7 @@ clean:
 
 .PHONY: clean 
 
-install: $(INSTALL_DIR)/system32/$(TARGETNAME).exe
+install: all $(INSTALL_DIR)/system32/$(TARGETNAME).exe
 
 $(INSTALL_DIR)/system32/$(TARGETNAME).exe: $(TARGETNAME).exe
        $(CP) $(TARGETNAME).exe $(INSTALL_DIR)/system32/$(TARGETNAME).exe
index 712de53..6f65225 100644 (file)
@@ -22,7 +22,7 @@
 /*
  * Maximum size of the kmalloc area (this is totally arbitary)
  */
-#define NONPAGED_POOL_SIZE   (4*1024*1024)
+#define NONPAGED_POOL_SIZE   (400*1024*1024)
 
 /*
  * Defines a descriptor as it appears in the processor tables
index e717228..b47eb13 100644 (file)
@@ -85,6 +85,9 @@ EiEnqueueMessagePort (
        IN OUT  PEPORT          Port,
        IN      PQUEUEDMESSAGE  Message
        );
+VOID STDCALL
+EiEnqueueMessageAtHeadPort (IN OUT     PEPORT          Port,
+                           IN  PQUEUEDMESSAGE  Message);
 PQUEUEDMESSAGE
 STDCALL
 EiDequeueConnectMessagePort (
index b3fcecb..02d9c77 100644 (file)
@@ -219,16 +219,22 @@ ULONG
 KiDoubleFaultHandler(VOID)
 {
   unsigned int cr2;
-  unsigned int i;
-  PULONG stack;
+  ULONG i, j;
   ULONG StackLimit;
+  ULONG StackBase;
   ULONG Esp0;
   ULONG ExceptionNr = 8;
   KTSS* OldTss;
+  PULONG Frame;
+  static PVOID StackTrace[MM_STACK_SIZE / sizeof(PVOID)];
+  static ULONG StackRepeatCount[MM_STACK_SIZE / sizeof(PVOID)];
+  static ULONG StackRepeatLength[MM_STACK_SIZE / sizeof(PVOID)];
+  ULONG TraceLength;
+  BOOLEAN FoundRepeat;
   
   /* Use the address of the trap frame as approximation to the ring0 esp */
   OldTss = KeGetCurrentKPCR()->TSS;
-  Esp0 = OldTss->Esp0;
+  Esp0 = OldTss->Esp;
   
   /* Get CR2 */
   __asm__("movl %%cr2,%0\n\t" : "=d" (cr2));
@@ -296,38 +302,95 @@ KiDoubleFaultHandler(VOID)
      }
   if ((OldTss->Cs & 0xffff) == KERNEL_CS)
     {
-       DbgPrint("ESP %x\n", Esp0);
-       stack = (PULONG) (Esp0 + 24);
-       stack = (PULONG)(((ULONG)stack) & (~0x3));
-       if (PsGetCurrentThread() != NULL)
-        {
-          StackLimit = (ULONG)PsGetCurrentThread()->Tcb.StackBase;
-        }
-       else
-        {
-          StackLimit = (ULONG)&init_stack_top;
-        }
-       
-       DbgPrint("stack<%p>: ", stack);
-        
-       for (i = 0; i < 18 && (((ULONG)&stack[i+5]) < StackLimit); i = i + 6)
-        {
-           DbgPrint("%.8x %.8x %.8x %.8x\n", 
-                    stack[i], stack[i+1], 
-                    stack[i+2], stack[i+3], 
-                    stack[i+4], stack[i+5]);
-        }
-       DbgPrint("Frames:\n");
-       for (i = 0; i < 32 && (((ULONG)&stack[i]) < StackLimit); i++)
-        {
-           if (stack[i] > ((unsigned int) &_text_start__) &&
-             !(stack[i] >= ((ULONG)&init_stack) &&
-               stack[i] <= ((ULONG)&init_stack_top)))
-             {
-                print_address((PVOID)stack[i]);
-                DbgPrint(" ");
-             }
-        }
+      DbgPrint("ESP %x\n", Esp0);
+      if (PsGetCurrentThread() != NULL)
+       {
+         StackLimit = (ULONG)PsGetCurrentThread()->Tcb.StackBase;
+         StackBase = (ULONG)PsGetCurrentThread()->Tcb.StackLimit;
+       }
+      else
+       {
+         StackLimit = (ULONG)&init_stack_top;
+         StackBase = (ULONG)&init_stack;
+       }
+
+      DbgPrint("Frames: ");
+      i = 0;
+      Frame = (PULONG)OldTss->Ebp;
+      while (Frame != NULL && (ULONG)Frame >= StackBase)
+       {
+         StackTrace[i] = (PVOID)Frame[1];
+         Frame = (PULONG)Frame[0];
+         i++;
+       }
+      TraceLength = i;
+
+      i = 0;
+      while (i < TraceLength)
+       {
+         StackRepeatCount[i] = 0;
+         j = i + 1;
+         FoundRepeat = FALSE;
+         while ((j - i) <= (TraceLength - j) && FoundRepeat == FALSE)
+           {
+             if (memcmp(&StackTrace[i], &StackTrace[j], 
+                        (j - i) * sizeof(PVOID)) == 0)
+               {
+                 StackRepeatCount[i] = 2;
+                 StackRepeatLength[i] = j - i;
+                 FoundRepeat = TRUE;
+               }
+             else
+               {
+                 j++;
+               }
+           }
+         if (FoundRepeat == FALSE)
+           {
+             i++;
+             continue;
+           }
+         j = j + StackRepeatLength[i];
+         while ((TraceLength - j) >= StackRepeatLength[i] && 
+                FoundRepeat == TRUE)
+           {
+             if (memcmp(&StackTrace[i], &StackTrace[j], 
+                        StackRepeatLength[i] * sizeof(PVOID)) == 0)
+               {
+                 StackRepeatCount[i]++;
+                 j = j + StackRepeatLength[i];
+               }
+             else
+               {
+                 FoundRepeat = FALSE;
+               }
+           }
+         i = j;
+       }
+
+      i = 0;
+      while (i < TraceLength)
+       {
+         if (StackRepeatCount[i] == 0)
+           {
+             print_address(StackTrace[i]);
+             i++;
+           }
+         else
+           {
+             DbgPrint("{");
+             if (StackRepeatLength[i] == 0)
+               {
+                 for(;;);
+               }
+             for (j = 0; j < StackRepeatLength[i]; j++)
+               {
+                 print_address(StackTrace[i + j]);
+               }
+             DbgPrint("}*%d", StackRepeatCount[i]);
+             i = i + StackRepeatLength[i] * StackRepeatCount[i];
+           }
+       }
     }
    
    DbgPrint("\n");
index 5f1ec1e..6582a58 100644 (file)
@@ -262,14 +262,14 @@ KiUserTrapHandler(PKTRAP_FRAME Tf, ULONG ExceptionNr, PVOID Cr2)
   Frame = (PULONG)Tf->Ebp;
   while (Frame != NULL && i < 50)
     {
-      Status = MmCopyFromCaller(&ReturnAddress, &Frame[1], sizeof(ULONG));
+      Status = MmSafeCopyFromUser(&ReturnAddress, &Frame[1], sizeof(ULONG));
       if (!NT_SUCCESS(Status))
        {
          DbgPrint("????????\n");
          break;
        }
       print_user_address((PVOID)ReturnAddress);
-      Status = MmCopyFromCaller(&NextFrame, &Frame[0], sizeof(ULONG));
+      Status = MmSafeCopyFromUser(&NextFrame, &Frame[0], sizeof(ULONG));
       if (!NT_SUCCESS(Status))
        {
          DbgPrint("Frame is inaccessible.\n");
@@ -280,9 +280,9 @@ KiUserTrapHandler(PKTRAP_FRAME Tf, ULONG ExceptionNr, PVOID Cr2)
          DbgPrint("Next frame is in kernel space!\n");
          break;
        }
-      if (NextFrame >= (ULONG)Frame)
+      if (NextFrame != 0 && NextFrame <= (ULONG)Frame)
        {
-         DbgPrint("Next frame is not below current frame!\n");
+         DbgPrint("Next frame is not above current frame!\n");
          break;
        }
       Frame = (PULONG)NextFrame;
index bb6e4a3..93c15a1 100644 (file)
@@ -82,145 +82,145 @@ KeInitializeThread(PKPROCESS Process, PKTHREAD Thread, BOOLEAN First)
  * FUNCTION: Initialize the microkernel state of the thread
  */
 {
-   PVOID KernelStack;
-   NTSTATUS Status;
-   extern unsigned int init_stack_top;
-   extern unsigned int init_stack;
-   PMEMORY_AREA StackArea;
-   ULONG i;
-
-   KeInitializeDispatcherHeader(&Thread->DispatcherHeader,
-                                InternalThreadType,
-                                sizeof(ETHREAD),
-                                FALSE);
-   InitializeListHead(&Thread->MutantListHead);
-   if (!First)
-     {
-       KernelStack = NULL;
-       
-          MmLockAddressSpace(MmGetKernelAddressSpace());
-          Status = MmCreateMemoryArea(NULL,
-                                  MmGetKernelAddressSpace(),
-                                  MEMORY_AREA_KERNEL_STACK,
-                                  &KernelStack,
-                                  MM_STACK_SIZE,
-                                  0,
-                                  &StackArea,
-                                  FALSE);
-          MmUnlockAddressSpace(MmGetKernelAddressSpace());
-
-       if (!NT_SUCCESS(Status))
-        {
-          DPRINT1("Failed to create thread stack\n");
-          KeBugCheck(0);
-        }
-       for (i = 0; i < (MM_STACK_SIZE / PAGESIZE); i++)
-        {
-          Status = MmCreateVirtualMapping(NULL,
-                                          KernelStack + (i * PAGESIZE),
-                                          PAGE_EXECUTE_READWRITE,
-                                          (ULONG)MmAllocPage(0));
-        }
-       Thread->InitialStack = KernelStack + MM_STACK_SIZE;
-       Thread->StackBase = KernelStack + MM_STACK_SIZE;
-       Thread->StackLimit = (ULONG)KernelStack;
-       Thread->KernelStack = KernelStack + MM_STACK_SIZE;
-     }
-   else
-     {
-       Thread->InitialStack = (PVOID)&init_stack_top;
-       Thread->StackBase = (PVOID)&init_stack_top;
-       Thread->StackLimit = (ULONG)&init_stack;
-       Thread->KernelStack = (PVOID)&init_stack_top;
-     }
-   
-   /* 
-    * The Native API function will initialize the TEB field later 
-    */
-   Thread->Teb = NULL;
-   Thread->TlsArray = NULL;
-   Thread->DebugActive = 0;
-   Thread->State = THREAD_STATE_BLOCKED;
-   Thread->Alerted[0] = 0;
-   Thread->Alerted[1] = 0;
-   Thread->Iopl = 0;
-   /*
-    * FIXME: Think how this might work
-    */
-   Thread->NpxState = 0;
-
-   Thread->Saturation = 0;
-   Thread->Priority = 0; 
-   InitializeListHead(&Thread->ApcState.ApcListHead[0]);
-   InitializeListHead(&Thread->ApcState.ApcListHead[1]);
-   Thread->ApcState.Process = Process;
-   Thread->ApcState.KernelApcInProgress = 0;
-   Thread->ApcState.KernelApcPending = 0;
-   Thread->ApcState.UserApcPending = 0;
-   Thread->ContextSwitches = 0;
-   Thread->WaitStatus = STATUS_SUCCESS;
-   Thread->WaitIrql = 0;
-   Thread->WaitMode = 0;
-   Thread->WaitNext = 0;
-   Thread->WaitBlockList = NULL;
-   Thread->WaitListEntry.Flink = NULL;
-   Thread->WaitListEntry.Blink = NULL;
-   Thread->WaitTime = 0;
-   Thread->BasePriority = 0; 
-   Thread->DecrementCount = 0;
-   Thread->PriorityDecrement = 0;
-   Thread->Quantum = 0;
-   memset(Thread->WaitBlock, 0, sizeof(KWAIT_BLOCK)*4);
-   Thread->LegoData = 0;
-   /*
-    * FIXME: Why this?
-    */
-   Thread->KernelApcDisable = 1;
-   Thread->UserAffinity = Process->Affinity;
-   Thread->SystemAffinityActive = 0;
-   Thread->Queue = NULL;
-   KeInitializeSpinLock(&Thread->ApcQueueLock);
-   memset(&Thread->Timer, 0, sizeof(KTIMER));
-   Thread->QueueListEntry.Flink = NULL;
-   Thread->QueueListEntry.Blink = NULL;
-   Thread->Affinity = Process->Affinity;
-   Thread->Preempted = 0;
-   Thread->ProcessReadyQueue = 0;
-   Thread->KernelStackResident = 1;
-   Thread->NextProcessor = 0;
-   Thread->CallbackStack = NULL;
-   Thread->Win32Thread = 0;
-   Thread->TrapFrame = NULL;
-   Thread->ApcStatePointer[0] = NULL;
-   Thread->ApcStatePointer[1] = NULL;
-   Thread->EnableStackSwap = 0;
-   Thread->LargeStack = 0;
-   Thread->ResourceIndex = 0;
-   Thread->PreviousMode = KernelMode;
-   Thread->KernelTime = 0;
-   Thread->UserTime = 0;
-   memset(&Thread->SavedApcState, 0, sizeof(KAPC_STATE));
-   Thread->Alertable = 1;
-   Thread->ApcStateIndex = 0;
-   Thread->ApcQueueable = 0;
-   Thread->AutoAlignment = 0;
-   KeInitializeApc(&Thread->SuspendApc,
-                  Thread,
-                  0,
-                  PiSuspendThreadKernelRoutine,
-                  PiSuspendThreadRundownRoutine,
-                  PiSuspendThreadNormalRoutine,
-                  KernelMode,
-                  NULL);
-   KeInitializeSemaphore(&Thread->SuspendSemaphore, 0, 255);
-   Thread->ThreadListEntry.Flink = NULL;
-   Thread->ThreadListEntry.Blink = NULL;
-   Thread->FreezeCount = 0;
-   Thread->SuspendCount = 0;
-
-   /*
-    * Initialize ReactOS specific members
-    */
+  PVOID KernelStack;
+  NTSTATUS Status;
+  extern unsigned int init_stack_top;
+  extern unsigned int init_stack;
+  PMEMORY_AREA StackArea;
+  ULONG i;
+  
+  KeInitializeDispatcherHeader(&Thread->DispatcherHeader,
+                              InternalThreadType,
+                              sizeof(ETHREAD),
+                              FALSE);
+  InitializeListHead(&Thread->MutantListHead);
+  if (!First)
+    {
+      KernelStack = NULL;
+      
+      MmLockAddressSpace(MmGetKernelAddressSpace());
+      Status = MmCreateMemoryArea(NULL,
+                                 MmGetKernelAddressSpace(),
+                                 MEMORY_AREA_KERNEL_STACK,
+                                 &KernelStack,
+                                 MM_STACK_SIZE,
+                                 0,
+                                 &StackArea,
+                                 FALSE);
+      MmUnlockAddressSpace(MmGetKernelAddressSpace());
+      
+      if (!NT_SUCCESS(Status))
+       {
+         DPRINT1("Failed to create thread stack\n");
+         KeBugCheck(0);
+       }
+      for (i = 0; i < (MM_STACK_SIZE / PAGESIZE); i++)
+       {
+         Status = MmCreateVirtualMapping(NULL,
+                                         KernelStack + (i * PAGESIZE),
+                                         PAGE_EXECUTE_READWRITE,
+                                         (ULONG)MmAllocPage(0));
+       }
+      Thread->InitialStack = KernelStack + MM_STACK_SIZE;
+      Thread->StackBase = KernelStack + MM_STACK_SIZE;
+      Thread->StackLimit = (ULONG)KernelStack;
+      Thread->KernelStack = KernelStack + MM_STACK_SIZE;
+    }
+  else
+    {
+      Thread->InitialStack = (PVOID)&init_stack_top;
+      Thread->StackBase = (PVOID)&init_stack_top;
+      Thread->StackLimit = (ULONG)&init_stack;
+      Thread->KernelStack = (PVOID)&init_stack_top;
+    }
+  
+  /* 
+   * The Native API function will initialize the TEB field later 
+   */
+  Thread->Teb = NULL;
+  Thread->TlsArray = NULL;
+  Thread->DebugActive = 0;
+  Thread->State = THREAD_STATE_BLOCKED;
+  Thread->Alerted[0] = 0;
+  Thread->Alerted[1] = 0;
+  Thread->Iopl = 0;
+  /*
+   * FIXME: Think how this might work
+   */
+  Thread->NpxState = 0;
+  
+  Thread->Saturation = 0;
+  Thread->Priority = 0; 
+  InitializeListHead(&Thread->ApcState.ApcListHead[0]);
+  InitializeListHead(&Thread->ApcState.ApcListHead[1]);
+  Thread->ApcState.Process = Process;
+  Thread->ApcState.KernelApcInProgress = 0;
+  Thread->ApcState.KernelApcPending = 0;
+  Thread->ApcState.UserApcPending = 0;
+  Thread->ContextSwitches = 0;
+  Thread->WaitStatus = STATUS_SUCCESS;
+  Thread->WaitIrql = 0;
+  Thread->WaitMode = 0;
+  Thread->WaitNext = 0;
+  Thread->WaitBlockList = NULL;
+  Thread->WaitListEntry.Flink = NULL;
+  Thread->WaitListEntry.Blink = NULL;
+  Thread->WaitTime = 0;
+  Thread->BasePriority = 0; 
+  Thread->DecrementCount = 0;
+  Thread->PriorityDecrement = 0;
+  Thread->Quantum = 0;
+  memset(Thread->WaitBlock, 0, sizeof(KWAIT_BLOCK)*4);
+  Thread->LegoData = 0;
+  /*
+   * FIXME: Why this?
+   */
+  Thread->KernelApcDisable = 1;
+  Thread->UserAffinity = Process->Affinity;
+  Thread->SystemAffinityActive = 0;
+  Thread->Queue = NULL;
+  KeInitializeSpinLock(&Thread->ApcQueueLock);
+  memset(&Thread->Timer, 0, sizeof(KTIMER));
+  Thread->QueueListEntry.Flink = NULL;
+  Thread->QueueListEntry.Blink = NULL;
+  Thread->Affinity = Process->Affinity;
+  Thread->Preempted = 0;
+  Thread->ProcessReadyQueue = 0;
+  Thread->KernelStackResident = 1;
+  Thread->NextProcessor = 0;
+  Thread->CallbackStack = NULL;
+  Thread->Win32Thread = 0;
+  Thread->TrapFrame = NULL;
+  Thread->ApcStatePointer[0] = NULL;
+  Thread->ApcStatePointer[1] = NULL;
+  Thread->EnableStackSwap = 0;
+  Thread->LargeStack = 0;
+  Thread->ResourceIndex = 0;
+  Thread->PreviousMode = KernelMode;
+  Thread->KernelTime = 0;
+  Thread->UserTime = 0;
+  memset(&Thread->SavedApcState, 0, sizeof(KAPC_STATE));
+  Thread->Alertable = 1;
+  Thread->ApcStateIndex = 0;
+  Thread->ApcQueueable = 0;
+  Thread->AutoAlignment = 0;
+  KeInitializeApc(&Thread->SuspendApc,
+                 Thread,
+                 0,
+                 PiSuspendThreadKernelRoutine,
+                 PiSuspendThreadRundownRoutine,
+                 PiSuspendThreadNormalRoutine,
+                 KernelMode,
+                 NULL);
+  KeInitializeSemaphore(&Thread->SuspendSemaphore, 0, 255);
+  Thread->ThreadListEntry.Flink = NULL;
+  Thread->ThreadListEntry.Blink = NULL;
+  Thread->FreezeCount = 0;
+  Thread->SuspendCount = 0;
+  
+  /*
+   * Initialize ReactOS specific members
+   */
    Thread->ProcessThreadListEntry.Flink = NULL;
    Thread->ProcessThreadListEntry.Blink = NULL;
    KeInitializeDpc(&Thread->TimerDpc,
@@ -231,6 +231,5 @@ KeInitializeThread(PKPROCESS Process, PKTHREAD Thread, BOOLEAN First)
    /*
     * Do x86 specific part
     */
-   
 }
 
index d431d12..03836aa 100644 (file)
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: main.c,v 1.108 2001/11/02 09:09:50 ekohl Exp $
+/* $Id: main.c,v 1.109 2001/11/25 15:21:10 dwelch Exp $
  *
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/ke/main.c
@@ -960,7 +960,7 @@ ExpInitializeExecutive(VOID)
   KeInit2();
   
   KeLowerIrql(PASSIVE_LEVEL);
-  
+
   ObInit();
   PiInitProcessManager();
   
@@ -991,8 +991,10 @@ ExpInitializeExecutive(VOID)
        }
       /* Allocate a stack for use when booting the processor */
       /* FIXME: The nonpaged memory for the stack is not released after use */
-      ProcessorStack = ExAllocatePool(NonPagedPool, MM_STACK_SIZE) + MM_STACK_SIZE;
-      Ki386InitialStackArray[((int)KeNumberProcessors)] = (PVOID)(ProcessorStack - MM_STACK_SIZE);
+      ProcessorStack = 
+       ExAllocatePool(NonPagedPool, MM_STACK_SIZE) + MM_STACK_SIZE;
+      Ki386InitialStackArray[((int)KeNumberProcessors)] = 
+       (PVOID)(ProcessorStack - MM_STACK_SIZE);
       HalInitializeProcessor(KeNumberProcessors, ProcessorStack);
       KeNumberProcessors++;
     }
@@ -1028,8 +1030,6 @@ ExpInitializeExecutive(VOID)
   /* Report all resources used by hal */
   HalReportResourceUsage();
   
-//  DumpBIOSMemoryMap();
-  
   /*
    * Initalize services loaded at boot time
    */
@@ -1163,10 +1163,6 @@ ExpInitializeExecutive(VOID)
    */
   InitSystemSharedUserPage ((PUCHAR)KeLoaderBlock.CommandLine);
 
-#if 0
-  SEHTest();
-#endif
-
   /*
    *  Launch initial process
    */
index 04f39af..3474123 100644 (file)
@@ -134,7 +134,7 @@ static VOID KiSideEffectsBeforeWake(DISPATCHER_HEADER* hdr,
                  if (Thread == NULL)
                    {
                      DPRINT1("Thread == NULL!\n");
-//                   KeBugCheck(0);
+                     KeBugCheck(0);
                    }
                  if (Abandoned != NULL)
                    *Abandoned = Mutex->Abandoned;
index 1abe36f..5674be3 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: queue.c,v 1.3 2000/12/28 03:38:07 dwelch Exp $
+/* $Id: queue.c,v 1.4 2001/11/25 15:21:10 dwelch Exp $
  * 
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -29,6 +29,14 @@ EiEnqueueMessagePort (IN OUT PEPORT          Port,
   Port->QueueLength++;
 }
 
+VOID STDCALL
+EiEnqueueMessageAtHeadPort (IN OUT     PEPORT          Port,
+                           IN  PQUEUEDMESSAGE  Message)
+{
+  InsertTailList (&Port->QueueListHead,
+                 &Message->QueueListEntry);
+  Port->QueueLength++;
+}
 
 PQUEUEDMESSAGE STDCALL
 EiDequeueMessagePort (IN OUT   PEPORT  Port)
index fe8b069..0470336 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: reply.c,v 1.7 2001/06/23 19:13:33 phreak Exp $
+/* $Id: reply.c,v 1.8 2001/11/25 15:21:10 dwelch Exp $
  * 
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -16,6 +16,7 @@
 #include <internal/port.h>
 #include <internal/dbg.h>
 #include <internal/pool.h>
+#include <internal/safe.h>
 
 #define NDEBUG
 #include <internal/debug.h>
@@ -227,7 +228,19 @@ NtReplyWaitReceivePortEx(IN  HANDLE                PortHandle,
    Request = EiDequeueMessagePort(Port);
    
    assert( Request );
-   memcpy(LpcMessage, &Request->Message, Request->Message.MessageSize);
+   Status = MmCopyToCaller(LpcMessage, &Request->Message,
+                          Request->Message.MessageSize);
+   if (!NT_SUCCESS(Status))
+     {
+       /*
+       * Copying the message to the caller's buffer failed so 
+       * undo what we did and return.
+       */
+       EiEnqueueMessageAtHeadPort(Port, Request);
+       KeReleaseSpinLock(&Port->Lock, oldIrql);
+       ObDereferenceObject(Port);
+       return(Status);
+     }
    if (Request->Message.MessageType == LPC_CONNECTION_REQUEST)
      {
        EiEnqueueConnectMessagePort(Port, Request);
index dab467b..9221fc3 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: send.c,v 1.5 2001/06/23 19:13:33 phreak Exp $
+/* $Id: send.c,v 1.6 2001/11/25 15:21:10 dwelch Exp $
  * 
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -15,6 +15,7 @@
 #include <internal/ob.h>
 #include <internal/port.h>
 #include <internal/dbg.h>
+#include <internal/safe.h>
 
 #define NDEBUG
 #include <internal/debug.h>
@@ -75,8 +76,8 @@ LpcSendDebugMessagePort (IN PEPORT Port,
        ObDereferenceObject(Port);
        return(Status);
      }
-   KeReleaseSemaphore( &Port->OtherPort->Semaphore, IO_NO_INCREMENT, 1, FALSE );   
-   
+   KeReleaseSemaphore(&Port->OtherPort->Semaphore, IO_NO_INCREMENT, 1, FALSE);
+
    /*
     * Wait for a reply
     */
@@ -183,17 +184,19 @@ NTSTATUS STDCALL NtRequestPort (IN        HANDLE          PortHandle,
  */
 NTSTATUS STDCALL 
 NtRequestWaitReplyPort (IN HANDLE PortHandle,
-                       PLPC_MESSAGE LpcRequest,    
-                       PLPC_MESSAGE LpcReply)
+                       PLPC_MESSAGE UnsafeLpcRequest,    
+                       PLPC_MESSAGE UnsafeLpcReply)
 {
    NTSTATUS Status;
    PEPORT Port;
    PQUEUEDMESSAGE Message;
    KIRQL oldIrql;
-   
+   PLPC_MESSAGE LpcRequest;
+   USHORT LpcRequestMessageSize;
+
    DPRINT("NtRequestWaitReplyPort(PortHandle %x, LpcRequest %x, "
          "LpcReply %x)\n", PortHandle, LpcRequest, LpcReply);
-   
+
    Status = ObReferenceObjectByHandle(PortHandle,
                                      PORT_ALL_ACCESS, 
                                      ExPortType,
@@ -204,8 +207,48 @@ NtRequestWaitReplyPort (IN HANDLE PortHandle,
      {
        return(Status);
      }
-   
-   
+
+   Status = MmCopyFromCaller(&LpcRequestMessageSize,
+                            &UnsafeLpcRequest->MessageSize,
+                            sizeof(USHORT));
+   if (!NT_SUCCESS(Status))
+     {
+       ObDereferenceObject(Port);
+       return(Status);
+     }
+   if (LpcRequestMessageSize > (sizeof(LPC_MESSAGE) + MAX_MESSAGE_DATA))
+     {
+       ObDereferenceObject(Port);
+       return(STATUS_PORT_MESSAGE_TOO_LONG);
+     }
+   LpcRequest = ExAllocatePool(NonPagedPool, LpcRequestMessageSize);
+   if (LpcRequest == NULL)
+     {
+       ObDereferenceObject(Port);
+       return(STATUS_NO_MEMORY);
+     }
+   Status = MmCopyFromCaller(LpcRequest, UnsafeLpcRequest,
+                            LpcRequestMessageSize);
+   if (!NT_SUCCESS(Status))
+     {
+       ExFreePool(LpcRequest);
+       ObDereferenceObject(Port);
+       return(Status);
+     }
+   LpcRequestMessageSize = LpcRequest->MessageSize;
+   if (LpcRequestMessageSize > (sizeof(LPC_MESSAGE) + MAX_MESSAGE_DATA))
+     {
+       ExFreePool(LpcRequest);
+       ObDereferenceObject(Port);
+       return(STATUS_PORT_MESSAGE_TOO_LONG);
+     }
+   if (LpcRequest->DataSize != (LpcRequest->MessageSize - sizeof(LPC_MESSAGE)))
+     {
+       ExFreePool(LpcRequest);
+       ObDereferenceObject(Port);
+       return(STATUS_PORT_MESSAGE_TOO_LONG);
+     }
+
    Status = EiReplyOrRequestPort(Port->OtherPort, 
                                 LpcRequest, 
                                 LPC_REQUEST,
@@ -213,10 +256,13 @@ NtRequestWaitReplyPort (IN HANDLE PortHandle,
    if (!NT_SUCCESS(Status))
      {
        DbgPrint("Enqueue failed\n");
+       ExFreePool(LpcRequest);
        ObDereferenceObject(Port);
        return(Status);
      }
-   KeReleaseSemaphore( &Port->OtherPort->Semaphore, IO_NO_INCREMENT, 1, FALSE);   
+   ExFreePool(LpcRequest);
+   KeReleaseSemaphore (&Port->OtherPort->Semaphore, IO_NO_INCREMENT, 
+                      1, FALSE);   
    
    /*
     * Wait for a reply
@@ -235,12 +281,13 @@ NtRequestWaitReplyPort (IN HANDLE PortHandle,
    KeReleaseSpinLock(&Port->Lock, oldIrql);
    DPRINT("Message->Message.MessageSize %d\n",
           Message->Message.MessageSize);
-   memcpy(LpcReply, &Message->Message, Message->Message.MessageSize);
+   Status = MmCopyToCaller(UnsafeLpcReply, &Message->Message, 
+                          Message->Message.MessageSize);
    ExFreePool(Message);
    
    ObDereferenceObject(Port);
    
-   return(STATUS_SUCCESS);
+   return(Status);
 }
 
 
index e51e205..545842f 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: aspace.c,v 1.6 2001/03/07 16:48:43 dwelch Exp $
+/* $Id: aspace.c,v 1.7 2001/11/25 15:21:11 dwelch Exp $
  * 
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -29,17 +29,31 @@ STATIC MADDRESS_SPACE KernelAddressSpace;
 VOID 
 MmLockAddressSpace(PMADDRESS_SPACE AddressSpace)
 {
-   (VOID)KeWaitForMutexObject(&AddressSpace->Lock,
-                             0,
-                             KernelMode,
-                             FALSE,
-                             NULL);   
+  /*
+   * Don't bother with locking if we are the first thread.
+   */
+  if (KeGetCurrentThread() == NULL)
+    {
+      return;
+    }
+  (VOID)KeWaitForMutexObject(&AddressSpace->Lock,
+                            0,
+                            KernelMode,
+                            FALSE,
+                            NULL);   
 }
 
 VOID 
 MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace)
 {
-   KeReleaseMutex(&AddressSpace->Lock, FALSE);
+  /*
+   * Don't bother locking if we are the first thread.
+   */
+  if (KeGetCurrentThread() == NULL)
+    {
+      return;
+    }
+  KeReleaseMutex(&AddressSpace->Lock, FALSE);
 }
 
 VOID 
index f064281..7431e23 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: kmap.c,v 1.10 2001/05/05 19:13:10 chorns Exp $
+/* $Id: kmap.c,v 1.11 2001/11/25 15:21:11 dwelch Exp $
  *
  * COPYRIGHT:    See COPYING in the top level directory
  * PROJECT:      ReactOS kernel
@@ -92,7 +92,7 @@ MiCopyFromUserPage(ULONG DestPhysPage, PVOID SourceAddress)
   return(STATUS_SUCCESS);
 }
 
-PVOID 
+PVOID
 ExAllocatePageWithPhysPage(ULONG PhysPage)
 {
    KIRQL oldlvl;
@@ -101,25 +101,25 @@ ExAllocatePageWithPhysPage(ULONG PhysPage)
    NTSTATUS Status;
 
    KeAcquireSpinLock(&AllocMapLock, &oldlvl);
-   for (i=1; i<ALLOC_MAP_SIZE;i++)
+   for (i = 1; i < ALLOC_MAP_SIZE; i++)
      {
-       if (!test_bit(i%32,&AllocMap[i/32]))
-         {
-            DPRINT("i %x\n",i);
-            set_bit(i%32,&AllocMap[i/32]);
-            addr = (ULONG)(NonPagedPoolBase + (i*PAGESIZE));
-            Status = MmCreateVirtualMapping(NULL, 
-                                            (PVOID)addr, 
-                                            PAGE_READWRITE | PAGE_SYSTEM, 
-                                            PhysPage);
-            if (!NT_SUCCESS(Status))
-              {
-                 DbgPrint("Unable to create virtual mapping\n");
-                 KeBugCheck(0);
-              }
-            KeReleaseSpinLock(&AllocMapLock, oldlvl);
-            return((PVOID)addr);
-         }
+       if (!test_bit(i % 32, &AllocMap[i / 32]))
+        {
+           DPRINT("i %x\n",i);
+           set_bit(i % 32, &AllocMap[i / 32]);
+           addr = (ULONG)(NonPagedPoolBase + (i*PAGESIZE));
+           Status = MmCreateVirtualMapping(NULL, 
+                                           (PVOID)addr, 
+                                           PAGE_READWRITE | PAGE_SYSTEM, 
+                                           PhysPage);
+           if (!NT_SUCCESS(Status))
+             {
+               DbgPrint("Unable to create virtual mapping\n");
+               KeBugCheck(0);
+             }
+           KeReleaseSpinLock(&AllocMapLock, oldlvl);
+           return((PVOID)addr);
+        }
      }
    KeReleaseSpinLock(&AllocMapLock, oldlvl);
    return(NULL);
@@ -132,6 +132,23 @@ MmInitKernelMap(PVOID BaseAddress)
    KeInitializeSpinLock(&AllocMapLock);
 }
 
+VOID
+MiFreeNonPagedPoolRegion(PVOID Addr, ULONG Count, BOOLEAN Free)
+{
+  ULONG i;
+  ULONG Base = (Addr - NonPagedPoolBase) / PAGESIZE;
+
+  for (i = 0; i < Count; i++)
+    {
+      clear_bit((Base + i) % 32, &AllocMap[(Base + i) / 32]);
+      MmDeleteVirtualMapping(NULL, 
+                            Addr + (i * PAGESIZE), 
+                            Free, 
+                            NULL, 
+                            NULL);
+    }
+}
+
 PVOID
 MiAllocNonPagedPoolRegion(ULONG nr_pages)
 /*
@@ -161,7 +178,7 @@ MiAllocNonPagedPoolRegion(ULONG nr_pages)
                    {
                       set_bit(j%32,&AllocMap[j/32]);
                    }
-      DPRINT("returning %x\n",((start*PAGESIZE)+NonPagedPoolBase));
+                 DPRINT("returning %x\n",((start*PAGESIZE)+NonPagedPoolBase));
                  return(((start*PAGESIZE)+NonPagedPoolBase));
               }
          }
index 2a9f227..29a6c25 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mminit.c,v 1.25 2001/08/30 20:38:20 dwelch Exp $
+/* $Id: mminit.c,v 1.26 2001/11/25 15:21:11 dwelch Exp $
  *
  * COPYRIGHT:   See COPYING in the top directory
  * PROJECT:     ReactOS kernel 
@@ -97,7 +97,10 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
    Length = PAGE_ROUND_UP(((ULONG)&_text_end__)) - KERNEL_BASE;
    ParamLength = ParamLength - Length;
    
-   MmLockAddressSpace(MmGetKernelAddressSpace());
+   /*
+    * No need to lock the address space at this point since no
+    * other threads are running.
+    */
    MmCreateMemoryArea(NULL,
                      MmGetKernelAddressSpace(),
                      MEMORY_AREA_SYSTEM,
@@ -106,7 +109,6 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
                      0,
                      &kernel_text_desc,
                      FALSE);
-   MmUnlockAddressSpace(MmGetKernelAddressSpace());
 
    Length = PAGE_ROUND_UP(((ULONG)&_bss_end__)) - 
             PAGE_ROUND_UP(((ULONG)&_text_end__));
@@ -114,7 +116,11 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
    DPRINT("Length %x\n",Length);
    BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG)&_text_end__));
    DPRINT("BaseAddress %x\n",BaseAddress);
-   MmLockAddressSpace(MmGetKernelAddressSpace());
+
+   /*
+    * No need to lock the address space at this point since we are
+    * the only thread running.
+    */
    MmCreateMemoryArea(NULL,
                      MmGetKernelAddressSpace(),                      
                      MEMORY_AREA_SYSTEM,
@@ -146,7 +152,10 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
                      0,
                      &kernel_pool_desc,
                      FALSE);
-   
+
+   /*
+    * Create the kernel mapping of the user/kernel shared memory.
+    */
    BaseAddress = (PVOID)KERNEL_SHARED_DATA_BASE;
    Length = PAGESIZE;
    MmCreateMemoryArea(NULL,
@@ -157,7 +166,6 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
                      0,
                      &kernel_shared_data_desc,
                      FALSE);
-   MmUnlockAddressSpace(MmGetKernelAddressSpace());
    MmSharedDataPagePhysicalAddress = MmAllocPage(0);
    Status = MmCreateVirtualMapping(NULL,
                                   (PVOID)KERNEL_SHARED_DATA_BASE,
@@ -169,22 +177,6 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
        KeBugCheck(0);
      }
    ((PKUSER_SHARED_DATA)KERNEL_SHARED_DATA_BASE)->TickCountLow = 0xdeadbeef;
-#if 0
-  for (i = 0; i < 0x100; i++)
-    {
-  Status = MmCreateVirtualMapping(NULL,
-         (PVOID)(i*PAGESIZE),
-               PAGE_READWRITE,
-               (ULONG)(i*PAGESIZE));
-   if (!NT_SUCCESS(Status))
-     {
-       DbgPrint("Unable to create virtual mapping\n");
-       KeBugCheck(0);
-     }
-  }
-#endif
-//   MmDumpMemoryAreas();
-   DPRINT("MmInitVirtualMemory() done\n");
 }
 
 VOID MmInit1(ULONG FirstKrnlPhysAddr,
index f46a30d..20a78e5 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: npool.c,v 1.48 2001/10/29 02:39:38 dwelch Exp $
+/* $Id: npool.c,v 1.49 2001/11/25 15:21:11 dwelch Exp $
  *
  * COPYRIGHT:    See COPYING in the top level directory
  * PROJECT:      ReactOS kernel
@@ -35,9 +35,8 @@
  * Put each block in its own range of pages and position the block at the
  * end of the range so any accesses beyond the end of block are to invalid
  * memory locations. 
- * FIXME: Not implemented yet.
  */
-/* #define WHOLE_PAGE_ALLOCATIONS */
+//#define WHOLE_PAGE_ALLOCATIONS
 
 #ifdef ENABLE_VALIDATE_POOL
 #define VALIDATE_POOL validate_kernel_pool()
@@ -70,6 +69,11 @@ typedef struct _BLOCK_HDR
   BOOLEAN Dumped;
 } BLOCK_HDR;
 
+PVOID STDCALL 
+ExAllocateWholePageBlock(ULONG Size);
+VOID STDCALL
+ExFreeWholePageBlock(PVOID Addr);
+
 /* GLOBALS *****************************************************************/
 
 /*
@@ -87,6 +91,7 @@ static LIST_ENTRY FreeBlockListHead;
  */
 static LIST_ENTRY UsedBlockListHead;
 
+#ifndef WHOLE_PAGE_ALLOCATIONS
 /*
  * Count of free blocks
  */
@@ -96,6 +101,7 @@ static ULONG EiNrFreeBlocks = 0;
  * Count of used blocks
  */
 static ULONG EiNrUsedBlocks = 0;
+#endif
 
 /*
  * Lock that protects the non-paged pool data structures
@@ -118,6 +124,9 @@ ULONG EiUsedNonPagedPool = 0;
 PVOID
 MiAllocNonPagedPoolRegion(unsigned int nr_pages);
 
+VOID
+MiFreeNonPagedPoolRegion(PVOID Addr, ULONG Count, BOOLEAN Free);
+
 #ifdef TAG_STATISTICS_TRACKING
 #define TAG_HASH_TABLE_SIZE       (1024)
 static BLOCK_HDR* tag_hash_table[TAG_HASH_TABLE_SIZE];
@@ -355,6 +364,8 @@ MiDebugDumpNonPagedPool(BOOLEAN NewOnly)
    KeReleaseSpinLock(&MmNpoolLock, oldIrql);
 }
 
+#ifndef WHOLE_PAGE_ALLOCATIONS
+
 #ifdef ENABLE_VALIDATE_POOL
 static void validate_free_list(void)
 /*
@@ -813,6 +824,8 @@ static void* take_block(BLOCK_HDR* current, unsigned int size,
    return(block_to_address(current));
 }
 
+#endif /* not WHOLE_PAGE_ALLOCATIONS */
+
 VOID STDCALL ExFreePool (PVOID block)
 /*
  * FUNCTION: Releases previously allocated memory
@@ -820,11 +833,33 @@ VOID STDCALL ExFreePool (PVOID block)
  *        block = block to free
  */
 {
+#ifdef WHOLE_PAGE_ALLOCATIONS /* WHOLE_PAGE_ALLOCATIONS */
+   KIRQL oldIrql;
+
+   if (block == NULL)
+     {
+       return;
+     }
+
+   DPRINT("freeing block %x\n",blk);
+   
+   POOL_TRACE("ExFreePool(block %x), size %d, caller %x\n",block,blk->size,
+            ((PULONG)&block)[-1]);
+   
+   KeAcquireSpinLock(&MmNpoolLock, &oldIrql);
+
+   ExFreeWholePageBlock(block);
+   KeReleaseSpinLock(&MmNpoolLock, oldIrql);      
+
+#else /* not WHOLE_PAGE_ALLOCATIONS */
+
    BLOCK_HDR* blk=address_to_block(block);
    KIRQL oldIrql;
 
-   if( !block )
-     return;
+   if (block == NULL)
+     {
+       return;
+     }
 
    DPRINT("freeing block %x\n",blk);
    
@@ -832,7 +867,7 @@ VOID STDCALL ExFreePool (PVOID block)
             ((PULONG)&block)[-1]);
    
    KeAcquireSpinLock(&MmNpoolLock, &oldIrql);
-      
+
    VALIDATE_POOL;
    
    if (blk->Magic != BLOCK_HDR_USED_MAGIC)
@@ -861,16 +896,40 @@ VOID STDCALL ExFreePool (PVOID block)
    merge_free_block(blk);
 
    EiUsedNonPagedPool = EiUsedNonPagedPool - blk->Size;
-   EiFreeNonPagedPool = EiFreeNonPagedPool + blk->Size;
-   
+   EiFreeNonPagedPool = EiFreeNonPagedPool + blk->Size;   
    VALIDATE_POOL;
-   
    KeReleaseSpinLock(&MmNpoolLock, oldIrql);
+
+#endif /* WHOLE_PAGE_ALLOCATIONS */
 }
 
 PVOID STDCALL 
 ExAllocateNonPagedPoolWithTag(ULONG Type, ULONG Size, ULONG Tag, PVOID Caller)
 {
+#ifdef WHOLE_PAGE_ALLOCATIONS
+   PVOID block;
+   KIRQL oldIrql;
+   
+   POOL_TRACE("ExAllocatePool(NumberOfBytes %d) caller %x ",
+             Size,Caller);
+   
+   KeAcquireSpinLock(&MmNpoolLock, &oldIrql);
+   
+   /*
+    * accomodate this useful idiom
+    */
+   if (Size == 0)
+     {
+       POOL_TRACE("= NULL\n");
+       KeReleaseSpinLock(&MmNpoolLock, oldIrql);
+       return(NULL);
+     }
+
+   block = ExAllocateWholePageBlock(Size);
+   KeReleaseSpinLock(&MmNpoolLock, oldIrql);
+   return(block);
+
+#else /* not WHOLE_PAGE_ALLOCATIONS */
    BLOCK_HDR* current = NULL;
    PLIST_ENTRY current_entry;
    PVOID block;
@@ -928,7 +987,57 @@ ExAllocateNonPagedPoolWithTag(ULONG Type, ULONG Size, ULONG Tag, PVOID Caller)
    memset(block, 0, Size);
    KeReleaseSpinLock(&MmNpoolLock, oldIrql);
    return(block);
+#endif /* WHOLE_PAGE_ALLOCATIONS */
+}
+
+#ifdef WHOLE_PAGE_ALLOCATIONS
+
+PVOID STDCALL 
+ExAllocateWholePageBlock(ULONG UserSize)
+{
+  PVOID Address;
+  PVOID Page;
+  ULONG i;
+  ULONG Size;
+  ULONG NrPages;
+
+  Size = sizeof(ULONG) + UserSize;
+  NrPages = ROUND_UP(Size, PAGESIZE) / PAGESIZE;
+
+  Address = MiAllocNonPagedPoolRegion(NrPages + 1);
+
+  for (i = 0; i < NrPages; i++)
+    {
+      Page = MmAllocPage(0);
+      if (Page == NULL)
+       {
+         KeBugCheck(0);
+       }
+      MmCreateVirtualMapping(NULL, 
+                            Address + (i * PAGESIZE),
+                            PAGE_READWRITE | PAGE_SYSTEM,
+                            (ULONG)Page);
+    }
+
+  *((PULONG)((ULONG)Address + (NrPages * PAGESIZE) - Size)) = NrPages;
+  return((PVOID)((ULONG)Address + (NrPages * PAGESIZE) - UserSize));
+}
+
+VOID STDCALL
+ExFreeWholePageBlock(PVOID Addr)
+{
+  ULONG NrPages;
+  
+  if ((ULONG)Addr < kernel_pool_base ||
+      (ULONG)Addr >= (kernel_pool_base + NONPAGED_POOL_SIZE))
+    {
+      DbgPrint("Block %x found outside pool area\n", Addr);
+      KeBugCheck(0);
+    }
+  NrPages = *(PULONG)((ULONG)Addr - sizeof(ULONG));
+  MiFreeNonPagedPoolRegion((PVOID)PAGE_ROUND_DOWN((ULONG)Addr), NrPages, TRUE);
 }
 
+#endif /* WHOLE_PAGE_ALLOCATIONS */
 
 /* EOF */
index 2b0428a..f43b9e1 100644 (file)
@@ -12,12 +12,35 @@ OBJECTS = getopt.o lang.o mcl.o utils.o wmc.o write.o y_tab.o
 CLEAN_FILES = *.o wmc$(EXE_POSTFIX)
 
 wmc$(EXE_POSTFIX): $(OBJECTS)
-       $(HOST_CC) $(OBJECTS) -lkernel32 -lcrtdll -luser32 -o wmc$(EXE_POSTFIX)
+       $(HOST_CC) $(OBJECTS) -o wmc$(EXE_POSTFIX)
+
+HOST_CFLAGS = -I.
+
+getopt.o: getopt.c
+       $(HOST_CC) $(HOST_CFLAGS) -c getopt.c -o getopt.o
+
+lang.o: lang.c
+       $(HOST_CC) $(HOST_CFLAGS) -c lang.c -o lang.o
+
+mcl.o: mcl.c
+       $(HOST_CC) $(HOST_CFLAGS) -c mcl.c -o mcl.o
+
+utils.o: utils.c
+       $(HOST_CC) $(HOST_CFLAGS) -c utils.c -o utils.o
+
+wmc.o: wmc.c
+       $(HOST_CC) $(HOST_CFLAGS) -c wmc.c -o wmc.o
+
+write.o: write.c
+       $(HOST_CC) $(HOST_CFLAGS) -c write.c -o write.o
+
+y_tab.o: y_tab.c
+       $(HOST_CC) $(HOST_CFLAGS) -c y_tab.c -o y_tab.o
 
 ifeq ($(HOST),mingw32-linux)
 clean:
-       rm *.o
-       rm wmc$(EXE_POSTFIX)
+       rm -f *.o
+       rm -f wmc$(EXE_POSTFIX)
 endif
 ifeq ($(HOST),mingw32-windows)
 clean: