From 993f68752829bf9191fd420a36428daa43a8e5ae Mon Sep 17 00:00:00 2001 From: Aram Date: Sun, 19 Mar 2017 19:55:02 +0100 Subject: [PATCH] Memalign/sysconf fixes for mingw/windows (thanks to @iceman1001) --- crypto1_bs_crack.c | 14 +++++++++++++- solve_piwi.c | 6 +++++- solve_piwi_bs.c | 9 +++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/crypto1_bs_crack.c b/crypto1_bs_crack.c index dee13b7..36a4ea9 100644 --- a/crypto1_bs_crack.c +++ b/crypto1_bs_crack.c @@ -39,7 +39,19 @@ inline uint64_t crack_states_bitsliced(uint32_t **task){ bitslice_t * restrict bitsliced_even_states[(task[4]-task[3])/MAX_BITSLICES]; size_t bitsliced_blocks = 0; for(uint32_t const * restrict p_even = task[3]; p_even < task[4]; p_even+=MAX_BITSLICES){ - bitslice_t * restrict lstate_p = memalign(sizeof(bitslice_t), (STATE_SIZE+ROLLBACK_SIZE)*sizeof(bitslice_t)); +#ifdef __WIN32 + #ifdef __MINGW32__ + bitslice_t * restrict lstate_p = __mingw_aligned_malloc((STATE_SIZE+ROLLBACK_SIZE) * sizeof(bitslice_t), sizeof(bitslice_t)); + #else + bitslice_t * restrict lstate_p = _aligned_malloc((STATE_SIZE+ROLLBACK_SIZE) * sizeof(bitslice_t), sizeof(bitslice_t)); + #endif +#else + #ifdef __APPLE__ + bitslice_t * restrict lstate_p = malloc((STATE_SIZE+ROLLBACK_SIZE) * sizeof(bitslice_t)); + #else + bitslice_t * restrict lstate_p = memalign(sizeof(bitslice_t), (STATE_SIZE+ROLLBACK_SIZE) * sizeof(bitslice_t)); + #endif +#endif memset(lstate_p, 0x0, (STATE_SIZE)*sizeof(bitslice_t)); // bitslice even half-states const size_t max_slices = (task[4]-p_even) < MAX_BITSLICES ? task[4]-p_even : MAX_BITSLICES; diff --git a/solve_piwi.c b/solve_piwi.c index 102cb02..6f3ed2f 100644 --- a/solve_piwi.c +++ b/solve_piwi.c @@ -3,7 +3,9 @@ #include #include #include +#ifndef __WIN32 #include +#endif #include "craptev1.h" #include #define __STDC_FORMAT_MACROS @@ -43,7 +45,7 @@ uint64_t *readnonces(char* fname){ } uint32_t **space; -size_t thread_count; +size_t thread_count = 1; uint64_t states_tested = 0; uint64_t total_states; @@ -71,7 +73,9 @@ int main(int argc, char* argv[]){ space = craptev1_get_space(nonces, 95, uid); total_states = craptev1_sizeof_space(space); +#ifndef __WIN32 thread_count = get_nprocs_conf(); +#endif // append some zeroes to the end of the space to make sure threads don't go off into the wild size_t j = 0; for(j = 0; space[j]; j+=5){ diff --git a/solve_piwi_bs.c b/solve_piwi_bs.c index 920d4d6..ba53ae0 100644 --- a/solve_piwi_bs.c +++ b/solve_piwi_bs.c @@ -4,7 +4,9 @@ #include #include #include +#ifndef __WIN32 #include +#endif #include "craptev1.h" #include "crypto1_bs.h" #include "crypto1_bs_crack.h" @@ -44,7 +46,7 @@ uint64_t *readnonces(char* fname){ } uint32_t **space; -size_t thread_count; +size_t thread_count = 1; void* crack_states_thread(void* x){ const size_t thread_id = (size_t)x; @@ -72,7 +74,10 @@ int main(int argc, char* argv[]){ space = craptev1_get_space(nonces, 95, uid); total_states = craptev1_sizeof_space(space); - thread_count = get_nprocs_conf(); +#ifndef __WIN32 + thread_count = sysconf(_SC_NPROCESSORS_CONF); +#endif /* _WIN32 */ + // append some zeroes to the end of the space to make sure threads don't go off into the wild size_t j = 0; for(j = 0; space[j]; j+=5){