Page 3 of 3
Re: switching to new pagemap causes 0xe and more exceptions
Posted: Tue Nov 05, 2024 4:19 pm
by RayanMargham
theres a lot of vmm region corruption going on here
i might just give up at this point idfk
Re: switching to new pagemap causes 0xe and more exceptions
Posted: Tue Nov 05, 2024 4:49 pm
by MichaelPetch
I am still baffled by your find_pte even after your changes which really didn't do anything. You have
Code: Select all
uint64_t *find_pte(uint64_t *pt, uint64_t virt) {
uint64_t shift = 48;
for (int i = 0; i < 4; i++) {
shift -= 9;
uint64_t idx = (virt >> shift) & 0x1ff;
uint64_t *page_table =
(uint64_t *)((uint64_t)pt + hhdm_request.response->offset);
if (i == 2) {
return page_table + idx;
}
if (!(page_table[idx] & PRESENT)) {
if (page_table[idx] & PAGE2MB) {
panic("This shall not happen.");
}
return page_table + idx;
} else {
pt = (uint64_t *)(page_table[idx] & 0x000ffffffffff000);
}
}
return 0;
}
For instance:
Code: Select all
if (i == 2) {
return page_table + idx;
}
Why do you use `i == 2` and stop at the Page Directory? What happens when you have a 4KiB page? wouldn't you have to descend one level further to the Page Table??
Re: switching to new pagemap causes 0xe and more exceptions
Posted: Tue Nov 05, 2024 6:01 pm
by RayanMargham
ill remove that right now
Re: switching to new pagemap causes 0xe and more exceptions
Posted: Tue Nov 05, 2024 6:01 pm
by RayanMargham
its changed look at git
Re: switching to new pagemap causes 0xe and more exceptions
Posted: Tue Nov 05, 2024 6:41 pm
by RayanMargham
so now im trying to implment ksan and theres a bunch of faults going on
read my code its in src/mem/ksan.c
Re: switching to new pagemap causes 0xe and more exceptions
Posted: Tue Nov 05, 2024 11:45 pm
by MichaelPetch
I have made a pull request with a fix for `find_pte` here:
https://github.com/rayanmargham/NyauxKC/pull/1 . The pull request disables your ksan. I didn't have time to investigate the reason but with your ksan implementation the stack overflows and the result is the pml4_table is corrupted and a page fault occurs.
Re: switching to new pagemap causes 0xe and more exceptions
Posted: Wed Nov 06, 2024 8:00 pm
by MichaelPetch
I discovered another bug in `vmm_init` . I had noticed page faults when building with `-O0` and discovered a bug in a switch statement:
Code: Select all
default:
uint64_t disalignz = entry->base % 2097152;
entry->base = align_down(entry->base, 2097152);
uint64_t page_amountz =
align_up(entry->length - disalignz, 2097152) / 2097152;
for (uint64_t j = 0; j != page_amountz; j++) {
map2mb(ker_map.pml4, entry->base + (j * 2097152),
hhdm_request.response->offset + entry->base + (j * 2097152),
PRESENT | RWALLOWED);
}
hhdm_pages += page_amount;
break;
}
The bug is specifically `hhdm_pages += page_amount;`. This should be `hhdm_pages += page_amountz;`. It is possible to use an uninitialized variable defined in another case statement (at the same scope). This is allowed in older versions of C. I have updated my pull request with a bug fix that fixes this issue in a cleaner way by putting the case statements in a new scope using {}. My pull request is here:
https://github.com/rayanmargham/NyauxKC/pull/1