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.
11 #include <AllocationTracking.h>
13 #include <slab/Slab.h>
16 #include "kernel_debug_config.h"
21 #define TRACE_CACHE(cache, format, args...) \
22 dprintf("Cache[%p, %s] " format "\n", cache, cache->name , ##args)
24 #define TRACE_CACHE(cache, format, bananas...) do { } while (0)
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.
51 #if SLAB_ALLOCATION_TRACKING_AVAILABLE
55 class AllocationTrackingCallback
{
57 virtual ~AllocationTrackingCallback();
59 virtual bool ProcessTrackingInfo(
60 AllocationTrackingInfo
* info
,
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
79 fill_block(void* buffer
, size_t size
, uint32 pattern
)
84 size
&= ~(sizeof(pattern
) - 1);
85 for (size_t i
= 0; i
< size
/ sizeof(pattern
); i
++)
86 ((uint32
*)buffer
)[i
] = pattern
;
94 fill_allocated_block(void* buffer
, size_t size
)
96 #if PARANOID_KERNEL_MALLOC
97 return fill_block(buffer
, size
, 0xcccccccc);
105 fill_freed_block(void* buffer
, size_t size
)
107 #if PARANOID_KERNEL_FREE
108 return fill_block(buffer
, size
, 0xdeadbeef);
115 #endif // SLAB_DEBUG_H