Module: Mesa
Branch: main
Commit: 5b767c890f841c2e1b958372771c3e787e59602b
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=5b767c890f841c2e1b958372771c3e787e59602b

Author: Caio Oliveira <[email protected]>
Date:   Fri Sep 29 15:34:02 2023 -0700

util: Add a canary to identify gc_ctx in debug mode

Acked-by: Marek Olšák <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25482>

---

 src/util/ralloc.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/util/ralloc.c b/src/util/ralloc.c
index 3b51b7fa474..1625744c043 100644
--- a/src/util/ralloc.c
+++ b/src/util/ralloc.c
@@ -550,6 +550,7 @@ ralloc_vasprintf_rewrite_tail(char **str, size_t *start, 
const char *fmt,
 /* The size of a slab. */
 #define SLAB_SIZE (32 * 1024)
 
+#define GC_CONTEXT_CANARY 0xAF6B6C83
 #define GC_CANARY 0xAF6B5B72
 
 enum gc_flags {
@@ -605,6 +606,10 @@ typedef struct gc_slab {
 } gc_slab;
 
 struct gc_ctx {
+#ifndef NDEBUG
+   unsigned canary;
+#endif
+
    /* Array of slabs for fixed-size allocations. Each slab tracks allocations
     * of specific sized blocks. User allocations are rounded up to the nearest
     * fixed size. slabs[N] contains allocations of size
@@ -671,6 +676,9 @@ gc_context(const void *parent)
       list_inithead(&ctx->slabs[i].slabs);
       list_inithead(&ctx->slabs[i].free_slabs);
    }
+#ifndef NDEBUG
+   ctx->canary = GC_CONTEXT_CANARY;
+#endif
    return ctx;
 }
 

Reply via email to