Re: don't let mmap allocate down to zero

From: Olivier Galibert
Date: Wed Jan 26 2005 - 21:36:45 EST


On Wed, Jan 26, 2005 at 01:20:53PM -0500, linux-os wrote:
> On Wed, 26 Jan 2005, Olivier Galibert wrote:
> >Given that the man page itself says that unless you're using MAP_FIXED
> >start is only a hint and you should use 0 if you don't care things can
> >get real annoying real fast. Imagine if you want to mmap a <4K file
> >and mmap then returns 0, i.e. NULL, as the mapping address as you
> >asked. It's illegal from the point of view of susv3[1] and it's real
> >annoying in a C/C++ program.
>
> mmap() can (will) return 0 if you use 0 as the hint and use MAP_FIXED
> at 0. That's the reason why one does NOT check for NULL with mmap() but
> for MAP_FAILED (which on this system is (void *)-1.

All the paragraph was under an obvious "when you do not use MAP_FIXED"
precondition. The patch is not supposed to change anything to the
MAP_FIXED case. Malloc does not use MAP_FIXED. Usual file mmaping
as an alternative to read() does not use MAP_FIXED.

OG.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/