mmap & MAP_ANON/MAP_PRIVATE/MAP_SHARED

Andrew Pollard (andrewp@autosim.demon.co.uk)
Fri, 19 Sep 1997 12:27:38 +0100


Hello,

I wonder if anyone can tell me whether Linux (2.0.31pre9 and 2.1.55)
should handle mmap with MAP_ANON|MAP_SHARED as an argument?

The source in mm/mmap.c has a check (if -1 as a file handle is given):

if ((flags & MAP_TYPE) != MAP_PRIVATE)
return -EINVAL;

thus, it disallows MAP_ANON|MAP_SHARED.

Is this the correct behaviour?

I wanted to use an anonymous mmap with MAP_SHARED to share memory
between a parent and a child process. The copy of "Advanced
Programming in the UNIX Environment - W. Richard Stevens" says that
(from 4.3BSD) that you can do

mmap(0, SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0)

to do this.

It also mentions that you can mmap in /dev/zero with MAP_SHARED to do
it under SVR4 type machines (eg solaris2)

In this respect is Linux BSD based or SVR4 based?

Neither seem to work under linux-2.0.31pre9.

Any ideas?

Andrew.

--
 Andrew Pollard, Auto Simulations Ltd. UK.  | work: andrewp@autosim.com
 2 Milbanke Court, Milbanke Way, Bracknell  | home: andrew@odie.demon.co.uk
Tel:+44(0)1344 426486 Fax:+44(0)1344 426615 | http://www.odie.demon.co.uk