simple allocation debugger
This can be enabled by using the Tracking::Debug policy, currently this just fills allocation on alloc() and free(), which is useful to help detect access to uninitialized memory and use after free. Now enabled by default in libfilament allocators on debug builds. This caught uninitialized access in the froxelizer.
This commit is contained in:
committed by
Mathias Agopian
parent
c0de0ca36d
commit
844dde4e6d
@@ -125,6 +125,15 @@ AtomicFreeList::AtomicFreeList(void* begin, void* end,
|
||||
mHead.store({ int32_t(head - mStorage), 0 });
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
void TrackingPolicy::HighWatermark::onAlloc(
|
||||
void* p, size_t size, size_t alignment, size_t extra) noexcept {
|
||||
if (!mBase) { mBase = p; }
|
||||
mCurrent += uint32_t(size);
|
||||
mHighWaterMark = mCurrent > mHighWaterMark ? mCurrent : mHighWaterMark;
|
||||
}
|
||||
|
||||
TrackingPolicy::HighWatermark::~HighWatermark() noexcept {
|
||||
size_t wm = mHighWaterMark;
|
||||
size_t wmpct = wm / (mSize / 100);
|
||||
@@ -134,4 +143,29 @@ TrackingPolicy::HighWatermark::~HighWatermark() noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
void TrackingPolicy::Debug::onAlloc(void* p, size_t size, size_t alignment, size_t extra) noexcept {
|
||||
memset(p, 0xeb, size);
|
||||
HighWatermark::onAlloc(p, size, alignment, extra);
|
||||
}
|
||||
|
||||
void TrackingPolicy::Debug::onFree(void* p, size_t size) noexcept {
|
||||
memset(p, 0xef, size);
|
||||
HighWatermark::onFree(p, size);
|
||||
}
|
||||
|
||||
void TrackingPolicy::Debug::onReset() noexcept {
|
||||
if (mBase) {
|
||||
memset(mBase, 0xec, mSize);
|
||||
}
|
||||
HighWatermark::onReset();
|
||||
}
|
||||
|
||||
void TrackingPolicy::Debug::onRewind(void* addr) noexcept {
|
||||
if (mBase) {
|
||||
memset(addr, 0x55, uintptr_t(mBase) + mSize - uintptr_t(addr));
|
||||
}
|
||||
HighWatermark::onRewind(addr);
|
||||
}
|
||||
|
||||
|
||||
} // namespace utils
|
||||
|
||||
Reference in New Issue
Block a user