headers/bsd: Add sys/queue.h.
[haiku.git] / src / system / libroot / posix / malloc_debug / malloc_debug_api.h
blobdc949a9dd99452f22fe865a172541092c417cbd9
1 /*
2 * Copyright 2015, Michael Lotz <mmlr@mlotz.ch>.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef MALLOC_DEBUG_API_H
6 #define MALLOC_DEBUG_API_H
8 #include <OS.h>
11 struct heap_implementation {
12 status_t (*init)();
13 void (*terminate_after)();
15 // Mandatory hooks
16 void* (*memalign)(size_t alignment, size_t size);
17 void* (*malloc)(size_t size);
18 void (*free)(void* address);
19 void* (*realloc)(void* address, size_t newSize);
21 // Hooks with default implementations
22 void* (*calloc)(size_t numElements, size_t size);
23 void* (*valloc)(size_t size);
24 int (*posix_memalign)(void** pointer, size_t alignment,
25 size_t size);
27 // Heap Debug API
28 status_t (*start_wall_checking)(int msInterval);
29 status_t (*stop_wall_checking)();
30 void (*set_paranoid_validation)(bool enabled);
31 void (*set_memory_reuse)(bool enabled);
32 void (*set_debugger_calls)(bool enabled);
33 void (*set_default_alignment)(size_t defaultAlignment);
34 void (*validate_heaps)();
35 void (*validate_walls)();
36 void (*dump_allocations)(bool statsOnly, thread_id thread);
37 void (*dump_heaps)(bool dumpAreas, bool dumpBins);
38 void* (*malloc_with_guard_page)(size_t size);
39 status_t (*get_allocation_info)(void* address, size_t *size,
40 thread_id *thread);
41 status_t (*set_dump_allocations_on_exit)(bool enabled);
42 status_t (*set_stack_trace_depth)(size_t stackTraceDepth);
46 extern heap_implementation __mallocDebugHeap;
47 extern heap_implementation __mallocGuardedHeap;
50 static inline bool
51 is_valid_alignment(size_t number)
53 // this cryptic line accepts zero and all powers of two
54 return ((~number + 1) | ((number << 1) - 1)) == ~0UL;
57 #endif // MALLOC_DEBUG_API_H