IBNOS
Classes | Macros | Functions
Allocator

Classes

struct  heapEntry
 

Macros

#define HEAP_ALIGN_SIZE   16
 
#define HEAP_ALIGN_MASK   (HEAP_ALIGN_SIZE - 1)
 
#define SMALL_HEAP_MAGIC   0xFEEFABB1
 
#define LARGE_HEAP_MAGIC   0xFEEFABB2
 

Functions

void * heapAlloc (uint32_t length)
 Allocates a block of kernel memory. More...
 
void heapFree (void *addr)
 Deallocates a block of kernel memory. More...
 
uint32_t heapSize (void *addr)
 Determines the size of a specific kernel memory block. More...
 
void * heapReAlloc (void *addr, uint32_t length)
 Resizes a block of kernel memory. More...
 
void heapVerify ()
 Runs some internal checks to ensure that the heap is still valid. More...
 

Detailed Description

Implementation of the kernel memory allocator.

Macro Definition Documentation

◆ HEAP_ALIGN_MASK

#define HEAP_ALIGN_MASK   (HEAP_ALIGN_SIZE - 1)

Definition at line 40 of file allocator.c.

◆ HEAP_ALIGN_SIZE

#define HEAP_ALIGN_SIZE   16

Definition at line 39 of file allocator.c.

◆ LARGE_HEAP_MAGIC

#define LARGE_HEAP_MAGIC   0xFEEFABB2

Definition at line 42 of file allocator.c.

◆ SMALL_HEAP_MAGIC

#define SMALL_HEAP_MAGIC   0xFEEFABB1

Definition at line 41 of file allocator.c.

Function Documentation

◆ heapAlloc()

void* heapAlloc ( uint32_t  length)

Allocates a block of kernel memory.

Allocates a block of kernel memory of the requested size. The algorithm will always return a pointer aligned to a 16-byte boundary, or NULL if the request cannot be fulfilled. The new memory block will not be initialized.

Parameters
lengthNumber of bytes to allocate
Returns
Pointer to the allocated memory block or NULL if the request cannot be fulfilled

Definition at line 363 of file allocator.c.

◆ heapFree()

void heapFree ( void *  addr)

Deallocates a block of kernel memory.

Verifies that the provided memory pointer is valid, and afterwards releases the full block. If something goes wrong an assertion is thrown. This typically means that the application has corrupted the block header.

Parameters
addrPointer to a memory block allocated with heapAlloc()

Definition at line 385 of file allocator.c.

◆ heapReAlloc()

void* heapReAlloc ( void *  addr,
uint32_t  length 
)

Resizes a block of kernel memory.

Provides a fast method to change the size of a memory block. If the return value is NULL then it was impossible to fulfill the request (for example not enough memory left). Otherwise this function returns a pointer to the new location of the memory block, which can be, but is not necessarily equal to the previous location. The new bytes of memory are not initialized before this function returns.

Parameters
addrPointer to a memory block
lengthNew requested length
Returns
Pointer to a new block of kernel memory

Definition at line 439 of file allocator.c.

◆ heapSize()

uint32_t heapSize ( void *  addr)

Determines the size of a specific kernel memory block.

Returns the number of bytes of a specific kernel memory block. The result of this function can be greater than the requested size specified when calling heapAlloc() due to align issues.

Parameters
addrPointer to a memory block allocated with heapAlloc()
Returns
Size of the memory block in bytes

Definition at line 411 of file allocator.c.

◆ heapVerify()

void heapVerify ( )

Runs some internal checks to ensure that the heap is still valid.

Definition at line 485 of file allocator.c.