diff --git a/core/box/free_local_box.c b/core/box/free_local_box.c index 23f65f2b..cb915c2c 100644 --- a/core/box/free_local_box.c +++ b/core/box/free_local_box.c @@ -30,6 +30,7 @@ void tiny_free_local_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void* void* base = (void*)((uint8_t*)ptr - 1); // Targeted header integrity check (env: HAKMEM_TINY_SLL_DIAG, C7 focus) +#if !HAKMEM_BUILD_RELEASE do { static int g_free_diag_en = -1; static _Atomic uint32_t g_free_diag_shot = 0; @@ -56,6 +57,7 @@ void tiny_free_local_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void* } } } while (0); +#endif if (__builtin_expect(tiny_refill_failfast_level() >= 2, 0)) { int actual_idx = slab_index_for(ss, base); @@ -77,6 +79,7 @@ void tiny_free_local_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void* void* prev = meta->freelist; // Detect suspicious prev before writing next (env-gated) +#if !HAKMEM_BUILD_RELEASE do { static int g_prev_diag_en = -1; static _Atomic uint32_t g_prev_diag_shot = 0; @@ -100,6 +103,7 @@ void tiny_free_local_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void* } } } while (0); +#endif // FREELIST CORRUPTION DEBUG: Validate pointer before writing if (__builtin_expect(tiny_refill_failfast_level() >= 2, 0)) { @@ -157,6 +161,7 @@ void tiny_free_local_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void* atomic_thread_fence(memory_order_release); // Optional freelist mask update on first push +#if !HAKMEM_BUILD_RELEASE do { static int g_mask_en = -1; if (__builtin_expect(g_mask_en == -1, 0)) { @@ -168,6 +173,7 @@ void tiny_free_local_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void* atomic_fetch_or_explicit(&ss->freelist_mask, bit, memory_order_release); } } while (0); +#endif // Track local free (debug helpers may be no-op) tiny_remote_track_on_local_free(ss, slab_idx, ptr, "local_free", my_tid); @@ -180,11 +186,15 @@ void tiny_free_local_box(SuperSlab* ss, int slab_idx, TinySlabMeta* meta, void* ss_mark_slab_empty(ss, slab_idx); // DEBUG LOGGING - Track when used reaches 0 +#if !HAKMEM_BUILD_RELEASE static int dbg = -1; if (__builtin_expect(dbg == -1, 0)) { const char* e = getenv("HAKMEM_SS_FREE_DEBUG"); dbg = (e && *e && *e != '0') ? 1 : 0; } +#else + const int dbg = 0; +#endif if (dbg == 1) { fprintf(stderr, "[FREE_LOCAL_BOX] EMPTY detected: cls=%u ss=%p slab=%d empty_mask=0x%x empty_count=%u\n", cls, (void*)ss, slab_idx, ss->empty_mask, ss->empty_count);