summaryrefslogtreecommitdiff
path: root/misc.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2019-09-28 18:22:11 -0400
committerJeffrey Walton <noloader@gmail.com>2019-09-28 18:22:11 -0400
commit1190da17eaae1874610a27cb2303cb91d6da20dc (patch)
treedc691f2566530dc153e1875c4dd0b3b3f257905d /misc.cpp
parent5be96f92f2b0078eb764f40f4cdd16f1ccbcbcf9 (diff)
downloadcryptopp-git-1190da17eaae1874610a27cb2303cb91d6da20dc.tar.gz
Avoid circular dependency using AlignedAllocate (GH #885)
Diffstat (limited to 'misc.cpp')
-rw-r--r--misc.cpp80
1 files changed, 1 insertions, 79 deletions
diff --git a/misc.cpp b/misc.cpp
index 91f1d8d0..2b68afcb 100644
--- a/misc.cpp
+++ b/misc.cpp
@@ -13,20 +13,11 @@
#ifndef CRYPTOPP_IMPORTS
#include "misc.h"
-#include "words.h"
+#include "trap.h"
#include "words.h"
#include "stdcpp.h"
#include "integer.h"
-// for memalign
-#if defined(CRYPTOPP_MEMALIGN_AVAILABLE) || defined(CRYPTOPP_MM_MALLOC_AVAILABLE) || defined(QNX)
-# include <malloc.h>
-#endif
-// for posix_memalign
-#if defined(CRYPTOPP_POSIX_MEMALIGN_AVAILABLE)
-# include <stdlib.h>
-#endif
-
NAMESPACE_BEGIN(CryptoPP)
void xorbuf(byte *buf, const byte *mask, size_t count)
@@ -265,75 +256,6 @@ std::wstring StringWiden(const char *str, bool throwOnError)
return result;
}
-void CallNewHandler()
-{
- using std::new_handler;
- using std::set_new_handler;
-
- new_handler newHandler = set_new_handler(NULLPTR);
- if (newHandler)
- set_new_handler(newHandler);
-
- if (newHandler)
- newHandler();
- else
- throw std::bad_alloc();
-}
-
-void * AlignedAllocate(size_t size)
-{
- byte *p;
-#if defined(CRYPTOPP_MM_MALLOC_AVAILABLE)
- while ((p = (byte *)_mm_malloc(size, 16)) == NULLPTR)
-#elif defined(CRYPTOPP_MEMALIGN_AVAILABLE)
- while ((p = (byte *)memalign(16, size)) == NULLPTR)
-#elif defined(CRYPTOPP_MALLOC_ALIGNMENT_IS_16)
- while ((p = (byte *)malloc(size)) == NULLPTR)
-#elif defined(CRYPTOPP_POSIX_MEMALIGN_AVAILABLE)
- while (posix_memalign(reinterpret_cast<void**>(&p), 16, size) != 0)
-#else
- while ((p = (byte *)malloc(size + 16)) == NULLPTR)
-#endif
- CallNewHandler();
-
-#ifdef CRYPTOPP_NO_ALIGNED_ALLOC
- size_t adjustment = 16-((size_t)p%16);
- CRYPTOPP_ASSERT(adjustment > 0);
- p += adjustment;
- p[-1] = (byte)adjustment;
-#endif
-
- // If this assert fires then there are problems that need
- // to be fixed. Please open a bug report.
- CRYPTOPP_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
-}
-
-void * UnalignedAllocate(size_t size)
-{
- void *p;
- while ((p = malloc(size)) == NULLPTR)
- CallNewHandler();
- return p;
-}
-
-void UnalignedDeallocate(void *p)
-{
- free(p);
-}
-
NAMESPACE_END
#endif