PatchworkOS
Loading...
Searching...
No Matches
heap.c File Reference
#include "heap.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/bitmap.h>
#include <sys/io.h>
#include <sys/math.h>
#include <sys/proc.h>
#include <threads.h>

Go to the source code of this file.

Functions

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.
 
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 newSize)
 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.
 

Variables

static mtx_t mutex
 
static fd_t zeroDev = ERR
 
static list_t freeLists [_HEAP_NUM_BINS] = {0}
 
static bitmap_t freeBitmap = {0}
 
static uint64_t freeBitmapBuffer [BITMAP_BITS_TO_QWORDS(_HEAP_NUM_BINS)] = {0}
 
list_t _heapList = LIST_CREATE(_heapList)
 A list of all blocks sorted by address.
 

Variable Documentation

◆ freeBitmap

bitmap_t freeBitmap = {0}
static

◆ freeBitmapBuffer

uint64_t freeBitmapBuffer[BITMAP_BITS_TO_QWORDS(_HEAP_NUM_BINS)] = {0}
static

Definition at line 58 of file heap.c.

Referenced by _heap_init().

◆ freeLists

list_t freeLists[_HEAP_NUM_BINS] = {0}
static

◆ mutex

◆ zeroDev

fd_t zeroDev = ERR
static

Definition at line 37 of file heap.c.

Referenced by _heap_init(), and _heap_map_memory().