PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
heap.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include <sys/list.h>
#include <sys/proc.h>
Include dependency graph for heap.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _heap_header_t
 

Macros

#define _HEAP_ALIGNMENT   64
 
#define _HEAP_HEADER_MAGIC   0xDEADBEEF
 
#define _HEAP_LARGE_ALLOC_THRESHOLD   (PAGE_SIZE * 4)
 
#define _HEAP_NUM_BINS   (_HEAP_LARGE_ALLOC_THRESHOLD / _HEAP_ALIGNMENT)
 

Enumerations

enum  _heap_flags_t { _HEAP_ALLOCATED = 1 << 0 , _HEAP_MAPPED = 1 << 1 , _HEAP_ZEROED = 1 << 2 }
 Flags for heap blocks. More...
 

Functions

void _heap_init (void)
 Initialize the heap.
 
void _heap_acquire (void)
 Acquire the heap lock.
 
void _heap_release (void)
 Release the heap lock.
 
uint64_t _heap_get_bin_index (uint64_t size)
 Get the bin index for a given size.
 
_heap_header_t_heap_block_new (uint64_t minSize)
 Directly maps a new heap block of at least minSize bytes.
 
void _heap_block_split (_heap_header_t *block, uint64_t size)
 Splits a heap block into two blocks, the first of size bytes and the second with the remaining bytes.
 
void _heap_add_to_free_list (_heap_header_t *block)
 Adds a block to the appropriate free list.
 
void _heap_remove_from_free_list (_heap_header_t *block)
 Removes a block from its free list.
 
_heap_header_t_heap_alloc (uint64_t size)
 Allocates a block of memory of given size.
 
void _heap_free (_heap_header_t *block)
 Frees a previously allocated heap block.
 
void * _heap_map_memory (uint64_t size)
 Directly maps memory of the given size.
 
void _heap_unmap_memory (void *addr, uint64_t size)
 Unmaps previously mapped memory.
 

Variables

list_t _heapList
 A list of all blocks sorted by address.