summaryrefslogtreecommitdiff
path: root/libheap
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-07-05 14:33:57 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-07-08 10:18:32 -0600
commita91d0bd85150a3c5f2e0e7bff733c6b9c435a8cc (patch)
tree9394c567e28da2f8e5567e32a970096f3d5a4b6a /libheap
parent72b9036dc961d9fe7e0e9deb12e87f121a4d0ccf (diff)
Diffstat (limited to 'libheap')
-rw-r--r--libheap/malloc.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/libheap/malloc.c b/libheap/malloc.c
index 9a4a07e..676f754 100644
--- a/libheap/malloc.c
+++ b/libheap/malloc.c
@@ -25,6 +25,9 @@
#endif
#endif
+#if CONFIG_HEAP_VALGRIND
+ #include <valgrind/valgrind.h>
+#endif
#if CONFIG_COROUTINE_VALGRIND
#include <valgrind/memcheck.h>
#endif
@@ -176,6 +179,8 @@ static bool heap_alloc_can_alloc(struct waiter *waiter, bool check [[maybe_unuse
return false;
}
+#define REDZONE 0
+
void *__lm_heap_aligned_realloc(void *ptr, size_t align, size_t size) {
heap_ensure_init();
@@ -308,6 +313,13 @@ void *__lm_heap_aligned_realloc(void *ptr, size_t align, size_t size) {
if (mode == MODE_SIMPLE && ptr)
__lm_heap_free(ptr);
+#if CONFIG_HEAP_VALGRIND
+ if (old_rec && choice == old_rec)
+ VALGRIND_RESIZEINPLACE_BLOCK(ret, old_size, heap_record_size(choice), REDZONE);
+ else
+ VALGRIND_MALLOCLIKE_BLOCK(ret, heap_record_size(choice), REDZONE, true);
+#endif
+
/* return ====================*/
if (heap_meta.waiters.front &&
heap_alloc_can_alloc(&heap_meta.waiters.front->val, false))
@@ -349,6 +361,10 @@ void __lm_heap_free(void *ptr) {
memset(onext, 0, sizeof(struct record));
}
+#if CONFIG_HEAP_VALGRIND
+ VALGRIND_FREELIKE_BLOCK(ptr, REDZONE);
+#endif
+
if (!heap_meta.unpausing &&
heap_meta.waiters.front &&
(heap_record_fits(prev2, &heap_meta.waiters.front->val, true) ||