Re: mmap

From: Eric Dumazet
Date: Fri Dec 02 2011 - 09:45:30 EST


Le vendredi 02 dÃcembre 2011 Ã 13:20 +0100, SÃbastien Paumier a Ãcrit :
> Hi,
> I have a question about mmap's behavior when one tries to map a file asking for
> a length greater than the actual file size. When I run the attached code on a
> 100 bytes file, I have the following output:
>
> (... file content followed by zeros...)
> n=4096
> write: Bad address
>
> So, it seems that the actual memory area provided by mmap is one page large and
> not the requested length of filesize+10000. I guess that 'write' writes less
> than requested because it was interrupted by the SIGBUS signal. And my question is:
>
> shouldn't mmap either complain about the requested length or provide an
> accessible area of the requested length, instead of silently failing ?


Accessing non existing memory leads to SIGBUS signal, not a silent
failure. Its documented behavior.

man mmap

SIGBUS Attempted access to a portion of the buffer that does not correâ
spond to the file (for example, beyond the end of the file,
including the case where another process has truncated the
file).


--
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/