Import backup from 2004-06-12

This commit is contained in:
josh committed 2017-07-25 22:23:47 -04:00
1 parent 9a8d2c29cb
commit c76725eac3
10 files changed
+224 -185

No files matched your search

+32 -4
View File
@@ -113,7 +113,7 @@ void *malloc(unsigned int bytes)
if (attempt)
return attempt;
if(vmm_moreCore(bytes))
return 0; //we could not get any more heap memory
return NULL; //we could not get any more heap memory
return vmm_getFreeChunk(bytes);
}
@@ -341,12 +341,40 @@ HeapEntry *vmm_getHeapEntryByBase(unsigned int base)
if (!he)
break;
}
return 0;
return NULL;
}
// This function re-allocates memory already allocated, preserving the old contents
// (as long as newSize is greater than oldSize)
void *realloc(void *orig, unsigned int newSize)
{
void *newMem;
if ((newMem = malloc(newSize)))
{
HeapEntry *he = vmm_getHeapEntryByBase((unsigned int) orig);
if (!he)
return NULL; //old chunk not found / nonexistent
memcpy(newMem, orig, (he->size < newSize ? he->size : newSize));
free(orig);
return newMem;
}
else
return NULL; //could not get mem for new chunk
}
// This function allocates and zeros memory for the given number of objects,
// given the size of each object
void *calloc(unsigned int number, unsigned int size)
{
void *mem = malloc(number * size);
if (!mem)
return NULL; //could not get memory
memset(mem, 0, number * size);
return mem;
}
+2
View File
@@ -48,6 +48,8 @@ void vmm_addHeapEntryBlock();
int vmm_moreCore(unsigned int bytes);
void vmm_coalesceHeapEntry(HeapEntry *he);
HeapEntry *vmm_getHeapEntryByBase(unsigned int base);
void *realloc(void *orig, unsigned int newSize);
void *calloc(unsigned int number, unsigned int size);
#endif