ReactOS 0.4.15-dev-7842-g558ab78
misc.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/rtl/misc.c
5 * PURPOSE: Various functions
6 *
7 * PROGRAMMERS:
8 */
9
10/* INCLUDES *****************************************************************/
11
12#include <ntoskrnl.h>
13#define NDEBUG
14#include <debug.h>
15
16/* GLOBALS *******************************************************************/
17
18extern ULONG NtGlobalFlag;
22#define PRODUCT_TAG 'iPtR'
23
24/* FUNCTIONS *****************************************************************/
25
26/*
27* @implemented
28*/
32{
33 return NtGlobalFlag;
34}
35
36/*
37 * @implemented
38 */
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}
65
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}
207
208#if !defined(_M_IX86)
209//
210// Stub for architectures which don't have this implemented
211//
212VOID
216{
217 //
218 // Do nothing
219 //
222}
223#endif
224
225/* EOF */
#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:32
enum _NT_PRODUCT_TYPE * PNT_PRODUCT_TYPE
@ 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
NTSYSAPI ULONG WINAPI RtlGetNtGlobalFlags(void)
Definition: libsupp.c:93
#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
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define VER_PLATFORM_WIN32_NT
Definition: rtltypes.h:238
@ KeyValuePartialInformation
Definition: nt_native.h:1182
#define FASTCALL
Definition: nt_native.h:50
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
struct _KEY_VALUE_PARTIAL_INFORMATION * PKEY_VALUE_PARTIAL_INFORMATION
#define UNICODE_NULL
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
ULONG CmNtCSDVersion
Definition: init.c:59
ULONG NtOSCSDVersion
ULONG NtMajorVersion
Definition: init.c:45
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 functi...
Definition: misc.c:87
ULONG NtGlobalFlag
Definition: init.c:54
VOID FASTCALL RtlPrefetchMemoryNonTemporal(IN PVOID Source, IN SIZE_T Length)
Definition: misc.c:214
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: misc.c:41
#define PRODUCT_TAG
Definition: misc.c:22
ULONG NtMinorVersion
Definition: init.c:46
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
#define SharedUserData
#define STATUS_SUCCESS
Definition: shellext.h:65
static void Exit(void)
Definition: sock.c:1330
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
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define NTAPI
Definition: typedefs.h:36
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
struct _OSVERSIONINFOEXW * PRTL_OSVERSIONINFOEXW
__wchar_t WCHAR
Definition: xmlstorage.h:180