Skip to content

Commit

Permalink
Merge pull request #45 from AntelopeIO/asan_mlock_war
Browse files Browse the repository at this point in the history
work around ASAN intercepting `mlock()` as a noop
  • Loading branch information
spoonincode authored Mar 27, 2024
2 parents a6eeebd + 8e05fee commit 0324e06
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/pinnable_mapped_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
#include <sys/sysinfo.h>
#endif

// 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 {

std::vector<pinnable_mapped_file*> pinnable_mapped_file::_instance_tracker;
Expand Down Expand Up @@ -216,7 +223,7 @@ pinnable_mapped_file::pinnable_mapped_file(const std::filesystem::path& dir, boo

#ifndef _WIN32
if(mode == locked) {
if(mlock(_non_file_mapped_mapping, _non_file_mapped_mapping_size)) {
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 0324e06

Please sign in to comment.