From f6bc11b76ac7155508b933f28a997ebfe8b97079 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 16 Oct 2020 09:48:33 -0700 Subject: [PATCH] ircd::vg: Add stack register/deregister to interface. ircd::vg: Use extern const bool for active(); minor reorg. --- include/ircd/vg.h | 8 +++++++- ircd/Makefile.am | 2 +- ircd/db_allocator.cc | 2 +- ircd/info.cc | 4 ++-- ircd/vg.cc | 29 ++++++++++++++++++++++++++--- modules/console.cc | 2 +- 6 files changed, 38 insertions(+), 9 deletions(-) diff --git a/include/ircd/vg.h b/include/ircd/vg.h index 3b1009d9e..be81c3fd4 100644 --- a/include/ircd/vg.h +++ b/include/ircd/vg.h @@ -14,7 +14,7 @@ /// Valgrind memcheck hypercall suite namespace ircd::vg { - bool active() noexcept; + extern const bool active; size_t errors() noexcept; bool defined(const const_buffer &) noexcept; @@ -22,3 +22,9 @@ namespace ircd::vg void set_undefined(const const_buffer &) noexcept; void set_noaccess(const const_buffer &) noexcept; } + +namespace ircd::vg::stack +{ + uint add(const mutable_buffer &) noexcept; + void del(const uint &id) noexcept; +} diff --git a/ircd/Makefile.am b/ircd/Makefile.am index 3ea4fd58e..b9826364f 100644 --- a/ircd/Makefile.am +++ b/ircd/Makefile.am @@ -121,10 +121,10 @@ libircd_la_LIBADD = \ libircd_la_SOURCES =# libircd_la_SOURCES += assert.cc libircd_la_SOURCES += info.cc +libircd_la_SOURCES += vg.cc libircd_la_SOURCES += allocator.cc libircd_la_SOURCES += allocator_gnu.cc libircd_la_SOURCES += allocator_je.cc -libircd_la_SOURCES += vg.cc libircd_la_SOURCES += exception.cc libircd_la_SOURCES += util.cc libircd_la_SOURCES += demangle.cc diff --git a/ircd/db_allocator.cc b/ircd/db_allocator.cc index 546f4609f..687546e63 100644 --- a/ircd/db_allocator.cc +++ b/ircd/db_allocator.cc @@ -70,7 +70,7 @@ ircd::db::database::allocator::mlock_enabled mlock_limit == -1UL // mlock2() not supported by valgrind - && !vg::active() + && !vg::active }; decltype(ircd::db::database::allocator::mlock_current) diff --git a/ircd/info.cc b/ircd/info.cc index 1cdc65fbc..ad7137d0d 100644 --- a/ircd/info.cc +++ b/ircd/info.cc @@ -283,8 +283,8 @@ ircd::info::dump_cpu_info_x86() hardware::virtualized? "virtual"_sv: "physical"_sv, - vg::active()? - " valgrind "_sv: + vg::active? + " valgrind"_sv: ""_sv, support, }; diff --git a/ircd/vg.cc b/ircd/vg.cc index 009c2872a..d63a3bd12 100644 --- a/ircd/vg.cc +++ b/ircd/vg.cc @@ -61,15 +61,38 @@ noexcept #endif } -bool -ircd::vg::active() -noexcept +decltype(ircd::vg::active) +ircd::vg::active{[]() -> bool { #ifdef HAVE_VALGRIND_VALGRIND_H return RUNNING_ON_VALGRIND; #else return false; #endif +}()}; + +// +// vg::stack +// + +void +ircd::vg::stack::del(const uint &id) +noexcept +{ + #ifdef HAVE_VALGRIND_MEMCHECK_H + VALGRIND_STACK_DEREGISTER(id); + #endif +} + +uint +ircd::vg::stack::add(const mutable_buffer &buf) +noexcept +{ + #ifdef HAVE_VALGRIND_MEMCHECK_H + return VALGRIND_STACK_REGISTER(ircd::data(buf) + ircd::size(buf), ircd::data(buf)); + #else + return 0; + #endif } /////////////////////////////////////////////////////////////////////////////// diff --git a/modules/console.cc b/modules/console.cc index 63640dce0..68b43a226 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -1339,7 +1339,7 @@ console_cmd__mem__get(opt &out, const string_view &line) bool console_cmd__vg(opt &out, const string_view &line) { - if(vg::active()) + if(vg::active) out << "running on valgrind" << std::endl; else out << "bare metal" << std::endl;