20 #ifndef SLAM_ALLOCATOR_H 21 #define SLAM_ALLOCATOR_H 29 #include "pedigree/kernel/Spinlock.h" 30 #include "pedigree/kernel/compiler.h" 31 #include "pedigree/kernel/processor/types.h" 33 #ifdef PEDIGREE_BENCHMARK 36 uintptr_t getHeapBase();
37 uintptr_t getHeapEnd();
38 void getPageAt(
void *addr);
39 void unmapPage(
void *page);
51 #define SLAB_MINIMUM_SIZE (4096 * SLAB_SIZE) 61 #define MAGIC_TYPE uintptr_t 64 #define MAGIC_VALUE 0xb00b1e55ULL 67 #define ABSOLUTE_MINIMUM_SIZE 64 68 #define ALL_HEADERS_SIZE \ 69 (sizeof(SlamCache::Node) + sizeof(SlamAllocator::AllocHeader) + \ 70 sizeof(SlamAllocator::AllocFooter)) 71 #define OBJECT_MINIMUM_SIZE \ 72 (ALL_HEADERS_SIZE < ABSOLUTE_MINIMUM_SIZE ? ABSOLUTE_MINIMUM_SIZE : \ 76 #define DEBUGGING_SLAB_ALLOCATOR 0 79 #define TEMP_MAGIC 0x67845753 83 #ifdef USE_DEBUG_ALLOCATOR 84 #define OVERRUN_CHECK 0 86 #define OVERRUN_CHECK 1 91 #define VIGILANT_OVERRUN_CHECK 0 93 #define VIGILANT_MAGIC 0x1337cafe 97 #define CRIPPLINGLY_VIGILANT 0 103 #define BOCHS_MAGIC_WATCHPOINTS 0 108 #define SCRIBBLE_FREED_BLOCKS 1 111 #define WARN_PAGE_SIZE_OR_LARGER 0 117 #define SLABS_FOR_HUGE_ALLOCS 0 120 #define VERBOSE_ISPOINTERVALID 0 126 #define EVERY_ALLOCATION_IS_A_SLAB 0 130 #ifdef SLAM_USE_DEBUG_ALLOCATOR 131 #define SLAM_LOCKED 1 // need the lock for the debug allocator 132 #elif !defined(THREADS) 133 #define SLAM_LOCKED 0 // never use if no threading 135 #define SLAM_LOCKED 0 165 uintptr_t allocate();
168 void free(uintptr_t
object);
171 size_t recovery(
size_t maxSlabs);
173 bool isPointerValid(uintptr_t
object)
const;
175 inline size_t objectSize()
const 180 inline size_t slabSize()
const 185 #if CRIPPLINGLY_VIGILANT 186 void trackSlab(uintptr_t slab);
194 #ifdef MULTIPROCESSOR 195 #define NUM_LISTS 255 200 typedef volatile Node *alignedNode;
201 alignedNode m_PartialLists[NUM_LISTS];
203 Node *pop(alignedNode *head);
205 void push(alignedNode *head,
Node *newTail,
Node *newHead = 0);
208 void freeSlab(uintptr_t slab);
210 Node *initialiseSlab(uintptr_t slab);
219 uintptr_t m_FirstSlab;
234 struct Node m_EmptyNode;
245 #ifdef PEDIGREE_BENCHMARK 250 uintptr_t allocate(
size_t nBytes);
251 void free(uintptr_t
mem);
253 size_t recovery(
size_t maxSlabs = 1);
255 bool isPointerValid(uintptr_t mem)
260 bool isWithinHeap(uintptr_t mem)
const;
262 size_t allocSize(uintptr_t mem);
266 #ifdef PEDIGREE_BENCHMARK 274 size_t heapPageCount()
const 276 return m_HeapPageCount;
279 uintptr_t getSlab(
size_t fullSize);
280 void freeSlab(uintptr_t address,
size_t length);
282 #ifdef USE_DEBUG_ALLOCATOR 283 inline size_t headerSize()
const 287 inline size_t footerSize()
const 293 void setVigilance(
bool b)
297 bool getVigilance()
const 306 #ifndef PEDIGREE_BENCHMARK 324 #if BOCHS_MAGIC_WATCHPOINTS 328 #if VIGILANT_OVERRUN_CHECK 329 uintptr_t backtrace[NUM_SLAM_BT_FRAMES];
339 #if BOCHS_MAGIC_WATCHPOINTS 355 size_t m_HeapPageCount;
357 uint64_t *m_SlabRegionBitmap;
358 size_t m_SlabRegionBitmapEntries;
SlamAllocator * m_pParentAllocator