ReactOS 0.4.16-dev-295-g4aee028
misc.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for misc.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define PRODUCT_TAG   'iPtR'
 

Functions

ULONG NTAPI RtlGetNtGlobalFlags (VOID)
 
NTSTATUS NTAPI RtlGetVersion (IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
 
BOOLEAN NTAPI RtlGetNtProductType (OUT PNT_PRODUCT_TYPE ProductType)
 Retrieves the NT type product of the operating system. This is the kernel-mode variant of this function.
 
VOID FASTCALL RtlPrefetchMemoryNonTemporal (IN PVOID Source, IN SIZE_T Length)
 

Variables

ULONG NtGlobalFlag
 
ULONG NtMajorVersion
 
ULONG NtMinorVersion
 
ULONG NtOSCSDVersion
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file misc.c.

◆ PRODUCT_TAG

#define PRODUCT_TAG   'iPtR'

Definition at line 22 of file misc.c.

Function Documentation

◆ RtlGetNtGlobalFlags()

ULONG NTAPI RtlGetNtGlobalFlags ( VOID  )

Definition at line 31 of file misc.c.

32{
33 return NtGlobalFlag;
34}
ULONG NtGlobalFlag
Definition: init.c:54

Referenced by FatalExit(), RtlAssert(), RtlCreateHeap(), and RtlCreateUserProcess().

◆ RtlGetNtProductType()

BOOLEAN NTAPI RtlGetNtProductType ( OUT PNT_PRODUCT_TYPE  ProductType)

Retrieves the NT type product of the operating system. This is the kernel-mode variant of this function.

Parameters
[out]ProductTypeThe NT type product enumeration value returned by the call.
Returns
The function returns TRUE when the call successfully returned the type product of the system. It'll return FALSE on failure otherwise. In the latter case the function will return WinNT as the default product type.
Remarks
The call expects to be called at PASSIVE_LEVEL. The function firstly checks if the product type is actually valid by checking the "ProductTypeIsValid" member of _KUSER_SHARED_DATA structure. Currently we do not implement code that is responsible for the management of this member, yet.

Definition at line 87 of file misc.c.

88{
89 HANDLE Key;
95 ULONG BufferKeyLength = sizeof(PKEY_VALUE_PARTIAL_INFORMATION) + (256 * sizeof(WCHAR));
96 UNICODE_STRING NtProductType;
97 static UNICODE_STRING WorkstationProduct = RTL_CONSTANT_STRING(L"WinNT");
98 static UNICODE_STRING LanManProduct = RTL_CONSTANT_STRING(L"LanmanNT");
99 static UNICODE_STRING ServerProduct = RTL_CONSTANT_STRING(L"ServerNT");
100 static UNICODE_STRING KeyProduct = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\ProductOptions");
101 static UNICODE_STRING ValueNtProduct = RTL_CONSTANT_STRING(L"ProductType");
102
103 PAGED_CODE();
104
105 /* Before doing anything else we must allocate some buffer space in the pool */
106 BufferKey = ExAllocatePoolWithTag(PagedPool, BufferKeyLength, PRODUCT_TAG);
107 if (!BufferKey)
108 {
109 /* We failed to allocate pool memory, bail out */
110 DPRINT1("RtlGetNtProductType(): Memory pool allocation has failed!\n");
111 Success = FALSE;
112 goto Exit;
113 }
114
115 /* Initialize the object attributes to open our key */
117 &KeyProduct,
119 NULL,
120 NULL);
121
122 /* Open the key */
124 if (!NT_SUCCESS(Status))
125 {
126 DPRINT1("RtlGetNtProductType(): The ZwOpenKey() function has failed! (Status: 0x%lx)\n", Status);
127 Success = FALSE;
128 goto Exit;
129 }
130
131 /* Now it's time to query the value from the key to check what kind of product the OS is */
132 Status = ZwQueryValueKey(Key,
133 &ValueNtProduct,
135 BufferKey,
136 BufferKeyLength,
138
139 /* Free the key from the memory */
140 ZwClose(Key);
141
142 if (!NT_SUCCESS(Status))
143 {
144 DPRINT1("RtlGetNtProductType(): The ZwQueryValueKey() function has failed! (Status: 0x%lx)\n", Status);
145 Success = FALSE;
146 goto Exit;
147 }
148
149 /*
150 * Do a sanity check before we get the product type of the operating system
151 * so that we're sure the type of the value we've got is actually correct.
152 */
153 if (BufferKey->Type != REG_SZ)
154 {
155 /* We've got something else, so bail out */
156 DPRINT1("RtlGetNtProductType(): An invalid value type has been found!\n");
157 Success = FALSE;
158 goto Exit;
159 }
160
161 /* Initialise the Unicode string with the data from the registry value */
162 NtProductType.Length = NtProductType.MaximumLength = BufferKey->DataLength;
163 NtProductType.Buffer = (PWCHAR)BufferKey->Data;
164
165 if (NtProductType.Length > sizeof(WCHAR) && NtProductType.Buffer[NtProductType.Length /
166 sizeof(WCHAR) - 1] == UNICODE_NULL)
167 {
168 NtProductType.Length -= sizeof(WCHAR);
169 }
170
171 /* Now it's time to get the product based on the value data */
172 if (RtlCompareUnicodeString(&NtProductType, &WorkstationProduct, TRUE) == 0)
173 {
174 /* The following product is an OS Workstation */
175 *ProductType = NtProductWinNt;
176 Success = TRUE;
177 }
178 else if (RtlCompareUnicodeString(&NtProductType, &LanManProduct, TRUE) == 0)
179 {
180 /* The following product is an OS Advanced Server */
181 *ProductType = NtProductLanManNt;
182 Success = TRUE;
183 }
184 else if (RtlCompareUnicodeString(&NtProductType, &ServerProduct, TRUE) == 0)
185 {
186 /* The following product is an OS Server */
187 *ProductType = NtProductServer;
188 Success = TRUE;
189 }
190 else
191 {
192 /* None of the product types match so bail out */
193 DPRINT1("RtlGetNtProductType(): Couldn't find a valid product type! Defaulting to WinNT...\n");
194 Success = FALSE;
195 goto Exit;
196 }
197
198Exit:
199 if (!Success)
200 {
201 *ProductType = NtProductWinNt;
202 }
203
204 ExFreePoolWithTag(BufferKey, PRODUCT_TAG);
205 return Success;
206}
#define PAGED_CODE()
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:188
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
@ NtProductWinNt
Definition: shellpath.c:64
@ NtProductLanManNt
Definition: shellpath.c:65
@ NtProductServer
Definition: shellpath.c:66
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
#define PagedPool
Definition: env_spec_w32.h:308
@ Success
Definition: eventcreate.c:712
Status
Definition: gdiplustypes.h:25
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define REG_SZ
Definition: layer.c:22
if(dx< 0)
Definition: linetemp.h:194
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
@ KeyValuePartialInformation
Definition: nt_native.h:1182
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
struct _KEY_VALUE_PARTIAL_INFORMATION * PKEY_VALUE_PARTIAL_INFORMATION
#define UNICODE_NULL
#define PRODUCT_TAG
Definition: misc.c:22
#define L(x)
Definition: ntvdm.h:50
static void Exit(void)
Definition: sock.c:1330
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ RtlGetVersion()

NTSTATUS NTAPI RtlGetVersion ( IN OUT PRTL_OSVERSIONINFOW  lpVersionInformation)

Definition at line 41 of file misc.c.

42{
43 PAGED_CODE();
44
45 /* Return the basics */
46 lpVersionInformation->dwMajorVersion = NtMajorVersion;
47 lpVersionInformation->dwMinorVersion = NtMinorVersion;
48 lpVersionInformation->dwBuildNumber = NtBuildNumber & 0x3FFF;
49 lpVersionInformation->dwPlatformId = VER_PLATFORM_WIN32_NT;
50
51 /* Check if this is the extended version */
52 if (lpVersionInformation->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
53 {
54 PRTL_OSVERSIONINFOEXW InfoEx = (PRTL_OSVERSIONINFOEXW)lpVersionInformation;
55 InfoEx->wServicePackMajor = (USHORT)(CmNtCSDVersion >> 8) & 0xFF;
56 InfoEx->wServicePackMinor = (USHORT)(CmNtCSDVersion & 0xFF);
57 InfoEx->wSuiteMask = (USHORT)(SharedUserData->SuiteMask & 0xFFFF);
58 InfoEx->wProductType = SharedUserData->NtProductType;
59 InfoEx->wReserved = 0;
60 }
61
62 /* Always succeed */
63 return STATUS_SUCCESS;
64}
#define VER_PLATFORM_WIN32_NT
Definition: rtltypes.h:238
ULONG CmNtCSDVersion
Definition: init.c:59
ULONG NtMajorVersion
Definition: init.c:45
ULONG NtMinorVersion
Definition: init.c:46
unsigned short USHORT
Definition: pedump.c:61
#define SharedUserData
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG NtBuildNumber
Definition: init.c:50
USHORT wServicePackMinor
Definition: rtltypes.h:276
UCHAR wProductType
Definition: rtltypes.h:278
USHORT wSuiteMask
Definition: rtltypes.h:277
USHORT wServicePackMajor
Definition: rtltypes.h:275
struct _OSVERSIONINFOEXW * PRTL_OSVERSIONINFOEXW

◆ RtlPrefetchMemoryNonTemporal()

VOID FASTCALL RtlPrefetchMemoryNonTemporal ( IN PVOID  Source,
IN SIZE_T  Length 
)

Definition at line 214 of file misc.c.

216{
217 //
218 // Do nothing
219 //
222}
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102

Referenced by KiInitMachineDependent(), and START_TEST().

Variable Documentation

◆ NtGlobalFlag

◆ NtMajorVersion

ULONG NtMajorVersion
extern

Definition at line 45 of file init.c.

Referenced by ExpInitializeExecutive(), MmCreatePeb(), PsGetVersion(), and RtlGetVersion().

◆ NtMinorVersion

ULONG NtMinorVersion
extern

Definition at line 46 of file init.c.

Referenced by ExpInitializeExecutive(), MmCreatePeb(), PsGetVersion(), and RtlGetVersion().

◆ NtOSCSDVersion

ULONG NtOSCSDVersion
extern