Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2009-2010 Satoshi Nakamoto2// Copyright (c) 2009-present The Bitcoin Core developers3// Distributed under the MIT software license, see the accompanying4// file COPYING or http://www.opensource.org/licenses/mit-license.php.6#include <support/cleanse.h>8#include <cstring>10#if defined(WIN32)11#include <windows.h>12#endif14void memory_cleanse(void *ptr, size_t len)15{16#if defined(WIN32)17/* SecureZeroMemory is guaranteed not to be optimized out. */18SecureZeroMemory(ptr, len);19#else20std::memset(ptr, 0, len);22/* Memory barrier that scares the compiler away from optimizing out the memset.23*24* Quoting Adam Langley <[email protected]> in commit ad1907fe73334d6c696c8539646c21b11178f20f25* in BoringSSL (ISC License):26* As best as we can tell, this is sufficient to break any optimisations that27* might try to eliminate "superfluous" memsets.28* This method is used in memzero_explicit() the Linux kernel, too. Its advantage is that it29* is pretty efficient because the compiler can still implement the memset() efficiently,30* just not remove it entirely. See "Dead Store Elimination (Still) Considered Harmful" by31* Yang et al. (USENIX Security 2017) for more background.32*/33__asm__ __volatile__("" : : "r"(ptr) : "memory");34#endif35}