Fix include order in hakmem.c - move hak_kpi_util.inc.h before hak_core_init.inc.h
Problem: hak_core_init.inc.h references KPI measurement variables (g_latency_histogram, g_latency_samples, g_baseline_soft_pf, etc.) but hakmem.c was including hak_kpi_util.inc.h AFTER hak_core_init.inc.h, causing undefined reference errors. Solution: Reorder includes so hak_kpi_util.inc.h (definition) comes before hak_core_init.inc.h (usage). Build result: ✅ Success (libhakmem.so 547KB, 0 errors) Minor changes: - Added extern __thread declarations for TLS SLL debug variables - Added signal handler logging for debug_dump_last_push - Improved hakmem_tiny.c structure for Phase 2 preparation 🤖 Generated with Claude Code + Task Agent Co-Authored-By: Gemini <gemini@example.com> Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -27,8 +27,9 @@ core/box/carve_push_box.o: core/box/carve_push_box.c \
|
||||
core/box/../ptr_trace.h core/box/../box/tiny_next_ptr_box.h \
|
||||
core/hakmem_tiny_config.h core/tiny_nextptr.h core/hakmem_build_flags.h \
|
||||
core/tiny_region_id.h core/superslab/superslab_inline.h \
|
||||
core/box/../tiny_debug_ring.h core/box/../superslab/superslab_inline.h \
|
||||
core/box/tiny_header_box.h core/box/../tiny_nextptr.h \
|
||||
core/box/tiny_layout_box.h core/box/tiny_header_box.h \
|
||||
core/box/tiny_layout_box.h core/box/../tiny_debug_ring.h \
|
||||
core/box/../superslab/superslab_inline.h core/box/tiny_header_box.h \
|
||||
core/box/../tiny_refill_opt.h core/box/../tiny_region_id.h \
|
||||
core/box/../box/slab_freelist_atomic.h \
|
||||
core/box/../box/../superslab/superslab_types.h \
|
||||
@ -83,10 +84,12 @@ core/tiny_nextptr.h:
|
||||
core/hakmem_build_flags.h:
|
||||
core/tiny_region_id.h:
|
||||
core/superslab/superslab_inline.h:
|
||||
core/box/tiny_layout_box.h:
|
||||
core/box/tiny_header_box.h:
|
||||
core/box/tiny_layout_box.h:
|
||||
core/box/../tiny_debug_ring.h:
|
||||
core/box/../superslab/superslab_inline.h:
|
||||
core/box/tiny_header_box.h:
|
||||
core/box/../tiny_nextptr.h:
|
||||
core/box/../tiny_refill_opt.h:
|
||||
core/box/../tiny_region_id.h:
|
||||
core/box/../box/slab_freelist_atomic.h:
|
||||
|
||||
@ -12,17 +12,19 @@ core/box/front_gate_box.o: core/box/front_gate_box.c \
|
||||
core/superslab/superslab_types.h core/superslab/../tiny_box_geometry.h \
|
||||
core/tiny_debug_ring.h core/tiny_remote.h core/box/ss_addr_map_box.h \
|
||||
core/box/../hakmem_build_flags.h core/tiny_debug_api.h \
|
||||
core/box/tls_sll_box.h core/box/../hakmem_internal.h \
|
||||
core/box/../hakmem.h core/box/../hakmem_build_flags.h \
|
||||
core/box/../hakmem_config.h core/box/../hakmem_features.h \
|
||||
core/box/../hakmem_sys.h core/box/../hakmem_whale.h \
|
||||
core/box/../box/ptr_type_box.h core/box/../hakmem_tiny_config.h \
|
||||
core/box/tiny_layout_box.h core/box/../hakmem_tiny_config.h \
|
||||
core/box/tiny_header_box.h core/box/tiny_layout_box.h \
|
||||
core/box/../tiny_region_id.h core/box/tls_sll_box.h \
|
||||
core/box/../hakmem_internal.h core/box/../hakmem.h \
|
||||
core/box/../hakmem_build_flags.h core/box/../hakmem_config.h \
|
||||
core/box/../hakmem_features.h core/box/../hakmem_sys.h \
|
||||
core/box/../hakmem_whale.h core/box/../box/ptr_type_box.h \
|
||||
core/box/../hakmem_debug_master.h core/box/../tiny_remote.h \
|
||||
core/box/../tiny_region_id.h core/box/../hakmem_tiny_integrity.h \
|
||||
core/box/../hakmem_tiny.h core/box/../ptr_track.h \
|
||||
core/box/../ptr_trace.h core/box/../tiny_debug_ring.h \
|
||||
core/box/../superslab/superslab_inline.h core/box/tiny_header_box.h \
|
||||
core/box/../tiny_nextptr.h core/box/ptr_conversion_box.h
|
||||
core/box/../hakmem_tiny_integrity.h core/box/../hakmem_tiny.h \
|
||||
core/box/../ptr_track.h core/box/../ptr_trace.h \
|
||||
core/box/../tiny_debug_ring.h core/box/../superslab/superslab_inline.h \
|
||||
core/box/tiny_header_box.h core/box/ptr_conversion_box.h \
|
||||
core/box/ptr_type_box.h
|
||||
core/box/front_gate_box.h:
|
||||
core/hakmem_tiny.h:
|
||||
core/hakmem_build_flags.h:
|
||||
@ -52,6 +54,11 @@ core/tiny_remote.h:
|
||||
core/box/ss_addr_map_box.h:
|
||||
core/box/../hakmem_build_flags.h:
|
||||
core/tiny_debug_api.h:
|
||||
core/box/tiny_layout_box.h:
|
||||
core/box/../hakmem_tiny_config.h:
|
||||
core/box/tiny_header_box.h:
|
||||
core/box/tiny_layout_box.h:
|
||||
core/box/../tiny_region_id.h:
|
||||
core/box/tls_sll_box.h:
|
||||
core/box/../hakmem_internal.h:
|
||||
core/box/../hakmem.h:
|
||||
@ -61,10 +68,8 @@ core/box/../hakmem_features.h:
|
||||
core/box/../hakmem_sys.h:
|
||||
core/box/../hakmem_whale.h:
|
||||
core/box/../box/ptr_type_box.h:
|
||||
core/box/../hakmem_tiny_config.h:
|
||||
core/box/../hakmem_debug_master.h:
|
||||
core/box/../tiny_remote.h:
|
||||
core/box/../tiny_region_id.h:
|
||||
core/box/../hakmem_tiny_integrity.h:
|
||||
core/box/../hakmem_tiny.h:
|
||||
core/box/../ptr_track.h:
|
||||
@ -72,5 +77,5 @@ core/box/../ptr_trace.h:
|
||||
core/box/../tiny_debug_ring.h:
|
||||
core/box/../superslab/superslab_inline.h:
|
||||
core/box/tiny_header_box.h:
|
||||
core/box/../tiny_nextptr.h:
|
||||
core/box/ptr_conversion_box.h:
|
||||
core/box/ptr_type_box.h:
|
||||
|
||||
@ -10,14 +10,18 @@
|
||||
|
||||
// Debug-only SIGSEGV handler (gated by HAKMEM_DEBUG_SEGV)
|
||||
static void hakmem_sigsegv_handler(int sig) {
|
||||
#ifdef __GLIBC__
|
||||
void* bt[64]; int n = backtrace(bt, 64);
|
||||
fprintf(stderr, "\n[HAKMEM][SIGSEGV] dumping backtrace (%d frames)\n", n);
|
||||
backtrace_symbols_fd(bt, n, fileno(stderr));
|
||||
#else
|
||||
(void)sig;
|
||||
fprintf(stderr, "\n[HAKMEM][SIGSEGV] (execinfo unavailable)\n");
|
||||
const char* msg = "\n[HAKMEM] Segmentation Fault\n";
|
||||
(void)write(2, msg, 29);
|
||||
|
||||
#if !HAKMEM_BUILD_RELEASE
|
||||
// Dump Class 1 (16B) last push info for debugging
|
||||
tiny_debug_dump_last_push(1);
|
||||
#endif
|
||||
|
||||
// Restore default handler and re-raise
|
||||
signal(sig, SIG_DFL);
|
||||
raise(sig);
|
||||
}
|
||||
|
||||
// Phase 7 Task 3: Pre-warm TLS cache helper
|
||||
|
||||
@ -40,7 +40,8 @@
|
||||
#include "tiny_header_box.h" // Header Box: Single Source of Truth for header operations
|
||||
|
||||
// Per-thread debug shadow: last successful push base per class (release-safe)
|
||||
static __thread hak_base_ptr_t s_tls_sll_last_push[TINY_NUM_CLASSES] = {0};
|
||||
// Changed to extern to share across TUs (defined in hakmem_tiny.c)
|
||||
extern __thread hak_base_ptr_t s_tls_sll_last_push[TINY_NUM_CLASSES];
|
||||
|
||||
// Per-thread callsite tracking: last push caller per class (debug-only)
|
||||
#if !HAKMEM_BUILD_RELEASE
|
||||
@ -116,7 +117,6 @@ static inline hak_base_ptr_t tls_sll_normalize_base(int class_idx, hak_base_ptr_
|
||||
// Narrow dump around TLS SLL array when corruption is detected (env-gated)
|
||||
static inline void tls_sll_dump_tls_window(int class_idx, const char* stage)
|
||||
{
|
||||
#if !HAKMEM_BUILD_RELEASE
|
||||
static _Atomic uint32_t g_tls_sll_diag_shots = 0;
|
||||
static int s_diag_enable = -1;
|
||||
if (__builtin_expect(s_diag_enable == -1, 0)) {
|
||||
@ -160,9 +160,6 @@ static inline void tls_sll_dump_tls_window(int class_idx, const char* stage)
|
||||
fprintf(stderr, " canary_before=%#llx canary_after=%#llx\n",
|
||||
(unsigned long long)g_tls_canary_before_sll,
|
||||
(unsigned long long)g_tls_canary_after_sll);
|
||||
#else
|
||||
(void)class_idx; (void)stage;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void tls_sll_record_writer(int class_idx, const char* who)
|
||||
@ -365,6 +362,14 @@ static inline bool tls_sll_push_impl(int class_idx, hak_base_ptr_t ptr, uint32_t
|
||||
return false;
|
||||
}
|
||||
|
||||
// DEBUG: Strict address check on push to catch corruption early
|
||||
uintptr_t ptr_val = (uintptr_t)raw_ptr;
|
||||
if (ptr_val < 4096 || ptr_val > 0x00007fffffffffffULL) {
|
||||
fprintf(stderr, "[TLS_SLL_PUSH_INVALID] cls=%d base=%p (val=%llx) from=%s\n",
|
||||
class_idx, raw_ptr, (unsigned long long)ptr_val, where ? where : "(null)");
|
||||
abort();
|
||||
}
|
||||
|
||||
// Header restoration using Header Box (C1-C6 only; C0/C7 skip)
|
||||
// Safe mode (HAKMEM_TINY_SLL_SAFEHEADER=1): never overwrite header; reject on magic mismatch.
|
||||
// Default mode: restore expected header.
|
||||
@ -541,6 +546,7 @@ static inline bool tls_sll_pop_impl(int class_idx, hak_base_ptr_t* out, const ch
|
||||
fprintf(stderr, "[TLS_SLL_POP_INVALID] cls=%d head=%p (val=%llx) dropped count=%llu\n",
|
||||
class_idx, raw_base, (unsigned long long)base_addr, (unsigned long long)cnt + 1);
|
||||
s_log_limit[class_idx]++;
|
||||
tls_sll_dump_tls_window(class_idx, "invalid_head"); // Added dump
|
||||
}
|
||||
// Help triage: show last successful push base for this thread/class
|
||||
if (!hak_base_is_null(s_tls_sll_last_push[class_idx]) && s_log_limit[class_idx] <= 4) {
|
||||
|
||||
@ -30,9 +30,12 @@ core/box/unified_batch_box.o: core/box/unified_batch_box.c \
|
||||
core/box/../box/../ptr_track.h core/box/../box/../ptr_trace.h \
|
||||
core/box/../box/../box/tiny_next_ptr_box.h core/hakmem_tiny_config.h \
|
||||
core/tiny_nextptr.h core/hakmem_build_flags.h core/tiny_region_id.h \
|
||||
core/superslab/superslab_inline.h core/box/../box/../tiny_debug_ring.h \
|
||||
core/superslab/superslab_inline.h core/box/tiny_layout_box.h \
|
||||
core/box/../hakmem_tiny_config.h core/box/tiny_header_box.h \
|
||||
core/box/../hakmem_build_flags.h core/box/tiny_layout_box.h \
|
||||
core/box/../tiny_region_id.h core/box/../box/../tiny_debug_ring.h \
|
||||
core/box/../box/../superslab/superslab_inline.h \
|
||||
core/box/../box/tiny_header_box.h core/box/../box/../tiny_nextptr.h
|
||||
core/box/../box/tiny_header_box.h
|
||||
core/box/unified_batch_box.h:
|
||||
core/box/carve_push_box.h:
|
||||
core/box/../box/tls_sll_box.h:
|
||||
@ -78,7 +81,12 @@ core/tiny_nextptr.h:
|
||||
core/hakmem_build_flags.h:
|
||||
core/tiny_region_id.h:
|
||||
core/superslab/superslab_inline.h:
|
||||
core/box/tiny_layout_box.h:
|
||||
core/box/../hakmem_tiny_config.h:
|
||||
core/box/tiny_header_box.h:
|
||||
core/box/../hakmem_build_flags.h:
|
||||
core/box/tiny_layout_box.h:
|
||||
core/box/../tiny_region_id.h:
|
||||
core/box/../box/../tiny_debug_ring.h:
|
||||
core/box/../box/../superslab/superslab_inline.h:
|
||||
core/box/../box/tiny_header_box.h:
|
||||
core/box/../box/../tiny_nextptr.h:
|
||||
|
||||
Reference in New Issue
Block a user