:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / lib / kernel32 / misc / sysinfo.c
1 /* $Id$
2  *
3  * reactos/lib/kernel32/misc/sysinfo.c
4  *
5  */
6 #include <ddk/ntddk.h>
7
8 #include <kernel32/kernel32.h>
9 #include <kernel32/error.h>
10
11 #define WIN32_LEAN_AND_MEAN
12 #include <windows.h>
13
14
15 #define PV_NT351 0x00030033
16
17 VOID
18 STDCALL
19 GetSystemInfo (
20         LPSYSTEM_INFO   Si
21         )
22 {
23         SYSTEM_BASIC_INFORMATION        Sbi;
24         SYSTEM_PROCESSOR_INFORMATION    Spi;
25         DWORD                           ProcessVersion;
26         NTSTATUS                        Status;
27
28         RtlZeroMemory (Si, sizeof (SYSTEM_INFO));
29         Status = NtQuerySystemInformation (
30                         SystemBasicInformation, /* 0 */
31                         & Sbi,
32                         sizeof Sbi, /* 44 */
33                         0
34                         );
35         if (STATUS_SUCCESS != Status)
36         {
37                 SetLastErrorByStatus (Status);
38                 return;
39         }
40         Status = NtQuerySystemInformation (
41                         SystemProcessorInformation, /* 1 */
42                         & Spi,
43                         sizeof Spi, /* 12 */
44                         0
45                         );
46         if (STATUS_SUCCESS != Status)
47         {
48                 SetLastErrorByStatus (Status);
49                 return;
50         }
51         /*
52          *      PROCESSOR_ARCHITECTURE_INTEL 0
53          *      PROCESSOR_ARCHITECTURE_MIPS  1
54          *      PROCESSOR_ARCHITECTURE_ALPHA 2
55          *      PROCESSOR_ARCHITECTURE_PPC   3
56          *      PROCESSOR_ARCHITECTURE_UNKNOWN 0xFFFF
57          */
58         Si->u.s.wProcessorArchitecture  = Spi.ProcessorArchitecture;
59         /* For future use: always zero */
60         Si->u.s.wReserved               = 0;
61         Si->dwPageSize                  = Sbi.PageSize;
62         Si->lpMinimumApplicationAddress = (PVOID)Sbi.MinimumUserModeAddress;
63         Si->lpMaximumApplicationAddress = (PVOID)Sbi.MaximumUserModeAddress;
64         Si->dwActiveProcessorMask       = Sbi.ActiveProcessorsAffinityMask;
65         Si->dwNumberOfProcessors        = Sbi.NumberOfProcessors;
66         /*
67          * Compatibility (no longer relevant):
68          *      PROCESSOR_INTEL_386     386
69          *      PROCESSOR_INTEL_486     486
70          *      PROCESSOR_INTEL_PENTIUM 586
71          *      PROCESSOR_MIPS_R4000    4000
72          *      PROCESSOR_ALPHA_21064   21064
73          */
74         switch (Spi.ProcessorArchitecture)
75         {
76         case PROCESSOR_ARCHITECTURE_INTEL:
77                 switch (Spi.ProcessorLevel)
78                 {
79                 case 3:
80                         Si->dwProcessorType = PROCESSOR_INTEL_386;
81                         break;
82                 case 4:
83                         Si->dwProcessorType = PROCESSOR_INTEL_486;
84                         break;
85                 case 5:
86                         Si->dwProcessorType = PROCESSOR_INTEL_PENTIUM;
87                         break;
88                 default:
89                         /* FIXME: P2, P3, P4...? */
90                         Si->dwProcessorType = PROCESSOR_INTEL_PENTIUM;
91                 }
92                 break;
93                 
94         case PROCESSOR_ARCHITECTURE_MIPS:
95                 Si->dwProcessorType = PROCESSOR_MIPS_R4000;
96                 break;
97                 
98         case PROCESSOR_ARCHITECTURE_ALPHA:
99                 Si->dwProcessorType = PROCESSOR_ALPHA_21064;
100                 break;
101                 
102         case PROCESSOR_ARCHITECTURE_PPC:
103                 Si->dwProcessorType = -1; /* FIXME: what value? */
104                 break;
105                 
106         }
107         /* Once hardcoded to 64kb */
108         Si->dwAllocationGranularity     = Sbi.AllocationGranularity;
109         /* */
110         Si->wProcessorLevel             = Spi.ProcessorLevel;
111         Si->wProcessorRevision          = Spi.ProcessorRevision;
112         /*
113          * Get the version of Windows on which
114          * the process expects to run.
115          */
116         ProcessVersion = GetProcessVersion (0); /* current process */
117          /* In NT 3.1 and 3.5 these fields were always zero. */
118         if (PV_NT351 > ProcessVersion)
119         {
120                 Si->wProcessorLevel = 0;
121                 Si->wProcessorRevision = 0;
122         }
123 }
124
125
126 /* EOF */