Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
It might be that I found a bug in VirtualBox but I cannot say for sure yet. It seems that "rep stosb" does not trigger a page fault when it goes beyond the mapped memory area. In real hardware everything works as expected and a page fault occurs. Maybe this is not a bug but a feature and it may be that I am not interested in to analyze it very thoroughly. Have you ever found out similar kind of features in virtual machines?
Interesting. Just out of curiosity, what happens if you write a non-aligned dword straddling the page boundary, e.g. if page A is mapped and page B is unmapped and you write a dword with the mov instruction, two bytes into page A and two bytes into page B?
Does this also avoid throwing the page fault in the emulator? Sounds like a bounds checking bug or something to me...
I updated to the latest version and now everything works. However, that bug was not very serious for normal operating systems. I guess Windows and Linux do not rely on triggering a page fault that way (if there are no bugs). A user program might use it... to terminate itself?
I also tried to do memset(memory, 0, 0xFFFFFFFF) and it still did not trigger a page fault. However, it did not clear all the memory but stopped to the first unmapped page.
brain wrote:write a non-aligned dword straddling the page boundary
That would have been a good test. I should have tried.
jnc100 wrote:Are you using hardware virtualisation or relying on VirtualBox's emulation?
Antti wrote:I guess Windows and Linux do not rely on triggering a page fault that way (if there are no bugs). A user program might use it... to terminate itself?
...to initialise a memory region that is partially COW or swapped out?
A little offtopic note: I have a huge problem with my assembly code base. I posted my simple memset function to this thread and it is horrendously wrong. Unbelievable that I have missed this and noticed it until now: I have not saved registers ESI and EDI! This same problem is everywhere and I have to check all my assembly procedures. I somehow thought that only registers EBP and EBX should be saved. What a mistake.
There were some symptoms visible because I wondered why some things broke when I enabled high optimize levels in gcc. It is strange that I got this far even my widely used memset and memcpy always trashed registers that should be saved.