ReactOS  0.4.15-dev-2704-gd5265b0
fxmemoryobject.hpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxMemoryObject.hpp
8 
9 Abstract:
10  This is the base class for a whole host of memory objects which serve
11  different purposes: The hierarchy is this
12 
13  FxMemoryObject : public FxObject, public IFxMemory
14  FxMemoryBuffer
15  FxMemoryBufferFromPool
16  FxMemoryPagedBufferFromPool
17  FxMemoryBufferFromLookaside
18  FxMemoryBufferFromPoolLookaside
19  FxMemoryPagedBufferFromPoolLookaside
20  FxMemoryBufferPreallocated
21  FxRequestMemory
22 
23  Here is quick overview of what each object does/brings to the table:
24 
25  FxMemoryObject: provides an implementation for almost all of IFxMemory's
26  abstract functions. It also provides a static _Create function which
27  can create non lookaside based memory objects
28 
29  FxMemoryBuffer: memory object which can hold the external buffer within its
30  own object allocation. This means that the sizeof(FxMemoryBuffer) +
31  external bufer size + extra computations < PAGE_SIZE
32 
33  FxMemoryBufferFromPool: memory object whose external buffer is a separate
34  allocation. The external buffer can be either paged or non paged.
35 
36  FxMemoryPagedBufferFromPool: same as FxMemoryBufferFromPool. In addition,
37  it has a back pointer to the owning FxDeviceBase so that the object
38  can be disposed on the correct dispose list.
39 
40  FxMemoryBufferFromLookaside: same as FxMemoryBuffer. In addition, the
41  object knows how to return itself to the lookaside which created it.
42 
43  FxMemoryBufferFromPoolLookaside: same as FxMemoryBufferFromPool. In
44  addtion, the object knows how to return itself to the lookaside which
45  created it.
46 
47  FxMemoryPagedBufferFromPoolLookaside: same as
48  FxMemoryBufferFromPoolLookaside. In addtion, it has a back pointer to
49  the owning FxDeviceBase so that the object can be disposed on the
50  correct dispose list.
51 
52  FxMemoryBufferPreallocated: a memory object which does not own the external
53  buffer's lifetime. It is a wrapper object to allow existing buffers to
54  be used as a WDFMEMORY.
55 
56  FxRequestMemory: same as FxMemoryBufferPreallocated. In addtion, it knows
57  about PMDLs and is tied to the lifetime of a WDFREQUEST.
58 
59 Author:
60 
61 Environment:
62 
63  kernel mode only
64 
65 Revision History:
66 
67 --*/
68 
69 #ifndef _FXMEMORYOBJECT_H_
70 #define _FXMEMORYOBJECT_H_
71 
72 class FxMemoryObject : public FxObject, public IFxMemory {
73 public:
74  static
76  NTSTATUS
77  _Create(
82  __in size_t BufferSize,
84  );
85 
86  // begin IFxMemory derivations
87  virtual
88  size_t
90  VOID
91  )
92  {
93  return m_BufferSize;
94  }
95 
96  virtual
97  PMDL
99  VOID
100  )
101  {
102  //
103  // This function or its derivatives do not allocate the PMDL, they just
104  // return one if there is one in the object already.
105  //
106  return NULL;
107  }
108 
109  virtual
110  WDFMEMORY
112  VOID
113  )
114  {
115  return (WDFMEMORY) GetObjectHandle();
116  }
117 
118  virtual
121  VOID
122  )
123  {
125  }
126 
127  virtual
128  ULONG
130  __in PVOID Tag,
131  __in LONG Line,
133  )
134  {
135  return FxObject::AddRef(Tag, Line, File);
136  }
137 
138  virtual
139  ULONG
141  __in PVOID Tag,
142  __in LONG Line,
144  )
145  {
146  return FxObject::Release(Tag, Line, File);
147  }
148 
149  virtual
150  VOID
152  VOID
153  )
154  {
155  DeleteObject();
156  }
157 
158  virtual
159  USHORT
161  VOID
162  )
163  {
164  //
165  // By default, memory is readable and writable
166  return 0;
167  }
168  // end IFxMemory derivations
169 
170 protected:
171 
173  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
174  __in USHORT ObjectSize,
175  __in size_t BufferSize
176  );
177 
178  virtual
180  NTSTATUS
183  )
184  {
185  switch (Params->Type) {
186  case IFX_TYPE_MEMORY:
187  // cast is necessary for necessary this pointer offset to be computed
188  *Params->Object = (IFxMemory*) this;
189  return STATUS_SUCCESS;
190 
191  default:
192  return FxObject::QueryInterface(Params); // __super call
193  }
194  }
195 
196  size_t m_BufferSize;
197 };
198 
199 #endif // _FXMEMORYOBJECT_H_
virtual VOID DeleteObject(VOID)
#define _Must_inspect_result_
Definition: no_sal2.h:62
virtual ULONG Release(__in_opt PVOID Tag=NULL, __in LONG Line=0, __in_opt PSTR File=NULL)
Definition: fxobject.hpp:853
_In_ WDFIOTARGET _In_ PWDF_REQUEST_COMPLETION_PARAMS Params
Definition: wdfrequest.h:306
virtual ULONG Release(__in PVOID Tag, __in LONG Line, __in_opt PSTR File)
#define __in_opt
Definition: dbghelp.h:38
LONG NTSTATUS
Definition: precomp.h:26
DriverGlobals
long LONG
Definition: pedump.c:60
PVOID __inline GetObjectHandle(VOID)
Definition: fxobject.hpp:603
#define __out
Definition: dbghelp.h:62
virtual PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
virtual USHORT GetFlags(VOID)
INT POOL_TYPE
Definition: typedefs.h:78
virtual PMDL GetMdl(VOID)
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _Strict_type_match_ POOL_TYPE _In_opt_ ULONG PoolTag
Definition: wdfmemory.h:159
Definition: ncftp.h:79
FxMemoryObject(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in USHORT ObjectSize, __in size_t BufferSize)
#define __inout
Definition: dbghelp.h:50
virtual VOID Delete(VOID)
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4061
virtual size_t GetBufferSize(VOID)
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
virtual WDFMEMORY GetHandle(VOID)
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
unsigned short USHORT
Definition: pedump.c:61
signed char * PSTR
Definition: retypes.h:7
#define NULL
Definition: types.h:112
ULONG __inline AddRef(__in_opt PVOID Tag=NULL, __in LONG Line=0, __in_opt PSTR File=NULL)
Definition: fxobject.hpp:826
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3810
unsigned int ULONG
Definition: retypes.h:1
virtual _Must_inspect_result_ NTSTATUS QueryInterface(__in FxQueryInterfaceParams *Params)
Definition: fxobject.cpp:255
Definition: File.h:15
#define STATUS_SUCCESS
Definition: shellext.h:65
#define __in
Definition: dbghelp.h:35
virtual _Must_inspect_result_ NTSTATUS QueryInterface(__inout FxQueryInterfaceParams *Params)
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
virtual ULONG AddRef(__in PVOID Tag, __in LONG Line, __in_opt PSTR File)
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
static _Must_inspect_result_ NTSTATUS _Create(__in PFX_DRIVER_GLOBALS DriverGlobals, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __in POOL_TYPE PoolType, __in ULONG PoolTag, __in size_t BufferSize, __out FxMemoryObject **Object)