PageRenderTime 26ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/reactos/dll/win32/kernel32/client/sysinfo.c

https://gitlab.com/dj-tech/reactos
C | 477 lines | 339 code | 55 blank | 83 comment | 26 complexity | 1c7fc3449cd676b9dfb11eb84d21ccc8 MD5 | raw file
  1. /*
  2. * PROJECT: ReactOS Win32 Base API
  3. * LICENSE: See COPYING in the top level directory
  4. * FILE: dll/win32/kernel32/client/sysinfo.c
  5. * PURPOSE: System Information Functions
  6. * PROGRAMMERS: Emanuele Aliberti
  7. * Christoph von Wittich
  8. * Thomas Weidenmueller
  9. * Gunnar Andre Dalsnes
  10. */
  11. /* INCLUDES *******************************************************************/
  12. #include <k32.h>
  13. #define NDEBUG
  14. #include <debug.h>
  15. #define PV_NT351 0x00030033
  16. /* PRIVATE FUNCTIONS **********************************************************/
  17. VOID
  18. WINAPI
  19. GetSystemInfoInternal(IN PSYSTEM_BASIC_INFORMATION BasicInfo,
  20. IN PSYSTEM_PROCESSOR_INFORMATION ProcInfo,
  21. OUT LPSYSTEM_INFO SystemInfo)
  22. {
  23. RtlZeroMemory(SystemInfo, sizeof (SYSTEM_INFO));
  24. SystemInfo->wProcessorArchitecture = ProcInfo->ProcessorArchitecture;
  25. SystemInfo->wReserved = 0;
  26. SystemInfo->dwPageSize = BasicInfo->PageSize;
  27. SystemInfo->lpMinimumApplicationAddress = (PVOID)BasicInfo->MinimumUserModeAddress;
  28. SystemInfo->lpMaximumApplicationAddress = (PVOID)BasicInfo->MaximumUserModeAddress;
  29. SystemInfo->dwActiveProcessorMask = BasicInfo->ActiveProcessorsAffinityMask;
  30. SystemInfo->dwNumberOfProcessors = BasicInfo->NumberOfProcessors;
  31. SystemInfo->wProcessorLevel = ProcInfo->ProcessorLevel;
  32. SystemInfo->wProcessorRevision = ProcInfo->ProcessorRevision;
  33. SystemInfo->dwAllocationGranularity = BasicInfo->AllocationGranularity;
  34. switch (ProcInfo->ProcessorArchitecture)
  35. {
  36. case PROCESSOR_ARCHITECTURE_INTEL:
  37. switch (ProcInfo->ProcessorLevel)
  38. {
  39. case 3:
  40. SystemInfo->dwProcessorType = PROCESSOR_INTEL_386;
  41. break;
  42. case 4:
  43. SystemInfo->dwProcessorType = PROCESSOR_INTEL_486;
  44. break;
  45. default:
  46. SystemInfo->dwProcessorType = PROCESSOR_INTEL_PENTIUM;
  47. }
  48. break;
  49. case PROCESSOR_ARCHITECTURE_AMD64:
  50. SystemInfo->dwProcessorType = PROCESSOR_AMD_X8664;
  51. break;
  52. case PROCESSOR_ARCHITECTURE_IA64:
  53. SystemInfo->dwProcessorType = PROCESSOR_INTEL_IA64;
  54. break;
  55. default:
  56. SystemInfo->dwProcessorType = 0;
  57. break;
  58. }
  59. if (PV_NT351 > GetProcessVersion(0))
  60. {
  61. SystemInfo->wProcessorLevel = 0;
  62. SystemInfo->wProcessorRevision = 0;
  63. }
  64. }
  65. /* PUBLIC FUNCTIONS ***********************************************************/
  66. /*
  67. * @implemented
  68. */
  69. SIZE_T
  70. WINAPI
  71. GetLargePageMinimum(VOID)
  72. {
  73. return SharedUserData->LargePageMinimum;
  74. }
  75. /*
  76. * @implemented
  77. */
  78. VOID
  79. WINAPI
  80. GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
  81. {
  82. SYSTEM_BASIC_INFORMATION BasicInfo;
  83. SYSTEM_PROCESSOR_INFORMATION ProcInfo;
  84. NTSTATUS Status;
  85. Status = NtQuerySystemInformation(SystemBasicInformation,
  86. &BasicInfo,
  87. sizeof(BasicInfo),
  88. 0);
  89. if (!NT_SUCCESS(Status)) return;
  90. Status = NtQuerySystemInformation(SystemProcessorInformation,
  91. &ProcInfo,
  92. sizeof(ProcInfo),
  93. 0);
  94. if (!NT_SUCCESS(Status)) return;
  95. GetSystemInfoInternal(&BasicInfo, &ProcInfo, lpSystemInfo);
  96. }
  97. /*
  98. * @implemented
  99. */
  100. BOOL
  101. WINAPI
  102. IsProcessorFeaturePresent(IN DWORD ProcessorFeature)
  103. {
  104. if (ProcessorFeature >= PROCESSOR_FEATURE_MAX) return FALSE;
  105. return ((BOOL)SharedUserData->ProcessorFeatures[ProcessorFeature]);
  106. }
  107. /*
  108. * @implemented
  109. */
  110. BOOL
  111. WINAPI
  112. GetSystemRegistryQuota(OUT PDWORD pdwQuotaAllowed,
  113. OUT PDWORD pdwQuotaUsed)
  114. {
  115. SYSTEM_REGISTRY_QUOTA_INFORMATION QuotaInfo;
  116. ULONG BytesWritten;
  117. NTSTATUS Status;
  118. Status = NtQuerySystemInformation(SystemRegistryQuotaInformation,
  119. &QuotaInfo,
  120. sizeof(QuotaInfo),
  121. &BytesWritten);
  122. if (NT_SUCCESS(Status))
  123. {
  124. if (pdwQuotaAllowed) *pdwQuotaAllowed = QuotaInfo.RegistryQuotaAllowed;
  125. if (pdwQuotaUsed) *pdwQuotaUsed = QuotaInfo.RegistryQuotaUsed;
  126. return TRUE;
  127. }
  128. BaseSetLastNTError(Status);
  129. return FALSE;
  130. }
  131. /*
  132. * @implemented
  133. */
  134. VOID
  135. WINAPI
  136. GetNativeSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
  137. {
  138. SYSTEM_BASIC_INFORMATION BasicInfo;
  139. SYSTEM_PROCESSOR_INFORMATION ProcInfo;
  140. NTSTATUS Status;
  141. /* FIXME: Should be SystemNativeBasicInformation */
  142. Status = NtQuerySystemInformation(SystemBasicInformation,
  143. &BasicInfo,
  144. sizeof(BasicInfo),
  145. 0);
  146. if (!NT_SUCCESS(Status)) return;
  147. /* FIXME: Should be SystemNativeProcessorInformation */
  148. Status = NtQuerySystemInformation(SystemProcessorInformation,
  149. &ProcInfo,
  150. sizeof(ProcInfo),
  151. 0);
  152. if (!NT_SUCCESS(Status)) return;
  153. GetSystemInfoInternal(&BasicInfo, &ProcInfo, lpSystemInfo);
  154. }
  155. /*
  156. * @implemented
  157. */
  158. BOOL
  159. WINAPI
  160. GetLogicalProcessorInformation(OUT PSYSTEM_LOGICAL_PROCESSOR_INFORMATION Buffer,
  161. IN OUT PDWORD ReturnLength)
  162. {
  163. NTSTATUS Status;
  164. if (!ReturnLength)
  165. {
  166. SetLastError(ERROR_INVALID_PARAMETER);
  167. return FALSE;
  168. }
  169. Status = NtQuerySystemInformation(SystemLogicalProcessorInformation,
  170. Buffer,
  171. *ReturnLength,
  172. ReturnLength);
  173. /* Normalize the error to what Win32 expects */
  174. if (Status == STATUS_INFO_LENGTH_MISMATCH) Status = STATUS_BUFFER_TOO_SMALL;
  175. if (!NT_SUCCESS(Status))
  176. {
  177. BaseSetLastNTError(Status);
  178. return FALSE;
  179. }
  180. return TRUE;
  181. }
  182. /*
  183. * @implemented
  184. */
  185. BOOL
  186. WINAPI
  187. GetNumaHighestNodeNumber(OUT PULONG HighestNodeNumber)
  188. {
  189. NTSTATUS Status;
  190. ULONG Length;
  191. ULONG PartialInfo[2]; // First two members of SYSTEM_NUMA_INFORMATION
  192. /* Query partial NUMA info */
  193. Status = NtQuerySystemInformation(SystemNumaProcessorMap,
  194. PartialInfo,
  195. sizeof(PartialInfo),
  196. &Length);
  197. if (!NT_SUCCESS(Status))
  198. {
  199. BaseSetLastNTError(Status);
  200. return FALSE;
  201. }
  202. if (Length < sizeof(ULONG))
  203. {
  204. SetLastError(ERROR_INVALID_PARAMETER);
  205. return FALSE;
  206. }
  207. /* First member of the struct is the highest node number */
  208. *HighestNodeNumber = PartialInfo[0];
  209. return TRUE;
  210. }
  211. /*
  212. * @implemented
  213. */
  214. BOOL
  215. WINAPI
  216. GetNumaNodeProcessorMask(IN UCHAR Node,
  217. OUT PULONGLONG ProcessorMask)
  218. {
  219. NTSTATUS Status;
  220. SYSTEM_NUMA_INFORMATION NumaInformation;
  221. ULONG Length;
  222. /* Query NUMA information */
  223. Status = NtQuerySystemInformation(SystemNumaProcessorMap,
  224. &NumaInformation,
  225. sizeof(NumaInformation),
  226. &Length);
  227. if (!NT_SUCCESS(Status))
  228. {
  229. BaseSetLastNTError(Status);
  230. return FALSE;
  231. }
  232. /* Validate input node number */
  233. if (Node > NumaInformation.HighestNodeNumber)
  234. {
  235. SetLastError(ERROR_INVALID_PARAMETER);
  236. return FALSE;
  237. }
  238. /* Return mask for that node */
  239. *ProcessorMask = NumaInformation.ActiveProcessorsAffinityMask[Node];
  240. return TRUE;
  241. }
  242. /*
  243. * @implemented
  244. */
  245. BOOL
  246. WINAPI
  247. GetNumaProcessorNode(IN UCHAR Processor,
  248. OUT PUCHAR NodeNumber)
  249. {
  250. NTSTATUS Status;
  251. SYSTEM_NUMA_INFORMATION NumaInformation;
  252. ULONG Length;
  253. ULONG Node;
  254. ULONGLONG Proc;
  255. /* Can't handle processor number >= 32 */
  256. if (Processor >= MAXIMUM_PROCESSORS)
  257. {
  258. *NodeNumber = -1;
  259. SetLastError(ERROR_INVALID_PARAMETER);
  260. return FALSE;
  261. }
  262. /* Query NUMA information */
  263. Status = NtQuerySystemInformation(SystemNumaProcessorMap,
  264. &NumaInformation,
  265. sizeof(NumaInformation),
  266. &Length);
  267. if (!NT_SUCCESS(Status))
  268. {
  269. *NodeNumber = -1;
  270. BaseSetLastNTError(Status);
  271. return FALSE;
  272. }
  273. /* Find ourselves */
  274. Node = 0;
  275. Proc = 1ULL << Processor;
  276. while ((Proc & NumaInformation.ActiveProcessorsAffinityMask[Node]) == 0ULL)
  277. {
  278. ++Node;
  279. /* Out of options */
  280. if (Node > NumaInformation.HighestNodeNumber)
  281. {
  282. *NodeNumber = -1;
  283. SetLastError(ERROR_INVALID_PARAMETER);
  284. return FALSE;
  285. }
  286. }
  287. /* Return found node */
  288. *NodeNumber = Node;
  289. return TRUE;
  290. }
  291. /*
  292. * @implemented
  293. */
  294. BOOL
  295. WINAPI
  296. GetNumaAvailableMemoryNode(IN UCHAR Node,
  297. OUT PULONGLONG AvailableBytes)
  298. {
  299. NTSTATUS Status;
  300. SYSTEM_NUMA_INFORMATION NumaInformation;
  301. ULONG Length;
  302. /* Query NUMA information */
  303. Status = NtQuerySystemInformation(SystemNumaAvailableMemory,
  304. &NumaInformation,
  305. sizeof(NumaInformation),
  306. &Length);
  307. if (!NT_SUCCESS(Status))
  308. {
  309. BaseSetLastNTError(Status);
  310. return FALSE;
  311. }
  312. /* Validate input node number */
  313. if (Node > NumaInformation.HighestNodeNumber)
  314. {
  315. SetLastError(ERROR_INVALID_PARAMETER);
  316. return FALSE;
  317. }
  318. /* Return available memory for that node */
  319. *AvailableBytes = NumaInformation.AvailableMemory[Node];
  320. return TRUE;
  321. }
  322. /*
  323. * @unimplemented
  324. */
  325. DWORD
  326. WINAPI
  327. GetFirmwareEnvironmentVariableW(IN LPCWSTR lpName,
  328. IN LPCWSTR lpGuid,
  329. IN PVOID pValue,
  330. IN DWORD nSize)
  331. {
  332. STUB;
  333. return 0;
  334. }
  335. /*
  336. * @unimplemented
  337. */
  338. BOOL
  339. WINAPI
  340. SetFirmwareEnvironmentVariableW(IN LPCWSTR lpName,
  341. IN LPCWSTR lpGuid,
  342. IN PVOID pValue,
  343. IN DWORD nSize)
  344. {
  345. STUB;
  346. return 0;
  347. }
  348. /*
  349. * @unimplemented
  350. */
  351. DWORD
  352. WINAPI
  353. GetFirmwareEnvironmentVariableA(IN LPCSTR lpName,
  354. IN LPCSTR lpGuid,
  355. IN PVOID pValue,
  356. IN DWORD nSize)
  357. {
  358. STUB;
  359. return 0;
  360. }
  361. /*
  362. * @unimplemented
  363. */
  364. BOOL
  365. WINAPI
  366. SetFirmwareEnvironmentVariableA(IN LPCSTR lpName,
  367. IN LPCSTR lpGuid,
  368. IN PVOID pValue,
  369. IN DWORD nSize)
  370. {
  371. STUB;
  372. return 0;
  373. }
  374. /*
  375. * @unimplemented
  376. */
  377. UINT
  378. WINAPI
  379. EnumSystemFirmwareTables(IN DWORD FirmwareTableProviderSignature,
  380. OUT PVOID pFirmwareTableBuffer,
  381. IN DWORD BufferSize)
  382. {
  383. STUB;
  384. return 0;
  385. }
  386. /*
  387. * @unimplemented
  388. */
  389. UINT
  390. WINAPI
  391. GetSystemFirmwareTable(IN DWORD FirmwareTableProviderSignature,
  392. IN DWORD FirmwareTableID,
  393. OUT PVOID pFirmwareTableBuffer,
  394. IN DWORD BufferSize)
  395. {
  396. STUB;
  397. return 0;
  398. }
  399. /*
  400. * @unimplemented
  401. */
  402. BOOL
  403. WINAPI
  404. GetSystemFileCacheSize(OUT PSIZE_T lpMinimumFileCacheSize,
  405. OUT PSIZE_T lpMaximumFileCacheSize,
  406. OUT PDWORD lpFlags)
  407. {
  408. STUB;
  409. return FALSE;
  410. }
  411. /*
  412. * @unimplemented
  413. */
  414. BOOL
  415. WINAPI
  416. SetSystemFileCacheSize(IN SIZE_T MinimumFileCacheSize,
  417. IN SIZE_T MaximumFileCacheSize,
  418. IN DWORD Flags)
  419. {
  420. STUB;
  421. return FALSE;
  422. }