ReactOS 0.4.16-dev-306-g647d351
fxvalidatefunctions.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft. All rights reserved.
4
5Module Name:
6
7 FxValidateFunctions.cpp
8
9Abstract:
10
11 Functions which validate external WDF data structures
12
13Author:
14
15
16
17Environment:
18
19 Both kernel and user mode
20
21Revision History:
22
23
24
25
26
27
28
29
30
31
32--*/
33
34#include "fxobjectpch.hpp"
35
36// We use DoTraceMessage
37extern "C" {
38#if defined(EVENT_TRACING)
39#include "FxValidateFunctions.tmh"
40#endif
41}
42
46 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
49 )
50{
51 if (Attributes == NULL) {
54 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDEVICE,
55 "WDF_OBJECT_ATTRIBUTES required, %!STATUS!",
57
59 }
60 else {
61 return STATUS_SUCCESS;
62 }
63 }
64
65 if (Attributes->Size != sizeof(WDF_OBJECT_ATTRIBUTES)) {
66 //
67 // Size is wrong, bail out
68 //
70 "Attributes %p Size incorrect, expected %d, got %d, %!STATUS!",
73
75 }
76
77 if (Attributes->ContextTypeInfo != NULL) {
78#pragma prefast(suppress:__WARNING_REDUNDANTTEST, "different structs of the same size")
79 if (Attributes->ContextTypeInfo->Size !=
81 Attributes->ContextTypeInfo->Size !=
84 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGAPIERROR,
85 "Attributes %p ContextTypeInfo %p Size %d incorrect, expected %d, %!STATUS!",
86 Attributes, Attributes->ContextTypeInfo,
87 Attributes->ContextTypeInfo->Size,
89
91 }
92
93 //
94 // A ContextName != NULL and a ContextSize of 0 is allowed
95 //
96 if (Attributes->ContextTypeInfo->ContextSize > 0 &&
97 Attributes->ContextTypeInfo->ContextName == NULL) {
98
100 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGAPIERROR,
101 "Attributes %p ContextTypeInfo %p ContextSize %I64d is not zero, "
102 "but ContextName is NULL, %!STATUS!",
103 Attributes, Attributes->ContextTypeInfo,
104 Attributes->ContextTypeInfo->ContextSize,
106
108 }
109 }
110
111 if (Attributes->ContextSizeOverride > 0) {
112 if (Attributes->ContextTypeInfo == NULL) {
113 //
114 // Can't specify additional size without a type
115 //
117 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGAPIERROR,
118 "Attributes %p ContextSizeOverride of %I64d specified, but no type "
119 "information, %!STATUS!",
120 Attributes, Attributes->ContextSizeOverride,
122
124 }
125 else if (Attributes->ContextSizeOverride <
126 Attributes->ContextTypeInfo->ContextSize) {
128 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGAPIERROR,
129 "Attributes %p ContextSizeOverride %I64d < "
130 "ContextTypeInfo->ContextSize %I64d, %!STATUS!",
131 Attributes, Attributes->ContextSizeOverride,
132 Attributes->ContextTypeInfo->ContextSize,
134
136 }
137 }
138
140 if (Attributes->ParentObject != NULL) {
142 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGAPIERROR,
143 "Attributes %p does not allow a parent object to be set, set to "
144 "%p, %!STATUS!", Attributes, Attributes->ParentObject,
146
148 }
149 }
151 Attributes->ParentObject == NULL) {
153 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGDEVICE,
154 "ParentObject required in WDF_OBJECT_ATTRIBUTES %p, %!STATUS!",
156
158 }
159
160 // Enum range checks
161 if ((Attributes->ExecutionLevel == WdfExecutionLevelInvalid) ||
162 (Attributes->ExecutionLevel > WdfExecutionLevelDispatch)) {
164 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGAPIERROR,
165 "Attributes %p execution level set to %d, out of range, %!STATUS!",
166 Attributes, Attributes->ExecutionLevel,
169 }
170
171 if ((Attributes->SynchronizationScope == WdfSynchronizationScopeInvalid) ||
172 (Attributes->SynchronizationScope > WdfSynchronizationScopeNone)) {
174 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGAPIERROR,
175 "Attributes %p synchronization scope set to %d, out of range, %!STATUS!",
176 Attributes, Attributes->SynchronizationScope,
179 }
180
182
183 //
184 // If synchronization is not allowed for this object,
185 // check the requested level to ensure none was specified.
186 //
187 if ((Attributes->SynchronizationScope != WdfSynchronizationScopeInheritFromParent) &&
188 (Attributes->SynchronizationScope != WdfSynchronizationScopeNone)) {
189
191 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGAPIERROR,
192 "Attributes %p does not allow synchronization scope too be set, "
193 "but was set to %!WDF_SYNCHRONIZATION_SCOPE!, %!STATUS!",
194 Attributes, Attributes->SynchronizationScope,
196
198 }
199 }
200
202
203 //
204 // If execution level restrictions are not allowed for this object,
205 // check the requested level to ensure none was specified.
206 //
207 if (Attributes->ExecutionLevel != WdfExecutionLevelInheritFromParent) {
209 FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGAPIERROR,
210 "Attributes %p does not allow execution level to be set, but was"
211 " set to %!WDF_EXECUTION_LEVEL!, %!STATUS!",
212 Attributes, Attributes->ExecutionLevel,
214
216 }
217 }
218
219 return STATUS_SUCCESS;
220}
LONG NTSTATUS
Definition: precomp.h:26
#define __in
Definition: dbghelp.h:35
#define TRACINGDEVICE
Definition: dbgtrace.h:58
#define TRACINGAPIERROR
Definition: dbgtrace.h:60
#define NULL
Definition: types.h:112
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
_Must_inspect_result_ NTSTATUS FxValidateObjectAttributes(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_OBJECT_ATTRIBUTES Attributes, __in ULONG Flags)
@ FX_VALIDATE_OPTION_PARENT_REQUIRED_FLAG
@ FX_VALIDATE_OPTION_SYNCHRONIZATION_SCOPE_ALLOWED
@ FX_VALIDATE_OPTION_EXECUTION_LEVEL_ALLOWED
@ FX_VALIDATE_OPTION_ATTRIBUTES_REQUIRED
@ FX_VALIDATE_OPTION_PARENT_NOT_ALLOWED
#define _Must_inspect_result_
Definition: no_sal2.h:62
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
@ WdfSynchronizationScopeInheritFromParent
Definition: wdfobject.h:63
@ WdfSynchronizationScopeNone
Definition: wdfobject.h:66
@ WdfSynchronizationScopeInvalid
Definition: wdfobject.h:62
@ WdfExecutionLevelDispatch
Definition: wdfobject.h:55
@ WdfExecutionLevelInheritFromParent
Definition: wdfobject.h:53
@ WdfExecutionLevelInvalid
Definition: wdfobject.h:52
#define STATUS_WDF_PARENT_ASSIGNMENT_NOT_ALLOWED
Definition: wdfstatus.h:225
#define STATUS_WDF_OBJECT_ATTRIBUTES_INVALID
Definition: wdfstatus.h:171
#define STATUS_WDF_SYNCHRONIZATION_SCOPE_INVALID
Definition: wdfstatus.h:234
#define STATUS_WDF_EXECUTION_LEVEL_INVALID
Definition: wdfstatus.h:243
#define STATUS_WDF_PARENT_NOT_SPECIFIED
Definition: wdfstatus.h:252
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170