Skip to content

Commit 8b6042f

Browse files
committed
implement valgrind macros used in critnib
1 parent 179eb8b commit 8b6042f

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

src/critnib/critnib.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ struct critnib_leaf {
119119

120120
struct critnib {
121121
struct critnib_node *root;
122-
uint64_t remove_count;
123122

124123
/* pool of freed nodes: singly linked list, next at child[0] */
125124
struct critnib_node *deleted_node;
@@ -129,6 +128,8 @@ struct critnib {
129128
struct critnib_node *pending_del_nodes[DELETED_LIFE];
130129
struct critnib_leaf *pending_del_leaves[DELETED_LIFE];
131130

131+
uint64_t remove_count;
132+
132133
struct utils_mutex_t mutex; /* writes/removes */
133134
};
134135

@@ -173,8 +174,8 @@ struct critnib *critnib_new(void) {
173174
goto err_free_critnib;
174175
}
175176

176-
VALGRIND_HG_DRD_DISABLE_CHECKING(&c->root, sizeof(c->root));
177-
VALGRIND_HG_DRD_DISABLE_CHECKING(&c->remove_count, sizeof(c->remove_count));
177+
utils_annotate_memory_no_check(&c->root, sizeof(c->root));
178+
utils_annotate_memory_no_check(&c->remove_count, sizeof(c->remove_count));
178179

179180
return c;
180181
err_free_critnib:
@@ -259,7 +260,7 @@ static struct critnib_node *alloc_node(struct critnib *__restrict c) {
259260
struct critnib_node *n = c->deleted_node;
260261

261262
c->deleted_node = n->child[0];
262-
VALGRIND_ANNOTATE_NEW_MEMORY(n, sizeof(*n));
263+
utils_annotate_memory_new(n, sizeof(*n));
263264

264265
return n;
265266
}
@@ -290,7 +291,7 @@ static struct critnib_leaf *alloc_leaf(struct critnib *__restrict c) {
290291
struct critnib_leaf *k = c->deleted_leaf;
291292

292293
c->deleted_leaf = k->value;
293-
VALGRIND_ANNOTATE_NEW_MEMORY(k, sizeof(*k));
294+
utils_annotate_memory_new(k, sizeof(*k));
294295

295296
return k;
296297
}
@@ -315,7 +316,7 @@ int critnib_insert(struct critnib *c, word key, void *value, int update) {
315316
return ENOMEM;
316317
}
317318

318-
VALGRIND_HG_DRD_DISABLE_CHECKING(k, sizeof(struct critnib_leaf));
319+
utils_annotate_memory_no_check(k, sizeof(struct critnib_leaf));
319320

320321
k->key = key;
321322
k->value = value;
@@ -376,7 +377,7 @@ int critnib_insert(struct critnib *c, word key, void *value, int update) {
376377

377378
return ENOMEM;
378379
}
379-
VALGRIND_HG_DRD_DISABLE_CHECKING(m, sizeof(struct critnib_node));
380+
utils_annotate_memory_no_check(m, sizeof(struct critnib_node));
380381

381382
for (int i = 0; i < SLNODES; i++) {
382383
m->child[i] = NULL;

src/utils/utils_common.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ typedef enum umf_purge_advise_t {
5353
#define ASSERT_IS_ALIGNED(value, align) \
5454
DO_WHILE_EXPRS(assert(IS_ALIGNED(value, align)))
5555

56-
#define VALGRIND_ANNOTATE_NEW_MEMORY(p, s) DO_WHILE_EMPTY
57-
#define VALGRIND_HG_DRD_DISABLE_CHECKING(p, s) DO_WHILE_EMPTY
58-
5956
#ifdef _WIN32 /* Windows */
6057

6158
#define __TLS __declspec(thread)

src/utils/utils_sanitizers.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2024 Intel Corporation
3+
* Copyright (C) 2024-2025 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -168,6 +168,24 @@ static inline void utils_annotate_memory_inaccessible(void *ptr, size_t size) {
168168
#endif
169169
}
170170

171+
static inline void utils_annotate_memory_new(void *ptr, size_t size) {
172+
#ifdef UMF_VG_DRD_ENABLED
173+
ANNOTATE_NEW_MEMORY(ptr, size);
174+
#else
175+
(void)ptr;
176+
(void)size;
177+
#endif
178+
}
179+
180+
static inline void utils_annotate_memory_no_check(void *ptr, size_t size) {
181+
#ifdef UMF_VG_HELGRIND_ENABLED
182+
VALGRIND_HG_DISABLE_CHECKING(ptr, size);
183+
#else
184+
(void)ptr;
185+
(void)size;
186+
#endif
187+
}
188+
171189
#ifdef __cplusplus
172190
}
173191
#endif

0 commit comments

Comments
 (0)