LCOV - code coverage report
Current view: top level - src/support - cleanse.cpp (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 5 5 100.0 %
Date: 2022-04-21 14:51:19 Functions: 1 1 100.0 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 0 0 -

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2009-2010 Satoshi Nakamoto
#       2                 :            : // Copyright (c) 2009-2019 The Bitcoin Core developers
#       3                 :            : // Distributed under the MIT software license, see the accompanying
#       4                 :            : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#       5                 :            : 
#       6                 :            : #include <support/cleanse.h>
#       7                 :            : 
#       8                 :            : #include <cstring>
#       9                 :            : 
#      10                 :            : #if defined(_MSC_VER)
#      11                 :            : #include <Windows.h> // For SecureZeroMemory.
#      12                 :            : #endif
#      13                 :            : 
#      14                 :            : void memory_cleanse(void *ptr, size_t len)
#      15                 :   20575221 : {
#      16                 :            : #if defined(_MSC_VER)
#      17                 :            :     /* SecureZeroMemory is guaranteed not to be optimized out by MSVC. */
#      18                 :            :     SecureZeroMemory(ptr, len);
#      19                 :            : #else
#      20                 :   20575221 :     std::memset(ptr, 0, len);
#      21                 :            : 
#      22                 :            :     /* Memory barrier that scares the compiler away from optimizing out the memset.
#      23                 :            :      *
#      24                 :            :      * Quoting Adam Langley <agl@google.com> in commit ad1907fe73334d6c696c8539646c21b11178f20f
#      25                 :            :      * in BoringSSL (ISC License):
#      26                 :            :      *    As best as we can tell, this is sufficient to break any optimisations that
#      27                 :            :      *    might try to eliminate "superfluous" memsets.
#      28                 :            :      * This method is used in memzero_explicit() the Linux kernel, too. Its advantage is that it
#      29                 :            :      * 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" by
#      31                 :            :      * Yang et al. (USENIX Security 2017) for more background.
#      32                 :            :      */
#      33                 :   20575221 :     __asm__ __volatile__("" : : "r"(ptr) : "memory");
#      34                 :   20575221 : #endif
#      35                 :   20575221 : }

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a