Has anybody succeeded in mmap'ing a /proc/pid/mem file with Linux kernel 2.6? I am getting an ENODEV (No such device) error. My call looks like this:
char * map = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, mem_fd, offset);
And I have verified by looking at the /proc/pid/maps file while debugging that, when execution reaches this call, offset has the value of the top of the stack minus PAGE_SIZE. I have also verified with ptrace that mmap is setting errno to ENODEV.
Use open , lseek and read to read from /proc/PID/mem . Before reading from /proc/PID/mem , you need to figure out where the process has things mapped. This information is in /proc/PID/maps . This file is in a text file with reasonable line lengths, so using fopen and fgets is fine.
The /proc/pid pseudo-filesystem was created in order to make access to a ton of kernel data accessible to other programs without being tied to binary structures.
The /proc/PID/smaps is an extension based on maps, showing the memory consumption for each of the process's mappings.
find(1) with the -inum option can be used to locate the file. /proc/[pid]/fd/ This is a subdirectory containing one entry for each file which the process has open, named by its file descriptor, and which is a symbolic link to the actual file. Thus, 0 is standard input, 1 standard output, 2 standard error, and so on.
See proc_mem_operations
in /usr/src/linux/fs/proc/base.c
: /proc/.../mem
does not support mmap
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With