My Kernel v0.1.0

Internal functions and structures used for managing buckets. More...

Collaboration diagram for Kmalloc - Internals:

Data Structures

struct  bucket_meta
 The metadata for a single bucket. More...
 

Macros

#define KMALLOC_ALIGNMENT   (32)
 All returned addresses are aligned on a 32B boundary.
 
#define KMALLOC_FREE_MAGIC   (0x3402CECE)
 Magic value to detect if a block is free. More...
 

Functions

static bucket_tbucket_find (llist_t *buckets, size_t size, const u16 flags)
 Find a bucket containing with at least one free block of the given size.
 
static void * bucket_get_free_block (bucket_t *bucket)
 Reserve a free block inside a bucket.
 
static struct bucket_metabucket_create (struct address_space *as, llist_t *buckets, size_t block_size, const u16 flags)
 Create a new empty bucket for blocks of size block_size.
 
static void bucket_free_block (struct address_space *as, bucket_t *bucket, void *block)
 Free a block inside a bucket.
 

Detailed Description

Macro Definition Documentation

◆ KMALLOC_FREE_MAGIC

#define KMALLOC_FREE_MAGIC   (0x3402CECE)

To prevent corrupting the metadata by freeing the same block multiple times we write this number right after the linked list node when freeing a block. We then check for this arbitrary value before freeing it. If it's present this means we're freeing an already free block.