Files
2026-03-31 22:15:00 +02:00

35 lines
1.5 KiB
C

// SPDX-License-Identifier: MPL-2.0
#ifndef SH_LIB_HEAP_H
#define SH_LIB_HEAP_H
#include "memory/page.h"
#include "memory/pba.h"
#include "memory/pez/pez.h"
#include "memory/pez/radix.h"
#include "memory/slabs/slab_generic.h"
#include "std/status.h"
#include "std/type.h"
// Heap structure
typedef struct {
sh_pez_PHYSICAL_PLANE *phys_plane;
sh_pez_VIRTUAL_PLANE *virt_plane;
sh_page_PAGE_TABLE_POOL *kernel_ptp;
struct sh_slab_generic_SLAB_ALLOCATOR slabs_allocator[8];
sh_pba_PAGE_BLOCK_ALLOCATOR pba[8];
sh_radix_TREE alloc_size_tree;
} sh_heap_KERNEL_HEAP;
// Return default kernel heap
sh_heap_KERNEL_HEAP *sh_heap_get_default_heap();
// Load default kernel heap
void sh_heap_load_default_heap(sh_heap_KERNEL_HEAP *heap);
// Initialize heap structure, calling entity need to input manually all slabs allocator.
SH_STATUS sh_heap_init_heap(sh_pez_PHYSICAL_PLANE *phys_plane,sh_pez_VIRTUAL_PLANE *virt_plane,sh_page_PAGE_TABLE_POOL *kernel_ptp,sh_heap_KERNEL_HEAP *kernel_heap);
// Allocate a certain amount of pages from Pez physical backend
SH_STATUS sh_heap_allocate_pages(sh_uint32 pages_count,sh_page_VIRTUAL_ADDRESS *address);
// Free a allocated region of pages from the heap
SH_STATUS sh_heap_free_pages(sh_page_VIRTUAL_ADDRESS va);
// Allocate a certain object based on his size
SH_STATUS sh_heap_allocate_object(sh_uint32 size_bytes,sh_page_VIRTUAL_ADDRESS *address);
// Free a certain object based on his size
SH_STATUS sh_heap_free_object(sh_page_VIRTUAL_ADDRESS va);
#endif