* Adding malloc_debug.h that exposes the malloc_debug API.
* Moving some functions around, removing and adding others for the public API. I've written a blog post at haiku-os.org to go as documentation for this introducing the API and the other helpful bits. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35431 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010, Haiku Inc. All Rights Reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef MALLOC_DEBUG_H
|
||||||
|
#define MALLOC_DEBUG_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern status_t heap_debug_start_wall_checking(int msInterval);
|
||||||
|
extern status_t heap_debug_stop_wall_checking();
|
||||||
|
|
||||||
|
extern void heap_debug_set_paranoid_validation(bool enabled);
|
||||||
|
extern void heap_debug_validate_heaps();
|
||||||
|
extern void heap_debug_validate_walls();
|
||||||
|
|
||||||
|
extern void heap_debug_dump_allocations(bool statsOnly, thread_id thread);
|
||||||
|
extern void heap_debug_dump_heaps(bool dumpAreas, bool dumpBins);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* MALLOC_DEBUG_H */
|
||||||
@@ -246,15 +246,7 @@ dump_allocator(heap_allocator *heap, bool areas, bool bins)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
static void
|
||||||
dump_heap_list(int argc, char **argv)
|
|
||||||
{
|
|
||||||
for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++)
|
|
||||||
dump_allocator(sHeaps[i], true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
dump_allocations(bool statsOnly, thread_id thread)
|
dump_allocations(bool statsOnly, thread_id thread)
|
||||||
{
|
{
|
||||||
size_t totalSize = 0;
|
size_t totalSize = 0;
|
||||||
@@ -346,7 +338,7 @@ dump_allocations(bool statsOnly, thread_id thread)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
static void
|
||||||
heap_validate_walls()
|
heap_validate_walls()
|
||||||
{
|
{
|
||||||
for (uint32 classIndex = 0; classIndex < HEAP_CLASS_COUNT; classIndex++) {
|
for (uint32 classIndex = 0; classIndex < HEAP_CLASS_COUNT; classIndex++) {
|
||||||
@@ -1503,21 +1495,25 @@ heap_create_new_heap_area(heap_allocator *heap, const char *name, size_t size)
|
|||||||
static int32
|
static int32
|
||||||
heap_wall_checker(void *data)
|
heap_wall_checker(void *data)
|
||||||
{
|
{
|
||||||
|
int msInterval = (int32)data;
|
||||||
while (!sStopWallChecking) {
|
while (!sStopWallChecking) {
|
||||||
heap_validate_walls();
|
heap_validate_walls();
|
||||||
snooze(1 * 1000 * 1000);
|
snooze(msInterval * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - Heap Debug API
|
||||||
|
|
||||||
|
|
||||||
extern "C" status_t
|
extern "C" status_t
|
||||||
heap_debug_start_wall_checking()
|
heap_debug_start_wall_checking(int msInterval)
|
||||||
{
|
{
|
||||||
if (sWallCheckThread < 0) {
|
if (sWallCheckThread < 0) {
|
||||||
sWallCheckThread = spawn_thread(heap_wall_checker, "heap wall checker",
|
sWallCheckThread = spawn_thread(heap_wall_checker, "heap wall checker",
|
||||||
B_LOW_PRIORITY, NULL);
|
B_LOW_PRIORITY, (void *)msInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sWallCheckThread < 0)
|
if (sWallCheckThread < 0)
|
||||||
@@ -1537,23 +1533,46 @@ heap_debug_stop_wall_checking()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern "C" status_t
|
extern "C" void
|
||||||
heap_debug_set_paranoid_validation(bool enabled)
|
heap_debug_set_paranoid_validation(bool enabled)
|
||||||
{
|
{
|
||||||
sParanoidValidation = enabled;
|
sParanoidValidation = enabled;
|
||||||
return B_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern "C" void *
|
extern "C" void
|
||||||
sbrk_hook(long)
|
heap_debug_validate_heaps()
|
||||||
{
|
{
|
||||||
debug_printf("sbrk not supported on malloc debug\n");
|
for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++)
|
||||||
panic("sbrk not supported on malloc debug\n");
|
heap_validate_heap(sHeaps[i]);
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" void
|
||||||
|
heap_debug_validate_walls()
|
||||||
|
{
|
||||||
|
heap_validate_walls();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" void
|
||||||
|
heap_debug_dump_allocations(bool statsOnly, thread_id thread)
|
||||||
|
{
|
||||||
|
dump_allocations(statsOnly, thread);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" void
|
||||||
|
heap_debug_dump_heaps(bool dumpAreas, bool dumpBins)
|
||||||
|
{
|
||||||
|
for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++)
|
||||||
|
dump_allocator(sHeaps[i], dumpAreas, dumpBins);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - Init
|
||||||
|
|
||||||
|
|
||||||
extern "C" status_t
|
extern "C" status_t
|
||||||
__init_heap(void)
|
__init_heap(void)
|
||||||
{
|
{
|
||||||
@@ -1586,6 +1605,15 @@ __init_heap(void)
|
|||||||
// #pragma mark - Public API
|
// #pragma mark - Public API
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" void *
|
||||||
|
sbrk_hook(long)
|
||||||
|
{
|
||||||
|
debug_printf("sbrk not supported on malloc debug\n");
|
||||||
|
panic("sbrk not supported on malloc debug\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
memalign(size_t alignment, size_t size)
|
memalign(size_t alignment, size_t size)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user