Modestus Moon OS  R4
CS 450 project
mcb.h
Go to the documentation of this file.
1 #ifndef MCB_H
2 #define MCB_H
3 
4 #include <system.h>
5 #include <mem/heap.h>
6 #include <core/pcb.h>
7 #include <linked_list.h>
8 
9 
12 
19 
25 
27 
28 typedef struct s_cmcb cmcb_t;
29 
30 typedef struct s_lmcb lmcb_t;
31 
32 typedef void* mcbAddressPtr_t;
33 
34 typedef size_t mcbSize_t;
35 
36 typedef void* heapLocationPtr_t;
37 
41 struct s_cmcb
42 {
44 
46 
48 
49  const char* procName;
50 
52 
54 
55 }__attribute__((packed));
56 
60 struct s_lmcb
61 {
63 
65 
67 }__attribute__((packed));
68 
74 void initHeap(size_t initialHeapSize);
75 
82 void* allocateMemFromHeap(size_t requestedSize);
83 
90 int freeHeapMem(void* blockAddress);
91 
94 
98 void printAlloc();
99 
103 void printFree();
104 
109 int heapIsEmpty();
110 
111 const char* mcbResultToString(e_mcb_result_t result);
112 const char* mcbTypeToString(e_mcb_type_t type);
113 
120 int mcbCompareFunc(void* mcb, void* mcbToCompare);
121 
128 int mcbSearchCompFunc(void* mcb, void* blockStartAddress);
129 
134 void insertMCBIntoList(cmcb_t* blockToInsert);
135 
139 void heapTest();
140 
145 void printMCBFunc(void* cmcb);
146 
150 void reclaimFreeMem();
151 
152 #endif // MCB_H
void * heapLocationPtr_t
Definition: mcb.h:36
linkedList_t mcbAllocList
Definition: mcb.c:6
linkedList_t mcbFreeList
Definition: mcb.c:5
typedef of linked list node (see s_ll_node).
const char * mcbTypeToString(e_mcb_type_t type)
Definition: mcb.c:257
The s_cmcb struct the struct type for cmcb&#39;s -> defines the properties.
Definition: mcb.h:41
size_t mcbSize_t
Definition: mcb.h:34
e_mcb_type_t cmcbType
Definition: mcb.h:45
void printMCBFunc(void *cmcb)
printMCBFunc prints the type, block size, block pointer of the blocks in a given list.
Definition: mcb.c:223
e_mcb_type_t lmcbType
Definition: mcb.h:66
int mcbCompareFunc(void *mcb, void *mcbToCompare)
mcbCompareFunc compares the start addresses of two mcbs.
Definition: mcb.c:135
typedef of linked list (see s_ll).
mcbSize_t sizeOfHeapAllocated()
void * mcbAddressPtr_t
Definition: mcb.h:32
mcbSize_t mcbBlockSize
Definition: mcb.h:47
e_mcb_result_t lastMCBError
Definition: mcb.c:8
void printAlloc()
printAlloc prints the allocated memory blocks. Traverses through the allocated mcb list...
Definition: mcb.c:123
const char * mcbResultToString(e_mcb_result_t result)
Definition: mcb.c:235
void initHeap(size_t initialHeapSize)
initHeap initializes the system heap by calling kmalloc with a valid byte size. Creates a CMCB at the...
Definition: mcb.c:11
int heapIsEmpty()
heapIsEmpty returns if the heap is empty.
Definition: mcb.c:229
mcbSize_t mcbBlockSize
Definition: mcb.h:64
mcbAddressPtr_t blockStartAddress
Definition: mcb.h:53
void insertMCBIntoList(cmcb_t *blockToInsert)
insertMCBIntoList inserts the mcb into the list specified.
Definition: mcb.c:271
The s_lmcb struct defines the properties of lmcb&#39;s.
Definition: mcb.h:60
e_mcb_result_t
The e_mcb_result_t enum defines the return status of functions working with MCBs. ...
Definition: mcb.h:16
e_mcb_type_t
The e_mcb_type_t enum defines the state of the MCBs.
Definition: mcb.h:23
struct s_cmcb __attribute__((packed))
node_t representingNode
Definition: mcb.h:43
int mcbSearchCompFunc(void *mcb, void *blockStartAddress)
mcbSearchCompFunc searches for the mcb that you want to compare with.
Definition: mcb.c:144
mcbSize_t sizeOfHeapFree()
mcbAddressPtr_t blockStopAddress
Definition: mcb.h:62
void heapTest()
heapTest test function to create sample mcbs.
Definition: mcb.c:286
lmcb_t * associatedLMCB
Definition: mcb.h:51
Definition: mcb.h:23
void printFree()
printFree prints the free memory blocks. Traverses through the free mcb list.
Definition: mcb.c:129
void * allocateMemFromHeap(size_t requestedSize)
allocateMemFromHeap takes the requested size and finds the first block that fits. Implements first fi...
Definition: mcb.c:45
const char * procName
Definition: mcb.h:49
int freeHeapMem(void *blockAddress)
freeHeapMem takes the block address and frees the memory from the CMCB start to the LMCB end location...
Definition: mcb.c:154
void reclaimFreeMem()
reclaimFreeMem groups free blocks together if they are adjacent.
Definition: mcb.c:184