diff options
Diffstat (limited to 'src/Platform/Memory.cpp')
-rw-r--r-- | src/Platform/Memory.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/Platform/Memory.cpp b/src/Platform/Memory.cpp index c8c04766..1184d466 100644 --- a/src/Platform/Memory.cpp +++ b/src/Platform/Memory.cpp @@ -13,6 +13,7 @@ #include "Common/Tcdefs.h" #include "Memory.h" #include "Exception.h" +#include <stdlib.h> namespace VeraCrypt { @@ -27,6 +28,23 @@ namespace VeraCrypt return bufPtr; } + + void *Memory::AllocateAligned (std::size_t size, std::size_t alignment) + { + if (size < 1) + throw ParameterIncorrect (SRC_POS); +#ifdef TC_WINDOWS + void *bufPtr = _aligned_malloc (size, alignment); +#else + void *bufPtr = NULL; + if (0 != posix_memalign (&bufPtr, alignment, size)) + bufPtr = NULL; +#endif + if (!bufPtr) + throw bad_alloc(); + + return bufPtr; + } int Memory::Compare (const void *memory1, size_t size1, const void *memory2, size_t size2) { @@ -59,4 +77,14 @@ namespace VeraCrypt assert (memory != nullptr); free (memory); } + + void Memory::FreeAligned (void *memory) + { + assert (memory != nullptr); +#ifdef TC_WINDOWS + _aligned_free (memory); +#else + free (memory); +#endif + } } |