| 155 | } |
| 156 | |
| 157 | void DestroyAddressSpace(address_space_t* addressSpace){ |
| 158 | for(int i = 0; i < DIRS_PER_PDPT; i++){ |
| 159 | for(int j = 0; j < TABLES_PER_DIR; j++){ |
| 160 | pd_entry_t dirEnt = addressSpace->pageDirs[i][j]; |
| 161 | if(dirEnt & PAGE_PRESENT){ |
| 162 | uint64_t phys = GetPageFrame(dirEnt); |
| 163 | |
| 164 | for(int k = 0; k < PAGES_PER_TABLE; k++){ |
| 165 | if(addressSpace->pageTables[i][j][k] & 0x1){ |
| 166 | uint64_t pagePhys = GetPageFrame(addressSpace->pageTables[i][j][k]); |
| 167 | FreePhysicalMemoryBlock(pagePhys); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | FreePhysicalMemoryBlock(phys); |
| 172 | addressSpace->pageDirs[i][j] = 0; |
| 173 | KernelFree4KPages(addressSpace->pageTables[i][j], 1); |
| 174 | } |
| 175 | addressSpace->pageDirs[i][j] = 0; |
| 176 | } |
| 177 | |
| 178 | addressSpace->pdpt[i] = 0; |
| 179 | Memory::FreePhysicalMemoryBlock(addressSpace->pageDirsPhys[i]); |
| 180 | KernelFree4KPages(addressSpace->pageDirs[i], 1); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | bool CheckRegion(uintptr_t addr, uint64_t len, address_space_t* addressSpace){ |
| 185 | return addr < PDPT_SIZE && (addr + len) < PDPT_SIZE && (addressSpace->pdpt[PDPT_GET_INDEX(addr)] & PDPT_USER) && (addressSpace->pdpt[PDPT_GET_INDEX(addr + len)] & PDPT_USER); |
no test coverage detected