8 #ifdef HAVE_VALGRIND_SUPPORT
17 typedef size_t ABTI_valgrind_id;
19 typedef struct ABTI_valgrind_id_list_t {
21 ABTI_valgrind_id valgrind_id;
22 struct ABTI_valgrind_id_list_t *p_next;
23 } ABTI_valgrind_id_list;
28 static int g_num_malloc_failures = 0;
29 static ABTI_valgrind_id_list *gp_valgrind_id_list_head = NULL;
30 static ABTI_valgrind_id_list *gp_valgrind_id_list_tail = NULL;
32 #include <valgrind/valgrind.h>
34 void ABTI_valgrind_register_stack(
const void *p_stack,
size_t size)
39 const void *p_start = (
char *)(p_stack);
40 const void *p_end = (
char *)(p_stack) + size;
43 ABTI_valgrind_id_list *p_valgrind_id_list =
44 (ABTI_valgrind_id_list *)malloc(
sizeof(ABTI_valgrind_id_list));
45 if (p_valgrind_id_list) {
46 ABTI_valgrind_id valgrind_id = VALGRIND_STACK_REGISTER(p_start, p_end);
47 p_valgrind_id_list->p_stack = p_stack;
48 p_valgrind_id_list->valgrind_id = valgrind_id;
49 p_valgrind_id_list->p_next = 0;
50 if (!gp_valgrind_id_list_head) {
51 gp_valgrind_id_list_head = p_valgrind_id_list;
52 gp_valgrind_id_list_tail = p_valgrind_id_list;
54 gp_valgrind_id_list_tail->p_next = p_valgrind_id_list;
55 gp_valgrind_id_list_tail = p_valgrind_id_list;
57 LOG_DEBUG(
"valgrind : register stack %p (id = %d)\n", p_stack,
62 g_num_malloc_failures++;
67 void ABTI_valgrind_unregister_stack(
const void *p_stack)
73 if (gp_valgrind_id_list_head->p_stack == p_stack) {
74 VALGRIND_STACK_DEREGISTER(gp_valgrind_id_list_head->valgrind_id);
75 ABTI_valgrind_id_list *p_next = gp_valgrind_id_list_head->p_next;
76 free(gp_valgrind_id_list_head);
77 gp_valgrind_id_list_head = p_next;
79 gp_valgrind_id_list_tail = NULL;
82 ABTI_valgrind_id_list *p_prev = gp_valgrind_id_list_head;
83 ABTI_valgrind_id_list *p_current = gp_valgrind_id_list_head->p_next;
86 if (p_current->p_stack == p_stack) {
87 LOG_DEBUG(
"valgrind : deregister stack %p (id = %d)\n", p_stack,
88 (
int)p_current->valgrind_id);
89 VALGRIND_STACK_DEREGISTER(p_current->valgrind_id);
90 p_prev->p_next = p_current->p_next;
92 gp_valgrind_id_list_tail = p_prev;
98 p_current = p_current->p_next;
100 if (!deregister_flag) {
104 g_num_malloc_failures--;