Re: Controlling allocation in 64-bit space
Le Fri, Mar 24, 2006 at 10:44:43PM +0100, Goswin von Brederlow écrivait/wrote:
> Basile STARYNKEVITCH <basile@starynkevitch.net> writes:
>
> >
> > I suggest more precisely to
> > mmap((void*)0, (size_t)size, PROT_READ|PROT_WRITE,
> > MAP_PRIVATE|MAP_ANONYMOUS, (int)-1 /*no fd*/, (off_t)0)
> >
> > with MAP_ANONYMOUS you don't need to open /dev/zero (but internally it is
> > the same)
> >
> > Regards
>
> Is that protable or just a linux speciality?
It exists in recent Solaris, Linux, BSD. And should be conformant to SUSv3 but not SUSv2. the UNIX (from SCO) has it
http://uw713doc.sco.com/en/man/html.2/mmap.2.html
I tend to believe that you can test #ifdef MAP_ANONYMOUS; if it is not
defined, you'll need to open /dev/zero.
I don't know if the availability of /dev/zero is more common today
than MAP_ANONYMOUS
MAP_ANONYMOUS is not a linuxism anymore (IIRC, SunOS got it
before). But I can't be sure that every Unix have it... (IIRC, SunOS4
did not have it, but SunOS5 have it). And MAP_ANONYMOUS is quite common.
Google for mmap & MAP_ANONYMOUS &! linux gives significant results.
Of course, you may find some systems with mmap without MAP_ANONYMOUS
but these are rare, and you can detect them with a #ifdef
MAP_ANONYMOUS (I'll be extremely surprised by systems where
MAP_ANONYMOUS exist but is not a preprocessor name).
But I am not a unix lawyer, even if I did practice several unix before
Linux.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net
aliases: basile<at>tunes<dot>org = bstarynk<at>nerim<dot>net
8, rue de la Faïencerie, 92340 Bourg La Reine, France
Reply to: