bootloader heap: Actually implement DEBUG_ALLOCATIONS.

The old define was really "check heap integrity", so it's split off.
In the userland test harness, this takes the total time spent in
the allocator from around 1ms to 14ms for all the allocations used
during a boot with "nightly" profile, so it seems acceptable to
enable it under KDEBUG.

Tested with both BIOS and EFI bootloaders, still works.
This commit is contained in:
Augustin Cavalier
2025-01-07 17:30:28 -05:00
parent 0f843fe15a
commit 7137fc03b2
2 changed files with 14 additions and 2 deletions
@@ -266,6 +266,9 @@ public:
#ifdef DEBUG_MAX_HEAP_USAGE
fMaxHeapUsage = std::max(fMaxHeapUsage, fMaxHeapSize - fAvailable);
#endif
#ifdef DEBUG_ALLOCATIONS
memset(allocated, 0xcc, chunk->Size());
#endif
return allocated;
}
@@ -306,7 +309,7 @@ public:
FreeChunk* freedChunk = FreeChunk::SetToAllocated(allocated);
#ifdef DEBUG_ALLOCATIONS
#ifdef DEBUG_VALIDATE_HEAP_ON_FREE
if (freedChunk->Size() > (fMaxHeapSize - fAvailable)) {
panic("freed chunk %p clobbered (%#zx)!\n", freedChunk,
freedChunk->Size());
@@ -321,6 +324,10 @@ public:
}
}
#endif
#ifdef DEBUG_ALLOCATIONS
for (uint32 i = 0; i < (freedChunk->Size() / 4); i++)
((uint32*)allocated)[i] = 0xdeadbeef;
#endif
// try to join the new free chunk with an existing one
// it may be joined with up to two chunks