mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
-BEGIN VERIFY SCRIPT-
for f in \
src/*.cpp \
src/*.h \
src/bench/*.cpp \
src/bench/*.h \
src/compat/*.cpp \
src/compat/*.h \
src/consensus/*.cpp \
src/consensus/*.h \
src/crypto/*.cpp \
src/crypto/*.h \
src/crypto/ctaes/*.h \
src/policy/*.cpp \
src/policy/*.h \
src/primitives/*.cpp \
src/primitives/*.h \
src/qt/*.cpp \
src/qt/*.h \
src/qt/test/*.cpp \
src/qt/test/*.h \
src/rpc/*.cpp \
src/rpc/*.h \
src/script/*.cpp \
src/script/*.h \
src/support/*.cpp \
src/support/*.h \
src/support/allocators/*.h \
src/test/*.cpp \
src/test/*.h \
src/wallet/*.cpp \
src/wallet/*.h \
src/wallet/test/*.cpp \
src/wallet/test/*.h \
src/zmq/*.cpp \
src/zmq/*.h
do
base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f
done
-END VERIFY SCRIPT-
40 lines
1.4 KiB
C++
40 lines
1.4 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>
|
|
|
|
/* 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)
|
|
__asm;
|
|
#else
|
|
__asm__ __volatile__("" : : "r"(ptr) : "memory");
|
|
#endif
|
|
}
|