Skip to content

Commit

Permalink
do mlock2() workaround differently
Browse files Browse the repository at this point in the history
  • Loading branch information
spoonincode committed Mar 27, 2024
1 parent 468e27d commit 8e05fee
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/pinnable_mapped_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
#include <sys/sysinfo.h>
#endif

#ifndef __has_feature
#define __has_feature(x) 0
// use mlock2() on Linux to avoid a noop intercept of mlock() when ASAN is enabled (still present in compiler-rt 18.1)
#ifdef __linux__
#define MLOCK(a, b) mlock2(a, b, 0)
#else
#define MLOCK(a, b) mlock(a, b)
#endif

namespace chainbase {
Expand Down Expand Up @@ -220,13 +223,7 @@ pinnable_mapped_file::pinnable_mapped_file(const std::filesystem::path& dir, boo

#ifndef _WIN32
if(mode == locked) {
#if __has_feature(address_sanitizer) && defined(__linux__)
//as of llvm's compilerrt 18, mlock() continues to be intercepted as a noop thus breaking tests the expect memory locking
// to fail. mlock2() isn't intercepted though, so use it when ASAN is enabled on Linux
if(mlock2(_non_file_mapped_mapping, _non_file_mapped_mapping_size, 0)) {
#else
if(mlock(_non_file_mapped_mapping, _non_file_mapped_mapping_size)) {
#endif
if(MLOCK(_non_file_mapped_mapping, _non_file_mapped_mapping_size)) {
std::string what_str("Failed to mlock database \"" + _database_name + "\"");
BOOST_THROW_EXCEPTION(std::system_error(make_error_code(db_error_code::no_mlock), what_str));
}
Expand Down

0 comments on commit 8e05fee

Please sign in to comment.