Alexandre Julliard : kernel32: Retrieve the system info from ntdll on startup.

Alexandre Julliard julliard at winehq.org
Wed Jan 9 13:30:37 CST 2013


Module: wine
Branch: master
Commit: 62f22dd4e3ab4f4b21f8e6b571fd7f9ba3547020
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=62f22dd4e3ab4f4b21f8e6b571fd7f9ba3547020

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Jan  8 22:02:21 2013 +0100

kernel32: Retrieve the system info from ntdll on startup.

---

 dlls/kernel32/cpu.c            |   19 +++++++++----------
 dlls/kernel32/kernel_private.h |    1 +
 dlls/kernel32/process.c        |    2 ++
 dlls/kernel32/virtual.c        |   18 ++++++------------
 4 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/dlls/kernel32/cpu.c b/dlls/kernel32/cpu.c
index 333e402..0ebf8f3 100644
--- a/dlls/kernel32/cpu.c
+++ b/dlls/kernel32/cpu.c
@@ -39,9 +39,10 @@
 #include "winnt.h"
 #include "winternl.h"
 #include "psapi.h"
+#include "ddk/wdm.h"
 #include "wine/unicode.h"
+#include "kernel_private.h"
 #include "wine/debug.h"
-#include "ddk/wdm.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(reg);
 
@@ -104,13 +105,11 @@ VOID WINAPI GetSystemInfo(
 	LPSYSTEM_INFO si	/* [out] Destination for system information, may not be NULL */)
 {
     NTSTATUS                 nts;
-    SYSTEM_BASIC_INFORMATION sbi;
     SYSTEM_CPU_INFORMATION   sci;
 
     TRACE("si=0x%p\n", si);
 
-    if ((nts = NtQuerySystemInformation( SystemBasicInformation, &sbi, sizeof(sbi), NULL )) != STATUS_SUCCESS ||
-        (nts = NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL )) != STATUS_SUCCESS)
+    if ((nts = NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL )) != STATUS_SUCCESS)
     {
         SetLastError(RtlNtStatusToDosError(nts));
         return;
@@ -118,11 +117,11 @@ VOID WINAPI GetSystemInfo(
 
     si->u.s.wProcessorArchitecture  = sci.Architecture;
     si->u.s.wReserved               = 0;
-    si->dwPageSize                  = sbi.PageSize;
-    si->lpMinimumApplicationAddress = sbi.LowestUserAddress;
-    si->lpMaximumApplicationAddress = sbi.HighestUserAddress;
-    si->dwActiveProcessorMask       = sbi.ActiveProcessorsAffinityMask;
-    si->dwNumberOfProcessors        = sbi.NumberOfProcessors;
+    si->dwPageSize                  = system_info.PageSize;
+    si->lpMinimumApplicationAddress = system_info.LowestUserAddress;
+    si->lpMaximumApplicationAddress = system_info.HighestUserAddress;
+    si->dwActiveProcessorMask       = system_info.ActiveProcessorsAffinityMask;
+    si->dwNumberOfProcessors        = system_info.NumberOfProcessors;
 
     switch (sci.Architecture)
     {
@@ -162,7 +161,7 @@ VOID WINAPI GetSystemInfo(
         FIXME("Unknown processor architecture %x\n", sci.Architecture);
         si->dwProcessorType = 0;
     }
-    si->dwAllocationGranularity     = sbi.AllocationGranularity;
+    si->dwAllocationGranularity     = system_info.AllocationGranularity;
     si->wProcessorLevel             = sci.Level;
     si->wProcessorRevision          = sci.Revision;
 }
diff --git a/dlls/kernel32/kernel_private.h b/dlls/kernel32/kernel_private.h
index feeeb55..cfc2935 100644
--- a/dlls/kernel32/kernel_private.h
+++ b/dlls/kernel32/kernel_private.h
@@ -53,6 +53,7 @@ static inline obj_handle_t console_handle_unmap(HANDLE h)
 #define KERNEL32_CONSOLE_SHELL          ((HANDLE)2)
 
 extern HMODULE kernel32_handle DECLSPEC_HIDDEN;
+extern SYSTEM_BASIC_INFORMATION system_info DECLSPEC_HIDDEN;
 
 extern const WCHAR *DIR_Windows DECLSPEC_HIDDEN;
 extern const WCHAR *DIR_System DECLSPEC_HIDDEN;
diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index 3a88aaa..8fcf67b 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -87,6 +87,7 @@ static BOOL is_wow64;
 static const int is_win64 = (sizeof(void *) > sizeof(int));
 
 HMODULE kernel32_handle = 0;
+SYSTEM_BASIC_INFORMATION system_info = { 0 };
 
 const WCHAR *DIR_Windows = NULL;
 const WCHAR *DIR_System = NULL;
@@ -1146,6 +1147,7 @@ void CDECL __wine_kernel_init(void)
     setbuf(stderr,NULL);
     kernel32_handle = GetModuleHandleW(kernel32W);
     IsWow64Process( GetCurrentProcess(), &is_wow64 );
+    NtQuerySystemInformation( SystemBasicInformation, &system_info, sizeof(system_info), NULL );
 
     LOCALE_Init();
 
diff --git a/dlls/kernel32/virtual.c b/dlls/kernel32/virtual.c
index bddd638..0470073 100644
--- a/dlls/kernel32/virtual.c
+++ b/dlls/kernel32/virtual.c
@@ -48,8 +48,6 @@
 WINE_DECLARE_DEBUG_CHANNEL(seh);
 WINE_DECLARE_DEBUG_CHANNEL(file);
 
-static unsigned int page_size;
-
 
 /***********************************************************************
  *             VirtualAlloc   (KERNEL32.@)
@@ -648,19 +646,17 @@ BOOL WINAPI IsBadReadPtr( LPCVOID ptr, UINT size )
 {
     if (!size) return FALSE;  /* handle 0 size case w/o reference */
     if (!ptr) return TRUE;
-    
-    if (!page_size) page_size = getpagesize();
     __TRY
     {
         volatile const char *p = ptr;
         char dummy __attribute__((unused));
         UINT count = size;
 
-        while (count > page_size)
+        while (count > system_info.PageSize)
         {
             dummy = *p;
-            p += page_size;
-            count -= page_size;
+            p += system_info.PageSize;
+            count -= system_info.PageSize;
         }
         dummy = p[0];
         dummy = p[count - 1];
@@ -692,18 +688,16 @@ BOOL WINAPI IsBadWritePtr( LPVOID ptr, UINT size )
 {
     if (!size) return FALSE;  /* handle 0 size case w/o reference */
     if (!ptr) return TRUE;
-    
-    if (!page_size) page_size = getpagesize();
     __TRY
     {
         volatile char *p = ptr;
         UINT count = size;
 
-        while (count > page_size)
+        while (count > system_info.PageSize)
         {
             *p |= 0;
-            p += page_size;
-            count -= page_size;
+            p += system_info.PageSize;
+            count -= system_info.PageSize;
         }
         p[0] |= 0;
         p[count - 1] |= 0;




More information about the wine-cvs mailing list