Author: ion
Date: Mon Jul 25 20:23:43 2011
New Revision: 52872

URL: http://svn.reactos.org/svn/reactos?rev=52872&view=rev
Log:
[KERNEL32]: Now that we have the BaseStaticServerData initialized, don't build 
the \ReactOS and \ReactOS\System32 paths by hand: use the ones we have.
[KERNEL32]: Same goes for BaseCachedSysInfo. Use the 
BaseStaticServerData->SysInfo instead now.
[KERNEL32]: Don't assume that the BNO directory is called BaseNamedObjects 
(this won't be true once GedMurphy's dream of multi-session support comes true) 
-- instead, use the one from BaseStaticServerData.

Modified:
    trunk/reactos/dll/win32/kernel32/client/dllmain.c
    trunk/reactos/dll/win32/kernel32/client/except.c
    trunk/reactos/dll/win32/kernel32/client/heapmem.c

Modified: trunk/reactos/dll/win32/kernel32/client/dllmain.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/dllmain.c?rev=52872&r1=52871&r2=52872&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/dllmain.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/dllmain.c [iso-8859-1] Mon Jul 25 
20:23:43 2011
@@ -29,6 +29,7 @@
 
 WCHAR BaseDefaultPathBuffer[6140];
 
+HANDLE BaseNamedObjectDirectory;
 HANDLE hProcessHeap = NULL;
 HMODULE hCurrentModule = NULL;
 HMODULE kernel32_handle = NULL;
@@ -36,7 +37,7 @@
 PPEB Peb;
 ULONG SessionId;
 BOOL ConsoleInitialized = FALSE;
-
+UNICODE_STRING BaseWindowsDirectory, BaseWindowsSystemDirectory;
 static BOOL DllInitialized = FALSE;
 
 BOOL WINAPI
@@ -68,34 +69,28 @@
 #define WIN_OBJ_DIR L"\\Windows"
 #define SESSION_DIR L"\\Sessions"
 
-SYSTEM_BASIC_INFORMATION BaseCachedSysInfo;
-
 /* FUNCTIONS *****************************************************************/
 
 NTSTATUS
 WINAPI
-OpenBaseDirectory(PHANDLE DirHandle)
+BaseGetNamedObjectDirectory(VOID)
 {
     OBJECT_ATTRIBUTES ObjectAttributes;
-    UNICODE_STRING Name = RTL_CONSTANT_STRING(L"\\BaseNamedObjects");
     NTSTATUS Status;
 
     InitializeObjectAttributes(&ObjectAttributes,
-                               &Name,
+                               &BaseStaticServerData->NamedObjectDirectory,
                                OBJ_CASE_INSENSITIVE,
                                NULL,
                                NULL);
 
-    Status = NtOpenDirectoryObject(DirHandle,
+    Status = NtOpenDirectoryObject(&BaseNamedObjectDirectory,
                                    DIRECTORY_ALL_ACCESS &
                                    ~(DELETE | WRITE_DAC | WRITE_OWNER),
                                    &ObjectAttributes);
-    if (!NT_SUCCESS(Status))
-    {
-        return Status;
-    }
-
-    DPRINT("Opened BNO: %lx\n", *DirHandle);
+    if (!NT_SUCCESS(Status)) return Status;
+
+    DPRINT("Opened BNO: %lx\n", BaseNamedObjectDirectory);
     return Status;
 }
 
@@ -144,8 +139,8 @@
     WCHAR lpTest[MAX_PATH];
     GetModuleFileNameW(NULL, lpTest, MAX_PATH);
     DPRINT("BasepInitConsole for : %S\n", lpTest);
-    DPRINT("Our current console handles are: %lx, %lx, %lx %lx\n", 
-           Parameters->ConsoleHandle, Parameters->StandardInput, 
+    DPRINT("Our current console handles are: %lx, %lx, %lx %lx\n",
+           Parameters->ConsoleHandle, Parameters->StandardInput,
            Parameters->StandardOutput, Parameters->StandardError);
 
     /* We have nothing to do if this isn't a console app... */
@@ -204,7 +199,7 @@
     ExeName = wcsrchr(Parameters->ImagePathName.Buffer, L'\\');
     if (ExeName)
         SetConsoleInputExeNameW(ExeName + 1);
-    
+
     /* Now use the proper console handle */
     Request.Data.AllocConsoleRequest.Console = Parameters->ConsoleHandle;
 
@@ -216,7 +211,7 @@
      */
     CsrRequest = MAKE_CSR_API(ALLOC_CONSOLE, CSR_CONSOLE);
     Request.Data.AllocConsoleRequest.CtrlDispatcher = ConsoleControlDispatcher;
-    Status = CsrClientCallServer(&Request, 
+    Status = CsrClientCallServer(&Request,
                                  NULL,
                                  CsrRequest,
                                  sizeof(CSR_API_MESSAGE));
@@ -226,7 +221,7 @@
         /* We're lying here, so at least the process can load... */
         return TRUE;
     }
-    
+
     if (NotConsole) return TRUE;
 
     /* We got the handles, let's set them */
@@ -247,7 +242,7 @@
         }
     }
 
-    DPRINT("Console setup: %lx, %lx, %lx, %lx\n", 
+    DPRINT("Console setup: %lx, %lx, %lx, %lx\n",
             Parameters->ConsoleHandle,
             Parameters->StandardInput,
             Parameters->StandardOutput,
@@ -274,7 +269,7 @@
         },
         {0}
     };
-    
+
     /* Allocate the fake data */
     BaseStaticServerData = RtlAllocateHeap(RtlGetProcessHeap(),
                                            HEAP_ZERO_MEMORY,
@@ -305,13 +300,13 @@
         Status = 
RtlCreateUnicodeString(&BaseStaticServerData->NamedObjectDirectory,
                                         L"\\BaseNamedObjects");
         ASSERT(NT_SUCCESS(Status));
-    } 
+    }
     else
     {
         /* Hopefully we'll fix CSRSS Before we add multiple sessions... */
         ASSERT(FALSE);
     }
-    
+
     /*
      * Confirmed that in Windows, CSDNumber and RCNumber are actually Length
      * and MaximumLength of the CSD String, since the same UNICODE_STRING is
@@ -319,10 +314,10 @@
      *
      * Somehow, in Windows this doesn't cause a buffer overflow, but it might
      * in ReactOS, so this code is disabled until someone figures out WTF.
-     */ 
+     */
     BaseStaticServerData->CSDNumber = 0;
     BaseStaticServerData->RCNumber = 0;
-    
+
     /* Initialize the CSD string */
     RtlInitEmptyUnicodeString(&BaseSrvCSDString, Buffer, sizeof(Buffer));
 
@@ -333,7 +328,6 @@
                                     NULL);
     if (NT_SUCCESS(Status))
     {
-        DPRINT1("CSD String: %wZ\n", &BaseSrvCSDString);
         wcsncpy(BaseStaticServerData->CSDVersion,
                 BaseSrvCSDString.Buffer,
                 BaseSrvCSDString.Length / sizeof(WCHAR));
@@ -348,7 +342,7 @@
                                       sizeof(BaseStaticServerData->SysInfo),
                                       NULL);
     ASSERT(NT_SUCCESS(Status));
-    
+
     BaseStaticServerData->DefaultSeparateVDM = FALSE;
     BaseStaticServerData->IsWowTaskReady = FALSE;
     BaseStaticServerData->LUIDDeviceMapsEnabled = FALSE;
@@ -360,14 +354,6 @@
                                       sizeof(BaseStaticServerData->TimeOfDay),
                                       NULL);
     ASSERT(NT_SUCCESS(Status));
-    
-    DPRINT1("ReactOS Base API Connected: %wZ %wZ %wZ %S %d KB\n",
-            &BaseStaticServerData->WindowsDirectory,
-            &BaseStaticServerData->WindowsSystemDirectory,
-            &BaseStaticServerData->NamedObjectDirectory,
-            BaseStaticServerData->CSDVersion,
-            BaseStaticServerData->SysInfo.PageSize *
-            BaseStaticServerData->SysInfo.NumberOfPhysicalPages / 1024);
 }
 
 BOOL
@@ -429,26 +415,24 @@
             ZwTerminateProcess(NtCurrentProcess(), Status);
             return FALSE;
         }
-        
+
         /* Get the server data */
-        DPRINT1("Server data: %p\n", Peb->ReadOnlyStaticServerData);
         if (!Peb->ReadOnlyStaticServerData)
         {
             /* Build fake one for ReactOS */
             BasepFakeStaticServerData();
-            
+
             /* Allocate the array */
             Peb->ReadOnlyStaticServerData = 
RtlAllocateHeap(RtlGetProcessHeap(),
                                                             HEAP_ZERO_MEMORY,
                                                             4 * sizeof(PVOID));
-                                                            
+
             /* Set the data for the BASESRV DLL Index */
             Peb->ReadOnlyStaticServerData[CSR_CONSOLE] = BaseStaticServerData;
         }
-        
+
         /* Get the server data */
         BaseStaticServerData = Peb->ReadOnlyStaticServerData[CSR_CONSOLE];
-        DPRINT1("Static data: %p\n", BaseStaticServerData);
         ASSERT(BaseStaticServerData);
 
         /* Check if we are running a CSR Server */
@@ -459,30 +443,21 @@
             CsrNewThread();
         }
 
+        /* Initialize heap handle table */
         hProcessHeap = RtlGetProcessHeap();
         RtlInitializeHandleTable(0xFFFF,
                                  sizeof(BASE_HEAP_HANDLE_ENTRY),
                                  &BaseHeapHandleTable);
+        DPRINT("Heap: %p\n", hProcessHeap);
+
+        /* Set HMODULE for our DLL */
         kernel32_handle = hCurrentModule = hDll;
-        DPRINT("Heap: %p\n", hProcessHeap);
-
-        /*
-         * Initialize WindowsDirectory and SystemDirectory
-         */
-        DPRINT("NtSystemRoot: %S\n", SharedUserData->NtSystemRoot);
-        RtlCreateUnicodeString (&WindowsDirectory, 
SharedUserData->NtSystemRoot);
-        SystemDirectory.MaximumLength = WindowsDirectory.MaximumLength + 18;
-        SystemDirectory.Length = WindowsDirectory.Length + 18;
-        SystemDirectory.Buffer = RtlAllocateHeap(hProcessHeap,
-                                                 0,
-                                                 
SystemDirectory.MaximumLength);
-        if(SystemDirectory.Buffer == NULL)
-        {
-           DPRINT1("Failure allocating SystemDirectory buffer\n");
-           return FALSE;
-        }
-        wcscpy(SystemDirectory.Buffer, WindowsDirectory.Buffer);
-        wcscat(SystemDirectory.Buffer, L"\\System32");
+
+        /* Set the directories */
+        BaseWindowsDirectory = BaseStaticServerData->WindowsDirectory;
+        BaseWindowsSystemDirectory = 
BaseStaticServerData->WindowsSystemDirectory;
+        SystemDirectory = BaseWindowsSystemDirectory;
+        WindowsDirectory = BaseWindowsDirectory;
 
         /* Construct the default path (using the static buffer) */
         _snwprintf(BaseDefaultPathBuffer, sizeof(BaseDefaultPathBuffer) / 
sizeof(WCHAR),
@@ -501,7 +476,8 @@
         InitCommandLines();
 
         /* Open object base directory */
-        Status = OpenBaseDirectory(&hBaseDir);
+        Status = BaseGetNamedObjectDirectory();
+        hBaseDir = BaseNamedObjectDirectory;
         if (!NT_SUCCESS(Status))
         {
             DPRINT1("Failed to open object base directory (Status %lx)\n", 
Status);
@@ -522,17 +498,6 @@
         if (!BasepInitConsole())
         {
             DPRINT1("Failure to set up console\n");
-            return FALSE;
-        }
-
-        /* Cache static system information */
-        Status = ZwQuerySystemInformation(SystemBasicInformation,
-                                          &BaseCachedSysInfo,
-                                          sizeof(BaseCachedSysInfo),
-                                          NULL);
-        if (!NT_SUCCESS(Status))
-        {
-            DPRINT1("Failure to get system information\n");
             return FALSE;
         }
 
@@ -559,9 +524,6 @@
 
                 /* Close object base directory */
                 NtClose(hBaseDir);
-
-                RtlFreeUnicodeString (&SystemDirectory);
-                RtlFreeUnicodeString (&WindowsDirectory);
             }
             break;
 

Modified: trunk/reactos/dll/win32/kernel32/client/except.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/except.c?rev=52872&r1=52871&r2=52872&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/except.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/except.c [iso-8859-1] Mon Jul 25 
20:23:43 2011
@@ -454,7 +454,7 @@
     if (!lp) return TRUE;
 
     /* Get the page size */
-    PageSize = BaseCachedSysInfo.PageSize;
+    PageSize = BaseStaticServerData->SysInfo.PageSize;
 
     /* Calculate the last page */
     Last = (PCHAR)((ULONG_PTR)lp + ucb - 1);
@@ -526,7 +526,7 @@
     if (!lp) return TRUE;
 
     /* Get the page size */
-    PageSize = BaseCachedSysInfo.PageSize;
+    PageSize = BaseStaticServerData->SysInfo.PageSize;
 
     /* Calculate the last page */
     Last = (PCHAR)((ULONG_PTR)lp + ucb - 1);

Modified: trunk/reactos/dll/win32/kernel32/client/heapmem.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/heapmem.c?rev=52872&r1=52871&r2=52872&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/heapmem.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/heapmem.c [iso-8859-1] Mon Jul 25 
20:23:43 2011
@@ -38,7 +38,7 @@
     /* Check if heap is growable and ensure max size is correct */
     if (dwMaximumSize == 0)
         Flags |= HEAP_GROWABLE;
-    else if (dwMaximumSize < BaseCachedSysInfo.PageSize &&
+    else if (dwMaximumSize < BaseStaticServerData->SysInfo.PageSize &&
             dwInitialSize > dwMaximumSize)
     {
         /* Max size is non-zero but less than page size which can't be correct.
@@ -1204,18 +1204,18 @@
                              NULL);
 
     /* Calculate memory load */
-    lpBuffer->dwMemoryLoad = ((DWORD)(BaseCachedSysInfo.NumberOfPhysicalPages -
+    lpBuffer->dwMemoryLoad = 
((DWORD)(BaseStaticServerData->SysInfo.NumberOfPhysicalPages -
                                       PerformanceInfo.AvailablePages) * 100) /
-                                      BaseCachedSysInfo.NumberOfPhysicalPages;
+                                      
BaseStaticServerData->SysInfo.NumberOfPhysicalPages;
 
     /* Save physical memory */
-    PhysicalMemory = BaseCachedSysInfo.NumberOfPhysicalPages *
-                     BaseCachedSysInfo.PageSize;
+    PhysicalMemory = BaseStaticServerData->SysInfo.NumberOfPhysicalPages *
+                     BaseStaticServerData->SysInfo.PageSize;
     lpBuffer->ullTotalPhys = PhysicalMemory;
 
     /* Now save available physical memory */
     PhysicalMemory = PerformanceInfo.AvailablePages *
-                     BaseCachedSysInfo.PageSize;
+                     BaseStaticServerData->SysInfo.PageSize;
     lpBuffer->ullAvailPhys = PhysicalMemory;
 
     /* Query VM and Quota Limits */
@@ -1241,11 +1241,11 @@
     lpBuffer->ullAvailPageFile = min(PageFile,
                                      QuotaLimits.PagefileLimit -
                                      VmCounters.PagefileUsage);
-    lpBuffer->ullAvailPageFile *= BaseCachedSysInfo.PageSize;
+    lpBuffer->ullAvailPageFile *= BaseStaticServerData->SysInfo.PageSize;
 
     /* Now calculate the total virtual space */
-    lpBuffer->ullTotalVirtual = (BaseCachedSysInfo.MaximumUserModeAddress -
-                                 BaseCachedSysInfo.MinimumUserModeAddress) + 1;
+    lpBuffer->ullTotalVirtual = 
(BaseStaticServerData->SysInfo.MaximumUserModeAddress -
+                                 
BaseStaticServerData->SysInfo.MinimumUserModeAddress) + 1;
 
     /* And finally the avilable virtual space */
     lpBuffer->ullAvailVirtual = lpBuffer->ullTotalVirtual -


Reply via email to