GitOS
Operating system exercise
Loading...
Searching...
No Matches
heap.h File Reference
#include <stdint.h>
#include <stddef.h>

Go to the source code of this file.

Data Structures

struct  heap_table
 
struct  heap
 

Macros

#define HEAP_BLOCK_TABLE_ENTRY_TAKEN   0x01
 
#define HEAP_BLOCK_TABLE_ENTRY_FREE   0x00
 
#define HEAP_BLOCK_HAS_NEXT   0b10000000
 
#define HEAP_BLOCK_IS_FIRST   0b01000000
 
#define HEAP_TABLE_ADDRESS   0x00007e00
 
#define HEAP_BLOCK_SIZE   4096
 

Typedefs

typedef unsigned char HEAP_BLOCK_TABLE_ENTRY
 

Functions

int heap_create (heap *heap, heap_table *table, void *ptr, void *end)
 Creates heap in specified chunk of memory.
 
void * heap_malloc (heap *heap, size_t size)
 
void heap_free (heap *heap, void *ptr)
 Frees specified pointer in heap.
 

Macro Definition Documentation

◆ HEAP_BLOCK_HAS_NEXT

#define HEAP_BLOCK_HAS_NEXT   0b10000000

◆ HEAP_BLOCK_IS_FIRST

#define HEAP_BLOCK_IS_FIRST   0b01000000

◆ HEAP_BLOCK_SIZE

#define HEAP_BLOCK_SIZE   4096

◆ HEAP_BLOCK_TABLE_ENTRY_FREE

#define HEAP_BLOCK_TABLE_ENTRY_FREE   0x00

◆ HEAP_BLOCK_TABLE_ENTRY_TAKEN

#define HEAP_BLOCK_TABLE_ENTRY_TAKEN   0x01

◆ HEAP_TABLE_ADDRESS

#define HEAP_TABLE_ADDRESS   0x00007e00

Typedef Documentation

◆ HEAP_BLOCK_TABLE_ENTRY

typedef unsigned char HEAP_BLOCK_TABLE_ENTRY

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,
size_t  size 
)