ReactOS  0.4.15-dev-2985-g54406bf
fxregkeyum.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxRegKey.cpp
8 
9 Abstract:
10 
11 Author:
12 
13 Environment:
14 
15  user mode only
16 
17 Revision History:
18 
19 --*/
20 
21 #include "FxSupportPch.hpp"
22 
23 //#define UNICODE
24 //#define _UNICODE
25 #include <Winreg.h>
26 
27 extern "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.");
45 FxRegKey::~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.");
57 FxRegKey::_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.");
74 FxRegKey::_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 
113 NTSTATUS
114 #pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "Can't apply kernel mode annotations.");
115 FxRegKey::_OpenKey(
118  __out HANDLE* Key,
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 
148 NTSTATUS
149 #pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "Can't apply kernel mode annotations.");
150 FxRegKey::_SetValue(
151  _In_ HANDLE Key,
156  )
157 {
158  DWORD err;
159 
161  ValueName->Buffer,
162  0,
163  ValueType,
164  (BYTE*)Value,
165  ValueLength);
166  if (ERROR_SUCCESS == err) {
167  return STATUS_SUCCESS;
168  }
169  else {
170  return WinErrorToNtStatus(err);
171  }
172 }
173 
175 NTSTATUS
176 #pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "Can't apply kernel mode annotations.");
177 FxRegKey::_QueryValue(
178  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
179  __in HANDLE Key,
185  )
186 {
187  DWORD err;
189  ULONG length;
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 
243 NTSTATUS
244 #pragma prefast(suppress:__WARNING_UNMATCHED_DECL_ANNO, "Can't apply kernel mode annotations.");
245 FxRegKey::_QueryULong(
246  __in HANDLE Key,
249  )
250 {
251  DWORD err;
253  ULONG length, type;
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.");
288 NTSTATUS
289 FxRegKey::_QueryQuadWord(
290  __in HANDLE Key,
293  )
294 {
298 
299  return STATUS_UNSUCCESSFUL;
300 }
301 
302 
#define RegQueryValueEx
Definition: winreg.h:524
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2654
NTSTATUS WinErrorToNtStatus(__in ULONG WinError)
Definition: errtostatus.cpp:60
#define ERROR_SUCCESS
Definition: deptool.c:10
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
#define __in_opt
Definition: dbghelp.h:38
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:279
#define __out_opt
Definition: dbghelp.h:65
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
__drv_maxIRQL(PASSIVE_LEVEL) FxRegKey
Definition: fxregkeyum.cpp:43
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define __out
Definition: dbghelp.h:62
#define _In_
Definition: ms_sal.h:308
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2697
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
BOOLEAN m_CanCloseHandle
Definition: fxregkey.hpp:271
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: ntstatus.h:273
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG _Out_opt_ PULONG CreateDisposition
Definition: wdfregistry.h:112
HANDLE m_Key
Definition: fxregkey.hpp:261
#define ASSERT(a)
Definition: mode.c:44
unsigned long DWORD
Definition: ntddk_ex.h:95
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
FxRegKey(PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: fxregkeykm.cpp:29
#define err(...)
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define ERROR_MORE_DATA
Definition: dderror.h:13
unsigned char BYTE
Definition: xxhash.c:193
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG CreateOptions
Definition: wdfregistry.h:112
_Must_inspect_result_ __in WDFKEY __in PCUNICODE_STRING __in ULONG __out_bcount_opt(ValueLength) PVOID Value
#define RegOpenKeyEx
Definition: winreg.h:520
_Must_inspect_result_ _In_opt_ WDFKEY ParentKey
Definition: wdfregistry.h:69
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
unsigned int * PULONG
Definition: retypes.h:1
PFX_DRIVER_GLOBALS m_Globals
Definition: fxobject.hpp:259
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG ValueLengthQueried
Definition: wdfregistry.h:279
HANDLE HKEY
Definition: registry.h:24
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#define HKEY_PERFORMANCE_DATA
Definition: winreg.h:14
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define __in
Definition: dbghelp.h:35
#define REG_DWORD
Definition: sdbapi.c:596
static SERVICE_STATUS status
Definition: service.c:31
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define RegSetValueEx
Definition: winreg.h:533
#define RegCreateKeyEx
Definition: winreg.h:501
_Must_inspect_result_ __in ULONG __in ULONG ValueLength
Definition: fxregkey.hpp:153
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define _In_reads_bytes_(size)
Definition: ms_sal.h:321
Definition: ps.c:97
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG ValueLength
Definition: wdfregistry.h:271