| Index: src/installer-ca/dutil/memutil.cpp |
| =================================================================== |
| new file mode 100644 |
| --- /dev/null |
| +++ b/src/installer-ca/dutil/memutil.cpp |
| @@ -0,0 +1,75 @@ |
| +#pragma once |
| +//------------------------------------------------------------------------------------------------- |
| +// <copyright file="memutil.cpp" company="Outercurve Foundation"> |
| +// Copyright (c) 2004, Outercurve Foundation. |
| +// This software is released under Microsoft Reciprocal License (MS-RL). |
| +// The license and further copyright text can be found in the file |
| +// LICENSE.TXT at the root directory of the distribution. |
| +// </copyright> |
| +// |
| +// <summary> |
| +// Memory helper functions. |
| +// </summary> |
| +//------------------------------------------------------------------------------------------------- |
| + |
| +#include "../precomp.h" |
| + |
| + |
| +#if DEBUG |
| +static BOOL vfMemInitialized = FALSE; |
| +#endif |
| + |
| +extern "C" HRESULT DAPI MemInitialize() |
| +{ |
| +#if DEBUG |
| + vfMemInitialized = TRUE; |
| +#endif |
| + return S_OK; |
| +} |
| + |
| +extern "C" void DAPI MemUninitialize() |
| +{ |
| +#if DEBUG |
| + vfMemInitialized = FALSE; |
| +#endif |
| +} |
| + |
| +extern "C" LPVOID DAPI MemAlloc( |
| + __in SIZE_T cbSize, |
| + __in BOOL fZero |
| + ) |
| +{ |
| +// AssertSz(vfMemInitialized, "MemInitialize() not called, this would normally crash"); |
| + AssertSz(cbSize > 0, "MemAlloc() called with invalid size"); |
| + return ::HeapAlloc(::GetProcessHeap(), fZero ? HEAP_ZERO_MEMORY : 0, cbSize); |
| +} |
| + |
| + |
| +extern "C" LPVOID DAPI MemReAlloc( |
| + __in LPVOID pv, |
| + __in SIZE_T cbSize, |
| + __in BOOL fZero |
| + ) |
| +{ |
| +// AssertSz(vfMemInitialized, "MemInitialize() not called, this would normally crash"); |
| + AssertSz(cbSize > 0, "MemReAlloc() called with invalid size"); |
| + return ::HeapReAlloc(::GetProcessHeap(), fZero ? HEAP_ZERO_MEMORY : 0, pv, cbSize); |
| +} |
| + |
| + |
| +extern "C" HRESULT DAPI MemFree( |
| + __in LPVOID pv |
| + ) |
| +{ |
| +// AssertSz(vfMemInitialized, "MemInitialize() not called, this would normally crash"); |
| + return ::HeapFree(::GetProcessHeap(), 0, pv) ? S_OK : HRESULT_FROM_WIN32(::GetLastError()); |
| +} |
| + |
| + |
| +extern "C" SIZE_T DAPI MemSize( |
| + __in LPCVOID pv |
| + ) |
| +{ |
| +// AssertSz(vfMemInitialized, "MemInitialize() not called, this would normally crash"); |
| + return ::HeapSize(::GetProcessHeap(), 0, pv); |
| +} |