diff options
author | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2010-07-24 05:33:58 +0000 |
---|---|---|
committer | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2010-07-24 05:33:58 +0000 |
commit | 2a1a234dd199a14aa5588a1bbccd88265cbf9ec2 (patch) | |
tree | bd0beb26047039c3cfae1015062ad5841d23ffe2 /misc.cpp | |
parent | d8af7d476f7b49f5a1ff07b2202fc9ad626d83d7 (diff) | |
download | cryptopp-2a1a234dd199a14aa5588a1bbccd88265cbf9ec2.tar.gz |
move memory allocation/deallocation for SecBlock into DLL
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@505 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'misc.cpp')
-rw-r--r-- | misc.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
@@ -125,6 +125,59 @@ void CallNewHandler() throw std::bad_alloc(); } +#if CRYPTOPP_BOOL_ALIGN16_ENABLED + +void * AlignedAllocate(size_t size) +{ + byte *p; +#ifdef CRYPTOPP_MM_MALLOC_AVAILABLE + while (!(p = (byte *)_mm_malloc(size, 16))) +#elif defined(CRYPTOPP_MEMALIGN_AVAILABLE) + while (!(p = (byte *)memalign(16, size))) +#elif defined(CRYPTOPP_MALLOC_ALIGNMENT_IS_16) + while (!(p = (byte *)malloc(size))) +#else + while (!(p = (byte *)malloc(size + 16))) +#endif + CallNewHandler(); + +#ifdef CRYPTOPP_NO_ALIGNED_ALLOC + size_t adjustment = 16-((size_t)p%16); + p += adjustment; + p[-1] = (byte)adjustment; +#endif + + assert(IsAlignedOn(p, 16)); + return p; +} + +void AlignedDeallocate(void *p) +{ +#ifdef CRYPTOPP_MM_MALLOC_AVAILABLE + _mm_free(p); +#elif defined(CRYPTOPP_NO_ALIGNED_ALLOC) + p = (byte *)p - ((byte *)p)[-1]; + free(p); +#else + free(p); +#endif +} + +#endif + +void * UnalignedAllocate(size_t size) +{ + void *p; + while (!(p = malloc(size))) + CallNewHandler(); + return p; +} + +void UnalignedDeallocate(void *p) +{ + free(p); +} + NAMESPACE_END #endif |