Modestus Moon OS
R4
CS 450 project
|
Go to the source code of this file.
Data Structures | |
struct | s_cmcb |
The s_cmcb struct the struct type for cmcb's -> defines the properties. More... | |
struct | s_lmcb |
The s_lmcb struct defines the properties of lmcb's. More... | |
Typedefs | |
typedef struct s_cmcb | cmcb_t |
typedef struct s_lmcb | lmcb_t |
typedef void * | mcbAddressPtr_t |
typedef size_t | mcbSize_t |
typedef void * | heapLocationPtr_t |
Enumerations | |
enum | e_mcb_result_t { MCB_SUCCESS, ERROR_BLOCK_NOT_FOUND, ERROR_BLOCK_NOT_ALLOCATED, ERROR_GENERIC, ERROR_NOT_ENOUGH_MEMORY, MCB_ERROR_ACCESS_DENIED } |
The e_mcb_result_t enum defines the return status of functions working with MCBs. More... | |
enum | e_mcb_type_t { MCB_FREE, MCB_ALLOCATED, MCB_NOT_FREE } |
The e_mcb_type_t enum defines the state of the MCBs. More... | |
Functions | |
struct s_cmcb | __attribute__ ((packed)) |
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... | |
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... | |
mcbSize_t | sizeOfHeapAllocated () |
mcbSize_t | sizeOfHeapFree () |
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 | 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) |
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... | |
void | insertMCBIntoList (cmcb_t *blockToInsert) |
insertMCBIntoList inserts the mcb into the list specified. More... | |
void | heapTest () |
heapTest test function to create sample mcbs. More... | |
void | printMCBFunc (void *cmcb) |
printMCBFunc prints the type, block size, block pointer of the blocks in a given list. More... | |
void | reclaimFreeMem () |
reclaimFreeMem groups free blocks together if they are adjacent. More... | |
typedef void* heapLocationPtr_t |
typedef void* mcbAddressPtr_t |
enum e_mcb_result_t |
The e_mcb_result_t enum defines the return status of functions working with MCBs.
Enumerator | |
---|---|
MCB_SUCCESS | |
ERROR_BLOCK_NOT_FOUND | |
ERROR_BLOCK_NOT_ALLOCATED | |
ERROR_GENERIC | |
ERROR_NOT_ENOUGH_MEMORY | |
MCB_ERROR_ACCESS_DENIED |
Definition at line 16 of file mcb.h.
enum e_mcb_type_t |
struct s_cmcb __attribute__ | ( | (packed) | ) |
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().
mcbSize_t sizeOfHeapAllocated | ( | ) |
mcbSize_t sizeOfHeapFree | ( | ) |
mcbAddressPtr_t blockStartAddress |
Definition at line 47 of file mcb.h.
Referenced by mcbCompareFunc(), and printMCBFunc().
mcbAddressPtr_t blockStopAddress |
e_mcb_type_t cmcbType |
Definition at line 39 of file mcb.h.
Referenced by printMCBFunc().
e_mcb_result_t lastMCBError |
Definition at line 8 of file mcb.c.
Referenced by allocateMemFromHeap(), freeHeapMem(), heapIsEmpty(), heapTest(), and insertMCBIntoList().
e_mcb_type_t lmcbType |
linkedList_t mcbAllocList |
mcbSize_t mcbBlockSize |
Definition at line 41 of file mcb.h.
Referenced by printMCBFunc().
linkedList_t mcbFreeList |
const char* procName |
Definition at line 43 of file mcb.h.
Referenced by pcbFunc(), and printMCBFunc().