MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / DestroyAddressSpace

Function DestroyAddressSpace

Kernel/src/arch/x86_64/paging.cpp:157–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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);

Callers 1

EndProcessFunction · 0.85

Calls 3

GetPageFrameFunction · 0.85
FreePhysicalMemoryBlockFunction · 0.85
KernelFree4KPagesFunction · 0.85

Tested by

no test coverage detected