tested on Solaris 11/AMD64 when previous build failed
Yeah, I can't really understand or quickly find any references to this here, although it seems simply mapping /dev/zero is the proper way to get anonymous/private memory (sometimes?). It would be nice to back it up with a link to man mmap and man zero maybe?
Guys, thanks for your comments. I'd like to address them here:
- Irix support: the thing also surprised me in the original code and was the reason why I forked Solaris from solaris||irix ifdef block to make sure I do not break irix thing.
- the idea behind whole this fix is that Solaris requires for whatever reason to really allocate anon mem for us. In the second case of the original code this was not true as MAP_ANON was missing. Please note that I'm not able to quickly find why exactly we need to have anon mem here, but well, it's working this way
- there are exactly two ways how to get anon mem on Solaris, either use /dev/zero as in the code above or simply use MAP_ANON and -1 as file descriptor:
ret = mmap(addr, size, prot, flags | MAP_ANON | MAP_PRIVATE, -1, 0);
is working well too. If this is more close to common mmap understanding than I can update the patch to use this second way instead of /dev/zero above and then perhaps avoid a need for the comment?
Solaris `man mmap' claims this clearly:
When MAP_ANON is set in flags, and fildes is set to -1, mmap() provides a direct path to return anonymous pages to the caller. This operation is equivalent to passing mmap() an open file descriptor on /dev/zero with MAP_ANON elided from the flags argument.