views:

166

answers:

3

Hi, I have a physical memory address, which driver provide me through ioctl. How can I access it in my application in linux.

+5  A: 

If you absolutely have to, use the functions mmap and mprotect from the header <unistd.h> Open /dev/mem

Mads Elvheim
That would require root privileges to do so as a normal non-root user will be denied access to /dev/mem!
tommieb75
Yes, I kind of assumed he couldn't access the memory region via the driver interface. Or else he wouldn't have asked the question in the first place. The question did not mention the privilege level.
Mads Elvheim
Yes mmap /dev/mem. But it's sucky :)
MarkR
+3  A: 

Usually, to access that in userspace you'd use copy_to_user() to get a valid userspace copy.

abyx
+3  A: 

This is evil, you're going to have subtle problems with this approach, and you're most likely going to corrupt memory. As abyx says, have the IOCTL itself return the memory that you're interested in.

Paul Betts