[solved] #PF: altering page tables after loading PML4 to cr3
[solved] #PF: altering page tables after loading PML4 to cr3
When I load PML4 to cr3, afterwards the page tables can't be altered or else a page fault is thrown.
I was stepping through the function (with a debugger) to set up paging. Everything seemed okay, I loaded the PML4 pointer into cr3, but as soon as I do, the debugger can't access PML4 anymore. Neither can the kernel. Attempting to access PML4 results in a page fault.
Source code: https://github.com/microNET-OS/microCOR ... memory.cxx
I was stepping through the function (with a debugger) to set up paging. Everything seemed okay, I loaded the PML4 pointer into cr3, but as soon as I do, the debugger can't access PML4 anymore. Neither can the kernel. Attempting to access PML4 results in a page fault.
Source code: https://github.com/microNET-OS/microCOR ... memory.cxx
Last edited by austanss on Tue Feb 02, 2021 10:14 am, edited 1 time in total.
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
Re: page fault: altering page tables after loading PML4 to c
Hi,
All paging structures use physical frame numbers not virtual. Where in your code are you mapping the paging structures themselves into the address space? (With this said, this is where recursive paging can be helpful.)
All paging structures use physical frame numbers not virtual. Where in your code are you mapping the paging structures themselves into the address space? (With this said, this is where recursive paging can be helpful.)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: page fault: altering page tables after loading PML4 to c
I map PML4's page directly after requesting a page for it.neon wrote:Hi,
All paging structures use physical frame numbers not virtual. Where in your code are you mapping the paging structures themselves into the address space? (With this said, this is where recursive paging can be helpful.)
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
Re: page fault: altering page tables after loading PML4 to c
If you have mapped PML4's page, and all the pages in the table it refers to, then you shouldn't get a page fault. The next step is to determine at which memory address the page fault is occurring and the exact nature of the fault. CR2 and the error code for the page fault give you this information.
Re: page fault: altering page tables after loading PML4 to c
I haven't done that...iansjack wrote:all the pages in the table it refers to
I checked, the page fault error code is 0000 and CR2 is PML4's address.
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
- AndrewAPrice
- Member
- Posts: 2300
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
Re: page fault: altering page tables after loading PML4 to c
Make sure the paging strutures you're trying to write to are mapped into virtual memory, and you're writing to them via their virtual address. Make sure that the entries in the paging structure are their physical addresses. Make sure you are loading the physical address of the PML4 into cr3.
My OS is Perception.
Re: page fault: altering page tables after loading PML4 to c
So you tried to read a non-present page. Probably, as mentioned above, you are trying to read the physical page directly rather than using the mapping.
Re: page fault: altering page tables after loading PML4 to c
I mapped the pages. Also, I don't know how I could access the physical address. I mapped its virtual address to its physical address.
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
Re: page fault: altering page tables after loading PML4 to c
Without seeing your code repository all that can be said is that you are doing something wrong. Are you sure that you understand the difference between physical and virtual addresses and how you access such memory from C?
Re: page fault: altering page tables after loading PML4 to c
What do you mean you can't see my code repository? I linked it!iansjack wrote:Without seeing your code repository all that can be said is that you are doing something wrong. Are you sure that you understand the difference between physical and virtual addresses and how you access such memory from C?
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
Re: page fault: altering page tables after loading PML4 to c
Hi,
It is possible that I just missed it when I quickly scanned it earlier -- but just in case -- where at, specifically, are you mapping them? Source & line number please.I mapped the pages.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: page fault: altering page tables after loading PML4 to c
src/kconfigf.cxx:20neon wrote:Hi,It is possible that I just missed it when I quickly scanned it earlier -- but just in case -- where at, specifically, are you mapping them? Source & line number please.I mapped the pages.
Sorry, did it in a different file.
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
Re: page fault: altering page tables after loading PML4 to c
Hi,
Why do you clear pml_4 right after the call to map_memory? (line 22 kconfigf)
Why do you clear pml_4 right after the call to map_memory? (line 22 kconfigf)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: page fault: altering page tables after loading PML4 to c
...neon wrote:Hi,
Why do you clear pml_4 right after the call to map_memory? (line 22 kconfigf)
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
Re: page fault: altering page tables after loading PML4 to c
That fixes that issue.rizxt wrote:...neon wrote:Hi,
Why do you clear pml_4 right after the call to map_memory? (line 22 kconfigf)
Skylight: https://github.com/austanss/skylight
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".
I make stupid mistakes and my vision is terrible. Not a good combination.
NOTE: Never respond to my posts with "it's too hard".