0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-15 22:41:12 +01:00

ircd::vg: Start a valgrind emulator hypercall suite.

This commit is contained in:
Jason Volk 2019-04-17 00:51:14 -07:00
parent e861743203
commit 08b53b1746
2 changed files with 48 additions and 0 deletions

View file

@ -37,6 +37,15 @@ namespace ircd::allocator
string_view info(const mutable_buffer &);
};
/// Valgrind memcheck hypercall suite
namespace ircd::vg::mem
{
bool defined(const const_buffer &);
void set_defined(const const_buffer &);
void set_undefined(const const_buffer &);
void set_noaccess(const const_buffer &);
}
/// Profiling counters. The purpose of this device is to gauge whether unwanted
/// or non-obvious allocations are taking place for a specific section. This
/// profiler has that very specific purpose and is not a replacement for

View file

@ -9,6 +9,7 @@
// full license for this software is available in the LICENSE file.
#include <RB_INC_MALLOC_H
#include <RB_INC_VALGRIND_MEMCHECK_H
// Uncomment or -D this #define to enable our own crude but simple ability to
// profile dynamic memory usage. Global `new` and `delete` will be captured
@ -66,6 +67,44 @@ ircd::allocator::trim(const size_t &pad)
}
#endif
//
// valgrind
//
void
ircd::vg::mem::set_noaccess(const const_buffer &buf)
{
#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_MAKE_MEM_NOACCESS(data(buf), size(buf));
#endif
}
void
ircd::vg::mem::set_undefined(const const_buffer &buf)
{
#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_MAKE_MEM_UNDEFINED(data(buf), size(buf));
#endif
}
void
ircd::vg::mem::set_defined(const const_buffer &buf)
{
#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_MAKE_MEM_DEFINED(data(buf), size(buf));
#endif
}
bool
ircd::vg::mem::defined(const const_buffer &buf)
{
#ifdef HAVE_VALGRIND_MEMCHECK_H
return VALGRIND_CHECK_MEM_IS_DEFINED(data(buf), size(buf)) == 0;
#else
return true;
#endif
}
//
// allocator::state
//