mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
virt_to_phys.sh also works with nopat
This commit is contained in:
@@ -58,8 +58,11 @@ BR2_PACKAGE_HOST_DTC=y
|
||||
#
|
||||
# - https://superuser.com/questions/71389/what-is-dev-mem/1214662#1214662
|
||||
# - https://unix.stackexchange.com/questions/4948/shell-command-to-read-device-registers
|
||||
# - man mem
|
||||
#
|
||||
# TODO: why with mmap MAP_PRIVATE (used in my previous custom naive version),
|
||||
# the entire register page is read?;
|
||||
#
|
||||
# TODO: have a look at: https://github.com/kaiwan/device-memory-readwrite
|
||||
#
|
||||
BR2_PACKAGE_DEVMEM2=y
|
||||
|
||||
@@ -4,7 +4,7 @@ Only tested in x86_64.
|
||||
Provide an allocated userland memory address for us to test out kernel memory APIs, including:
|
||||
|
||||
- /proc/pid/maps
|
||||
- /proc/pid/pagemap
|
||||
- /proc/pid/pagemap. See also: https://stackoverflow.com/questions/17021214/decode-proc-pid-pagemap-entry/45126141#45126141
|
||||
- /dev/mem
|
||||
|
||||
Usage:
|
||||
@@ -18,13 +18,13 @@ Outputs address and pid, e.g.:
|
||||
|
||||
Now translate the virtual address to physical for the given PID:
|
||||
|
||||
/pagemap2.out 110 | grep 0x600000
|
||||
/pagemap_dump.out 110 | grep 0x600000
|
||||
|
||||
where 0x600000 is the page that contains 0x600800.
|
||||
|
||||
This produces a line of type:
|
||||
|
||||
0x600000 0x7c7b 0 0 0 1 /pagemap_test.out
|
||||
0x600000 0x7c7b 0 0 0 1 /usermem.out
|
||||
|
||||
where 0x7c7b is the PFN. To get the physical address, just add three zeros back:
|
||||
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
/*
|
||||
TODO not working. Tested with both:
|
||||
|
||||
/virt_to_phys.sh
|
||||
|
||||
and on QEMU monitor:
|
||||
Also try on QEMU monitor:
|
||||
|
||||
xp 0x<vaddr>
|
||||
|
||||
|
||||
@@ -3,8 +3,10 @@ set -ex
|
||||
insmod /virt_to_phys.ko
|
||||
cd /sys/kernel/debug
|
||||
cat lkmc_virt_to_phys
|
||||
# *i = 0x12345678
|
||||
addr=$(grep virt_to_phys lkmc_virt_to_phys | cut -d ' ' -f 2)
|
||||
devmem2 "$addr"
|
||||
devmem2 "$addr" w 0x9ABCDEF0
|
||||
cat lkmc_virt_to_phys
|
||||
# *i = 0x9ABCDEF0
|
||||
rmmod virt_to_phys
|
||||
|
||||
Reference in New Issue
Block a user