Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > comp.os.linux.development.apps > #605
| Newsgroups | comp.os.linux.development.apps |
|---|---|
| Date | 2013-07-28 15:45 -0700 |
| Message-ID | <5f6a4592-ca68-4322-9a1b-2b7d7bb5cc2b@googlegroups.com> (permalink) |
| Subject | Iterating over mem_map and printing out the 'struct pages' instances |
| From | freesoft12@gmail.com |
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 | Next — Next in thread | Find similar
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