diff --git a/Sim03/logfile_1.lgf b/Sim03/logfile_1.lgf index 0a374fe..52b0e91 100644 --- a/Sim03/logfile_1.lgf +++ b/Sim03/logfile_1.lgf @@ -1,4 +1,4 @@ -0.000001, OS: Simulator start +0.000000, OS: Simulator start READY state from NEW state ate diff --git a/Sim03/sim03 b/Sim03/sim03 index e58449e..b426ccf 100755 Binary files a/Sim03/sim03 and b/Sim03/sim03 differ diff --git a/Sim03/simulator.c b/Sim03/simulator.c index a91f9c8..1583ecb 100644 --- a/Sim03/simulator.c +++ b/Sim03/simulator.c @@ -2,7 +2,8 @@ /* Name: accessMemory -Process: checks offset from the PCB +Process: checks that the memory is between the offset and the size. + checks that the memory is ??? Function Input/Parameters: source PCB (ProcessControlBlock *), offset (int), size (int) Function Output/Parameters: none Function Output/Returned: boolean to indicate success or failure of accessed memory @@ -90,15 +91,15 @@ ProcessControlBlockLL *createProcessList() /* Name: deallocMemory -Process: 'deallocates' memory within the PCB, removes offset and size within it's PCB -Function Input/Parameters: source PCB (ProcessControlBlock *), offset (int), size (int) +Process: 'deallocates' memory within the PCB, removes every offset and size within it's PCB +Function Input/Parameters: source PCB (ProcessControlBlock *) Function Output/Parameters: none Function Output/Returned: boolean to indicate success or failure of allocated memory Device Input/Device: none Device Output/Device: none Dependencies: ??? */ -bool deallocMemory(ProcessControlBlock *singlePCB, int offset, int size) +bool deallocMemory(ProcessControlBlock *singlePCB) { // return true (temp) return true; @@ -377,12 +378,12 @@ Process: checks to make sure an allocate will be successful, Function Input/Parameters: PCBList (ProcessControlBlockLL *), memory code (MEMORY_SIGNALS), offset (int), size (int), configuration data (ConfigDataType *) Function Output/Parameters: none -Function Output/Returned: none? +Function Output/Returned: boolean for success or failure of memory management Device Input/Device: none Device Output/Device: none Dependencies: ??? */ -void memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offset, int size, ConfigDataType *configPtr, ProcessControlBlock *singlePCB) +bool memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offset, int size, ConfigDataType *configPtr, ProcessControlBlock *singlePCB) { bool memDisplay = configPtr->memDisplay; ProcessControlBlock *wkgPtr; @@ -402,8 +403,11 @@ void memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs // count up the total used memory within each process control block. for(memIterator = 0; memIterator < wkgPtr->memArraySize; memIterator++) { - // grab how much memory is used by that process - usedMem = usedMem + wkgPtr->allocatedMemSizes[memIterator]; + if(wkgPtr->allocatedMemSizes[memIterator] != -1) + { + // grab how much memory is used by that process + usedMem = usedMem + wkgPtr->allocatedMemSizes[memIterator]; + } totalArraySize = totalArraySize + 1; } // move to the next pointer @@ -456,9 +460,19 @@ void memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs break; case MEMORY_ALLOCATE: - // grab the offset and size, store it, using the allocate memory function. + // check if the memory allocation can happen before storing it. + if(size <= availableMem - usedMem + 1) + { + // grab the offset and size, store it, using the allocate memory function. + subFunctionSuccess = allocMemory(singlePCB, offset, size); + usedMem = usedMem + size; + } + else + { + // set the subfunction success to false. + subFunctionSuccess = false; + } // if the function returns true, then it successfully did the operation, display as such. - subFunctionSuccess = allocMemory(singlePCB, offset, size); if (memDisplay) { if(subFunctionSuccess) @@ -507,7 +521,7 @@ void memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs break; case MEMORY_DEALLOCATE: - subFunctionSuccess = deallocMemory(singlePCB, offset, size); + subFunctionSuccess = deallocMemory(singlePCB); if (memDisplay) { if (subFunctionSuccess) @@ -545,7 +559,8 @@ void memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offs } // clear out the dynamic array free(memorySizeArray); - // no return, void (temp) + // return if the subfunction succeeded, if applicable + return subFunctionSuccess; } /* @@ -625,13 +640,14 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, Proce char *argument; int intArg; int intArgTwo; + bool memManagerSuccess = true; // char *inOutArg; command = workingMeta->command; argument = workingMeta->strArg1; intArg = workingMeta->intArg2; intArgTwo = workingMeta->intArg3; // inOutArg = workingMeta->inOutArg; - while (!(compareString(command, "app") == EQUIV && compareString(argument, "end") == EQUIV) && !(compareString(command, "sys") == EQUIV && compareString(argument, "end") == EQUIV)) + while (!(compareString(command, "app") == EQUIV && compareString(argument, "end") == EQUIV) && !(compareString(command, "sys") == EQUIV && compareString(argument, "end") == EQUIV) && memManagerSuccess) { // check to see what operation will be performed if (compareString(command, "cpu") == EQUIV && compareString(argument, "process") == EQUIV) @@ -652,14 +668,26 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, Proce sprintf(processOutput, "%f, Process: %d, %s %s request (%d, %d)\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid, command, argument, intArg, intArgTwo); logOutput(configPtr, processOutput, false); // run the memory manager in allocate mode - memManager(pcbList, MEMORY_ALLOCATE, intArg, intArgTwo, configPtr, singlePCB); + memManagerSuccess = memManager(pcbList, MEMORY_ALLOCATE, intArg, intArgTwo, configPtr, singlePCB); + if(!memManagerSuccess) + { + // + sprintf(processOutput, "%f, Process: %d, failed %s %s request (%d, %d)\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid, command, argument, intArg, intArgTwo); + logOutput(configPtr, processOutput, false); + } } else if(compareString(argument, "access") == EQUIV) { sprintf(processOutput, "%f, Process: %d, %s %s request (%d, %d)\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid, command, argument, intArg, intArgTwo); logOutput(configPtr, processOutput, false); // run the memory manager in access mode - memManager(pcbList, MEMORY_ACCESS, intArg, intArgTwo, configPtr, singlePCB); + memManagerSuccess = memManager(pcbList, MEMORY_ACCESS, intArg, intArgTwo, configPtr, singlePCB); + if (!memManagerSuccess) + { + // + sprintf(processOutput, "%f, Process: %d, failed %s %s request (%d, %d)\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid, command, argument, intArg, intArgTwo); + logOutput(configPtr, processOutput, false); + } } } workingMeta = workingMeta->nextNode; @@ -668,9 +696,19 @@ void runProcess(ProcessControlBlock *singlePCB, ConfigDataType *configPtr, Proce intArg = workingMeta->intArg2; intArgTwo = workingMeta->intArg3; } - // display the process exited - sprintf(processOutput, "\n%f, OS: Process %d ended\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid); - logOutput(configPtr, processOutput, false); + // display the process exited, if not segfaulted. + if(memManagerSuccess) + { + // + sprintf(processOutput, "\n%f, OS: Process %d ended\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid); + logOutput(configPtr, processOutput, false); + } + else + { + // + sprintf(processOutput, "\n%f, OS: Segmentation Fault, Process %d ended\n", accessTimer(LAP_TIMER, timeStringy), singlePCB->uniquePid); + logOutput(configPtr, processOutput, false); + } // deallocate the memory for the process memManager(pcbList, MEMORY_DEALLOCATE, intArg, intArgTwo, configPtr, singlePCB); }