Phase 15: Box BenchMeta separation + ExternalGuard debug + investigation report
- Implement Box BenchMeta pattern in bench_random_mixed.c (BENCH_META_CALLOC/FREE) - Add enhanced debug logging to external_guard_box.h (caller tracking, FG classification) - Document investigation in PHASE15_BUG_ANALYSIS.md Issue: Page-aligned MIDCAND pointer not in SuperSlab registry → ExternalGuard → crash Hypothesis: May be pre-existing SuperSlab bug (not Phase 15-specific) Next: Test in Phase 14-C to verify
This commit is contained in:
@ -24,6 +24,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/mman.h>
|
||||
#include "front_gate_v2.h" // Phase 15: For fg_classification_t types
|
||||
|
||||
// ENV control: mincore enable/disable
|
||||
static inline int external_guard_mincore_enabled(void) {
|
||||
@ -87,8 +88,34 @@ static inline int external_guard_try_free(void* ptr) {
|
||||
g_external_guard_stats.total_calls++;
|
||||
|
||||
if (external_guard_log_enabled()) {
|
||||
fprintf(stderr, "[ExternalGuard] ptr=%p (call #%lu)\n",
|
||||
ptr, g_external_guard_stats.total_calls);
|
||||
// PHASE 15: Track caller address for debugging (ChatGPT advice)
|
||||
void* caller0 = __builtin_return_address(0);
|
||||
void* caller1 = __builtin_return_address(1);
|
||||
fprintf(stderr, "[ExternalGuard] ptr=%p offset_in_page=0x%lx (call #%lu)\n",
|
||||
ptr, (uintptr_t)ptr & 0xFFF, g_external_guard_stats.total_calls);
|
||||
fprintf(stderr, "[ExternalGuard] Stack: [0]=%p [1]=%p\n", caller0, caller1);
|
||||
|
||||
// Debug: Read header at ptr-1
|
||||
if ((uintptr_t)ptr >= 4096 && ((uintptr_t)ptr & 0xFFF) != 0) {
|
||||
uint8_t header = *((uint8_t*)ptr - 1);
|
||||
fprintf(stderr, "[ExternalGuard] header at ptr-1 = 0x%02x (magic=0x%02x class=%d)\n",
|
||||
header, header & 0xf0, header & 0x0f);
|
||||
}
|
||||
|
||||
// Debug: Check if this looks like a HAKMEM allocation
|
||||
extern SuperSlab* hak_super_lookup(void*);
|
||||
SuperSlab* ss = hak_super_lookup(ptr);
|
||||
fprintf(stderr, "[ExternalGuard] hak_super_lookup(ptr) = %p\n", (void*)ss);
|
||||
if (ss) {
|
||||
fprintf(stderr, "[ExternalGuard] HAKMEM SS FOUND! ptr=%p ss=%p magic=0x%x class=%d\n",
|
||||
ptr, (void*)ss, ss->magic, ss->slabs ? ss->slabs[0].class_idx : -1);
|
||||
}
|
||||
|
||||
// Debug: Check FrontGate classification (types defined in front_gate_v2.h)
|
||||
fg_classification_t fg = fg_classify_domain(ptr);
|
||||
const char* domain_name[] = {"TINY", "POOL", "MIDCAND", "EXTERNAL"};
|
||||
fprintf(stderr, "[ExternalGuard] FrontGate classification: domain=%s class_idx=%d\n",
|
||||
domain_name[fg.domain], fg.class_idx);
|
||||
}
|
||||
|
||||
// Safety check: is memory mapped?
|
||||
|
||||
Reference in New Issue
Block a user