mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-19 09:35:15 -04:00
Flush TLB after editing paging
This commit is contained in:
parent
7c61a533eb
commit
871e1f2775
@ -36,6 +36,10 @@ uintptr_t init_new_page(){
|
|||||||
return new_page;
|
return new_page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void flush_tlb(void* page){
|
||||||
|
asm volatile("invlpg [%0]" :: "r" (reinterpret_cast<uintptr_t>(page)) : "memory");
|
||||||
|
}
|
||||||
|
|
||||||
} //end of anonymous namespace
|
} //end of anonymous namespace
|
||||||
|
|
||||||
//TODO Update to support offsets at the end of virt
|
//TODO Update to support offsets at the end of virt
|
||||||
@ -142,6 +146,9 @@ bool paging::map(void* virt, void* physical){
|
|||||||
//Map to the physical address
|
//Map to the physical address
|
||||||
pt[table] = reinterpret_cast<page_entry>(reinterpret_cast<uintptr_t>(physical) | (PRESENT | WRITEABLE));
|
pt[table] = reinterpret_cast<page_entry>(reinterpret_cast<uintptr_t>(physical) | (PRESENT | WRITEABLE));
|
||||||
|
|
||||||
|
//Flush TLB
|
||||||
|
flush_tlb(virt);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,6 +220,9 @@ bool paging::unmap(void* virt){
|
|||||||
//Unmap the virtual address
|
//Unmap the virtual address
|
||||||
pt[table] = 0x0;
|
pt[table] = 0x0;
|
||||||
|
|
||||||
|
//Flush TLB
|
||||||
|
flush_tlb(virt);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -786,6 +786,9 @@ void exec_command(const std::vector<std::string>& params){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Save it to be able to free it later
|
||||||
|
allocated_segments[p] = memory;
|
||||||
|
|
||||||
//3. Find a start of a page inside the physical memory
|
//3. Find a start of a page inside the physical memory
|
||||||
|
|
||||||
auto aligned_memory = paging::page_aligned(memory) ? memory :
|
auto aligned_memory = paging::page_aligned(memory) ? memory :
|
||||||
@ -799,9 +802,6 @@ void exec_command(const std::vector<std::string>& params){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Save it to be able to free it later
|
|
||||||
allocated_segments[p] = memory;
|
|
||||||
|
|
||||||
//5. Copy memory
|
//5. Copy memory
|
||||||
|
|
||||||
auto memory_start = reinterpret_cast<uintptr_t>(aligned_memory) + left_padding;
|
auto memory_start = reinterpret_cast<uintptr_t>(aligned_memory) + left_padding;
|
||||||
@ -834,7 +834,9 @@ void exec_command(const std::vector<std::string>& params){
|
|||||||
auto bytes = left_padding + paging::PAGE_SIZE + p_header.p_memsz;
|
auto bytes = left_padding + paging::PAGE_SIZE + p_header.p_memsz;
|
||||||
auto pages = (bytes / paging::PAGE_SIZE) + 1;
|
auto pages = (bytes / paging::PAGE_SIZE) + 1;
|
||||||
|
|
||||||
paging::unmap(reinterpret_cast<void*>(first_page), pages);
|
if(!paging::unmap(reinterpret_cast<void*>(first_page), pages)){
|
||||||
|
k_print_line("Unmap failed, memory could be in invalid state");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user