[WDF] Add Windows Driver Framework files
[reactos.git] / sdk / lib / drivers / wdf / shared / inc / private / common / fxmemorybuffer.hpp
diff --git a/sdk/lib/drivers/wdf/shared/inc/private/common/fxmemorybuffer.hpp b/sdk/lib/drivers/wdf/shared/inc/private/common/fxmemorybuffer.hpp
new file mode 100644 (file)
index 0000000..e2f61c1
--- /dev/null
@@ -0,0 +1,93 @@
+/*++
+
+Copyright (c) Microsoft Corporation
+
+Module Name:
+
+    FxMemoryBuffer.hpp
+
+Abstract:
+
+Author:
+
+Environment:
+
+    kernel mode only
+
+Revision History:
+
+
+--*/
+
+#ifndef _FXMEMORYBUFFER_H_
+#define _FXMEMORYBUFFER_H_
+
+class FxMemoryBuffer : public FxMemoryObject {
+
+public:
+
+    // Factory function
+    static
+    _Must_inspect_result_
+    NTSTATUS
+    _Create(
+        __in  PFX_DRIVER_GLOBALS DriverGlobals,
+        __in_opt PWDF_OBJECT_ATTRIBUTES Attributes,
+        __in  ULONG PoolTag,
+        __in  size_t BufferSize,
+        __in POOL_TYPE PoolType,
+        __out FxMemoryObject** Object
+        );
+
+    FxMemoryBuffer(
+        __in PFX_DRIVER_GLOBALS FxDriverGlobals,
+        __in size_t BufferSize
+        );
+
+    PVOID
+    GetBuffer(
+        VOID
+        );
+
+    PVOID
+    __inline
+    operator new(
+        __in size_t Size,
+        __in PFX_DRIVER_GLOBALS FxDriverGlobals,
+        __in_opt PWDF_OBJECT_ATTRIBUTES Attributes,
+        __in USHORT ExtraSize,
+        __in ULONG Tag,
+        __in POOL_TYPE PoolType
+        )
+    {
+        //
+        // PoolType must be non paged pool but it can be NonPagedPool
+        // or NonPagedPoolNx or their variants
+        //
+        ASSERT(!FxIsPagedPoolType(PoolType));
+
+        //
+        // Specialize operator new so that we can use the caller's tag when
+        // making the object allocation vs using the default driver-wide tag.
+        //
+        return FxObjectHandleAlloc(FxDriverGlobals,
+                                   PoolType,
+                                   Size,
+                                   Tag,
+                                   Attributes,
+                                   ExtraSize,
+                                   FxObjectTypeExternal);
+    }
+
+protected:
+
+    FxMemoryBuffer(
+        __in PFX_DRIVER_GLOBALS FxDriverGlobals,
+        __in USHORT ObjectSize,
+        __in size_t BufferSize
+        );
+
+    ~FxMemoryBuffer();
+};
+
+#endif // _FXMEMORYBUFFER_H_