0

I have very simple question. I'm not able to find the answer on my own as I don't have any environment to test it.

If I access 4 bytes on the edge of page, what will happen?

mov eax, dword [0x100000+4095]

What will be the upper three bytes when I have access to page on 0x101000 and when I don't?

Please help.

user35443
  • 6,309
  • 12
  • 52
  • 75
  • If the page is not mapped, then the operating system should get a page fault, and map it for you. If you don't have access to the page, the operating system will most likely kill your process (it will "crash"). – Some programmer dude Aug 26 '13 at 11:24
  • uhm, so bytes will be taken from page after it? – user35443 Aug 26 '13 at 11:25
  • If it's okay by the operating system for you to read from that page, then yes. – Some programmer dude Aug 26 '13 at 11:26
  • Ok, thanks. Can you please write this to answer so I can accept it? or should I remove this question? – user35443 Aug 26 '13 at 11:28
  • A sane mental assumption is that reading uninitialized memory is undefined behaviour. Even if the instruction is legal, it's still mostly pointless... perhaps with some rare exceptions, like if you just want to make sure that some memory region is indeed paged. – Kerrek SB Aug 26 '13 at 13:05

1 Answers1

1

What happnes depends mostly on your operating system. If you have normal memory access, then nothing will happen. the value is simply read whatever is there at the time. If access to the page is not allowed, then your program will generate a page fault, which the OS has to deal with.

If the page is on disc, because it was swapped out, then the OS will load the page, and resume your program where it left off. Your programm will not notice this. If the page is invalid then the OS will raise an exception and depending on the OS you may be able to catch it, or your program will crash.

If the access is done on the kernel level and can not be resolved, your OS will most likely crash with a kernel panic, or if it is well written, it may just disable the driver, that caused it.

Devolus
  • 21,661
  • 13
  • 66
  • 113