Re: mmap(MAP_SHARED | MAP_ANON) broke!

Mark Hemment (markhe@sco.COM)
Mon, 13 Jan 1997 11:58:34 +0000 (GMT)


Hi,

> > There is also another solution (That's a real hack).
> > x = mmap(..., MAP_ANON |MAP_PRIVATE, ...);
> > fd = open("/proc/self/mem");
> > y = mmap(...., MAP_SHARED, ..., fd, x);
> > munmap(x);
>
> This didn't work for me... I also tried forking and then
> mmap-ing() the
> space out of the other processes /proc/.../mem--
>
> Any idea what's going on (code attached).

Without a source tree at work, I can only guess from memory (no
pun intended :)

Check in proc/fs, there is a file which implements the
file operations for /proc/pid|self/* (it's probably called mem.c).
There is a func for mmap() ops on /proc/*/mem, which has a few
restrictions. One of the limitations (if I remember correctly),
is that the pte's in the range being mapped must be present (ie.
pte_none() needs to return zero).
The anon mapping will not fill out any pte's in the mapped range,
so this maybe why the second mmap() fails.

After mmap(..,MAP_ANON...), try touching each page. A read might
be succifient (it will set the pte's to point to the ZERO page), if
that doesn't work try a write to each page.

Also, it's probably worth checking your rlimits (although that should
return -ENMEM (12), not the 22 you are seeing).

Best of luck,

markhe