Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.os.linux.development.apps > #760

Re: Iterating over mem_map and printing out the 'struct pages' instances

Newsgroups comp.os.linux.development.apps
Date 2014-09-29 11:29 -0700
References <5f6a4592-ca68-4322-9a1b-2b7d7bb5cc2b@googlegroups.com>
Message-ID <a0f2935a-6036-4523-b50d-32cb3405e5ca@googlegroups.com> (permalink)
Subject Re: Iterating over mem_map and printing out the 'struct pages' instances
From sm <mukundsarangan@gmail.com>

Show all headers | View raw


Hi:

I am trying to iterate over mem_map array to get virtual addr of the list and also correspondingly get the phys addr along with total page count. 

were you able to print through the complete mem_map array entries with below call. 

kindly advise how and in what way it works. 

thanks 



On Sunday, July 28, 2013 3:45:32 PM UTC-7, frees...@gmail.com wrote:
> Hi,
> 
> 
> 
> I created a module that will publish the virtual and physical address of the global 'mem_map' variable:
> 
> 
> 
> Module code:
> 
> int mem_map_proc_init() {
> 
>     int result=0;
> 
> 
> 
>     if (create_proc_read_entry(DEVICE_NAME,0,NULL,read_mem_map_array,NULL) == NULL) { 
> 
>         printk("Failed to create new /proc/mem_map entry\n");
> 
>         result = -1; 
> 
>     }   
> 
>     else 
> 
>         printk("Created new /proc/mem_map entry\n");    
> 
>     return result;
> 
> }
> 
> 
> 
> int read_mem_map_array(char *buf,char **start,off_t offset,
> 
>                        int count,int *eof,void *data ) { 
> 
>     int len=0;
> 
>     
> 
>     len = sprintf(buf,"mem_map Virtual Address = %p phy address = %#x Number of pages = %ul\n", mem_map, virt_to_phys(mem_map), num_physpages); 
> 
>    
> 
>     return len;
> 
> }
> 
> 
> 
> When I open the /proc/mem_map file, I get the foll output:
> 
> 
> 
> $ cat /proc/mem_map
> 
> mem_map Virtual Address = f73fe000 phy address = 0x373fe000 Number of pages = 0l
> 
> 
> 
> I tried to confirm that the physical address of 'mem_map' by retrieving from '/dev/mem' & mmap(), via a user program:
> 
> 
> 
> int main()
> 
> {
> 
>   int fd=-1;
> 
>   long mem_map_phy_addr = 0x373fe000; /* Use the output in /proc/mem_map */
> 
>   struct page *address = 0;
> 
>   long page_size = sysconf(_SC_PAGESIZE); /* returns 4096 */
> 
> 
> 
>   if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) {
> 
>         perror("open");
> 
>         return -1; 
> 
>   }   
> 
> 
> 
>   address = mmap(0, page_size, PROT_READ, MAP_SHARED, fd, mem_map_phy_addr); 
> 
> 
> 
>   if (address == MAP_FAILED) {
> 
>         perror("mmap");
> 
>         return -1;
> 
>   }
> 
>   printf("Memory mapped at address %p.\n", address);
> 
> 
> 
>   return 0;
> 
> }
> 
> 
> 
> When I execute this user program, I get the following error message from 'perror()':
> 
> mmap: Invalid argument
> 
> 
> 
> I am not sure why the physical address 0x373fe000 is wrong. I thought one possibility might be the requirement that this 'offset' arg to mmap must be divisible by 4096 (page boundary), as per the mmap man page documentation.  It is divisible by 4096.
> 
> 
> 
> Any ideas on why my mmap() experiment is failing with an "invalid argument" error?
> 
> 
> 
> Regards
> 
> CS

Back to comp.os.linux.development.apps | Previous | NextPrevious in thread | Find similar


Thread

Iterating over mem_map and printing out the 'struct pages' instances freesoft12@gmail.com - 2013-07-28 15:45 -0700
  Re: Iterating over mem_map and printing out the 'struct pages' instances sm <mukundsarangan@gmail.com> - 2014-09-29 11:29 -0700

csiph-web