MyOS Kernel
kmalloc.c File Reference
#include "cpu/arch_consts.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>

Macros

#define KMALLOC_BMAP_SZ   (((KMALLOC_SZ*1024)/4)/8)
 The size of the kmalloc bitmap.
 

Functions

static char get_bmap_bit (size_t index)
 
static void set_bmap_bit (size_t index)
 
static void clear_bmap_bit (size_t index)
 
void * kmalloc (size_t size)
 
void kfree (void *mem)
 

Variables

static char bitmap [KMALLOC_BMAP_SZ]
 Bitmap of used areas of the heap.
 
static void * data =(void*)KMALLOC_START
 Start of the kmalloc heap.
 

Function Documentation

◆ clear_bmap_bit()

static void clear_bmap_bit ( size_t  index)
static

Clear a bit in the heap bitmap

Parameters
indexThe bit to clear

◆ get_bmap_bit()

static char get_bmap_bit ( size_t  index)
static

Get a bit in the heap bitmap

Parameters
indexThe bit to get
Returns
the bit

◆ kfree()

void kfree ( void *  mem)

Free a block in the kernel heap

Parameters
memThe address of the block

◆ kmalloc()

void* kmalloc ( size_t  size)

Allocate a block in the kernel heap

Parameters
sizeThe size of the block
Returns
the address of the block in the heap.

◆ set_bmap_bit()

static void set_bmap_bit ( size_t  index)
static

Set a bit in the heap bitmap

Parameters
indexThe bit to set