Phase 7-1.1: Fix 1024B crash (header validation + malloc fallback)
Fixed critical bugs preventing Phase 7 from working with 1024B allocations. ## Bug Fixes (by Task Agent Ultrathink) 1. **Header Validation Missing in Release Builds** - `core/tiny_region_id.h:73-97` - Removed `#if !HAKMEM_BUILD_RELEASE` - Always validate magic byte and class_idx (prevents SEGV on Mid/Large) 2. **1024B Malloc Fallback Missing** - `core/box/hak_alloc_api.inc.h:35-49` - Direct fallback to malloc - Phase 7 rejects 1024B (needs header) → skip ACE → use malloc ## Test Results | Test | Result | |------|--------| | 128B, 512B, 1023B (Tiny) | +39%~+436% ✅ | | 1024B only (100 allocs) | 100% success ✅ | | Mixed 128B+1024B (200) | 100% success ✅ | | bench_random_mixed 1024B | Still crashes ❌ | ## Known Issue `bench_random_mixed` with 1024B still crashes (intermittent SEGV). Simple tests pass, suggesting issue is with complex allocation patterns. Investigation pending. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Task Agent Ultrathink
This commit is contained in:
@ -29,7 +29,24 @@ inline void* hak_alloc_at(size_t size, hak_callsite_t site) {
|
||||
HKM_TIME_END(HKM_CAT_TINY_ALLOC, t_tiny);
|
||||
#endif
|
||||
if (tiny_ptr) { hkm_ace_track_alloc(); return tiny_ptr; }
|
||||
|
||||
// Phase 7: If Tiny rejects size <= TINY_MAX_SIZE (e.g., 1024B needs header),
|
||||
// skip Mid/ACE and route directly to malloc fallback
|
||||
#if HAKMEM_TINY_HEADER_CLASSIDX
|
||||
if (size <= TINY_MAX_SIZE) {
|
||||
// Tiny rejected this size (likely 1024B), use malloc directly
|
||||
static int log_count = 0;
|
||||
if (log_count < 3) {
|
||||
fprintf(stderr, "[DEBUG] Phase 7: tiny_alloc(%zu) rejected, using malloc fallback\n", size);
|
||||
log_count++;
|
||||
}
|
||||
void* fallback_ptr = hak_alloc_malloc_impl(size);
|
||||
if (fallback_ptr) return fallback_ptr;
|
||||
// If malloc fails, continue to other fallbacks below
|
||||
}
|
||||
#else
|
||||
static int log_count = 0; if (log_count < 3) { fprintf(stderr, "[DEBUG] tiny_alloc(%zu) returned NULL, falling back\n", size); log_count++; }
|
||||
#endif
|
||||
}
|
||||
|
||||
hkm_size_hist_record(size);
|
||||
|
||||
Reference in New Issue
Block a user