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;
26 ABTI_spinlock g_valgrind_id_list_lock = ABTI_SPINLOCK_STATIC_INITIALIZER();
27 ABTI_valgrind_id_list *gp_valgrind_id_list_head = NULL;
28 ABTI_valgrind_id_list *gp_valgrind_id_list_tail = NULL;
30 #include <valgrind/valgrind.h> 32 void ABTI_valgrind_register_stack(
const void *p_stack,
size_t size)
37 const void *p_start = (
char *)(p_stack);
38 const void *p_end = (
char *)(p_stack) + size;
40 ABTI_spinlock_acquire(&g_valgrind_id_list_lock);
41 ABTI_valgrind_id valgrind_id = VALGRIND_STACK_REGISTER(p_start, p_end);
42 ABTI_valgrind_id_list *p_valgrind_id_list =
43 (ABTI_valgrind_id_list *)malloc(
sizeof(ABTI_valgrind_id_list));
44 p_valgrind_id_list->p_stack = p_stack;
45 p_valgrind_id_list->valgrind_id = valgrind_id;
46 p_valgrind_id_list->p_next = 0;
47 if (!gp_valgrind_id_list_head) {
48 gp_valgrind_id_list_head = p_valgrind_id_list;
49 gp_valgrind_id_list_tail = p_valgrind_id_list;
51 gp_valgrind_id_list_tail->p_next = p_valgrind_id_list;
52 gp_valgrind_id_list_tail = p_valgrind_id_list;
54 LOG_DEBUG(
"valgrind : register stack %p (id = %d)\n", p_stack,
56 ABTI_spinlock_release(&g_valgrind_id_list_lock);
59 void ABTI_valgrind_unregister_stack(
const void *p_stack)
64 ABTI_spinlock_acquire(&g_valgrind_id_list_lock);
65 if (gp_valgrind_id_list_head->p_stack == p_stack) {
66 VALGRIND_STACK_DEREGISTER(gp_valgrind_id_list_head->valgrind_id);
67 ABTI_valgrind_id_list *p_next = gp_valgrind_id_list_head->p_next;
68 free(gp_valgrind_id_list_head);
69 gp_valgrind_id_list_head = p_next;
71 gp_valgrind_id_list_tail = NULL;
74 ABTI_valgrind_id_list *p_prev = gp_valgrind_id_list_head;
75 ABTI_valgrind_id_list *p_current = gp_valgrind_id_list_head->p_next;
78 if (p_current->p_stack == p_stack) {
79 LOG_DEBUG(
"valgrind : deregister stack %p (id = %d)\n", p_stack,
80 (
int)p_current->valgrind_id);
81 VALGRIND_STACK_DEREGISTER(p_current->valgrind_id);
82 p_prev->p_next = p_current->p_next;
84 gp_valgrind_id_list_tail = p_prev;
90 p_current = p_current->p_next;
92 ABTI_ASSERT(deregister_flag);
94 ABTI_spinlock_release(&g_valgrind_id_list_lock);
#define LOG_DEBUG(fmt,...)