GitOS
Operating system exercise
Loading...
Searching...
No Matches
heap.c File Reference
#include "heap.h"
#include "../../common/status.h"
#include "../memory.h"

Functions

void heap_mark_blocks_taken (heap *heap, int start_block, int total_blocks)
 Marks blocks taken.
 
int heap_create (heap *heap, heap_table *table, void *ptr, void *end)
 Creates heap in specified chunk of memory.
 
void * heap_malloc (heap *heap, uint32_t size)
 Allocates memory in heap.
 
void heap_free (heap *heap, void *ptr)
 Frees specified pointer in heap.
 

Function Documentation

◆ heap_create()

int heap_create ( heap heap,
heap_table table,
void *  ptr,
void *  end 
)

Creates heap in specified chunk of memory.

Parameters
heapHeap to manage
tableHeap table to manage
ptrStarting address
endEnding address
Returns
int Status

References EINVARG, heap_table::entries, HEAP_BLOCK_TABLE_ENTRY_FREE, memset(), heap::start_address, heap::table, and heap_table::total.

◆ heap_free()

void heap_free ( heap heap,
void *  ptr 
)

Frees specified pointer in heap.

Parameters
heapHeap to manage
ptrPointer to free

◆ heap_malloc()

void * heap_malloc ( heap heap,
uint32_t  size 
)

Allocates memory in heap.

Parameters
heapHeap to manage
sizeRequested allocation size
Returns
void* Pointer to allocated memory, 0 if errored

References HEAP_BLOCK_SIZE, and size.

◆ heap_mark_blocks_taken()

void heap_mark_blocks_taken ( heap heap,
int  start_block,
int  total_blocks 
)

Marks blocks taken.

Parameters
heapHeap to manage
start_blockStarting block to mark taken
total_blocksTotal amount of blocks to mark taken

References heap_table::entries, HEAP_BLOCK_HAS_NEXT, HEAP_BLOCK_TABLE_ENTRY_TAKEN, and heap::table.