2024-06-04 02:59:36 +00:00
|
|
|
#ifndef SEODISPARATE_COM_ANOTHER_MEMCHECK_H
|
|
|
|
#define SEODISPARATE_COM_ANOTHER_MEMCHECK_H
|
|
|
|
|
2024-06-04 06:40:57 +00:00
|
|
|
extern "C" {
|
|
|
|
#include <pthread.h>
|
|
|
|
}
|
|
|
|
|
2024-06-04 02:59:36 +00:00
|
|
|
namespace SC_AM_Internal {
|
|
|
|
// Forward declaration.
|
|
|
|
struct Stats;
|
|
|
|
|
|
|
|
extern Stats *stats;
|
|
|
|
|
|
|
|
Stats *get_init_stats();
|
|
|
|
|
|
|
|
constexpr unsigned int DATA_BLOCK_SIZE = 24;
|
|
|
|
constexpr unsigned int DATA_ITEMS_SIZE = 500;
|
|
|
|
|
|
|
|
extern void *(*real_malloc)(std::size_t size);
|
2024-06-04 06:15:05 +00:00
|
|
|
extern void *(*real_calloc)(std::size_t n, std::size_t size);
|
2024-06-04 02:59:36 +00:00
|
|
|
extern void (*real_free)(void *ptr);
|
|
|
|
|
|
|
|
struct Malloced {
|
|
|
|
Malloced();
|
|
|
|
Malloced(void *address, std::size_t size);
|
|
|
|
|
|
|
|
void* address;
|
|
|
|
std::size_t size;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ListNode {
|
2024-06-04 06:08:33 +00:00
|
|
|
ListNode() : next(nullptr), prev(nullptr), data(nullptr) {}
|
|
|
|
|
|
|
|
static void add_to_list(ListNode *tail, Malloced *data);
|
|
|
|
/// Returns true if removed.
|
|
|
|
static bool remove_from_list(ListNode *head, void *ptr);
|
2024-06-04 02:59:36 +00:00
|
|
|
|
|
|
|
ListNode *next;
|
2024-06-04 06:08:33 +00:00
|
|
|
ListNode *prev;
|
2024-06-04 02:59:36 +00:00
|
|
|
Malloced *data;
|
|
|
|
};
|
|
|
|
|
2024-06-04 06:08:33 +00:00
|
|
|
|
2024-06-04 02:59:36 +00:00
|
|
|
struct Stats {
|
|
|
|
Stats();
|
|
|
|
|
2024-06-04 06:08:33 +00:00
|
|
|
ListNode *malloced_list_head;
|
|
|
|
ListNode *malloced_list_tail;
|
2024-06-04 06:40:57 +00:00
|
|
|
pthread_mutex_t pthread_mutex;
|
2024-06-04 02:59:36 +00:00
|
|
|
|
|
|
|
void initialize();
|
2024-06-04 06:40:57 +00:00
|
|
|
void cleanup();
|
2024-06-04 02:59:36 +00:00
|
|
|
|
|
|
|
void *do_malloc(std::size_t size);
|
2024-06-04 06:15:05 +00:00
|
|
|
void *do_calloc(std::size_t n, std::size_t size);
|
2024-06-04 02:59:36 +00:00
|
|
|
void do_free(void *ptr);
|
|
|
|
|
|
|
|
void print_status() const;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// vim: et sw=2 ts=2 sts=2
|