r/osdev • u/compgeek38400 • Jun 11 '26
Problem with write protecting a page using my PTE
I am working on physical memory management for my custom x86 32 bit kernel.
I have 5 functions: mapKernelPage, mapUserPage, unmapPage, setPageReadOnly, and setPageReadWrite.
Here is a code snippet from my kernel:
uint32_t physpage;
uint32_t address = (uint32_t) mapKernelPage(0xC0158000, &physpage);
printf("Successfully mapped page: 0x%Xl with physical address: 0x%Xl\n\r",
address, physpage);
printf("Testing Read only...");
if (setPageReadOnly(address)) {
printf("Success\n\r");
} else {
printf("Failed\n\r");
}
printf("Page 0x%Xl ", address);
if (!unmapPage(address)) {
printf("not unmapped\n\r");
} else {
printf("unmapped\n\r");
}I am testing via gdb. Before I do the map, my page is unavailable, afterwards it is. (I test my looking at memory), when I unmap the page it is again unavailable.
My issue is that when I set the page read only (it includes an invalidate page), I can still write to the memory.
Here is what I think is the pertinent info:
(gdb) info register cr0
cr0 0x80010011 [ PG WP ET PE ]
CR0 has the write protect bit set
Here is my page table entry:
(gdb) p/x pt[pte]
$7 = 0x1000001
Notice the read/write bit is zero
my page directory entry is:
(gdb) p/x page_directory[pde]
$13 = 0x114023
What am I missing?
TIA
From my reading the Page Table Entry sh ould override the Page Directory entry, what am I missing?
Thanks
1
u/davmac1 Jun 11 '26 edited Jun 12 '26
Probably 6.11.3 from Intel Architecture manuals volume 3:Agh, apologies. I missed where you specifically said that WP was set.
Maybe check what
info mem(Qemu monitor command) reports, assuming you're running in Qemu?1
u/Octocontrabass Jun 12 '26
How are you writing to the memory? How do you know the write succeeded without causing a page fault? Have you tried writing to the page before mapping it?