Author: ion
Date: Thu Aug 4 00:55:52 2011
New Revision: 53057
URL:
http://svn.reactos.org/svn/reactos?rev=53057&view=rev
Log:
[KERNEL32]: Cleanup GetSystemInfo and friends, fix some bugs, mainly removing support for
unsupported CPUs/architectures, and adding support for PROCESSOR_ARCHITECTURE_AMD64. Did
some refactoring to support WoW64 in the future as well.
Modified:
trunk/reactos/dll/win32/kernel32/client/sysinfo.c
Modified: trunk/reactos/dll/win32/kernel32/client/sysinfo.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/sysinfo.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/sysinfo.c [iso-8859-1] Thu Aug 4 00:55:52
2011
@@ -1,25 +1,81 @@
-/* $Id$
- *
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS system libraries
- * FILE: dll/win32/kernel32/misc/sysinfo.c
- * PURPOSE: SystemInfo functions
- * PROGRAMMER: Emanuele Aliberti
+/*
+ * PROJECT: ReactOS Win32 Base API
+ * LICENSE: See COPYING in the top level directory
+ * FILE: dll/win32/kernel32/client/sysinfo.c
+ * PURPOSE: System Information Functions
+ * PROGRAMMERS: Emanuele Aliberti
* Christoph von Wittich
* Thomas Weidenmueller
* Gunnar Andre Dalsnes
- * UPDATE HISTORY:
- * 2000-04-26 created
- */
+ */
+
+/* INCLUDES *******************************************************************/
#include <k32.h>
#define NDEBUG
#include <debug.h>
-
#define PV_NT351 0x00030033
+/* PRIVATE FUNCTIONS **********************************************************/
+
+VOID
+WINAPI
+GetSystemInfoInternal(IN PSYSTEM_BASIC_INFORMATION BasicInfo,
+ IN PSYSTEM_PROCESSOR_INFORMATION ProcInfo,
+ OUT LPSYSTEM_INFO SystemInfo)
+{
+ RtlZeroMemory(SystemInfo, sizeof (SYSTEM_INFO));
+ SystemInfo->wProcessorArchitecture = ProcInfo->ProcessorArchitecture;
+ SystemInfo->wReserved = 0;
+ SystemInfo->dwPageSize = BasicInfo->PageSize;
+ SystemInfo->lpMinimumApplicationAddress =
(PVOID)BasicInfo->MinimumUserModeAddress;
+ SystemInfo->lpMaximumApplicationAddress =
(PVOID)BasicInfo->MaximumUserModeAddress;
+ SystemInfo->dwActiveProcessorMask = BasicInfo->ActiveProcessorsAffinityMask;
+ SystemInfo->dwNumberOfProcessors = BasicInfo->NumberOfProcessors;
+ SystemInfo->wProcessorLevel = ProcInfo->ProcessorLevel;
+ SystemInfo->wProcessorRevision = ProcInfo->ProcessorRevision;
+ SystemInfo->dwAllocationGranularity = BasicInfo->AllocationGranularity;
+
+ switch (ProcInfo->ProcessorArchitecture)
+ {
+ case PROCESSOR_ARCHITECTURE_INTEL:
+ switch (ProcInfo->ProcessorLevel)
+ {
+ case 3:
+ SystemInfo->dwProcessorType = PROCESSOR_INTEL_386;
+ break;
+ case 4:
+ SystemInfo->dwProcessorType = PROCESSOR_INTEL_486;
+ break;
+ default:
+ SystemInfo->dwProcessorType = PROCESSOR_INTEL_PENTIUM;
+ }
+ break;
+
+ case PROCESSOR_ARCHITECTURE_AMD64:
+ SystemInfo->dwProcessorType = PROCESSOR_AMD_X8664;
+ break;
+
+ case PROCESSOR_ARCHITECTURE_IA64:
+ SystemInfo->dwProcessorType = PROCESSOR_INTEL_IA64;
+ break;
+
+ default:
+ SystemInfo->dwProcessorType = 0;
+ break;
+ }
+
+ if (PV_NT351 > GetProcessVersion(0))
+ {
+ SystemInfo->wProcessorLevel = 0;
+ SystemInfo->wProcessorRevision = 0;
+ }
+}
+
+/* PUBLIC FUNCTIONS ***********************************************************/
+
/*
* @implemented
*/
@@ -27,189 +83,66 @@
WINAPI
GetLargePageMinimum(VOID)
{
- return SharedUserData->LargePageMinimum;
-}
-
-/*
- * @unimplemented
+ return SharedUserData->LargePageMinimum;
+}
+
+/*
+ * @implemented
*/
VOID
WINAPI
-GetSystemInfo (
- LPSYSTEM_INFO Si
- )
-{
- SYSTEM_BASIC_INFORMATION Sbi;
- SYSTEM_PROCESSOR_INFORMATION Spi;
- DWORD ProcessVersion;
- NTSTATUS Status;
-
- RtlZeroMemory (Si, sizeof (SYSTEM_INFO));
- Status = NtQuerySystemInformation (
- SystemBasicInformation, /* 0 */
- & Sbi,
- sizeof Sbi, /* 44 */
- 0
- );
- if (STATUS_SUCCESS != Status)
- {
- BaseSetLastNTError (Status);
- return;
- }
- Status = NtQuerySystemInformation (
- SystemProcessorInformation, /* 1 */
- & Spi,
- sizeof Spi, /* 12 */
- 0
- );
- if (STATUS_SUCCESS != Status)
- {
- BaseSetLastNTError (Status);
- return;
- }
- /*
- * PROCESSOR_ARCHITECTURE_INTEL 0
- * PROCESSOR_ARCHITECTURE_MIPS 1
- * PROCESSOR_ARCHITECTURE_ALPHA 2
- * PROCESSOR_ARCHITECTURE_PPC 3
- * PROCESSOR_ARCHITECTURE_UNKNOWN 0xFFFF
- */
- Si->wProcessorArchitecture = Spi.ProcessorArchitecture;
- /* For future use: always zero */
- Si->wReserved = 0;
- Si->dwPageSize = Sbi.PageSize;
- Si->lpMinimumApplicationAddress = (PVOID)Sbi.MinimumUserModeAddress;
- Si->lpMaximumApplicationAddress = (PVOID)Sbi.MaximumUserModeAddress;
- Si->dwActiveProcessorMask = Sbi.ActiveProcessorsAffinityMask;
- Si->dwNumberOfProcessors = Sbi.NumberOfProcessors;
- /*
- * Compatibility (no longer relevant):
- * PROCESSOR_INTEL_386 386
- * PROCESSOR_INTEL_486 486
- * PROCESSOR_INTEL_PENTIUM 586
- * PROCESSOR_MIPS_R4000 4000
- * PROCESSOR_ALPHA_21064 21064
- */
- switch (Spi.ProcessorArchitecture)
- {
- case PROCESSOR_ARCHITECTURE_INTEL:
- switch (Spi.ProcessorLevel)
- {
- case 3:
- Si->dwProcessorType = PROCESSOR_INTEL_386;
- break;
- case 4:
- Si->dwProcessorType = PROCESSOR_INTEL_486;
- break;
- case 5:
- Si->dwProcessorType = PROCESSOR_INTEL_PENTIUM;
- break;
- default:
- /* FIXME: P2, P3, P4...? */
- Si->dwProcessorType = PROCESSOR_INTEL_PENTIUM;
- }
- break;
-
- case PROCESSOR_ARCHITECTURE_MIPS:
- Si->dwProcessorType = PROCESSOR_MIPS_R4000;
- break;
-
- case PROCESSOR_ARCHITECTURE_ALPHA:
- Si->dwProcessorType = PROCESSOR_ALPHA_21064;
- break;
-
- case PROCESSOR_ARCHITECTURE_IA64:
- Si->dwProcessorType = PROCESSOR_INTEL_IA64;
- break;
-
- case PROCESSOR_ARCHITECTURE_PPC:
- switch (Spi.ProcessorLevel)
- {
- case 1:
- Si->dwProcessorType = PROCESSOR_PPC_601;
- break;
- case 3:
- Si->dwProcessorType = PROCESSOR_PPC_603;
- break;
- case 4:
- Si->dwProcessorType = PROCESSOR_PPC_604;
- break;
- case 6:
- /* PPC 603+ */
- Si->dwProcessorType = PROCESSOR_PPC_603;
- break;
- case 9:
- /* PPC 604+ */
- Si->dwProcessorType = PROCESSOR_PPC_604;
- break;
- case 20:
- Si->dwProcessorType = PROCESSOR_PPC_620;
- break;
- default:
- Si->dwProcessorType = 0;
- }
- break;
-
- }
- /* Once hardcoded to 64kb */
- Si->dwAllocationGranularity = Sbi.AllocationGranularity;
- /* */
- Si->wProcessorLevel = Spi.ProcessorLevel;
- Si->wProcessorRevision = Spi.ProcessorRevision;
- /*
- * Get the version of Windows on which
- * the process expects to run.
- */
- ProcessVersion = GetProcessVersion (0); /* current process */
- /* In NT 3.1 and 3.5 these fields were always zero. */
- if (PV_NT351 > ProcessVersion)
- {
- Si->wProcessorLevel = 0;
- Si->wProcessorRevision = 0;
- }
-}
-
-
-/*
- * @implemented
- */
-BOOL WINAPI
-IsProcessorFeaturePresent(DWORD ProcessorFeature)
-{
- if (ProcessorFeature >= PROCESSOR_FEATURE_MAX)
- return(FALSE);
-
- return((BOOL)SharedUserData->ProcessorFeatures[ProcessorFeature]);
-}
-
-
-/*
- * @implemented
- */
-BOOL
-WINAPI
-GetSystemRegistryQuota(PDWORD pdwQuotaAllowed,
- PDWORD pdwQuotaUsed)
-{
- SYSTEM_REGISTRY_QUOTA_INFORMATION srqi;
+GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
+{
+ SYSTEM_BASIC_INFORMATION BasicInfo;
+ SYSTEM_PROCESSOR_INFORMATION ProcInfo;
+ NTSTATUS Status;
+
+ Status = NtQuerySystemInformation(SystemBasicInformation,
+ &BasicInfo,
+ sizeof(BasicInfo),
+ 0);
+ if (!NT_SUCCESS(Status)) return;
+
+ Status = NtQuerySystemInformation(SystemProcessorInformation,
+ &ProcInfo,
+ sizeof(ProcInfo),
+ 0);
+ if (!NT_SUCCESS(Status)) return;
+
+ GetSystemInfoInternal(&BasicInfo, &ProcInfo, lpSystemInfo);
+}
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+IsProcessorFeaturePresent(IN DWORD ProcessorFeature)
+{
+ if (ProcessorFeature >= PROCESSOR_FEATURE_MAX) return FALSE;
+ return ((BOOL)SharedUserData->ProcessorFeatures[ProcessorFeature]);
+}
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+GetSystemRegistryQuota(OUT PDWORD pdwQuotaAllowed,
+ OUT PDWORD pdwQuotaUsed)
+{
+ SYSTEM_REGISTRY_QUOTA_INFORMATION QuotaInfo;
ULONG BytesWritten;
NTSTATUS Status;
Status = NtQuerySystemInformation(SystemRegistryQuotaInformation,
- &srqi,
- sizeof(srqi),
+ &QuotaInfo,
+ sizeof(QuotaInfo),
&BytesWritten);
- if(NT_SUCCESS(Status))
- {
- if(pdwQuotaAllowed != NULL)
- {
- *pdwQuotaAllowed = srqi.RegistryQuotaAllowed;
- }
- if(pdwQuotaUsed != NULL)
- {
- *pdwQuotaUsed = srqi.RegistryQuotaUsed;
- }
-
+ if (NT_SUCCESS(Status))
+ {
+ if (pdwQuotaAllowed) *pdwQuotaAllowed = QuotaInfo.RegistryQuotaAllowed;
+ if (pdwQuotaUsed) *pdwQuotaUsed = QuotaInfo.RegistryQuotaUsed;
return TRUE;
}
@@ -222,15 +155,27 @@
*/
VOID
WINAPI
-GetNativeSystemInfo(
- LPSYSTEM_INFO lpSystemInfo
- )
-{
- //FIXME: GetNativeSystemInfo should return always the real Hardware
Processorarchitecture
- // in case a Program is running in 32bit Mode on AMD64
- // GetSystemInfo should return PROCESSOR_ARCHITECTURE_INTEL and
- // GetNativeSystemInfo should return PROCESSOR_ARCHITECTURE_AMD64
- GetSystemInfo(lpSystemInfo);
+GetNativeSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
+{
+ SYSTEM_BASIC_INFORMATION BasicInfo;
+ SYSTEM_PROCESSOR_INFORMATION ProcInfo;
+ NTSTATUS Status;
+
+ /* FIXME: Should be SystemNativeBasicInformation */
+ Status = NtQuerySystemInformation(SystemBasicInformation,
+ &BasicInfo,
+ sizeof(BasicInfo),
+ 0);
+ if (!NT_SUCCESS(Status)) return;
+
+ /* FIXME: Should be SystemNativeProcessorInformation */
+ Status = NtQuerySystemInformation(SystemProcessorInformation,
+ &ProcInfo,
+ sizeof(ProcInfo),
+ 0);
+ if (!NT_SUCCESS(Status)) return;
+
+ GetSystemInfoInternal(&BasicInfo, &ProcInfo, lpSystemInfo);
}
/*
@@ -254,15 +199,11 @@
*ReturnLength,
ReturnLength);
+ /* Normalize the error to what Win32 expects */
+ if (Status == STATUS_INFO_LENGTH_MISMATCH) Status = STATUS_BUFFER_TOO_SMALL;
if (!NT_SUCCESS(Status))
{
- /*
- * When NtQuerySystemInformation says STATUS_INFO_LENGTH_MISMATCH,
- * return ERROR_INSUFFICIENT_BUFFER instead of ERROR_BAD_LENGTH.
- */
- BaseSetLastNTError(Status == STATUS_INFO_LENGTH_MISMATCH
- ? STATUS_BUFFER_TOO_SMALL
- : Status);
+ BaseSetLastNTError(Status);
return FALSE;
}
@@ -274,42 +215,39 @@
*/
BOOL
WINAPI
-GetNumaHighestNodeNumber(
- PULONG HighestNodeNumber
- )
-{
- STUB;
- return 0;
-}
-
-/*
- * @unimplemented
- */
-BOOL
-WINAPI
-GetNumaNodeProcessorMask(
- UCHAR Node,
- PULONGLONG ProcessorMask
- )
-{
- STUB;
- return 0;
-}
-
-/*
- * @unimplemented
- */
-BOOL
-WINAPI
-GetNumaProcessorNode(
- UCHAR Processor,
- PUCHAR NodeNumber
- )
-{
- STUB;
- return 0;
-}
-
+GetNumaHighestNodeNumber(OUT PULONG HighestNodeNumber)
+{
+ STUB;
+ return 0;
+}
+
+/*
+ * @unimplemented
+ */
+BOOL
+WINAPI
+GetNumaNodeProcessorMask(IN UCHAR Node,
+ OUT PULONGLONG ProcessorMask)
+{
+ STUB;
+ return 0;
+}
+
+/*
+ * @unimplemented
+ */
+BOOL
+WINAPI
+GetNumaProcessorNode(IN UCHAR Processor,
+ OUT PUCHAR NodeNumber)
+{
+ STUB;
+ return 0;
+}
+
+/*
+ * @unimplemented
+ */
BOOL
WINAPI
GetNumaAvailableMemoryNode(IN UCHAR Node,
@@ -324,28 +262,24 @@
*/
DWORD
WINAPI
-GetFirmwareEnvironmentVariableW(
- LPCWSTR lpName,
- LPCWSTR lpGuid,
- PVOID pBuffer,
- DWORD nSize
- )
-{
- STUB;
- return 0;
-}
-
-/*
- * @unimplemented
- */
-BOOL
-WINAPI
-SetFirmwareEnvironmentVariableW(
- LPCWSTR lpName,
- LPCWSTR lpGuid,
- PVOID pValue,
- DWORD nSize
- )
+GetFirmwareEnvironmentVariableW(IN LPCWSTR lpName,
+ IN LPCWSTR lpGuid,
+ IN PVOID pValue,
+ IN DWORD nSize)
+{
+ STUB;
+ return 0;
+}
+
+/*
+ * @unimplemented
+ */
+BOOL
+WINAPI
+SetFirmwareEnvironmentVariableW(IN LPCWSTR lpName,
+ IN LPCWSTR lpGuid,
+ IN PVOID pValue,
+ IN DWORD nSize)
{
STUB;
return 0;
@@ -356,33 +290,32 @@
*/
DWORD
WINAPI
-GetFirmwareEnvironmentVariableA(
- LPCSTR lpName,
- LPCSTR lpGuid,
- PVOID pBuffer,
- DWORD nSize
- )
-{
- STUB;
- return 0;
-}
-
-/*
- * @unimplemented
- */
-BOOL
-WINAPI
-SetFirmwareEnvironmentVariableA(
- LPCSTR lpName,
- LPCSTR lpGuid,
- PVOID pValue,
- DWORD nSize
- )
-{
- STUB;
- return 0;
-}
-
+GetFirmwareEnvironmentVariableA(IN LPCSTR lpName,
+ IN LPCSTR lpGuid,
+ IN PVOID pValue,
+ IN DWORD nSize)
+{
+ STUB;
+ return 0;
+}
+
+/*
+ * @unimplemented
+ */
+BOOL
+WINAPI
+SetFirmwareEnvironmentVariableA(IN LPCSTR lpName,
+ IN LPCSTR lpGuid,
+ IN PVOID pValue,
+ IN DWORD nSize)
+{
+ STUB;
+ return 0;
+}
+
+/*
+ * @unimplemented
+ */
UINT
WINAPI
EnumSystemFirmwareTables(IN DWORD FirmwareTableProviderSignature,
@@ -393,6 +326,9 @@
return 0;
}
+/*
+ * @unimplemented
+ */
UINT
WINAPI
GetSystemFirmwareTable(IN DWORD FirmwareTableProviderSignature,
@@ -404,6 +340,9 @@
return 0;
}
+/*
+ * @unimplemented
+ */
BOOL
WINAPI
GetSystemFileCacheSize(OUT PSIZE_T lpMinimumFileCacheSize,
@@ -414,7 +353,9 @@
return FALSE;
}
-
+/*
+ * @unimplemented
+ */
BOOL
WINAPI
SetSystemFileCacheSize(IN SIZE_T MinimumFileCacheSize,
@@ -424,4 +365,3 @@
STUB;
return FALSE;
}
-