mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-26 11:41:35 +01:00
virt_to_phys: fix %p vs %px
Move doc to README
This commit is contained in:
52
README.adoc
52
README.adoc
@@ -4127,7 +4127,9 @@ The module also shows which handlers are registered for each IRQ, as we have obs
|
||||
|
||||
When in text mode, we can also observe interrupt line 4 with handler `ttyS0` increase continuously as IO goes through the UART.
|
||||
|
||||
=== Linux kernel utility functions
|
||||
=== Kernel utility functions
|
||||
|
||||
https://github.com/torvalds/linux/blob/v4.17/Documentation/core-api/kernel-api.rst
|
||||
|
||||
==== kstrto
|
||||
|
||||
@@ -4151,6 +4153,54 @@ Sources:
|
||||
|
||||
Bibliography: https://stackoverflow.com/questions/6139493/how-convert-char-to-int-in-linux-kernel/49811658#49811658
|
||||
|
||||
==== virt_to_phys
|
||||
|
||||
Convert a virtual address to physical:
|
||||
|
||||
....
|
||||
insmod /virt_to_phys.ko
|
||||
cat /sys/kernel/debug/lkmc_virt_to_phys
|
||||
....
|
||||
|
||||
Source: link:kernel_module/virt_to_phys.c[]
|
||||
|
||||
Sample output:
|
||||
|
||||
....
|
||||
*kmalloc_ptr = 0x12345678
|
||||
kmalloc_ptr = ffff88000e169ae8
|
||||
virt_to_phys(kmalloc_ptr) = 0xe169ae8
|
||||
static_var = 0x12345678
|
||||
&static_var = ffffffffc0002308
|
||||
virt_to_phys(&static_var) = 0x40002308
|
||||
....
|
||||
|
||||
We can confirm that the `kmalloc_ptr` translation worked with:
|
||||
|
||||
....
|
||||
./qemumonitor 'xp 0xe169ae8'
|
||||
....
|
||||
|
||||
which reads four bytes from a given physical address, and gives the expected:
|
||||
|
||||
....
|
||||
000000000e169ae8: 0x12345678
|
||||
....
|
||||
|
||||
TODO it only works for kmalloc however, for the static variable:
|
||||
|
||||
....
|
||||
./qemumonitor 'xp 0x40002308'
|
||||
....
|
||||
|
||||
it gave a wrong value of `00000000`.
|
||||
|
||||
Bibliography:
|
||||
|
||||
* https://stackoverflow.com/questions/5748492/is-there-any-api-for-determining-the-physical-address-from-virtual-address-in-li/45128487#45128487
|
||||
* https://stackoverflow.com/questions/39134990/mmap-of-dev-mem-fails-with-invalid-argument-for-virt-to-phys-address-but-addre/45127582#45127582
|
||||
* https://stackoverflow.com/questions/43325205/can-we-use-virt-to-phys-for-user-space-memory-in-kernel-module
|
||||
|
||||
=== Linux kernel tracing
|
||||
|
||||
Good overviews:
|
||||
|
||||
Reference in New Issue
Block a user