ReactOS  0.4.15-dev-3446-g30010a5
fxvalidatefunctions.hpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft. All rights reserved.
4 
5 Module Name:
6 
7  FxValidateFunctions.h
8 
9 Abstract:
10 
11  Inline functions which validate external WDF data structures
12 
13 Author:
14 
15 
16 
17 Environment:
18 
19  Both kernel and user mode
20 
21 Revision History:
22 
23  Made it mode agnostic
24 
25  Moved request options validation to FxRequestValidateFunctions.hpp
26  in kmdf\inc\private
27 
28  When request is merged FxRequestValidateFunctions.hpp can be moved to
29  shared directory
30 
31 --*/
32 
33 #ifndef _FXVALIDATEFUNCTIONS_H_
34 #define _FXVALIDATEFUNCTIONS_H_
35 
36 extern "C" {
37 
38 #if defined(EVENT_TRACING)
39 #include "FxValidateFunctions.hpp.tmh"
40 #endif
41 
42 }
43 
50 
51  // not used directly, use FX_VALIDATE_OPTION_PARENT_REQUIRED instead
53 
54  // if a parent is required, the attributes themselves are requried
57 };
58 
62  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
65  );
66 
69 __inline
71  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
74  )
75 {
76  if (Attributes == NULL) {
79  FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDEVICE,
80  "WDF_OBJECT_ATTRIBUTES required, %!STATUS!",
82  }
84  }
85 
86  if (Attributes->Size != sizeof(WDF_OBJECT_ATTRIBUTES)) {
87  //
88  // Size is wrong, bail out
89  //
91  "Attributes %p Size incorrect, expected %d, got %d, %!STATUS!",
94 
96  }
97 
98  if (Attributes->ParentObject == NULL) {
101  FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDEVICE,
102  "ParentObject required in WDF_OBJECT_ATTRIBUTES %p, %!STATUS!",
104  }
106  }
107 
108  return STATUS_SUCCESS;
109 }
110 
112 NTSTATUS
113 __inline
115  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
117  )
118 {
120 
122 
123  if (String->Length & 1) {
125  FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGAPIERROR,
126  "UNICODE_STRING %p, Length %d is odd, %!STATUS!",
127  String, String->Length, status);
128 
129  return status;
130  }
131 
132  if (String->MaximumLength & 1) {
134  FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGAPIERROR,
135  "UNICODE_STRING %p, MaximumLength %d is odd, %!STATUS!",
136  String, String->MaximumLength, status);
137 
138  return status;
139  }
140 
141  if (String->MaximumLength > 0 && String->Buffer == NULL) {
143  FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGAPIERROR,
144  "UNICODE_STRING %p, MaximumLength %d > 0, Buffer is NULL, %!STATUS!",
145  String, String->MaximumLength, status);
146 
147  return status;
148  }
149 
150  if (String->Length > String->MaximumLength) {
152  FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGAPIERROR,
153  "UNICODE_STRING %p, Length %d > MaximumLength %d, %!STATUS!",
154  String, String->Length, String->MaximumLength, status);
155 
156  return status;
157  }
158 
159  return STATUS_SUCCESS;
160 }
161 
162 #endif // _FXVALIDATEFUNCTIONS_H_
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
FX_VALIDATE_FUNCTIONS_FLAGS
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define TRACINGAPIERROR
Definition: dbgtrace.h:60
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2430
_Must_inspect_result_ NTSTATUS __inline FxValidateObjectAttributesForParentHandle(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
#define TRACINGDEVICE
Definition: dbgtrace.h:58
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags=FX_VALIDATE_OPTION_NONE_SPECIFIED)
_Must_inspect_result_ NTSTATUS __inline FxValidateUnicodeString(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PCUNICODE_STRING String)
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define STATUS_WDF_PARENT_NOT_SPECIFIED
Definition: wdfstatus.h:252
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#define __in
Definition: dbghelp.h:35
static SERVICE_STATUS status
Definition: service.c:31
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
Definition: ps.c:97