简体   繁体   中英

Linux kernel: how to traverse physical pages in mem_map from user space using /dev/mem?

I need to traverse all physical pages contained in mem_map in user space via /dev/mem. mmap can't be used. The only hope is to use open/read calls. I know the physical address of mem_map inside the kernel. This is the code in user land:

 /* open /dev/mem file*/
 if((fd = open("/dev/mem", O_RDONLY)) == -1) {
    printf("/dev/mem could not be opened.\n");
perror("open");
    exit(1);
  } else {
  printf("/dev/mem opened.\n");

 /* seek to the mem_map at mem_map_phy_addr */
 if(lseek(fd, mem_map_phy_addr, SEEK_SET) == -1) {
   perror("lseek");
 }
 else {
   printf("lseek ok\n");
 }

Now the question is how to start traversing the mem_map? What user land include file has the 'struct page'?

Thanks.

First, you need to get the offset of 'mem_map', which is the physical address of that symbol. As 'mem_map' is exported, so you can write a small kernel module to get this address.

Then, you can lseek() to that offset (which is the address you get above), and you can start reading 'mem_map' from there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM