最近在看ARM的内存管理,刚好看到全局页表swapper_pg_dir,看了很久细想能否直接通过查看内存方式查看swapper_pg_dir的内存:
幸好之前弄过/dev/mem,知道可以把物理内存映射出来。
先贴工具代码:
#include
#include
#include
#include
#include
#include
#include
#include
#define DEVMEM "/dev/mem"
#define PAGE_SIZE 0x1000
int main(int argc, char* argv[])
{
int i,fd;
char *mbase;
char read_buf[10];
unsigned int phyAddr,varAddr,size;
unsigned int *ptr = NULL;
if(argc<3){
printf("./%s paddr size\n",argv[0]);
return 0;
}
phyAddr = strtoul(argv[1], 0, 16);
size = strtoul(argv[2], 0, 16);
fd = open(DEVMEM, O_RDONLY);
if(fd == -1) {
perror("open");
exit(-1);
}
mbase = mmap(0,PAGE_SIZE,PROT_READ,MAP_SHARED,fd, phyAddr);
if(mbase == MAP_FAILED) {
printf("map failed %s\n",strerror(errno));
}
ptr = (unsigned int *)mbase;
for(i=0;i
printf("%#x=%#x\n",phyAddr,*ptr++);
phyAddr += 4;
}
close(fd);
munmap(mbase,PAGE_SIZE);
return 0;
}
交叉编译出./mem工具。
怎么用呢?首先得知道swapper_pg_dir的物理地址吧。
其实最简单的就是看uImage的运行地址,从u-boot的运行过程:
U-Boot > boot
FEC: Link is Up 796d
Using FEC0 device
TFTP from server 192.168.1.105; our IP address is 192.168.1.235
Filename 'uImage'.
Load address: 0x10800000
Loading: #################################################################
#################################################################
#################################################################
#################################################################
############################################
done
Bytes transferred = 4452608 (43f100 hex)
## Booting kernel from Legacy Image at 10800000 ...
Image Name: Linux-3.0.35
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 4452544 Bytes = 4.2 MB
Load Address: 10008000
Entry Point: 10008000
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK
从红色标注可以看出我的开发板内存运行地址是0x10008000;
另外熟知内核都会之全局页表其实地址一般都是都是安排在内核运行地址前0x4000,4Byte对应1M物理空间,因此需要0x4000Byte全局页表空间。
因此我们全局页表的物理地址范围:0x10004000-0x10008000
由于4G虚拟地址又分为:内核空间3G-4G;
用户空间0G-3G,,因此我们的全局页表也对应分为两部分。我们这里只分析内核空间,因此只需要导出物理内存0x10007000-0x10008000.
/ # ./mnt/mem 0x10007000 0x1000
0x10007000=0x1001140e
0x10007004=0x1011140e
0x10007008=0x1021140e
0x1000700c=0x1031140e
0x10007010=0x1041140e
0x10007014=0x1051140e
0x10007018=0x1061140e
0x1000701c=0x1071140e
0x10007020=0x1081140e
0x10007024=0x1091140e
0x10007028=0x10a1140e
0x1000702c=0x10b1140e
0x10007030=0x10c1140e
0x10007034=0x10d1140e
0x10007038=0x10e1140e
0x1000703c=0x10f1140e
0x10007040=0x1101140e
0x10007044=0x1111140e
0x10007048=0x1121140e
0x1000704c=0x1131140e
0x10007050=0x1141140e
0x10007054=0x1151140e
0x10007058=0x1161140e
0x1000705c=0x1171140e
0x10007060=0x1181140e
0x10007064=0x1191140e
0x10007068=0x11a1140e
0x1000706c=0x11b1140e
0x10007070=0x11c1140e
0x10007074=0x11d1140e
0x10007078=0x11e1140e
0x1000707c=0x11f1140e
0x10007080=0x1201140e
0x10007084=0x1211140e
0x10007088=0x1221140e
0x1000708c=0x1231140e
0x10007090=0x1241140e
0x10007094=0x1251140e
0x10007098=0x1261140e
0x1000709c=0x1271140e
0x100070a0=0x1281140e
0x100070a4=0x1291140e
0x100070a8=0x12a1140e
0x100070ac=0x12b1140e
0x100070b0=0x12c1140e
0x100070b4=0x12d1140e
0x100070b8=0x12e1140e
0x100070bc=0x12f1140e
0x100070c0=0x1301140e
0x100070c4=0x1311140e
0x100070c8=0x1321140e
0x100070cc=0x1331140e
0x100070d0=0x1341140e
0x100070d4=0x1351140e
0x100070d8=0x1361140e
0x100070dc=0x1371140e
0x100070e0=0x1381140e
0x100070e4=0x1391140e
0x100070e8=0x13a1140e
0x100070ec=0x13b1140e
0x100070f0=0x13c1140e
0x100070f4=0x13d1140e
0x100070f8=0x13e1140e
0x100070fc=0x13f1140e
0x10007100=0x1401140e
0x10007104=0x1411140e
0x10007108=0x1421140e
0x1000710c=0x1431140e
0x10007110=0x1441140e
0x10007114=0x1451140e
0x10007118=0x1461140e
0x1000711c=0x1471140e
0x10007120=0x1481140e
0x10007124=0x1491140e
0x10007128=0x14a1140e
0x1000712c=0x14b1140e
0x10007130=0x14c1140e
0x10007134=0x14d1140e
0x10007138=0x14e1140e
0x1000713c=0x14f1140e
0x10007140=0x1501140e
0x10007144=0x1511140e
0x10007148=0x1521140e
0x1000714c=0x1531140e
0x10007150=0x1541140e
0x10007154=0x1551140e
0x10007158=0x1561140e
0x1000715c=0x1571140e
0x10007160=0x1581140e
0x10007164=0x1591140e
0x10007168=0x15a1140e
0x1000716c=0x15b1140e
0x10007170=0x15c1140e
0x10007174=0x15d1140e
0x10007178=0x15e1140e
0x1000717c=0x15f1140e
0x10007180=0x1601140e
0x10007184=0x1611140e
0x10007188=0x1621140e
0x1000718c=0x1631140e
0x10007190=0x1641140e
0x10007194=0x1651140e
0x10007198=0x1661140e
0x1000719c=0x1671140e
0x100071a0=0x1681140e
0x100071a4=0x1691140e
0x100071a8=0x16a1140e
0x100071ac=0x16b1140e
0x100071b0=0x16c1140e
0x100071b4=0x16d1140e
0x100071b8=0x16e1140e
0x100071bc=0x16f1140e
0x100071c0=0x1701140e
0x100071c4=0x1711140e
0x100071c8=0x1721140e
0x100071cc=0x1731140e
0x100071d0=0x1741140e
0x100071d4=0x1751140e
0x100071d8=0x1761140e
0x100071dc=0x1771140e
0x100071e0=0x1781140e
0x100071e4=0x1791140e
0x100071e8=0x17a1140e
0x100071ec=0x17b1140e
0x100071f0=0x17c1140e
0x100071f4=0x17d1140e
0x100071f8=0x17e1140e
0x100071fc=0x17f1140e
0x10007200=0x1801140e
0x10007204=0x1811140e
0x10007208=0x1821140e
0x1000720c=0x1831140e
0x10007210=0x1841140e
0x10007214=0x1851140e
0x10007218=0x1861140e
0x1000721c=0x1871140e
0x10007220=0x1881140e
0x10007224=0x1891140e
0x10007228=0x18a1140e
0x1000722c=0x18b1140e
0x10007230=0x18c1140e
0x10007234=0x18d1140e
0x10007238=0x18e1140e
0x1000723c=0x18f1140e
0x10007240=0x1901140e
0x10007244=0x1911140e
0x10007248=0x1921140e
0x1000724c=0x1931140e
0x10007250=0x1941140e
0x10007254=0x1951140e
0x10007258=0x1961140e
0x1000725c=0x1971140e
0x10007260=0x1981140e
0x10007264=0x1991140e
0x10007268=0x19a1140e
0x1000726c=0x19b1140e
0x10007270=0x19c1140e
0x10007274=0x19d1140e
0x10007278=0x19e1140e
0x1000727c=0x19f1140e
0x10007280=0x1a01140e
0x10007284=0x1a11140e
0x10007288=0x1a21140e
0x1000728c=0x1a31140e
0x10007290=0x1a41140e
0x10007294=0x1a51140e
0x10007298=0x1a61140e
0x1000729c=0x1a71140e
0x100072a0=0x1a81140e
0x100072a4=0x1a91140e
0x100072a8=0x1aa1140e
0x100072ac=0x1ab1140e
0x100072b0=0x1ac1140e
0x100072b4=0x1ad1140e
0x100072b8=0x1ae1140e
0x100072bc=0x1af1140e
0x100072c0=0x1b01140e
0x100072c4=0x1b11140e
0x100072c8=0x1b21140e
0x100072cc=0x1b31140e
0x100072d0=0x1b41140e
0x100072d4=0x1b51140e
0x100072d8=0x1b61140e
0x100072dc=0x1b71140e
0x100072e0=0x1b81140e
0x100072e4=0x1b91140e
0x100072e8=0x1ba1140e
0x100072ec=0x1bb1140e
0x100072f0=0x1bc1140e
0x100072f4=0x1bd1140e
0x100072f8=0x1be1140e
0x100072fc=0x1bf1140e
0x10007300=0x1c01140e
0x10007304=0x1c11140e
0x10007308=0x1c21140e
0x1000730c=0x1c31140e
0x10007310=0x1c41140e
0x10007314=0x1c51140e
0x10007318=0x1c61140e
0x1000731c=0x1c71140e
0x10007320=0x1c81140e
0x10007324=0x1c91140e
0x10007328=0x1ca1140e
0x1000732c=0x1cb1140e
0x10007330=0x1cc1140e
0x10007334=0x1cd1140e
0x10007338=0x1ce1140e
0x1000733c=0x1cf1140e
0x10007340=0x1d01140e
0x10007344=0x1d11140e
0x10007348=0x1d21140e
0x1000734c=0x1d31140e
0x10007350=0x1d41140e
0x10007354=0x1d51140e
0x10007358=0x1d61140e
0x1000735c=0x1d71140e
0x10007360=0x1d81140e
0x10007364=0x1d91140e
0x10007368=0x1da1140e
0x1000736c=0x1db1140e
0x10007370=0x1dc1140e
0x10007374=0x1dd1140e
0x10007378=0x1de1140e
0x1000737c=0x1df1140e
0x10007380=0x1e01140e
0x10007384=0x1e11140e
0x10007388=0x1e21140e
0x1000738c=0x1e31140e
0x10007390=0x1e41140e
0x10007394=0x1e51140e
0x10007398=0x1e61140e
0x1000739c=0x1e71140e
0x100073a0=0x1e81140e
0x100073a4=0x1e91140e
0x100073a8=0x1ea1140e
0x100073ac=0x1eb1140e
0x100073b0=0x1ec1140e
0x100073b4=0x1ed1140e
0x100073b8=0x1ee1140e
0x100073bc=0x1ef1140e
0x100073c0=0x1f01140e
0x100073c4=0x1f11140e
0x100073c8=0x1f21140e
0x100073cc=0x1f31140e
0x100073d0=0x1f41140e
0x100073d4=0x1f51140e
0x100073d8=0x1f61140e
0x100073dc=0x1f71140e
0x100073e0=0x1f81140e
0x100073e4=0x1f91140e
0x100073e8=0x1fa1140e
0x100073ec=0x1fb1140e
0x100073f0=0x1fc1140e
0x100073f4=0x1fd1140e
0x100073f8=0x1fe1140e
0x100073fc=0x1ff1140e
0x10007400=0x2001140e
0x10007404=0x2011140e
0x10007408=0x2021140e
0x1000740c=0x2031140e
0x10007410=0x2041140e
0x10007414=0x2051140e
0x10007418=0x2061140e
0x1000741c=0x2071140e
0x10007420=0x2081140e
0x10007424=0x2091140e
0x10007428=0x20a1140e
0x1000742c=0x20b1140e
0x10007430=0x20c1140e
0x10007434=0x20d1140e
0x10007438=0x20e1140e
0x1000743c=0x20f1140e
0x10007440=0x2101140e
0x10007444=0x2111140e
0x10007448=0x2121140e
0x1000744c=0x2131140e
0x10007450=0x2141140e
0x10007454=0x2151140e
0x10007458=0x2161140e
0x1000745c=0x2171140e
0x10007460=0x2181140e
0x10007464=0x2191140e
0x10007468=0x21a1140e
0x1000746c=0x21b1140e
0x10007470=0x21c1140e
0x10007474=0x21d1140e
0x10007478=0x21e1140e
0x1000747c=0x21f1140e
0x10007480=0x2201140e
0x10007484=0x2211140e
0x10007488=0x2221140e
0x1000748c=0x2231140e
0x10007490=0x2241140e
0x10007494=0x2251140e
0x10007498=0x2261140e
0x1000749c=0x2271140e
0x100074a0=0x2281140e
0x100074a4=0x2291140e
0x100074a8=0x22a1140e
0x100074ac=0x22b1140e
0x100074b0=0x22c1140e
0x100074b4=0x22d1140e
0x100074b8=0x22e1140e
0x100074bc=0x22f1140e
0x100074c0=0x2301140e
0x100074c4=0x2311140e
0x100074c8=0x2321140e
0x100074cc=0x2331140e
0x100074d0=0x2341140e
0x100074d4=0x2351140e
0x100074d8=0x2361140e
0x100074dc=0x2371140e
0x100074e0=0x2381140e
0x100074e4=0x2391140e
0x100074e8=0x23a1140e
0x100074ec=0x23b1140e
0x100074f0=0x23c1140e
0x100074f4=0x23d1140e
0x100074f8=0x23e1140e
0x100074fc=0x23f1140e
0x10007500=0x2401140e
0x10007504=0x2411140e
0x10007508=0x2421140e
0x1000750c=0x2431140e
0x10007510=0x2441140e
0x10007514=0x2451140e
0x10007518=0x2461140e
0x1000751c=0x2471140e
0x10007520=0x2481140e
0x10007524=0x2491140e
0x10007528=0x24a1140e
0x1000752c=0x24b1140e
0x10007530=0x24c1140e
0x10007534=0x24d1140e
0x10007538=0x24e1140e
0x1000753c=0x24f1140e
0x10007540=0x2501140e
0x10007544=0x2511140e
0x10007548=0x2521140e
0x1000754c=0x2531140e
0x10007550=0x2541140e
0x10007554=0x2551140e
0x10007558=0x2561140e
0x1000755c=0x2571140e
0x10007560=0x2581140e
0x10007564=0x2591140e
0x10007568=0x25a1140e
0x1000756c=0x25b1140e
0x10007570=0x25c1140e
0x10007574=0x25d1140e
0x10007578=0x25e1140e
0x1000757c=0x25f1140e
0x10007580=0x2601140e
0x10007584=0x2611140e
0x10007588=0x2621140e
0x1000758c=0x2631140e
0x10007590=0x2641140e
0x10007594=0x2651140e
0x10007598=0x2661140e
0x1000759c=0x2671140e
0x100075a0=0x2681140e
0x100075a4=0x2691140e
0x100075a8=0x26a1140e
0x100075ac=0x26b1140e
0x100075b0=0x26c1140e
0x100075b4=0x26d1140e
0x100075b8=0x26e1140e
0x100075bc=0x26f1140e
0x100075c0=0x2701140e
0x100075c4=0x2711140e
0x100075c8=0x2721140e
0x100075cc=0x2731140e
0x100075d0=0x2741140e
0x100075d4=0x2751140e
0x100075d8=0x2761140e
0x100075dc=0x2771140e
0x100075e0=0x2781140e
0x100075e4=0x2791140e
0x100075e8=0x27a1140e
0x100075ec=0x27b1140e
0x100075f0=0x27c1140e
0x100075f4=0x27d1140e
0x100075f8=0x27e1140e
0x100075fc=0x27f1140e
0x10007600=0x2801140e
0x10007604=0x2811140e
0x10007608=0x2821140e
0x1000760c=0x2831140e
0x10007610=0x2841140e
0x10007614=0x2851140e
0x10007618=0x2861140e
0x1000761c=0x2871140e
0x10007620=0x2881140e
0x10007624=0x2891140e
0x10007628=0x28a1140e
0x1000762c=0x28b1140e
0x10007630=0x28c1140e
0x10007634=0x28d1140e
0x10007638=0x28e1140e
0x1000763c=0x28f1140e
0x10007640=0x2901140e
0x10007644=0x2911140e
0x10007648=0x2921140e
0x1000764c=0x2931140e
0x10007650=0x2941140e
0x10007654=0x2951140e
0x10007658=0x2961140e
0x1000765c=0x2971140e
0x10007660=0x2981140e
0x10007664=0x2991140e
0x10007668=0x29a1140e
0x1000766c=0x29b1140e
0x10007670=0x29c1140e
0x10007674=0x29d1140e
0x10007678=0x29e1140e
0x1000767c=0x29f1140e
0x10007680=0x2a01140e
0x10007684=0x2a11140e
0x10007688=0x2a21140e
0x1000768c=0x2a31140e
0x10007690=0x2a41140e
0x10007694=0x2a51140e
0x10007698=0x2a61140e
0x1000769c=0x2a71140e
0x100076a0=0x2a81140e
0x100076a4=0x2a91140e
0x100076a8=0x2aa1140e
0x100076ac=0x2ab1140e
0x100076b0=0x2ac1140e
0x100076b4=0x2ad1140e
0x100076b8=0x2ae1140e
0x100076bc=0x2af1140e
0x100076c0=0x2b01140e
0x100076c4=0x2b11140e
0x100076c8=0x2b21140e
0x100076cc=0x2b31140e
0x100076d0=0x2b41140e
0x100076d4=0x2b51140e
0x100076d8=0x2b61140e
0x100076dc=0x2b71140e
0x100076e0=0x2b81140e
0x100076e4=0x2b91140e
0x100076e8=0x2ba1140e
0x100076ec=0x2bb1140e
0x100076f0=0x2bc1140e
0x100076f4=0x2bd1140e
0x100076f8=0x2be1140e
0x100076fc=0x2bf1140e
0x10007700=0x2c01140e
0x10007704=0x2c11140e
0x10007708=0x2c21140e
0x1000770c=0x2c31140e
0x10007710=0x2c41140e
0x10007714=0x2c51140e
0x10007718=0x2c61140e
0x1000771c=0x2c71140e
0x10007720=0x2c81140e
0x10007724=0x2c91140e
0x10007728=0x2ca1140e
0x1000772c=0x2cb1140e
0x10007730=0x2cc1140e
0x10007734=0x2cd1140e
0x10007738=0x2ce1140e
0x1000773c=0x2cf1140e
0x10007740=0x2d01140e
0x10007744=0x2d11140e
0x10007748=0x2d21140e
0x1000774c=0x2d31140e
0x10007750=0x2d41140e
0x10007754=0x2d51140e
0x10007758=0x2d61140e
0x1000775c=0x2d71140e
0x10007760=0x2d81140e
0x10007764=0x2d91140e
0x10007768=0x2da1140e
0x1000776c=0x2db1140e
0x10007770=0x2dc1140e
0x10007774=0x2dd1140e
0x10007778=0x2de1140e
0x1000777c=0x2df1140e
0x10007780=0x2e01140e
0x10007784=0x2e11140e
0x10007788=0x2e21140e
0x1000778c=0x2e31140e
0x10007790=0x2e41140e
0x10007794=0x2e51140e
0x10007798=0x2e61140e
0x1000779c=0x2e71140e
0x100077a0=0x2e81140e
0x100077a4=0x2e91140e
0x100077a8=0x2ea1140e
0x100077ac=0x2eb1140e
0x100077b0=0x2ec1140e
0x100077b4=0x2ed1140e
0x100077b8=0x2ee1140e
0x100077bc=0x2ef1140e
0x100077c0=0x2f01140e
0x100077c4=0x2f11140e
0x100077c8=0x2f21140e
0x100077cc=0x2f31140e
0x100077d0=0x2f41140e
0x100077d4=0x2f51140e
0x100077d8=0x2f61140e
0x100077dc=0x2f71140e
0x100077e0=0x2f81140e
0x100077e4=0x2f91140e
0x100077e8=0x2fa1140e
0x100077ec=0x2fb1140e
0x100077f0=0x2fc1140e
0x100077f4=0x2fd1140e
0x100077f8=0x2fe1140e
0x100077fc=0x2ff1140e
0x10007800=0x3001140e
0x10007804=0x3011140e
0x10007808=0x3021140e
0x1000780c=0x3031140e
0x10007810=0x3041140e
0x10007814=0x3051140e
0x10007818=0x3061140e
0x1000781c=0x3071140e
0x10007820=0x3081140e
0x10007824=0x3091140e
0x10007828=0x30a1140e
0x1000782c=0x30b1140e
0x10007830=0x30c1140e
0x10007834=0x30d1140e
0x10007838=0x30e1140e
0x1000783c=0x30f1140e
0x10007840=0x3101140e
0x10007844=0x3111140e
0x10007848=0x3121140e
0x1000784c=0x3131140e
0x10007850=0x3141140e
0x10007854=0x3151140e
0x10007858=0x3161140e
0x1000785c=0x3171140e
0x10007860=0x3181140e
0x10007864=0x3191140e
0x10007868=0x31a1140e
0x1000786c=0x31b1140e
0x10007870=0x31c1140e
0x10007874=0x31d1140e
0x10007878=0x31e1140e
0x1000787c=0x31f1140e
0x10007880=0x3201140e
0x10007884=0x3211140e
0x10007888=0x3221140e
0x1000788c=0x3231140e
0x10007890=0x3241140e
0x10007894=0x3251140e
0x10007898=0x3261140e
0x1000789c=0x3271140e
0x100078a0=0x3281140e
0x100078a4=0x3291140e
0x100078a8=0x32a1140e
0x100078ac=0x32b1140e
0x100078b0=0x32c1140e
0x100078b4=0x32d1140e
0x100078b8=0x32e1140e
0x100078bc=0x32f1140e
0x100078c0=0x3301140e
0x100078c4=0x3311140e
0x100078c8=0x3321140e
0x100078cc=0x3331140e
0x100078d0=0x3341140e
0x100078d4=0x3351140e
0x100078d8=0x3361140e
0x100078dc=0x3371140e
0x100078e0=0x3381140e
0x100078e4=0x3391140e
0x100078e8=0x33a1140e
0x100078ec=0x33b1140e
0x100078f0=0x33c1140e
0x100078f4=0x33d1140e
0x100078f8=0x33e1140e
0x100078fc=0x33f1140e
0x10007900=0x3401140e
0x10007904=0x3411140e
0x10007908=0x3421140e
0x1000790c=0x3431140e
0x10007910=0x3441140e
0x10007914=0x3451140e
0x10007918=0x3461140e
0x1000791c=0x3471140e
0x10007920=0x3481140e
0x10007924=0x3491140e
0x10007928=0x34a1140e
0x1000792c=0x34b1140e
0x10007930=0x34c1140e
0x10007934=0x34d1140e
0x10007938=0x34e1140e
0x1000793c=0x34f1140e
0x10007940=0x3501140e
0x10007944=0x3511140e
0x10007948=0x3521140e
0x1000794c=0x3531140e
0x10007950=0x3541140e
0x10007954=0x3551140e
0x10007958=0x3561140e
0x1000795c=0x3571140e
0x10007960=0x3581140e
0x10007964=0x3591140e
0x10007968=0x35a1140e
0x1000796c=0x35b1140e
0x10007970=0x35c1140e
0x10007974=0x35d1140e
0x10007978=0x35e1140e
0x1000797c=0x35f1140e
0x10007980=0x3601140e
0x10007984=0x3611140e
0x10007988=0x3621140e
0x1000798c=0x3631140e
0x10007990=0x3641140e
0x10007994=0x3651140e
0x10007998=0x3661140e
0x1000799c=0x3671140e
0x100079a0=0x3681140e
0x100079a4=0x3691140e
0x100079a8=0x36a1140e
0x100079ac=0x36b1140e
0x100079b0=0x36c1140e
0x100079b4=0x36d1140e
0x100079b8=0x36e1140e
0x100079bc=0x36f1140e
0x100079c0=0x3701140e
0x100079c4=0x3711140e
0x100079c8=0x3721140e
0x100079cc=0x3731140e
0x100079d0=0x3741140e
0x100079d4=0x3751140e
0x100079d8=0x3761140e
0x100079dc=0x3771140e
0x100079e0=0x3781140e
0x100079e4=0x3791140e
0x100079e8=0x37a1140e
0x100079ec=0x37b1140e
0x100079f0=0x37c1140e
0x100079f4=0x37d1140e
0x100079f8=0x37e1140e
0x100079fc=0x37f1140e
0x10007a00=0x3801140e
0x10007a04=0x3811140e
0x10007a08=0x3821140e
0x10007a0c=0x3831140e
0x10007a10=0x3841140e
0x10007a14=0x3851140e
0x10007a18=0x3861140e
0x10007a1c=0x3871140e
0x10007a20=0x3881140e
0x10007a24=0x3891140e
0x10007a28=0x38a1140e
0x10007a2c=0x38b1140e
0x10007a30=0x38c1140e
0x10007a34=0x38d1140e
0x10007a38=0x38e1140e
0x10007a3c=0x38f1140e
0x10007a40=0x3901140e
0x10007a44=0x3911140e
0x10007a48=0x3921140e
0x10007a4c=0x3931140e
0x10007a50=0x3941140e
0x10007a54=0x3951140e
0x10007a58=0x3961140e
0x10007a5c=0x3971140e
0x10007a60=0x3981140e
0x10007a64=0x3991140e
0x10007a68=0x39a1140e
0x10007a6c=0x39b1140e
0x10007a70=0x39c1140e
0x10007a74=0x39d1140e
0x10007a78=0x39e1140e
0x10007a7c=0x39f1140e
0x10007a80=0
0x10007a84=0
0x10007a88=0
0x10007a8c=0
0x10007a90=0
0x10007a94=0
0x10007a98=0
0x10007a9c=0
0x10007aa0=0x39ff5811
0x10007aa4=0x39ff5c11
0x10007aa8=0x39cfa811
0x10007aac=0x39cfac11
0x10007ab0=0x39cf9811
0x10007ab4=0x39cf9c11
0x10007ab8=0x39cfb811
0x10007abc=0x39cfbc11
0x10007ac0=0
0x10007ac4=0
0x10007ac8=0
0x10007acc=0
0x10007ad0=0
0x10007ad4=0
0x10007ad8=0
0x10007adc=0
0x10007ae0=0
0x10007ae4=0
0x10007ae8=0
0x10007aec=0
0x10007af0=0
0x10007af4=0
0x10007af8=0
0x10007afc=0
0x10007b00=0
0x10007b04=0
0x10007b08=0
0x10007b0c=0
0x10007b10=0
0x10007b14=0
0x10007b18=0
0x10007b1c=0
0x10007b20=0
0x10007b24=0
0x10007b28=0
0x10007b2c=0
0x10007b30=0
0x10007b34=0
0x10007b38=0
0x10007b3c=0
0x10007b40=0
0x10007b44=0
0x10007b48=0
0x10007b4c=0
0x10007b50=0
0x10007b54=0
0x10007b58=0
0x10007b5c=0
0x10007b60=0
0x10007b64=0
0x10007b68=0
0x10007b6c=0
0x10007b70=0
0x10007b74=0
0x10007b78=0
0x10007b7c=0
0x10007b80=0
0x10007b84=0
0x10007b88=0
0x10007b8c=0
0x10007b90=0
0x10007b94=0
0x10007b98=0
0x10007b9c=0
0x10007ba0=0
0x10007ba4=0
0x10007ba8=0
0x10007bac=0
0x10007bb0=0
0x10007bb4=0
0x10007bb8=0
0x10007bbc=0
0x10007bc0=0
0x10007bc4=0
0x10007bc8=0
0x10007bcc=0
0x10007bd0=0
0x10007bd4=0
0x10007bd8=0
0x10007bdc=0
0x10007be0=0
0x10007be4=0
0x10007be8=0
0x10007bec=0
0x10007bf0=0
0x10007bf4=0
0x10007bf8=0
0x10007bfc=0
0x10007c00=0
0x10007c04=0
0x10007c08=0
0x10007c0c=0
0x10007c10=0
0x10007c14=0
0x10007c18=0
0x10007c1c=0
0x10007c20=0
0x10007c24=0
0x10007c28=0
0x10007c2c=0
0x10007c30=0
0x10007c34=0
0x10007c38=0
0x10007c3c=0
0x10007c40=0
0x10007c44=0
0x10007c48=0
0x10007c4c=0
0x10007c50=0
0x10007c54=0
0x10007c58=0
0x10007c5c=0
0x10007c60=0
0x10007c64=0
0x10007c68=0
0x10007c6c=0
0x10007c70=0
0x10007c74=0
0x10007c78=0x39c20811
0x10007c7c=0x39c20c11
0x10007c80=0x11452
0x10007c84=0
0x10007c88=0
0x10007c8c=0
0x10007c90=0
0x10007c94=0
0x10007c98=0
0x10007c9c=0
0x10007ca0=0
0x10007ca4=0
0x10007ca8=0x39ffd841
0x10007cac=0x39ffdc41
0x10007cb0=0
0x10007cb4=0
0x10007cb8=0
0x10007cbc=0
0x10007cc0=0
0x10007cc4=0
0x10007cc8=0
0x10007ccc=0
0x10007cd0=0
0x10007cd4=0
0x10007cd8=0
0x10007cdc=0
0x10007ce0=0
0x10007ce4=0
0x10007ce8=0
0x10007cec=0
0x10007cf0=0
0x10007cf4=0
0x10007cf8=0
0x10007cfc=0
0x10007d00=0x2011452
0x10007d04=0x2111452
0x10007d08=0
0x10007d0c=0
0x10007d10=0
0x10007d14=0
0x10007d18=0x39f56811
0x10007d1c=0x39f56c11
0x10007d20=0x39f57811
0x10007d24=0x39f57c11
0x10007d28=0x39f58811
0x10007d2c=0x39f58c11
0x10007d30=0x39f59811
0x10007d34=0x39f59c11
0x10007d38=0x39f5a811
0x10007d3c=0x39f5ac11
0x10007d40=0x39f5b811
0x10007d44=0x39f5bc11
0x10007d48=0x39f5c811
0x10007d4c=0x39f5cc11
0x10007d50=0x39f5d811
0x10007d54=0x39f5dc11
0x10007d58=0x39f5e811
0x10007d5c=0x39f5ec11
0x10007d60=0x39f5f811
0x10007d64=0x39f5fc11
0x10007d68=0x39f60811
0x10007d6c=0x39f60c11
0x10007d70=0x39f61811
0x10007d74=0x39f61c11
0x10007d78=0x39f62811
0x10007d7c=0x39f62c11
0x10007d80=0x39f63811
0x10007d84=0x39f63c11
0x10007d88=0x39f64811
0x10007d8c=0x39f64c11
0x10007d90=0x39f65811
0x10007d94=0x39f65c11
0x10007d98=0x39f66811
0x10007d9c=0x39f66c11
0x10007da0=0x39f67811
0x10007da4=0x39f67c11
0x10007da8=0x39f68811
0x10007dac=0x39f68c11
0x10007db0=0x39f69811
0x10007db4=0x39f69c11
0x10007db8=0x39f6a811
0x10007dbc=0x39f6ac11
0x10007dc0=0x39f6b811
0x10007dc4=0x39f6bc11
0x10007dc8=0x39f0a811
0x10007dcc=0x39f0ac11
0x10007dd0=0x39f0b811
0x10007dd4=0x39f0bc11
0x10007dd8=0x39f6c811
0x10007ddc=0x39f6cc11
0x10007de0=0x39f6d811
0x10007de4=0x39f6dc11
0x10007de8=0x39f6e811
0x10007dec=0x39f6ec11
0x10007df0=0x39f6f811
0x10007df4=0x39f6fc11
0x10007df8=0x39f70811
0x10007dfc=0x39f70c11
0x10007e00=0x39f71811
0x10007e04=0x39f71c11
0x10007e08=0x39f72811
0x10007e0c=0x39f72c11
0x10007e10=0x39f73811
0x10007e14=0x39f73c11
0x10007e18=0x39f74811
0x10007e1c=0x39f74c11
0x10007e20=0x39f75811
0x10007e24=0x39f75c11
0x10007e28=0x39f76811
0x10007e2c=0x39f76c11
0x10007e30=0x39f77811
0x10007e34=0x39f77c11
0x10007e38=0x39f78811
0x10007e3c=0x39f78c11
0x10007e40=0x39f79811
0x10007e44=0x39f79c11
0x10007e48=0x39f7a811
0x10007e4c=0x39f7ac11
0x10007e50=0x39f7b811
0x10007e54=0x39f7bc11
0x10007e58=0x39f7c811
0x10007e5c=0x39f7cc11
0x10007e60=0x39f7d811
0x10007e64=0x39f7dc11
0x10007e68=0x39f7e811
0x10007e6c=0x39f7ec11
0x10007e70=0x39f7f811
0x10007e74=0x39f7fc11
0x10007e78=0x39e00811
0x10007e7c=0x39e00c11
0x10007e80=0x39e01811
0x10007e84=0x39e01c11
0x10007e88=0x39e02811
0x10007e8c=0x39e02c11
0x10007e90=0x39e03811
0x10007e94=0x39e03c11
0x10007e98=0x39e04811
0x10007e9c=0x39e04c11
0x10007ea0=0x39e05811
0x10007ea4=0x39e05c11
0x10007ea8=0x39e06811
0x10007eac=0x39e06c11
0x10007eb0=0x39e07811
0x10007eb4=0x39e07c11
0x10007eb8=0x39e08811
0x10007ebc=0x39e08c11
0x10007ec0=0x39e09811
0x10007ec4=0x39e09c11
0x10007ec8=0x39e0a811
0x10007ecc=0x39e0ac11
0x10007ed0=0x39e0b811
0x10007ed4=0x39e0bc11
0x10007ed8=0x39e0c811
0x10007edc=0x39e0cc11
0x10007ee0=0x39e0d811
0x10007ee4=0x39e0dc11
0x10007ee8=0x39e0e811
0x10007eec=0x39e0ec11
0x10007ef0=0x39e0f811
0x10007ef4=0x39e0fc11
0x10007ef8=0x39e10811
0x10007efc=0x39e10c11
0x10007f00=0x39e11811
0x10007f04=0x39e11c11
0x10007f08=0x39e12811
0x10007f0c=0x39e12c11
0x10007f10=0x39e13811
0x10007f14=0x39e13c11
0x10007f18=0x39e14811
0x10007f1c=0x39e14c11
0x10007f20=0x39e15811
0x10007f24=0x39e15c11
0x10007f28=0x39e16811
0x10007f2c=0x39e16c11
0x10007f30=0x39e17811
0x10007f34=0x39e17c11
0x10007f38=0x39e18811
0x10007f3c=0x39e18c11
0x10007f40=0x39e19811
0x10007f44=0x39e19c11
0x10007f48=0x39e1a811
0x10007f4c=0x39e1ac11
0x10007f50=0x39e1b811
0x10007f54=0x39e1bc11
0x10007f58=0x39e1c811
0x10007f5c=0x39e1cc11
0x10007f60=0x39e1d811
0x10007f64=0x39e1dc11
0x10007f68=0x39e1e811
0x10007f6c=0x39e1ec11
0x10007f70=0x39e1f811
0x10007f74=0x39e1fc11
0x10007f78=0x39e20811
0x10007f7c=0x39e20c11
0x10007f80=0x39e21811
0x10007f84=0x39e21c11
0x10007f88=0x39e22811
0x10007f8c=0x39e22c11
0x10007f90=0x39e23811
0x10007f94=0x39e23c11
0x10007f98=0x39e24811
0x10007f9c=0x39e24c11
0x10007fa0=0x39e25811
0x10007fa4=0x39e25c11
0x10007fa8=0x39e26811
0x10007fac=0x39e26c11
0x10007fb0=0x39e27811
0x10007fb4=0x39e27c11
0x10007fb8=0x39e28811
0x10007fbc=0x39e28c11
0x10007fc0=0x39e29811
0x10007fc4=0x39e29c11
0x10007fc8=0x39e2a811
0x10007fcc=0x39e2ac11
0x10007fd0=0x39e2b811
0x10007fd4=0x39e2bc11
0x10007fd8=0x39e2c811
0x10007fdc=0x39e2cc11
0x10007fe0=0x39e2d811
0x10007fe4=0x39e2dc11
0x10007fe8=0x39e2e811
0x10007fec=0x39e2ec11
0x10007ff0=0x39e2f811
0x10007ff4=0x39e2fc11
0x10007ff8=0x39ffe821
0x10007ffc=0x39ffec21
/ #
我们增加一个例子,通过vmalloc获取一个10页的内存空间,并通过页表转换找到对应所在的物理内存数据是否与我们例子初始值一致。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
MODULE_LICENSE("GPL");
MODULE_AUTHOR("dean");
MODULE_DESCRIPTION("test");
static int memsize = 10;
module_param(memsize, int, S_IRUGO);
__u8 *data;
static int __init myhook_init(void)
{
int i;
printk(KERN_INFO"dean: %s =>> %s ==>>%d\n",__FILE__,__FUNCTION__,__LINE__);
data = vmalloc(4096 * memsize);
if (!data)
return -ENOMEM;
for(i=0;i<4096 * memsize;i++)
{
data[i] = i%256;
}
printk("module loaded. data=%#x\n",data);
return 0;
}
static void __exit myhook_fini(void)
{
vfree(data);
printk(KERN_INFO"dean: %s =>> %s ==>>%d\n",__FILE__,__FUNCTION__,__LINE__);
}
module_init(myhook_init);
module_exit(myhook_fini);
通过以上例子,我们获得10页内核虚拟空间,其实地址为0xeae47000:
/mnt # insmod vmalloc.ko
[ 4641.387650] dean: /home/dean/ucm6510/test/vmalloc/vmalloc.c =>> myhook_init ==>>30
[ 4641.395724] module loaded. data=0xeae47000
/mnt #
通过0xeae47000的高12位0xeae找到对应的全局页表物理地址:0xeae *4 +0x10004000 = 0x10007AB8
通过./mem 0x10007000 0x1000找到对应的 0x10007AB8内存值:
0x10007ab8=0x3991b811
可以看到全局页表保存的是0x3991b811,表示的是粗页表描述符,高20位表示二级页表的物理起始地址0x3991b000;
偏移量从虚拟地址0xeae47000的bit19-bit12,即0x47,再乘以4(PTE为4Bytes),得到0x11C,加上二级页表基地址0x3991b000等于0x3991b11c。
通过./mem 0x3991b000 0x1000找到对应的内存值:
HW/pte
0x3991b11c=0x4ed1165f
0x3991b120=0x4ed1065f
0x3991b124=0x4ed0f65f
0x3991b128=0x4ed0e65f
0x3991b12c=0x4ed0d65f
0x3991b130=0x4ed0c65f
0x3991b134=0x4ed0b65f
0x3991b138=0x4ed0a65f
0x3991b13c=0x4ed0965f
0x3991b140=0x4ed0865f
Linux/pte
0x3991b91c=0x4ed1145f
0x3991b920=0x4ed1045f
0x3991b924=0x4ed0f45f
0x3991b928=0x4ed0e45f
0x3991b92c=0x4ed0d45f
0x3991b930=0x4ed0c45f
0x3991b934=0x4ed0b45f
0x3991b938=0x4ed0a45f
0x3991b93c=0x4ed0945f
0x3991b940=0x4ed0845f
可以看出0x3991b11c-0x3991b140刚好分配了10个PTE。从0x4ed1165f得到对应的物理地址0x4ed11000;
/mnt # ./mem 0x4ed11000 0x1000
0x4ed11000=0x3020100
0x4ed11004=0x7060504
0x4ed11008=0xb0a0908
0x4ed1100c=0xf0e0d0c
0x4ed11010=0x13121110
0x4ed11014=0x17161514
0x4ed11018=0x1b1a1918
0x4ed1101c=0x1f1e1d1c
0x4ed11020=0x23222120
0x4ed11024=0x27262524
0x4ed11028=0x2b2a2928
0x4ed1102c=0x2f2e2d2c
0x4ed11030=0x33323130
0x4ed11034=0x37363534
0x4ed11038=0x3b3a3938
0x4ed1103c=0x3f3e3d3c
0x4ed11040=0x43424140
0x4ed11044=0x47464544
0x4ed11048=0x4b4a4948
0x4ed1104c=0x4f4e4d4c
0x4ed11050=0x53525150
0x4ed11054=0x57565554
0x4ed11058=0x5b5a5958
0x4ed1105c=0x5f5e5d5c
0x4ed11060=0x63626160
从以上数据可以看到和我们module初始值一致。因此可以确定转换过程OK。Bingo!
下次再分析PTE的HW PTE和Linux PTE 低12位的含义以及全局页表低12位的含义。