From 983d8beac7c35bae68a142fbad41946930cdc16d Mon Sep 17 00:00:00 2001 From: Massimo Del Zotto Date: Wed, 15 Nov 2017 10:01:48 +0100 Subject: [PATCH 01/12] Upgrade to VS2017 and recent Win SDK --- .gitignore | 1 + winbuild/jansson/jansson.vcxproj | 11 ++++++----- winbuild/sgminer.vcxproj | 13 ++++++++----- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index ce23abd80..65cec604b 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,4 @@ lib/warn-on-use.h mkinstalldirs *.swp +winbuild/.vs/sgminer/ diff --git a/winbuild/jansson/jansson.vcxproj b/winbuild/jansson/jansson.vcxproj index 9807ac15b..c68ab7fa8 100644 --- a/winbuild/jansson/jansson.vcxproj +++ b/winbuild/jansson/jansson.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -21,33 +21,34 @@ {AFE7D2AA-025C-4837-B4B2-81117E010B3B} jansson + 10.0.16299.0 StaticLibrary true MultiByte - v120 + v141 StaticLibrary true MultiByte - v120 + v141 StaticLibrary false true MultiByte - v120 + v141 StaticLibrary false true MultiByte - v120 + v141 diff --git a/winbuild/sgminer.vcxproj b/winbuild/sgminer.vcxproj index 67679bb1d..f9c247193 100644 --- a/winbuild/sgminer.vcxproj +++ b/winbuild/sgminer.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -22,33 +22,34 @@ {CCA64DCD-6401-42A3-ABC3-89E48A36D239} Win32Proj sgminer + 10.0.16299.0 Application true MultiByte - v120 + v141 Application true MultiByte - v120 + v141 Application false true MultiByte - v120 + v141 Application false true MultiByte - v120 + v141 @@ -70,6 +71,8 @@ false $(SolutionDir)output\x86\$(Configuration)\ $(SolutionDir)output\x86\obj\ + $(VC_IncludePath);$(WindowsSDK_IncludePath);$(AMDAPPSDKROOT)\include; + $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86;$(AMDAPPSDKROOT)\lib\x86; false From 4431ed32789a891b35a1e1cf1e6d7919160584bd Mon Sep 17 00:00:00 2001 From: Massimo Del Zotto Date: Wed, 15 Nov 2017 10:46:10 +0100 Subject: [PATCH 02/12] cURL was really supposed to be an optional dependancy. But over the years stuff was put in the wrong place. Pull those out of the cURL dependancies. Also, you cannot reap cURLs if they're not there. --- miner.h | 3 +++ sgminer.c | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/miner.h b/miner.h index 0b0bceee8..8320aa255 100644 --- a/miner.h +++ b/miner.h @@ -19,6 +19,7 @@ extern char *curly; #define curl_global_cleanup() {} #define CURL_GLOBAL_ALL 0 #define curl_global_init(X) (0) +#define CURL_ERROR_SIZE 1 #endif #include @@ -1301,12 +1302,14 @@ typedef struct _dev_blk_ctx { struct work *work; } dev_blk_ctx; +#ifdef HAVE_LIBCURL struct curl_ent { CURL *curl; char curl_err_str[CURL_ERROR_SIZE]; struct list_head node; struct timeval tv; }; +#endif /* The lowest enum of a freshly calloced value is the default */ enum pool_state { diff --git a/sgminer.c b/sgminer.c index 8a79d8bf7..dc9d9ceae 100644 --- a/sgminer.c +++ b/sgminer.c @@ -2063,6 +2063,7 @@ static void update_gbt(struct pool *pool) } curl_easy_cleanup(curl); } +#endif /* Return the work coin/network difficulty */ static double get_work_blockdiff(const struct work *work) @@ -2103,6 +2104,7 @@ static double get_work_blockdiff(const struct work *work) return numerator / (double)diff64; } +#ifdef HAVE_LIBCURL static void gen_gbt_work(struct pool *pool, struct work *work) { unsigned char *merkleroot; @@ -3700,6 +3702,7 @@ static inline bool can_roll(struct work *work) return (!work->stratum && work->pool && work->rolltime && !work->clone && work->rolls < 7000 && !stale_work(work, false)); } +#endif static uint32_t _get_work_time(struct work *work) { @@ -3721,6 +3724,7 @@ static void _set_work_time(struct work *work, uint32_t ntime) (*work_ntime) = ntime; } +#ifdef HAVE_LIBCURL static void roll_work(struct work *work) { uint32_t work_ntime; @@ -7735,6 +7739,7 @@ static struct timeval rotate_tv; /* We reap curls if they are unused for over a minute */ static void reap_curl(struct pool *pool) { +#ifdef HAVE_LIBCURL struct curl_ent *ent, *iter; struct timeval now; int reaped = 0; @@ -7757,6 +7762,7 @@ static void reap_curl(struct pool *pool) if (reaped) applog(LOG_DEBUG, "Reaped %d curl%s from %s", reaped, reaped > 1 ? "s" : "", get_pool_name(pool)); +#endif } static void *watchpool_thread(void __maybe_unused *userdata) From db39e4f05e6b331c4e0269f4d3b50d805112b1d4 Mon Sep 17 00:00:00 2001 From: Massimo Del Zotto Date: Wed, 15 Nov 2017 10:46:51 +0100 Subject: [PATCH 03/12] Since VS2015 time.h defines timespec. Hurrah! It was about time. --- winbuild/dist/include/config.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/winbuild/dist/include/config.h b/winbuild/dist/include/config.h index 869317088..b03a14eb0 100644 --- a/winbuild/dist/include/config.h +++ b/winbuild/dist/include/config.h @@ -13,6 +13,10 @@ #define STDC_HEADERS 1 #define EXECV_2ND_ARG_TYPE char* const* +#if defined(_MSC_VER) && _MSC_VER > 1500 // visual studio 2015 and later has timespec in time.h +#define HAVE_STRUCT_TIMESPEC 1 +#endif + #define HAVE_ALLOCA 1 #define HAVE_ATTRIBUTE_COLD 1 #define HAVE_ATTRIBUTE_CONST 1 From 18bed148823e67543fb1767d864d6efa5b0bfca9 Mon Sep 17 00:00:00 2001 From: Massimo Del Zotto Date: Wed, 15 Nov 2017 10:54:48 +0100 Subject: [PATCH 04/12] Help the tokenizer. For some reason sgminer is compiled as c++ app in VS. Now, VS2017 supports user defined literals but it cannot figure out of something is a literal or a macro to be expanded so help its parsers. There's nothing really wrong with spaces every once in a while btw. --- api.c | 6 +++--- sgminer.c | 4 ++-- util.c | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/api.c b/api.c index 1efa30045..3ecf8a542 100644 --- a/api.c +++ b/api.c @@ -766,13 +766,13 @@ struct api_data *print_data(struct api_data *root, char *buf, bool isjson, bool sprintf(buf, "%u", *((unsigned int *)(root->data))); break; case API_UINT32: - sprintf(buf, "%"PRIu32, *((uint32_t *)(root->data))); + sprintf(buf, "%" PRIu32, *((uint32_t *)(root->data))); break; case API_HEX32: snprintf(buf, sizeof(buf), "0x%08x", *((uint32_t *)(root->data))); break; case API_UINT64: - sprintf(buf, "%"PRIu64, *((uint64_t *)(root->data))); + sprintf(buf, "%" PRIu64, *((uint64_t *)(root->data))); break; case API_TIME: sprintf(buf, "%lu", *((unsigned long *)(root->data))); @@ -808,7 +808,7 @@ struct api_data *print_data(struct api_data *root, char *buf, bool isjson, bool sprintf(buf, "%s", *((bool *)(root->data)) ? TRUESTR : FALSESTR); break; case API_TIMEVAL: - sprintf(buf, "%"PRIu64".%06lu", + sprintf(buf, "%" PRIu64 ".%06lu", (uint64_t)((struct timeval *)(root->data))->tv_sec, (unsigned long)((struct timeval *)(root->data))->tv_usec); break; diff --git a/sgminer.c b/sgminer.c index dc9d9ceae..0824ceeca 100644 --- a/sgminer.c +++ b/sgminer.c @@ -5145,7 +5145,7 @@ static void hashmeter(int thr_id, struct timeval *diff, double thread_rolling = 0.0; int i; - applog(LOG_DEBUG, "[thread %d: %"PRIu64" hashes, %.1f khash/sec]", + applog(LOG_DEBUG, "[thread %d: %" PRIu64 " hashes, %.1f khash/sec]", thr_id, hashes_done, hashes_done / 1000 / secs); /* Rolling average for each thread and each device */ @@ -6251,7 +6251,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work) free(merkle_hash); } applog(LOG_DEBUG, "[THR%d] Generated stratum header %s", work->thr_id, header); - applog(LOG_DEBUG, "[THR%d] Work job_id %s nonce2 %"PRIu64" ntime %s", work->thr_id, work->job_id, + applog(LOG_DEBUG, "[THR%d] Work job_id %s nonce2 %" PRIu64 " ntime %s", work->thr_id, work->job_id, work->nonce2, work->ntime); free(header); } diff --git a/util.c b/util.c index c525b3d29..6fb898307 100644 --- a/util.c +++ b/util.c @@ -1795,7 +1795,7 @@ static bool send_version(struct pool *pool, json_t *val) if (!id) return false; - sprintf(s, "{\"id\": %d, \"result\": \""PACKAGE"/"CGMINER_VERSION"\", \"error\": null}", id); + sprintf(s, "{\"id\": %d, \"result\": \"" PACKAGE "/" CGMINER_VERSION "\", \"error\": null}", id); if (!stratum_send(pool, s, strlen(s))) return false; @@ -2484,9 +2484,9 @@ bool initiate_stratum(struct pool *pool) sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": []}", swork_id++); } else { if (pool->sessionid) - sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\""PACKAGE"/"CGMINER_VERSION"\", \"%s\"]}", swork_id++, pool->sessionid); + sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\"" PACKAGE "/" CGMINER_VERSION "\", \"%s\"]}", swork_id++, pool->sessionid); else - sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\""PACKAGE"/"CGMINER_VERSION"\"]}", swork_id++); + sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": [\"" PACKAGE "/" CGMINER_VERSION "\"]}", swork_id++); } if (__stratum_send(pool, s, strlen(s)) != SEND_OK) { From 942f0824964e7a74c06405f0a32c580617878ad6 Mon Sep 17 00:00:00 2001 From: Massimo Del Zotto Date: Wed, 15 Nov 2017 11:08:56 +0100 Subject: [PATCH 05/12] Need to include config before pthread. It would be best to pass all the config as command line params but hey.. --- findnonce.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/findnonce.c b/findnonce.c index 4e80dac17..c365df9fb 100644 --- a/findnonce.c +++ b/findnonce.c @@ -8,6 +8,8 @@ * any later version. See COPYING for more details. */ +#include "config.h" // you always need this before pthread.h or it'll try to re-define struct timespec + #include #include #include From 5fce3502f6c15884836b85a1b3ee05fd9fa73c83 Mon Sep 17 00:00:00 2001 From: Massimo Del Zotto Date: Wed, 15 Nov 2017 11:51:52 +0100 Subject: [PATCH 06/12] Dependancies in visual studio are not handled this way. They are handled through references. Upgrade jansson to use right snprintf --- winbuild/dist/include/config.h | 1 - winbuild/jansson/jansson.vcxproj | 2 +- winbuild/sgminer.vcxproj | 5 +++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/winbuild/dist/include/config.h b/winbuild/dist/include/config.h index b03a14eb0..173db5432 100644 --- a/winbuild/dist/include/config.h +++ b/winbuild/dist/include/config.h @@ -58,7 +58,6 @@ #pragma comment(lib, "wsock32.lib") #pragma comment(lib, "pthreadVC2.lib") #pragma comment(lib, "OpenCL.lib") -#pragma comment(lib, "jansson.lib") #ifdef HAVE_LIBCURL #define CURL_STATICLIB 1 diff --git a/winbuild/jansson/jansson.vcxproj b/winbuild/jansson/jansson.vcxproj index c68ab7fa8..ba4bca9fa 100644 --- a/winbuild/jansson/jansson.vcxproj +++ b/winbuild/jansson/jansson.vcxproj @@ -91,7 +91,7 @@ Level3 Disabled ProgramDatabase - WIN32;_WINDOWS;_DEBUG;_CRT_SECURE_NO_WARNINGS;JANSSON_USING_CMAKE;HAVE_CONFIG_H;%(PreprocessorDefinitions) + WIN32;_WINDOWS;_DEBUG;_CRT_SECURE_NO_WARNINGS;JANSSON_USING_CMAKE;HAVE_CONFIG_H;%(PreprocessorDefinitions);HAVE_SNPRINTF CompileAsC 4005;4996 $(ProjectDir);%(AdditionalIncludeDirectories) diff --git a/winbuild/sgminer.vcxproj b/winbuild/sgminer.vcxproj index f9c247193..e080fdbd0 100644 --- a/winbuild/sgminer.vcxproj +++ b/winbuild/sgminer.vcxproj @@ -402,6 +402,11 @@ + + + {afe7d2aa-025c-4837-b4b2-81117e010b3b} + + From 4817eaf08f081e154864e924eecbcd6ddfd99e3e Mon Sep 17 00:00:00 2001 From: Massimo Del Zotto Date: Wed, 15 Nov 2017 12:11:09 +0100 Subject: [PATCH 07/12] Maintainance: import files which were missing, causing link fail. --- winbuild/sgminer.vcxproj | 16 +++++++++++ winbuild/sgminer.vcxproj.filters | 48 ++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/winbuild/sgminer.vcxproj b/winbuild/sgminer.vcxproj index e080fdbd0..5b88730ee 100644 --- a/winbuild/sgminer.vcxproj +++ b/winbuild/sgminer.vcxproj @@ -266,18 +266,26 @@ + + + + + + + + @@ -333,12 +341,19 @@ + + + + + + + @@ -346,6 +361,7 @@ + diff --git a/winbuild/sgminer.vcxproj.filters b/winbuild/sgminer.vcxproj.filters index 7866e29d6..bcb574bca 100644 --- a/winbuild/sgminer.vcxproj.filters +++ b/winbuild/sgminer.vcxproj.filters @@ -224,6 +224,30 @@ Source Files\algorithm + + Source Files\algorithm + + + Source Files\algorithm + + + Source Files\algorithm + + + Source Files\algorithm + + + Source Files\algorithm + + + Source Files\algorithm + + + Source Files\algorithm + + + Source Files\algorithm + @@ -433,6 +457,30 @@ Header Files\algorithm + + Header Files\algorithm + + + Header Files\algorithm + + + Header Files\algorithm + + + Header Files\algorithm + + + Header Files\algorithm + + + Header Files\algorithm + + + Header Files\algorithm + + + Header Files\algorithm + From f7dfb8109a0c8d561854329aaa35fbe9caf6ed1f Mon Sep 17 00:00:00 2001 From: Massimo Del Zotto Date: Wed, 15 Nov 2017 12:11:40 +0100 Subject: [PATCH 08/12] getaddrinfo dependancy from ws2_32.lib --- winbuild/sgminer.vcxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winbuild/sgminer.vcxproj b/winbuild/sgminer.vcxproj index 5b88730ee..776339676 100644 --- a/winbuild/sgminer.vcxproj +++ b/winbuild/sgminer.vcxproj @@ -109,7 +109,7 @@ Console true $(ProjectDir)dist\lib\x86;$(ProjectDir)jansson\Debug\x86 - %(AdditionalDependencies) + %(AdditionalDependencies);Ws2_32.lib false true From 328838e80ad1448deb3fae833098342248426650 Mon Sep 17 00:00:00 2001 From: Massimo Del Zotto Date: Wed, 15 Nov 2017 13:19:49 +0100 Subject: [PATCH 09/12] Yescrypt requires some care. Mostly typesafe casts for enums. Also pull in VS2015 TLS. --- algorithm/yescrypt-opt.c | 24 ++++++++++++------------ algorithm/yescryptcommon.c | 24 +++++++++++++++--------- winbuild/sgminer.vcxproj | 3 +++ winbuild/sgminer.vcxproj.filters | 9 +++++++++ 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/algorithm/yescrypt-opt.c b/algorithm/yescrypt-opt.c index 6adef7e74..8d623c3dc 100644 --- a/algorithm/yescrypt-opt.c +++ b/algorithm/yescrypt-opt.c @@ -159,7 +159,7 @@ uint8_t * buf, size_t buflen) dummy.mask1 = 1; if (yescrypt_kdf(&dummy, shared1, param, paramlen, NULL, 0, N, r, p, 0, - YESCRYPT_RW | YESCRYPT_PARALLEL_SMIX | __YESCRYPT_INIT_SHARED_1, + (yescrypt_flags_t)(YESCRYPT_RW | YESCRYPT_PARALLEL_SMIX | __YESCRYPT_INIT_SHARED_1), salt, sizeof(salt))) goto out; @@ -172,19 +172,19 @@ uint8_t * buf, size_t buflen) if (p > 1 && yescrypt_kdf(&half1, &half2.shared1, param, paramlen, salt, sizeof(salt), N, r, p, 0, - YESCRYPT_RW | YESCRYPT_PARALLEL_SMIX | __YESCRYPT_INIT_SHARED_2, + (yescrypt_flags_t)(YESCRYPT_RW | YESCRYPT_PARALLEL_SMIX | __YESCRYPT_INIT_SHARED_2), salt, sizeof(salt))) goto out; if (yescrypt_kdf(&half2, &half1.shared1, param, paramlen, salt, sizeof(salt), N, r, p, 0, - YESCRYPT_RW | YESCRYPT_PARALLEL_SMIX | __YESCRYPT_INIT_SHARED_1, + (yescrypt_flags_t)(YESCRYPT_RW | YESCRYPT_PARALLEL_SMIX | __YESCRYPT_INIT_SHARED_1), salt, sizeof(salt))) goto out; if (yescrypt_kdf(&half1, &half2.shared1, param, paramlen, salt, sizeof(salt), N, r, p, 0, - YESCRYPT_RW | YESCRYPT_PARALLEL_SMIX | __YESCRYPT_INIT_SHARED_1, + (yescrypt_flags_t)(YESCRYPT_RW | YESCRYPT_PARALLEL_SMIX | __YESCRYPT_INIT_SHARED_1), buf, buflen)) goto out; @@ -600,7 +600,7 @@ smix1(uint64_t * B, size_t r, uint64_t N, yescrypt_flags_t flags, blockmix(Y, X, Z, r); } } else { - yescrypt_flags_t rw = flags & YESCRYPT_RW; + yescrypt_flags_t rw = (yescrypt_flags_t)(flags & YESCRYPT_RW); /* 4: X <-- H(X) */ blockmix(Y, X, Z, r); @@ -674,7 +674,7 @@ smix2(uint64_t * B, size_t r, uint64_t N, uint64_t Nloop, const uint64_t * VROM = (uint64_t *)shared->shared1.aligned; uint32_t VROM_mask = shared->mask1 | 1; size_t s = 16 * r; - yescrypt_flags_t rw = flags & YESCRYPT_RW; + yescrypt_flags_t rw = (yescrypt_flags_t)(flags & YESCRYPT_RW); uint64_t * X = XY; uint64_t * Y = &XY[s]; uint64_t * Z = S ? S : &XY[2 * s]; @@ -835,7 +835,7 @@ smix(uint64_t * B, size_t r, uint64_t N, uint32_t p, uint32_t t, uint64_t * Sp = S ? &S[i * S_SIZE_ALL] : S; if (Sp) - smix1(Bp, 1, S_SIZE_ALL / 16, (yescrypt_flags_t)flags & ~YESCRYPT_PWXFORM,Sp, NROM, shared, XYp, NULL); + smix1(Bp, 1, S_SIZE_ALL / 16, (yescrypt_flags_t)(flags & ~YESCRYPT_PWXFORM),Sp, NROM, shared, XYp, NULL); @@ -856,7 +856,7 @@ smix(uint64_t * B, size_t r, uint64_t N, uint32_t p, uint32_t t, uint64_t * XYp = XY; uint64_t * Sp = S ? &S[i * S_SIZE_ALL] : S; - smix2(Bp, r, N, Nloop_all - Nloop_rw,flags & ~YESCRYPT_RW, V, NROM, shared, XYp, Sp); + smix2(Bp, r, N, Nloop_all - Nloop_rw,(yescrypt_flags_t)(flags & ~YESCRYPT_RW), V, NROM, shared, XYp, Sp); } } @@ -914,7 +914,7 @@ uint64_t * XY, uint64_t * S) uint64_t * Sp = S ? &S[i * S_SIZE_ALL] : S; if (Sp) { - smix1(Bp, 1, S_SIZE_ALL / 16, flags & ~YESCRYPT_PWXFORM, Sp, NROM, shared, XYp, NULL); + smix1(Bp, 1, S_SIZE_ALL / 16, (yescrypt_flags_t)(flags & ~YESCRYPT_PWXFORM), Sp, NROM, shared, XYp, NULL); } @@ -934,7 +934,7 @@ uint64_t * XY, uint64_t * S) uint64_t * XYp = XY; uint64_t * Sp = S ? &S[i * S_SIZE_ALL] : S; - smix2(Bp, r, N, Nloop_all - Nloop_rw, flags & ~YESCRYPT_RW, V, NROM, shared, XYp, Sp); + smix2(Bp, r, N, Nloop_all - Nloop_rw, (yescrypt_flags_t)(flags & ~YESCRYPT_RW), V, NROM, shared, XYp, Sp); } } } @@ -975,7 +975,7 @@ yescrypt_kdf(const yescrypt_shared_t * shared, yescrypt_local_t * local, * because any deviation from classic scrypt implies those. */ if (p == 1) - flags &= ~YESCRYPT_PARALLEL_SMIX; + flags = (yescrypt_flags_t)(flags & ~YESCRYPT_PARALLEL_SMIX); /* Sanity-check parameters */ if (flags & ~YESCRYPT_KNOWN_FLAGS) { @@ -1181,7 +1181,7 @@ uint8_t * buf, size_t buflen) * because any deviation from classic scrypt implies those. */ if (p == 1) - flags &= ~YESCRYPT_PARALLEL_SMIX; + flags = (yescrypt_flags_t)(flags & ~YESCRYPT_PARALLEL_SMIX); /* Sanity-check parameters */ if (flags & ~YESCRYPT_KNOWN_FLAGS) { diff --git a/algorithm/yescryptcommon.c b/algorithm/yescryptcommon.c index cf7067d02..215db6933 100644 --- a/algorithm/yescryptcommon.c +++ b/algorithm/yescryptcommon.c @@ -150,7 +150,7 @@ yescrypt_r(const yescrypt_shared_t * shared, yescrypt_local_t * local, fflush(stdout); return NULL; } - flags = decoded_flags; + flags = (yescrypt_flags_t)decoded_flags; if (*++src != '$') { fflush(stdout); @@ -263,7 +263,7 @@ yescrypt_gensalt_r(uint32_t N_log2, uint32_t r, uint32_t p, size_t need; if (p == 1) - flags &= ~YESCRYPT_PARALLEL_SMIX; + flags = (yescrypt_flags_t)(flags & ~YESCRYPT_PARALLEL_SMIX); if (flags) { if (flags & ~0x3f) @@ -320,19 +320,21 @@ yescrypt_gensalt(uint32_t N_log2, uint32_t r, uint32_t p, buf, sizeof(buf)); } + +#if defined(_MSC_VER) && _MSC_VER > 1500 +#define __thread __declspec( thread ) +#endif + + static int yescrypt_bsty(const uint8_t * passwd, size_t passwdlen, - const uint8_t * salt, size_t saltlen, uint64_t N, uint32_t r, uint32_t p, - uint8_t * buf, size_t buflen) + const uint8_t * salt, size_t saltlen, uint64_t N, uint32_t r, uint32_t p, + uint8_t * buf, size_t buflen) { static __thread int initialized = 0; static __thread yescrypt_shared_t shared; static __thread yescrypt_local_t local; -// static __declspec(thread) int initialized = 0; -// static __declspec(thread) yescrypt_shared_t shared; -// static __declspec(thread) yescrypt_local_t local; - int retval; if (!initialized) { /* "shared" could in fact be shared, but it's simpler to keep it private @@ -347,12 +349,16 @@ yescrypt_bsty(const uint8_t * passwd, size_t passwdlen, initialized = 1; } retval = yescrypt_kdf(&shared, &local, - passwd, passwdlen, salt, saltlen, N, r, p, 0, YESCRYPT_FLAGS, + passwd, passwdlen, salt, saltlen, N, r, p, 0, (yescrypt_flags_t)YESCRYPT_FLAGS, buf, buflen); return retval; } +#if defined(_MSC_VER) && _MSC_VER > 1500 +#undef __thread +#endif + void yescrypt_hash(const unsigned char *input, unsigned char *output) { diff --git a/winbuild/sgminer.vcxproj b/winbuild/sgminer.vcxproj index 776339676..23531c5a9 100644 --- a/winbuild/sgminer.vcxproj +++ b/winbuild/sgminer.vcxproj @@ -285,7 +285,9 @@ + + @@ -362,6 +364,7 @@ + diff --git a/winbuild/sgminer.vcxproj.filters b/winbuild/sgminer.vcxproj.filters index bcb574bca..fcd1ab8af 100644 --- a/winbuild/sgminer.vcxproj.filters +++ b/winbuild/sgminer.vcxproj.filters @@ -248,6 +248,12 @@ Source Files\algorithm + + Source Files\algorithm + + + Source Files\algorithm + @@ -481,6 +487,9 @@ Header Files\algorithm + + Header Files + From 45ae9beb5564a61cb084f2fb9628ec94734ef204 Mon Sep 17 00:00:00 2001 From: Massimo Del Zotto Date: Wed, 15 Nov 2017 14:56:44 +0100 Subject: [PATCH 10/12] Solve other missing links and add safe casts. --- sph/gost.c | 12 ++++++------ sph/ripemd.c | 6 +++--- sph/sha256_Y.c | 4 ++-- winbuild/sgminer.vcxproj | 3 +++ winbuild/sgminer.vcxproj.filters | 9 +++++++++ 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/sph/gost.c b/sph/gost.c index f46aeb583..2cb92d6b5 100644 --- a/sph/gost.c +++ b/sph/gost.c @@ -667,8 +667,8 @@ const unsigned char C[12][64] = { void AddModulo512(const void *a,const void *b,void *c) { - const unsigned char *A=a, *B=b; - unsigned char *C=c; + const unsigned char *A=(const unsigned char*)a, *B=(const unsigned char*)b; + unsigned char *C=(unsigned char*)c; int t = 0; #ifdef FULL_UNROLL #define ADDBYTE_8(i) t = A[i] + B[i] + (t >> 8); C[i] = t & 0xFF; @@ -751,8 +751,8 @@ void AddModulo512(const void *a,const void *b,void *c) void AddXor512(const void *a,const void *b,void *c) { - const unsigned long long *A=a, *B=b; - unsigned long long *C=c; + const unsigned long long *A=(const unsigned long long*)a, *B=(const unsigned long long*)b; + unsigned long long *C=(unsigned long long*)c; #ifdef FULL_UNROLL C[0] = A[0] ^ B[0]; C[1] = A[1] ^ B[1]; @@ -1051,7 +1051,7 @@ sph_gost256_init(void *cc) void sph_gost256(void *cc, const void *data, size_t len) { - hash_256(data, 8*len, cc); + hash_256((const unsigned char*)data, 8*len, (unsigned char*)cc); } /* see sph_gost.h */ @@ -1080,7 +1080,7 @@ sph_gost512_init(void *cc) void sph_gost512(void *cc, const void *data, size_t len) { - hash_512(data, 8*len, cc); + hash_512((const unsigned char*)data, 8*len, (unsigned char*)cc); } /* see sph_gost.h */ diff --git a/sph/ripemd.c b/sph/ripemd.c index e242ac254..53da30c24 100644 --- a/sph/ripemd.c +++ b/sph/ripemd.c @@ -251,7 +251,7 @@ sph_ripemd_init(void *cc) { sph_ripemd_context *sc; - sc = cc; + sc = (sph_ripemd_context*)cc; memcpy(sc->val, oIV, sizeof sc->val); #if SPH_64 sc->count = 0; @@ -505,7 +505,7 @@ sph_ripemd128_init(void *cc) { sph_ripemd128_context *sc; - sc = cc; + sc = (sph_ripemd128_context*)cc; memcpy(sc->val, IV, sizeof sc->val); #if SPH_64 sc->count = 0; @@ -798,7 +798,7 @@ sph_ripemd160_init(void *cc) { sph_ripemd160_context *sc; - sc = cc; + sc = (sph_ripemd160_context*)cc; memcpy(sc->val, IV, sizeof sc->val); #if SPH_64 sc->count = 0; diff --git a/sph/sha256_Y.c b/sph/sha256_Y.c index 6a2dac456..b4289f51b 100644 --- a/sph/sha256_Y.c +++ b/sph/sha256_Y.c @@ -236,7 +236,7 @@ SHA256_Update_Y(SHA256_CTX_Y * ctx, const void *in, size_t len) { uint32_t bitlen[2]; uint32_t r; - const unsigned char *src = in; + const unsigned char *src = (const unsigned char*)in; /* Number of bytes left in the buffer from previous updates */ r = (ctx->count[1] >> 3) & 0x3f; @@ -299,7 +299,7 @@ HMAC_SHA256_Init_Y(HMAC_SHA256_CTX_Y * ctx, const void * _K, size_t Klen) { unsigned char pad[64]; unsigned char khash[32]; - const unsigned char * K = _K; + const unsigned char * K = (const unsigned char*)_K; size_t i; /* If Klen > 64, the key is really SHA256(K). */ diff --git a/winbuild/sgminer.vcxproj b/winbuild/sgminer.vcxproj index 23531c5a9..443bba133 100644 --- a/winbuild/sgminer.vcxproj +++ b/winbuild/sgminer.vcxproj @@ -321,6 +321,7 @@ + @@ -328,7 +329,9 @@ + + diff --git a/winbuild/sgminer.vcxproj.filters b/winbuild/sgminer.vcxproj.filters index fcd1ab8af..fdc08622b 100644 --- a/winbuild/sgminer.vcxproj.filters +++ b/winbuild/sgminer.vcxproj.filters @@ -254,6 +254,15 @@ Source Files\algorithm + + Source Files\sph + + + Source Files\sph + + + Source Files\sph + From 3fcb5277497af157ac91ad50cfccc2ae29a53c8a Mon Sep 17 00:00:00 2001 From: Massimo Del Zotto Date: Wed, 15 Nov 2017 15:32:44 +0100 Subject: [PATCH 11/12] Years have gone by, and Windows Sockets still didn't get initialized. Wsock sucks but that's not a good excuse for not driving them correctly. It happens windows still exists so get along with it, IDK how many times I applied this patch privately; it stops being funny after a while. --- sgminer.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/sgminer.c b/sgminer.c index 0824ceeca..0ac376a58 100644 --- a/sgminer.c +++ b/sgminer.c @@ -8167,6 +8167,12 @@ void _quit(int status) } #endif +#ifdef _WIN32 + // Calling startup means we somewhere must call this. It would be ideal to have it in main but the exit never gets reached. + // Or, since WIN32 builds under MSVC compile as C++ we could RAII-n-scope it but anyway. + WSACleanup(); +#endif // _WIN32 + exit(status); } @@ -8768,6 +8774,17 @@ int main(int argc, char *argv[]) int i; char *s; +#ifdef _WIN32 + { + WSADATA wsaData; + int err = WSAStartup(MAKEWORD(2, 2), &wsaData); + if (err) { + quit(1, "Winsock startup failed with error %d\n", err); + return err; + } + } +#endif // _WIN32 + /* This dangerous function tramples random dynamically allocated * variables so do it before anything at all */ if (unlikely(curl_global_init(CURL_GLOBAL_ALL))) @@ -8779,6 +8796,7 @@ int main(int argc, char *argv[]) quithere(1, "Failed to pthread_mutex_init lockstat_lock errno=%d", errno); #endif + // initialize default profile (globals) before reading config options init_default_profile(); @@ -9300,6 +9318,5 @@ int main(int argc, char *argv[]) push_curl_entry(ce, pool); #endif /* HAVE_LIBCURL */ } - return 0; } From cbe3546a04bc59e2a490e8ca2c4928a71ef7bf11 Mon Sep 17 00:00:00 2001 From: Massimo Del Zotto Date: Wed, 15 Nov 2017 15:55:00 +0100 Subject: [PATCH 12/12] BUGFIX: buffer overrun! --- algorithm/blake256.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithm/blake256.c b/algorithm/blake256.c index b81b1fbac..a1a83ea19 100644 --- a/algorithm/blake256.c +++ b/algorithm/blake256.c @@ -54,7 +54,7 @@ void blake256_midstate(struct work *work) sph_blake256_context ctx_blake; uint32_t data[16]; - be32enc_vect(data, (const uint32_t *)work->data, 19); + be32enc_vect(data, (const uint32_t *)work->data, 16); sph_blake256_init(&ctx_blake); sph_blake256 (&ctx_blake, (unsigned char *)data, 64);