Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling Paging in x86 32bit

I am trying to write directly to a physical memory location, so I am using an assembly function to first disable paging, write the value, and then re-enable paging, but for some reason a page fault is still triggered when trying to write the value.

As I understand it, in x86-32bit, paging is set on and off by flipping bit 32 in cr0, so here is my assembly function:

mov 4(%esp), %ecx //address
mov 8(%esp), %edx //value

mov %cr0, %eax
and $0x7fffffff, %eax
mov %eax, %cr0

mov %edx, (%ecx) //this line still triggers a page fault somehow

or $0x80000000, %eax
mov %eax, %cr0

ret

Is this the correct way to achieve what I am wanting to do? If so, why is a page fault still being triggered with the bit in cr0 flipped?

like image 551
user12341234135245 Avatar asked Nov 21 '15 09:11

user12341234135245


1 Answers

The change in the CR0 register will become active when a jump instruction (far jump only?) is done.

Disabling the paging however is not a good idea: You have to guarantee that the code is located in 1:1 mapped memory and that interrupts are disabled.

If you use the stack you must also ensure that the stack is mapped 1:1.

It is much easier to modify the page tables in a way that the physical address in ecx is mapped to a virtual address and then to write to the virtual address.

like image 83
Martin Rosenau Avatar answered Sep 30 '22 18:09

Martin Rosenau