2024-06-04 02:59:36 +00:00
|
|
|
#ifndef SEODISPARATE_COM_ANOTHER_MEMCHECK_H
|
|
|
|
#define SEODISPARATE_COM_ANOTHER_MEMCHECK_H
|
|
|
|
|
2024-11-12 07:10:10 +00:00
|
|
|
#include <cstdint>
|
|
|
|
|
2024-06-04 02:59:36 +00:00
|
|
|
namespace SC_AM_Internal {
|
|
|
|
// Forward declaration.
|
|
|
|
struct Stats;
|
|
|
|
|
|
|
|
extern Stats *stats;
|
|
|
|
|
2024-06-06 06:16:42 +00:00
|
|
|
constexpr int ANOTHER_MEMCHECK_QUIET_EXISTS = 1;
|
|
|
|
constexpr int ANOTHER_MEMCHECK_QUIET_NOT_EXISTS = 2;
|
|
|
|
|
|
|
|
/// 0 If unknown, 1 if env "ANOTHER_MEMCHECK_QUIET" exists, 2 if not.
|
|
|
|
extern int is_env_status;
|
2024-06-04 02:59:36 +00:00
|
|
|
|
2024-06-06 06:16:42 +00:00
|
|
|
Stats *get_init_stats();
|
2024-06-04 02:59:36 +00:00
|
|
|
|
|
|
|
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-27 05:45:40 +00:00
|
|
|
extern void *(*real_realloc)(void *ptr, 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;
|
2024-06-26 05:01:51 +00:00
|
|
|
unsigned long long id;
|
|
|
|
static unsigned long long count;
|
2024-06-04 02:59:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
2024-06-27 05:45:40 +00:00
|
|
|
static void add_to_list(ListNode *tail, ListNode *node);
|
2024-06-04 06:08:33 +00:00
|
|
|
/// Returns true if removed.
|
2024-06-27 05:45:40 +00:00
|
|
|
static bool remove_from_list(ListNode *head,
|
|
|
|
void *ptr,
|
|
|
|
Stats *defer_handler = nullptr);
|
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-11-12 07:10:10 +00:00
|
|
|
~Stats();
|
|
|
|
|
|
|
|
// Disable copy.
|
|
|
|
Stats(Stats &other) = delete;
|
|
|
|
Stats& operator=(Stats &other) = delete;
|
|
|
|
|
|
|
|
// Disable move.
|
|
|
|
Stats(Stats &&other) = delete;
|
|
|
|
Stats& operator=(Stats &&other) = delete;
|
2024-06-04 02:59:36 +00:00
|
|
|
|
2024-06-04 06:08:33 +00:00
|
|
|
ListNode *malloced_list_head;
|
|
|
|
ListNode *malloced_list_tail;
|
2024-06-27 05:45:40 +00:00
|
|
|
ListNode *deferred_node;
|
2024-11-12 05:38:25 +00:00
|
|
|
void *recursive_mutex;
|
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-27 05:45:40 +00:00
|
|
|
void *do_realloc(void*, std::size_t size);
|
2024-06-26 05:01:51 +00:00
|
|
|
/// true on success.
|
|
|
|
bool do_free(void *ptr);
|
2024-06-04 02:59:36 +00:00
|
|
|
|
|
|
|
void print_status() const;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// vim: et sw=2 ts=2 sts=2
|