Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mmap on /proc/pid/mem

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.

like image 740
Amittai Aviram Avatar asked Mar 07 '11 05:03

Amittai Aviram


People also ask

How do I read from proc PID MEM?

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.

What is proc PID?

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.

What is proc PID Smaps?

The /proc/PID/smaps is an extension based on maps, showing the memory consumption for each of the process's mappings.

What is proc PID FD?

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.


1 Answers

See proc_mem_operations in /usr/src/linux/fs/proc/base.c: /proc/.../mem does not support mmap.

like image 184
ephemient Avatar answered Sep 19 '22 21:09

ephemient