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
2009-11-25 17:34:29
That would require root privileges to do so as a normal non-root user will be denied access to /dev/mem!
tommieb75
2009-11-25 18:08:40
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
2009-11-25 18:39:39
Yes mmap /dev/mem. But it's sucky :)
MarkR
2009-11-25 18:45:33
+3
A:
Usually, to access that in userspace you'd use copy_to_user()
to get a valid userspace copy.
abyx
2009-11-25 17:41:55
+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
2009-11-25 17:44:20