malloc_debug: Implement alloc/free stack traces in guarded heap.

When configured to do so (using heap_debug_set_stack_trace_depth(depth)
or MALLOC_DEBUG=s<depth>) the guarded heap now captures stack traces on
alloc and free.

A crash due to hitting a guard page or an already freed page now dumps
these stack traces. In the case of use-after-free one can therefore see
both where the allocation was done and where it was freed.

Note that there is a hardcoded maximum stack trace depth of 50 and that
the alloc stack trace takes away space from the free stack trace which
uses up the rest of that maximum.
This commit is contained in:
Michael Lotz
2015-04-10 16:28:42 +02:00
parent f4bd38257b
commit 158e20e60e
3 changed files with 122 additions and 0 deletions
+2
View File
@@ -30,6 +30,8 @@ void *heap_debug_malloc_with_guard_page(size_t size);
status_t heap_debug_get_allocation_info(void *address, size_t *size,
thread_id *thread);
status_t heap_debug_set_stack_trace_depth(size_t stackTraceDepth);
#ifdef __cplusplus
}
#endif