X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fheap.c;h=f42d59f8001bfe4933fb72c0bf9624f3aab60dd0;hb=25f19babe7a0ab75d04ff7e6f98f7bcb65fb8941;hp=fbff88b29eecd7cd33e5f3a29a9afbfd53432b7f;hpb=c6668f5ce555ff5550fa3d9ab1462e5a625f832c;p=tpg%2Facess2.git diff --git a/Kernel/heap.c b/Kernel/heap.c index fbff88b2..f42d59f8 100644 --- a/Kernel/heap.c +++ b/Kernel/heap.c @@ -2,7 +2,7 @@ * AcessOS Microkernel Version * heap.c */ -#include +#include #include #include @@ -251,7 +251,7 @@ void free(void *Ptr) // Alignment Check if( (Uint)Ptr & (sizeof(Uint)-1) ) { - Warning("free - Passed a non-aligned address (%p)\n", Ptr); + Warning("free - Passed a non-aligned address (%p)", Ptr); return; } @@ -265,7 +265,7 @@ void free(void *Ptr) // Check memory block - Header head = (void*)( (Uint)Ptr - sizeof(tHeapHead) ); if(head->Magic == MAGIC_FREE) { - Warning("free - Passed a freed block (%p)\n", head); + Warning("free - Passed a freed block (%p) by %p", head, __builtin_return_address(0)); return; } if(head->Magic != MAGIC_USED) { @@ -280,7 +280,7 @@ void free(void *Ptr) return; } if(foot->Magic != MAGIC_FOOT) { - Warning("free - Footer magic is invalid (%p, 0x%x)\n", head, foot->Magic); + Warning("free - Footer magic is invalid (%p, %p = 0x%x)\n", head, &foot->Magic, foot->Magic); return; } @@ -368,6 +368,22 @@ void *realloc(void *__ptr, size_t __size) return NULL; } +/** + * \fn void *calloc(size_t num, size_t size) + * \brief Allocate and Zero a buffer in memory + * \param num Number of elements + * \param size Size of each element + */ +void *calloc(size_t num, size_t size) +{ + void *ret = malloc(num*size); + if(ret == NULL) return NULL; + + memset( ret, 0, num*size ); + + return ret; +} + /** * \fn int IsHeap(void *Ptr) * \brief Checks if an address is a heap address @@ -428,3 +444,8 @@ void Heap_Dump() } } #endif + +// === EXPORTS === +EXPORT(malloc); +EXPORT(realloc); +EXPORT(free);