mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-17 07:12:37 -03:00
68e021e3a3
fbf327b
Minimal code changes to allow msvc compilation. (Aaron Clauson)
Pull request description:
These changes are required to allow the Bitcoin source to build with Microsoft's C++ compiler (#11562 is also required).
I looked around for a better place for the typedef of ssize_t which is in random.h. The best candidate looks like src/compat.h but I figured including that header in random.h is a bigger change than the typedef. Note that the same typedef is in at least two other places including the OpenSSL and Berkeley DB headers so some of the Bitcoin code already picks it up.
Tree-SHA512: aa6cc6283015e08ab074641f9abdc116c4dc58574dc90f75e7a5af4cc82946d3052370e5cbe855fb6180c00f8dc66997d3724ff0412e4b7417e51b6602154825
43 lines
1.5 KiB
C++
43 lines
1.5 KiB
C++
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <support/cleanse.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 <agl@google.com>
|
|
* Commit: ad1907fe73334d6c696c8539646c21b11178f20f
|
|
* BoringSSL (LICENSE: ISC)
|
|
*/
|
|
void memory_cleanse(void *ptr, size_t 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
|
|
}
|