Improving the debug capabilities of the heap code, changed VFS to use const char...
[tpg/acess2.git] / Kernel / heap.c
1 /*
2  * AcessOS Microkernel Version
3  * heap.c
4  */
5 #include <acess.h>
6 #include <mm_virt.h>
7 #include <heap_int.h>
8
9 #define WARNINGS        1
10 #define DEBUG_TRACE     0
11
12 // === CONSTANTS ===
13 #define HEAP_INIT_SIZE  0x8000  // 32 KiB
14 #define MIN_SIZE        (sizeof(void*))*8       // 8 Machine Words
15 #define POW2_SIZES      0
16 #define COMPACT_HEAP    0       // Use 4 byte header?
17 #define FIRST_FIT       0
18
19 //#define       MAGIC_FOOT      0x2ACE5505
20 //#define       MAGIC_FREE      0xACE55000
21 //#define       MAGIC_USED      0x862B0505      // MAGIC_FOOT ^ MAGIC_FREE
22 #define MAGIC_FOOT      0x544F4F46      // 'FOOT'
23 #define MAGIC_FREE      0x45455246      // 'FREE'
24 #define MAGIC_USED      0x44455355      // 'USED'
25
26 // === PROTOTYPES ===
27 void    Heap_Install(void);
28 void    *Heap_Extend(int Bytes);
29 void    *Heap_Merge(tHeapHead *Head);
30 void    *Heap_Allocate(const char *File, int Line, size_t Bytes);
31 void    *Heap_AllocateZero(const char *File, int Line, size_t Bytes);
32 void    *Heap_Reallocate(const char *File, int Line, void *Ptr, size_t Bytes);
33 void    Heap_Deallocate(void *Ptr);
34 void    Heap_Dump(void);
35 void    Heap_Stats(void);
36
37 // === GLOBALS ===
38 tSpinlock       glHeap;
39 void    *gHeapStart;
40 void    *gHeapEnd;
41
42 // === CODE ===
43 void Heap_Install(void)
44 {
45         gHeapStart      = (void*)MM_KHEAP_BASE;
46         gHeapEnd        = (void*)MM_KHEAP_BASE;
47         Heap_Extend(HEAP_INIT_SIZE);
48 }
49
50 /**
51  * \fn void *Heap_Extend(int Bytes)
52  * \brief Extend the size of the heap
53  */
54 void *Heap_Extend(int Bytes)
55 {
56         Uint    i;
57         tHeapHead       *head = gHeapEnd;
58         tHeapFoot       *foot;
59         
60         // Bounds Check
61         if( (tVAddr)gHeapEnd == MM_KHEAP_MAX )
62                 return NULL;
63         
64         // Bounds Check
65         if( (tVAddr)gHeapEnd + ((Bytes+0xFFF)&~0xFFF) > MM_KHEAP_MAX ) {
66                 Bytes = MM_KHEAP_MAX - (tVAddr)gHeapEnd;
67                 return NULL;
68         }
69         
70         // Heap expands in pages
71         for(i=0;i<(Bytes+0xFFF)>>12;i++)
72                 MM_Allocate( (tVAddr)gHeapEnd+(i<<12) );
73         
74         // Increas heap end
75         gHeapEnd += i << 12;
76         
77         // Create Block
78         head->Size = (Bytes+0xFFF)&~0xFFF;
79         head->Magic = MAGIC_FREE;
80         foot = (void*)( (Uint)gHeapEnd - sizeof(tHeapFoot) );
81         foot->Head = head;
82         foot->Magic = MAGIC_FOOT;
83         
84         return Heap_Merge(head);        // Merge with previous block
85 }
86
87 /**
88  * \fn void *Heap_Merge(tHeapHead *Head)
89  * \brief Merges two ajacent heap blocks
90  */
91 void *Heap_Merge(tHeapHead *Head)
92 {
93         tHeapFoot       *foot;
94         tHeapFoot       *thisFoot;
95         tHeapHead       *head;
96         
97         //Log("Heap_Merge: (Head=%p)", Head);
98         
99         thisFoot = (void*)( (Uint)Head + Head->Size - sizeof(tHeapFoot) );
100         if((Uint)thisFoot > (Uint)gHeapEnd)     return NULL;
101         
102         // Merge Left (Down)
103         foot = (void*)( (Uint)Head - sizeof(tHeapFoot) );
104         if( ((Uint)foot < (Uint)gHeapEnd && (Uint)foot > (Uint)gHeapStart)
105         && foot->Head->Magic == MAGIC_FREE) {
106                 foot->Head->Size += Head->Size; // Increase size
107                 thisFoot->Head = foot->Head;    // Change backlink
108                 Head->Magic = 0;        // Clear old head
109                 Head->Size = 0;
110                 Head = foot->Head;      // Save new head address
111                 foot->Head = NULL;      // Clear central footer
112                 foot->Magic = 0;
113         }
114         
115         // Merge Right (Upwards)
116         head = (void*)( (Uint)Head + Head->Size );
117         if((Uint)head < (Uint)gHeapEnd && head->Magic == MAGIC_FREE)
118         {
119                 Head->Size += head->Size;
120                 foot = (void*)( (Uint)Head + Head->Size - sizeof(tHeapFoot) );
121                 foot->Head = Head;      // Update Backlink
122                 thisFoot->Head = NULL;  // Clear old footer
123                 thisFoot->Magic = 0;
124                 head->Size = 0;         // Clear old header
125                 head->Magic = 0;
126         }
127         
128         // Return new address
129         return Head;
130 }
131
132 /**
133  * \brief Allocate memory from the heap
134  * \param File  Allocating source file
135  * \param Line  Source line
136  * \param Bytes Size of region to allocate
137  */
138 void *Heap_Allocate(const char *File, int Line, size_t Bytes)
139 {
140         tHeapHead       *head, *newhead;
141         tHeapFoot       *foot, *newfoot;
142         tHeapHead       *best = NULL;
143         Uint    bestSize = 0;   // Speed hack
144         
145         // Get required size
146         #if POW2_SIZES
147         Bytes = Bytes + sizeof(tHeapHead) + sizeof(tHeapFoot);
148         Bytes = 1UUL << LOG2(Bytes);
149         #else
150         Bytes = (Bytes + sizeof(tHeapHead) + sizeof(tHeapFoot) + MIN_SIZE-1) & ~(MIN_SIZE-1);
151         #endif
152         
153         // Lock Heap
154         LOCK(&glHeap);
155         
156         // Traverse Heap
157         for( head = gHeapStart;
158                 (Uint)head < (Uint)gHeapEnd;
159                 head = (void*)((Uint)head + head->Size)
160                 )
161         {
162                 // Alignment Check
163                 #if POW2_SIZES
164                 if( head->Size != 1UUL << LOG2(head->Size) ) {
165                 #else
166                 if( head->Size & (MIN_SIZE-1) ) {
167                 #endif
168                         RELEASE(&glHeap);       // Release spinlock
169                         #if WARNINGS
170                         Log_Warning("Heap", "Size of heap address %p is invalid not aligned (0x%x)", head, head->Size);
171                         Heap_Dump();
172                         #endif
173                         return NULL;
174                 }
175                 
176                 // Check if allocated
177                 if(head->Magic == MAGIC_USED)   continue;
178                 // Error check
179                 if(head->Magic != MAGIC_FREE)   {
180                         RELEASE(&glHeap);       // Release spinlock
181                         #if WARNINGS
182                         Log_Warning("Heap", "Magic of heap address %p is invalid (0x%x)", head, head->Magic);
183                         Heap_Dump();
184                         #endif
185                         return NULL;
186                 }
187                 
188                 // Size check
189                 if(head->Size < Bytes)  continue;
190                 
191                 // Perfect fit
192                 if(head->Size == Bytes) {
193                         head->Magic = MAGIC_USED;
194                         head->File = File;
195                         head->Line = Line;
196                         RELEASE(&glHeap);       // Release spinlock
197                         #if DEBUG_TRACE
198                         Log("[Heap   ] Malloc'd %p (%i bytes), returning to %p", head->Data, head->Size,  __builtin_return_address(0));
199                         #endif
200                         return head->Data;
201                 }
202                 
203                 // Break out of loop
204                 #if FIRST_FIT
205                 best = head;
206                 bestSize = head->Size;
207                 break;
208                 #else
209                 // or check if the block is the best size
210                 if(bestSize > head->Size) {
211                         best = head;
212                         bestSize = head->Size;
213                 }
214                 #endif
215         }
216         
217         // If no block large enough is found, create one
218         if(!best)
219         {
220                 best = Heap_Extend( Bytes );
221                 // Check for errors
222                 if(!best) {
223                         RELEASE(&glHeap);       // Release spinlock
224                         return NULL;
225                 }
226                 // Check size
227                 if(best->Size == Bytes) {
228                         best->Magic = MAGIC_USED;       // Mark block as used
229                         best->File = File;
230                         best->Line = Line;
231                         RELEASE(&glHeap);       // Release spinlock
232                         #if DEBUG_TRACE
233                         Log("[Heap   ] Malloc'd %p (%i bytes), returning to %p", best->Data, best->Size, __builtin_return_address(0));
234                         #endif
235                         return best->Data;
236                 }
237         }
238         
239         // Split Block
240         newhead = (void*)( (Uint)best + Bytes );
241         newfoot = (void*)( (Uint)best + Bytes - sizeof(tHeapFoot) );
242         foot = (void*)( (Uint)best + best->Size - sizeof(tHeapFoot) );
243         
244         newfoot->Head = best;   // Create new footer
245         newfoot->Magic = MAGIC_FOOT;
246         newhead->Size = best->Size - Bytes;     // Create new header
247         newhead->Magic = MAGIC_FREE;
248         foot->Head = newhead;   // Update backlink in old footer
249         best->Size = Bytes;             // Update size in old header
250         best->Magic = MAGIC_USED;       // Mark block as used
251         best->File = File;
252         best->Line = Line;
253         
254         RELEASE(&glHeap);       // Release spinlock
255         #if DEBUG_TRACE
256         Log_Debug("Heap", "newhead(%p)->Size = 0x%x", newhead, newhead->Size);
257         Log_Debug("Heap", "Malloc'd %p (0x%x bytes), returning to %s:%i",
258                 best->Data, best->Size, File, Line);
259         #endif
260         return best->Data;
261 }
262
263 /**
264  * \fn void Heap_Deallocate(void *Ptr)
265  * \brief Free an allocated memory block
266  */
267 void Heap_Deallocate(void *Ptr)
268 {
269         tHeapHead       *head;
270         tHeapFoot       *foot;
271         
272         #if DEBUG_TRACE
273         Log_Log("Heap", "free: Ptr = %p", Ptr);
274         Log_Log("Heap", "free: Returns to %p", __builtin_return_address(0));
275         #endif
276         
277         // Alignment Check
278         if( (Uint)Ptr & (sizeof(Uint)-1) ) {
279                 Log_Warning("Heap", "free - Passed a non-aligned address (%p)", Ptr);
280                 return;
281         }
282         
283         // Sanity check
284         if((Uint)Ptr < (Uint)gHeapStart || (Uint)Ptr > (Uint)gHeapEnd)
285         {
286                 Log_Warning("Heap", "free - Passed a non-heap address (%p < %p < %p)\n",
287                         gHeapStart, Ptr, gHeapEnd);
288                 return;
289         }
290         
291         // Check memory block - Header
292         head = (void*)( (Uint)Ptr - sizeof(tHeapHead) );
293         if(head->Magic == MAGIC_FREE) {
294                 Log_Warning("Heap", "free - Passed a freed block (%p) by %p", head, __builtin_return_address(0));
295                 return;
296         }
297         if(head->Magic != MAGIC_USED) {
298                 Log_Warning("Heap", "free - Magic value is invalid (%p, 0x%x)", head, head->Magic);
299                 Log_Notice("Heap", "Allocated %s:%i", head->File, head->Line);
300                 return;
301         }
302         
303         // Check memory block - Footer
304         foot = (void*)( (Uint)head + head->Size - sizeof(tHeapFoot) );
305         if(foot->Head != head) {
306                 Log_Warning("Heap", "free - Footer backlink is incorrect (%p, 0x%x)", head, foot->Head);
307                 Log_Notice("Heap", "Allocated %s:%i", head->File, head->Line);
308                 return;
309         }
310         if(foot->Magic != MAGIC_FOOT) {
311                 Log_Warning("Heap", "free - Footer magic is invalid (%p, %p = 0x%x)", head, &foot->Magic, foot->Magic);
312                 Log_Notice("Heap", "Allocated %s:%i", head->File, head->Line);
313                 return;
314         }
315         
316         // Lock
317         LOCK( &glHeap );
318         
319         // Mark as free
320         head->Magic = MAGIC_FREE;
321         // Merge blocks
322         Heap_Merge( head );
323         
324         // Release
325         RELEASE( &glHeap );
326 }
327
328 /**
329  */
330 void *Heap_Reallocate(const char *File, int Line, void *__ptr, size_t __size)
331 {
332         tHeapHead       *head = (void*)( (Uint)__ptr-8 );
333         tHeapHead       *nextHead;
334         tHeapFoot       *foot;
335         Uint    newSize = (__size + sizeof(tHeapFoot)+sizeof(tHeapHead)+MIN_SIZE-1)&~(MIN_SIZE-1);
336         
337         // Check for reallocating NULL
338         if(__ptr == NULL)       return Heap_Allocate(File, Line, __size);
339         
340         // Check if resize is needed
341         if(newSize <= head->Size)       return __ptr;
342         
343         // Check if next block is free
344         nextHead = (void*)( (Uint)head + head->Size );
345         
346         // Extend into next block
347         if(nextHead->Magic == MAGIC_FREE && nextHead->Size+head->Size >= newSize)
348         {
349                 Uint    size = nextHead->Size + head->Size;
350                 foot = (void*)( (Uint)nextHead + nextHead->Size - sizeof(tHeapFoot) );
351                 // Exact Fit
352                 if(size == newSize) {
353                         head->Size = newSize;
354                         head->File = File;
355                         head->Line = Line;
356                         foot->Head = head;
357                         nextHead->Magic = 0;
358                         nextHead->Size = 0;
359                         return __ptr;
360                 }
361                 // Create a new heap block
362                 nextHead = (void*)( (Uint)head + newSize );
363                 nextHead->Size = size - newSize;
364                 nextHead->Magic = MAGIC_FREE;
365                 foot->Head = nextHead;  // Edit 2nd footer
366                 head->Size = newSize;   // Edit first header
367                 head->File = File;
368                 head->Line = Line;
369                 // Create new footer
370                 foot = (void*)( (Uint)head + newSize - sizeof(tHeapFoot) );
371                 foot->Head = head;
372                 foot->Magic = MAGIC_FOOT;
373                 return __ptr;
374         }
375         
376         // Extend downwards?
377         foot = (void*)( (Uint)head - sizeof(tHeapFoot) );
378         nextHead = foot->Head;
379         if(nextHead->Magic == MAGIC_FREE && nextHead->Size+head->Size >= newSize)
380         {
381                 Uint    size = nextHead->Size + head->Size;
382                 // Inexact fit, split things up
383                 if(size > newSize)
384                 {
385                         // TODO
386                         Warning("[Heap   ] TODO: Space efficient realloc when new size is smaller");
387                 }
388                 
389                 // Exact fit
390                 if(size >= newSize)
391                 {
392                         Uint    oldDataSize;
393                         // Set 1st (new/lower) header
394                         nextHead->Magic = MAGIC_USED;
395                         nextHead->Size = newSize;
396                         nextHead->File = File;
397                         nextHead->Line = Line;
398                         // Get 2nd (old) footer
399                         foot = (void*)( (Uint)nextHead + newSize );
400                         foot->Head = nextHead;
401                         // Save old data size
402                         oldDataSize = head->Size - sizeof(tHeapFoot) - sizeof(tHeapHead);
403                         // Clear old header
404                         head->Size = 0;
405                         head->Magic = 0;
406                         // Copy data
407                         memcpy(nextHead->Data, __ptr, oldDataSize);
408                         // Return
409                         return nextHead->Data;
410                 }
411                 // On to the expensive then
412         }
413         
414         // Well, darn
415         nextHead = Heap_Allocate( File, Line, __size );
416         nextHead -= 1;
417         nextHead->File = File;
418         nextHead->Line = Line;
419         
420         memcpy(
421                 nextHead->Data,
422                 __ptr,
423                 head->Size - sizeof(tHeapFoot) - sizeof(tHeapHead)
424                 );
425         
426         free(__ptr);
427         
428         return nextHead->Data;
429 }
430
431 /**
432  * \fn void *Heap_AllocateZero(const char *File, int Line, size_t size)
433  * \brief Allocate and Zero a buffer in memory
434  * \param File  Allocating file
435  * \param Line  Line of allocation
436  * \param size  Size of the allocation
437  */
438 void *Heap_AllocateZero(const char *File, int Line, size_t size)
439 {
440         void    *ret = Heap_Allocate(File, Line, size);
441         if(ret == NULL) return NULL;
442         
443         memset( ret, 0, size );
444         
445         return ret;
446 }
447
448 /**
449  * \fn int Heap_IsHeapAddr(void *Ptr)
450  * \brief Checks if an address is a heap pointer
451  */
452 int Heap_IsHeapAddr(void *Ptr)
453 {
454         tHeapHead       *head;
455         if((Uint)Ptr < (Uint)gHeapStart)        return 0;
456         if((Uint)Ptr > (Uint)gHeapEnd)  return 0;
457         if((Uint)Ptr & (sizeof(Uint)-1))        return 0;
458         
459         head = (void*)( (Uint)Ptr - sizeof(tHeapHead) );
460         if(head->Magic != MAGIC_USED && head->Magic != MAGIC_FREE)
461                 return 0;
462         
463         return 1;
464 }
465
466 #if WARNINGS
467 void Heap_Dump(void)
468 {
469         tHeapHead       *head, *badHead;
470         tHeapFoot       *foot;
471         
472         head = gHeapStart;
473         while( (Uint)head < (Uint)gHeapEnd )
474         {               
475                 foot = (void*)( (Uint)head + head->Size - sizeof(tHeapFoot) );
476                 Log_Log("Heap", "%p (0x%llx): 0x%08lx %4C",
477                         head, MM_GetPhysAddr((Uint)head), head->Size, &head->Magic);
478                 Log_Log("Heap", "%p %4C", foot->Head, &foot->Magic);
479                 if(head->File) {
480                         Log_Log("Heap", "%sowned by %s:%i",
481                                 (head->Magic==MAGIC_FREE?"was ":""), head->File, head->Line);
482                 }
483                 Log_Log("Heap", "");
484                 
485                 // Sanity Check Header
486                 if(head->Size == 0) {
487                         Log_Warning("Heap", "HALTED - Size is zero");
488                         break;
489                 }
490                 if(head->Size & (MIN_SIZE-1)) {
491                         Log_Warning("Heap", "HALTED - Size is malaligned");
492                         break;
493                 }
494                 if(head->Magic != MAGIC_FREE && head->Magic != MAGIC_USED) {
495                         Log_Warning("Heap", "HALTED - Head Magic is Bad");
496                         break;
497                 }
498                 
499                 // Check footer
500                 if(foot->Magic != MAGIC_FOOT) {
501                         Log_Warning("Heap", "HALTED - Foot Magic is Bad");
502                         break;
503                 }
504                 if(head != foot->Head) {
505                         Log_Warning("Heap", "HALTED - Footer backlink is invalid");
506                         break;
507                 }
508                 
509                 // All OK? Go to next
510                 head = foot->NextHead;
511         }
512         
513         // Check for a bad return
514         if( (tVAddr)head >= (tVAddr)gHeapEnd )
515                 return ;
516         
517         badHead = head;
518         
519         Log_Log("Heap", "==== Going Backwards ==== (from %p)", badHead);
520         
521         // Work backwards
522         foot = (void*)( (tVAddr)gHeapEnd - sizeof(tHeapFoot) );
523         head = foot->Head;
524         while( (tVAddr)head >= (tVAddr)badHead )
525         {
526                 Log_Log("Heap", "%p (0x%llx): 0x%08lx %4C",
527                         head, MM_GetPhysAddr((Uint)head), head->Size, &head->Magic);
528                 Log_Log("Heap", "%p %4C", foot->Head, &foot->Magic);
529                 if(head->File)
530                         Log_Log("Heap", "%sowned by %s:%i",
531                                 (head->Magic!=MAGIC_USED?"was ":""),
532                                 head->File, head->Line);
533                 Log_Log("Heap", "");
534                 
535                 // Sanity Check Header
536                 if(head->Size == 0) {
537                         Log_Warning("Heap", "HALTED - Size is zero");
538                         break;
539                 }
540                 if(head->Size & (MIN_SIZE-1)) {
541                         Log_Warning("Heap", " - Size is malaligned (&0x%x)", ~(MIN_SIZE-1));
542                         break ;
543                 }
544                 if(head->Magic != MAGIC_FREE && head->Magic != MAGIC_USED) {
545                         Log_Warning("Heap", "HALTED - Head Magic is Bad");
546                         break;
547                 }
548                 
549                 // Check footer
550                 if(foot->Magic != MAGIC_FOOT) {
551                         Log_Warning("Heap", "HALTED - Foot Magic is Bad");
552                         break;
553                 }
554                 if(head != foot->Head) {
555                         Log_Warning("Heap", "HALTED - Footer backlink is invalid");
556                         break;
557                 }
558                 
559                 if(head == badHead)     break;
560                 
561                 foot = (void*)( (tVAddr)head - sizeof(tHeapFoot) );
562                 head = foot->Head;
563                 Log_Debug("Heap", "head=%p", head);
564         }
565 }
566 #endif
567
568 #if 1
569 void Heap_Stats(void)
570 {
571         tHeapHead       *head;
572          int    nBlocks = 0;
573          int    nFree = 0;
574          int    totalBytes = 0;
575          int    freeBytes = 0;
576          int    maxAlloc=0, minAlloc=-1;
577          int    avgAlloc, frag, overhead;
578         
579         for(head = gHeapStart;
580                 (Uint)head < (Uint)gHeapEnd;
581                 head = (void*)( (Uint)head + head->Size )
582                 )
583         {       
584                 nBlocks ++;
585                 totalBytes += head->Size;
586                 if( head->Magic == MAGIC_FREE )
587                 {
588                         nFree ++;
589                         freeBytes += head->Size;
590                 }
591                 else if( head->Magic == MAGIC_USED) {
592                         if(maxAlloc < head->Size)       maxAlloc = head->Size;
593                         if(minAlloc == -1 || minAlloc > head->Size)
594                                 minAlloc = head->Size;
595                 }
596                 else {
597                         Log_Warning("Heap", "Magic on %p invalid, skipping remainder of heap", head);
598                         break;
599                 }
600                 
601                 // Print the block info?
602                 #if 1
603                 Log_Debug("Heap", "%p - 0x%x Owned by %s:%i",
604                         head, head->Size, head->File, head->Line);
605                 #endif
606         }
607
608         Log_Log("Heap", "%i blocks (0x%x bytes)", nBlocks, totalBytes);
609         Log_Log("Heap", "%i free blocks (0x%x bytes)", nFree, freeBytes);
610         frag = (nFree-1)*10000/nBlocks;
611         Log_Log("Heap", "%i.%02i%% Heap Fragmentation", frag/100, frag%100);
612         avgAlloc = (totalBytes-freeBytes)/(nBlocks-nFree);
613         overhead = (sizeof(tHeapFoot)+sizeof(tHeapHead))*10000/avgAlloc;
614         Log_Log("Heap", "Average allocation: %i bytes, Average Overhead: %i.%02i%%",
615                 avgAlloc, overhead/100, overhead%100
616                 );
617         Log_Log("Heap", "Smallest Block: %i bytes, Largest: %i bytes", 
618                 minAlloc, maxAlloc);
619         
620         // Scan and get distribution
621         #if 1
622         {
623                 struct {
624                         Uint    Size;
625                         Uint    Count;
626                 }       sizeCounts[nBlocks];
627                  int    i;
628                 
629                 memset(sizeCounts, 0, nBlocks*sizeof(sizeCounts[0]));
630                 
631                 for(head = gHeapStart;
632                         (Uint)head < (Uint)gHeapEnd;
633                         head = (void*)( (Uint)head + head->Size )
634                         )
635                 {
636                         for( i = 0; i < nBlocks; i ++ ) {
637                                 if( sizeCounts[i].Size == 0 )
638                                         break;
639                                 if( sizeCounts[i].Size == head->Size )
640                                         break;
641                         }
642                         // Should never reach this part (in a non-concurrent case)
643                         if( i == nBlocks )      continue;
644                         sizeCounts[i].Size = head->Size;
645                         sizeCounts[i].Count ++;
646                         #if 1
647                         //Log("Heap_Stats: %i %p - 0x%x bytes (%s) (%i)", nBlocks, head,
648                         //      head->Size, (head->Magic==MAGIC_FREE?"FREE":"used"), i
649                         //      );
650                         //Log("Heap_Stats: sizeCounts[%i] = {Size:0x%x, Count: %i}", i,
651                         //      sizeCounts[i].Size, sizeCounts[i].Count);
652                         #endif
653                 }
654                 
655                 for( i = 0; i < nBlocks && sizeCounts[i].Count; i ++ )
656                 {
657                         Log("Heap_Stats: 0x%x - %i blocks",
658                                 sizeCounts[i].Size, sizeCounts[i].Count
659                                 );
660                 }
661         }
662         #endif
663 }
664 #endif
665
666 // === EXPORTS ===
667 EXPORT(Heap_Allocate);
668 EXPORT(Heap_AllocateZero);
669 EXPORT(Heap_Reallocate);
670 EXPORT(Heap_Deallocate);
671 EXPORT(Heap_IsHeapAddr);

UCC git Repository :: git.ucc.asn.au