Revision: 256 Author: nieklinnenbank Date: Sun Aug 2 03:58:47 2009Log: Modified PageAllocator to use the new CreatePrivate function of MemoryServer.
The previous Heap* functions are now deprecated and have been removed. http://code.google.com/p/freenos/source/detail?r=256 Modified: /trunk/lib/liballoc/PageAllocator.cpp /trunk/lib/liballoc/PageAllocator.h /trunk/lib/liballoc/SConscript ======================================= --- /trunk/lib/liballoc/PageAllocator.cpp Sat Jun 6 06:01:22 2009 +++ /trunk/lib/liballoc/PageAllocator.cpp Sun Aug 2 03:58:47 2009 @@ -20,40 +20,44 @@ #include <MemoryMessage.h> #include <Config.h> #include "PageAllocator.h" - -PageAllocator::PageAllocator() - : heapStart(ZERO), heapEnd(ZERO), allocated(ZERO) -{ -} PageAllocator::PageAllocator(Size size) - : heapStart(ZERO), heapEnd(ZERO), allocated(ZERO) -{ + : start(ZERO), allocated(ZERO) +{ + MemoryMessage mem; + + /* First reserve ~128MB virtual memory. */ + mem.action = ReservePrivate; + mem.bytes = 1024 * 1024 * 128; + mem.virtualAddress = 1024 * 1024 * 16; + mem.ipc(MEMSRV_PID, SendReceive, sizeof(mem)); + + /* Set heap pointer. */ + start = mem.virtualAddress; + + /* Allocate the given bytes. */ allocate(&size); } PageAllocator::PageAllocator(PageAllocator *p) - : heapStart(p->heapStart), heapEnd(p->heapEnd), - allocated(p->allocated) + : start(p->start), allocated(p->allocated) { } Address PageAllocator::allocate(Size *size) { MemoryMessage msg; - Address ret = heapStart + allocated; - Size bytes = *size > PAGEALLOC_MINIMUM ? *size : PAGEALLOC_MINIMUM; + Address ret = start + allocated; + Size bytes = *size > PAGEALLOC_MINIMUM ? + *size : PAGEALLOC_MINIMUM; /* Fill in the message. */ - msg.action = HeapGrow; - msg.bytes = bytes; - - /* Grow heap. */ - IPCMessage(MEMSRV_PID, SendReceive, &msg, sizeof(msg)); - - /* Update heap pointers. */ - heapStart = msg.startAddr; - heapEnd = msg.endAddr; + msg.action = CreatePrivate; + msg.bytes = bytes; + msg.protection = PAGE_RW | PAGE_RESERVED; + msg.virtualAddress = (1024 * 1024 * 16) + allocated; + msg.physicalAddress = ZERO; + msg.ipc(MEMSRV_PID, SendReceive, sizeof(msg)); /* Update count. */ allocated += msg.bytes; @@ -65,21 +69,5 @@ void PageAllocator::release(Address addr) { - MemoryMessage msg; - - /* Release heap pages. */ - for (Address i = heapStart + allocated; i > addr; i += PAGESIZE) - { - if (i - addr >= PAGESIZE) - { - /* Fill in the message. */ - msg.action = HeapShrink; - msg.bytes = PAGESIZE; - - /* Shrink heap. */ - IPCMessage(MEMSRV_PID, SendReceive, &msg, sizeof(msg)); - } - } - /* Update counter. */ - allocated = addr - heapStart; -} + // TODO +} ======================================= --- /trunk/lib/liballoc/PageAllocator.h Sat Jun 6 06:01:22 2009 +++ /trunk/lib/liballoc/PageAllocator.h Sun Aug 2 03:58:47 2009 @@ -37,11 +37,6 @@ { public: - /** - * Empty class constructor. - */ - PageAllocator(); - /** * Class constructor. * @param size Initial size in bytes. @@ -70,21 +65,18 @@ void release(Address addr); /** - * Get start address of the heap. - * @return Start heap address. + * Get the first address of the allocated memory region. + * @return Start address. */ - Address getHeapStart() - { - return heapStart; + Address getStart() + { + return start; } private: - /** Start of the current heap. */ - Address heapStart; - - /** End of the heap. */ - Address heapEnd; + /** Start of the allocated memory region. */ + Address start; /** Total number of bytes allocated. */ Size allocated; ======================================= --- /trunk/lib/liballoc/SConscript Mon Jun 1 15:41:52 2009 +++ /trunk/lib/liballoc/SConscript Sun Aug 2 03:58:47 2009 @@ -20,4 +20,4 @@ env = Prepare(target, [ 'libposix', 'libc' ], [ 'memory' ]) env.Library('liballoc', [ 'Allocator.cpp', 'BubbleAllocator.cpp', 'ListAllocator.cpp', 'PageAllocator.cpp', - 'PoolAllocator.cpp' ]) + 'PoolAllocator.cpp', 'VMCtlAllocator.cpp' ])