///////////////////////////////////// // PUBLIC METHODS ///////////////////////////////////// public unsafe PhysicalHeap(UIntPtr start, UIntPtr limit) { DebugStub.Assert(MemoryManager.IsPageAligned(start)); DebugStub.Assert(MemoryManager.IsPageAligned(limit)); // Note that this wastes a little bit of memory by allocating // table space to describe page-table memory! UIntPtr numPages = MemoryManager.PagesFromBytes(limit - start); UIntPtr bytesForTable = numPages * BytesPerTableEntry; bytesForTable = MemoryManager.PagePad(bytesForTable); UIntPtr pagesForTable = MemoryManager.PagesFromBytes(bytesForTable); pageCount = numPages - pagesForTable; startAddr = start + bytesForTable; heapLimit = limit; pageTable = (ushort *)start; heapLock = new SpinLock(SpinLock.Types.PhysicalHeap); // The entire heap is free to start out with freeList = new FreeList(); // Initialize the page table SetPages(startAddr, pageCount, FreePage); fixed(PhysicalHeap *thisPtr = &this) { freeList.CreateAndInsert(thisPtr, startAddr, pageCount); } CheckConsistency(); }