namespace {
-void overwrite_symbols();
+void overwrite_symbols() noexcept;
namespace hooks {
static constexpr auto name = "malloc";
static constexpr auto original = &::malloc;
- static void* hook(size_t size)
+ static void* hook(size_t size) noexcept
{
auto ptr = original(size);
heaptrack_malloc(ptr, size);
static constexpr auto name = "free";
static constexpr auto original = &::free;
- static void hook(void *ptr)
+ static void hook(void *ptr) noexcept
{
heaptrack_free(ptr);
original(ptr);
static constexpr auto name = "realloc";
static constexpr auto original = &::realloc;
- static void* hook(void *ptr, size_t size)
+ static void* hook(void *ptr, size_t size) noexcept
{
auto ret = original(ptr, size);
heaptrack_realloc(ptr, size, ret);
static constexpr auto name = "calloc";
static constexpr auto original = &::calloc;
- static void* hook(size_t num, size_t size)
+ static void* hook(size_t num, size_t size) noexcept
{
auto ptr = original(num, size);
heaptrack_malloc(ptr, num * size);
static constexpr auto name = "cfree";
static constexpr auto original = &::cfree;
- static void hook(void *ptr)
+ static void hook(void *ptr) noexcept
{
heaptrack_free(ptr);
original(ptr);
static constexpr auto name = "dlopen";
static constexpr auto original = &::dlopen;
- static void* hook(const char *filename, int flag)
+ static void* hook(const char *filename, int flag) noexcept
{
auto ret = original(filename, flag);
if (ret) {
static constexpr auto name = "dlclose";
static constexpr auto original = &::dlclose;
- static int hook(void *handle)
+ static int hook(void *handle) noexcept
{
auto ret = original(handle);
if (!ret) {
static constexpr auto name = "posix_memalign";
static constexpr auto original = &::posix_memalign;
- static int hook(void **memptr, size_t alignment, size_t size)
+ static int hook(void **memptr, size_t alignment, size_t size) noexcept
{
auto ret = original(memptr, alignment, size);
if (!ret) {
void* originalAddress;
template<typename Hook>
- static constexpr hook wrap()
+ static constexpr hook wrap() noexcept
{
static_assert(sizeof(&Hook::hook) == sizeof(void*), "Mismatched pointer sizes");
static_assert(std::is_convertible<decltype(&Hook::hook), decltype(Hook::original)>::value,
T* table = nullptr;
ElfW(Xword) size = ElfW(Xword)();
- bool consume(const ElfW(Dyn) *dyn)
+ bool consume(const ElfW(Dyn) *dyn) noexcept
{
if (dyn->d_tag == AddrTag) {
table = reinterpret_cast<T*>(dyn->d_un.d_ptr);
using elf_jmprel_table = elftable<ElfW(Rela), DT_JMPREL, DT_PLTRELSZ>;
using elf_symbol_table = elftable<ElfW(Sym), DT_SYMTAB, DT_SYMENT>;
-void try_overwrite_symbols(const ElfW(Dyn) *dyn, const ElfW(Addr) base, const bool restore)
+void try_overwrite_symbols(const ElfW(Dyn) *dyn, const ElfW(Addr) base, const bool restore) noexcept
{
elf_symbol_table symbols;
elf_jmprel_table jmprels;
}
}
-int iterate_phdrs(dl_phdr_info *info, size_t /*size*/, void *data)
+int iterate_phdrs(dl_phdr_info *info, size_t /*size*/, void *data) noexcept
{
if (strstr(info->dlpi_name, "/libheaptrack_inject.so")) {
// prevent infinite recursion: do not overwrite our own symbols
return 0;
}
-void overwrite_symbols()
+void overwrite_symbols() noexcept
{
dl_iterate_phdr(&iterate_phdrs, nullptr);
}
extern "C" {
-void heaptrack_inject(const char *outputFileName)
+void heaptrack_inject(const char *outputFileName) noexcept
{
heaptrack_init(outputFileName, [] () {
overwrite_symbols();
using Signature = SignatureT*;
Signature original = nullptr;
- void init()
+ void init() noexcept
{
auto ret = dlsym(RTLD_NEXT, Base::identifier);
if (!ret) {
}
template<typename... Args>
- auto operator() (Args... args) const -> decltype(original(args...))
+ auto operator() (Args... args) const noexcept -> decltype(original(args...))
{
return original(args...);
}
- explicit operator bool () const
+ explicit operator bool () const noexcept
{
return original;
}
*
* This is only called at startup and will eventually be replaced by the "proper" calloc implementation.
*/
-void* dummy_calloc(size_t num, size_t size)
+void* dummy_calloc(size_t num, size_t size) noexcept
{
const size_t MAX_SIZE = 1024;
static char* buf[MAX_SIZE];
/// TODO: memalign, pvalloc, ...?
-void* malloc(size_t size) throw()
+void* malloc(size_t size) noexcept
{
if (!hooks::malloc) {
hooks::init();
return ptr;
}
-void free(void* ptr) throw()
+void free(void* ptr) noexcept
{
if (!hooks::free) {
hooks::init();
hooks::free(ptr);
}
-void* realloc(void* ptr, size_t size) throw()
+void* realloc(void* ptr, size_t size) noexcept
{
if (!hooks::realloc) {
hooks::init();
return ret;
}
-void* calloc(size_t num, size_t size) throw()
+void* calloc(size_t num, size_t size) noexcept
{
if (!hooks::calloc) {
hooks::init();
return ret;
}
-void cfree(void* ptr) throw()
+void cfree(void* ptr) noexcept
{
if (!hooks::cfree) {
hooks::init();
hooks::cfree(ptr);
}
-int posix_memalign(void **memptr, size_t alignment, size_t size) throw()
+int posix_memalign(void **memptr, size_t alignment, size_t size) noexcept
{
if (!hooks::posix_memalign) {
hooks::init();
return ret;
}
-void* aligned_alloc(size_t alignment, size_t size) throw()
+void* aligned_alloc(size_t alignment, size_t size) noexcept
{
if (!hooks::aligned_alloc) {
hooks::init();
return ret;
}
-void* valloc(size_t size) throw()
+void* valloc(size_t size) noexcept
{
if (!hooks::valloc) {
hooks::init();
return ret;
}
-void *dlopen(const char *filename, int flag) throw()
+void *dlopen(const char *filename, int flag) noexcept
{
if (!hooks::dlopen) {
hooks::init();
return ret;
}
-int dlclose(void *handle) throw()
+int dlclose(void *handle) noexcept
{
if (!hooks::dlclose) {
hooks::init();