Page 3 of 4

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

Re: switching to new pagemap causes 0xe and more exceptions

Posted: Thu Nov 07, 2024 4:06 pm
by RayanMargham
merged!

Re: switching to new pagemap causes 0xe and more exceptions

Posted: Thu Nov 07, 2024 4:56 pm
by RayanMargham
thank you so much!!!! actually. everything is solved (except for ksan) do u have any idea why ksan isnt working?

Re: switching to new pagemap causes 0xe and more exceptions

Posted: Thu Nov 07, 2024 5:21 pm
by MichaelPetch
When I get a chance this weekend I will look at your kasan implementation. What I know is that the kasan issue is not related to any bugs you were currently hunting down and was a unique problem specific to that code.

I also have another pull request coming that cleans up your IDT stubs and handler, and also sets a default handler for idt entries that you aren't handling. I noticed in your code if you didn't set up a handler your unhandled interrupts would cause yet another exception leading to possible double and triple faults.

Edit: New pull request is here: https://github.com/rayanmargham/NyauxKC/pull/2

Re: switching to new pagemap causes 0xe and more exceptions

Posted: Thu Nov 07, 2024 10:20 pm
by RayanMargham
Thank you! merged

Re: switching to new pagemap causes 0xe and more exceptions

Posted: Fri Nov 08, 2024 1:47 pm
by RayanMargham
Let me know when u get a chance to look at ksan, Thanks!

Re: switching to new pagemap causes 0xe and more exceptions

Posted: Sun Nov 10, 2024 7:38 pm
by RayanMargham
any update?

Re: switching to new pagemap causes 0xe and more exceptions

Posted: Sun Nov 10, 2024 8:00 pm
by MichaelPetch
Didn't have time. You'll have to investigate.

Re: switching to new pagemap causes 0xe and more exceptions

Posted: Sun Nov 10, 2024 8:12 pm
by RayanMargham
also ive found a bug

the handler for page fault says its a unhandled exception... what???? even tho its changed????