Skip to content
Advertisement

can /proc/self/exe be mmap’ed?

Can a process read /proc/self/exe using mmap? This program fails to mmap the file:

JavaScript

Advertisement

Answer

You are making 2 mistakes here:

  • Mapped size must be > 0. Zero-size mappings are invalid.
  • You have to specify, if you want to create a shared (MAP_SHARED) or a private (MAP_PRIVATE) mapping.

The following should work for example:

JavaScript

If you wish to map the full executable, you will have to do a stat() on it first, to retrieve the correct file size and then use that as the second parameter to mmap().

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement