Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.development.apps > #605
| X-Received | by 10.224.137.137 with SMTP id w9mr45438890qat.6.1375051533251; Sun, 28 Jul 2013 15:45:33 -0700 (PDT) |
|---|---|
| X-Received | by 10.50.120.8 with SMTP id ky8mr338574igb.11.1375051533212; Sun, 28 Jul 2013 15:45:33 -0700 (PDT) |
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!cb17no299613qab.0!news-out.google.com!ce7ni0qab.0!nntp.google.com!cb17no299612qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.os.linux.development.apps |
| Date | Sun, 28 Jul 2013 15:45:32 -0700 (PDT) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=98.248.78.61; posting-account=lZhWrQoAAACQmfPerCaHVNn3I4R064Y9 |
| NNTP-Posting-Host | 98.248.78.61 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| 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 |
| Injection-Date | Sun, 28 Jul 2013 22:45:33 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Xref | csiph.com comp.os.linux.development.apps:605 |
Show key headers only | View raw
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