[kernel] Fix the mysterious paging bug!!
There has been a random bug (that occurs frequently outside the debugger but rarely inside the debugger, of course) that seemed to be caused by inconsistent page mappings. Sometimes loading an ELF would work. Other times loading that same ELF, the loader would complain of missing sections or invalid headers. Worse, occasionally program execution would jump off into random memory for no reason I could see by examining the disassembly. This issue has been plauging me FOR A YEAR and I've been pulling my hair out trying to find it. https://stackoverflow.com/a/28384866 Eventually this stack overflow answer to a different question about INVLPG gave me a hint that the 'accessed' flag of page table entries might not be set on pages even if they end up in the TLB. Good riddance to this damned bug.
This commit is contained in:
@@ -250,10 +250,10 @@ vm_space::clear(const obj::vm_area &vma, uintptr_t offset, size_t count, bool fr
|
|||||||
|
|
||||||
if (flags & page_flags::present) {
|
if (flags & page_flags::present) {
|
||||||
e = 0;
|
e = 0;
|
||||||
if (flags & page_flags::accessed) {
|
|
||||||
auto *addr = reinterpret_cast<const uint8_t *>(it.vaddress());
|
auto *addr = reinterpret_cast<const uint8_t *>(it.vaddress());
|
||||||
asm ( "invlpg %0" :: "m"(*addr) : "memory" );
|
asm ( "invlpg %0" :: "m"(*addr) : "memory" );
|
||||||
}
|
|
||||||
if (free_count && phys == free_start + (free_count * frame_size)) {
|
if (free_count && phys == free_start + (free_count * frame_size)) {
|
||||||
++free_count;
|
++free_count;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user