2024-06-04 02:59:36 +00:00
|
|
|
// Standard library includes.
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
// Unix includes.
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
|
|
// Local includes.
|
|
|
|
#include "another_memcheck.h"
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
void *malloc(std::size_t size) {
|
|
|
|
if (SC_AM_Internal::real_malloc == nullptr) {
|
|
|
|
SC_AM_Internal::real_malloc = reinterpret_cast<void*(*)(std::size_t)>(dlsym(RTLD_NEXT, "malloc"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SC_AM_Internal::stats == nullptr) {
|
|
|
|
SC_AM_Internal::stats = SC_AM_Internal::get_init_stats();
|
|
|
|
}
|
|
|
|
|
2024-06-06 06:16:42 +00:00
|
|
|
if (SC_AM_Internal::is_env_status == SC_AM_Internal::ANOTHER_MEMCHECK_QUIET_NOT_EXISTS) {
|
2024-06-26 05:01:51 +00:00
|
|
|
std::clog << "attempting to malloc size: " << size;
|
2024-06-06 06:16:42 +00:00
|
|
|
}
|
|
|
|
|
2024-06-04 02:59:36 +00:00
|
|
|
return SC_AM_Internal::stats->do_malloc(size);
|
|
|
|
}
|
|
|
|
|
2024-06-04 06:15:05 +00:00
|
|
|
void *calloc(std::size_t n, std::size_t size) {
|
|
|
|
if (SC_AM_Internal::real_calloc == nullptr) {
|
|
|
|
SC_AM_Internal::real_calloc = reinterpret_cast<void*(*)(std::size_t, std::size_t)>(
|
|
|
|
dlsym(RTLD_NEXT, "calloc"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SC_AM_Internal::stats == nullptr) {
|
|
|
|
SC_AM_Internal::stats = SC_AM_Internal::get_init_stats();
|
|
|
|
}
|
|
|
|
|
2024-06-06 06:16:42 +00:00
|
|
|
if (SC_AM_Internal::is_env_status == SC_AM_Internal::ANOTHER_MEMCHECK_QUIET_NOT_EXISTS) {
|
2024-06-26 05:01:51 +00:00
|
|
|
std::clog << "attempting to calloc size: " << size;
|
2024-06-06 06:16:42 +00:00
|
|
|
}
|
|
|
|
|
2024-06-04 06:15:05 +00:00
|
|
|
return SC_AM_Internal::stats->do_calloc(n, size);
|
|
|
|
}
|
|
|
|
|
2024-06-27 05:45:40 +00:00
|
|
|
void *realloc(void *ptr, std::size_t size) {
|
|
|
|
if (SC_AM_Internal::real_realloc == nullptr) {
|
|
|
|
SC_AM_Internal::real_realloc = reinterpret_cast<void*(*)(void*, std::size_t)>(dlsym(RTLD_NEXT, "realloc"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SC_AM_Internal::stats == nullptr) {
|
|
|
|
SC_AM_Internal::stats = SC_AM_Internal::get_init_stats();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SC_AM_Internal::is_env_status == SC_AM_Internal::ANOTHER_MEMCHECK_QUIET_NOT_EXISTS) {
|
|
|
|
std::clog << "attempting to realloc size: " << size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SC_AM_Internal::stats->do_realloc(ptr, size);
|
|
|
|
}
|
|
|
|
|
2024-06-04 02:59:36 +00:00
|
|
|
void free(void *ptr) {
|
|
|
|
if (SC_AM_Internal::real_free == nullptr) {
|
|
|
|
SC_AM_Internal::real_free = reinterpret_cast<void(*)(void*)>(dlsym(RTLD_NEXT, "free"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SC_AM_Internal::stats == nullptr) {
|
|
|
|
SC_AM_Internal::stats = SC_AM_Internal::get_init_stats();
|
|
|
|
}
|
|
|
|
|
2024-06-06 06:16:42 +00:00
|
|
|
if (SC_AM_Internal::is_env_status == SC_AM_Internal::ANOTHER_MEMCHECK_QUIET_NOT_EXISTS) {
|
2024-06-26 05:01:51 +00:00
|
|
|
std::clog << "attempting to free";
|
2024-06-06 06:16:42 +00:00
|
|
|
}
|
|
|
|
|
2024-06-26 05:01:51 +00:00
|
|
|
if (!SC_AM_Internal::stats->do_free(ptr)) {
|
|
|
|
std::clog << std::endl;
|
|
|
|
}
|
2024-06-04 02:59:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// vim: et sw=2 ts=2 sts=2
|