-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalloc_stats.h
More file actions
49 lines (41 loc) · 1.36 KB
/
alloc_stats.h
File metadata and controls
49 lines (41 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef MSTAT_H
#define MSTAT_H
#include <stdbool.h>
#include <stddef.h>
typedef struct {
size_t alloc;
size_t calloc;
size_t free;
size_t realloc;
} mstat_t;
extern bool VERBOSE;
extern mstat_t MEM_STAT;
/* From valgrind's docs:
*
* The GNU C library (`libc.so`), which is used by all programs, may allocate
* memory for its own uses. Usually it doesn't bother to free that memory when
* the program ends—there would be no point, since the Linux kernel reclaims
* all process resources when a process exits anyway, so it would just slow
* things down.
*
* The glibc authors realised that this behaviour causes leak checkers, such as
* Valgrind, to falsely report leaks in glibc, when a leak check is done at
* exit. In order to avoid this, they provided a routine called
* `__libc_freeres` specifically to make glibc release all memory it has
* allocated. Memcheck therefore tries to run `__libc_freeres` at exit.
**/
extern void __libc_freeres(void);
void resolve_symbol(void **funcp, const char *sym_name);
void print_stats(void);
void lookup_env(void);
/* wrapped */
void *calloc(size_t nmemb, size_t size);
void *malloc(size_t size);
void *realloc(void *ptr, size_t size);
void *reallocarray(void *ptr, size_t nmemb, size_t size);
void free(void *ptr);
/* exit */
void abort(void);
void _exit(int status);
void exit(int status);
#endif