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

Method exit

lab8/src/6/src/kernel/program.cpp:517–564  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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