Skip to content
This repository has been archived by the owner on Jan 9, 2021. It is now read-only.

Better Visual Studio and Windows support. #10

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ lib/warn-on-use.h
mkinstalldirs

*.swp
winbuild/.vs/sgminer/
2 changes: 1 addition & 1 deletion algorithm/blake256.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 12 additions & 12 deletions algorithm/yescrypt-opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);



Expand All @@ -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);

}
}
Expand Down Expand Up @@ -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);


}
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
24 changes: 15 additions & 9 deletions algorithm/yescryptcommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
{

Expand Down
6 changes: 3 additions & 3 deletions api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions findnonce.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
#include <pthread.h>
#include <string.h>
Expand Down
3 changes: 3 additions & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sched.h>

Expand Down Expand Up @@ -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 {
Expand Down
29 changes: 26 additions & 3 deletions sgminer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down Expand Up @@ -5141,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 */
Expand Down Expand Up @@ -6247,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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -8161,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);
}

Expand Down Expand Up @@ -8762,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)))
Expand All @@ -8773,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();

Expand Down Expand Up @@ -9294,6 +9318,5 @@ int main(int argc, char *argv[])
push_curl_entry(ce, pool);
#endif /* HAVE_LIBCURL */
}

return 0;
}
12 changes: 6 additions & 6 deletions sph/gost.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down
Loading