Subject: Re: port-i386/3927: mmap doens't behave rigth in linux emulation
To: None <gnats-bugs@gnats.netbsd.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: netbsd-bugs
Date: 07/30/1997 06:50:33
> [Some linux programs] mmap an area of size (file_size + a little),
> and [use] the fact that the vm system fills the extra space with
> NULL's to detect the end of the file.  Under NetBSD, the wm subsystem
> seems to use the size of the file to compute the number of pages
> needed, and not the argument passed to mmap.  This implies that, on a
> file with a size just multiple of a page size, mmap will not map the
> last page (which would be filled in with NULLs only), and thus the
> program will get a SIGSEV at the end of the file.

It seems to me that NetBSD is doing it correctly; the "last page" does
not have any file backing it, so you _should_ to get a SIGSEGV when
accessing it.  (Indeed, you really _ought_ to get a SIGSEGV when
accessing bytes in the slop between EOF and the end of the page
containing EOF, but while that's possible, it would probably be ugly to
implement and highly inefficient when accessing bytes that _do_ exist
on that last page, unless the VM hardware supports byte-granularity
access permissions.)

Do we really want to be _this_ bug-compatible with Linux?  It seems to
me (though admittedly I haven't looked at doing it either) that it
would mean allocating two pagers, not one, for the mmap, one to back
most of it, with the file, and one to back the "extra" page, with swap.
I'd say this should be reported to the Linux community as a bug in
their mmap.

					der Mouse

			       mouse@rodents.montreal.qc.ca
		     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B