• Charles Jacobsen's avatar
    test-v2: RAM map tests pass. · c543053a
    Charles Jacobsen authored
    Couple duplicate memory interval tree inserts/deletes were leading
    to some use-after-frees/page faults. Cleaned that up. Added some
    resource tree debug code along the way.
    Also, caught something subtle (noted in code). I didn't consider
    the following scenario: Heap tries to allocate pages; the allocator
    notices it needs to bring in more fresh pages, and notifies the
    heap (via a callback); the heap allocs the fresh pages (from the
    microkernel), maps them, and inserts those pages into the memory interval
    tree; the memory interval tree kmallocs a tree node; kmalloc
    calls back into the heap to grow a slab cache.
    That last bit could be a potential problem (recursive call back
    into the heap before we finish the original call). Lucky for me,
    I designed the heap/allocator so that (1) the pages from the first
    call are already marked as in use (not on a free list); (2) the
    fresh pages are mapped first *before* inserting the corresponding
    cptr into the memory interval tree.
    The Linux kernel deals with these same recursive issues (they
    resolve them using special GFP_ flags so that you don't get
    recursion). In my case, the recursion is risky, but works.
heap.c 11.2 KB