From bdeaae2b8e480560abae9616fd69e1905928de14 Mon Sep 17 00:00:00 2001 From: Dmitry Fleytman Date: Sun, 6 Apr 2014 11:49:11 +0300 Subject: [PATCH] UsbDk: Util: static buffer duplication function Signed-off-by: Dmitry Fleytman --- UsbDk/Trace.h | 1 + UsbDk/UsbDkUtil.cpp | 19 +++++++++++++++++++ UsbDk/UsbDkUtil.h | 2 ++ 3 files changed, 22 insertions(+) diff --git a/UsbDk/Trace.h b/UsbDk/Trace.h index 7497b51..89bca49 100644 --- a/UsbDk/Trace.h +++ b/UsbDk/Trace.h @@ -28,6 +28,7 @@ WPP_DEFINE_BIT(TRACE_FILTERDEVICE) \ WPP_DEFINE_BIT(TRACE_WDFDEVICE) \ WPP_DEFINE_BIT(TRACE_REDIRECTOR) \ + WPP_DEFINE_BIT(TRACE_UTILS) \ ) #define WPP_FLAG_LEVEL_LOGGER(flag, level) \ diff --git a/UsbDk/UsbDkUtil.cpp b/UsbDk/UsbDkUtil.cpp index ff5098b..7e320d5 100644 --- a/UsbDk/UsbDkUtil.cpp +++ b/UsbDk/UsbDkUtil.cpp @@ -1,5 +1,7 @@ #include "Alloc.h" #include "UsbDkUtil.h" +#include "Trace.h" +#include "UsbDkUtil.tmh" NTSTATUS CWdmEvent::Wait(bool WithTimeout, LONGLONG Timeout, bool Alertable) { @@ -54,3 +56,20 @@ bool CStringComparator::operator== (const UNICODE_STRING& Str) return RtlEqualMemory(m_String.Buffer, Str.Buffer, Str.Length); } + +PVOID DuplicateStaticBuffer(const void *Buffer, SIZE_T Length, POOL_TYPE PoolType) +{ + ASSERT(Buffer != nullptr); + ASSERT(Length > 0); + + auto Duplicate = ExAllocatePoolWithTag(PoolType, Length, 'BDHR'); + if (Duplicate != nullptr) + { + RtlCopyMemory(Duplicate, Buffer, Length); + } + else + { + TraceEvents(TRACE_LEVEL_ERROR, TRACE_UTILS, "%!FUNC! Failed to allocate buffer"); + } + return Duplicate; +} diff --git a/UsbDk/UsbDkUtil.h b/UsbDk/UsbDkUtil.h index 4149c19..a6387f5 100644 --- a/UsbDk/UsbDkUtil.h +++ b/UsbDk/UsbDkUtil.h @@ -354,3 +354,5 @@ private: CString(const CString&) = delete; CString& operator= (const CString&) = delete; }; + +PVOID DuplicateStaticBuffer(const void *Buffer, SIZE_T Length, POOL_TYPE PoolType = PagedPool);