diff --git a/src/sys/lib/kmalloc.c b/src/sys/lib/kmalloc.c index 23554c3..e52dd7f 100644 --- a/src/sys/lib/kmalloc.c +++ b/src/sys/lib/kmalloc.c @@ -245,8 +245,9 @@ void *kmalloc(uInt32 len) { struct memDescriptor *tmpDesc1 = 0x0; struct memDescriptor *tmpDesc2 = 0x0; - char *buf = 0x0; - int i = 0x0; + char *buf = 0x0; + int i = 0x0; + uInt16 pages = 0x0; spinLock(&mallocSpinLock); @@ -272,6 +273,7 @@ if (usedKernDesc != 0x0) usedKernDesc->prev = tmpDesc1; usedKernDesc = tmpDesc1; + if (tmpDesc1->limit > (len + 32)) { tmpDesc2 = getEmptyDesc(); assert(tmpDesc2); @@ -293,7 +295,8 @@ tmpDesc1 = getEmptyDesc(); //kprintf("no empty desc\n"); if (tmpDesc1 != 0x0) { - tmpDesc1->baseAddr = (struct memDescriptor *)vmm_getFreeMallocPage((len + 4095)/4096); + pages = ((len + 4095)/4096); + tmpDesc1->baseAddr = (struct memDescriptor *)vmm_getFreeMallocPage(pages); tmpDesc1->limit = len; tmpDesc1->next = usedKernDesc; tmpDesc1->prev = 0x0; @@ -301,11 +304,11 @@ usedKernDesc->prev = tmpDesc1; usedKernDesc = tmpDesc1; - if ((len%0x1000) > 0x0) { + if (((pages * 4096)-len) > 0x0) { tmpDesc2 = getEmptyDesc(); assert(tmpDesc2); tmpDesc2->baseAddr = tmpDesc1->baseAddr + tmpDesc1->limit; - tmpDesc2->limit = ((len + 4095)/0x1000)*0x1000 - tmpDesc1->limit; + tmpDesc2->limit = ((pages * 4096)-len); tmpDesc2->prev = 0x0; tmpDesc2->next = 0x0; if (tmpDesc2->limit <= 0x0) @@ -337,7 +340,7 @@ ************************************************************************/ void kfree(void *baseAddr) { - struct memDescriptor *tmpDesc1 = 0x0; + struct memDescriptor *tmpDesc = 0x0; spinLock(&mallocSpinLock); @@ -345,26 +348,26 @@ assert(usedKernDesc); - for (tmpDesc1 = usedKernDesc;tmpDesc1 != 0x0;tmpDesc1 = tmpDesc1->next) { + for (tmpDesc = usedKernDesc;tmpDesc != 0x0;tmpDesc = tmpDesc->next) { - if (tmpDesc1->baseAddr == baseAddr) { + if (tmpDesc->baseAddr == baseAddr) { - if (usedKernDesc == tmpDesc1) - usedKernDesc = tmpDesc1->next; + if (usedKernDesc == tmpDesc) + usedKernDesc = tmpDesc->next; - if (tmpDesc1->prev != 0x0) - tmpDesc1->prev->next = tmpDesc1->next; + if (tmpDesc->prev != 0x0) + tmpDesc->prev->next = tmpDesc->next; - if (tmpDesc1->next != 0x0) - tmpDesc1->next->prev = tmpDesc1->prev; + if (tmpDesc->next != 0x0) + tmpDesc->next->prev = tmpDesc->prev; - tmpDesc1->next = 0x0; - tmpDesc1->prev = 0x0; + tmpDesc->next = 0x0; + tmpDesc->prev = 0x0; - if (tmpDesc1->limit <= 0x0) - kprintf("kfree tmpDesc1: [%i]\n",tmpDesc1->limit); - insertFreeDesc(tmpDesc1); + if (tmpDesc->limit <= 0x0) + kprintf("kfree tmpDesc1: [%i]\n",tmpDesc->limit); + insertFreeDesc(tmpDesc); //mergeMemBlocks(); spinUnlock(&mallocSpinLock); @@ -378,6 +381,9 @@ /*** $Log$ + Revision 1.25 2004/09/11 12:11:11 reddawg + Cleaning up the VFS more changes to follow... + Revision 1.24 2004/09/08 23:19:58 reddawg hmm