lkml.org 
[lkml]   [2002]   [Oct]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectFinding a physical address from userspace?
Assume I run this code from userspace as root (I'll omit all error checking
and assume the page size is known to be 4KB to keep the code short):

#define PAGECNT 10
#define PAGESIZE 4096

int
main(int argc, char *argv[])
{
char * cp;
char * physaddr[PAGECNT];

cp = malloc(PAGECNT*PAGESIZE);
mlock(cp, PAGECNT*PAGESIZE);

for (i = 0; i < PAGECNT; i++) {
physaddr[i] = USERSPACE_VIRT_TO_PHYS(cp + i * PAGESIZE);
}
}


Two questions:

(1) The mlock() manpage says only that it will lock the pages into memory.
It's not clear if the pages also are guaranteed not to change physical
addresses while the mlock() is in effect. I realize that, in theory,
the pages could move in physical memory, but in the real world of
kernel 2.4.x, could the physical addresses of mlock()'ed pages ever
change?

(2) Is there any way to write the 'USERSPACE_VIRT_TO_PHYS' function? I
realize I could write a simple character device driver to accomplish
the task, but I was hoping there would be a purely userspace solution
that would not require writing (and installing) a kernel module.
Suggestions? It seems like this would a FAQ, but I couldn't find a
mention of it in the LKML archives.

(How about something "insane" like mmap()'ing /dev/mem starting at
offset zero, filling the block pointed to by 'cp' with a known pattern,
and then running through the mmap()'ed /dev/mem looking for the known
pattern? Is this crazy/stupid enough to work?)

Thanks.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:30    [W:0.037 / U:0.496 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site