Esempio n. 1
0
//----------------------------------------------------------------------
//
//	ProcessFreeResources
//
//	Free the resources associated with a process.  This assumes the
//	process isn't currently on any queue.
//
//----------------------------------------------------------------------
void ProcessFreeResources (PCB *pcb) {
  int i = 0;
  int usrsp = MEM_ADDRESS_TO_PAGE(pcb->currentSavedFrame[PROCESS_STACK_USER_STACKPOINTER]);
  
  // Allocate a new link for this pcb on the freepcbs queue
  if ((pcb->l = AQueueAllocLink(pcb)) == NULL) {
    printf("FATAL ERROR: could not get Queue Link in ProcessFreeResources!\n");
    exitsim();
  }
  // Set the pcb's status to available
  pcb->flags = PROCESS_STATUS_FREE;
  // Insert the link into the freepcbs queue
  if (AQueueInsertLast(&freepcbs, pcb->l) != QUEUE_SUCCESS) {
    printf("FATAL ERROR: could not insert PCB link into freepcbs queue in ProcessFreeResources!\n");
    exitsim();
  }

  //------------------------------------------------------------
  // STUDENT: Free any memory resources on process death here.
  //------------------------------------------------------------
  for(i = 0; i < 5; i++) {
    MemoryFreePte(pcb->pagetable[i]);
  }
  for(i = usrsp; i <= MEM_ADDRESS_TO_PAGE(MEM_MAX_VIRTUAL_ADDRESS); i++) {
    MemoryFreePte(pcb->pagetable[i]);
  }
  MemoryFreePage (pcb->sysStackArea / MEM_PAGESIZE);
  ProcessSetStatus (pcb, PROCESS_STATUS_FREE);
  dbprintf ('p', "ProcessFreeResources: function complete\n");
}
Esempio n. 2
0
//----------------------------------------------------------------------
//
//	ProcessFreeResources
//
//	Free the resources associated with a process.  This assumes the
//	process isn't currently on any queue.
//
//----------------------------------------------------------------------
void
ProcessFreeResources (PCB *pcb)
{
  int		i;
  int		npages;

  QueueInsertLast (&freepcbs, &pcb->l);
  // Free the process's memory.  This is easy with a one-level page
  // table, but could get more complex with two-level page tables.
  npages = pcb->npages;

  for (i=0; i<npages; i++)
  {
    MemoryFreeSharedPte(pcb, i); // *MUST* be called before calling
    				 // MemoryFreePte. MemoryFreePte does not know
				 // anything about shared pages, and hence it
				 // might screw up big time
  }
  for (i = 0; i < pcb->npages; i++) {
    MemoryFreePte (pcb->pagetable[i]);
  }
  // Free the page allocated for the system stack
  MemoryFreePage (pcb->sysStackArea / MEMORY_PAGE_SIZE);
  ProcessSetStatus (pcb, PROCESS_STATUS_FREE);
}
Esempio n. 3
0
//----------------------------------------------------------------------
//
//	ProcessFreeResources
//
//	Free the resources associated with a process.  This assumes the
//	process isn't currently on any queue.
//
//----------------------------------------------------------------------
void ProcessFreeResources (PCB *pcb) {
  int i = 0;

  dbprintf ('p', "ProcessFreeResources: function started\n");

  // Allocate a new link for this pcb on the freepcbs queue
  if ((pcb->l = AQueueAllocLink(pcb)) == NULL) {
    printf("FATAL ERROR: could not get Queue Link in ProcessFreeResources!\n");
    GracefulExit();
  }
  // Set the pcb's status to available
  pcb->flags = PROCESS_STATUS_FREE;
  // Insert the link into the freepcbs queue
  if (AQueueInsertLast(&freepcbs, pcb->l) != QUEUE_SUCCESS) {
    printf("FATAL ERROR: could not insert PCB link into freepcbs queue in ProcessFreeResources!\n");
    GracefulExit();
  }

  // Free the process's memory.
  for (i = 0; i < pcb->npages; i++) {
    MemoryFreePte (pcb->pagetable[i]);
  }
  // Free the page allocated for the system stack
  MemoryFreePage (pcb->sysStackArea / MEMORY_PAGE_SIZE);
  ProcessSetStatus (pcb, PROCESS_STATUS_FREE);
  dbprintf ('p', "ProcessFreeResources: function complete\n");
}
Esempio n. 4
0
//----------------------------------------------------------------------
//
//	ProcessFreeResources
//
//	Free the resources associated with a process.  This assumes the
//	process isn't currently on any queue.
//
//----------------------------------------------------------------------
void ProcessFreeResources (PCB *pcb) {
  int i = 0;
  uint32 page;

  // Allocate a new link for this pcb on the freepcbs queue
  if ((pcb->l = AQueueAllocLink(pcb)) == NULL) {
    printf("FATAL ERROR: could not get Queue Link in ProcessFreeResources!\n");
    exitsim();
  }
  // Set the pcb's status to available
  pcb->flags = PROCESS_STATUS_FREE;
  // Insert the link into the freepcbs queue
  if (AQueueInsertLast(&freepcbs, pcb->l) != QUEUE_SUCCESS) {
    printf("FATAL ERROR: could not insert PCB link into freepcbs queue in ProcessFreeResources!\n");
    exitsim();
  }

  //------------------------------------------------------------
  // STUDENT: Free any memory resources on process death here.
  //------------------------------------------------------------

  /////////////////////////////////////////////////////////////
  // TODO CHANGE FOR 2 LEVEL Free Resource
  // JSM - free all physical pages corresponding to valid page table entries in process
  // AS WEL AS FREEING SYSTEM STACK PAGE ASSOCIATED WITH PROCESS
  for (i = 0; i < MEM_L1_PAGE_TABLE_SIZE; i++)
  {
  	if(pcb->pagetable[i] & MEM_PTE_VALID) // For every page currently valid in page table
  	{
  		pcb->pagetable[i] &= ~(MEM_PTE_VALID);  // Invalidate page table entry
  		page = (pcb->pagetable[i]) / MEM_PAGE_SIZE;
  		dbprintf ('p', "Preparing to free physical page #%d\n", page);
  		MemoryFreePage(page); // Free page in freemap
  	}
  }
	dbprintf ('p', "Preparing to free physical page #%d (System Stack)\n", (pcb->sysStackArea / MEM_PAGE_SIZE) );
	MemoryFreePage(pcb->sysStackArea / MEM_PAGE_SIZE); // Free page in freemap

  /////////////////////////////////////////////////////////////

  dbprintf ('p', "Free Resources DONE!\n\n");
  //while(1);

  ProcessSetStatus (pcb, PROCESS_STATUS_FREE);
}
//----------------------------------------------------------------------
//
//	ProcessFreeResources
//
//	Free the resources associated with a process.  This assumes the
//	process isn't currently on any queue.
//
//----------------------------------------------------------------------
void
ProcessFreeResources (PCB *pcb)
{
  int		i;
  int		npages;

  QueueInsertLast (&freepcbs, &pcb->l);
  // Free the process's memory.  This is easy with a one-level page
  // table, but could get more complex with two-level page tables.

//------------------------------------------
// You may change the code below
//------------------------------------------

  npages = pcb->npages;

  for (i = 0; i < pcb->npages; i++) {
    MemoryFreePte (pcb->pagetable[i]);
  }
  // Free the page allocated for the system stack
  MemoryFreePage (pcb->sysStackArea / MEMORY_PAGE_SIZE);
  ProcessSetStatus (pcb, PROCESS_STATUS_FREE);
}
Esempio n. 6
0
//----------------------------------------------------------------------
//
//	ProcessFreeResources
//
//	Free the resources associated with a process.  This assumes the
//	process isn't currently on any queue.
//
//----------------------------------------------------------------------
void ProcessFreeResources (PCB *pcb) {
  int i,j;
  uint32 entry, page;
  uint32 *p;

  // Allocate a new link for this pcb on the freepcbs queue
  if ((pcb->l = AQueueAllocLink(pcb)) == NULL) {
    printf("FATAL ERROR: could not get Queue Link in ProcessFreeResources!\n");
    exitsim();
  }
  // Set the pcb's status to available
  pcb->flags = PROCESS_STATUS_FREE;
  // Insert the link into the freepcbs queue
  if (AQueueInsertLast(&freepcbs, pcb->l) != QUEUE_SUCCESS) {
    printf("FATAL ERROR: could not insert PCB link into freepcbs queue in ProcessFreeResources!\n");
    exitsim();
  }

  //------------------------------------------------------------
  // STUDENT: Free any memory resources on process death here.
  //------------------------------------------------------------

  /////////////////////////////////////////////////////////////
  // TODO4 CHANGE FOR 2 LEVEL DONE
  // JSM - free all physical pages corresponding to valid page table entries in process
  // AS WELL AS FREEING SYSTEM STACK PAGE ASSOCIATED WITH PROCESS
  for (i = 0; i < MEM_L1_PAGE_TABLE_SIZE; i++)
  {
  	if(pcb->pagetable[i] != 0) // For every page currently valid in L1 Page Table
  	{
  		dbprintf ('p', "\nFreeing L2 PT entries from L1 PT index #%d\n", i);
  		dbprintf ('p', "L1P1 index #%d Contents: %d\n", i, pcb->pagetable[i]);
  		dbprintf ('p', "Start of corresponding L2PT Block: %d\n", (uint32)(level2_pt_block));
  		entry = ((pcb->pagetable[i])-(uint32)(level2_pt_block))/(sizeof(level2_pt));
  		dbprintf ('p', "Level2_pt_block entry for L1 PT index #%d is: %d\n\n", i, entry);

  		p = (uint32 *)&level2_pt_block[entry];
  	  for (j = 0; j < MEM_L2_PAGE_TABLE_SIZE; j++)
  	  {
  	  	if(*(p+j) & MEM_PTE_VALID) // For every page currently valid in page table
  	  	{
  	  		dbprintf ('p', "Invalidating L1_idx: %d, L2_idx:%d\n", i, j);
  	  		*(p+j) &= ~(MEM_PTE_VALID);  // Invalidate page table entry
  	  		page = (*(p+j) / MEM_PAGE_SIZE);
  	  		dbprintf ('p', "Preparing to free physical page #%d\n", page);
  	  		MemoryFreePage(page); // Free page in freemap
  	  	}
  	  }
  	  // Invalidate L1 Page Table Entry
  	  pcb->pagetable[i] = 0;
  	  // FREE L2 PAGE TABLE
  	  MemoryFreeL2PT(entry);
  	}
  }

	dbprintf ('p', "\nPreparing to free physical page #%d (System Stack)\n", (pcb->sysStackArea / MEM_PAGE_SIZE) );
	MemoryFreePage(pcb->sysStackArea / MEM_PAGE_SIZE); // Free page in freemap

  /////////////////////////////////////////////////////////////

  dbprintf ('M', "Free Resources DONE!\n\n");
	for(i=0; i<MEM_FREEMAP_SIZE_IN_WORDS; i++)
	{
		dbprintf('M', "Freemap Int #%d value: 0x%.8X\n", i, freemap[i]);
	}
	dbprintf('m', "\n");
	for(i=0; i<MEM_FREEMAP_PT_SIZE_IN_WORDS; i++)
	{
		dbprintf('M', "freemap_pt index #%d value: 0x%.8X\n", i, pt_freemap[i]);
	}

  ProcessSetStatus (pcb, PROCESS_STATUS_FREE);
}
Esempio n. 7
0
void MemoryFreePte (uint32 pte)
{
  MemoryFreePage ((pte & MEM_PTE_MASK) /(MEM_PAGESIZE));
}