/// <summary> /// Add a new root block for a certain size /// </summary> /// <param name="aSize">Size must be divisible by 2 otherwise Alloc breaks</param> private static void AddRootSMTBlock(SMTPage *aPage, uint aSize) { RootSMTBlock *ptr = aPage->First; while (ptr->LargerSize != null) { ptr = ptr->LargerSize; } if (aSize < ptr->Size) { // we cant later add a block with a size smaller than an earlier block. That would break the algorithm Debugger.DoSendNumber(aSize); Debugger.DoSendNumber(ptr->Size); Debugger.SendKernelPanic(0x83); while (true) { } } if (ptr->Size == 0) { ptr->Size = aSize; } else { var block = (RootSMTBlock *)NextFreeBlock(aPage); // we should actually check that this is not null //but we should also only call this code right at the beginning so it should be fine block->Size = aSize; ptr->LargerSize = block; } CreatePage(aPage, aSize); }
/// <summary> /// Gets the root block in the SMT for objects of this size /// </summary> /// <param name="aSize">Size of allocated block</param> /// <param name="aPage">Page to seach in</param> /// <returns>Pointer of block in SMT.</returns> private static RootSMTBlock *GetFirstBlock(SMTPage *aPage, uint aSize) { RootSMTBlock *ptr = aPage->First; uint curSize = ptr->Size; while (curSize < aSize) { ptr = ptr->LargerSize; if (ptr == null) { return(null); } curSize = ptr->Size; } return(ptr); }
/// <summary> /// Get the first block for this size, which has space left to allocate to /// </summary> /// <param name="aSize"></param> /// <param name="root">The root node to start the search at</param> /// <returns></returns> private static SMTBlock *GetFirstWithSpace(uint aSize, RootSMTBlock *root) { SMTBlock *ptr = root->First; if (ptr == null) { return(null); } var lptr = ptr; while (ptr->SpacesLeft == 0 && ptr->NextBlock != null) { lptr = ptr; ptr = ptr->NextBlock; } if (ptr->SpacesLeft == 0 && ptr->NextBlock == null) { return(null); } return(ptr); }