[haiku-commits] r35431 - in haiku/trunk: headers/posix src/system/libroot/posix/malloc_debug

  • From: mmlr@xxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 8 Feb 2010 02:27:21 +0100 (CET)

Author: mmlr
Date: 2010-02-08 02:27:21 +0100 (Mon, 08 Feb 2010)
New Revision: 35431
Changeset: http://dev.haiku-os.org/changeset/35431/haiku

Added:
   haiku/trunk/headers/posix/malloc_debug.h
Modified:
   haiku/trunk/src/system/libroot/posix/malloc_debug/heap.cpp
Log:
* 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.


Added: haiku/trunk/headers/posix/malloc_debug.h
===================================================================
--- haiku/trunk/headers/posix/malloc_debug.h                            (rev 0)
+++ haiku/trunk/headers/posix/malloc_debug.h    2010-02-08 01:27:21 UTC (rev 
35431)
@@ -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 */

Modified: haiku/trunk/src/system/libroot/posix/malloc_debug/heap.cpp
===================================================================
--- haiku/trunk/src/system/libroot/posix/malloc_debug/heap.cpp  2010-02-08 
00:47:11 UTC (rev 35430)
+++ haiku/trunk/src/system/libroot/posix/malloc_debug/heap.cpp  2010-02-08 
01:27:21 UTC (rev 35431)
@@ -246,15 +246,7 @@
 }
 
 
-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 @@
 }
 
 
-void
+static void
 heap_validate_walls()
 {
        for (uint32 classIndex = 0; classIndex < HEAP_CLASS_COUNT; 
classIndex++) {
@@ -1503,21 +1495,25 @@
 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 @@
 }
 
 
-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 @@
 //     #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)
 {


Other related posts: