UsbDk: Util: static buffer duplication function

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
This commit is contained in:
Dmitry Fleytman 2014-04-06 11:49:11 +03:00
parent d3c4ba2cd5
commit bdeaae2b8e
3 changed files with 22 additions and 0 deletions

View file

@ -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) \

View file

@ -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;
}

View file

@ -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);