Changeset View
Changeset View
Standalone View
Standalone View
src/compat/glibc_sanity.cpp
// Copyright (c) 2009-2014 The Bitcoin Core developers | // Copyright (c) 2009-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#if defined(HAVE_CONFIG_H) | #if defined(HAVE_CONFIG_H) | ||||
#include <config/bitcoin-config.h> | #include <config/bitcoin-config.h> | ||||
#endif | #endif | ||||
#include <cstddef> | #include <cstddef> | ||||
#if defined(HAVE_SYS_SELECT_H) | |||||
#include <sys/select.h> | |||||
#endif | |||||
extern "C" void *memcpy(void *a, const void *b, size_t c); | extern "C" void *memcpy(void *a, const void *b, size_t c); | ||||
void *memcpy_int(void *a, const void *b, size_t c) { | void *memcpy_int(void *a, const void *b, size_t c) { | ||||
return memcpy(a, b, c); | return memcpy(a, b, c); | ||||
} | } | ||||
namespace { | namespace { | ||||
// trigger: Use the memcpy_int wrapper which calls our internal memcpy. | // trigger: Use the memcpy_int wrapper which calls our internal memcpy. | ||||
// A direct call to memcpy may be optimized away by the compiler. | // A direct call to memcpy may be optimized away by the compiler. | ||||
Show All 11 Lines | template <unsigned int T> bool sanity_test_memcpy() { | ||||
for (unsigned int i = 0; i != T; ++i) { | for (unsigned int i = 0; i != T; ++i) { | ||||
if (memcpy_verify[i] != i) { | if (memcpy_verify[i] != i) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
#if defined(HAVE_SYS_SELECT_H) | |||||
// trigger: Call FD_SET to trigger __fdelt_chk. FORTIFY_SOURCE must be defined | |||||
// as >0 and optimizations must be set to at least -O2. | |||||
// test: Add a file descriptor to an empty fd_set. Verify that it has been | |||||
// correctly added. | |||||
bool sanity_test_fdelt() { | |||||
fd_set fds; | |||||
FD_ZERO(&fds); | |||||
FD_SET(0, &fds); | |||||
return FD_ISSET(0, &fds); | |||||
} | |||||
#endif | |||||
} // namespace | } // namespace | ||||
bool glibc_sanity_test() { | bool glibc_sanity_test() { | ||||
#if defined(HAVE_SYS_SELECT_H) | |||||
if (!sanity_test_fdelt()) { | |||||
return false; | |||||
} | |||||
#endif | |||||
return sanity_test_memcpy<1025>(); | return sanity_test_memcpy<1025>(); | ||||
} | } |