Reactos
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxUserObject.cpp
8
9Abstract:
10
11 This module implements the user object that device
12 driver writers can use to take advantage of the
13 driver frameworks infrastructure.
14
15Author:
16
17
18
19
20Environment:
21
22 Both kernel and user mode
23
24Revision History:
25
26
27
28
29
30
31--*/
32
33#include "fxobjectpch.hpp"
34
35#include "fxuserobject.hpp"
36
37// Tracing support
38extern "C" {
39#if defined(EVENT_TRACING)
40#include "FxUserObject.tmh"
41#endif
42}
43
44_Must_inspect_result_
45NTSTATUS
46FxUserObject::_Create(
47 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
48 __in_opt PWDF_OBJECT_ATTRIBUTES Attributes,
49 __out FxUserObject** pUserObject
50 )
51{
52 FxUserObject* pObject = NULL;
53 NTSTATUS status;
54 USHORT wrapperSize = 0;
55 WDFOBJECT handle;
56
57#ifdef INLINE_WRAPPER_ALLOCATION
58#if FX_CORE_MODE==FX_CORE_USER_MODE
59 wrapperSize = FxUserObject::GetWrapperSize();
60#endif
61#endif
62
63 pObject = new(FxDriverGlobals, Attributes, wrapperSize)
64 FxUserObject(FxDriverGlobals);
65
66
67 if (pObject == NULL) {
68 DoTraceLevelMessage(FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGOBJECT,
69 "Memory allocation failed");
70 return STATUS_INSUFFICIENT_RESOURCES;
71 }
72
73 status = pObject->Commit(Attributes, &handle);
74
75 if (!NT_SUCCESS(status)) {
76 DoTraceLevelMessage(FxDriverGlobals, TRACE_LEVEL_ERROR,
77 TRACINGOBJECT,
78 "FxObject::Commit failed %!STATUS!", status);
79 }
80
81 if (NT_SUCCESS(status)) {
82 *pUserObject = pObject;
83 }
84 else {
85 pObject->DeleteFromFailedCreate();
86 }
87
88 return status;
89}
90
91//
92// Public constructors
93//
94
95FxUserObject::FxUserObject(
96 __in PFX_DRIVER_GLOBALS FxDriverGlobals
97 ) :
98#ifdef INLINE_WRAPPER_ALLOCATION
99 FxNonPagedObject(FX_TYPE_USEROBJECT, sizeof(FxUserObject) + GetWrapperSize(), FxDriverGlobals)
100#else
101 FxNonPagedObject(FX_TYPE_USEROBJECT, sizeof(FxUserObject), FxDriverGlobals)
102#endif
103{
104 return;
105}
106