public virtual void Setup(MemoryRegion region, AddressSpaceKind addressSpaceKind) { AddressSpaceKind = addressSpaceKind; region.Size = KMath.FloorToPowerOfTwo(region.Size); _Region = region; var totalPages = region.Size >> BuddyAllocatorImplementation.BUDDY_PAGE_SHIFT; KernelMessage.WriteLine("Init Allocator: StartAddr: {0}, {1} Pages", region.Start, totalPages); // init global memory block // all pages area var pages_size = totalPages * (uint)sizeof(Page); KernelMessage.WriteLine("Page Array Size in bytes: {0}", pages_size); Pages = (Page *)AllocRawMemory(pages_size).Start; KernelMessage.WriteLine("Page Array Addr: {0:X8}", (uint)Pages); var start_addr = region.Start; Zone.free_area = (BuddyAllocatorImplementation.free_area *)AllocRawMemory(BuddyAllocatorImplementation.BUDDY_MAX_ORDER * (uint)sizeof(BuddyAllocatorImplementation.free_area)).Start; fixed(BuddyAllocatorImplementation.mem_zone *zone = &Zone) ZonePtr = zone; BuddyAllocatorImplementation.buddy_system_init( ZonePtr, Pages, start_addr, totalPages); }
public Page *NextCompoundPage(Page *page) { if (page == null) { return(null); } var next = NextPage(page); if (next == null) { return(null); } if (BuddyAllocatorImplementation.PageHead(page)) { if (BuddyAllocatorImplementation.PageTail(next)) { return(next); } else { return(null); } } else if (BuddyAllocatorImplementation.PageTail(page)) { if (BuddyAllocatorImplementation.PageTail(next)) { return(next); } else { return(null); } } else { return(null); } }
private Page *Allocate(uint num) { return(BuddyAllocatorImplementation.buddy_get_pages(ZonePtr, GetOrderForPageCount(num))); }
public uint GetAddress(Page *page) { return((uint)BuddyAllocatorImplementation.page_to_virt(ZonePtr, page)); }
public uint GetPageNum(Page *page) { return((uint)BuddyAllocatorImplementation.page_to_virt(ZonePtr, page) >> BuddyAllocatorImplementation.BUDDY_PAGE_SHIFT); }
public void Free(Page *page) { BuddyAllocatorImplementation.buddy_free_pages(ZonePtr, page); }
public Page *GetPageByNum(uint pageNum) { return(BuddyAllocatorImplementation.virt_to_page(ZonePtr, (void *)(pageNum << BuddyAllocatorImplementation.BUDDY_PAGE_SHIFT))); }
public Page *GetPageByAddress(Addr addr) { return(BuddyAllocatorImplementation.virt_to_page(ZonePtr, addr)); }