MyOS Libc
stdlib.c File Reference
#include <math.h>
#include <memory.h>
#include <stdlib.h>
#include <string.h>

Data Structures

struct  heap_block
 

Macros

#define MAX_BLOCKS   512
 Maximum number of blocks that can be used.
 

Functions

static char get_bmap_bit (char *bmap, size_t index)
 
static void set_bmap_bit (char *bmap, size_t index)
 
static void clear_bmap_bit (char *bmap, size_t index)
 
static void reserve_block (size_t mem_blks)
 
void * malloc (size_t size)
 
void * realloc (void *mem, size_t new_sz)
 
void free (void *mem)
 

Variables

static heap_block entries [MAX_BLOCKS]
 List of blocks in the heap.
 
static size_t num_used_entries =0
 Number of blocks in the heap.
 

Function Documentation

◆ clear_bmap_bit()

static void clear_bmap_bit ( char *  bmap,
size_t  index 
)
static

Clear a bit in a bitmap

Parameters
bmapThe bitmap
indexThe index in the bitmap

◆ free()

void free ( void *  mem)

Frees a block of memory on the heap

Parameters
memThe block of memory to free

◆ get_bmap_bit()

static char get_bmap_bit ( char *  bmap,
size_t  index 
)
static

Get a bit in a bitmap

Parameters
bmapThe bitmap
indexThe index in the bitmap
Returns
the bit

◆ malloc()

void* malloc ( size_t  size)

Allocates a block of memory on the heap

Parameters
sizeThe size of the block to allocate
Returns
The address of the allocated block, or NUL if the allocation failed

◆ realloc()

void* realloc ( void *  mem,
size_t  new_sz 
)

Changes a block of memory on the heap to a new size, or if mem is NULL, act like malloc

Parameters
memThe block of memory to change size
new_szThe size of the block to allocate
Returns
The new address of the allocated block, or NUL if the allocation failed

◆ reserve_block()

static void reserve_block ( size_t  mem_blks)
static

Add a block to the heap

Parameters
mem_blksThe number of pages that this block will use

◆ set_bmap_bit()

static void set_bmap_bit ( char *  bmap,
size_t  index 
)
static

Set a bit in a bitmap

Parameters
bmapThe bitmap
indexThe index in the bitmap