Modestus Moon OS
R4
CS 450 project
|
#include <core/mcb.h>
Go to the source code of this file.
Functions | |
void | initHeap (size_t initialHeapSize) |
initHeap initializes the system heap by calling kmalloc with a valid byte size. Creates a CMCB at the beginning and an LMCB at the end. Note the total size is the given size + sizeof(CMCB) + sizeof(LMCB). More... | |
void * | allocateMemFromHeap (size_t requestedSize) |
allocateMemFromHeap takes the requested size and finds the first block that fits. Implements first fit. Size_t is unsigned. More... | |
void | printAlloc () |
printAlloc prints the allocated memory blocks. Traverses through the allocated mcb list. More... | |
void | printFree () |
printFree prints the free memory blocks. Traverses through the free mcb list. More... | |
int | mcbCompareFunc (void *mcb, void *mcbToCompare) |
mcbCompareFunc compares the start addresses of two mcbs. More... | |
int | mcbSearchCompFunc (void *mcb, void *blockStartAddress) |
mcbSearchCompFunc searches for the mcb that you want to compare with. More... | |
int | freeHeapMem (void *blockAddress) |
freeHeapMem takes the block address and frees the memory from the CMCB start to the LMCB end location and calls reclaimFreeMem() function. More... | |
void | reclaimFreeMem () |
reclaimFreeMem groups free blocks together if they are adjacent. More... | |
void | printMCBFunc (void *cmcb) |
printMCBFunc prints the type, block size, block pointer of the blocks in a given list. More... | |
int | heapIsEmpty () |
heapIsEmpty returns if the heap is empty. More... | |
const char * | mcbResultToString (e_mcb_result_t result) |
const char * | mcbTypeToString (e_mcb_type_t type) |
void | insertMCBIntoList (cmcb_t *blockToInsert) |
insertMCBIntoList inserts the mcb into the list specified. More... | |
void | heapTest () |
heapTest test function to create sample mcbs. More... | |
Variables | |
heapLocationPtr_t | heapLoc =0 |
linkedList_t | mcbFreeList |
linkedList_t | mcbAllocList |
e_mcb_result_t | lastMCBError = MCB_SUCCESS |
void* allocateMemFromHeap | ( | size_t | requestedSize | ) |
allocateMemFromHeap takes the requested size and finds the first block that fits. Implements first fit. Size_t is unsigned.
requestedSize | size in bytes to the allocated from the heap. |
Definition at line 45 of file mcb.c.
References s_cmcb::associatedLMCB, s_cmcb::blockStartAddress, s_lmcb::blockStopAddress, s_cmcb::cmcbType, currentOperatingProcess, ERROR_BLOCK_NOT_ALLOCATED, ERROR_NOT_ENOUGH_MEMORY, insertMCBIntoList(), lastMCBError, s_lmcb::lmcbType, MCB_ALLOCATED, MCB_FREE, MCB_SUCCESS, s_cmcb::mcbBlockSize, s_lmcb::mcbBlockSize, s_cmcb::procName, removeNode(), and s_cmcb::representingNode.
Referenced by heapTest(), and kmain().
int freeHeapMem | ( | void * | blockAddress | ) |
freeHeapMem takes the block address and frees the memory from the CMCB start to the LMCB end location and calls reclaimFreeMem() function.
blockAddress | pointer to the memory address to be freed. |
Definition at line 154 of file mcb.c.
References s_cmcb::associatedLMCB, s_cmcb::cmcbType, currentOperatingProcess, ERROR_BLOCK_NOT_FOUND, insertMCBIntoList(), lastMCBError, s_lmcb::lmcbType, MCB_ERROR_ACCESS_DENIED, MCB_FREE, MCB_SUCCESS, printMCBFunc(), s_cmcb::procName, reclaimFreeMem(), removeNode(), s_cmcb::representingNode, and searchList().
Referenced by heapTest(), and kmain().
int heapIsEmpty | ( | ) |
heapIsEmpty returns if the heap is empty.
Definition at line 229 of file mcb.c.
References lastMCBError, and MCB_SUCCESS.
void heapTest | ( | ) |
heapTest test function to create sample mcbs.
Definition at line 286 of file mcb.c.
References allocateMemFromHeap(), freeHeapMem(), lastMCBError, MCB_SUCCESS, mcbResultToString(), printf, and printList().
Referenced by mcbFunc().
void initHeap | ( | size_t | initialHeapSize | ) |
initHeap initializes the system heap by calling kmalloc with a valid byte size. Creates a CMCB at the beginning and an LMCB at the end. Note the total size is the given size + sizeof(CMCB) + sizeof(LMCB).
initialHeapSize | the size in bytes of the heap to be created |
Definition at line 11 of file mcb.c.
References s_cmcb::associatedLMCB, s_cmcb::blockStartAddress, s_lmcb::blockStopAddress, s_cmcb::cmcbType, heapLoc, initLinkedList(), insertMCBIntoList(), kmalloc(), s_lmcb::lmcbType, MCB_FREE, s_cmcb::mcbBlockSize, s_lmcb::mcbBlockSize, mcbCompareFunc(), mcbSearchCompFunc(), printf, printMCBFunc(), s_cmcb::procName, s_cmcb::representingNode, setInsertComparisonFunction(), setPrintFunction(), and setSearchComparisonFunction().
Referenced by kmain().
void insertMCBIntoList | ( | cmcb_t * | blockToInsert | ) |
insertMCBIntoList inserts the mcb into the list specified.
blockToInsert | the mcb block to insert into. |
Definition at line 271 of file mcb.c.
References s_cmcb::cmcbType, insertNode(), lastMCBError, MCB_ALLOCATED, MCB_FREE, MCB_SUCCESS, and s_cmcb::representingNode.
Referenced by allocateMemFromHeap(), freeHeapMem(), and initHeap().
int mcbCompareFunc | ( | void * | mcb, |
void * | mcbToCompare | ||
) |
mcbCompareFunc compares the start addresses of two mcbs.
mcb | pointer to mcb |
mcbToCompare | pointer to mcb to compare with. |
Definition at line 135 of file mcb.c.
References blockStartAddress.
Referenced by initHeap().
const char* mcbResultToString | ( | e_mcb_result_t | result | ) |
Definition at line 235 of file mcb.c.
References ERROR_BLOCK_NOT_ALLOCATED, ERROR_BLOCK_NOT_FOUND, ERROR_GENERIC, ERROR_NOT_ENOUGH_MEMORY, MCB_ERROR_ACCESS_DENIED, and MCB_SUCCESS.
Referenced by heapTest().
int mcbSearchCompFunc | ( | void * | mcb, |
void * | blockStartAddress | ||
) |
mcbSearchCompFunc searches for the mcb that you want to compare with.
mcb | pointer to mcb. |
blockStartAddress | start address of memory. |
Definition at line 144 of file mcb.c.
Referenced by initHeap().
const char* mcbTypeToString | ( | e_mcb_type_t | type | ) |
Definition at line 257 of file mcb.c.
References MCB_ALLOCATED, and MCB_FREE.
Referenced by printMCBFunc().
void printAlloc | ( | ) |
printAlloc prints the allocated memory blocks. Traverses through the allocated mcb list.
Definition at line 123 of file mcb.c.
References printf, and printList().
void printFree | ( | ) |
printFree prints the free memory blocks. Traverses through the free mcb list.
Definition at line 129 of file mcb.c.
References printf, and printList().
void printMCBFunc | ( | void * | cmcb | ) |
printMCBFunc prints the type, block size, block pointer of the blocks in a given list.
cmcb | CMCB to be printed out. |
Definition at line 223 of file mcb.c.
References blockStartAddress, cmcbType, mcbBlockSize, mcbTypeToString(), printf, and procName.
Referenced by freeHeapMem(), and initHeap().
void reclaimFreeMem | ( | ) |
reclaimFreeMem groups free blocks together if they are adjacent.
Definition at line 184 of file mcb.c.
References s_cmcb::associatedLMCB, s_cmcb::blockStartAddress, s_lmcb::blockStopAddress, s_cmcb::mcbBlockSize, s_lmcb::mcbBlockSize, removeNode(), and s_cmcb::representingNode.
Referenced by freeHeapMem().
heapLocationPtr_t heapLoc =0 |
Definition at line 3 of file mcb.c.
Referenced by initHeap().
e_mcb_result_t lastMCBError = MCB_SUCCESS |
Definition at line 8 of file mcb.c.
Referenced by allocateMemFromHeap(), freeHeapMem(), heapIsEmpty(), heapTest(), and insertMCBIntoList().
linkedList_t mcbAllocList |
linkedList_t mcbFreeList |