Example #1
0
        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);
        }
Example #2
0
        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);
            }
        }
Example #3
0
 private Page *Allocate(uint num)
 {
     return(BuddyAllocatorImplementation.buddy_get_pages(ZonePtr, GetOrderForPageCount(num)));
 }
Example #4
0
 public uint GetAddress(Page *page)
 {
     return((uint)BuddyAllocatorImplementation.page_to_virt(ZonePtr, page));
 }
Example #5
0
 public uint GetPageNum(Page *page)
 {
     return((uint)BuddyAllocatorImplementation.page_to_virt(ZonePtr, page) >> BuddyAllocatorImplementation.BUDDY_PAGE_SHIFT);
 }
Example #6
0
 public void Free(Page *page)
 {
     BuddyAllocatorImplementation.buddy_free_pages(ZonePtr, page);
 }
Example #7
0
 public Page *GetPageByNum(uint pageNum)
 {
     return(BuddyAllocatorImplementation.virt_to_page(ZonePtr, (void *)(pageNum << BuddyAllocatorImplementation.BUDDY_PAGE_SHIFT)));
 }
Example #8
0
 public Page *GetPageByAddress(Addr addr)
 {
     return(BuddyAllocatorImplementation.virt_to_page(ZonePtr, addr));
 }