ReactOS 0.4.15-dev-7924-g5949c20
fxregkeyum.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 user mode only
16
17Revision History:
18
19--*/
20
21#include "FxSupportPch.hpp"
22
23//#define UNICODE
24//#define _UNICODE
25#include <Winreg.h>
26
27extern "C" {
28#if defined(EVENT_TRACING)
29#include "FxRegKeyUM.tmh"
30#endif
31}
32
34 PFX_DRIVER_GLOBALS FxDriverGlobals
35 ) :
36 FxPagedObject(FX_TYPE_REG_KEY, sizeof(FxRegKey), FxDriverGlobals),
37 m_Key(NULL),
38 m_Globals(FxDriverGlobals),
39 m_CanCloseHandle(TRUE)
40{
41}
42
44#pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "Can't apply kernel mode annotations.");
45FxRegKey::~FxRegKey()
46{
47 if (m_Key != NULL) {
48 if (m_CanCloseHandle == TRUE) {
50 }
51 m_Key = NULL;
52 }
53}
54
56#pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "Can't apply kernel mode annotations.");
57FxRegKey::_Close(
59 )
60{
62
63 if (ERROR_SUCCESS == err) {
64 return STATUS_SUCCESS;
65 }
66 else {
67 return WinErrorToNtStatus(err);
68 }
69}
70
73#pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "Can't apply kernel mode annotations.");
74FxRegKey::_Create(
77 __out HANDLE* NewKey,
81 )
82{
83 HKEY parentKey;
84
85 if (NULL == ParentKey)
86 {
87 parentKey = HKEY_LOCAL_MACHINE;
88 }
89 else
90 {
91 parentKey = (HKEY) ParentKey;
92 }
93
94 DWORD err = RegCreateKeyEx(parentKey,
95 KeyName->Buffer,
96 0,
97 NULL,
100 NULL,
101 (PHKEY)NewKey,
103
104 if (ERROR_SUCCESS == err) {
105 return STATUS_SUCCESS;
106 }
107 else {
108 return WinErrorToNtStatus(err);
109 }
110}
111
114#pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "Can't apply kernel mode annotations.");
115FxRegKey::_OpenKey(
120 )
121{
122 HKEY parentKey;
123
124 if (NULL == ParentKey)
125 {
126 parentKey = HKEY_LOCAL_MACHINE;
127 }
128 else
129 {
130 parentKey = (HKEY) ParentKey;
131 }
132
133 DWORD err = RegOpenKeyEx(parentKey,
134 KeyName->Buffer,
135 0,
137 (PHKEY)Key);
138
139 if (ERROR_SUCCESS == err) {
140 return STATUS_SUCCESS;
141 }
142 else {
143 return WinErrorToNtStatus(err);
144 }
145}
146
149#pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "Can't apply kernel mode annotations.");
150FxRegKey::_SetValue(
156 )
157{
158 DWORD err;
159
161 ValueName->Buffer,
162 0,
163 ValueType,
164 (BYTE*)Value,
166 if (ERROR_SUCCESS == err) {
167 return STATUS_SUCCESS;
168 }
169 else {
170 return WinErrorToNtStatus(err);
171 }
172}
173
176#pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "Can't apply kernel mode annotations.");
177FxRegKey::_QueryValue(
178 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
185 )
186{
187 DWORD err;
190
191 UNREFERENCED_PARAMETER(FxDriverGlobals);
193
195
197 ValueName->Buffer,
198 NULL,
199 ValueType,
200 (LPBYTE)Value,
201 &length);
202
203 if (ValueLengthQueried != NULL) {
205 }
206
207 //
208 // Please see the comment in FxRegKeyKm.cpp FxRegKey::_QueryValue about
209 // the call to ZwQueryValueKey.
210 //
211 // If the user supplies a NULL data buffer, RegQueryValueEx will return
212 // ERROR_SUCCESS. However, in order to satisfy UMDF-KMDF DDI parity as well
213 // as internal mode-agnostic code, we must overwrite RegQueryValueEx's
214 // return value of ERROR_SUCCESS (STATUS_SUCCESS) with STATUS_BUFFER_OVERFLOW.
215 //
216 // Other return values are overwritten because WinErrorToNtStatus does not map
217 // all Win32 error codes that RegQueryValueEx returns to the same NTSTATUS
218 // values that ZwQueryValueKey would return in the KM implementation of
219 // FxRegKey::_QueryValue.
220 //
221 if (err == ERROR_SUCCESS) {
222 if (Value != NULL) {
224 }
225 else {
227 }
228 }
229 else if (err == ERROR_MORE_DATA) {
231 }
232 else if (err == ERROR_FILE_NOT_FOUND) {
234 }
235 else {
237 }
238
239 return status;
240}
241
244#pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "Can't apply kernel mode annotations.");
245FxRegKey::_QueryULong(
249 )
250{
251 DWORD err;
254
256
257 type = REG_DWORD;
258 length = sizeof(ULONG);
259
261 ValueName->Buffer,
262 NULL,
263 &type,
264 (LPBYTE)Value,
265 &length);
266
267 if ((err == ERROR_SUCCESS || err == ERROR_MORE_DATA) &&
268 type != REG_DWORD) {
269
270 ASSERT(FALSE);
271
273 }
274 else {
275 if (ERROR_SUCCESS == err) {
277 }
278 else {
280 }
281 }
282
283 return status;
284}
285
287#pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "Can't apply kernel mode annotations.");
289FxRegKey::_QueryQuadWord(
293 )
294{
298
299 return STATUS_UNSUCCESSFUL;
300}
301
302
LONG NTSTATUS
Definition: precomp.h:26
HANDLE HKEY
Definition: registry.h:26
#define RegCloseKey(hKey)
Definition: registry.h:49
HANDLE m_Key
Definition: fxregkey.hpp:261
FxRegKey(PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: fxregkeykm.cpp:29
BOOLEAN m_CanCloseHandle
Definition: fxregkey.hpp:271
_Must_inspect_result_ __in ULONG __in ULONG ValueLength
Definition: fxregkey.hpp:153
#define __out_opt
Definition: dbghelp.h:65
#define __in
Definition: dbghelp.h:35
#define __in_opt
Definition: dbghelp.h:38
#define __out
Definition: dbghelp.h:62
#define __out_bcount_opt(x)
Definition: dbghelp.h:71
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define __drv_maxIRQL(irql)
Definition: driverspecs.h:291
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
NTSTATUS WinErrorToNtStatus(__in ULONG WinError)
Definition: errtostatus.cpp:60
unsigned long DWORD
Definition: ntddk_ex.h:95
@ FX_TYPE_REG_KEY
Definition: fxtypes.h:51
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define ASSERT(a)
Definition: mode.c:44
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define _In_reads_bytes_(size)
Definition: ms_sal.h:321
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define _In_
Definition: ms_sal.h:308
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: ntstatus.h:273
#define err(...)
#define REG_DWORD
Definition: sdbapi.c:596
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
Definition: ps.c:97
uint32_t * PULONG
Definition: typedefs.h:59
unsigned char * LPBYTE
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_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
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegSetValueEx
Definition: winreg.h:533
#define RegCreateKeyEx
Definition: winreg.h:501
#define RegQueryValueEx
Definition: winreg.h:524
#define HKEY_PERFORMANCE_DATA
Definition: winreg.h:14
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
unsigned char BYTE
Definition: xxhash.c:193