diff --git a/src/sys/lib/kmalloc.c b/src/sys/lib/kmalloc.c index d84e191..d903b1e 100644 --- a/src/sys/lib/kmalloc.c +++ b/src/sys/lib/kmalloc.c @@ -1,42 +1,27 @@ /***************************************************************************************** - Copyright (c) 2002 The UbixOS Project + Copyright (c) 2002-2004 The UbixOS Project All rights reserved. -Redistribution and use in source and binary forms, with or without modification, are -permitted provided that the following conditions are met: + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: -Redistributions of source code must retain the above copyright notice, this list of -conditions, the following disclaimer and the list of authors. Redistributions in binary -form must reproduce the above copyright notice, this list of conditions, the following -disclaimer and the list of authors in the documentation and/or other materials provided -with the distribution. Neither the name of the UbixOS Project nor the names of its -contributors may be used to endorse or promote products derived from this software -without specific prior written permission. + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT -OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR -TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - $Log$ - Revision 1.3 2004/05/19 04:07:43 reddawg - kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been - - Revision 1.2 2004/04/20 00:53:16 reddawg - Works - - Revision 1.1.1.1 2004/04/15 12:07:10 reddawg - UbixOS v1.0 - - Revision 1.21 2004/04/13 16:36:33 reddawg - Changed our copyright, it is all now under a BSD-Style license - - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. $Id$ @@ -47,19 +32,20 @@ #include #include #include +#include #include struct memDescriptor *kernDesc = 0x0; struct memDescriptor *freeKernDesc = 0x0; struct memDescriptor *emptyKernDesc = 0x0; -int mallocLock = 0x0; +static spinLock_t mallocSpinLock = SPIN_LOCK_INITIALIZER; void initMalloc() { int i=0; struct memDescriptor *tmpDesc1 = 0x0; struct memDescriptor *tmpDesc2 = 0x0; - emptyKernDesc = (struct memDescriptor *)vmmGetFreeKernelPage(sysID,4); + emptyKernDesc = (struct memDescriptor *)vmmGetFreeKernelPage(sysID,4); tmpDesc1 = emptyKernDesc; tmpDesc1->prev = 0x0; tmpDesc1->status = 0x0; @@ -116,10 +102,8 @@ char *buf = 0x0; int i = 0x0; - if (mallocLock != 0x0) - while (1) asm("nop"); + spinLock(&mallocSpinLock); - mallocLock = sysID;// _current->id; //If Kernel Descriptor Is NULL Initialize Malloc if (emptyKernDesc == 0x0) { initMalloc(); @@ -127,6 +111,7 @@ len = (len + 15) & 0xFFFFFFF0; if (len == 0x0) { kpanic("Malloc of Size 0 Requested\n"); + spinUnlock(&mallocSpinLock); return(0x0); } for (tmpDesc1 = freeKernDesc;tmpDesc1;tmpDesc1=tmpDesc1->next) { @@ -154,11 +139,11 @@ tmpDesc2->prev = 0x0; insertFreeDesc(tmpDesc2); } - mallocLock = 0x0; buf = (char *)tmpDesc1->baseAddr; for (i=0;ilimit;i++) { (char)buf[i] = (char)0x0; } + spinUnlock(&mallocSpinLock); return(tmpDesc1->baseAddr); } } @@ -180,15 +165,15 @@ tmpDesc2->next = 0x0; insertFreeDesc(tmpDesc2); } - mallocLock = 0x0; buf = (char *)tmpDesc1->baseAddr; for (i=0;ilimit;i++) { (char)buf[i] = (char)0x0; } + spinUnlock(&mallocSpinLock); return(tmpDesc1->baseAddr); } //Return Null If Unable To Malloc - mallocLock = 0x0; + spinUnlock(&mallocSpinLock); return(0x0); } @@ -208,9 +193,8 @@ struct memDescriptor *tmpDesc1 = 0x0; struct memDescriptor *tmpDesc2 = 0x0; - while (mallocLock != 0x0) asm("nop"); + spinLock(&mallocSpinLock); - mallocLock = _current->id; for (tmpDesc1=kernDesc;tmpDesc1;tmpDesc1=tmpDesc1->next) { if (tmpDesc1->baseAddr == baseAddr) { tmpDesc1->status = 0x0; @@ -233,12 +217,12 @@ data[i] = 0x0; } //mergeMemBlocks(); - mallocLock = 0x0; + spinUnlock(&mallocSpinLock); return; } } kprintf("Error Freeing Descriptor! [0x%X]\n",baseAddr); - mallocLock = 0x0; + spinUnlock(&mallocSpinLock); return; } @@ -344,6 +328,7 @@ } /*** + $Log$ END ***/