Skip to content

Commit

Permalink
Minimal code changes to allow msvc compilation.
Browse files Browse the repository at this point in the history
Cherry-picked from: fbf327b
  • Loading branch information
sipsorcery authored and xanimo committed Apr 3, 2024
1 parent 29aa4e0 commit 99e0be1
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 13 deletions.
14 changes: 8 additions & 6 deletions src/bench/base58.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@
#include "validation.h"
#include "base58.h"

#include <array>
#include <vector>
#include <string>


static void Base58Encode(benchmark::State& state)
{
unsigned char buff[32] = {
17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203, 163, 36, 58, 147,
227, 139, 2, 215, 100, 91, 38, 11, 141, 253, 40, 117, 21, 16, 90,
200, 24
static const std::array<unsigned char, 32> buff = {
{
17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203, 163, 36, 58, 147,
227, 139, 2, 215, 100, 91, 38, 11, 141, 253, 40, 117, 21, 16, 90,
200, 24
}
};
unsigned char* b = buff;
while (state.KeepRunning()) {
EncodeBase58(b, b + 32);
EncodeBase58(buff.data(), buff.data() + buff.size());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/bench/checkqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static const int MIN_CORES = 2;
static const size_t BATCHES = 101;
static const size_t BATCH_SIZE = 30;
static const int PREVECTOR_SIZE = 28;
static const int QUEUE_BATCH_SIZE = 128;
static const unsigned int QUEUE_BATCH_SIZE = 128;
static void CCheckQueueSpeed(benchmark::State& state)
{
struct FakeJobNoWork {
Expand Down
5 changes: 3 additions & 2 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,9 @@ class CRegTestParams : public CChainParams {
fMineBlocksOnDemand = true;

checkpointData = (CCheckpointData){
boost::assign::map_list_of
( 0, uint256S("0x3d2160a3b5dc4a9d62e7e66a295f70313ac808440ef7400d6c0772171ce973a5"))
{
{0, uint256S("0x3d2160a3b5dc4a9d62e7e66a295f70313ac808440ef7400d6c0772171ce973a5")},
}
};

chainTxData = ChainTxData{
Expand Down
10 changes: 10 additions & 0 deletions src/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <mswsock.h>
#include <windows.h>
#include <ws2tcpip.h>
#include <stdint.h>
#else
#include <sys/fcntl.h>
#include <sys/mman.h>
Expand Down Expand Up @@ -74,6 +75,15 @@ typedef u_int SOCKET;
#else
#define MAX_PATH 1024
#endif
#ifdef _MSC_VER
#if !defined(ssize_t)
#ifdef _WIN64
typedef int64_t ssize_t;
#else
typedef int32_t ssize_t;
#endif
#endif
#endif

// As Solaris does not have the MSG_NOSIGNAL flag for send(2) syscall, it is defined as 0
#if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL)
Expand Down
2 changes: 1 addition & 1 deletion src/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class FastRandomContext {
* sure that the underlying OS APIs for all platforms support the number.
* (many cap out at 256 bytes).
*/
static const ssize_t NUM_OS_RANDOM_BYTES = 32;
static const int NUM_OS_RANDOM_BYTES = 32;

/** Get 32 bytes of system entropy. Do not use this in application code: use
* GetStrongRandBytes instead.
Expand Down
34 changes: 32 additions & 2 deletions src/support/cleanse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,39 @@

#include "cleanse.h"

#include <openssl/crypto.h>
#include <cstring>

#if defined(_MSC_VER)
#include <Windows.h> // For SecureZeroMemory.
#endif

/* Compilers have a bad habit of removing "superfluous" memset calls that
* are trying to zero memory. For example, when memset()ing a buffer and
* then free()ing it, the compiler might decide that the memset is
* unobservable and thus can be removed.
*
* Previously we used OpenSSL which tried to stop this by a) implementing
* memset in assembly on x86 and b) putting the function in its own file
* for other platforms.
*
* This change removes those tricks in favour of using asm directives to
* scare the compiler away. As best as our compiler folks can tell, this is
* sufficient and will continue to be so.
*
* Adam Langley <[email protected]>
* Commit: ad1907fe73334d6c696c8539646c21b11178f20f
* BoringSSL (LICENSE: ISC)
*/
void memory_cleanse(void *ptr, size_t len)
{
OPENSSL_cleanse(ptr, len);
std::memset(ptr, 0, len);

/* As best as we can tell, this is sufficient to break any optimisations that
might try to eliminate "superfluous" memsets. If there's an easy way to
detect memset_s, it would be better to use that. */
#if defined(_MSC_VER)
SecureZeroMemory(ptr, len);
#else
__asm__ __volatile__("" : : "r"(ptr) : "memory");
#endif
}
2 changes: 1 addition & 1 deletion src/test/checkqueue_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// otherwise.
BOOST_FIXTURE_TEST_SUITE(checkqueue_tests, TestingSetup)

static const int QUEUE_BATCH_SIZE = 128;
static const unsigned int QUEUE_BATCH_SIZE = 128;

struct FakeCheck {
bool operator()()
Expand Down

0 comments on commit 99e0be1

Please sign in to comment.