MushOS
0.1
A UNIX-like OS prototype, written from scratch
|
This is a standard implementation of heap for MushLib. More...
Go to the source code of this file.
Data Structures | |
struct | heap_header |
struct | heap_block_header |
Functions | |
boolean | is_in_heap (void *structure) |
static heap_block_header * | get_header (void *structure) |
u_dword | size (void *structure) |
precise | occupation () |
static void * | allocate_space (void *free_pointer, u_dword size, heap_block_header *previous, heap_block_header *next) |
static void | handle_allocation_exception () |
void | initialize_heap (void *start_address, u_dword initial_size) |
void * | ralloc (u_dword size) |
void * | zalloc (u_dword size) |
void * | challoc (void *structure, u_dword new_size) |
void | unalloc (void *structure) |
Variables | |
heap_header * | header |
This is a standard implementation of heap for MushLib.
The heap doesn't use paging, so it has a limited size. This allows kernel to use it right after launch, but there's also a significant drawback: when kernel heap gets overflown, no standard exception can be shown (because it requires heap space allocation). The drawback is handled with kernel allocation exception handler . Any non-kernel apps may set up their own kernel exception handler (using allocation_exception_id) or just do nothing - default allocation exception handler will allow kernel to terminate safely any app with overflown heap.
Definition in file lib/base/heap.c.
boolean is_in_heap | ( | void * | structure | ) |
Function for determining whether the structure is inside the heap or outside.
structure | a pointer to the structure. |
Definition at line 49 of file lib/base/heap.c.
References header.
Referenced by get_header().
|
static |
Internal function for getting heap header of any structure located in heap. It just substracts heap block header size from pointer and casts it to heap block header. Throws heap exception if the given pointer is outside of the current heap.
structure | a pointer to the structure. |
Definition at line 60 of file lib/base/heap.c.
References heap_exception_id, heap_exception_type, and is_in_heap().
Referenced by allocate_space(), challoc(), occupation(), ralloc(), size(), and unalloc().
u_dword size | ( | void * | structure | ) |
Function for structure located in heap size calculation (in bytes). Throws heap exception if the given pointer is outside of the current heap.
structure | a pointer to the structure. |
Definition at line 65 of file lib/base/heap.c.
References get_header().
Referenced by allocate_space(), challoc(), ralloc(), and zalloc().
precise occupation | ( | ) |
Function for heap occupation calculation.
Definition at line 69 of file lib/base/heap.c.
References get_header(), and header.
|
static |
Internal function for space allocation in heap. Sets up and fills heap block header, optionally alters headers of the next and previous heap blocks.
free_pointer | pointer to free space (heap block header size + required size). |
size | required size of heap block. |
previous | previous heap block. |
next | next heap block. |
Definition at line 95 of file lib/base/heap.c.
References get_header(), and size().
Referenced by ralloc().
|
static |
Allocation exception can't be handled regularily: handling requires heap. So, heap exception terminate app without any on-screen explanation.
Definition at line 111 of file lib/base/heap.c.
References heap_exception_id.
Referenced by initialize_heap().
void initialize_heap | ( | void * | start_address, |
u_dword | initial_size | ||
) |
Function for heap initialization, sets up singleton heap header. This implementation of heap has fixed size, and so doesn't rely on paging. That's enough for kernel and basic app needs, TODO: provide another heap implementation for extended MushLib.
start_address | pointer to the start of the heap. |
initial_size | initial size of the heap. |
Definition at line 116 of file lib/base/heap.c.
References allocation_exception_id, handle_allocation_exception(), and header.
Referenced by _start().
void * ralloc | ( | u_dword | size | ) |
Function for allocation of a raw heap block. Searches for a place of suitable size to fit a structure of requested size in. Throws allocation exception if no free space is available.
size | requested block size. |
Definition at line 125 of file lib/base/heap.c.
References allocate_space(), allocation_exception_id, allocation_exception_type, get_header(), header, and size().
void * zalloc | ( | u_dword | size | ) |
Function for allocation of a heap block and clearing it. Does the same as ralloc
, but sets every allocated byte to zero. Throws allocation exception if no free space is available.
size | requested block size. |
Definition at line 171 of file lib/base/heap.c.
void * challoc | ( | void * | structure, |
u_dword | new_size | ||
) |
Function for heap block size alteration. Attempts to alter size in-place and copys the block only if in-place growth is not available. Throws heap exception if the structure is located outside of the heap.
structure | pointer to the structure for allocation size changing. |
new_size | new requested size of the structure. |
Definition at line 177 of file lib/base/heap.c.
References get_header(), ralloc(), size(), and unalloc().
void unalloc | ( | void * | structure | ) |
Function for heap block unallocation. Throws heap exception if the structure is located outside of the heap.
structure | pointer to the structure for unallocation. |
Definition at line 193 of file lib/base/heap.c.
References get_header(), and header.
Referenced by challoc().
heap_header* header |
Header of the current app heap. Every app in MushOS has its own heap. This implementation of heap is a singleton.
Definition at line 46 of file lib/base/heap.c.
Referenced by initialize_heap(), is_in_heap(), occupation(), ralloc(), and unalloc().