Re: wierd problem with 'make dep'

Ralf Baechle (ralf@cobaltmicro.com)
Thu, 2 Oct 1997 10:20:41 -0700 (PDT)


Hi Bill,

> Ralf Baechle wrote:
> > There is another bug in mkdep. mkdep mmap(2) the file to work on. The
> > algorithem it uses may access upto 6 bytes beyond the end of the mapped
> > file. If those 6 bytes happen to be on the following page, the kernel
> > will send mkdep into the kingdom of happy signals. This however only
> > happens for more strictly standard conforming implementations of mmap
> > (like when crosscompiling on Solaris or IRIX); by my interpretation
> > Linux's isn't.
>
> Hi Ralf,
> Are you saying the Linux mmap implementation needs to be fixed to
> conform with the expected standards? If so, if you can give me a
> pointer to where the behavior is incorrect I'll take a look at the code.

mkdep accounts for accessing upto six bytes beyond the end of the mmaped
file by trying to map six bytes more. The Linux kernel is smart and
zero maps these six bytes, even if this means mapping an extra page.

I discusses this with Ulrich Drepper some time ago, here the two cites
from standards he came up with.

POSIX.1 says:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The system shall always zero-fill any partial page at the end of an
object. Further, the system shall never write out anu modified
portions of the last page of an object that are beyond its end. If
the Memory Protection option is supported, references withing the
address range starting at <tt/pa/ [[das ist der Rückgabewert von
mmap]] and continuing for <tt/len/ bytes to whole pages following the
end of an object shall result in the generation of a SIGBUS signal.
When the Memory Protection option is not supported, the result of
references withing the address range starting at <tt/pa/ and
continuing for <tt/len/ bytes to whole pages following the end of an
object is undefined.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

POSIX.1 also says that the mapped part of the file has to be valid.
I'd interpret that such that it is _not_ possible to map beyond the
end of a file.

XPG4.2 says:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If the mapping established by <tt/mmap()/ extends into pages beyond
the page cotnaining the last byte of the file, an application
reference to any of the @ages in the mapping that are beyond the last
page results in the delivery of a SIGBUS or SIGSEGV signal.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Which is exactly what happens on IRIX or Solaris.

Ralf