From aee296d663aa9e0cc365d6adc4c2a7b72b122c5f Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 21 Jan 2018 19:48:36 -0500 Subject: [PATCH] Fix AIX AlignedAllocate Well, the IBM docs were not quite correct when they stated "The block is aligned so that it can be used for any type of data". The vector data types are pretty standard, even across different machines from diffent manufacturers --- config.h | 4 +++- misc.cpp | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/config.h b/config.h index bbf76717..23444ea3 100644 --- a/config.h +++ b/config.h @@ -695,7 +695,9 @@ NAMESPACE_END #define CRYPTOPP_MM_MALLOC_AVAILABLE #elif defined(__APPLE__) #define CRYPTOPP_APPLE_MALLOC_AVAILABLE -#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(_AIX) +#elif defined(_AIX) + #define CRYPTOPP_POSIX_MEMALIGN_AVAILABLE +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) #define CRYPTOPP_MALLOC_ALIGNMENT_IS_16 #elif defined(__linux__) || defined(__sun__) || defined(__CYGWIN__) #define CRYPTOPP_MEMALIGN_AVAILABLE diff --git a/misc.cpp b/misc.cpp index f844487e..7ebc20df 100644 --- a/misc.cpp +++ b/misc.cpp @@ -22,6 +22,10 @@ #if defined(CRYPTOPP_MEMALIGN_AVAILABLE) || defined(CRYPTOPP_MM_MALLOC_AVAILABLE) || defined(QNX) # include #endif +// for posix_memalign +#if defined(CRYPTOPP_POSIX_MEMALIGN_AVAILABLE) +# include +#endif NAMESPACE_BEGIN(CryptoPP) @@ -285,6 +289,8 @@ void * AlignedAllocate(size_t size) while ((p = (byte *)malloc(size)) == NULLPTR) #elif defined(CRYPTOPP_MM_MALLOC_AVAILABLE) while ((p = (byte *)_mm_malloc(size, 16)) == NULLPTR) +#elif defined(CRYPTOPP_POSIX_MEMALIGN_AVAILABLE) + while (posix_memalign(reinterpret_cast(&p), 16, size) != 0) #elif defined(CRYPTOPP_MEMALIGN_AVAILABLE) while ((p = (byte *)memalign(16, size)) == NULLPTR) #elif defined(CRYPTOPP_MALLOC_ALIGNMENT_IS_16)