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