Page 1 of 1

Something overwrittes memory after address space mapping

Posted: Sun Apr 25, 2021 11:05 am
by daniilq
Hi,
There is a small operating system I developed. I try to implement multitasking in kernel mode. I load my exe file into memory with dma controller and floppy disk. I hardcoded physical address 0x20000 for my program (I've tryed other addresses, it doesn't matter). If I do identity mapping of the first megabyte and start new process with the EIP register that is equal 0x20000 everything is fine. It works as expected. When I try to map 0x20000 of physical memory to 0 address of virtual address space something happens. Something overwrite 0x20000 physical memory address. I tryed analyze it, I tryed to find a bug in my code I didn't have any result. I hope somebody faced something similar. Thank you!
P.S. I attached normal and overwritted memory screenshots.

Re: Something overwrittes memory after address space mapping

Posted: Mon Apr 26, 2021 9:29 am
by sj95126
It sounds like you may be dereferencing a null pointer and overwriting something you don't want to overwrite.

As a matter of practice, it's usually good to make virtual address 0 unusable, for exactly this reason. You may want to try either removing the mapping for that address, or at least set it read-only and see what happens.

Re: Something overwrittes memory after address space mapping

Posted: Tue Apr 27, 2021 2:26 am
by daniilq
Thanks a lot! When I made memory read only I faced with another issue, but moving of memory mapping helped me! I tried to use virtual address 1 instead of virtual address 0 and it started to work. \:D/