MCPcopy Create free account
hub / github.com/YatSenOS/YatSenOS-Tutorial-Volume-1 / exit

Method exit

lab8/src/7/src/kernel/program.cpp:513–560  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

511}
512
513void ProgramManager::exit(int ret)
514{
515 interruptManager.disableInterrupt();
516
517 PCB *program = this->running;
518 program->retValue = ret;
519 program->status = ProgramStatus::DEAD;
520
521 int *pageDir, *page;
522 int paddr;
523
524 if (program->pageDirectoryAddress)
525 {
526 pageDir = (int *)program->pageDirectoryAddress;
527 for (int i = 0; i < 768; ++i)
528 {
529 if (!(pageDir[i] & 0x1))
530 {
531 continue;
532 }
533
534 page = (int *)(0xffc00000 + (i << 12));
535
536 for (int j = 0; j < 1024; ++j)
537 {
538 if (!(page[j] & 0x1))
539 {
540 continue;
541 }
542
543 paddr = memoryManager.vaddr2paddr((i << 22) + (j << 12));
544 memoryManager.releasePhysicalPages(AddressPoolType::USER, paddr, 1);
545 }
546
547 paddr = memoryManager.vaddr2paddr((int)page);
548 memoryManager.releasePhysicalPages(AddressPoolType::USER, paddr, 1);
549 }
550
551 memoryManager.releasePages(AddressPoolType::KERNEL, (int)pageDir, 1);
552
553 int bitmapBytes = ceil(program->userVirtual.resources.length, 8);
554 int bitmapPages = ceil(bitmapBytes, PAGE_SIZE);
555
556 memoryManager.releasePages(AddressPoolType::KERNEL, (int)program->userVirtual.resources.bitmap, bitmapPages);
557 }
558
559 schedule();
560}
561
562int ProgramManager::wait(int *retval)
563{

Callers 1

syscall_exitFunction · 0.45

Calls 5

ceilFunction · 0.50
disableInterruptMethod · 0.45
vaddr2paddrMethod · 0.45
releasePhysicalPagesMethod · 0.45
releasePagesMethod · 0.45

Tested by

no test coverage detected