forked from dogecoin/dogecoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minimal code changes to allow msvc compilation.
-include <array> and change buff from unsigned char[32] to static const std::array<unsigned char, 32> in bench/base58.cpp -drop copy of buff to new variable b, begin() and end() and use data() and size() on buffer in bench/base58.cpp -drop boost::assign::map_list_of for checkpointData in chainparams.cpp and change to std::list -add msvc ssize_t definition in compat.h -make bool operator a constant in net_processing.cpp IteratorComparator -change NUM_OS_RANDOM_BYTES to int from ssize_t in random.h -if msvc is defined include <Windows.h> and replace __asm with SecureZeroMemory() in support/cleanse.cpp -change QUEUE_BATCH_SIZE to unsigned int in test/checkqueue_tests.cpp Includes squashed commit: f7dc992 Inspired by: fbf327b
- Loading branch information
1 parent
90d1972
commit a3810a4
Showing
8 changed files
with
233 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// Copyright (c) 2009-2010 Satoshi Nakamoto | ||
// Copyright (c) 2009-2021 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_COMPAT_COMPAT_H | ||
#define BITCOIN_COMPAT_COMPAT_H | ||
|
||
#if defined(HAVE_CONFIG_H) | ||
#include <config/bitcoin-config.h> | ||
#endif | ||
|
||
// Windows defines FD_SETSIZE to 64 (see _fd_types.h in mingw-w64), | ||
// which is too small for our usage, but allows us to redefine it safely. | ||
// We redefine it to be 1024, to match glibc, see typesizes.h. | ||
#ifdef WIN32 | ||
#ifdef FD_SETSIZE | ||
#undef FD_SETSIZE | ||
#endif | ||
#define FD_SETSIZE 1024 | ||
#include <winsock2.h> | ||
#include <ws2tcpip.h> | ||
#include <cstdint> | ||
#else | ||
#include <fcntl.h> | ||
#include <sys/mman.h> | ||
#include <sys/select.h> | ||
#include <sys/socket.h> | ||
#include <sys/types.h> | ||
#include <net/if.h> | ||
#include <netinet/in.h> | ||
#include <netinet/tcp.h> | ||
#include <arpa/inet.h> | ||
#include <ifaddrs.h> | ||
#include <limits.h> | ||
#include <netdb.h> | ||
#include <unistd.h> | ||
#endif | ||
|
||
// We map Linux / BSD error functions and codes, to the equivalent | ||
// Windows definitions, and use the WSA* names throughout our code. | ||
// Note that glibc defines EWOULDBLOCK as EAGAIN (see errno.h). | ||
#ifndef WIN32 | ||
typedef unsigned int SOCKET; | ||
#include <cerrno> | ||
#define WSAGetLastError() errno | ||
#define WSAEINVAL EINVAL | ||
#define WSAEWOULDBLOCK EWOULDBLOCK | ||
#define WSAEAGAIN EAGAIN | ||
#define WSAEMSGSIZE EMSGSIZE | ||
#define WSAEINTR EINTR | ||
#define WSAEINPROGRESS EINPROGRESS | ||
#define WSAEADDRINUSE EADDRINUSE | ||
#define INVALID_SOCKET (SOCKET)(~0) | ||
#define SOCKET_ERROR -1 | ||
#else | ||
// WSAEAGAIN doesn't exist on Windows | ||
#ifdef EAGAIN | ||
#define WSAEAGAIN EAGAIN | ||
#else | ||
#define WSAEAGAIN WSAEWOULDBLOCK | ||
#endif | ||
#endif | ||
|
||
// Windows doesn't define S_IRUSR or S_IWUSR. We define both | ||
// here, with the same values as glibc (see stat.h). | ||
#ifdef WIN32 | ||
#ifndef S_IRUSR | ||
#define S_IRUSR 0400 | ||
#define S_IWUSR 0200 | ||
#endif | ||
#endif | ||
|
||
// Windows defines MAX_PATH as it's maximum path length. | ||
// We define MAX_PATH for use on non-Windows systems. | ||
#ifndef WIN32 | ||
#define MAX_PATH 1024 | ||
#endif | ||
|
||
// ssize_t is POSIX, and not present when using MSVC. | ||
#ifdef _MSC_VER | ||
#include <BaseTsd.h> | ||
typedef SSIZE_T ssize_t; | ||
#endif | ||
|
||
// The type of the option value passed to getsockopt & setsockopt | ||
// differs between Windows and non-Windows. | ||
#ifndef WIN32 | ||
typedef void* sockopt_arg_type; | ||
#else | ||
typedef char* sockopt_arg_type; | ||
#endif | ||
|
||
#ifdef WIN32 | ||
// Export main() and ensure working ASLR when using mingw-w64. | ||
// Exporting a symbol will prevent the linker from stripping | ||
// the .reloc section from the binary, which is a requirement | ||
// for ASLR. While release builds are not affected, anyone | ||
// building with a binutils < 2.36 is subject to this ld bug. | ||
#define MAIN_FUNCTION __declspec(dllexport) int main(int argc, char* argv[]) | ||
#else | ||
#define MAIN_FUNCTION int main(int argc, char* argv[]) | ||
#endif | ||
|
||
// Note these both should work with the current usage of poll, but best to be safe | ||
// WIN32 poll is broken https://daniel.haxx.se/blog/2012/10/10/wsapoll-is-broken/ | ||
// __APPLE__ poll is broke https://github.com/bitcoin/bitcoin/pull/14336#issuecomment-437384408 | ||
#if defined(__linux__) | ||
#define USE_POLL | ||
#endif | ||
|
||
bool static inline IsSelectableSocket(const SOCKET& s) { | ||
#if defined(USE_POLL) || defined(WIN32) | ||
return true; | ||
#else | ||
return (s < FD_SETSIZE); | ||
#endif | ||
} | ||
|
||
// MSG_NOSIGNAL is not available on some platforms, if it doesn't exist define it as 0 | ||
#if !defined(MSG_NOSIGNAL) | ||
#define MSG_NOSIGNAL 0 | ||
#endif | ||
|
||
// MSG_DONTWAIT is not available on some platforms, if it doesn't exist define it as 0 | ||
#if !defined(MSG_DONTWAIT) | ||
#define MSG_DONTWAIT 0 | ||
#endif | ||
|
||
#endif // BITCOIN_COMPAT_COMPAT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters