ReactOS 0.4.15-dev-7924-g5949c20
fxregkeykm.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxRegKey.cpp
8
9Abstract:
10
11Author:
12
13Environment:
14
15 kernel mode only
16
17Revision History:
18
19--*/
20
21#include "fxsupportpch.hpp"
22
23extern "C" {
24// #include "FxRegKeyKM.tmh"
25}
26
27#define AT_PASSIVE() ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL)
28
30 PFX_DRIVER_GLOBALS FxDriverGlobals
31 ) :
32 FxPagedObject(FX_TYPE_REG_KEY, sizeof(FxRegKey), FxDriverGlobals),
33 m_Key(NULL),
34 m_Globals(FxDriverGlobals)
35{
36}
37
39FxRegKey::~FxRegKey()
40{
41 if (m_Key != NULL) {
43 m_Key = NULL;
44 }
45}
46
49FxRegKey::_Close(
51 )
52{
53 return ZwClose(Key);
54}
55
59FxRegKey::_Create(
62 __out HANDLE* NewKey,
66 )
67{
69
70 AT_PASSIVE();
71
72 //
73 // Force OBJ_KERNEL_HANDLE because we are never passing the handle back
74 // up to a process and we don't want to create a handle in an arbitrary
75 // process from which that process can close the handle out from underneath
76 // us.
77 //
79 &oa,
83 NULL);
84
85 return ZwCreateKey(NewKey,
87 &oa,
88 0,
89 0,
92}
93
97FxRegKey::_OpenKey(
102 )
103{
105
106 AT_PASSIVE();
107
108 //
109 // Force OBJ_KERNEL_HANDLE because we are never passing the handle back
110 // up to a process and we don't want to create a handle in an arbitrary
111 // process from which that process can close the handle out from underneath
112 // us.
113 //
115 &oa,
118 ParentKey,
119 NULL);
120
121 return ZwOpenKey(Key, DesiredAccess, &oa);
122}
123
127FxRegKey::_SetValue(
133 )
134{
135 AT_PASSIVE();
136
137 return ZwSetValueKey(Key,
139 0,
140 ValueType,
141 Value,
143}
144
148FxRegKey::_QueryValue(
149 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
156 )
157{
158 KEY_VALUE_PARTIAL_INFORMATION *pPartial, partial;
161
162 if (Value == NULL) {
163 //
164 // Caller wants just the length
165 //
166 pPartial = &partial;
167 length = _ComputePartialSize(0);
168 RtlZeroMemory(&partial, length);
169 }
170 else {
171 length = _ComputePartialSize(ValueLength);
173 MxMemory::MxAllocatePoolWithTag(PagedPool, length, FxDriverGlobals->Tag);
174
175 if (pPartial == NULL) {
177 }
178 }
179
180 //
181 // We always pass a buffer of at least sizeof(KEY_VALUE_PARTIAL_INFORMATION)
182 // to ZwQueryValueKey. This means that ZwQueryValueKey will write at least
183 // some information to the buffer it receives, even if the user-supplied data
184 // buffer is NULL or too small.
185 //
186 // According to ZwQueryValueKey's contract, this means that it will never return
187 // STATUS_BUFFER_TOO_SMALL (returned when no data is written). Therefore, if the
188 // user passes a NULL or insufficient buffer and the value exists in the registry,
189 // ZwQueryValueKey will return STATUS_BUFFER_OVERFLOW.
190 //
191 status = ZwQueryValueKey(Key,
194 pPartial,
195 length,
196 &length);
197
198 if (NT_SUCCESS(status) && Value != NULL && (ValueLength >= pPartial->DataLength)) {
199 RtlCopyMemory(Value, &pPartial->Data[0], pPartial->DataLength);
200 }
201
203 if (ValueLengthQueried != NULL) {
204 *ValueLengthQueried = pPartial->DataLength;
205 }
206 if (ValueType != NULL) {
207 *ValueType = pPartial->Type;
208 }
209 }
210
211 if (pPartial != &partial) {
212 MxMemory::MxFreePool(pPartial);
213 }
214
215 return status;
216}
217
221FxRegKey::_QueryULong(
225 )
226{
229
232
233 length = sizeof(buffer);
234 pPartial = (PKEY_VALUE_PARTIAL_INFORMATION) &buffer[0];
235
236 status = ZwQueryValueKey(Key,
239 pPartial,
240 length,
241 &length);
242
244 pPartial->Type != REG_DWORD) {
246 }
247
248 if (NT_SUCCESS(status)) {
249 ASSERT(sizeof(ULONG) == pPartial->DataLength);
250
251 RtlCopyMemory(Value, &pPartial->Data[0], sizeof(ULONG));
252 }
253
254 return status;
255}
256
260FxRegKey::_QueryQuadWord(
264 )
265{
268
271
272 length = sizeof(buffer);
273 pPartial = (PKEY_VALUE_PARTIAL_INFORMATION) &buffer[0];
274
275 status = ZwQueryValueKey(Key,
278 pPartial,
279 length,
280 &length);
281
283 pPartial->Type != REG_QWORD) {
285 }
286
287 if (NT_SUCCESS(status)) {
288 ASSERT(sizeof(LARGE_INTEGER) == pPartial->DataLength);
289
290 RtlCopyMemory(Value, &pPartial->Data[0], sizeof(LARGE_INTEGER));
291 }
292
293 return status;
294}
295
296
LONG NTSTATUS
Definition: precomp.h:26
HANDLE m_Key
Definition: fxregkey.hpp:261
FxRegKey(PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: fxregkeykm.cpp:29
static __inline VOID MxFreePool(__in PVOID Ptr)
Definition: mxmemorykm.h:41
static __inline PVOID MxAllocatePoolWithTag(__in POOL_TYPE PoolType, __in SIZE_T NumberOfBytes, __in ULONG Tag)
Definition: mxmemorykm.h:30
#define __out_opt
Definition: dbghelp.h:65
#define __in
Definition: dbghelp.h:35
#define __in_bcount(x)
Definition: dbghelp.h:41
#define __in_opt
Definition: dbghelp.h:38
#define __out
Definition: dbghelp.h:62
#define __out_bcount_opt(x)
Definition: dbghelp.h:71
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define __drv_maxIRQL(irql)
Definition: driverspecs.h:291
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define PagedPool
Definition: env_spec_w32.h:308
#define AT_PASSIVE()
Definition: fxregkeykm.cpp:27
@ FX_TYPE_REG_KEY
Definition: fxtypes.h:51
GLuint buffer
Definition: glext.h:5915
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define ASSERT(a)
Definition: mode.c:44
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define _In_
Definition: ms_sal.h:308
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
@ KeyValuePartialInformation
Definition: nt_native.h:1182
ULONG ACCESS_MASK
Definition: nt_native.h:40
struct _KEY_VALUE_PARTIAL_INFORMATION * PKEY_VALUE_PARTIAL_INFORMATION
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: ntstatus.h:273
#define REG_QWORD
Definition: sdbapi.c:597
#define REG_DWORD
Definition: sdbapi.c:596
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
Definition: ps.c:97
uint32_t * PULONG
Definition: typedefs.h:59
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
union _LARGE_INTEGER LARGE_INTEGER
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG _Out_opt_ PULONG CreateDisposition
Definition: wdfregistry.h:120
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG ValueLengthQueried
Definition: wdfregistry.h:279
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG CreateOptions
Definition: wdfregistry.h:118
_Must_inspect_result_ _In_opt_ WDFKEY ParentKey
Definition: wdfregistry.h:69
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:282
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG ValueLength
Definition: wdfregistry.h:275
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
unsigned char UCHAR
Definition: xmlstorage.h:181