From f6a6245c8936995c9b23ab65a5b3854ea6a5088b Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Mon, 8 Feb 2010 01:27:21 +0000 Subject: [PATCH] * 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 --- headers/posix/malloc_debug.h | 26 +++++++ .../libroot/posix/malloc_debug/heap.cpp | 68 +++++++++++++------ 2 files changed, 74 insertions(+), 20 deletions(-) create mode 100644 headers/posix/malloc_debug.h diff --git a/headers/posix/malloc_debug.h b/headers/posix/malloc_debug.h new file mode 100644 index 0000000000..f26f760575 --- /dev/null +++ b/headers/posix/malloc_debug.h @@ -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 */ diff --git a/src/system/libroot/posix/malloc_debug/heap.cpp b/src/system/libroot/posix/malloc_debug/heap.cpp index 943f28bc0a..5e20f1effd 100644 --- a/src/system/libroot/posix/malloc_debug/heap.cpp +++ b/src/system/libroot/posix/malloc_debug/heap.cpp @@ -246,15 +246,7 @@ dump_allocator(heap_allocator *heap, bool areas, bool bins) } -void -dump_heap_list(int argc, char **argv) -{ - for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) - dump_allocator(sHeaps[i], true, true); -} - - -void +static void dump_allocations(bool statsOnly, thread_id thread) { size_t totalSize = 0; @@ -346,7 +338,7 @@ dump_allocations(bool statsOnly, thread_id thread) } -void +static void heap_validate_walls() { 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 heap_wall_checker(void *data) { + int msInterval = (int32)data; while (!sStopWallChecking) { heap_validate_walls(); - snooze(1 * 1000 * 1000); + snooze(msInterval * 1000); } return 0; } +// #pragma mark - Heap Debug API + + extern "C" status_t -heap_debug_start_wall_checking() +heap_debug_start_wall_checking(int msInterval) { if (sWallCheckThread < 0) { sWallCheckThread = spawn_thread(heap_wall_checker, "heap wall checker", - B_LOW_PRIORITY, NULL); + B_LOW_PRIORITY, (void *)msInterval); } 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) { sParanoidValidation = enabled; - return B_OK; } -extern "C" void * -sbrk_hook(long) +extern "C" void +heap_debug_validate_heaps() { - debug_printf("sbrk not supported on malloc debug\n"); - panic("sbrk not supported on malloc debug\n"); - return NULL; + for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) + heap_validate_heap(sHeaps[i]); } +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 __init_heap(void) { @@ -1586,6 +1605,15 @@ __init_heap(void) // #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 * memalign(size_t alignment, size_t size) {