kernel/src/allocator/mem_alloc.c
void init_heap() {
    heap_end = KERNEL_HEAP_BASE;

    // Allocate space for the heap_t struct. is too large but at least big enough.
    void * ret = vm2_allocate_page(kernell1PageTable,
                                   KERNEL_HEAP_BASE,
                                   false,
                                   (struct PagePermission){.access = KernelRW, .executable = false},
                                   NULL);
    if (ret == NULL) { FATAL("Couldn't allocate page for the kernel heap"); }

    heap_t * heap = (heap_t *)KERNEL_HEAP_BASE;

    memset(heap, 0, sizeof(heap_t));

    heap_end += sizeof(heap_t);


    for (int i = 0; i < BIN_COUNT; i++) {
        heap->bins[i] = (bin_t *)heap_end;
        memset(heap->bins[0], 0, sizeof(bin_t));
        heap_end += sizeof(bin_t);
    }

    assert(KERNEL_HEAP_BASE + sizeof(heap_t) + BIN_COUNT * sizeof(bin_t) == heap_end);

    // current heap end.
    heap_end = ALIGN(heap_end, PAGE_SIZE);
    size_t heap_start = heap_end;

    while (heap_end < (heap_start + HEAP_INIT_SIZE)) {
        if (vm2_allocate_page(kernell1PageTable,
                              heap_end,
                              false,
                              (struct PagePermission){.access = KernelRW, .executable = false},
                              NULL) == NULL) {
            FATAL("Allocation of the kernel heap went wrong!");
        }

        heap_end += PAGE_SIZE;
    }

    assert(heap_end >= (heap_start + HEAP_INIT_SIZE));

    create_heap(heap, heap_start);
    allocator = heap;

    INFO("Heap successfully initialized.");
}
/// Initializes the heap by asking for HEAP_INIT_SIZE of pages, and putting the heap datastructure
/// there. After the heap is initialized [kmalloc] and related functions can be used.
Initializes the heap by asking for HEAP_INIT_SIZE of pages, and putting the heap datastructure
there. After the heap is initialized [kmalloc] and related functions can be used.
Initializes the heap by asking for HEAP_INIT_SIZE of pages and putting the heap datastructure there . After the heap is initialized [ kmalloc ] and related functions can be used .
void init_heap() {
    heap_end = KERNEL_HEAP_BASE;
    void * ret = vm2_allocate_page(kernell1PageTable,
                                   KERNEL_HEAP_BASE,
                                   false,
                                   (struct PagePermission){.access = KernelRW, .executable = false},
                                   NULL);
    if (ret == NULL) { FATAL("Couldn't allocate page for the kernel heap"); }
    heap_t * heap = (heap_t *)KERNEL_HEAP_BASE;
    memset(heap, 0, sizeof(heap_t));
    heap_end += sizeof(heap_t);
    for (int i = 0; i < BIN_COUNT; i++) {
        heap->bins[i] = (bin_t *)heap_end;
        memset(heap->bins[0], 0, sizeof(bin_t));
        heap_end += sizeof(bin_t);
    }
    assert(KERNEL_HEAP_BASE + sizeof(heap_t) + BIN_COUNT * sizeof(bin_t) == heap_end);
    heap_end = ALIGN(heap_end, PAGE_SIZE);
    size_t heap_start = heap_end;
    while (heap_end < (heap_start + HEAP_INIT_SIZE)) {
        if (vm2_allocate_page(kernell1PageTable,
                              heap_end,
                              false,
                              (struct PagePermission){.access = KernelRW, .executable = false},
                              NULL) == NULL) {
            FATAL("Allocation of the kernel heap went wrong!");
        }
        heap_end += PAGE_SIZE;
    }
    assert(heap_end >= (heap_start + HEAP_INIT_SIZE));
    create_heap(heap, heap_start);
    allocator = heap;
    INFO("Heap successfully initialized.");
}
void init_heap ( ) { heap_end = KERNEL_HEAP_BASE ; void * ret = vm2_allocate_page ( kernell1PageTable , KERNEL_HEAP_BASE , false , ( struct PagePermission ) { . access = KernelRW , . executable = false } , NULL ) ; if ( ret == NULL ) { FATAL ( " " ) ; } heap_t * heap = ( heap_t * ) KERNEL_HEAP_BASE ; memset ( heap , 0 , sizeof ( heap_t ) ) ; heap_end += sizeof ( heap_t ) ; for ( int i = 0 ; i < BIN_COUNT ; i ++ ) { heap -> bins [ i ] = ( bin_t * ) heap_end ; memset ( heap -> bins [ 0 ] , 0 , sizeof ( bin_t ) ) ; heap_end += sizeof ( bin_t ) ; } assert ( KERNEL_HEAP_BASE + sizeof ( heap_t ) + BIN_COUNT * sizeof ( bin_t ) == heap_end ) ; heap_end = ALIGN ( heap_end , PAGE_SIZE ) ; size_t heap_start = heap_end ; while ( heap_end < ( heap_start + HEAP_INIT_SIZE ) ) { if ( vm2_allocate_page ( kernell1PageTable , heap_end , false , ( struct PagePermission ) { . access = KernelRW , . executable = false } , NULL ) == NULL ) { FATAL ( " " ) ; } heap_end += PAGE_SIZE ; } assert ( heap_end >= ( heap_start + HEAP_INIT_SIZE ) ) ; create_heap ( heap , heap_start ) ; allocator = heap ; INFO ( " " ) ; }
Initializes the heap by asking for HEAP_INIT_SIZE of pages, and putting the heap datastructure
there.
Initializes the heap by asking for HEAP_INIT_SIZE of pages and putting the heap datastructure there .
// Allocate space for the heap_t struct. is too large but at least big enough. // current heap end.