accessing physical memory from linux kernel

后端 未结 3 1032
别跟我提以往
别跟我提以往 2021-01-04 20:15

Can we access any physical memory via some kernel code.? Because, i wrote a device driver which only had init_module and exit_module.. the code is following.



        
相关标签:
3条回答
  • 2021-01-04 20:47

    I suggest reading the chapter about memory in this book:

    http://lwn.net/Kernel/LDD3/

    It's available online for free. Good stuff!

    0 讨论(0)
  • 2021-01-04 20:53

    To access real physical memory you should use phys_to_virt function. In case it is io memory (e.g. PCI memory) you should have a closer look at ioremap.

    This whole topic is very complex, if you are a beginner I would suggest some kernel/driver development books/doc.

    0 讨论(0)
  • 2021-01-04 20:55

    Inside the kernel, memory is still mapped virtually, just not the same way as in userspace.

    The chances are that 0x10 is in a guard page or something, to catch null pointers, so it generates an unhandled page fault in the kernel when you touch it.

    Normally this causes an OOPS not a hang (but it can be configured to cause a panic). OOPS is an unexpected kernel condition which can be recovered from in some cases, and does not necessarily bring down the whole system. Normally it kills the task (in this case, insmod)

    Did you do this on a desktop Linux system with a GUI loaded? I recommend that you set up a Linux VM (Vmware, virtualbox etc) with a simple (i.e. quick to reboot) text-based distribution if you want to hack around with the kernel. You're going to crash it a bit and you want it to reboot as quickly as possible. Also by using a text-based distribution, it is easier to see kernel crash messages (Oops or panic)

    0 讨论(0)
提交回复
热议问题