2019-07-03 23:45:23 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2019 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#include <RB_INC_VALGRIND_VALGRIND_H
|
|
|
|
#include <RB_INC_VALGRIND_MEMCHECK_H
|
|
|
|
#include <RB_INC_VALGRIND_CALLGRIND_H
|
|
|
|
|
2022-06-14 23:15:53 +02:00
|
|
|
[[gnu::visibility("protected")]]
|
2019-07-03 23:45:23 +02:00
|
|
|
void
|
2022-06-15 03:39:03 +02:00
|
|
|
ircd::vg::set_noaccess(const const_buffer buf)
|
2020-10-16 18:44:04 +02:00
|
|
|
noexcept
|
2019-07-03 23:45:23 +02:00
|
|
|
{
|
|
|
|
#ifdef HAVE_VALGRIND_MEMCHECK_H
|
|
|
|
VALGRIND_MAKE_MEM_NOACCESS(data(buf), size(buf));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-06-14 23:15:53 +02:00
|
|
|
[[gnu::visibility("protected")]]
|
2019-07-03 23:45:23 +02:00
|
|
|
void
|
2022-06-15 03:39:03 +02:00
|
|
|
ircd::vg::set_undefined(const const_buffer buf)
|
2020-10-16 18:44:04 +02:00
|
|
|
noexcept
|
2019-07-03 23:45:23 +02:00
|
|
|
{
|
|
|
|
#ifdef HAVE_VALGRIND_MEMCHECK_H
|
|
|
|
VALGRIND_MAKE_MEM_UNDEFINED(data(buf), size(buf));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-06-14 23:15:53 +02:00
|
|
|
[[gnu::visibility("protected")]]
|
2019-07-03 23:45:23 +02:00
|
|
|
void
|
2022-06-15 03:39:03 +02:00
|
|
|
ircd::vg::set_defined(const const_buffer buf)
|
2020-10-16 18:44:04 +02:00
|
|
|
noexcept
|
2019-07-03 23:45:23 +02:00
|
|
|
{
|
|
|
|
#ifdef HAVE_VALGRIND_MEMCHECK_H
|
|
|
|
VALGRIND_MAKE_MEM_DEFINED(data(buf), size(buf));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-06-14 23:15:53 +02:00
|
|
|
[[gnu::visibility("protected")]]
|
2019-07-03 23:45:23 +02:00
|
|
|
bool
|
2022-06-15 03:39:03 +02:00
|
|
|
ircd::vg::defined(const void *const ptr,
|
|
|
|
const size_t size)
|
2020-10-16 18:44:04 +02:00
|
|
|
noexcept
|
2019-07-03 23:45:23 +02:00
|
|
|
{
|
|
|
|
#ifdef HAVE_VALGRIND_MEMCHECK_H
|
2022-06-15 03:39:03 +02:00
|
|
|
return VALGRIND_CHECK_MEM_IS_DEFINED(ptr, size) == 0;
|
2019-07-03 23:45:23 +02:00
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-06-14 23:15:53 +02:00
|
|
|
[[gnu::visibility("protected")]]
|
2020-10-16 18:44:04 +02:00
|
|
|
size_t
|
|
|
|
ircd::vg::errors()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
#ifdef HAVE_VALGRIND_VALGRIND_H
|
|
|
|
return VALGRIND_COUNT_ERRORS;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-10-16 18:48:33 +02:00
|
|
|
decltype(ircd::vg::active)
|
|
|
|
ircd::vg::active{[]() -> bool
|
2020-10-16 18:44:04 +02:00
|
|
|
{
|
|
|
|
#ifdef HAVE_VALGRIND_VALGRIND_H
|
|
|
|
return RUNNING_ON_VALGRIND;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2020-10-16 18:48:33 +02:00
|
|
|
}()};
|
|
|
|
|
|
|
|
//
|
|
|
|
// vg::stack
|
|
|
|
//
|
|
|
|
|
2022-06-14 23:15:53 +02:00
|
|
|
[[gnu::visibility("protected")]]
|
2020-10-16 18:48:33 +02:00
|
|
|
void
|
2022-06-15 03:39:03 +02:00
|
|
|
ircd::vg::stack::del(const uint id)
|
2020-10-16 18:48:33 +02:00
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
#ifdef HAVE_VALGRIND_MEMCHECK_H
|
|
|
|
VALGRIND_STACK_DEREGISTER(id);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-06-14 23:15:53 +02:00
|
|
|
[[gnu::visibility("protected")]]
|
2020-10-16 18:48:33 +02:00
|
|
|
uint
|
2022-06-15 03:39:03 +02:00
|
|
|
ircd::vg::stack::add(const mutable_buffer buf)
|
2020-10-16 18:48:33 +02:00
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
#ifdef HAVE_VALGRIND_MEMCHECK_H
|
|
|
|
return VALGRIND_STACK_REGISTER(ircd::data(buf) + ircd::size(buf), ircd::data(buf));
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2020-10-16 18:44:04 +02:00
|
|
|
}
|
|
|
|
|
2019-07-03 23:45:23 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// ircd/prof.h
|
|
|
|
//
|
|
|
|
|
|
|
|
namespace ircd::prof::vg
|
|
|
|
{
|
|
|
|
static bool _enabled;
|
|
|
|
}
|
|
|
|
|
2022-06-14 23:15:53 +02:00
|
|
|
[[gnu::visibility("protected")]]
|
2019-07-03 23:45:23 +02:00
|
|
|
void
|
|
|
|
ircd::prof::vg::stop()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
#ifdef HAVE_VALGRIND_CALLGRIND_H
|
|
|
|
CALLGRIND_STOP_INSTRUMENTATION;
|
|
|
|
assert(_enabled);
|
|
|
|
_enabled = false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-06-14 23:15:53 +02:00
|
|
|
[[gnu::visibility("protected")]]
|
2019-07-03 23:45:23 +02:00
|
|
|
void
|
|
|
|
ircd::prof::vg::start()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
#ifdef HAVE_VALGRIND_CALLGRIND_H
|
|
|
|
assert(!_enabled);
|
|
|
|
_enabled = true;
|
|
|
|
CALLGRIND_START_INSTRUMENTATION;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-06-14 23:15:53 +02:00
|
|
|
[[gnu::visibility("protected")]]
|
2019-07-03 23:45:23 +02:00
|
|
|
void
|
|
|
|
ircd::prof::vg::reset()
|
|
|
|
{
|
|
|
|
#ifdef HAVE_VALGRIND_CALLGRIND_H
|
|
|
|
CALLGRIND_ZERO_STATS;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-06-14 23:15:53 +02:00
|
|
|
[[gnu::visibility("protected")]]
|
2019-07-03 23:45:23 +02:00
|
|
|
void
|
|
|
|
ircd::prof::vg::toggle()
|
|
|
|
{
|
|
|
|
#ifdef HAVE_VALGRIND_CALLGRIND_H
|
|
|
|
CALLGRIND_TOGGLE_COLLECT;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-06-14 23:15:53 +02:00
|
|
|
[[gnu::visibility("protected")]]
|
2019-07-03 23:45:23 +02:00
|
|
|
void
|
|
|
|
ircd::prof::vg::dump(const char *const reason)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_VALGRIND_CALLGRIND_H
|
|
|
|
CALLGRIND_DUMP_STATS_AT(reason);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-06-14 23:15:53 +02:00
|
|
|
[[gnu::visibility("protected")]]
|
2019-07-03 23:45:23 +02:00
|
|
|
bool
|
|
|
|
ircd::prof::vg::enabled()
|
|
|
|
{
|
|
|
|
return _enabled;
|
|
|
|
}
|