libroot_debug: Merge guarded heap into libroot_debug.
[haiku.git] / src / system / kernel / slab / slab_debug.h
blobb0dd769a6c4754c151d9c36ee0f1c7ee37d4a5a9
1 /*
2 * Copyright 2011, Michael Lotz <mmlr@mlotz.ch>.
3 * Copyright 2011, Ingo Weinhold <ingo_weinhold@gmx.de>.
5 * Distributed under the terms of the MIT License.
6 */
7 #ifndef SLAB_DEBUG_H
8 #define SLAB_DEBUG_H
11 #include <AllocationTracking.h>
12 #include <debug.h>
13 #include <slab/Slab.h>
14 #include <tracing.h>
16 #include "kernel_debug_config.h"
19 //#define TRACE_SLAB
20 #ifdef TRACE_SLAB
21 #define TRACE_CACHE(cache, format, args...) \
22 dprintf("Cache[%p, %s] " format "\n", cache, cache->name , ##args)
23 #else
24 #define TRACE_CACHE(cache, format, bananas...) do { } while (0)
25 #endif
28 #define COMPONENT_PARANOIA_LEVEL OBJECT_CACHE_PARANOIA
29 #include <debug_paranoia.h>
32 // Macros determining whether allocation tracking is actually available.
33 #define SLAB_OBJECT_CACHE_ALLOCATION_TRACKING (SLAB_ALLOCATION_TRACKING != 0 \
34 && SLAB_OBJECT_CACHE_TRACING != 0 \
35 && SLAB_OBJECT_CACHE_TRACING_STACK_TRACE > 0)
36 // The object cache code needs to do allocation tracking.
37 #define SLAB_MEMORY_MANAGER_ALLOCATION_TRACKING (SLAB_ALLOCATION_TRACKING != 0 \
38 && SLAB_MEMORY_MANAGER_TRACING != 0 \
39 && SLAB_MEMORY_MANAGER_TRACING_STACK_TRACE > 0)
40 // The memory manager code needs to do allocation tracking.
41 #define SLAB_ALLOCATION_TRACKING_AVAILABLE \
42 (SLAB_OBJECT_CACHE_ALLOCATION_TRACKING \
43 || SLAB_MEMORY_MANAGER_ALLOCATION_TRACKING)
44 // Guards code that is needed for either object cache or memory manager
45 // allocation tracking.
48 struct object_depot;
51 #if SLAB_ALLOCATION_TRACKING_AVAILABLE
53 namespace BKernel {
55 class AllocationTrackingCallback {
56 public:
57 virtual ~AllocationTrackingCallback();
59 virtual bool ProcessTrackingInfo(
60 AllocationTrackingInfo* info,
61 void* allocation,
62 size_t allocationSize) = 0;
67 using BKernel::AllocationTrackingCallback;
69 #endif // SLAB_ALLOCATION_TRACKING_AVAILABLE
72 void dump_object_depot(object_depot* depot);
73 int dump_object_depot(int argCount, char** args);
74 int dump_depot_magazine(int argCount, char** args);
77 #if PARANOID_KERNEL_MALLOC || PARANOID_KERNEL_FREE
78 static inline void*
79 fill_block(void* buffer, size_t size, uint32 pattern)
81 if (buffer == NULL)
82 return NULL;
84 size &= ~(sizeof(pattern) - 1);
85 for (size_t i = 0; i < size / sizeof(pattern); i++)
86 ((uint32*)buffer)[i] = pattern;
88 return buffer;
90 #endif
93 static inline void*
94 fill_allocated_block(void* buffer, size_t size)
96 #if PARANOID_KERNEL_MALLOC
97 return fill_block(buffer, size, 0xcccccccc);
98 #else
99 return buffer;
100 #endif
104 static inline void*
105 fill_freed_block(void* buffer, size_t size)
107 #if PARANOID_KERNEL_FREE
108 return fill_block(buffer, size, 0xdeadbeef);
109 #else
110 return buffer;
111 #endif
115 #endif // SLAB_DEBUG_H