You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Store the address of the kernel's PML4 for later use
Previously, there was a common problem with how we handled the
kernel's page mapping. It was returned by memory::init, but then
had to be kept in a variable to be usable. The neat solution
would be to store it in a static variable in the memory module,
but since OffsetPageTable can't be initialised with a dummy value,
there's no safe way to initialise the static variable before the
kernel starts and is able to provide the proper value.
With that option ruled out, the next best option is to store
the PML4's virtual address in a static variable, then provide
a function (kernel_pml4) that instantiates the PML4 using that
address. This replaces the similar active_level_4_table function,
but reading from where we keep the kernel's PML4, rather than
whatever is currently stored in the cr3 register.
I would love to make this neater.
With that change made, memory::init now returns nothing, so when
we debug the virtual address space in main, we do so by calling
kernel_pml4 to get another instance of the memory map.
It's important to note that we run the risk of undefined behaviour
if two references to the kernel's PML4 exist at the same time.
Frankly, I don't know enough about the nuance to know how risky
this is, but in the grand scheme of things it's an acceptable risk.
Signed-off-by: SlyMarbo <[email protected]>
0 commit comments