|
MentOS
0.8.0
The Mentoring Operating System
|
Classes | |
| struct | block_t |
| Represents a block of memory within the heap. This structure includes metadata for managing memory allocation and free status. More... | |
| struct | heap_header_t |
| Maps the heap memory to easily accessible values. This structure contains pointers to the list of all blocks and the list of free blocks. More... | |
Macros | |
| #define | __DEBUG_HEADER__ "[KHEAP ]" |
| Change header. | |
| #define | __DEBUG_LEVEL__ LOGLEVEL_INFO |
| Set log level. | |
| #define | HEAP_SIZE (4 * M) |
| The size of the heap in bytes, defined as 4 megabytes. | |
| #define | HEAP_VM_LB 0x40000000 |
| The lower bound address for virtual memory area placement. This address marks the starting point of the heap. | |
| #define | HEAP_VM_UB 0x50000000 |
| The upper bound address for virtual memory area placement. This address marks the endpoint of the heap, ensuring no overlap with other memory regions. | |
| #define | OVERHEAD sizeof(block_t) |
| The overhead introduced by the block_t structure itself. This is used for memory management and bookkeeping. | |
| #define | ADDR_ALIGN(addr) ((((uint32_t)(addr)) & 0xFFFFF000) + 0x1000) |
| Aligns the given address to the nearest upper page boundary. The address will be aligned to 4096 bytes (0x1000). More... | |
| #define | IS_ALIGN(addr) ((((uint32_t)(addr)) & 0x00000FFF) == 0) |
| Checks if the given address is aligned to a page boundary. More... | |
Typedefs | |
| typedef struct block_t | block_t |
| Represents a block of memory within the heap. This structure includes metadata for managing memory allocation and free status. | |
Functions | |
| static uint32_t | __blkmngr_get_rounded_size (uint32_t size) |
| Returns the given size, rounded to the nearest multiple of 16. This is useful for ensuring memory alignment requirements are met. More... | |
| static int | __blkmngr_does_it_fit (block_t *block, uint32_t size) |
| Checks if the given size fits inside the block. This function verifies whether the specified size can be accommodated within the block's available size. More... | |
| static const char * | __block_to_string (block_t *block) |
| Prepares a string that represents the block. This function formats the information of the specified block into a human-readable string. More... | |
| static void | __blkmngr_dump (heap_header_t *header) |
| Dumpts debug information about the heap. More... | |
| static block_t * | __blkmngr_find_best_fitting (heap_header_t *header, uint32_t size) |
| Find the best fitting block in the memory pool. More... | |
| static block_t * | __blkmngr_get_previous_block (heap_header_t *header, block_t *block) |
| Given a block, finds its previous block. More... | |
| static block_t * | __blkmngr_get_next_block (heap_header_t *header, block_t *block) |
| Given a block, finds its next block in the memory pool. More... | |
| static int | __blkmngr_is_previous_block (block_t *block, block_t *previous) |
Checks if the given previous block is actually the block that comes before block in the memory pool. More... | |
| static int | __blkmngr_is_next_block (block_t *block, block_t *next) |
Checks if the given next block is actually the block that comes after block in the memory pool. More... | |
| static int | __blkmngr_split_block (heap_header_t *header, block_t *block, uint32_t size) |
| Splits a block into two blocks based on the specified size for the first block. More... | |
| static int | __blkmngr_merge_blocks (heap_header_t *header, block_t *block, block_t *other) |
| Merges two adjacent blocks into the first block, effectively expanding its size. More... | |
| static void * | __do_brk (vm_area_struct_t *heap, uint32_t increment) |
| Extends the provided heap by a specified increment. More... | |
| static void * | __do_malloc (vm_area_struct_t *heap, size_t size) |
| Allocates a specified number of bytes of uninitialized storage from the heap. More... | |
| static int | __do_free (vm_area_struct_t *heap, void *ptr) |
| Deallocates previously allocated space, returning it to the heap. More... | |
| void * | sys_brk (void *addr) |
| User malloc. More... | |
| #define ADDR_ALIGN | ( | addr | ) | ((((uint32_t)(addr)) & 0xFFFFF000) + 0x1000) |
Aligns the given address to the nearest upper page boundary. The address will be aligned to 4096 bytes (0x1000).
| addr | The address to align. |
| #define IS_ALIGN | ( | addr | ) | ((((uint32_t)(addr)) & 0x00000FFF) == 0) |
Checks if the given address is aligned to a page boundary.
| addr | The address to check. |
Checks if the given size fits inside the block. This function verifies whether the specified size can be accommodated within the block's available size.
| block | The given block to check. Must not be NULL. |
| size | The size to check against the block's size. |
|
inlinestatic |
Dumpts debug information about the heap.
| header | the heap header. |
|
inlinestatic |
Find the best fitting block in the memory pool.
| header | header describing the heap. |
| size | the size we want. |
|
inlinestatic |
Given a block, finds its next block in the memory pool.
| header | The heap header containing information about the heap. |
| block | The current block for which the next block is to be found. |
|
inlinestatic |
Given a block, finds its previous block.
| header | the heap header. |
| block | the block. |
Returns the given size, rounded to the nearest multiple of 16. This is useful for ensuring memory alignment requirements are met.
| size | The given size to be rounded. |
Checks if the given next block is actually the block that comes after block in the memory pool.
| block | The current block from which we are checking the next block. |
| next | The block that is supposedly the next block. |
next is the actual next block of block, 0 otherwise. Returns -1 on error. Checks if the given previous block is actually the block that comes before block in the memory pool.
| block | The current block from which we are checking the previous block. |
| previous | The block that is supposedly the previous block. |
previous is the actual previous block of block, 0 otherwise. Returns -1 on error.
|
inlinestatic |
Merges two adjacent blocks into the first block, effectively expanding its size.
| header | The heap header containing metadata about the memory pool. |
| block | The first block that will be expanded. |
| other | The second block that will be merged into the first block, becoming invalid in the process. |
|
inlinestatic |
Splits a block into two blocks based on the specified size for the first block.
| header | The heap header containing metadata about the memory pool. |
| block | The block to be split, which must be free. |
| size | The size of the first of the two new blocks. Must be less than the original block's size minus overhead. |
|
inlinestatic |
Prepares a string that represents the block. This function formats the information of the specified block into a human-readable string.
| block | The block to represent. Can be NULL. |
|
static |
Extends the provided heap by a specified increment.
| heap | Pointer to the heap structure that tracks the heap's memory area. |
| increment | The amount by which to increase the heap size. |
|
static |
Deallocates previously allocated space, returning it to the heap.
| heap | Pointer to the heap to which the allocated memory is returned. |
| ptr | Pointer to the previously allocated memory to be deallocated. |
|
static |
Allocates a specified number of bytes of uninitialized storage from the heap.
| heap | Pointer to the heap from which we will allocate memory. |
| size | The size of the desired memory area to allocate. |
| void* sys_brk | ( | void * | addr | ) |
User malloc.
| addr | This argument is treated as an address of a dynamically allocated memory if falls inside the process heap area. Otherwise, it is treated as an amount of memory that should be allocated. |