[Zion] Call invlpg when unmapping memory.

This commit is contained in:
Drew Galbraith 2023-12-05 15:53:42 -08:00
parent 0b9f83b321
commit 1f8085f791
4 changed files with 27 additions and 9 deletions

View file

@ -65,6 +65,24 @@ glcr::ErrorOr<uint64_t> AddressSpace::MapInMemoryObject(
return vaddr;
}
glcr::ErrorCode AddressSpace::FreeAddressRange(uint64_t vaddr_base,
uint64_t vaddr_limit) {
RET_ERR(mapping_tree_.FreeMemoryRange(vaddr_base, vaddr_limit));
// If this is the current address space we need to invalidate any pages.
// TODO: Consider moving this to the Mapping Tree implmementation to only
// call this instruction for pages that we know are mapped.
if (cr3_ == CurrCr3()) {
for (uint64_t addr = vaddr_base; addr < vaddr_limit; addr += kPageSize) {
asm volatile("invlpg (%0)" : : "b"(addr) : "memory");
}
// Clobber vaddr_limit as well in case of an alignment issue.
asm volatile("invlpg (%0)" : : "b"(vaddr_limit) : "memory");
}
return glcr::OK;
}
uint64_t AddressSpace::AllocateKernelStack() {
return KernelVmm::AcquireKernelStack();
}

View file

@ -82,9 +82,7 @@ class AddressSpace : public KernelObject {
const glcr::RefPtr<MemoryObject>& mem_obj, uint64_t align);
[[nodiscard]] glcr::ErrorCode FreeAddressRange(uint64_t vaddr_base,
uint64_t vaddr_limit) {
return mapping_tree_.FreeMemoryRange(vaddr_base, vaddr_limit);
}
uint64_t vaddr_limit);
// Kernel Mappings.
uint64_t AllocateKernelStack();