From c3d117a8a1140af91b1c9cc245ec6cf2c26df391 Mon Sep 17 00:00:00 2001 From: pwpiwi Date: Thu, 8 Jun 2017 08:08:30 +0200 Subject: [PATCH] fix MacOS compile errors by replacing memalign() with posix_memalign() --- client/hardnested/hardnested_bf_core.c | 16 ++++++++++++++-- client/hardnested/hardnested_bitarray_core.c | 11 ++++++++++- client/hardnested/hardnested_bruteforce.c | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/client/hardnested/hardnested_bf_core.c b/client/hardnested/hardnested_bf_core.c index c22a9a08..05246296 100644 --- a/client/hardnested/hardnested_bf_core.c +++ b/client/hardnested/hardnested_bf_core.c @@ -52,8 +52,10 @@ THE SOFTWARE. #include #include #include -#include +#ifndef __APPLE__ #include +#endif +#include #include #include "crapto1/crapto1.h" #include "parity.h" @@ -141,9 +143,19 @@ bitslice_test_nonces_t bitslice_test_nonces_MMX; bitslice_test_nonces_t bitslice_test_nonces_NOSIMD; bitslice_test_nonces_t bitslice_test_nonces_dispatch; -#ifdef _WIN32 +#if defined (_WIN32) #define malloc_bitslice(x) __builtin_assume_aligned(_aligned_malloc((x), MAX_BITSLICES/8), MAX_BITSLICES/8) #define free_bitslice(x) _aligned_free(x) +#elif defined (__APPLE__) +static void *malloc_bitslice(size_t x) { + char *allocated_memory; + if (posix_memalign((void**)&allocated_memory, MAX_BITSLICES/8, x)) { + return NULL; + } else { + return __builtin_assume_aligned(allocated_memory, MAX_BITSLICES/8); + } +} +#define free_bitslice(x) free(x) #else #define malloc_bitslice(x) memalign(MAX_BITSLICES/8, (x)) #define free_bitslice(x) free(x) diff --git a/client/hardnested/hardnested_bitarray_core.c b/client/hardnested/hardnested_bitarray_core.c index 5b48a735..320c4a96 100644 --- a/client/hardnested/hardnested_bitarray_core.c +++ b/client/hardnested/hardnested_bitarray_core.c @@ -21,7 +21,9 @@ #include #include #include +#ifndef __APPLE__ #include +#endif // this needs to be compiled several times for each instruction set. // For each instruction set, define a dedicated function name: @@ -143,8 +145,15 @@ count_bitarray_AND4_t count_bitarray_AND4_AVX512, count_bitarray_AND4_AVX2, coun inline uint32_t *MALLOC_BITARRAY(uint32_t x) { -#ifdef _WIN32 +#if defined (_WIN32) return __builtin_assume_aligned(_aligned_malloc((x), __BIGGEST_ALIGNMENT__), __BIGGEST_ALIGNMENT__); +#elif defined (__APPLE__) + uint32_t *allocated_memory; + if (posix_memalign((void**)&allocated_memory, __BIGGEST_ALIGNMENT__, x)) { + return NULL; + } else { + return __builtin_assume_aligned(allocated_memory, __BIGGEST_ALIGNMENT__); + } #else return __builtin_assume_aligned(memalign(__BIGGEST_ALIGNMENT__, (x)), __BIGGEST_ALIGNMENT__); #endif diff --git a/client/hardnested/hardnested_bruteforce.c b/client/hardnested/hardnested_bruteforce.c index 3b1c5071..718b7c5d 100644 --- a/client/hardnested/hardnested_bruteforce.c +++ b/client/hardnested/hardnested_bruteforce.c @@ -54,7 +54,7 @@ THE SOFTWARE. #include #include #include -#include +#include #include "proxmark3.h" #include "cmdhfmfhard.h" #include "hardnested_bf_core.h" -- 2.39.2